Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: extend nglib api #28

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions libsrc/core/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace ngcore
{
namespace detail
{
/*
// see https://github.com/RobotLocomotion/drake/blob/master/common/nice_type_name.cc
static const auto demangle_regexes =
std::array<std::pair<std::regex, std::string>, 8>{
Expand All @@ -39,10 +40,11 @@ namespace ngcore
{std::regex("\\bstd::basic_string<char,std::char_traits<char>,"
"std::allocator<char>>"), "std::string"}
};
*/
std::string CleanupDemangledName( std::string s )
{
for(const auto & [r, sub] : demangle_regexes)
s = std::regex_replace (s,r,sub);
//for(const auto & [r, sub] : demangle_regexes)
// s = std::regex_replace (s,r,sub);

return s;
}
Expand Down
2 changes: 1 addition & 1 deletion libsrc/core/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace ngcore
}

static bool dummy = [](){
SetLibraryVersion("netgen", NETGEN_VERSION);
SetLibraryVersion("netgen", VersionInfo(NETGEN_VERSION));
return true;
}();
} // namespace ngcore
12 changes: 8 additions & 4 deletions libsrc/core/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,41 @@ namespace ngcore
VersionInfo() = default;
VersionInfo(std::string vstring)
{
try {
minor_ = release = patch = 0;
git_hash = "";
if(vstring.substr(0,1) == "v")
vstring = vstring.substr(1,vstring.size()-1);
auto dot = vstring.find('.');
mayor_ = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
if(dot == std::string::npos) vstring = "";
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
if(!vstring.empty())
{
dot = vstring.find('.');
minor_ = std::stoi(vstring.substr(0,dot));
if (dot == size_t(-1)) vstring = "";
if (dot == std::string::npos) vstring = "";
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
if(!vstring.empty())
{
dot = vstring.find('-');
release = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
if(dot == std::string::npos) vstring = "";
else vstring = vstring.substr(dot+1,vstring.size()-dot-1);
if(!vstring.empty())
{
dot = vstring.find('-');
patch = std::stoi(vstring.substr(0,dot));
if(dot == size_t(-1)) vstring = "";
if(dot == std::string::npos) vstring = "";
else vstring = vstring.substr(dot+1, vstring.size()-dot-1);
if(!vstring.empty())
git_hash = vstring;
}
}
}
}
catch (const std::invalid_argument&)
{}
}
VersionInfo(const char* cstr) : VersionInfo(std::string(cstr)) { }

Expand Down
2 changes: 1 addition & 1 deletion libsrc/interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ target_sources(nglib PRIVATE
nginterface.cpp nginterface_v2.cpp
read_fnf_mesh.cpp readtetmesh.cpp readuser.cpp writeabaqus.cpp writediffpack.cpp
writedolfin.cpp writeelmer.cpp writefeap.cpp writefluent.cpp writegmsh.cpp writejcm.cpp
writepermas.cpp writetecplot.cpp writetet.cpp writetochnog.cpp writeuser.cpp
writepermas.cpp writetecplot.cpp writetet.cpp writetochnog.cpp writeuser.cpp writevtk.cpp
wuchemnitz.cpp writegmsh2.cpp writeOpenFOAM15x.cpp rw_cgns.cpp
)

Expand Down
6 changes: 5 additions & 1 deletion libsrc/interface/writeuser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ namespace netgen
"VRML Format", ".*",
"Gmsh Format", ".gmsh",
"Gmsh2 Format", ".gmsh2",
"VTK Format", ".vtk",
"OpenFOAM 1.5+ Format", "*",
"OpenFOAM 1.5+ Compressed", "*",
"OpenFOAM 1.5+ Compressed", "*",
"JCMwave Format", ".jcm",
"TET Format", ".tet",
"CGNS Format", ".cgns",
Expand Down Expand Up @@ -130,6 +131,9 @@ bool WriteUserFormat (const filesystem::path & format,
else if (format == "Gmsh2 Format")
WriteGmsh2Format (mesh, geom, filename);

else if (format == "VTK Format")
WriteVtkFormat (mesh, filename);

// Philippose - 25/10/2009
// Added OpenFOAM 1.5+ Mesh export capability
else if (format == "OpenFOAM 1.5+ Format")
Expand Down
3 changes: 3 additions & 0 deletions libsrc/interface/writeuser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ void WriteGmsh2Format (const Mesh & mesh,
const NetgenGeometry & geom,
const filesystem::path & filename);

extern
void WriteVtkFormat (const Mesh & mesh,
const string & filename);

// Philippose - 25/10/2009
// Added OpenFOAM 1.5+ Mesh Export support
Expand Down
136 changes: 136 additions & 0 deletions libsrc/interface/writevtk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*************************************
* Write Gmsh file
* First issue the 04/26/2004 by Paul CARRICO ([email protected])
* At the moment, the GMSH format is available for
* linear tetrahedron elements i.e. in 3D
* (based on Neutral Format)
*
* Second issue the 05/05/2004 by Paul CARRICO
* Thanks to Joachim Schoeberl for the correction of a minor bug
* the 2 initial Gmsh Format (i.e. volume format and surface format) are group together)
* in only one file
**************************************/

#include <mystdlib.h>

#include <myadt.hpp>
#include <linalg.hpp>
#include <csg.hpp>
#include <meshing.hpp>

namespace netgen
{
#include "writeuser.hpp"

extern MeshingParameters mparam;


/*
* VTK mesh format
* points, elements, surface elements
*/

void WriteVtkFormat (const Mesh & mesh,
const string & filename)
{
ofstream outfile (filename.c_str());
outfile.precision(6);
outfile.setf (ios::fixed, ios::floatfield);
outfile.setf (ios::showpoint);

int np = mesh.GetNP(); /// number of point
int ne = mesh.GetNE(); /// number of element
int nse = mesh.GetNSE(); /// number of surface element (BC)

outfile << "# vtk DataFile Version 2.0\n";
outfile << "Created with netgen\n";
outfile << "ASCII\n";
outfile << "DATASET UNSTRUCTURED_GRID\n";

outfile << "POINTS " << np << " double\n";
for (int i=0; i<np; i++)
{
auto & p = mesh.Point(i+1);
outfile << p[0] << " " << p[1] << " " << p[2] << "\n";
}

std::vector<int> types;
std::vector<int> domains;
if (ne > 0)
{
unsigned int size = 0;
for (int i=0; i<ne; i++)
size += mesh.VolumeElement(i+1).GetNV() + 1; // only save "linear" corners

outfile << "CELLS " << ne << " " << size << "\n";
for (int i=0; i<ne; i++)
{
auto& el = mesh.VolumeElement(i+1);
domains.push_back(el.GetIndex());
switch (el.GetType())
{
case TET:
case TET10: // reorder to follow VTK convention & zero based indices
outfile << 4 << " " << el[0]-1 << " " << el[1]-1 << " " << el[3]-1 << " " << el[2]-1 << "\n";
types.push_back(10);
break;
case PRISM: // reorder to follow VTK convention & zero based indices
outfile << 6 << " "
<< el[0]-1 << " " << el[2]-1 << " " << el[1]-1 << " "
<< el[3]-1 << " " << el[5]-1 << " " << el[4]-1 << "\n";
types.push_back(13);
break;
default:
throw ngcore::Exception("Unexpected element type");
break;
}
}
}
else
{
unsigned int size = 0;
for (int i=0; i<nse; i++)
size += mesh.SurfaceElement(i+1).GetNV() + 1;

outfile << "CELLS " << nse << " " << size << "\n";
for (int i=0; i<nse; i++)
{
auto& el = mesh.SurfaceElement(i+1);
domains.push_back(el.GetIndex());
switch (el.GetType())
{
case TRIG:
case TRIG6:
outfile << 3 << " " << el[0]-1 << " " << el[1]-1 << " " << el[2]-1 << "\n";
types.push_back(5);
break;
case QUAD:
outfile << 4 << " " << el[0]-1 << " " << el[1]-1 << " " << el[2]-1 << " " << el[3]-1 << "\n";
types.push_back(9);
break;
default:
throw ngcore::Exception("Unexpected element type");
break;
}
}
}

outfile << "CELL_TYPES " << types.size() << "\n";
for (auto type_id: types)
{
outfile << type_id << "\n";
}

outfile << "CELL_DATA " << domains.size() << "\n";
outfile << "SCALARS scalars int 1\n";
outfile << "LOOKUP_TABLE default\n";
for (auto id: domains)
{
outfile << id << "\n";
}

outfile.close();
}
}


Loading