From 20c62589d2de1cab736c772ddde5e1088e3d9bc9 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 12 Jun 2018 11:06:50 +0200 Subject: [PATCH 1/7] Geometry information is now also Distributed when loading a mesh via NG_LoadMesh (was already fixed for python-meshes) --- libsrc/interface/nginterface.cpp | 51 +++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 2a340281..46228f79 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -68,6 +68,9 @@ using namespace netgen; void Ng_LoadGeometry (const char * filename) { + + cout << endl << "LOAD GEOMETRY FROM FILE " << filename << endl; + // he: if filename is empty, return // can be used to reset geometry if (!filename || strcmp(filename,"")==0) @@ -127,6 +130,10 @@ void Ng_LoadMesh (const char * filename) MPI_Comm_size(MPI_COMM_WORLD, &ntasks); MPI_Comm_rank(MPI_COMM_WORLD, &id); + char* buf; // for distributing geometry! + int strs; + istream * infile; + if (id == 0) { #endif @@ -136,6 +143,10 @@ void Ng_LoadMesh (const char * filename) strcmp (filename + (strlen (filename)-4), ".vol") != 0 ) */ { +#ifdef PARALLEL + if(ntasks>1) + throw NgException("Not sure what to do with this?? Does this work with MPI??"); +#endif mesh.reset (new Mesh()); ReadFile(*mesh,filename); @@ -146,13 +157,22 @@ void Ng_LoadMesh (const char * filename) string fn(filename); - istream * infile; if (fn.substr (fn.length()-3, 3) == ".gz") infile = new igzstream (filename); else infile = new ifstream (filename); + + // Ng_LoadMeshFromStream(*infile); + mesh.reset (new Mesh()); + mesh -> Load(*infile); - Ng_LoadMeshFromStream(*infile); + stringstream geom_part; + geom_part << infile->rdbuf(); + string geom_part_string = geom_part.str(); + strs = geom_part_string.size(); + buf = new char[strs]; + memcpy(buf, geom_part_string.c_str(), strs*sizeof(char)); + delete infile; #ifdef PARALLEL @@ -222,11 +242,34 @@ void Ng_LoadMesh (const char * filename) else { mesh.reset (new Mesh()); -// vssolution.SetMesh(mesh); -// vsmesh.SetMesh(mesh); + // vssolution.SetMesh(mesh); + // vsmesh.SetMesh(mesh); SetGlobalMesh (mesh); mesh->SendRecvMesh(); } + if(ntasks>1) { + /** Scatter the geometry-string **/ + MPI_Bcast(&strs, 1, MPI_INT, 0, MPI_COMM_WORLD); + if(id!=0) + buf = new char[strs]; + MPI_Bcast(buf, strs, MPI_CHAR, 0, MPI_COMM_WORLD); + infile = new istringstream(string((const char*)buf, (size_t)strs)); + delete[] buf; + for (int i = 0; i < geometryregister.Size(); i++) + { + NetgenGeometry * hgeom = geometryregister[i]->LoadFromMeshFile (*infile); + if (hgeom) + { + ng_geometry.reset (hgeom); + mesh->SetGeometry(ng_geometry); + break; + } + } + if (!ng_geometry) + ng_geometry = make_shared(); + mesh->SetGeometry(ng_geometry); + delete infile; + } #endif } From 30928eaaa84a423a7e5bf7344e7c0a7fb04fd4e2 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 12 Jun 2018 11:11:36 +0200 Subject: [PATCH 2/7] Fixed it --- libsrc/interface/nginterface.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 46228f79..ce3ad450 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -247,12 +247,15 @@ void Ng_LoadMesh (const char * filename) SetGlobalMesh (mesh); mesh->SendRecvMesh(); } + if(ntasks>1) { /** Scatter the geometry-string **/ MPI_Bcast(&strs, 1, MPI_INT, 0, MPI_COMM_WORLD); if(id!=0) buf = new char[strs]; MPI_Bcast(buf, strs, MPI_CHAR, 0, MPI_COMM_WORLD); +} +#endif infile = new istringstream(string((const char*)buf, (size_t)strs)); delete[] buf; for (int i = 0; i < geometryregister.Size(); i++) @@ -269,8 +272,6 @@ void Ng_LoadMesh (const char * filename) ng_geometry = make_shared(); mesh->SetGeometry(ng_geometry); delete infile; - } -#endif } void Ng_LoadMeshFromString (const char * mesh_as_string) From 89c7626a017d660c8d32ca92926d28963f679c3d Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 12 Jun 2018 11:18:13 +0200 Subject: [PATCH 3/7] Fixed it now? --- libsrc/interface/nginterface.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index ce3ad450..e69edec8 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -126,13 +126,15 @@ void Ng_LoadMesh (const char * filename) if(!infile.good()) throw NgException(string("Error opening file ") + filename); } + + istream * infile; + #ifdef PARALLEL MPI_Comm_size(MPI_COMM_WORLD, &ntasks); MPI_Comm_rank(MPI_COMM_WORLD, &id); char* buf; // for distributing geometry! int strs; - istream * infile; if (id == 0) { From 7e062372d4eb9f012ec7e09fe9b2ba55127b3751 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 12 Jun 2018 11:28:51 +0200 Subject: [PATCH 4/7] Fixed it now? --- libsrc/interface/nginterface.cpp | 5 ++--- libsrc/meshing/meshclass.cpp | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index e69edec8..f7dbe77b 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -128,14 +128,13 @@ void Ng_LoadMesh (const char * filename) } istream * infile; + char* buf; // for distributing geometry! + int strs; #ifdef PARALLEL MPI_Comm_size(MPI_COMM_WORLD, &ntasks); MPI_Comm_rank(MPI_COMM_WORLD, &id); - char* buf; // for distributing geometry! - int strs; - if (id == 0) { #endif diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index a89a6ff3..a3d96dd7 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -5856,6 +5856,8 @@ namespace netgen { if (!GetGeometry()) throw NgException ("don't have a geometry for mesh curving"); + + cout << "Build Curved Elements, order = " << aorder << endl; GetCurvedElements().BuildCurvedElements (&GetGeometry()->GetRefinement(), aorder, false); From 160a4b73fd16d542449a9466095332af16196c00 Mon Sep 17 00:00:00 2001 From: Lukas Kogler Date: Tue, 12 Jun 2018 11:37:14 +0200 Subject: [PATCH 5/7] Update meshclass.cpp --- libsrc/meshing/meshclass.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index a3d96dd7..a89a6ff3 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -5856,8 +5856,6 @@ namespace netgen { if (!GetGeometry()) throw NgException ("don't have a geometry for mesh curving"); - - cout << "Build Curved Elements, order = " << aorder << endl; GetCurvedElements().BuildCurvedElements (&GetGeometry()->GetRefinement(), aorder, false); From ebc6506f3e58142318c5c32a5e0b815928644681 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 12 Jun 2018 13:10:41 +0200 Subject: [PATCH 6/7] Forced linking of 2d-library to interface-library (this should solve the problem with SplineGeometryRegister if building without GUI) --- libsrc/interface/nginterface.cpp | 230 +++++++++++++++---------------- libsrc/meshing/meshclass.cpp | 2 - 2 files changed, 113 insertions(+), 119 deletions(-) diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index f7dbe77b..41ad68f7 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -2,7 +2,7 @@ #include #include - +#include #ifdef SOCKETS #include "../sockets/sockets.hpp" @@ -17,6 +17,9 @@ namespace netgen { DLL_HEADER MeshingParameters mparam; + + /** Force linking of geom2d library (for SplineGeometryRegister)**/ + SplineGeometry2d dummy_2dgeom; } static std::thread meshingthread; @@ -69,8 +72,6 @@ using namespace netgen; void Ng_LoadGeometry (const char * filename) { - cout << endl << "LOAD GEOMETRY FROM FILE " << filename << endl; - // he: if filename is empty, return // can be used to reset geometry if (!filename || strcmp(filename,"")==0) @@ -78,7 +79,7 @@ void Ng_LoadGeometry (const char * filename) ng_geometry.reset (new NetgenGeometry()); return; } - + for (int i = 0; i < geometryregister.Size(); i++) { NetgenGeometry * hgeom = geometryregister[i]->Load (filename); @@ -90,7 +91,6 @@ void Ng_LoadGeometry (const char * filename) } } - // if (id == 0) cerr << "cannot load geometry '" << filename << "'" << ", id = " << id << endl; } @@ -121,142 +121,136 @@ void Ng_LoadMeshFromStream ( istream & input ) void Ng_LoadMesh (const char * filename) { +#ifdef PARALLEL + MPI_Comm_size(MPI_COMM_WORLD, &ntasks); + MPI_Comm_rank(MPI_COMM_WORLD, &id); +#endif + { - ifstream infile(filename); - if(!infile.good()) - throw NgException(string("Error opening file ") + filename); + ifstream infile(filename); + if(!infile.good()) + throw NgException(string("Error opening file ") + filename); } - + + if ( string(filename).find(".vol") == string::npos ) + { +#ifdef PARALLEL + if(ntasks>1) + throw NgException("Not sure what to do with this?? Does this work with MPI??"); +#endif + mesh.reset (new Mesh()); + ReadFile(*mesh,filename); + //mesh->SetGlobalH (mparam.maxh); + //mesh->CalcLocalH(); + return; + } + istream * infile; char* buf; // for distributing geometry! int strs; -#ifdef PARALLEL - MPI_Comm_size(MPI_COMM_WORLD, &ntasks); - MPI_Comm_rank(MPI_COMM_WORLD, &id); + #ifdef PARALLEL + if( id == 0) { + #endif - if (id == 0) - { -#endif - if ( string(filename).find(".vol") == string::npos ) - /* - if ( (strlen (filename) > 4) && - strcmp (filename + (strlen (filename)-4), ".vol") != 0 ) - */ - { -#ifdef PARALLEL - if(ntasks>1) - throw NgException("Not sure what to do with this?? Does this work with MPI??"); -#endif - mesh.reset (new Mesh()); - ReadFile(*mesh,filename); - - //mesh->SetGlobalH (mparam.maxh); - //mesh->CalcLocalH(); - return; - } - - string fn(filename); - - if (fn.substr (fn.length()-3, 3) == ".gz") - infile = new igzstream (filename); - else - infile = new ifstream (filename); - - // Ng_LoadMeshFromStream(*infile); - mesh.reset (new Mesh()); - mesh -> Load(*infile); + string fn(filename); + if (fn.substr (fn.length()-3, 3) == ".gz") + infile = new igzstream (filename); + else + infile = new ifstream (filename); + mesh.reset (new Mesh()); + mesh -> Load(*infile); + // make string from rest of file (for geometry info!) + if(!ng_geometry) { stringstream geom_part; geom_part << infile->rdbuf(); string geom_part_string = geom_part.str(); strs = geom_part_string.size(); buf = new char[strs]; memcpy(buf, geom_part_string.c_str(), strs*sizeof(char)); - - delete infile; - + } + delete infile; + #ifdef PARALLEL - if (ntasks > 1) - { + if (ntasks > 1) + { - char * weightsfilename = new char [strlen(filename)+1]; - strcpy (weightsfilename, filename); - weightsfilename[strlen (weightsfilename)-3] = 'w'; - weightsfilename[strlen (weightsfilename)-2] = 'e'; - weightsfilename[strlen (weightsfilename)-1] = 'i'; + char * weightsfilename = new char [strlen(filename)+1]; + strcpy (weightsfilename, filename); + weightsfilename[strlen (weightsfilename)-3] = 'w'; + weightsfilename[strlen (weightsfilename)-2] = 'e'; + weightsfilename[strlen (weightsfilename)-1] = 'i'; - ifstream weightsfile(weightsfilename); - delete [] weightsfilename; + ifstream weightsfile(weightsfilename); + delete [] weightsfilename; - if (!(weightsfile.good())) - { - // cout << "regular distribute" << endl; - mesh -> Distribute(); - } - else - { - char str[20]; - bool endfile = false; - int n, dummy; + if (!(weightsfile.good())) + { + // cout << "regular distribute" << endl; + mesh -> Distribute(); + } + else + { + char str[20]; + bool endfile = false; + int n, dummy; - Array segment_weights; - Array surface_weights; - Array volume_weights; + Array segment_weights; + Array surface_weights; + Array volume_weights; - while (weightsfile.good() && !endfile) - { - weightsfile >> str; + while (weightsfile.good() && !endfile) + { + weightsfile >> str; - if (strcmp (str, "edgeweights") == 0) - { - weightsfile >> n; - segment_weights.SetSize(n); - for (int i = 0; i < n; i++) - weightsfile >> dummy >> segment_weights[i]; - } + if (strcmp (str, "edgeweights") == 0) + { + weightsfile >> n; + segment_weights.SetSize(n); + for (int i = 0; i < n; i++) + weightsfile >> dummy >> segment_weights[i]; + } - if (strcmp (str, "surfaceweights") == 0) - { - weightsfile >> n; - surface_weights.SetSize(n); - for (int i=0; i> dummy >> surface_weights[i]; - } + if (strcmp (str, "surfaceweights") == 0) + { + weightsfile >> n; + surface_weights.SetSize(n); + for (int i=0; i> dummy >> surface_weights[i]; + } - if (strcmp (str, "volumeweights") == 0) - { - weightsfile >> n; - volume_weights.SetSize(n); - for (int i=0; i> dummy >> volume_weights[i]; - } + if (strcmp (str, "volumeweights") == 0) + { + weightsfile >> n; + volume_weights.SetSize(n); + for (int i=0; i> dummy >> volume_weights[i]; + } - if (strcmp (str, "endfile") == 0) - endfile = true; - } + if (strcmp (str, "endfile") == 0) + endfile = true; + } - mesh -> Distribute(volume_weights, surface_weights, segment_weights); - } - } - } - else - { - mesh.reset (new Mesh()); - // vssolution.SetMesh(mesh); - // vsmesh.SetMesh(mesh); - SetGlobalMesh (mesh); - mesh->SendRecvMesh(); - } + mesh -> Distribute(volume_weights, surface_weights, segment_weights); + } + } // ntasks>1 end + } // id==0 end + else { + mesh.reset (new Mesh()); + SetGlobalMesh (mesh); + mesh->SendRecvMesh(); + } - if(ntasks>1) { + if(!ng_geometry && ntasks>1) { /** Scatter the geometry-string **/ MPI_Bcast(&strs, 1, MPI_INT, 0, MPI_COMM_WORLD); - if(id!=0) - buf = new char[strs]; + if(id!=0) buf = new char[strs]; MPI_Bcast(buf, strs, MPI_CHAR, 0, MPI_COMM_WORLD); -} + } #endif + + if(!ng_geometry) { infile = new istringstream(string((const char*)buf, (size_t)strs)); delete[] buf; for (int i = 0; i < geometryregister.Size(); i++) @@ -269,18 +263,20 @@ void Ng_LoadMesh (const char * filename) break; } } - if (!ng_geometry) - ng_geometry = make_shared(); + } + /** Dummy Geometry if we still could not find any geometry info! **/ + // if (!ng_geometry) + // ng_geometry = make_shared(); + if(ng_geometry) mesh->SetGeometry(ng_geometry); - delete infile; } -void Ng_LoadMeshFromString (const char * mesh_as_string) -{ + void Ng_LoadMeshFromString (const char * mesh_as_string) + { istringstream instream(mesh_as_string); Ng_LoadMeshFromStream(instream); } - + diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index a3d96dd7..a89a6ff3 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -5856,8 +5856,6 @@ namespace netgen { if (!GetGeometry()) throw NgException ("don't have a geometry for mesh curving"); - - cout << "Build Curved Elements, order = " << aorder << endl; GetCurvedElements().BuildCurvedElements (&GetGeometry()->GetRefinement(), aorder, false); From 68a552c7d65eeb9720d5f8f4c16bc5df35ffcc92 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 12 Jun 2018 13:13:42 +0200 Subject: [PATCH 7/7] Fixed indentions, etc. --- libsrc/interface/nginterface.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index 41ad68f7..58d957f0 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -71,7 +71,6 @@ using namespace netgen; void Ng_LoadGeometry (const char * filename) { - // he: if filename is empty, return // can be used to reset geometry if (!filename || strcmp(filename,"")==0) @@ -79,7 +78,7 @@ void Ng_LoadGeometry (const char * filename) ng_geometry.reset (new NetgenGeometry()); return; } - + for (int i = 0; i < geometryregister.Size(); i++) { NetgenGeometry * hgeom = geometryregister[i]->Load (filename); @@ -91,6 +90,7 @@ void Ng_LoadGeometry (const char * filename) } } + // if (id == 0) cerr << "cannot load geometry '" << filename << "'" << ", id = " << id << endl; } @@ -271,12 +271,12 @@ void Ng_LoadMesh (const char * filename) mesh->SetGeometry(ng_geometry); } - void Ng_LoadMeshFromString (const char * mesh_as_string) - { +void Ng_LoadMeshFromString (const char * mesh_as_string) +{ istringstream instream(mesh_as_string); Ng_LoadMeshFromStream(instream); } - +