mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 04:50:34 +05:00
rewrite create boundarylayer function (now more efficient and stable
and easier)
This commit is contained in:
parent
0d48924392
commit
609cbbcadf
File diff suppressed because it is too large
Load Diff
@ -14,7 +14,7 @@ public:
|
||||
// parameters by Philippose ..
|
||||
Array<int> surfid;
|
||||
Array<double> heights;
|
||||
Array<size_t> new_matnrs;
|
||||
string new_mat;
|
||||
BitArray domains;
|
||||
bool outside = false; // set the boundary layer on the outside
|
||||
bool grow_edges = false;
|
||||
|
@ -1017,9 +1017,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
|
||||
.def ("BoundaryLayer", [](Mesh & self, variant<string, int> boundary,
|
||||
variant<double, py::list> thickness,
|
||||
variant<string, py::list> material,
|
||||
string material,
|
||||
variant<string, int> domain, bool outside,
|
||||
bool grow_edges,
|
||||
optional<string> project_boundaries)
|
||||
{
|
||||
BoundaryLayerParameters blp;
|
||||
@ -1050,6 +1049,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
}
|
||||
}
|
||||
}
|
||||
blp.new_mat = material;
|
||||
|
||||
if(project_boundaries.has_value())
|
||||
{
|
||||
@ -1070,34 +1070,13 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
blp.heights.Append(val.cast<double>());
|
||||
}
|
||||
|
||||
auto prismlayers = blp.heights.Size();
|
||||
auto first_new_mat = self.GetNDomains() + 1;
|
||||
auto max_dom_nr = first_new_mat;
|
||||
if(string* pmaterial = get_if<string>(&material); pmaterial)
|
||||
{
|
||||
self.SetMaterial(first_new_mat, *pmaterial);
|
||||
for(auto i : Range(prismlayers))
|
||||
blp.new_matnrs.Append(first_new_mat);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto materials = *get_if<py::list>(&material);
|
||||
if(py::len(materials) != prismlayers)
|
||||
throw Exception("Length of thicknesses and materials must be same!");
|
||||
for(auto i : Range(prismlayers))
|
||||
{
|
||||
self.SetMaterial(first_new_mat+i, materials[i].cast<string>());
|
||||
blp.new_matnrs.Append(first_new_mat + i);
|
||||
}
|
||||
max_dom_nr += prismlayers-1;
|
||||
}
|
||||
|
||||
blp.domains.SetSize(max_dom_nr + 1); // one based
|
||||
int nr_domains = self.GetNDomains();
|
||||
blp.domains.SetSize(nr_domains + 1); // one based
|
||||
blp.domains.Clear();
|
||||
if(string* pdomain = get_if<string>(&domain); pdomain)
|
||||
{
|
||||
regex pattern(*pdomain);
|
||||
for(auto i : Range(1, first_new_mat))
|
||||
for(auto i : Range(1, nr_domains+1))
|
||||
if(regex_match(self.GetMaterial(i), pattern))
|
||||
blp.domains.SetBit(i);
|
||||
}
|
||||
@ -1106,19 +1085,15 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
auto idomain = *get_if<int>(&domain);
|
||||
blp.domains.SetBit(idomain);
|
||||
}
|
||||
// bits for new domains must be set
|
||||
if(!outside)
|
||||
for(auto i : Range(first_new_mat, max_dom_nr+1))
|
||||
blp.domains.SetBit(i);
|
||||
|
||||
blp.outside = outside;
|
||||
blp.grow_edges = grow_edges;
|
||||
blp.grow_edges = true;
|
||||
|
||||
GenerateBoundaryLayer (self, blp);
|
||||
self.UpdateTopology();
|
||||
}, py::arg("boundary"), py::arg("thickness"), py::arg("material"),
|
||||
py::arg("domains") = ".*", py::arg("outside") = false,
|
||||
py::arg("grow_edges") = false, py::arg("project_boundaries")=nullopt,
|
||||
py::arg("project_boundaries")=nullopt,
|
||||
R"delimiter(
|
||||
Add boundary layer to mesh.
|
||||
|
||||
|
@ -18,7 +18,7 @@ def test_boundarylayer(outside, capfd):
|
||||
mesh = unit_cube.GenerateMesh(maxh=0.3)
|
||||
ne_before = mesh.ne
|
||||
layer_surfacenames = ["right", "top", "left", "back", "bottom"]
|
||||
mesh.BoundaryLayer("|".join(layer_surfacenames), [0.01, 0.02], "layer", outside=outside, grow_edges=True)
|
||||
mesh.BoundaryLayer("|".join(layer_surfacenames), [0.01, 0.01], "layer", outside=outside)
|
||||
|
||||
should_ne = ne_before + 2 * GetNSurfaceElements(mesh, layer_surfacenames)
|
||||
assert mesh.ne == should_ne
|
||||
@ -26,7 +26,7 @@ def test_boundarylayer(outside, capfd):
|
||||
assert not "elements are not matching" in capture.out
|
||||
|
||||
for side in ["front"]:
|
||||
mesh.BoundaryLayer(side, [0.001, 0.002], "layer", outside=outside, grow_edges=True)
|
||||
mesh.BoundaryLayer(side, [0.001, 0.001], "layer", outside=outside)
|
||||
should_ne += 2 * GetNSurfaceElements(mesh, [side])
|
||||
assert mesh.ne == should_ne
|
||||
capture = capfd.readouterr()
|
||||
@ -53,8 +53,8 @@ def test_boundarylayer2(outside, version, capfd):
|
||||
geo.CloseSurfaces(top, bot, [])
|
||||
mesh = geo.GenerateMesh()
|
||||
should_ne = mesh.ne + 2 * GetNSurfaceElements(mesh, ["default"], "part")
|
||||
layersize = 0.05
|
||||
mesh.BoundaryLayer("default", [0.5 * layersize, layersize], "part", domains="part", outside=outside, grow_edges=True)
|
||||
layersize = 0.025
|
||||
mesh.BoundaryLayer("default", [layersize, layersize], "part", domains="part", outside=outside)
|
||||
assert mesh.ne == should_ne
|
||||
assert not "elements are not matching" in capfd.readouterr().out
|
||||
import netgen.gui
|
||||
@ -73,8 +73,7 @@ def test_wrong_orientation(outside):
|
||||
|
||||
mesh = geo.GenerateMesh()
|
||||
|
||||
mesh.BoundaryLayer(".*", 0.1, "air", domains="air", outside=outside,
|
||||
grow_edges=True)
|
||||
mesh.BoundaryLayer(".*", 0.1, "air", domains="air", outside=outside)
|
||||
ngs = pytest.importorskip("ngsolve")
|
||||
mesh = ngs.Mesh(mesh)
|
||||
assert ngs.Integrate(1, mesh) == pytest.approx(1.2**3 if outside else 1)
|
||||
@ -88,8 +87,7 @@ def test_splitted_surface():
|
||||
geo.Add((brick*slots).mat("slot"))
|
||||
|
||||
mesh = geo.GenerateMesh()
|
||||
mesh.BoundaryLayer(".*", [0.001, 0.002], "block", "block", outside=False,
|
||||
grow_edges=True)
|
||||
mesh.BoundaryLayer(".*", [0.001, 0.001], "block", "block", outside=False)
|
||||
ngs = pytest.importorskip("ngsolve")
|
||||
mesh = ngs.Mesh(mesh)
|
||||
assert ngs.Integrate(1, mesh) == pytest.approx(1)
|
||||
|
Loading…
Reference in New Issue
Block a user