Merge branch 'split_faces_by_adjacent_domains' into 'master'

Utility function to split faces when they have more than two adjacent domains

See merge request ngsolve/netgen!633
This commit is contained in:
Lackner, Christopher 2024-02-14 10:18:29 +01:00
commit 2e80cb34b6
3 changed files with 50 additions and 0 deletions

View File

@ -7152,6 +7152,53 @@ namespace netgen
SetNextMajorTimeStamp(); SetNextMajorTimeStamp();
} }
void Mesh :: SplitFacesByAdjacentDomains ()
{
UpdateTopology();
std::map<std::tuple<int, int, int>, int> face_doms_2_new_face;
int nfaces = FaceDescriptors().Size();
Array<bool> first_visit(nfaces);
first_visit = true;
for (auto sei : Range(SurfaceElements()))
{
int eli0, eli1;
GetTopology().GetSurface2VolumeElement(sei+1, eli0, eli1);
auto & sel = (*this)[sei];
int face = sel.GetIndex();
int domin = VolumeElement(eli0).GetIndex();
int domout = eli1 ? VolumeElement(eli1).GetIndex() : 0;
if(domin < domout)
swap(domin, domout);
auto key = std::make_tuple(face, domin, domout);
if(face_doms_2_new_face.find(key) == face_doms_2_new_face.end())
{
if(!first_visit[face-1]) {
nfaces++;
FaceDescriptor new_fd = FaceDescriptors()[face-1];
new_fd.bcprop = nfaces;
new_fd.domin = domin;
new_fd.domout = domout;
AddFaceDescriptor(new_fd);
SetBCName(nfaces-1, new_fd.GetBCName());
face_doms_2_new_face[key] = nfaces;
}
else {
face_doms_2_new_face[key] = face;
auto & fd = FaceDescriptors()[face-1];
fd.domin = domin;
fd.domout = domout;
}
first_visit[face-1] = false;
}
sel.SetIndex(face_doms_2_new_face[key]);
}
SetNextMajorTimeStamp();
RebuildSurfaceElementLists ();
CalcSurfacesOfNode();
UpdateTopology();
}
void Mesh :: SetMaterial (int domnr, const string & mat) void Mesh :: SetMaterial (int domnr, const string & mat)
{ {
if (domnr > materials.Size()) if (domnr > materials.Size())

View File

@ -699,6 +699,8 @@ namespace netgen
auto & GetCommunicator() const { return this->comm; } auto & GetCommunicator() const { return this->comm; }
void SetCommunicator(NgMPI_Comm acomm); void SetCommunicator(NgMPI_Comm acomm);
DLL_HEADER void SplitFacesByAdjacentDomains();
/// ///
DLL_HEADER void SetMaterial (int domnr, const string & mat); DLL_HEADER void SetMaterial (int domnr, const string & mat);
/// ///

View File

@ -1250,6 +1250,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
.def ("GetCD3Name", &Mesh::GetCD3Name) .def ("GetCD3Name", &Mesh::GetCD3Name)
.def ("SetCD3Name", &Mesh::SetCD3Name) .def ("SetCD3Name", &Mesh::SetCD3Name)
.def ("SplitFacesByAdjacentDomains", &Mesh::SplitFacesByAdjacentDomains)
.def("GetIdentifications", [](Mesh & self) -> py::list .def("GetIdentifications", [](Mesh & self) -> py::list
{ {
py::list points; py::list points;