mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +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 ..
|
// parameters by Philippose ..
|
||||||
Array<int> surfid;
|
Array<int> surfid;
|
||||||
Array<double> heights;
|
Array<double> heights;
|
||||||
Array<size_t> new_matnrs;
|
string new_mat;
|
||||||
BitArray domains;
|
BitArray domains;
|
||||||
bool outside = false; // set the boundary layer on the outside
|
bool outside = false; // set the boundary layer on the outside
|
||||||
bool grow_edges = false;
|
bool grow_edges = false;
|
||||||
|
@ -1017,9 +1017,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
|
|
||||||
.def ("BoundaryLayer", [](Mesh & self, variant<string, int> boundary,
|
.def ("BoundaryLayer", [](Mesh & self, variant<string, int> boundary,
|
||||||
variant<double, py::list> thickness,
|
variant<double, py::list> thickness,
|
||||||
variant<string, py::list> material,
|
string material,
|
||||||
variant<string, int> domain, bool outside,
|
variant<string, int> domain, bool outside,
|
||||||
bool grow_edges,
|
|
||||||
optional<string> project_boundaries)
|
optional<string> project_boundaries)
|
||||||
{
|
{
|
||||||
BoundaryLayerParameters blp;
|
BoundaryLayerParameters blp;
|
||||||
@ -1050,6 +1049,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
blp.new_mat = material;
|
||||||
|
|
||||||
if(project_boundaries.has_value())
|
if(project_boundaries.has_value())
|
||||||
{
|
{
|
||||||
@ -1070,34 +1070,13 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
blp.heights.Append(val.cast<double>());
|
blp.heights.Append(val.cast<double>());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto prismlayers = blp.heights.Size();
|
int nr_domains = self.GetNDomains();
|
||||||
auto first_new_mat = self.GetNDomains() + 1;
|
blp.domains.SetSize(nr_domains + 1); // one based
|
||||||
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
|
|
||||||
blp.domains.Clear();
|
blp.domains.Clear();
|
||||||
if(string* pdomain = get_if<string>(&domain); pdomain)
|
if(string* pdomain = get_if<string>(&domain); pdomain)
|
||||||
{
|
{
|
||||||
regex pattern(*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))
|
if(regex_match(self.GetMaterial(i), pattern))
|
||||||
blp.domains.SetBit(i);
|
blp.domains.SetBit(i);
|
||||||
}
|
}
|
||||||
@ -1106,19 +1085,15 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
|||||||
auto idomain = *get_if<int>(&domain);
|
auto idomain = *get_if<int>(&domain);
|
||||||
blp.domains.SetBit(idomain);
|
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.outside = outside;
|
||||||
blp.grow_edges = grow_edges;
|
blp.grow_edges = true;
|
||||||
|
|
||||||
GenerateBoundaryLayer (self, blp);
|
GenerateBoundaryLayer (self, blp);
|
||||||
self.UpdateTopology();
|
self.UpdateTopology();
|
||||||
}, py::arg("boundary"), py::arg("thickness"), py::arg("material"),
|
}, py::arg("boundary"), py::arg("thickness"), py::arg("material"),
|
||||||
py::arg("domains") = ".*", py::arg("outside") = false,
|
py::arg("domains") = ".*", py::arg("outside") = false,
|
||||||
py::arg("grow_edges") = false, py::arg("project_boundaries")=nullopt,
|
py::arg("project_boundaries")=nullopt,
|
||||||
R"delimiter(
|
R"delimiter(
|
||||||
Add boundary layer to mesh.
|
Add boundary layer to mesh.
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ def test_boundarylayer(outside, capfd):
|
|||||||
mesh = unit_cube.GenerateMesh(maxh=0.3)
|
mesh = unit_cube.GenerateMesh(maxh=0.3)
|
||||||
ne_before = mesh.ne
|
ne_before = mesh.ne
|
||||||
layer_surfacenames = ["right", "top", "left", "back", "bottom"]
|
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)
|
should_ne = ne_before + 2 * GetNSurfaceElements(mesh, layer_surfacenames)
|
||||||
assert mesh.ne == should_ne
|
assert mesh.ne == should_ne
|
||||||
@ -26,7 +26,7 @@ def test_boundarylayer(outside, capfd):
|
|||||||
assert not "elements are not matching" in capture.out
|
assert not "elements are not matching" in capture.out
|
||||||
|
|
||||||
for side in ["front"]:
|
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])
|
should_ne += 2 * GetNSurfaceElements(mesh, [side])
|
||||||
assert mesh.ne == should_ne
|
assert mesh.ne == should_ne
|
||||||
capture = capfd.readouterr()
|
capture = capfd.readouterr()
|
||||||
@ -53,8 +53,8 @@ def test_boundarylayer2(outside, version, capfd):
|
|||||||
geo.CloseSurfaces(top, bot, [])
|
geo.CloseSurfaces(top, bot, [])
|
||||||
mesh = geo.GenerateMesh()
|
mesh = geo.GenerateMesh()
|
||||||
should_ne = mesh.ne + 2 * GetNSurfaceElements(mesh, ["default"], "part")
|
should_ne = mesh.ne + 2 * GetNSurfaceElements(mesh, ["default"], "part")
|
||||||
layersize = 0.05
|
layersize = 0.025
|
||||||
mesh.BoundaryLayer("default", [0.5 * layersize, layersize], "part", domains="part", outside=outside, grow_edges=True)
|
mesh.BoundaryLayer("default", [layersize, layersize], "part", domains="part", outside=outside)
|
||||||
assert mesh.ne == should_ne
|
assert mesh.ne == should_ne
|
||||||
assert not "elements are not matching" in capfd.readouterr().out
|
assert not "elements are not matching" in capfd.readouterr().out
|
||||||
import netgen.gui
|
import netgen.gui
|
||||||
@ -73,8 +73,7 @@ def test_wrong_orientation(outside):
|
|||||||
|
|
||||||
mesh = geo.GenerateMesh()
|
mesh = geo.GenerateMesh()
|
||||||
|
|
||||||
mesh.BoundaryLayer(".*", 0.1, "air", domains="air", outside=outside,
|
mesh.BoundaryLayer(".*", 0.1, "air", domains="air", outside=outside)
|
||||||
grow_edges=True)
|
|
||||||
ngs = pytest.importorskip("ngsolve")
|
ngs = pytest.importorskip("ngsolve")
|
||||||
mesh = ngs.Mesh(mesh)
|
mesh = ngs.Mesh(mesh)
|
||||||
assert ngs.Integrate(1, mesh) == pytest.approx(1.2**3 if outside else 1)
|
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"))
|
geo.Add((brick*slots).mat("slot"))
|
||||||
|
|
||||||
mesh = geo.GenerateMesh()
|
mesh = geo.GenerateMesh()
|
||||||
mesh.BoundaryLayer(".*", [0.001, 0.002], "block", "block", outside=False,
|
mesh.BoundaryLayer(".*", [0.001, 0.001], "block", "block", outside=False)
|
||||||
grow_edges=True)
|
|
||||||
ngs = pytest.importorskip("ngsolve")
|
ngs = pytest.importorskip("ngsolve")
|
||||||
mesh = ngs.Mesh(mesh)
|
mesh = ngs.Mesh(mesh)
|
||||||
assert ngs.Integrate(1, mesh) == pytest.approx(1)
|
assert ngs.Integrate(1, mesh) == pytest.approx(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user