From e28f387b9ee079042dcef4f0285a71f1b404134d Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 6 Nov 2013 17:50:57 +0100 Subject: [PATCH] + Create finer meshes with netgen by bisecting --- src/Mod/MeshPart/App/Mesher.cpp | 96 +++++++++++++++++++-------------- src/Mod/MeshPart/App/Mesher.h | 29 +++++----- 2 files changed, 73 insertions(+), 52 deletions(-) diff --git a/src/Mod/MeshPart/App/Mesher.cpp b/src/Mod/MeshPart/App/Mesher.cpp index 7b4be92c7ac0..0c5d713ce900 100644 --- a/src/Mod/MeshPart/App/Mesher.cpp +++ b/src/Mod/MeshPart/App/Mesher.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,6 @@ #include #include -#include #if defined(_MSC_VER) #include #include @@ -90,7 +90,7 @@ int MeshingOutput::sync() Mesher::Mesher(const TopoDS_Shape& s) : shape(s), maxLength(0), maxArea(0), localLength(0), - deflection(0), regular(false) + deflection(0), minLen(0), maxLen(0), regular(false) { } @@ -110,29 +110,12 @@ Mesh::MeshObject* Mesher::createMesh() const int hyp=0; #if defined(_MSC_VER) -#if 0 - NETGENPlugin_SimpleHypothesis_2D* hyp2d = new NETGENPlugin_SimpleHypothesis_2D(hyp++,0,meshgen); - // localLength overrides maxLength if both are set - if (maxLength > 0) { - hyp2d->SetLocalLength(maxLength); - } - - if (localLength > 0) { - hyp2d->SetLocalLength(localLength); - } - - if (maxArea > 0) { - hyp2d->SetMaxElementArea(maxArea); - } - - hyp2d->SetNumberOfSegments(1); - hypoth.push_back(hyp2d); -#else NETGENPlugin_Hypothesis_2D* hyp2d = new NETGENPlugin_Hypothesis_2D(hyp++,0,meshgen); - float growth = 0; + //TODO: Try to find values so that we get similar results as with Mefisto meshing + double growth = 0; if (maxLength > 0 && localLength > 0) { - growth = std::min(maxLength, localLength); + growth = std::min(maxLength, localLength); } else if (maxLength > 0) { growth = maxLength; @@ -154,11 +137,13 @@ Mesh::MeshObject* Mesher::createMesh() const else hyp2d->SetFineness(NETGENPlugin_Hypothesis_2D::VeryCoarse); - hyp2d->SetGrowthRate(growth); - hyp2d->SetQuadAllowed(true); + //hyp2d->SetGrowthRate(growth); + //hyp2d->SetNbSegPerEdge(5); + //hyp2d->SetNbSegPerRadius(10); + hyp2d->SetQuadAllowed(false); hyp2d->SetOptimize(true); + hyp2d->SetSecondOrder(true); // apply bisecting to create four triangles out of one hypoth.push_back(hyp2d); -#endif NETGENPlugin_NETGEN_2D* alg2d = new NETGENPlugin_NETGEN_2D(hyp++,0,meshgen); hypoth.push_back(alg2d); @@ -168,34 +153,35 @@ Mesh::MeshObject* Mesher::createMesh() const hyp1d->SetLength(maxLength); hypoth.push_back(hyp1d); } - - if (localLength > 0) { + else if (localLength > 0) { StdMeshers_LocalLength* hyp1d = new StdMeshers_LocalLength(hyp++,0,meshgen); hyp1d->SetLength(localLength); hypoth.push_back(hyp1d); } - - if (maxArea > 0) { + else if (maxArea > 0) { StdMeshers_MaxElementArea* hyp2d = new StdMeshers_MaxElementArea(hyp++,0,meshgen); - hyp2d->SetMaxArea(1.0f); + hyp2d->SetMaxArea(maxArea); hypoth.push_back(hyp2d); } - - { - StdMeshers_NumberOfSegments* hyp1d = new StdMeshers_NumberOfSegments(hyp++,0,meshgen); - hyp1d->SetNumberOfSegments(1); + else if (deflection > 0) { + StdMeshers_Deflection1D* hyp1d = new StdMeshers_Deflection1D(hyp++,0,meshgen); + hyp1d->SetDeflection(deflection); hypoth.push_back(hyp1d); } - - // if none of the above hypothesis were applied - if (hypoth.empty()) { + else if (minLen > 0 && maxLen > 0) { + StdMeshers_Arithmetic1D* hyp1d = new StdMeshers_Arithmetic1D(hyp++,0,meshgen); + hyp1d->SetLength(minLen, false); + hyp1d->SetLength(maxLen, true); + hypoth.push_back(hyp1d); + } + else { StdMeshers_AutomaticLength* hyp1d = new StdMeshers_AutomaticLength(hyp++,0,meshgen); hypoth.push_back(hyp1d); } - if (deflection > 0) { - StdMeshers_Deflection1D* hyp1d = new StdMeshers_Deflection1D(hyp++,0,meshgen); - hyp1d->SetDeflection(deflection); + { + StdMeshers_NumberOfSegments* hyp1d = new StdMeshers_NumberOfSegments(hyp++,0,meshgen); + hyp1d->SetNumberOfSegments(1); hypoth.push_back(hyp1d); } @@ -269,6 +255,36 @@ Mesh::MeshObject* Mesher::createMesh() const faces.push_back(f1); faces.push_back(f2); } + else if (aFace->NbNodes() == 6) { + MeshCore::MeshFacet f1, f2, f3, f4; + const SMDS_MeshNode* node0 = aFace->GetNode(0); + const SMDS_MeshNode* node1 = aFace->GetNode(1); + const SMDS_MeshNode* node2 = aFace->GetNode(2); + const SMDS_MeshNode* node3 = aFace->GetNode(3); + const SMDS_MeshNode* node4 = aFace->GetNode(4); + const SMDS_MeshNode* node5 = aFace->GetNode(5); + + f1._aulPoints[0] = mapNodeIndex[node0]; + f1._aulPoints[1] = mapNodeIndex[node3]; + f1._aulPoints[2] = mapNodeIndex[node5]; + + f2._aulPoints[0] = mapNodeIndex[node1]; + f2._aulPoints[1] = mapNodeIndex[node4]; + f2._aulPoints[2] = mapNodeIndex[node3]; + + f3._aulPoints[0] = mapNodeIndex[node2]; + f3._aulPoints[1] = mapNodeIndex[node5]; + f3._aulPoints[2] = mapNodeIndex[node4]; + + f4._aulPoints[0] = mapNodeIndex[node3]; + f4._aulPoints[1] = mapNodeIndex[node4]; + f4._aulPoints[2] = mapNodeIndex[node5]; + + faces.push_back(f1); + faces.push_back(f2); + faces.push_back(f3); + faces.push_back(f4); + } } // clean up diff --git a/src/Mod/MeshPart/App/Mesher.h b/src/Mod/MeshPart/App/Mesher.h index 7ab6b89bd135..5fad63b02047 100644 --- a/src/Mod/MeshPart/App/Mesher.h +++ b/src/Mod/MeshPart/App/Mesher.h @@ -37,22 +37,26 @@ class Mesher Mesher(const TopoDS_Shape&); ~Mesher(); - void setMaxLength(float s) + void setMaxLength(double s) { maxLength = s; } - float getMaxLength() const + double getMaxLength() const { return maxLength; } - void setMaxArea(float s) + void setMaxArea(double s) { maxArea = s; } - float getMaxArea() const + double getMaxArea() const { return maxArea; } - void setLocalLength(float s) + void setLocalLength(double s) { localLength = s; } - float getLocalLength() const + double getLocalLength() const { return localLength; } - void setDeflection(float s) + void setDeflection(double s) { deflection = s; } - float getDeflection() const + double getDeflection() const { return deflection; } + void setMinMaxLengths(double f, double l) + { minLen = f; maxLen = l; } + void getMinMaxLengths(double& f, double& l) const + { f = minLen; l= maxLen; } void setRegular(bool s) { regular = s; } bool isRegular() const @@ -62,10 +66,11 @@ class Mesher private: const TopoDS_Shape& shape; - float maxLength; - float maxArea; - float localLength; - float deflection; + double maxLength; + double maxArea; + double localLength; + double deflection; + double minLen, maxLen; bool regular; };