TypeError: bad operand type for unary ~: 'ZCylinder'

Hi OpenMC users-

I am currently working on a project to build a test loop model for my undergraduate senior capstone and am trying to construct my geometry file for my system. I am getting a “TypeError: bad operand type for unary ~: ‘ZCylinder’” error when trying to assign air as a region between my “graveyard” (void) and the other systems in the model as a final step towards assigning all space within my void’s boundaries with a region. It is important to note that the void is a surface (large sphere), whereas the air is simply a region.

In previous equipment I have been able to construct, it has been rather easy. An example is as follows:

# Create the pump
pump = openmc.model.RectangularParallelepiped(xmin=x0_Pump, xmax=x0_Pump + length_x_Pump, ymin=y0_Pump, ymax=y0_Pump + length_y_Pump,zmin=z0_Pump, zmax=z0_Pump + length_z_Pump)

pump_region = -pump & +pipe_cylinder_steel_4

pump = openmc.Cell(13, 'pump')
pump.fill = steel
pump.region = pump_region

As seen here, the pump surface is created, and the region is defined as inside of the pump surface and outside of a conflicting pipe in the same space. OpenMC interprets this and assigns my pre-allocated material, namely “steel”. Finally, the region is assigned.

I have been performing this same process for all equipment in my model and would like to lastly do this for air to be outside all my equipment surfaces an inside my void. My attend to do so is as follows:

#air

air_region = -void & ~pipe_cylinder_tungsten_1& ~pipe_cylinder_steel_2& ~pipe_cylinder_steel_3 & ~pipe_cylinder_steel_4 & ~steel_block & ~concrete_slab & ~pump & ~nu2100

air_filter = openmc.Cell(15, 'air')
air.fill = air
air.region = air_region

Where void, pipe_cylinder_tungsten_1, etc. are defined surfaces in my model. I have also attempted doing these using regions instead of surfaces, and with the + instead of the ~. Where is my pitfall in this syntax?

Hi @uc_mstl_1,

Thanks for reaching out about this. ~ is a compliment operator and should be applied to openmc.Region objects rather than surfaces. - operates on openmc.Surface objects to indicate which side of the surface is used. For air_region above, if you change the ~ above being applied to surfaces like pipe_cylinder_steel_2 to - (but leave it in place for any of the regions in that definition) then you should end up with a valid region for the cell.

Hope this helps,

Patrick