Merge branch 'use_filesystem_path' into 'master'

use std::filesystem::path

See merge request jschoeberl/netgen!480
This commit is contained in:
Joachim Schöberl 2022-02-23 13:34:23 +00:00
commit afa018049b
50 changed files with 360 additions and 544 deletions

View File

@ -5,6 +5,7 @@
#include <array> // for array
#include <complex> // for complex
#include <cstring> // for size_t, strlen
#include <filesystem> // for path
#include <fstream> // for ifstream, ofstream
#include <functional> // for function
#include <map> // for map
@ -740,7 +741,7 @@ namespace ngcore
BinaryOutArchive(std::shared_ptr<std::ostream>&& astream)
: Archive(true), stream(std::move(astream))
{ }
BinaryOutArchive(const std::string& filename)
BinaryOutArchive(const std::filesystem::path& filename)
: BinaryOutArchive(std::make_shared<std::ofstream>(filename)) {}
~BinaryOutArchive () override { FlushBuffer(); }
@ -828,7 +829,7 @@ namespace ngcore
BinaryInArchive (std::shared_ptr<std::istream>&& astream)
: Archive(false), stream(std::move(astream))
{ }
BinaryInArchive (const std::string& filename)
BinaryInArchive (const std::filesystem::path& filename)
: BinaryInArchive(std::make_shared<std::ifstream>(filename)) { ; }
using Archive::operator&;
@ -903,7 +904,7 @@ namespace ngcore
TextOutArchive (std::shared_ptr<std::ostream>&& astream)
: Archive(true), stream(std::move(astream))
{ }
TextOutArchive (const std::string& filename) :
TextOutArchive (const std::filesystem::path& filename) :
TextOutArchive(std::make_shared<std::ofstream>(filename)) { }
using Archive::operator&;
@ -958,7 +959,7 @@ namespace ngcore
TextInArchive (std::shared_ptr<std::istream>&& astream) :
Archive(false), stream(std::move(astream))
{ }
TextInArchive (const std::string& filename)
TextInArchive (const std::filesystem::path& filename)
: TextInArchive(std::make_shared<std::ifstream>(filename)) {}
using Archive::operator&;

View File

@ -6,6 +6,7 @@
#include <pybind11/operators.h>
#include <pybind11/numpy.h>
#include <pybind11/stl.h>
#include <pybind11/stl/filesystem.h>
#include "array.hpp"
#include "table.hpp"

View File

@ -112,13 +112,12 @@ namespace ngcore
#endif
}
NGCORE_API std::string GetTempFilename()
NGCORE_API std::filesystem::path GetTempFilename()
{
static int counter = 0;
auto path = std::filesystem::temp_directory_path();
std::string filename = ".temp_netgen_file_"+ToString(counter++)+"_"+ToString(GetTimeCounter());
path.append(filename);
return path.string();
path += ".temp_netgen_file_"+ToString(counter++)+"_"+ToString(GetTimeCounter());
return path;
}
} // namespace ngcore

View File

@ -3,6 +3,7 @@
#include <atomic>
#include <chrono>
#include <filesystem>
#include <map>
#include <ostream>
#include <sstream>
@ -81,6 +82,22 @@ namespace ngcore
return ss.str();
}
inline std::string ToLower( const std::string & s )
{
std::string res;
res.reserve(s.size());
for(auto & c : res)
res.push_back(tolower(c));
return res;
}
inline std::string ToLower( const std::filesystem::path & p )
{
return ToLower(p.string());
}
template<typename T1, typename T2>
std::ostream& operator << (std::ostream& ost, const std::map<T1,T2>& map)
{
@ -201,7 +218,7 @@ namespace ngcore
NGCORE_API int GetCompiledSIMDSize();
NGCORE_API bool IsRangeCheckEnabled();
NGCORE_API std::string GetTempFilename();
NGCORE_API std::filesystem::path GetTempFilename();
} // namespace ngcore

View File

@ -264,7 +264,7 @@ namespace netgen
}
void CSGeometry :: Save (string filename) const
void CSGeometry :: Save (const filesystem::path & filename) const
{
ofstream ost (filename.c_str());
Save (ost);
@ -1619,21 +1619,21 @@ namespace netgen
class CSGeometryRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const;
virtual NetgenGeometry * Load (const filesystem::path & filename) const;
virtual NetgenGeometry * LoadFromMeshFile (istream & ist, string token) const;
// virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const;
};
extern CSGeometry * ParseCSG (istream & istr, CSGeometry *instance=nullptr);
NetgenGeometry * CSGeometryRegister :: Load (string filename) const
NetgenGeometry * CSGeometryRegister :: Load (const filesystem::path & filename) const
{
const char * cfilename = filename.c_str();
if (strcmp (&cfilename[strlen(cfilename)-3], "geo") == 0)
string extension = filename.extension().string();
if (extension == ".geo")
{
PrintMessage (1, "Load CSG geometry file ", cfilename);
PrintMessage (1, "Load CSG geometry file ", filename);
ifstream infile(cfilename);
ifstream infile(filename);
CSGeometry * hgeom = ParseCSG (infile);
if (!hgeom)
@ -1643,19 +1643,17 @@ namespace netgen
return hgeom;
}
if (strcmp (&cfilename[strlen(cfilename)-3], "ngg") == 0)
if (extension == ".ngg")
{
PrintMessage (1, "Load new CSG geometry file ", cfilename);
PrintMessage (1, "Load new CSG geometry file ", filename);
ifstream infile(cfilename);
ifstream infile(filename);
CSGeometry * hgeom = new CSGeometry("");
hgeom -> Load (infile);
return hgeom;
}
return NULL;
}

View File

@ -182,7 +182,7 @@ namespace netgen
void Clean ();
virtual void Save (string filename) const override;
virtual void Save (const filesystem::path & filename) const override;
void Save (ostream & ost) const;
void Load (istream & ist);

View File

@ -547,86 +547,10 @@ namespace netgen
}
/*
class CSGeometryRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const;
virtual NetgenGeometry * LoadFromMeshFile (istream & ist) const;
virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const;
};
extern CSGeometry * ParseCSG (istream & istr);
NetgenGeometry * CSGeometryRegister :: Load (string filename) const
{
const char * cfilename = filename.c_str();
if (strcmp (&cfilename[strlen(cfilename)-3], "geo") == 0)
{
PrintMessage (1, "Load CSG geometry file ", cfilename);
ifstream infile(cfilename);
CSGeometry * hgeom = ParseCSG (infile);
if (!hgeom)
throw NgException ("geo-file should start with 'algebraic3d'");
hgeom -> FindIdenticSurfaces(1e-8 * hgeom->MaxSize());
return hgeom;
}
if (strcmp (&cfilename[strlen(cfilename)-3], "ngg") == 0)
{
PrintMessage (1, "Load new CSG geometry file ", cfilename);
ifstream infile(cfilename);
CSGeometry * hgeom = new CSGeometry("");
hgeom -> Load (infile);
return hgeom;
}
return NULL;
}
NetgenGeometry * CSGeometryRegister :: LoadFromMeshFile (istream & ist) const
{
string auxstring;
if (ist.good())
{
ist >> auxstring;
if (auxstring == "csgsurfaces")
{
CSGeometry * geometry = new CSGeometry ("");
geometry -> LoadSurfaces(ist);
return geometry;
}
// else
// ist.putback (auxstring);
}
return NULL;
}
VisualScene * CSGeometryRegister :: GetVisualScene (const NetgenGeometry * geom) const
{
CSGeometry * geometry = dynamic_cast<CSGeometry*> (ng_geometry.get());
if (geometry)
{
vsgeom.SetGeometry (geometry);
return &vsgeom;
}
return NULL;
}
*/
class CSGeometryVisRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const { return NULL; }
virtual NetgenGeometry * Load (const filesystem::path & filename) const { return NULL; }
virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const;
};

View File

@ -44,7 +44,7 @@ namespace GZSTREAM_NAMESPACE {
// class gzstreambuf:
// --------------------------------------
gzstreambuf* gzstreambuf::open( const char* name, int open_mode) {
gzstreambuf* gzstreambuf::open( const filesystem::path & name, int open_mode) {
if ( is_open())
return (gzstreambuf*)0;
mode = open_mode;
@ -60,7 +60,11 @@ gzstreambuf* gzstreambuf::open( const char* name, int open_mode) {
*fmodeptr++ = 'w';
*fmodeptr++ = 'b';
*fmodeptr = '\0';
file = gzopen( name, fmode);
#ifdef WIN32
file = gzopen_w( name.c_str(), fmode);
#else // WIN32
file = gzopen( name.c_str(), fmode);
#endif // WIN32
if (file == 0)
return (gzstreambuf*)0;
opened = 1;
@ -139,17 +143,17 @@ int gzstreambuf::sync() {
// class gzstreambase:
// --------------------------------------
gzstreambase::gzstreambase( const char* name, int mode) {
gzstreambase::gzstreambase( const filesystem::path & name, int mode) {
init( &buf);
open( name, mode);
open( name.c_str(), mode);
}
gzstreambase::~gzstreambase() {
buf.close();
}
void gzstreambase::open( const char* name, int open_mode) {
if ( ! buf.open( name, open_mode))
void gzstreambase::open( const filesystem::path & name, int open_mode) {
if ( ! buf.open( name.c_str(), open_mode))
clear( rdstate() | std::ios::badbit);
}

View File

@ -62,7 +62,7 @@ public:
// ASSERT: both input & output capabilities will not be used together
}
int is_open() { return opened; }
gzstreambuf* open( const char* name, int open_mode);
gzstreambuf* open( const filesystem::path & name, int open_mode);
gzstreambuf* close();
~gzstreambuf() { close(); }
@ -76,9 +76,9 @@ protected:
gzstreambuf buf;
public:
gzstreambase() { init(&buf); }
DLL_HEADER gzstreambase( const char* name, int open_mode);
DLL_HEADER gzstreambase( const filesystem::path & name, int open_mode);
DLL_HEADER ~gzstreambase();
void open( const char* name, int open_mode);
void open( const filesystem::path & name, int open_mode);
void close();
gzstreambuf* rdbuf() { return &buf; }
};
@ -92,10 +92,10 @@ public:
class DLL_HEADER igzstream : public gzstreambase, public std::istream {
public:
igzstream() : std::istream( &buf) {}
igzstream( const char* name, int open_mode = std::ios::in)
igzstream( const filesystem::path & name, int open_mode = std::ios::in)
: gzstreambase( name, open_mode), std::istream( &buf) {}
gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
void open( const char* name, int open_mode = std::ios::in) {
void open( const filesystem::path & name, int open_mode = std::ios::in) {
gzstreambase::open( name, open_mode);
}
};
@ -103,10 +103,10 @@ public:
class DLL_HEADER ogzstream : public gzstreambase, public std::ostream {
public:
ogzstream() : std::ostream( &buf) {}
ogzstream( const char* name, int mode = std::ios::out)
ogzstream( const filesystem::path & name, int mode = std::ios::out)
: gzstreambase( name, mode), std::ostream( &buf) {}
gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); }
void open( const char* name, int open_mode = std::ios::out) {
void open( const filesystem::path & name, int open_mode = std::ios::out) {
gzstreambase::open( name, open_mode);
}
};

View File

@ -223,6 +223,10 @@ MyStr::MyStr(const string & st)
strcpy (str, st.c_str());
}
MyStr::MyStr(const filesystem::path & path)
: MyStr(path.string())
{ }
MyStr MyStr::Left(unsigned r)

View File

@ -19,6 +19,8 @@
#ifndef MYSTRING__H
#define MYSTRING__H
#include <filesystem>
namespace netgen
{
@ -58,6 +60,7 @@ public:
MyStr(const Point3d& p);
MyStr(const Vec3d& p);
MyStr(const string & st);
MyStr(const filesystem::path & st);
~MyStr();
MyStr Left(unsigned);

View File

@ -21,7 +21,7 @@ namespace netgen
class SplineGeometryVisRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const { return NULL; }
virtual NetgenGeometry * Load (const filesystem::path & filename) const { return NULL; }
virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const;
};

View File

@ -92,7 +92,7 @@ namespace netgen
return Vec<3> (0,0,1);
}
void SplineGeometry2d :: Load (const char * filename)
void SplineGeometry2d :: Load (const filesystem::path & filename)
{
ifstream infile;
@ -104,7 +104,7 @@ namespace netgen
if ( ! infile.good() )
throw NgException(string ("Input file '") +
string (filename) +
filename.string() +
string ("' not available!"));
TestComment ( infile );
@ -1075,21 +1075,20 @@ namespace netgen
class SplineGeometryRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const;
virtual NetgenGeometry * Load (const filesystem::path & filename) const;
};
NetgenGeometry * SplineGeometryRegister :: Load (string filename) const
NetgenGeometry * SplineGeometryRegister :: Load (const filesystem::path & filename) const
{
const char * cfilename = filename.c_str();
if (strcmp (&cfilename[strlen(cfilename)-4], "in2d") == 0)
string ext = ToLower(filename.extension());
if (ext == ".in2d")
{
PrintMessage (1, "Load 2D-Spline geometry file ", cfilename);
PrintMessage (1, "Load 2D-Spline geometry file ", filename);
ifstream infile(cfilename);
ifstream infile(filename);
SplineGeometry2d * hgeom = new SplineGeometry2d();
hgeom -> Load (cfilename);
hgeom -> Load (filename);
return hgeom;
}

View File

@ -143,7 +143,7 @@ namespace netgen
public:
DLL_HEADER virtual ~SplineGeometry2d();
DLL_HEADER void Load (const char * filename);
DLL_HEADER void Load (const filesystem::path & filename);
DLL_HEADER void LoadData( ifstream & infile );
DLL_HEADER void LoadDataNew ( ifstream & infile );

View File

@ -60,9 +60,9 @@ namespace netgen
void ReadFNFFormat (Mesh & mesh,
const string & filename)
const filesystem::path & filename)
{
ifstream fin (filename.c_str());
ifstream fin (filename);
string buf;

View File

@ -20,10 +20,8 @@ namespace netgen
void ReadTETFormat (Mesh & mesh,
const string & hfilename)
const filesystem::path & filename)
{
const char * filename = hfilename.c_str();
cout << "Reading .tet mesh" << endl;
ifstream in (filename);

View File

@ -15,22 +15,18 @@
namespace netgen
{
void ReadFile (Mesh & mesh,
const string & hfilename)
const filesystem::path & filename)
{
PrintMessage(3, "Read User File");
const char * filename = hfilename.c_str();
auto ext = filename.extension();
char reco[100];
int np, nbe;
// ".surf" - mesh
if ( (strlen (filename) > 5) &&
strcmp (&filename[strlen (filename)-5], ".surf") == 0 )
if ( ext == ".surf" )
{
cout << "Surface file" << endl;
@ -80,11 +76,7 @@ namespace netgen
}
if ( (strlen (filename) > 4) &&
strcmp (&filename[strlen (filename)-4], ".unv") == 0 )
if ( ext == ".unv" )
{
char reco[100];
// int invert;
@ -407,8 +399,7 @@ namespace netgen
// fepp format2d:
if ( (strlen (filename) > 7) &&
strcmp (&filename[strlen (filename)-7], ".mesh2d") == 0 )
if ( ext == ".mesh2d" )
{
cout << "Reading FEPP2D Mesh" << endl;
@ -449,8 +440,7 @@ namespace netgen
}
else if ( (strlen (filename) > 5) &&
strcmp (&filename[strlen (filename)-5], ".mesh") == 0 )
else if ( ext == ".mesh" )
{
cout << "Reading Neutral Format" << endl;
@ -522,21 +512,17 @@ namespace netgen
}
if ( (strlen (filename) > 4) &&
strcmp (&filename[strlen (filename)-4], ".emt") == 0 )
if ( ext == ".emt" )
{
ifstream inemt (filename);
string pktfile = filename;
int len = strlen (filename);
pktfile[len-3] = 'p';
pktfile[len-2] = 'k';
pktfile[len-1] = 't';
auto pktfile = filename;
pktfile.replace_extension("pkt");
cout << "pktfile = " << pktfile << endl;
int np, nse, i;
int bcprop;
ifstream inpkt (pktfile.c_str());
ifstream inpkt (pktfile);
inpkt >> np;
NgArray<double> values(np);
for (i = 1; i <= np; i++)
@ -629,31 +615,20 @@ namespace netgen
// .tet mesh
if ( (strlen (filename) > 4) &&
strcmp (&filename[strlen (filename)-4], ".tet") == 0 )
{
if ( ext == ".tet" )
ReadTETFormat (mesh, filename);
}
// .fnf mesh (FNF - PE neutral format)
if ( (strlen (filename) > 4) &&
strcmp (&filename[strlen (filename)-4], ".fnf") == 0 )
{
if ( ext == ".fnf" )
ReadFNFFormat (mesh, filename);
}
// .cgns file - CFD General Notation System
if ( (strlen (filename) > 5) &&
strcmp (&filename[strlen (filename)-5], ".cgns") == 0 )
{
if ( ext == ".cgns" )
ReadCGNSMesh (mesh, filename);
}
if ( ( (strlen (filename) > 4) && strcmp (&filename[strlen (filename)-4], ".stl") == 0 ) ||
( (strlen (filename) > 5) && strcmp (&filename[strlen (filename)-5], ".stlb") == 0 ) )
if ( ext == ".stl" || ext == ".stlb" )
{
ifstream ist{string{filename}};
ifstream ist{filename};
auto geom = shared_ptr<STLGeometry>(STLGeometry::Load(ist));
mesh.SetDimension (3);

View File

@ -629,12 +629,12 @@ namespace netgen::cg
namespace netgen
{
int ReadCGNSMesh (Mesh & mesh, const string & filename, Array<unique_ptr<cg::Zone>> & zones)
int ReadCGNSMesh (Mesh & mesh, const filesystem::path & filename, Array<unique_ptr<cg::Zone>> & zones)
{
mesh.SetDimension(3);
static Timer tall("CGNS::ReadMesh"); RegionTimer rtall(tall);
int fn;
cg_open(filename.c_str(),CG_MODE_READ,&fn);
cg_open(filename.string().c_str(),CG_MODE_READ,&fn);
int base = 1;
int nzones;
@ -698,7 +698,7 @@ namespace netgen
return fn;
}
void ReadCGNSMesh (Mesh & mesh, const string & filename)
void ReadCGNSMesh (Mesh & mesh, const filesystem::path & filename)
{
Array<unique_ptr<cg::Zone>> zones;
int fn = ReadCGNSMesh(mesh, filename, zones);
@ -706,7 +706,7 @@ namespace netgen
}
// Reads mesh and solutions of .csns file
tuple<shared_ptr<Mesh>, vector<string>, vector<Array<double>>, vector<int>> ReadCGNSFile(string filename, int base)
tuple<shared_ptr<Mesh>, vector<string>, vector<Array<double>>, vector<int>> ReadCGNSFile(const filesystem::path & filename, int base)
{
static Timer tall("CGNS::ReadFile"); RegionTimer rtall(tall);
@ -775,11 +775,11 @@ namespace netgen
}
void WriteCGNSMesh (const Mesh & mesh, const string & filename)
void WriteCGNSMesh (const Mesh & mesh, const filesystem::path & filename)
{
static Timer tall("CGNS::WriteMesh"); RegionTimer rtall(tall);
int fn, base, zone;
cg_open(filename.c_str(),CG_MODE_WRITE,&fn);
cg_open(filename.string().c_str(),CG_MODE_WRITE,&fn);
WriteCGNSMesh(mesh, fn, base, zone);
@ -787,11 +787,11 @@ namespace netgen
}
void WriteCGNSFile(shared_ptr<Mesh> mesh, string filename, vector<string> fields, vector<Array<double>> values, vector<int> locations)
void WriteCGNSFile(shared_ptr<Mesh> mesh, const filesystem::path & filename, vector<string> fields, vector<Array<double>> values, vector<int> locations)
{
static Timer tall("CGNS::WriteFile"); RegionTimer rtall(tall);
int fn, base, zone;
cg_open(filename.c_str(),CG_MODE_WRITE,&fn);
cg_open(filename.string().c_str(),CG_MODE_WRITE,&fn);
WriteCGNSMesh(*mesh, fn, base, zone);
@ -814,22 +814,22 @@ namespace netgen
namespace netgen
{
void ReadCGNSMesh (Mesh & mesh, const string & filename)
void ReadCGNSMesh (Mesh & mesh, const filesystem::path & filename)
{
PrintMessage(1, "Could not import CGNS mesh: Netgen was built without CGNS support");
}
tuple<shared_ptr<Mesh>, vector<string>, vector<Array<double>>, vector<int>> ReadCGNSFile(string filename, int base)
tuple<shared_ptr<Mesh>, vector<string>, vector<Array<double>>, vector<int>> ReadCGNSFile(const filesystem::path & filename, int base)
{
throw Exception("Netgen was built without CGNS support");
}
void WriteCGNSMesh (const Mesh & mesh, const string & filename)
void WriteCGNSMesh (const Mesh & mesh, const filesystem::path & filename)
{
PrintMessage(1, "Could not write CGNS mesh: Netgen was built without CGNS support");
}
void WriteCGNSFile(shared_ptr<Mesh> mesh, string filename, vector<string> fields, vector<Array<double>> values, vector<int> locations)
void WriteCGNSFile(shared_ptr<Mesh> mesh, const filesystem::path & filename, vector<string> fields, vector<Array<double>> values, vector<int> locations)
{
throw Exception("Netgen was built without CGNS support");
}

View File

@ -597,7 +597,7 @@ namespace netgen
void WriteOpenFOAM15xFormat (const Mesh & mesh, const string & casename, const bool compressed)
void WriteOpenFOAM15xFormat (const Mesh & mesh, const filesystem::path & dirname, const bool compressed)
{
bool error = false;
char casefiles[256];
@ -639,22 +639,12 @@ namespace netgen
}
cout << "Writing OpenFOAM 1.5+ Mesh files to case: " << casename << "\n";
cout << "Writing OpenFOAM 1.5+ Mesh files to case: " << dirname.string() << "\n";
// Create the case directory if it does not already exist
// NOTE: This needs to be improved for the Linux variant....!!!
#ifdef WIN32
char casedir[256];
sprintf(casedir, "mkdir %s\\constant\\polyMesh", casename.c_str());
system(casedir);
#else
char casedir[256];
mkdir(casename.c_str(), S_IRWXU|S_IRWXG);
sprintf(casedir, "%s/constant", casename.c_str());
mkdir(casedir, S_IRWXU|S_IRWXG);
sprintf(casedir, "%s/constant/polyMesh", casename.c_str());
mkdir(casedir, S_IRWXU|S_IRWXG);
#endif
auto mesh_dir = filesystem::path(dirname).append("constant").append("polyMesh");
filesystem::create_directories(mesh_dir);
// Open handles to the five required mesh files
// points
@ -662,59 +652,21 @@ namespace netgen
// owner
// neighbour
// boundary
ostream *outfile_pnts;
ostream *outfile_faces;
ostream *outfile_own;
ostream *outfile_nei;
ostream *outfile_bnd;
if(compressed)
{
sprintf(casefiles, "%s/constant/polyMesh/points.gz", casename.c_str());
outfile_pnts = new ogzstream(casefiles);
}
else
{
sprintf(casefiles, "%s/constant/polyMesh/points", casename.c_str());
outfile_pnts = new ofstream(casefiles);
}
auto get_name = [compressed, &mesh_dir]( string s ) {
auto p = filesystem::path(mesh_dir).append(s);
if(compressed)
p.concat(".gz");
return p;
};
if(compressed)
{
sprintf(casefiles, "%s/constant/polyMesh/faces.gz", casename.c_str());
outfile_faces = new ogzstream(casefiles);
}
else
{
sprintf(casefiles, "%s/constant/polyMesh/faces", casename.c_str());
outfile_faces = new ofstream(casefiles);
}
auto outfile_pnts = make_unique<ofstream>(get_name("points"));
auto outfile_faces = make_unique<ofstream>(get_name("faces"));
auto outfile_own = make_unique<ofstream>(get_name("owner"));
auto outfile_nei = make_unique<ofstream>(get_name("neighbor"));
if(compressed)
{
sprintf(casefiles, "%s/constant/polyMesh/owner.gz", casename.c_str());
outfile_own = new ogzstream(casefiles);
}
else
{
sprintf(casefiles, "%s/constant/polyMesh/owner", casename.c_str());
outfile_own = new ofstream(casefiles);
}
if(compressed)
{
sprintf(casefiles, "%s/constant/polyMesh/neighbour.gz", casename.c_str());
outfile_nei = new ogzstream(casefiles);
}
else
{
sprintf(casefiles, "%s/constant/polyMesh/neighbour", casename.c_str());
outfile_nei = new ofstream(casefiles);
}
// Note... the boundary file is not compressed
sprintf(casefiles, "%s/constant/polyMesh/boundary", casename.c_str());
outfile_bnd = new ofstream(casefiles);
// Note... the boundary file is not compressed
auto outfile_bnd = make_unique<ofstream>(mesh_dir.append("boundary"));
ResetTime();
@ -731,8 +683,7 @@ namespace netgen
if(outfile_own->good() && !error)
{
cout << "Writing the owner file: ";
WriteOwnerFile(outfile_own);
delete outfile_own;
WriteOwnerFile(outfile_own.get());
cout << "Done! (Time Elapsed = " << GetTime() << " sec)\n";
}
else
@ -746,8 +697,7 @@ namespace netgen
if(outfile_nei->good() && !error)
{
cout << "Writing the neighbour file: ";
WriteNeighbourFile(outfile_nei);
delete outfile_nei;
WriteNeighbourFile(outfile_nei.get());
cout << "Done! (Time Elapsed = " << GetTime() << " sec)\n";
}
else
@ -761,8 +711,7 @@ namespace netgen
if(outfile_faces->good() && !error)
{
cout << "Writing the faces file: ";
WriteFacesFile(outfile_faces, mesh);
delete outfile_faces;
WriteFacesFile(outfile_faces.get(), mesh);
cout << "Done! (Time Elapsed = " << GetTime() << " sec)\n";
}
else
@ -776,8 +725,7 @@ namespace netgen
if(outfile_pnts->good() && !error)
{
cout << "Writing the points file: ";
WritePointsFile(outfile_pnts,mesh);
delete outfile_pnts;
WritePointsFile(outfile_pnts.get(),mesh);
cout << "Done! (Time Elapsed = " << GetTime() << " sec)\n";
}
else
@ -791,8 +739,7 @@ namespace netgen
if(outfile_bnd->good() && !error)
{
cout << "Writing the boundary file: ";
WriteBoundaryFile(outfile_bnd);
delete outfile_bnd;
WriteBoundaryFile(outfile_bnd.get());
cout << "Done! (Time Elapsed = " << GetTime() << " sec)\n";
}
else

View File

@ -18,13 +18,13 @@ namespace netgen
void WriteAbaqusFormat (const Mesh & mesh,
const string & filename)
const filesystem::path & filename)
{
cout << "\nWrite Abaqus Volume Mesh" << endl;
ofstream outfile (filename.c_str());
ofstream outfile (filename);
outfile << "*Heading" << endl;
outfile << " " << filename << endl;
@ -124,16 +124,11 @@ void WriteAbaqusFormat (const Mesh & mesh,
// periodic identification, implementation for
// Helmut J. Boehm, TU Vienna
char cfilename[255];
strcpy (cfilename, filename.c_str());
char mpcfilename[255];
strcpy (mpcfilename, cfilename);
size_t len = strlen (cfilename);
if (len >= 4 && (strcmp (mpcfilename+len-4, ".inp") == 0))
strcpy (mpcfilename+len-4, ".mpc");
auto mpcfilename = filename;
if (filename.extension() == ".inp")
mpcfilename.replace_extension(".mpc");
else
strcat (mpcfilename, ".mpc");
mpcfilename.concat(".mpc");
ofstream mpc (mpcfilename);

View File

@ -21,12 +21,12 @@ namespace netgen
void WriteDiffPackFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename)
const filesystem::path & filename)
{
// double scale = globflags.GetNumFlag ("scale", 1);
double scale = 1;
ofstream outfile(filename.c_str());
ofstream outfile(filename);
outfile.precision(14);

View File

@ -19,7 +19,7 @@ namespace netgen
void WriteDolfinFormat (const Mesh & mesh, const string & filename)
void WriteDolfinFormat (const Mesh & mesh, const filesystem::path & filename)
{
cout << "start writing dolfin export" << endl;
@ -30,7 +30,7 @@ namespace netgen
// int invertsurf = mparam.inverttrigs;
// int i, j;
ofstream outfile (filename.c_str());
ofstream outfile (filename);
// char str[100];
outfile.precision(8);

View File

@ -21,7 +21,7 @@ namespace netgen
void WriteElmerFormat (const Mesh &mesh,
const string &filename)
const filesystem::path &dirname)
{
cout << "write elmer mesh files" << endl;
@ -62,25 +62,17 @@ void WriteElmerFormat (const Mesh &mesh,
int inverttets = mparam.inverttets;
int invertsurf = mparam.inverttrigs;
#ifdef WIN32
char a[256];
sprintf( a, "mkdir %s", filename.c_str() );
system( a );
#else
// int rc =
mkdir(filename.c_str(), S_IRWXU|S_IRWXG);
#endif
filesystem::create_directories(dirname);
sprintf( str, "%s/mesh.header", filename.c_str() );
ofstream outfile_h(str);
sprintf( str, "%s/mesh.nodes", filename.c_str() );
ofstream outfile_n(str);
sprintf( str, "%s/mesh.elements", filename.c_str() );
ofstream outfile_e(str);
sprintf( str, "%s/mesh.boundary", filename.c_str() );
ofstream outfile_b(str);
sprintf( str, "%s/mesh.names", filename.c_str() );
ofstream outfile_names(str);
auto get_name = [&dirname]( string s ) {
return filesystem::path(dirname).append(s);
};
ofstream outfile_h(get_name("mesh.header"));
ofstream outfile_n(get_name("mesh.nodes"));
ofstream outfile_e(get_name("mesh.elements"));
ofstream outfile_b(get_name("mesh.boundary"));
ofstream outfile_names(get_name("mesh.names"));
for( auto codim : IntRange(0, mesh.GetDimension()-1) )
{

View File

@ -22,7 +22,7 @@ namespace netgen
void WriteFEAPFormat (const Mesh & mesh,
const string & filename)
const filesystem::path & filename)
{
// Feap format by A. Rieger
@ -35,7 +35,7 @@ void WriteFEAPFormat (const Mesh & mesh,
double scale = 1; // globflags.GetNumFlag ("scale", 1);
ofstream outfile(filename.c_str());
ofstream outfile(filename);
outfile << "feap" << "\n";
outfile << mesh.GetNP();

View File

@ -18,7 +18,7 @@ namespace netgen
void WriteFluentFormat (const Mesh & mesh,
const string & filename)
const filesystem::path & filename)
{
cout << "start writing fluent export" << endl;
@ -28,7 +28,7 @@ void WriteFluentFormat (const Mesh & mesh,
int nse = mesh.GetNSE();
int i, j;
ofstream outfile (filename.c_str());
ofstream outfile (filename);
char str[100];
outfile.precision(6);

View File

@ -32,9 +32,9 @@ namespace netgen
void WriteGmshFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename)
const filesystem::path & filename)
{
ofstream outfile (filename.c_str());
ofstream outfile (filename);
outfile.precision(6);
outfile.setf (ios::fixed, ios::floatfield);
outfile.setf (ios::showpoint);

View File

@ -49,9 +49,9 @@ namespace netgen
*/
void WriteGmsh2Format (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename)
const filesystem::path & filename)
{
ofstream outfile (filename.c_str());
ofstream outfile (filename);
outfile.precision(6);
outfile.setf (ios::fixed, ios::floatfield);
outfile.setf (ios::showpoint);

View File

@ -17,7 +17,7 @@ namespace netgen
void WriteJCMFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename)
const filesystem::path & filename)
{
if (mesh.GetDimension() != 3)
{
@ -122,7 +122,7 @@ void WriteJCMFormat (const Mesh & mesh,
nbquad++;
}
ofstream outfile (filename.c_str());
ofstream outfile (filename);
outfile.precision(6);
outfile.setf (ios::fixed, ios::floatfield);
outfile.setf (ios::showpoint);

View File

@ -22,18 +22,18 @@ namespace netgen
// This should be the new function to export a PERMAS file
void WritePermasFormat (const Mesh &mesh, const string &filename,
void WritePermasFormat (const Mesh &mesh, const filesystem::path &filename,
string &strComp, string &strSitu)
{
ofstream outfile (filename.c_str());
ofstream outfile (filename);
addComponent(strComp, strSitu, outfile);
WritePermasFormat ( mesh, filename);
}
void WritePermasFormat (const Mesh &mesh, const string &filename)
void WritePermasFormat (const Mesh &mesh, const filesystem::path &filename)
{
string strComp, strSitu;
ofstream outfile (filename.c_str());
ofstream outfile (filename);
outfile.precision(8);

View File

@ -28,7 +28,7 @@ void WriteTecPlotFormat (const Mesh & mesh,
INDEX nse = mesh.GetNSE();
NgArray<int> sn(np);
ofstream outfile(filename.c_str());
ofstream outfile(filename);
outfile << "TITLE=\" " << filename << "\"" << endl;

View File

@ -272,7 +272,7 @@ namespace netgen
ofstream outfile(filename.c_str());
ofstream outfile(filename);
outfile.precision(16);

View File

@ -20,11 +20,11 @@ namespace netgen
void WriteTochnogFormat (const Mesh & mesh,
const string & filename)
const filesystem::path & filename)
{
cout << "\nWrite Tochnog Volume Mesh" << endl;
ofstream outfile (filename.c_str());
ofstream outfile (filename);
outfile << "(Nodes and Elements generated with NETGEN" << endl;
outfile << " " << filename << ")" << endl;

View File

@ -58,9 +58,9 @@ namespace netgen
bool WriteUserFormat (const string & format,
bool WriteUserFormat (const filesystem::path & format,
const Mesh & mesh,
const string & filename)
const filesystem::path & filename)
{
// cout << "write user &hgeom = " << &hgeom << endl;
// const CSGeometry & geom = *dynamic_cast<const CSGeometry*> (&hgeom);
@ -167,7 +167,7 @@ bool WriteUserFormat (const string & format,
void WriteNeutralFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename)
const filesystem::path & filename)
{
cout << "write neutral, new" << endl;
int np = mesh.GetNP();
@ -179,7 +179,7 @@ void WriteNeutralFormat (const Mesh & mesh,
int inverttets = mparam.inverttets;
int invertsurf = mparam.inverttrigs;
ofstream outfile (filename.c_str());
ofstream outfile (filename);
outfile.precision(6);
outfile.setf (ios::fixed, ios::floatfield);
@ -283,14 +283,14 @@ void WriteNeutralFormat (const Mesh & mesh,
void WriteSurfaceFormat (const Mesh & mesh,
const string & filename)
const filesystem::path & filename)
{
// surface mesh
int i, j;
cout << "Write Surface Mesh" << endl;
ofstream outfile (filename.c_str());
ofstream outfile (filename);
outfile << "surfacemesh" << endl;
@ -325,16 +325,17 @@ void WriteSurfaceFormat (const Mesh & mesh,
*/
void WriteSTLFormat (const Mesh & mesh,
const string & filename)
const filesystem::path & filename)
{
cout << "\nWrite STL Surface Mesh" << endl;
auto ext = filename.extension();
ostream *outfile;
if(filename.substr(filename.length()-3,3) == ".gz")
outfile = new ogzstream(filename.c_str());
if(ext == ".gz")
outfile = new ogzstream(filename);
else
outfile = new ofstream(filename.c_str());
outfile = new ofstream(filename);
int i;
@ -382,16 +383,17 @@ void WriteSTLFormat (const Mesh & mesh,
* when using a third-party mesher
*/
void WriteSTLExtFormat (const Mesh & mesh,
const string & filename)
const filesystem::path & filename)
{
cout << "\nWrite STL Surface Mesh (with separated boundary faces)" << endl;
auto ext = filename.extension();
ostream *outfile;
if(filename.substr(filename.length()-3,3) == ".gz")
outfile = new ogzstream(filename.c_str());
if(ext == ".gz")
outfile = new ogzstream(filename);
else
outfile = new ofstream(filename.c_str());
outfile = new ofstream(filename);
outfile->precision(10);
@ -474,7 +476,7 @@ void WriteSTLExtFormat (const Mesh & mesh,
void WriteVRMLFormat (const Mesh & mesh,
bool faces,
const string & filename)
const filesystem::path & filename)
{
if (faces)
@ -487,7 +489,7 @@ void WriteVRMLFormat (const Mesh & mesh,
int nse = mesh.GetNSE();
int i, j;
ofstream outfile (filename.c_str());
ofstream outfile (filename);
outfile.precision(6);
outfile.setf (ios::fixed, ios::floatfield);
@ -563,7 +565,7 @@ void WriteVRMLFormat (const Mesh & mesh,
int nse = mesh.GetNSE();
int i, j;
ofstream outfile (filename.c_str());
ofstream outfile (filename);
outfile.precision(6);
outfile.setf (ios::fixed, ios::floatfield);
@ -639,10 +641,10 @@ void WriteVRMLFormat (const Mesh & mesh,
*/
void WriteFEPPFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename)
const filesystem::path & filename)
{
ofstream outfile (filename.c_str());
ofstream outfile (filename);
if (mesh.GetDimension() == 3)
@ -770,7 +772,7 @@ void WriteFEPPFormat (const Mesh & mesh,
void WriteEdgeElementFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename)
const filesystem::path & filename)
{
cout << "write edge element format" << endl;
@ -785,7 +787,7 @@ void WriteEdgeElementFormat (const Mesh & mesh,
int invertsurf = mparam.inverttrigs;
NgArray<int> edges;
ofstream outfile (filename.c_str());
ofstream outfile (filename);
outfile.precision(6);
outfile.setf (ios::fixed, ios::floatfield);
@ -908,8 +910,8 @@ void WriteEdgeElementFormat (const Mesh & mesh,
void WriteFile (int typ,
const Mesh & mesh,
const CSGeometry & geom,
const char * filename,
const char * geomfile,
const filesystem::path & filename,
const filesystem::path & geomfile,
double h)
{

View File

@ -13,15 +13,15 @@ DLL_HEADER extern
void WriteFile (int typ,
const Mesh & mesh,
const NetgenGeometry & geom,
const char * filename,
const char * geomfile = NULL,
const filesystem::path & filename,
const filesystem::path & geomfile = "",
double h = 0);
DLL_HEADER extern
void ReadFile (Mesh & mesh,
const string & filename);
const filesystem::path & filename);
@ -31,15 +31,15 @@ void ReadFile (Mesh & mesh,
extern
void WriteNeutralFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename);
const filesystem::path & filename);
extern
void WriteSurfaceFormat (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern
void WriteSTLFormat (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
// Philippose - 16 August 2010
@ -48,134 +48,134 @@ void WriteSTLFormat (const Mesh & mesh,
// a separate "solid" entity in the STL file
extern
void WriteSTLExtFormat (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern
void WriteVRMLFormat (const Mesh & mesh,
bool faces,
const string & filename);
const filesystem::path & filename);
extern
void WriteFEPPFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename);
const filesystem::path & filename);
extern
void WriteGmshFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename);
const filesystem::path & filename);
// Philippose - 29/01/2009
// Added GMSH v2.xx Mesh Export support
void WriteGmsh2Format (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename);
const filesystem::path & filename);
// Philippose - 25/10/2009
// Added OpenFOAM 1.5+ Mesh Export support
extern
void WriteOpenFOAM15xFormat (const Mesh & mesh,
const string & casename,
const filesystem::path & casename,
const bool compressed);
extern
void WriteUserChemnitz (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern
void WriteJCMFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename);
const filesystem::path & filename);
extern
void WriteDiffPackFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename);
const filesystem::path & filename);
extern
void WriteTochnogFormat (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern
void WriteTecPlotFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename);
const filesystem::path & filename);
extern
void WriteAbaqusFormat (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern
void WriteFluentFormat (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern
void WritePermasFormat (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern
void WriteFEAPFormat (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern
void WriteElmerFormat (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern
void WriteEdgeElementFormat (const Mesh & mesh,
const NetgenGeometry & geom,
const string & filename);
const filesystem::path & filename);
#ifdef OLIVER
extern
void WriteTETFormat (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
#endif
extern void ReadTETFormat (Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern void ReadFNFFormat (Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern void DLL_HEADER ReadCGNSMesh (Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern void DLL_HEADER WriteCGNSMesh (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
// read/write mesh and solutions from CGNS file
extern tuple<shared_ptr<Mesh>, vector<string>, vector<Array<double>>, vector<int>>
DLL_HEADER ReadCGNSFile(string filename, int base);
DLL_HEADER ReadCGNSFile(const filesystem::path & filename, int base);
extern void DLL_HEADER WriteCGNSFile(shared_ptr<Mesh> mesh,string filename, vector<string> fields,
extern void DLL_HEADER WriteCGNSFile(shared_ptr<Mesh> mesh, const filesystem::path & filename, vector<string> fields,
vector<Array<double>> values, vector<int> locations);
void WriteDolfinFormat (const Mesh & mesh,
const string & filename);
const filesystem::path & filename);
extern void DLL_HEADER RegisterUserFormats (NgArray<const char*> & names,
NgArray<const char*> & extensions);
extern bool DLL_HEADER WriteUserFormat (const string & format,
extern bool DLL_HEADER WriteUserFormat (const filesystem::path & format,
const Mesh & mesh,
// const NetgenGeometry & geom,
const string & filename);
const filesystem::path & filename);
}

View File

@ -306,9 +306,9 @@ namespace netgen
void WriteUserChemnitz (const Mesh & mesh,
const string & filename)
const filesystem::path & filename)
{
ofstream outfile (filename.c_str());
ofstream outfile (filename);
ReadFileMesh (mesh);
Convert ();

View File

@ -1124,7 +1124,7 @@ namespace netgen
return 0;
}
void NetgenGeometry :: Save (string filename) const
void NetgenGeometry :: Save (const filesystem::path & filename) const
{
throw NgException("Cannot save geometry - no geometry available");
}

View File

@ -7,7 +7,6 @@
/* Date: 23. Aug. 09 */
/**************************************************************************/
struct Tcl_Interp;
namespace netgen
@ -298,7 +297,7 @@ namespace netgen
return i;
throw Exception("Couldn't find edge index");
}
virtual void Save (string filename) const;
virtual void Save (const filesystem::path & filename) const;
virtual void SaveToMeshFile (ostream & /* ost */) const { ; }
};
@ -310,7 +309,7 @@ namespace netgen
{
public:
virtual ~GeometryRegister();
virtual NetgenGeometry * Load (string filename) const = 0;
virtual NetgenGeometry * Load (const filesystem::path & filename) const = 0;
virtual NetgenGeometry * LoadFromMeshFile (istream & /* ist */, string) const { return NULL; }
virtual class VisualScene * GetVisualScene (const NetgenGeometry * /* geom */) const
{ return NULL; }

View File

@ -627,9 +627,12 @@ namespace netgen
void Mesh :: Save (const string & filename) const
void Mesh :: Save (const filesystem::path & filename) const
{
if (filename.find(".vol.bin") != string::npos)
string ext0 = filename.stem().extension().string();
string ext = filename.extension().string();
if (ext0 == ".vol" && ext == ".bin")
{
BinaryOutArchive in(filename);
in & const_cast<Mesh&>(*this);
@ -637,12 +640,12 @@ namespace netgen
}
ostream * outfile;
if (filename.find(".vol.gz")!=string::npos)
outfile = new ogzstream(filename.c_str());
else if (filename.find(".vol")!=string::npos)
outfile = new ofstream(filename.c_str());
if (ext0 == ".vol" && ext == ".gz")
outfile = new ogzstream(filename);
else if (ext == ".vol")
outfile = new ofstream(filename);
else
outfile = new ogzstream((filename+".vol.gz").c_str());
outfile = new ogzstream(filesystem::path(filename).concat(".vol.gz"));
Save(*outfile);
delete outfile;
@ -1109,11 +1112,14 @@ namespace netgen
void Mesh :: Load (const string & filename)
void Mesh :: Load (const filesystem::path & filename)
{
cout << "filename = " << filename << endl;
PrintMessage (1, "filename = ", filename);
if (filename.find(".vol.bin") != string::npos)
string ext0 = filename.stem().extension().string();
string ext = filename.extension().string();
if (ext0 == ".vol" && ext == ".bin")
{
BinaryInArchive in(filename);
in & (*this);
@ -1122,12 +1128,11 @@ namespace netgen
istream * infile = NULL;
if (filename.find(".vol.gz") != string::npos)
infile = new igzstream (filename.c_str());
if (ext0 == ".vol" && ext == ".gz")
infile = new igzstream (filename);
else
infile = new ifstream (filename.c_str());
infile = new ifstream (filename);
// ifstream infile(filename.c_str());
if (! (infile -> good()) )
throw NgException ("mesh file not found");
@ -1651,6 +1656,10 @@ namespace netgen
clusters -> Update();
}
auto geo = geometryregister.LoadFromMeshFile (infile);
if(geo)
geometry = geo;
SetNextMajorTimeStamp();
// PrintMemInfo (cout);
}
@ -1840,9 +1849,9 @@ namespace netgen
}
void Mesh :: Merge (const string & filename, const int surfindex_offset)
void Mesh :: Merge (const filesystem::path & filename, const int surfindex_offset)
{
ifstream infile(filename.c_str());
ifstream infile(filename);
if (!infile.good())
throw NgException ("mesh file not found");
@ -3758,7 +3767,7 @@ namespace netgen
}
void Mesh :: LoadLocalMeshSize (const string & meshsizefilename)
void Mesh :: LoadLocalMeshSize (const filesystem::path & meshsizefilename)
{
// Philippose - 10/03/2009
// Improve error checking when loading and reading
@ -3766,7 +3775,7 @@ namespace netgen
if (meshsizefilename.empty()) return;
ifstream msf(meshsizefilename.c_str());
ifstream msf(meshsizefilename);
// Philippose - 09/03/2009
// Adding print message information in case the specified

View File

@ -11,8 +11,12 @@
The mesh class
*/
#include<filesystem>
namespace netgen
{
using namespace std;
enum resthtype { RESTRICTH_FACE, RESTRICTH_EDGE,
RESTRICTH_SURFACEELEMENT, RESTRICTH_POINT, RESTRICTH_SEGMENT };
@ -446,7 +450,7 @@ namespace netgen
///
DLL_HEADER void RestrictLocalH (resthtype rht, int nr, double loch);
///
DLL_HEADER void LoadLocalMeshSize (const string & meshsizefilename);
DLL_HEADER void LoadLocalMeshSize (const filesystem::path & meshsizefilename);
///
DLL_HEADER void SetGlobalH (double h);
///
@ -546,11 +550,11 @@ namespace netgen
///
DLL_HEADER void Merge (istream & infile, const int surfindex_offset = 0);
///
DLL_HEADER void Save (const string & filename) const;
DLL_HEADER void Save (const filesystem::path & filename) const;
///
DLL_HEADER void Load (const string & filename);
DLL_HEADER void Load (const filesystem::path & filename);
///
DLL_HEADER void Merge (const string & filename, const int surfindex_offset = 0);
DLL_HEADER void Merge (const filesystem::path & filename, const int surfindex_offset = 0);
DLL_HEADER void DoArchive (Archive & archive);

View File

@ -813,8 +813,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
if(geo!=nullptr) mesh->SetGeometry(geo);
else if(ng_geometry!=nullptr) mesh->SetGeometry(ng_geometry);
}),py::call_guard<py::gil_scoped_release>())
// static_cast<void(Mesh::*)(const string & name)>(&Mesh::Load))
.def("Save", static_cast<void(Mesh::*)(const string & name)const>(&Mesh::Save),py::call_guard<py::gil_scoped_release>())
.def("Save", static_cast<void(Mesh::*)(const filesystem::path & name)const>(&Mesh::Save),py::call_guard<py::gil_scoped_release>())
.def("Export",
[] (Mesh & self, string filename, string format)
{

View File

@ -68,7 +68,7 @@
namespace netgen
{
void LoadOCCInto(OCCGeometry* occgeo, const char* filename);
void LoadOCCInto(OCCGeometry* occgeo, const filesystem::path & filename);
void PrintContents (OCCGeometry * geom);
std::map<Handle(TopoDS_TShape), ShapeProperties> OCCGeometry::global_shape_properties;
@ -140,10 +140,10 @@ namespace netgen
if(copy)
{
auto filename = GetTempFilename();
step_utils::WriteSTEP(_shape, filename.c_str());
LoadOCCInto(this, filename.c_str());
step_utils::WriteSTEP(_shape, filename);
LoadOCCInto(this, filename);
dimension = aoccdim;
std::remove(filename.c_str());
filesystem::remove(filename);
}
else
{
@ -1347,7 +1347,7 @@ namespace netgen
// }
void LoadOCCInto(OCCGeometry* occgeo, const char* filename)
void LoadOCCInto(OCCGeometry* occgeo, const filesystem::path & filename)
{
static Timer timer_all("LoadOCC"); RegionTimer rtall(timer_all);
static Timer timer_readfile("LoadOCC-ReadFile");
@ -1375,7 +1375,7 @@ namespace netgen
// Enable transfer of colours
reader.SetColorMode(Standard_True);
reader.SetNameMode(Standard_True);
Standard_Integer stat = reader.ReadFile((char*)filename);
Standard_Integer stat = reader.ReadFile(filename.string().c_str());
timer_readfile.Stop();
timer_transfer.Start();
@ -1411,7 +1411,7 @@ namespace netgen
to extract individual surface colours via the extended
OpenCascade XDE and XCAF Feature set.
*/
OCCGeometry *LoadOCC_IGES(const char *filename)
OCCGeometry *LoadOCC_IGES(const filesystem::path & filename)
{
OCCGeometry *occgeo;
occgeo = new OCCGeometry;
@ -1432,7 +1432,7 @@ namespace netgen
IGESCAFControl_Reader reader;
Standard_Integer stat = reader.ReadFile((char*)filename);
Standard_Integer stat = reader.ReadFile(filename.string().c_str());
if(stat != IFSelect_RetDone)
{
@ -1485,7 +1485,7 @@ namespace netgen
to extract individual surface colours via the extended
OpenCascade XDE and XCAF Feature set.
*/
OCCGeometry * LoadOCC_STEP (const char * filename)
OCCGeometry * LoadOCC_STEP (const filesystem::path & filename)
{
OCCGeometry * occgeo;
occgeo = new OCCGeometry;
@ -1497,13 +1497,13 @@ namespace netgen
OCCGeometry *LoadOCC_BREP (const char *filename)
OCCGeometry *LoadOCC_BREP (const filesystem::path & filename)
{
OCCGeometry * occgeo;
occgeo = new OCCGeometry;
BRep_Builder aBuilder;
Standard_Boolean result = BRepTools::Read(occgeo->shape, const_cast<char*> (filename),aBuilder);
Standard_Boolean result = BRepTools::Read(occgeo->shape, filename.string().c_str(), aBuilder);
if(!result)
{
@ -1521,34 +1521,36 @@ namespace netgen
}
void OCCGeometry :: Save (string sfilename) const
void OCCGeometry :: Save (const filesystem::path & filename) const
{
const char * filename = sfilename.c_str();
if (strlen(filename) < 4)
throw NgException ("illegal filename");
string ext = ToLower(filename.extension());
auto s_filename = filename.string();
auto c_filename = s_filename.c_str();
if (strcmp (&filename[strlen(filename)-3], "igs") == 0)
if (ext == ".igs")
{
IGESControl_Writer writer("millimeters", 1);
writer.AddShape (shape);
writer.Write (filename);
writer.Write (c_filename);
}
else if (strcmp (&filename[strlen(filename)-3], "stp") == 0)
else if (ext == ".stp")
{
step_utils::WriteSTEP(*this, filename);
}
else if (strcmp (&filename[strlen(filename)-3], "stl") == 0)
else if (ext == ".stl")
{
StlAPI_Writer writer;
writer.ASCIIMode() = Standard_True;
writer.Write (shape, filename);
writer.Write (shape, c_filename);
}
else if (strcmp (&filename[strlen(filename)-4], "stlb") == 0)
else if (ext == ".stlb")
{
StlAPI_Writer writer;
writer.ASCIIMode() = Standard_False;
writer.Write (shape, filename);
writer.Write (shape, c_filename);
}
throw NgException ("Unkown target format: " + filename);
}
void OCCGeometry :: SaveToMeshFile (ostream & ost) const
@ -2267,7 +2269,7 @@ namespace netgen
OCCGeometry::identifications[shape_origin.TShape()] = result;
}
void WriteSTEP(const TopoDS_Shape & shape, string filename)
void WriteSTEP(const TopoDS_Shape & shape, const filesystem::path & filename)
{
Interface_Static::SetCVal("write.step.schema", "AP242IS");
Interface_Static::SetIVal("write.step.assembly",1);
@ -2303,7 +2305,7 @@ namespace netgen
for (TopExp_Explorer e(shape, typ); e.More(); e.Next())
WriteProperties(model, finder, e.Current());
writer.Write(filename.c_str());
writer.Write(filename.string().c_str());
}
} // namespace step_utils

View File

@ -196,7 +196,7 @@ namespace netgen
int nr, FlatArray<int, PointIndex> glob2loc) const override;
// void OptimizeSurface(Mesh& mesh, const MeshingParameters& mparam) const override {}
void Save (string filename) const override;
void Save (const filesystem::path & filename) const override;
void SaveToMeshFile (ostream & /* ost */) const override;
void DoArchive(Archive& ar) override;
@ -356,9 +356,9 @@ namespace netgen
void PrintContents (OCCGeometry * geom);
DLL_HEADER OCCGeometry * LoadOCC_IGES (const char * filename);
DLL_HEADER OCCGeometry * LoadOCC_STEP (const char * filename);
DLL_HEADER OCCGeometry * LoadOCC_BREP (const char * filename);
DLL_HEADER OCCGeometry * LoadOCC_IGES (const filesystem::path & filename);
DLL_HEADER OCCGeometry * LoadOCC_STEP (const filesystem::path & filename);
DLL_HEADER OCCGeometry * LoadOCC_BREP (const filesystem::path & filename);
// Philippose - 31.09.2009
// External access to the mesh generation functions within the OCC
@ -535,9 +535,9 @@ namespace netgen
const Handle(TDocStd_Document) step_doc);
void WriteProperties(const Handle(Interface_InterfaceModel) model, const Handle(Transfer_FinderProcess) finder, const TopoDS_Shape & shape);
void WriteSTEP(const TopoDS_Shape & shape, string filename);
void WriteSTEP(const TopoDS_Shape & shape, const filesystem::path & filename);
inline void WriteSTEP(const OCCGeometry & geo, string filename)
inline void WriteSTEP(const OCCGeometry & geo, const filesystem::path & filename)
{
WriteSTEP(geo.GetShape(), filename);
}

View File

@ -43,7 +43,7 @@ namespace netgen
class OCCGeometryRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const;
virtual NetgenGeometry * Load (const filesystem::path & filename) const;
virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const;
virtual void SetParameters (Tcl_Interp * interp)
@ -893,55 +893,27 @@ namespace netgen
NetgenGeometry * OCCGeometryRegister :: Load (string filename) const
NetgenGeometry * OCCGeometryRegister :: Load (const filesystem::path & filename) const
{
const char * lgfilename = filename.c_str();
string ext = ToLower(filename.extension());
/*
if (strcmp (&cfilename[strlen(cfilename)-3], "geo") == 0)
if (ext == ".iges" || ext == ".igs")
{
PrintMessage (1, "Load OCCG geometry file ", cfilename);
extern OCCGeometry * ParseOCCG (istream & istr);
ifstream infile(cfilename);
OCCGeometry * hgeom = ParseOCCG (infile);
if (!hgeom)
throw NgException ("geo-file should start with 'algebraic3d'");
hgeom -> FindIdenticSurfaces(1e-8 * hgeom->MaxSize());
return hgeom;
}
*/
if ((strcmp (&lgfilename[strlen(lgfilename)-4], "iges") == 0) ||
(strcmp (&lgfilename[strlen(lgfilename)-3], "igs") == 0) ||
(strcmp (&lgfilename[strlen(lgfilename)-3], "IGS") == 0) ||
(strcmp (&lgfilename[strlen(lgfilename)-4], "IGES") == 0))
{
PrintMessage (1, "Load IGES geometry file ", lgfilename);
OCCGeometry * occgeometry = LoadOCC_IGES (lgfilename);
PrintMessage (1, "Load IGES geometry file ", filename);
OCCGeometry * occgeometry = LoadOCC_IGES (filename);
return occgeometry;
}
else if ((strcmp (&lgfilename[strlen(lgfilename)-4], "step") == 0) ||
(strcmp (&lgfilename[strlen(lgfilename)-3], "stp") == 0) ||
(strcmp (&lgfilename[strlen(lgfilename)-3], "STP") == 0) ||
(strcmp (&lgfilename[strlen(lgfilename)-4], "STEP") == 0))
else if (ext == ".stp" || ext == ".step")
{
PrintMessage (1, "Load STEP geometry file ", lgfilename);
OCCGeometry * occgeometry = LoadOCC_STEP (lgfilename);
PrintMessage (1, "Load STEP geometry file ", filename);
OCCGeometry * occgeometry = LoadOCC_STEP (filename);
return occgeometry;
}
else if ((strcmp (&lgfilename[strlen(lgfilename)-4], "brep") == 0) ||
(strcmp (&lgfilename[strlen(lgfilename)-4], "Brep") == 0) ||
(strcmp (&lgfilename[strlen(lgfilename)-4], "BREP") == 0))
else if (ext == ".brep")
{
PrintMessage (1, "Load BREP geometry file ", lgfilename);
OCCGeometry * occgeometry = LoadOCC_BREP (lgfilename);
PrintMessage (1, "Load BREP geometry file ", filename);
OCCGeometry * occgeometry = LoadOCC_BREP (filename);
return occgeometry;
}

View File

@ -137,11 +137,11 @@ DLL_HEADER void ExportNgOCC(py::module &m)
{
shared_ptr<OCCGeometry> geo;
if(EndsWith(filename, ".step") || EndsWith(filename, ".stp"))
geo.reset(LoadOCC_STEP(filename.c_str()));
geo.reset(LoadOCC_STEP(filename));
else if(EndsWith(filename, ".brep"))
geo.reset(LoadOCC_BREP(filename.c_str()));
geo.reset(LoadOCC_BREP(filename));
else if(EndsWith(filename, ".iges"))
geo.reset(LoadOCC_IGES(filename.c_str()));
geo.reset(LoadOCC_IGES(filename));
else
throw Exception("Cannot load file " + filename + "\nValid formats are: step, stp, brep, iges");
ng_geometry = geo;
@ -279,7 +279,7 @@ DLL_HEADER void ExportNgOCC(py::module &m)
m.def("LoadOCCGeometry",[] (const string & filename)
m.def("LoadOCCGeometry",[] (filesystem::path filename)
{
cout << "WARNING: LoadOCCGeometry is deprecated! Just use the OCCGeometry(filename) constructor. It is able to read brep and iges files as well!" << endl;
ifstream ist(filename);

View File

@ -68,28 +68,27 @@ STLGeometry :: ~STLGeometry()
// delete edgedata;
}
void STLGeometry :: Save (string filename) const
void STLGeometry :: Save (const filesystem::path & filename) const
{
const char * cfilename = filename.c_str();
if (strlen(cfilename) < 4)
throw NgException ("illegal filename");
string ext = ToLower(filename.extension());
if (strlen(cfilename) > 3 &&
strcmp (&cfilename[strlen(cfilename)-3], "stl") == 0)
if (ext == ".stl")
{
STLTopology::Save (cfilename);
STLTopology::Save (filename);
return;
}
else if (strlen(cfilename) > 4 &&
strcmp (&cfilename[strlen(cfilename)-4], "stlb") == 0)
else if (ext == ".stlb")
{
SaveBinary (cfilename,"Binary STL Geometry");
SaveBinary (filename,"Binary STL Geometry");
return;
}
else if (ext == ".stle")
{
SaveSTLE (filename);
return;
}
}
else if (strlen(cfilename) > 4 &&
strcmp (&cfilename[strlen(cfilename)-4], "stle") == 0)
{
SaveSTLE (cfilename);
}
throw Exception ("Unknown target format: " + filename.string());
}
@ -1100,22 +1099,22 @@ void STLGeometry :: ExportEdges()
}
void STLGeometry :: LoadEdgeData(const char* file)
void STLGeometry :: LoadEdgeData(const filesystem::path & filename)
{
StoreEdgeData();
PrintFnStart("Load edges from file '", file, "'");
ifstream fin(file);
PrintFnStart("Load edges from file '", filename, "'");
ifstream fin(filename);
edgedata->Read(fin);
// calcedgedataanglesnew = 1;
}
void STLGeometry :: SaveEdgeData(const char* file)
void STLGeometry :: SaveEdgeData(const filesystem::path & filename)
{
PrintFnStart("save edges to file '", file, "'");
ofstream fout(file);
PrintFnStart("save edges to file '", filename, "'");
ofstream fout(filename);
edgedata->Write(fout);
}
@ -3627,7 +3626,7 @@ void STLGeometry :: SmoothGeometry ()
}
}
void STLGeometry :: WriteChartToFile( ChartId chartnumber, string filename )
void STLGeometry :: WriteChartToFile( ChartId chartnumber, filesystem::path filename )
{
PrintMessage(1,"write chart ", int(chartnumber), " to ", filename);
Array<int> trignums;
@ -3701,38 +3700,38 @@ void STLGeometry :: WriteChartToFile( ChartId chartnumber, string filename )
class STLGeometryRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const;
virtual NetgenGeometry * Load (const filesystem::path & filename) const;
};
NetgenGeometry * STLGeometryRegister :: Load (string filename) const
NetgenGeometry * STLGeometryRegister :: Load (const filesystem::path & filename) const
{
const char * cfilename = filename.c_str();
string ext = ToLower(filename.extension());
if (strcmp (&cfilename[strlen(cfilename)-3], "stl") == 0)
if (ext == ".stl")
{
PrintMessage (1, "Load STL geometry file ", cfilename);
PrintMessage (1, "Load STL geometry file ", filename);
ifstream infile(cfilename);
ifstream infile(filename);
STLGeometry * hgeom = STLGeometry :: Load (infile);
hgeom -> edgesfound = 0;
return hgeom;
}
else if (strcmp (&cfilename[strlen(cfilename)-4], "stlb") == 0)
else if (ext == ".stlb")
{
PrintMessage (1, "Load STL binary geometry file ", cfilename);
PrintMessage (1, "Load STL binary geometry file ", filename);
ifstream infile(cfilename);
ifstream infile(filename);
STLGeometry * hgeom = STLGeometry :: LoadBinary (infile);
hgeom -> edgesfound = 0;
return hgeom;
}
else if (strcmp (&cfilename[strlen(cfilename)-3], "nao") == 0)
else if (ext == ".nao")
{
PrintMessage (1, "Load naomi (F. Kickinger) geometry file ", cfilename);
PrintMessage (1, "Load naomi (F. Kickinger) geometry file ", filename);
ifstream infile(cfilename);
ifstream infile(filename);
STLGeometry * hgeom = STLGeometry :: LoadNaomi (infile);
hgeom -> edgesfound = 0;

View File

@ -190,7 +190,7 @@ namespace netgen
void Clear();
virtual void Save (string filename) const override;
virtual void Save (const filesystem::path & filename) const override;
bool CalcPointGeomInfo(int surfind, PointGeomInfo& gi, const Point<3> & p3) const override;
PointGeomInfo ProjectPoint(INDEX surfind, Point<3> & p) const override;
@ -236,8 +236,8 @@ namespace netgen
DLL_HEADER void ImportEdges();
DLL_HEADER void AddEdges(const NgArray<Point<3> >& eps);
DLL_HEADER void ExportEdges();
DLL_HEADER void LoadEdgeData(const char* file);
DLL_HEADER void SaveEdgeData(const char* file);
DLL_HEADER void LoadEdgeData(const filesystem::path & file);
DLL_HEADER void SaveEdgeData(const filesystem::path & file);
// void SetEdgeAtSelected(int mode);
@ -475,7 +475,7 @@ namespace netgen
int GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam) override;
// Add additional Point to chart to close the surface and write the resulting stl to a file
DLL_HEADER void WriteChartToFile( ChartId chartnumber, string filename="chart.slb" );
DLL_HEADER void WriteChartToFile( ChartId chartnumber, filesystem::path filename="chart.slb" );
};

View File

@ -36,7 +36,7 @@ namespace netgen
class STLGeometryVisRegister : public GeometryRegister
{
public:
virtual NetgenGeometry * Load (string filename) const { return NULL; }
virtual NetgenGeometry * Load (const filesystem::path & filename) const { return NULL; }
virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const;
virtual void SetParameters (Tcl_Interp * interp)
{

View File

@ -90,7 +90,7 @@ STLGeometry * STLTopology :: LoadBinary (istream & ist)
}
void STLTopology :: SaveBinary (const char* filename, const char* aname) const
void STLTopology :: SaveBinary (const filesystem::path & filename, const char* aname) const
{
ofstream ost(filename);
PrintFnStart("Write STL binary file '",filename,"'");
@ -149,7 +149,7 @@ void STLTopology :: SaveBinary (const char* filename, const char* aname) const
}
void STLTopology :: SaveSTLE (const char* filename) const
void STLTopology :: SaveSTLE (const filesystem::path & filename) const
{
ofstream outf (filename);
int i, j;
@ -266,7 +266,7 @@ STLGeometry * STLTopology :: LoadNaomi (istream & ist)
return geom;
}
void STLTopology :: Save (const char* filename) const
void STLTopology :: Save (const filesystem::path & filename) const
{
PrintFnStart("Write stl-file '",filename, "'");

View File

@ -316,9 +316,9 @@ public:
static STLGeometry * Load (istream & ist);
static STLGeometry * LoadBinary (istream & ist);
void Save (const char* filename) const;
void SaveBinary (const char* filename, const char* aname) const;
void SaveSTLE (const char * filename) const; // stores trigs and edges
void Save (const filesystem::path & filename) const;
void SaveBinary (const filesystem::path & filename, const char* aname) const;
void SaveSTLE (const filesystem::path & filename) const; // stores trigs and edges
virtual void DoArchive(Archive& ar)
{

View File

@ -205,9 +205,9 @@ namespace netgen
Tcl_Interp * interp,
int argc, tcl_const char *argv[])
{
string filename (argv[1]);
auto filename = filesystem::u8path(argv[1]);
if (filename.find(".vol") == string::npos)
if (filename.string().find(".vol") == string::npos)
{
return Ng_ImportMesh(clientData,interp,argc,argv);
}
@ -217,42 +217,15 @@ namespace netgen
mesh = make_shared<Mesh>();
try
{
istream * infile;
// if (filename.substr (filename.length()-3, 3) == ".gz")
if (filename.find(".vol.gz") != string::npos)
infile = new igzstream (filename.c_str());
else
infile = new ifstream (filename.c_str());
// ifstream infile(filename.c_str());
mesh -> Load(*infile);
// vsmesh.SetMesh (mesh);
mesh -> Load(filename);
SetGlobalMesh (mesh);
#ifdef PARALLEL
MyMPI_SendCmd ("mesh");
mesh -> Distribute();
#endif
auto geo = geometryregister.LoadFromMeshFile (*infile);
if(geo)
ng_geometry = geo;
delete infile;
/*
string auxstring;
if(infile.good())
{
infile >> auxstring;
if(auxstring == "csgsurfaces")
{
CSGeometry * geometry = new CSGeometry ("");
geometry -> LoadSurfaces(infile);
delete ng_geometry;
ng_geometry = geometry;
}
}
*/
if(mesh->GetGeometry())
ng_geometry = mesh->GetGeometry();
}
catch (NgException e)
{