Commit 588506b7 authored by 's avatar
Browse files

Merge branch 'feature/geo-reader' of gitlab.nektar.info:meshing/nektar into feature/geo-reader

Conflicts:
	CHANGELOG.md
	library/NekMeshUtils/CADSystem/OCE/CADSystemOCE.cpp
	utilities/NekMesh/CMakeLists.txt
parents 586ece6d f543f4fb
......@@ -3,6 +3,7 @@ Changelog
v4.5.0
------
**NekMesh**:
- Add periodic boundary condition meshing in 2D (!733)
......@@ -106,6 +107,7 @@ v4.4.0
(!712)
- 2D to 3D mesh extrusion module (!715)
- Add new two-dimensional mesher from NACA code or step file (!720)
- Add basic gmsh cad (.geo) reader to the meshing system (!731)
- Fix inverted boundary layer in 2D (!736)
- More sensible element sizing with boundary layers in 2D (!736)
- Change variable names in mcf file to make more sense (!736)
......
......@@ -64,7 +64,7 @@ namespace Nektar
{
SymbolFunctor symbolFunctor(&symbol);
ValueFunctor valueFunctor(&value);
return parse(str,
// Begin grammar
(
......@@ -93,7 +93,7 @@ namespace Nektar
space_p).full;
}
static bool GenerateOrderedVector(const char *const str, std::vector<unsigned int> &vec)
{
// Functors used to parse the sequence.
......@@ -114,7 +114,7 @@ namespace Nektar
{
// Functors used to parse the sequence.
fctor4 functor4(&vec);
return parse(str,
// Begin grammar
(
......@@ -124,12 +124,12 @@ namespace Nektar
// End grammar
space_p).full;
}
static bool GenerateUnOrderedVector(const char *const str, std::vector<NekDouble> &vec)
{
// Functors used to parse the sequence.
fctor5 functor5(&vec);
return parse(str,
// Begin grammar
(
......@@ -139,7 +139,22 @@ namespace Nektar
// End grammar
space_p).full;
}
static bool GenerateUnOrderedVector(const char *const str, std::vector<unsigned int> &vec)
{
// Functors used to parse the sequence.
fctor6 functor6(&vec);
return parse(str,
// Begin grammar
(
uint_p[functor6] >> *(',' >> uint_p[functor6])
)
,
// End grammar
space_p).full;
}
static bool GenerateOrderedStringVector(const char *const str, std::vector<std::string> &vec)
{
// Functors used to parse the sequence.
......@@ -226,7 +241,7 @@ namespace Nektar
m_value(value)
{
}
void operator()(NekDouble val) const
{
*m_value = val;
......@@ -245,7 +260,7 @@ namespace Nektar
void operator()(unsigned int n) const
{
#ifdef NOTREQUIRED //SJS: I do not think we need this check
#ifdef NOTREQUIRED //SJS: I do not think we need this check
if (!m_vector->empty())
{
unsigned int prevElem = m_vector->back();
......@@ -304,7 +319,7 @@ namespace Nektar
std::vector<std::string> *m_vector;
};
// Probably should template fctor1 if that is possible?
// Probably should template fctor1 if that is possible?
struct fctor4
{
fctor4(std::vector<NekDouble> *vec):
......@@ -333,24 +348,41 @@ namespace Nektar
std::vector<NekDouble> *m_vector;
fctor4();
};
struct fctor5
{
fctor5(std::vector<NekDouble> *vec):
m_vector(vec)
{
}
void operator()(NekDouble n) const
{
m_vector->push_back(n);
}
private:
std::vector<NekDouble> *m_vector;
fctor5();
};
struct fctor6
{
fctor6(std::vector<unsigned int> *vec):
m_vector(vec)
{
}
void operator()(unsigned int n) const
{
m_vector->push_back(n);
}
private:
std::vector<unsigned int> *m_vector;
fctor6();
};
};
}
......
......@@ -40,8 +40,8 @@
#include <NekMeshUtils/CADSystem/OCE/CADSystemOCE.h>
#include <NekMeshUtils/CADSystem/OCE/CADVertOCE.h>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem.hpp>
using namespace std;
......@@ -61,7 +61,7 @@ bool CADSystemOCE::LoadCAD()
//could be a geo
string ext = boost::filesystem::extension(m_name);
if(boost::iequals(ext,".geo"))
if (boost::iequals(ext, ".geo"))
{
shape = BuildGeo(m_name);
}
......@@ -409,57 +409,66 @@ TopoDS_Shape CADSystemOCE::BuildGeo(string geo)
ifstream f;
f.open(geo.c_str());
map<int,string> points;
map<int,string> lines;
map<int,string> splines;
map<int,string> loops;
map<int,string> surfs;
map<int, string> points;
map<int, string> lines;
map<int, string> splines;
map<int, string> loops;
map<int, string> surfs;
string fline;
while( !f.eof() )
while (!f.eof())
{
getline( f, fline );
getline(f, fline);
if (fline.size() == 0)
{
continue;
}
if(fline.size() == 0)
if (boost::starts_with(fline, "//"))
{
continue;
}
vector<string> tmp1, tmp2;
boost::split(tmp1,fline,boost::is_any_of("="));
boost::split(tmp1, fline, boost::is_any_of("="));
boost::split(tmp2,tmp1[0],boost::is_any_of("("));
boost::split(tmp2, tmp1[0], boost::is_any_of("("));
string type = tmp2[0];
boost::erase_all(tmp2[1],")");
boost::erase_all(tmp2[1]," ");
boost::erase_all(tmp2[1], ")");
boost::erase_all(tmp2[1], " ");
int id = boost::lexical_cast<int>(tmp2[1]);
boost::erase_all(tmp1[1]," ");
boost::erase_all(tmp1[1],"{");
boost::erase_all(tmp1[1],"}");
boost::erase_all(tmp1[1],";");
boost::erase_all(tmp1[1], " ");
boost::erase_all(tmp1[1], "{");
boost::erase_all(tmp1[1], "}");
boost::erase_all(tmp1[1], ";");
string var = tmp1[1];
if(boost::iequals(type,"Point"))
if (boost::iequals(type, "Point"))
{
points[id] = var;
}
else if(boost::iequals(type,"Line"))
else if (boost::iequals(type, "Line"))
{
lines[id] = var;
}
else if(boost::iequals(type,"Spline"))
else if (boost::iequals(type, "Spline"))
{
splines[id] = var;
}
else if(boost::iequals(type,"Line Loop"))
else if (boost::iequals(type, "Line Loop"))
{
//line loops sometimes have negative entries for gmsh
//orientaton purposes
//we dont care so remove it
boost::erase_all(var, "-");
loops[id] = var;
}
else if(boost::iequals(type,"Plane Surface"))
else if (boost::iequals(type, "Plane Surface"))
{
surfs[id] = var;
}
......@@ -469,37 +478,38 @@ TopoDS_Shape CADSystemOCE::BuildGeo(string geo)
}
}
map<int,string>::iterator it;
map<int, string>::iterator it;
//build points
map<int,gp_Pnt> cPoints;
for(it = points.begin(); it != points.end(); it++)
// build points
map<int, gp_Pnt> cPoints;
for (it = points.begin(); it != points.end(); it++)
{
vector<NekDouble> data;
ParseUtils::GenerateUnOrderedVector(it->second.c_str(), data);
cPoints[it->first] = gp_Pnt(data[0]*1000.0,data[1]*1000.0,data[2]*1000.0);
cPoints[it->first] =
gp_Pnt(data[0] * 1000.0, data[1] * 1000.0, data[2] * 1000.0);
}
//build edges
map<int,TopoDS_Edge> cEdges;
for(it = lines.begin(); it != lines.end(); it++)
// build edges
map<int, TopoDS_Edge> cEdges;
for (it = lines.begin(); it != lines.end(); it++)
{
vector<NekDouble> data;
vector<unsigned int> data;
ParseUtils::GenerateUnOrderedVector(it->second.c_str(), data);
BRepBuilderAPI_MakeEdge em(cPoints[(int)data[0]],cPoints[(int)data[1]]);
BRepBuilderAPI_MakeEdge em(cPoints[data[0]], cPoints[data[1]]);
cEdges[it->first] = em.Edge();
}
for(it = splines.begin(); it != splines.end(); it++)
for (it = splines.begin(); it != splines.end(); it++)
{
vector<NekDouble> data;
vector<unsigned int> data;
ParseUtils::GenerateUnOrderedVector(it->second.c_str(), data);
TColgp_Array1OfPnt pointArray(0,data.size()-1);
TColgp_Array1OfPnt pointArray(0, data.size() - 1);
for(int i = 0; i < data.size(); i++)
for (int i = 0; i < data.size(); i++)
{
pointArray.SetValue(i,cPoints[(int)data[i]]);
pointArray.SetValue(i, cPoints[data[i]]);
}
GeomAPI_PointsToBSpline spline(pointArray);
Handle(Geom_BSplineCurve) curve = spline.Curve();
......@@ -508,32 +518,34 @@ TopoDS_Shape CADSystemOCE::BuildGeo(string geo)
cEdges[it->first] = em.Edge();
}
//build wires
map<int,TopoDS_Wire> cWires;
for(it = loops.begin(); it != loops.end(); it++)
// build wires
map<int, TopoDS_Wire> cWires;
for (it = loops.begin(); it != loops.end(); it++)
{
vector<NekDouble> data;
vector<unsigned int> data;
ParseUtils::GenerateUnOrderedVector(it->second.c_str(), data);
BRepBuilderAPI_MakeWire wm;
for(int i = 0; i < data.size(); i++)
for (int i = 0; i < data.size(); i++)
{
wm.Add(cEdges[(int)data[i]]);
wm.Add(cEdges[data[i]]);
}
cWires[it->first] = wm.Wire();
}
//make surface, at this point assuming its 2D (therefore only 1)
//also going to assume that the first loop in the list is the outer domain
ASSERTL0(surfs.size() == 1,"more than 1 surf");
// make surface, at this point assuming its 2D (therefore only 1)
// also going to assume that the first loop in the list is the outer domain
ASSERTL0(surfs.size() == 1, "more than 1 surf");
it = surfs.begin();
vector<NekDouble> data;
vector<unsigned int> data;
ParseUtils::GenerateUnOrderedVector(it->second.c_str(), data);
BRepBuilderAPI_MakeFace face(cWires[(int)data[0]], true);
for(int i = 1; i < data.size(); i++)
BRepBuilderAPI_MakeFace face(cWires[data[0]], true);
for (int i = 1; i < data.size(); i++)
{
face.Add(cWires[(int)data[i]]);
face.Add(cWires[data[i]]);
}
ASSERTL0(face.Error() == BRepBuilderAPI_FaceDone, "build geo failed");
ShapeFix_Face sf(face.Face());
sf.FixOrientation();
......
......@@ -152,7 +152,6 @@ IF(NEKTAR_USE_MESHGEN)
ADD_NEKTAR_TEST (MeshGen/geo)
ADD_NEKTAR_TEST (MeshGen/t106step)
ADD_NEKTAR_TEST_LENGTHY (MeshGen/rev)
ENDIF()
# varopti tests
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment