* Added the capability of generating Quad dominated 2D Meshes in Nglib

* Added the capability of generating Second Order 2D / 3D Meshes in Nglib
* More Meshing Parameters now taken into account in Nglib
* Streamlined the process of transferring the locally defined meshing parameters to the internal meshing parameters structure using a single function called "Transfer_Parameters"
* Formatting changes to make the gaps between function definitions consistent
This commit is contained in:
Philippose Rajan 2010-09-14 21:24:15 +00:00
parent a249e8a42e
commit c412992519
2 changed files with 272 additions and 97 deletions

View File

@ -9,8 +9,6 @@
Interface to the netgen meshing kernel
*/
#include <mystdlib.h>
#include <myadt.hpp>
@ -76,6 +74,7 @@ namespace nglib
// Clean-up functions before ending usage of nglib
DLL_HEADER void Ng_Exit ()
{
@ -84,6 +83,7 @@ namespace nglib
// Create a new netgen mesh object
DLL_HEADER Ng_Mesh * Ng_NewMesh ()
{
@ -94,6 +94,7 @@ namespace nglib
// Delete an existing netgen mesh object
DLL_HEADER void Ng_DeleteMesh (Ng_Mesh * mesh)
{
@ -112,6 +113,7 @@ namespace nglib
// Save a netgen mesh in the native VOL format
DLL_HEADER void Ng_SaveMesh(Ng_Mesh * mesh, const char* filename)
{
@ -120,6 +122,7 @@ namespace nglib
// Load a netgen native VOL mesh from a given file
DLL_HEADER Ng_Mesh * Ng_LoadMesh(const char* filename)
{
@ -130,6 +133,7 @@ namespace nglib
// Manually add a point to an existing mesh object
DLL_HEADER void Ng_AddPoint (Ng_Mesh * mesh, double * x)
{
@ -139,6 +143,7 @@ namespace nglib
// Manually add a surface element of a given type to an existing mesh object
DLL_HEADER void Ng_AddSurfaceElement (Ng_Mesh * mesh, Ng_Surface_Element_Type et,
int * pi)
@ -154,6 +159,7 @@ namespace nglib
// Manually add a volume element of a given type to an existing mesh object
DLL_HEADER void Ng_AddVolumeElement (Ng_Mesh * mesh, Ng_Volume_Element_Type et,
int * pi)
@ -170,6 +176,7 @@ namespace nglib
// Obtain the number of points in the mesh
DLL_HEADER int Ng_GetNP (Ng_Mesh * mesh)
{
@ -178,6 +185,7 @@ namespace nglib
// Obtain the number of surface elements in the mesh
DLL_HEADER int Ng_GetNSE (Ng_Mesh * mesh)
{
@ -186,6 +194,7 @@ namespace nglib
// Obtain the number of volume elements in the mesh
DLL_HEADER int Ng_GetNE (Ng_Mesh * mesh)
{
@ -194,6 +203,7 @@ namespace nglib
// Return point coordinates of a given point index in the mesh
DLL_HEADER void Ng_GetPoint (Ng_Mesh * mesh, int num, double * x)
{
@ -205,6 +215,7 @@ namespace nglib
// Return the surface element at a given index "pi"
DLL_HEADER Ng_Surface_Element_Type
Ng_GetSurfaceElement (Ng_Mesh * mesh, int num, int * pi)
@ -226,6 +237,7 @@ namespace nglib
// Return the volume element at a given index "pi"
DLL_HEADER Ng_Volume_Element_Type
Ng_GetVolumeElement (Ng_Mesh * mesh, int num, int * pi)
@ -248,6 +260,7 @@ namespace nglib
// Set a global limit on the maximum mesh size allowed
DLL_HEADER void Ng_RestrictMeshSizeGlobal (Ng_Mesh * mesh, double h)
{
@ -256,6 +269,7 @@ namespace nglib
// Set a local limit on the maximum mesh size allowed around the given point
DLL_HEADER void Ng_RestrictMeshSizePoint (Ng_Mesh * mesh, double * p, double h)
{
@ -264,6 +278,7 @@ namespace nglib
// Set a local limit on the maximum mesh size allowed within a given box region
DLL_HEADER void Ng_RestrictMeshSizeBox (Ng_Mesh * mesh, double * pmin, double * pmax, double h)
{
@ -275,6 +290,7 @@ namespace nglib
// Generates volume mesh from an existing surface mesh
DLL_HEADER Ng_Result Ng_GenerateVolumeMesh (Ng_Mesh * mesh, Ng_Meshing_Parameters * mp)
{
@ -284,12 +300,7 @@ namespace nglib
// Do not locally re-define "mparam" here... "mparam" is a global
// object
//MeshingParameters mparam;
mparam.maxh = mp->maxh;
mparam.meshsizefilename = mp->meshsize_filename;
double fineness = min(1., max(0., mp->fineness));
mparam.curvaturesafety = 0.3 + 5 * fineness;
mparam.segmentsperedge = 0.3 + 5 * fineness;
mp->Transfer_Parameters();
m->CalcLocalH();
@ -302,10 +313,8 @@ namespace nglib
/* ------------------ 2D Meshing Functions ------------------------- */
DLL_HEADER void Ng_AddPoint_2D (Ng_Mesh * mesh, double * x)
{
Mesh * m = (Mesh*)mesh;
@ -313,6 +322,9 @@ namespace nglib
m->AddPoint (Point3d (x[0], x[1], 0));
}
DLL_HEADER void Ng_AddBoundarySeg_2D (Ng_Mesh * mesh, int pi1, int pi2)
{
Mesh * m = (Mesh*)mesh;
@ -324,24 +336,35 @@ namespace nglib
}
DLL_HEADER int Ng_GetNP_2D (Ng_Mesh * mesh)
{
Mesh * m = (Mesh*)mesh;
return m->GetNP();
}
DLL_HEADER int Ng_GetNE_2D (Ng_Mesh * mesh)
{
Mesh * m = (Mesh*)mesh;
return m->GetNSE();
}
DLL_HEADER int Ng_GetNSeg_2D (Ng_Mesh * mesh)
{
Mesh * m = (Mesh*)mesh;
return m->GetNSeg();
}
DLL_HEADER void Ng_GetPoint_2D (Ng_Mesh * mesh, int num, double * x)
{
Mesh * m = (Mesh*)mesh;
@ -351,6 +374,9 @@ namespace nglib
x[1] = p(1);
}
DLL_HEADER void Ng_GetElement_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum)
{
const Element2d & el = ((Mesh*)mesh)->SurfaceElement(num);
@ -361,6 +387,8 @@ namespace nglib
}
DLL_HEADER void Ng_GetSegment_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum)
{
const Segment & seg = ((Mesh*)mesh)->LineSegment(num);
@ -390,9 +418,7 @@ namespace nglib
{
// use global variable mparam
// MeshingParameters mparam;
mparam.maxh = mp->maxh;
mparam.meshsizefilename = mp->meshsize_filename;
mparam.quad = mp->quad_dominated;
mp->Transfer_Parameters();
Mesh * m;
MeshFromSpline2D (*(SplineGeometry2d*)geom, m, mparam);
@ -428,10 +454,6 @@ namespace nglib
Array<STLReadTriangle> readtrias; //only before initstlgeometry
Array<Point<3> > readedges; //only before init stlgeometry
@ -484,6 +506,7 @@ namespace nglib
// generate new STL Geometry
DLL_HEADER Ng_STL_Geometry * Ng_STL_NewGeometry ()
{
@ -492,6 +515,7 @@ namespace nglib
// after adding triangles (and edges) initialize
DLL_HEADER Ng_Result Ng_STL_InitSTLGeometry (Ng_STL_Geometry * geom)
{
@ -516,6 +540,7 @@ namespace nglib
// automatically generates edges:
DLL_HEADER Ng_Result Ng_STL_MakeEdges (Ng_STL_Geometry * geom,
Ng_Mesh* mesh,
@ -528,9 +553,7 @@ namespace nglib
// Do not locally re-define "mparam" here... "mparam" is a global
// object
//MeshingParameters mparam;
mparam.maxh = mp->maxh;
mparam.meshsizefilename = mp->meshsize_filename;
mp->Transfer_Parameters();
me -> SetGlobalH (mparam.maxh);
me -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10),
@ -558,6 +581,8 @@ namespace nglib
}
// generates mesh, empty mesh be already created.
DLL_HEADER Ng_Result Ng_STL_GenerateSurfaceMesh (Ng_STL_Geometry * geom,
Ng_Mesh* mesh,
@ -570,9 +595,8 @@ namespace nglib
// Do not locally re-define "mparam" here... "mparam" is a global
// object
//MeshingParameters mparam;
mp->Transfer_Parameters();
mparam.maxh = mp->maxh;
mparam.meshsizefilename = mp->meshsize_filename;
/*
me -> SetGlobalH (mparam.maxh);
@ -616,6 +640,8 @@ namespace nglib
}
// fills STL Geometry
// positive orientation
// normal vector may be null-pointer
@ -648,10 +674,8 @@ namespace nglib
#ifdef OCCGEOMETRY
// --------------------- OCC Geometry / Meshing Utility Functions -------------------
// Create new OCC Geometry Object
DLL_HEADER Ng_OCC_Geometry * Ng_OCC_NewGeometry ()
{
@ -660,6 +684,7 @@ namespace nglib
// Delete the OCC Geometry Object
DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry(Ng_OCC_Geometry * geom)
{
@ -675,6 +700,7 @@ namespace nglib
// Loads geometry from STEP File
DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename)
{
@ -687,6 +713,7 @@ namespace nglib
// Loads geometry from IGES File
DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename)
{
@ -699,6 +726,7 @@ namespace nglib
// Loads geometry from BREP File
DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename)
{
@ -711,6 +739,7 @@ namespace nglib
// Locally limit the size of the mesh to be generated at various points
// based on the topology of the geometry
DLL_HEADER Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom,
@ -722,16 +751,7 @@ namespace nglib
me->geomtype = Mesh::GEOM_OCC;
mparam.uselocalh = mp->uselocalh;
mparam.maxh = mp->maxh;
mparam.minh = mp->minh;
mparam.segmentsperedge = mp->elementsperedge;
mparam.curvaturesafety = mp->elementspercurve;
mparam.grading = mp->grading;
mparam.meshsizefilename = mp->meshsize_filename;
mp->Transfer_Parameters();
occparam.resthcloseedgeenable = mp->closeedgeenable;
occparam.resthcloseedgefac = mp->closeedgefact;
@ -747,6 +767,7 @@ namespace nglib
// Mesh the edges and add Face descriptors to prepare for surface meshing
DLL_HEADER Ng_Result Ng_OCC_GenerateEdgeMesh (Ng_OCC_Geometry * geom,
Ng_Mesh * mesh,
@ -755,7 +776,7 @@ namespace nglib
OCCGeometry * occgeom = (OCCGeometry*)geom;
Mesh * me = (Mesh*)mesh;
mparam.uselocalh = mp->uselocalh;
mp->Transfer_Parameters();
OCCFindEdges(*occgeom, *me);
@ -782,7 +803,10 @@ namespace nglib
OCCGeometry * occgeom = (OCCGeometry*)geom;
Mesh * me = (Mesh*)mesh;
mparam.uselocalh = mp->uselocalh;
// Set the internal meshing parameters structure from the nglib meshing
// parameters structure
mp->Transfer_Parameters();
// Only go into surface meshing if the face descriptors have already been added
if(!me->GetNFD())
@ -813,6 +837,8 @@ namespace nglib
}
// Extract the face map from the OCC geometry
// The face map basically gives an index to each face in the geometry,
// which can be used to access a specific face
@ -841,8 +867,8 @@ namespace nglib
// ------------------ Begin - Meshing Parameters related functions ------------------
// Constructor for the local nglib meshing parameters class
DLL_HEADER Ng_Meshing_Parameters :: Ng_Meshing_Parameters()
{
uselocalh = 1;
@ -859,7 +885,7 @@ namespace nglib
closeedgeenable = 0;
closeedgefact = 2.0;
secondorder = 0;
second_order = 0;
quad_dominated = 0;
meshsize_filename = 0;
@ -869,10 +895,18 @@ namespace nglib
optsteps_2d = 3;
optsteps_3d = 3;
invert_tets = 0;
invert_trigs = 0;
check_overlap = 1;
check_overlapping_boundary = 1;
}
// Reset the local meshing parameters to the default values
DLL_HEADER void Ng_Meshing_Parameters :: Reset_Parameters()
{
uselocalh = 1;
@ -889,7 +923,7 @@ namespace nglib
closeedgeenable = 0;
closeedgefact = 2.0;
secondorder = 0;
second_order = 0;
quad_dominated = 0;
meshsize_filename = 0;
@ -899,37 +933,125 @@ namespace nglib
optsteps_2d = 3;
optsteps_3d = 3;
invert_tets = 0;
invert_trigs = 0;
check_overlap = 1;
check_overlapping_boundary = 1;
}
//
DLL_HEADER void Ng_Meshing_Parameters :: Transfer_Parameters()
{
mparam.uselocalh = uselocalh;
mparam.maxh = maxh;
mparam.minh = minh;
mparam.grading = grading;
mparam.curvaturesafety = elementspercurve;
mparam.segmentsperedge = elementsperedge;
mparam.secondorder = second_order;
mparam.quad = quad_dominated;
mparam.meshsizefilename = meshsize_filename;
mparam.optsteps2d = optsteps_2d;
mparam.optsteps3d = optsteps_3d;
mparam.inverttets = invert_tets;
mparam.inverttrigs = invert_trigs;
mparam.checkoverlap = check_overlap;
mparam.checkoverlappingboundary = check_overlapping_boundary;
}
// ------------------ End - Meshing Parameters related functions --------------------
// ------------------ Begin - Second Order Mesh generation functions ----------------
DLL_HEADER void Ng_Generate_SecondOrder(Ng_Mesh * mesh)
{
Refinement ref;
ref.MakeSecondOrder(*(Mesh*) mesh);
}
DLL_HEADER void Ng_2D_Generate_SecondOrder(Ng_Geometry_2D * geom,
Ng_Mesh * mesh)
{
( (SplineGeometry2d*)geom ) -> GetRefinement().MakeSecondOrder( * (Mesh*) mesh );
}
DLL_HEADER void Ng_STL_Generate_SecondOrder(Ng_STL_Geometry * geom,
Ng_Mesh * mesh)
{
((STLGeometry*)geom)->GetRefinement().MakeSecondOrder(*(Mesh*) mesh);
}
DLL_HEADER void Ng_CSG_Generate_SecondOrder (Ng_CSG_Geometry * geom,
Ng_Mesh * mesh)
{
((CSGeometry*)geom)->GetRefinement().MakeSecondOrder(*(Mesh*) mesh);
}
#ifdef OCCGEOMETRY
DLL_HEADER void Ng_OCC_Generate_SecondOrder (Ng_OCC_Geometry * geom,
Ng_Mesh * mesh)
{
((OCCGeometry*)geom )->GetRefinement().MakeSecondOrder(*(Mesh*) mesh);
}
#endif
// ------------------ End - Second Order Mesh generation functions ------------------
// ------------------ Begin - Uniform Mesh Refinement functions ---------------------
DLL_HEADER void Ng_Uniform_Refinement (Ng_Mesh * mesh)
{
Refinement ref;
ref.Refine ( * (Mesh*) mesh );
}
DLL_HEADER void Ng_2D_Uniform_Refinement (Ng_Geometry_2D * geom,
Ng_Mesh * mesh)
{
( (SplineGeometry2d*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
}
DLL_HEADER void Ng_STL_Uniform_Refinement (Ng_STL_Geometry * geom,
Ng_Mesh * mesh)
{
( (STLGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
}
DLL_HEADER void Ng_CSG_Uniform_Refinement (Ng_CSG_Geometry * geom,
Ng_Mesh * mesh)
{
@ -937,6 +1059,8 @@ namespace nglib
}
#ifdef OCCGEOMETRY
DLL_HEADER void Ng_OCC_Uniform_Refinement (Ng_OCC_Geometry * geom,
Ng_Mesh * mesh)
@ -944,23 +1068,15 @@ namespace nglib
( (OCCGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
}
#endif
// ------------------ End - Uniform Mesh Refinement functions -----------------------
} // End of namespace nglib
// compatibility functions:
namespace netgen
{
char geomfilename[255];
DLL_HEADER void MyError (const char * ch)
@ -968,31 +1084,45 @@ namespace netgen
cerr << ch;
}
//Destination for messages, errors, ...
DLL_HEADER void Ng_PrintDest(const char * s)
{
(*mycout) << s << flush;
}
DLL_HEADER double GetTime ()
{
return 0;
}
void ResetTime ()
{
;
}
void MyBeep (int i)
{
;
}
void Render()
{
;
}
} // End of namespace netgen

View File

@ -104,9 +104,9 @@ public:
double elementspercurve; //!< Elements to generate per curvature radius
int closeedgeenable; //!< Enable / Disable mesh refinement at close edges
double closeedgefact; //!< Factor to use for refinement at close edges (STL: larger => finer ; OCC: larger => coarser)
double closeedgefact; //!< Factor to use for refinement at close edges (larger => finer)
int secondorder; //!< Generate second-order surface and volume elements
int second_order; //!< Generate second-order surface and volume elements
int quad_dominated; //!< Creates a Quad-dominated mesh
char * meshsize_filename; //!< Optional external mesh size file
@ -117,6 +117,15 @@ public:
int optsteps_3d; //!< Number of optimize steps to use for 3-D mesh optimization
int optsteps_2d; //!< Number of optimize steps to use for 2-D mesh optimization
// Philippose - 13/09/2010
// Added a couple more parameters into the meshing parameters list
// from Netgen into Nglib
int invert_tets; //!< Invert all the volume elements
int invert_trigs; //!< Invert all the surface triangle elements
int check_overlap; //!< Check for overlapping surfaces during Surface meshing
int check_overlapping_boundary; //!< Check for overlapping surface elements before volume meshing
/*!
Default constructor for the Mesh Parameters class
@ -131,13 +140,17 @@ public:
- #elementspercurve: 2.0
- #closeedgeenable: 0
- #closeedgefact: 2.0
- #secondorder: 0.0
- #secondorder: 0
- #meshsize_filename: null
- #quad_dominated: 0
- #optsurfmeshenable: 1
- #optvolmeshenable: 1
- #optsteps_2d: 3
- #optsteps_3d: 3
- #invert_tets: 0
- #invert_trigs:0
- #check_overlap: 1
- #check_overlapping_boundary: 1
*/
DLL_HEADER Ng_Meshing_Parameters();
@ -150,6 +163,17 @@ public:
of the object to the default values
*/
DLL_HEADER void Reset_Parameters();
/*!
Transfer local meshing parameters to internal meshing parameters
This member function transfers all the meshing parameters
defined in the local meshing parameters structure of nglib into
the internal meshing parameters structure used by the Netgen core
*/
DLL_HEADER void Transfer_Parameters();
};
@ -636,14 +660,10 @@ DLL_HEADER Ng_Result Ng_OCC_GetFMap(Ng_OCC_Geometry * geom,
// **********************************************************
// ** Mesh refinement algorithms **
// **********************************************************
// uniform mesh refinement
DLL_HEADER void Ng_Uniform_Refinement (Ng_Mesh * mesh);
@ -666,4 +686,29 @@ DLL_HEADER void Ng_OCC_Uniform_Refinement (Ng_OCC_Geometry * geom,
// **********************************************************
// ** Second Order mesh algorithms **
// **********************************************************
// convert mesh to second order
DLL_HEADER void Ng_Generate_SecondOrder (Ng_Mesh * mesh);
// convert mesh to second order with geometry adaption:
DLL_HEADER void Ng_2D_Generate_SecondOrder (Ng_Geometry_2D * geom,
Ng_Mesh * mesh);
DLL_HEADER void Ng_STL_Generate_SecondOrder (Ng_STL_Geometry * geom,
Ng_Mesh * mesh);
DLL_HEADER void Ng_CSG_Generate_SecondOrder (Ng_CSG_Geometry * geom,
Ng_Mesh * mesh);
#ifdef OCCGEOMETRY
DLL_HEADER void Ng_OCC_Generate_SecondOrder (Ng_OCC_Geometry * geom,
Ng_Mesh * mesh);
#endif
#endif // NGLIB