Skip to content

WIP: extend nglib api #28

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

Closed
wants to merge 21 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build
*.vol
*.ini
__pycache__
*.json
*.zip
.cache
*.patch
.vscode/
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ option( USE_GEOM2D "build 2d geometry kernels" ON)
option( USE_JPEG "enable snapshots using library libjpeg" OFF )
option( USE_MPEG "enable video recording with FFmpeg, uses libavcodec" OFF )
option( USE_CGNS "enable CGNS file read/write support" OFF )
option( USE_NUMA "compile with NUMA-aware code")
option( INTEL_MIC "cross compile for intel xeon phi")
option( USE_NUMA "compile with NUMA-aware code" OFF)
option( INTEL_MIC "cross compile for intel xeon phi" OFF)
option( INSTALL_PROFILES "install environment variable settings to /etc/profile.d" OFF )
option( USE_CCACHE "use ccache")
option( USE_CCACHE "use ccache" OFF)
option( USE_INTERNAL_TCL "Compile tcl files into the code and don't install them" ON)
option( ENABLE_UNIT_TESTS "Enable Catch unit tests")
option( ENABLE_UNIT_TESTS "Enable Catch unit tests" OFF)
option( ENABLE_CPP_CORE_GUIDELINES_CHECK "Enable cpp core guideline checks on ngcore" OFF)
option( DEBUG_LOG "Enable more debug output (may increase computation time) - only works with USE_SPDLOG=ON" OFF)
option( CHECK_RANGE "Check array range access, automatically enabled if built in debug mode" OFF)
Expand Down
2 changes: 1 addition & 1 deletion libsrc/core/bitarray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class BitArray

bool operator[] (IndexType i) const { return Test(i); }
T_Range<IndexType> Range() const { return { IndexBASE<IndexType>(), IndexBASE<IndexType>()+Size() }; }
NGCORE_API TBitArray & Or (const TBitArray & ba2)
inline TBitArray & Or (const TBitArray & ba2)
{
BitArray::Or(ba2);
return *this;
Expand Down
6 changes: 4 additions & 2 deletions libsrc/core/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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 @@ -48,10 +49,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);
#ifdef EMSCRIPTEN
// for some reason regex_replace is not working at all
std::string temp = 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
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