Use CoefficientFunction as indicator function to define subdomains

Dear NGSolve community,

Is there a (efficient/clever) way to use CoefficientFunctions (VoxelCoefficientFunctions) as indicator functions to define subdomains? Hence, having a 3d volume/mesh and define different domains (materials) according to the value of the CoefficientFunction.
I assume it is similar to the explanations in stl file contains multiple parts / individual material parameters needed, where the element index is set using some coordinate criterium.

Thanks!
Chris

I use materialCF of mesh:

mesh.MaterialCF(
                {
                "Iron": function_or_constant_for_iron,
                "Permendur": function_or_constant_for_permendur
                },
                default = default_material
            )

If domains in mesh are named “Iron”, “Permendur” then you can asign different values.

Hi QB256,

Thanks for your answer. However, my question is about how to define those (sub)domains. Your answer assumes that one already has the domains. I am aware of domain-wise coefficient functions.

Best regards, Chris

How are you creating your 3D geometry? You are importing STL? In STL is probably no information about domain names. If you import STEP or create domains in NGsolve, then you can assign names to them.

Hi,

I’m aware of the alteratives with STEP files and the therein defined domains. But in this specific application I only have an STL outer shape and VoxelCoefficientFunctions as indicators for the domains.

You can get the center of each element as a MeshPoint by evaluating a p0 IntegrationRule on all tets. And then from these coordinates assign domain indices to the elements:
something like

center_points = mesh.MapToAllElements(IntegrationRule(ET.TET, 0), VOL)
coords = CF((x,y,z))(center_points)

this gives you a numpy array with all center coordinates.

1 Like