Merge remote-tracking branch 'origin/master' into boundarylayer_fixes

This commit is contained in:
Matthias Hochsteger 2024-03-07 12:10:37 +01:00
commit 8d05e3a213
14 changed files with 60 additions and 69 deletions

View File

@ -87,12 +87,15 @@ set(NG_INSTALL_SUFFIX netgen CACHE STRING "Suffix appended to install directorie
if(USE_PYTHON) if(USE_PYTHON)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18) if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18)
find_package(Python3 REQUIRED COMPONENTS Development.Module) find_package(Python3 REQUIRED COMPONENTS Development.Module)
find_package(Python3 COMPONENTS Interpreter Development.Embed) if(NOT EMSCRIPTEN)
find_package(Python3 COMPONENTS Interpreter Development.Embed)
endif()
else() else()
find_package(Python3 REQUIRED COMPONENTS Interpreter Development) find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
endif() endif()
if(NOT CMAKE_CROSSCOMPILING) if(NOT CMAKE_CROSSCOMPILING)
find_package(Python3 REQUIRED COMPONENTS Interpreter)
execute_process(COMMAND ${Python3_EXECUTABLE} -c "import os.path, sysconfig;print(os.path.relpath(sysconfig.get_path('platlib'), sysconfig.get_path('data')))" OUTPUT_VARIABLE PYTHON_PACKAGES_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${Python3_EXECUTABLE} -c "import os.path, sysconfig;print(os.path.relpath(sysconfig.get_path('platlib'), sysconfig.get_path('data')))" OUTPUT_VARIABLE PYTHON_PACKAGES_INSTALL_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
file(TO_CMAKE_PATH ${PYTHON_PACKAGES_INSTALL_DIR} PYTHON_PACKAGES_INSTALL_DIR) file(TO_CMAKE_PATH ${PYTHON_PACKAGES_INSTALL_DIR} PYTHON_PACKAGES_INSTALL_DIR)
endif(NOT CMAKE_CROSSCOMPILING) endif(NOT CMAKE_CROSSCOMPILING)

View File

@ -184,7 +184,9 @@ if (USE_PYTHON)
endif( PYBIND_INCLUDE_DIR ) endif( PYBIND_INCLUDE_DIR )
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18) if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.18)
find_package(Python3 COMPONENTS Interpreter Development.Module) find_package(Python3 COMPONENTS Interpreter Development.Module)
find_package(Python3 COMPONENTS Interpreter Development.Embed) if(NOT EMSCRIPTEN)
find_package(Python3 COMPONENTS Interpreter Development.Embed)
endif()
else() else()
find_package(Python3 REQUIRED COMPONENTS Interpreter Development) find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
endif() endif()

View File

@ -22,7 +22,7 @@ namespace netgen
ArrayMem<int, 1> points; ArrayMem<int, 1> points;
tree.GetIntersecting(p, p, points); tree.GetIntersecting(p, p, points);
if(points.Size()==0) if(points.Size()==0)
throw Exception("cannot find mapped point"); throw Exception("cannot find mapped point " + ToString(p));
return points[0]; return points[0];
} }
@ -313,23 +313,14 @@ namespace netgen
{ {
bool need_inverse = ident.from == s.get(); bool need_inverse = ident.from == s.get();
auto other = need_inverse ? ident.to : ident.from; auto other = need_inverse ? ident.to : ident.from;
if(other->nr <= s->primary->nr) if(other->primary->nr < s->primary->nr)
{
auto trafo = ident.trafo;
if(need_inverse)
trafo = trafo.CalcInverse();
s->primary = other;
s->primary_to_me.Combine(trafo, s->primary_to_me);
changed = other->nr != s->primary->nr;
}
if(other->primary->nr <= s->primary->nr)
{ {
auto trafo = ident.trafo; auto trafo = ident.trafo;
if(need_inverse) if(need_inverse)
trafo = trafo.CalcInverse(); trafo = trafo.CalcInverse();
s->primary = other->primary; s->primary = other->primary;
s->primary_to_me.Combine(trafo, other->primary_to_me); s->primary_to_me.Combine(trafo, other->primary_to_me);
changed = other->primary->nr != s->primary->nr; changed = true;
} }
} }
} }
@ -568,12 +559,13 @@ namespace netgen
auto & identifications = mesh.GetIdentifications(); auto & identifications = mesh.GetIdentifications();
std::map<size_t, PointIndex> vert2meshpt; Array<PointIndex> vert2meshpt(vertices.Size());
vert2meshpt = PointIndex::INVALID;
for(auto & vert : vertices) for(auto & vert : vertices)
{ {
auto pi = mesh.AddPoint(vert->GetPoint(), vert->properties.layer); auto pi = mesh.AddPoint(vert->GetPoint(), vert->properties.layer);
tree.Insert(mesh[pi], pi); tree.Insert(mesh[pi], pi);
vert2meshpt[vert->GetHash()] = pi; vert2meshpt[vert->nr] = pi;
mesh[pi].Singularity(vert->properties.hpref); mesh[pi].Singularity(vert->properties.hpref);
mesh[pi].SetType(FIXEDPOINT); mesh[pi].SetType(FIXEDPOINT);
@ -585,8 +577,8 @@ namespace netgen
for(auto & vert : vertices) for(auto & vert : vertices)
for(auto & ident : vert->identifications) for(auto & ident : vert->identifications)
identifications.Add(vert2meshpt[ident.from->GetHash()], identifications.Add(vert2meshpt[ident.from->nr],
vert2meshpt[ident.to->GetHash()], vert2meshpt[ident.to->nr],
ident.name, ident.name,
ident.type); ident.type);
@ -600,8 +592,8 @@ namespace netgen
auto edge = edges[edgenr].get(); auto edge = edges[edgenr].get();
PointIndex startp, endp; PointIndex startp, endp;
// throws if points are not found // throws if points are not found
startp = vert2meshpt.at(edge->GetStartVertex().GetHash()); startp = vert2meshpt[edge->GetStartVertex().nr];
endp = vert2meshpt.at(edge->GetEndVertex().GetHash()); endp = vert2meshpt[edge->GetEndVertex().nr];
// ignore collapsed edges // ignore collapsed edges
if(startp == endp && edge->GetLength() < 1e-10 * bounding_box.Diam()) if(startp == endp && edge->GetLength() < 1e-10 * bounding_box.Diam())
@ -944,11 +936,12 @@ namespace netgen
} }
bool have_identifications = false; bool have_identifications = false;
std::map<tuple<PointIndex, int>, PointIndex> mapto;
for(auto & face : faces) for(auto & face : faces)
if(face->primary != face.get()) if(face->primary != face.get())
{ {
have_identifications = true; have_identifications = true;
MapSurfaceMesh(mesh, *face); MapSurfaceMesh(mesh, *face, mapto);
} }
// identify points on faces // identify points on faces
@ -992,7 +985,8 @@ namespace netgen
if(ident.from == face.get()) if(ident.from == face.get())
for(auto pi : pi_of_face[face->nr]) for(auto pi : pi_of_face[face->nr])
{ {
auto pi_other = tree.Find(ident.trafo(mesh[pi])); auto pi_primary = ident.from->primary->nr == ident.from->nr ? pi : mapto[{pi, ident.to->primary->nr}];
auto pi_other = ident.to->primary->nr == ident.to->nr ? pi_primary : mapto[{pi_primary, ident.to->nr}];
mesh_ident.Add(pi, pi_other, ident.name, ident.type); mesh_ident.Add(pi, pi_other, ident.name, ident.type);
} }
} }
@ -1002,7 +996,7 @@ namespace netgen
multithread.task = savetask; multithread.task = savetask;
} }
void NetgenGeometry :: MapSurfaceMesh( Mesh & mesh, const GeometryFace & dst ) const void NetgenGeometry :: MapSurfaceMesh( Mesh & mesh, const GeometryFace & dst, std::map<tuple<PointIndex, int>, PointIndex> & mapto ) const
{ {
static Timer timer("MapSurfaceMesh"); static Timer timer("MapSurfaceMesh");
RegionTimer rt(timer); RegionTimer rt(timer);
@ -1083,6 +1077,8 @@ namespace netgen
pmap[pi] = mesh.AddPoint(trafo(mesh[pi]), 1, SURFACEPOINT); pmap[pi] = mesh.AddPoint(trafo(mesh[pi]), 1, SURFACEPOINT);
} }
sel_new[i] = pmap[pi]; sel_new[i] = pmap[pi];
mapto[{pi, dst.nr}] = pmap[pi];
mapto[{pmap[pi], src.nr}] = pi;
} }
if(do_invert.IsTrue()) if(do_invert.IsTrue())
sel_new.Invert(); sel_new.Invert();

View File

@ -68,7 +68,6 @@ namespace netgen
Transformation<3> primary_to_me; Transformation<3> primary_to_me;
virtual ~GeometryShape() {} virtual ~GeometryShape() {}
virtual size_t GetHash() const = 0;
virtual bool IsMappedShape( const GeometryShape & other, const Transformation<3> & trafo, double tolerance ) const; virtual bool IsMappedShape( const GeometryShape & other, const Transformation<3> & trafo, double tolerance ) const;
}; };
@ -243,7 +242,7 @@ namespace netgen
virtual void MeshSurface(Mesh& mesh, const MeshingParameters& mparam) const; virtual void MeshSurface(Mesh& mesh, const MeshingParameters& mparam) const;
virtual bool MeshFace(Mesh& mesh, const MeshingParameters& mparam, virtual bool MeshFace(Mesh& mesh, const MeshingParameters& mparam,
int nr, FlatArray<int, PointIndex> glob2loc) const; int nr, FlatArray<int, PointIndex> glob2loc) const;
virtual void MapSurfaceMesh( Mesh & mesh, const GeometryFace & dst ) const; virtual void MapSurfaceMesh( Mesh & mesh, const GeometryFace & dst, std::map<tuple<PointIndex, int>, PointIndex> & mapto) const;
virtual void OptimizeSurface(Mesh& mesh, const MeshingParameters& mparam) const; virtual void OptimizeSurface(Mesh& mesh, const MeshingParameters& mparam) const;
virtual void FinalizeMesh(Mesh& mesh) const; virtual void FinalizeMesh(Mesh& mesh) const;
@ -320,13 +319,6 @@ namespace netgen
throw Exception("Base geometry get tangent called"); throw Exception("Base geometry get tangent called");
} }
virtual size_t GetEdgeIndex(const GeometryEdge& edge) const
{
for(auto i : Range(edges))
if(edge.GetHash() == edges[i]->GetHash())
return i;
throw Exception("Couldn't find edge index");
}
virtual void Save (const filesystem::path & filename) const; virtual void Save (const filesystem::path & filename) const;
virtual void SaveToMeshFile (ostream & /* ost */) const { ; } virtual void SaveToMeshFile (ostream & /* ost */) const { ; }
}; };

View File

@ -12,8 +12,8 @@ extern double CalcTotalBad (const Mesh::T_POINTS & points,
/// ///
class MeshOptimize3d class MeshOptimize3d
{ {
const MeshingParameters & mp;
Mesh & mesh; Mesh & mesh;
const MeshingParameters & mp;
OPTIMIZEGOAL goal = OPT_QUALITY; OPTIMIZEGOAL goal = OPT_QUALITY;
double min_badness = 0; double min_badness = 0;

View File

@ -53,11 +53,6 @@ namespace netgen
throw Exception(ToString("not implemented") + __FILE__ + ":" + ToString(__LINE__)); throw Exception(ToString("not implemented") + __FILE__ + ":" + ToString(__LINE__));
} }
size_t OCCEdge::GetHash() const
{
return edge.HashCode(std::numeric_limits<Standard_Integer>::max());
}
void OCCEdge::ProjectPoint(Point<3>& p, EdgePointGeomInfo* gi) const void OCCEdge::ProjectPoint(Point<3>& p, EdgePointGeomInfo* gi) const
{ {
auto pnt = ng2occ(p); auto pnt = ng2occ(p);

View File

@ -36,7 +36,6 @@ namespace netgen
Point<3> GetCenter() const override; Point<3> GetCenter() const override;
Point<3> GetPoint(double t) const override; Point<3> GetPoint(double t) const override;
double CalcStep(double t, double sag) const override; double CalcStep(double t, double sag) const override;
size_t GetHash() const override;
void ProjectPoint(Point<3>& p, EdgePointGeomInfo* gi) const override; void ProjectPoint(Point<3>& p, EdgePointGeomInfo* gi) const override;
Vec<3> GetTangent(double t) const override; Vec<3> GetTangent(double t) const override;
bool IsDegenerated(double) const override { bool IsDegenerated(double) const override {

View File

@ -30,11 +30,6 @@ namespace netgen
return 0; return 0;
} }
size_t OCCFace::GetHash() const
{
return face.HashCode(std::numeric_limits<Standard_Integer>::max());
}
Point<3> OCCFace::GetCenter() const Point<3> OCCFace::GetCenter() const
{ {
return occ2ng( props.CentreOfMass() ); return occ2ng( props.CentreOfMass() );

View File

@ -31,7 +31,6 @@ namespace netgen
const TopoDS_Face Shape() const { return face; } const TopoDS_Face Shape() const { return face; }
size_t GetHash() const override;
Point<3> GetCenter() const override; Point<3> GetCenter() const override;
virtual size_t GetNBoundaries() const override; virtual size_t GetNBoundaries() const override;
virtual Array<Segment> GetBoundary(const Mesh& mesh) const override; virtual Array<Segment> GetBoundary(const Mesh& mesh) const override;

View File

@ -16,8 +16,6 @@ namespace netgen
OCCSolid(TopoDS_Shape dshape) OCCSolid(TopoDS_Shape dshape)
: solid(TopoDS::Solid(dshape)) : solid(TopoDS::Solid(dshape))
{ } { }
size_t GetHash() const override { return solid.HashCode(std::numeric_limits<Standard_Integer>::max()); }
}; };
} }

View File

@ -16,9 +16,4 @@ namespace netgen
{ {
return p; return p;
} }
size_t OCCVertex::GetHash() const
{
return vertex.HashCode(std::numeric_limits<Standard_Integer>::max());
}
} }

View File

@ -24,7 +24,6 @@ namespace netgen
OCCVertex( TopoDS_Shape s ); OCCVertex( TopoDS_Shape s );
~OCCVertex() {} ~OCCVertex() {}
Point<3> GetPoint() const override; Point<3> GetPoint() const override;
size_t GetHash() const override;
}; };
} }

View File

@ -1710,13 +1710,6 @@ namespace netgen
BRepTools::Read(shape, ss, builder); BRepTools::Read(shape, ss, builder);
} }
/*
// enumerate shapes and archive only integers
auto my_hash = [](const TopoDS_Shape & key) {
auto occ_hash = key.HashCode(1<<31UL);
return std::hash<decltype(occ_hash)>()(occ_hash);
};
*/
TopTools_IndexedMapOfShape shape_map; TopTools_IndexedMapOfShape shape_map;
Array<TopoDS_Shape> shape_list; Array<TopoDS_Shape> shape_list;
@ -1784,7 +1777,7 @@ namespace netgen
"Face", "Wire", "Edge", "Vertex"}; "Face", "Wire", "Edge", "Vertex"};
const char * orientationstring[] = const char * orientationstring[] =
{"+", "-"}; {"+", "-", "i", "e"};
@ -1843,6 +1836,16 @@ namespace netgen
} }
str << "{" << shapename[l] << " " << count2; str << "{" << shapename[l] << " " << count2;
if(HaveProperties(e.Current()))
{
const auto& props = GetProperties(e.Current());
if(props.name || props.maxh < 1e99)
str << " - ";
if(props.name)
str << props.GetName();
if(props.maxh < 1e99)
str << " maxh(" << props.maxh << ")";
}
if (l <= TopAbs_EDGE) if (l <= TopAbs_EDGE)
{ {
@ -2338,21 +2341,25 @@ namespace netgen
for(auto & ident : identifications) for(auto & ident : identifications)
{ {
const auto& to = STEPConstruct::FindEntity(finder, ident.from == shape ? ident.to : ident.from);
if(to.IsNull())
continue;
Array<Handle(StepRepr_RepresentationItem)> items; Array<Handle(StepRepr_RepresentationItem)> items;
// items.Append(STEPConstruct::FindEntity(finder, ident.other)); // TODO! items.Append(MakeReal(ident.from == shape ? 1 : 0));
items.Append(to);
auto & m = ident.trafo.GetMatrix(); auto & m = ident.trafo.GetMatrix();
for(auto i : Range(9)) for(auto i : Range(9))
items.Append(MakeReal(m(i))); items.Append(MakeReal(m(i)));
auto & v = ident.trafo.GetVector(); auto & v = ident.trafo.GetVector();
for(auto i : Range(3)) for(auto i : Range(3))
items.Append(MakeReal(v(i))); items.Append(MakeReal(v(i)));
for(auto & item : items.Range(1,items.Size())) items.Append(MakeInt(ident.type));
for(auto & item : items.Range(0, items.Size()))
model->AddEntity(item); model->AddEntity(item);
ident_items.Append(MakeCompound(items, ident.name)); ident_items.Append(MakeCompound(items, ident.name));
} }
for(auto & item : ident_items.Range(1, ident_items.Size()))
for(auto & item : ident_items.Range(1,ident_items.Size())) model->AddEntity(item);
model->AddEntity(item);
auto comp = MakeCompound(ident_items, "netgen_geometry_identification"); auto comp = MakeCompound(ident_items, "netgen_geometry_identification");
model->AddEntity(comp); model->AddEntity(comp);
} }
@ -2369,7 +2376,18 @@ namespace netgen
auto id_item = Handle(StepRepr_CompoundRepresentationItem)::DownCast(idents->ItemElementValue(i)); auto id_item = Handle(StepRepr_CompoundRepresentationItem)::DownCast(idents->ItemElementValue(i));
OCCIdentification ident; OCCIdentification ident;
ident.name = id_item->Name()->ToCString(); ident.name = id_item->Name()->ToCString();
// ident.other = TransferBRep::ShapeResult(transProc->Find(id_item->ItemElementValue(1))); /TODO! auto is_from = ReadReal(id_item->ItemElementValue(1));
if(is_from)
{
ident.from = shape_origin;
ident.to = TransferBRep::ShapeResult(transProc->Find(id_item->ItemElementValue(2)));
}
else
{
ident.from = TransferBRep::ShapeResult(
transProc->Find(id_item->ItemElementValue(2)));
ident.to = shape_origin;
}
auto & m = ident.trafo.GetMatrix(); auto & m = ident.trafo.GetMatrix();
for(auto i : Range(9)) for(auto i : Range(9))
@ -2377,7 +2395,7 @@ namespace netgen
auto & v = ident.trafo.GetVector(); auto & v = ident.trafo.GetVector();
for(auto i : Range(3)) for(auto i : Range(3))
v(i) = ReadReal(id_item->ItemElementValue(12+i)); v(i) = ReadReal(id_item->ItemElementValue(12+i));
ident.type = Identifications::ID_TYPE(ReadInt(id_item->ItemElementValue(15)));
result.push_back(ident); result.push_back(ident);
} }
OCCGeometry::GetIdentifications(shape_origin) = result; OCCGeometry::GetIdentifications(shape_origin) = result;

View File

@ -41,6 +41,7 @@ if sys.platform.startswith('win'):
del sys del sys
del os del os
from pyngcore import Timer
from . import libngpy from . import libngpy
from netgen.libngpy._meshing import _Redraw from netgen.libngpy._meshing import _Redraw
@ -48,7 +49,6 @@ from netgen.libngpy._meshing import _Redraw
def Redraw(*args, **kwargs): def Redraw(*args, **kwargs):
return _Redraw(*args, **kwargs) return _Redraw(*args, **kwargs)
from pyngcore import Timer
def TimeFunction(func, name=None): def TimeFunction(func, name=None):
name = name or func.__qualname__ name = name or func.__qualname__
timer = Timer(name) timer = Timer(name)