Fem: Add Z-refinement support for Netgen

This commit is contained in:
marioalexis
2025-02-08 13:20:28 -03:00
parent eb886449c2
commit f5de900f8d
2 changed files with 42 additions and 5 deletions

View File

@@ -112,6 +112,9 @@ class NetgenTools:
"result_file": self.result_file,
"mesh_region": self.get_mesh_region(),
"verbosity": self.param_grp.GetInt("LogVerbosity", 2),
"zrefine": self.obj.ZRefine,
"zrefine_size": self.obj.ZRefineSize,
"zrefine_direction": tuple(self.obj.ZRefineDirection),
}
with open(self.script_file, "w") as file:
@@ -146,6 +149,9 @@ def run_netgen(
result_file,
mesh_region,
verbosity,
zrefine,
zrefine_size,
zrefine_direction,
):
geom = occ.OCCGeometry(brep_file)
ngcore.SetNumThreads(threads)
@@ -162,6 +168,12 @@ def run_netgen(
elif t == "Solid":
shape.solids.solids[n - 1].maxh = l
if zrefine in ["Custom", "Regular"]:
for sol in shape.solids:
bottom = sol.faces.Min(zrefine_direction)
top = sol.faces.Max(zrefine_direction)
bottom.Identify(top, "bot-top", type=occ.IdentificationType.CLOSESURFACES)
with ngcore.TaskManager():
meshing.SetMessageImportance(verbosity)
geom = occ.OCCGeometry(shape)
@@ -169,6 +181,11 @@ def run_netgen(
geom.Heal()
mesh = geom.GenerateMesh(mp=meshing.MeshingParameters(**params))
if zrefine == "Regular":
mesh.ZRefine("bot-top", np.arange(zrefine_size[0], 1, zrefine_size[0]))
elif zrefine == "Custom":
mesh.ZRefine("bot-top", zrefine_size)
result = {{
"coords": [],
"Edges": [[], []],
@@ -317,7 +334,6 @@ run_netgen(**{kwds})
"try_hexes": self.obj.TryHexes,
"inverttets": self.obj.InvertTets,
"inverttrigs": self.obj.InvertTrigs,
"autozrefine": self.obj.AutoZRefine,
"parallel_meshing": self.obj.ParallelMeshing,
"nthreads": self.param_grp.GetInt("NumOfThreads", QThread.idealThreadCount()),
"closeedgefac": self.obj.CloseEdgeFactor,

View File

@@ -469,11 +469,32 @@ class MeshNetgen(base_fempythonobject.BaseFemPythonObject):
)
prop.append(
_PropHelper(
type="App::PropertyBool",
name="AutoZRefine",
type="App::PropertyEnumeration",
name="ZRefine",
group="Mesh Parameters",
doc="Automatic Z refine",
value=False,
doc="Z-refinement for extruded shapes",
value=["No", "Regular", "Custom"],
)
)
prop.append(
_PropHelper(
type="App::PropertyVector",
name="ZRefineDirection",
group="Mesh Parameters",
doc="Z-refinement direction",
value=Base.Vector(0, 0, 1),
)
)
prop.append(
_PropHelper(
type="App::PropertyFloatList",
name="ZRefineSize",
group="Mesh Parameters",
doc="Z-refinement size given as a fraction of the shape size.\n"
+ "For a regular partition only one value is needed",
value=[
0.1,
],
)
)
prop.append(