mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-25 21:40:33 +05:00
adding Mesh.AddRegion
This commit is contained in:
parent
dbe0aaa1bc
commit
de06f21bde
@ -6563,6 +6563,21 @@ namespace netgen
|
||||
return defaultstring;
|
||||
}
|
||||
|
||||
|
||||
NgArray<string*> & Mesh :: GetRegionNamesCD (int codim)
|
||||
{
|
||||
switch (codim)
|
||||
{
|
||||
case 0: return materials;
|
||||
case 1: return bcnames;
|
||||
case 2: return cd2names;
|
||||
case 3: return cd3names;
|
||||
default: throw Exception("don't have regions of co-dimension "+ToString(codim));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Mesh :: SetUserData(const char * id, NgArray<int> & data)
|
||||
{
|
||||
if(userdata_int.Used(id))
|
||||
|
@ -687,6 +687,9 @@ namespace netgen
|
||||
string * GetBCNamePtr (int bcnr) const
|
||||
{ return (bcnr < bcnames.Size() && bcnames[bcnr]) ? bcnames[bcnr] : &default_bc; }
|
||||
|
||||
|
||||
NgArray<string*> & GetRegionNamesCD (int codim);
|
||||
|
||||
///
|
||||
void ClearFaceDescriptors()
|
||||
{ facedecoding.SetSize(0); }
|
||||
|
@ -321,35 +321,35 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
;
|
||||
|
||||
py::class_<Element2d>(m, "Element2D")
|
||||
.def(py::init ([](int index, py::list vertices)
|
||||
.def(py::init ([](int index, std::vector<PointIndex> vertices)
|
||||
{
|
||||
Element2d * newel = nullptr;
|
||||
if (py::len(vertices) == 3)
|
||||
if (vertices.size() == 3)
|
||||
{
|
||||
newel = new Element2d(TRIG);
|
||||
for (int i = 0; i < 3; i++)
|
||||
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||
(*newel)[i] = vertices[i];
|
||||
newel->SetIndex(index);
|
||||
}
|
||||
else if (py::len(vertices) == 4)
|
||||
else if (vertices.size() == 4)
|
||||
{
|
||||
newel = new Element2d(QUAD);
|
||||
for (int i = 0; i < 4; i++)
|
||||
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||
(*newel)[i] = vertices[i];
|
||||
newel->SetIndex(index);
|
||||
}
|
||||
else if (py::len(vertices) == 6)
|
||||
else if (vertices.size() == 6)
|
||||
{
|
||||
newel = new Element2d(TRIG6);
|
||||
for(int i = 0; i<6; i++)
|
||||
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||
(*newel)[i] = vertices[i];
|
||||
newel->SetIndex(index);
|
||||
}
|
||||
else if (py::len(vertices) == 8)
|
||||
else if (vertices.size() == 8)
|
||||
{
|
||||
newel = new Element2d(QUAD8);
|
||||
for(int i = 0; i<8; i++)
|
||||
(*newel)[i] = py::extract<PointIndex>(vertices[i])();
|
||||
(*newel)[i] = vertices[i];
|
||||
newel->SetIndex(index);
|
||||
}
|
||||
else
|
||||
@ -801,6 +801,20 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
|
||||
return self.Compress ();
|
||||
} ,py::call_guard<py::gil_scoped_release>())
|
||||
|
||||
.def ("AddRegion", [] (Mesh & self, string name, int dim) -> int
|
||||
{
|
||||
auto & regionnames = self.GetRegionNamesCD(self.GetDimension()-dim);
|
||||
regionnames.Append (new string(name));
|
||||
int idx = regionnames.Size();
|
||||
if (dim == 2)
|
||||
{
|
||||
FaceDescriptor fd;
|
||||
fd.SetBCName(regionnames.Last());
|
||||
fd.SetBCProperty(idx);
|
||||
self.AddFaceDescriptor(fd);
|
||||
}
|
||||
return idx;
|
||||
}, py::arg("name"), py::arg("dim"))
|
||||
|
||||
.def ("SetBCName", &Mesh::SetBCName)
|
||||
.def ("GetBCName", FunctionPointer([](Mesh & self, int bc)->string
|
||||
|
Loading…
Reference in New Issue
Block a user