Merge branch 'fix_mesh_copy' into 'master'

Fix mesh copy

See merge request jschoeberl/netgen!328
This commit is contained in:
Joachim Schöberl 2020-07-23 18:08:29 +00:00
commit 6989bde831
9 changed files with 32 additions and 58 deletions

View File

@ -404,6 +404,8 @@ if(USE_CGNS)
endif(NOT WIN32 AND NOT APPLE) endif(NOT WIN32 AND NOT APPLE)
endif(USE_CGNS) endif(USE_CGNS)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/netgen_version.hpp DESTINATION ${NG_INSTALL_DIR_INCLUDE}/include COMPONENT netgen_devel)
add_subdirectory(libsrc) add_subdirectory(libsrc)
add_subdirectory(ng) add_subdirectory(ng)
add_subdirectory(tutorials) add_subdirectory(tutorials)

View File

@ -36,7 +36,17 @@ endif()
set(NETGEN_VERSION_LONG ${NETGEN_VERSION_SHORT}-${NETGEN_VERSION_TWEAK}-${NETGEN_VERSION_HASH}) set(NETGEN_VERSION_LONG ${NETGEN_VERSION_SHORT}-${NETGEN_VERSION_TWEAK}-${NETGEN_VERSION_HASH})
set(version_file ${BDIR}/netgen_version.hpp) set(version_file ${BDIR}/netgen_version.hpp)
set(new_version_file_string "#define NETGEN_VERSION \"${NETGEN_VERSION}\"\n") set(new_version_file_string "\
#ifndef NETGEN_VERSION_HPP_INCLUDED
#define NETGEN_VERSION_HPP_INCLUDED
#define NETGEN_VERSION \"${NETGEN_VERSION}\"
#define NETGEN_VERSION_MAJOR ${NETGEN_VERSION_MAJOR}
#define NETGEN_VERSION_MINOR ${NETGEN_VERSION_MINOR}
#define NETGEN_VERSION_PATCH ${NETGEN_VERSION_PATCH}
#define NETGEN_VERSION_TWEAK ${NETGEN_VERSION_TWEAK}
#define NETGEN_VERSION_HASH \"${NETGEN_VERSION_HASH}\"
#endif // NETGEN_VERSION_HPP_INCLUDED
")
if(EXISTS ${version_file}) if(EXISTS ${version_file})
file(READ ${version_file} old_version_file_string ) file(READ ${version_file} old_version_file_string )
if(${old_version_file_string} STREQUAL ${new_version_file_string}) if(${old_version_file_string} STREQUAL ${new_version_file_string})

View File

@ -1,5 +1,6 @@
#include "archive.hpp" #include "archive.hpp"
#include <netgen_version.hpp>
#ifndef WIN32 #ifndef WIN32
#include <cxxabi.h> #include <cxxabi.h>
@ -44,4 +45,10 @@ namespace ngcore
std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>(); std::make_unique<std::map<std::string, detail::ClassArchiveInfo>>();
return type_register->count(classname) != 0; return type_register->count(classname) != 0;
} }
static bool dummy = [](){
SetLibraryVersion("netgen", NETGEN_VERSION);
return true;
}();
} // namespace ngcore } // namespace ngcore

View File

@ -458,9 +458,6 @@ namespace netgen
for ( int sindex = 0; sindex < maxsegmentindex; sindex++ ) for ( int sindex = 0; sindex < maxsegmentindex; sindex++ )
mesh->SetBCName ( sindex, geometry.GetBCName( sindex+1 ) ); mesh->SetBCName ( sindex, geometry.GetBCName( sindex+1 ) );
for (SegmentIndex si = 0; si < mesh->GetNSeg(); si++)
(*mesh)[si].SetBCName ( (*mesh).GetBCNamePtr( (*mesh)[si].si-1 ) );
mesh->CalcLocalH(mp.grading); mesh->CalcLocalH(mp.grading);
int bnp = mesh->GetNP(); // boundary points int bnp = mesh->GetNP(); // boundary points

View File

@ -560,7 +560,7 @@ char * Ng_GetSurfaceElementBCName (int ei)
if ( mesh->GetDimension() == 3 ) if ( mesh->GetDimension() == 3 )
return const_cast<char *>(mesh->GetFaceDescriptor(mesh->SurfaceElement(ei).GetIndex()).GetBCName().c_str()); return const_cast<char *>(mesh->GetFaceDescriptor(mesh->SurfaceElement(ei).GetIndex()).GetBCName().c_str());
else else
return const_cast<char *>(mesh->LineSegment(ei).GetBCName().c_str()); return const_cast<char *>(mesh->GetBCName(mesh->LineSegment(ei).si).c_str());
} }

View File

@ -313,7 +313,6 @@ namespace netgen
ednr = mesh.AddEdgeDescriptor(ed); ednr = mesh.AddEdgeDescriptor(ed);
mesh.SetCD2Name(bcpr, name); mesh.SetCD2Name(bcpr, name);
auto nr = mesh.AddSegment(tmp_segments[get<0>(element_map[index])-1]); auto nr = mesh.AddSegment(tmp_segments[get<0>(element_map[index])-1]);
mesh[nr].SetBCName(mesh.GetCD2NamePtr(mesh.GetNCD2Names()));
mesh[nr].edgenr = ednr+1; mesh[nr].edgenr = ednr+1;
} }
else if(dim == 2) else if(dim == 2)
@ -321,7 +320,6 @@ namespace netgen
Segment & seg = mesh.LineSegment(get<0>(element_map[index])); Segment & seg = mesh.LineSegment(get<0>(element_map[index]));
seg.si = bccounter + 1; seg.si = bccounter + 1;
mesh.SetBCName(bccounter, name); mesh.SetBCName(bccounter, name);
seg.SetBCName(mesh.GetBCNamePtr(bccounter));
bccounter++; bccounter++;
} }
break; break;
@ -353,13 +351,11 @@ namespace netgen
{ {
auto nr = mesh.AddSegment(tmp_segments[get<0>(element_map[index])-1]); auto nr = mesh.AddSegment(tmp_segments[get<0>(element_map[index])-1]);
mesh[nr].edgenr = ednr+1; mesh[nr].edgenr = ednr+1;
mesh[nr].SetBCName(mesh.GetCD2NamePtr(mesh.GetNCD2Names()));
} }
else if(dim == 2) else if(dim == 2)
{ {
Segment & seg = mesh.LineSegment(get<0>(element_map[index])); Segment & seg = mesh.LineSegment(get<0>(element_map[index]));
seg.si = bccounter; seg.si = bccounter;
seg.SetBCName(mesh.GetBCNamePtr(bccounter-1));
} }
break; break;
default: default:
@ -388,7 +384,6 @@ namespace netgen
if(seg.si == -1){ if(seg.si == -1){
seg.si = bccounter + 1; seg.si = bccounter + 1;
if(bccounter_tmp == bccounter) mesh.SetBCName(bccounter, "default"); // could be more efficient if(bccounter_tmp == bccounter) mesh.SetBCName(bccounter, "default"); // could be more efficient
seg.SetBCName(mesh.GetBCNamePtr(bccounter));
bccounter_tmp++; bccounter_tmp++;
} }
} }

View File

@ -105,11 +105,18 @@ namespace netgen
if ( mesh2.materials[i] ) materials[i] = new string ( *mesh2.materials[i] ); if ( mesh2.materials[i] ) materials[i] = new string ( *mesh2.materials[i] );
else materials[i] = 0; else materials[i] = 0;
std::map<const string*, string*> bcmap;
bcnames.SetSize( mesh2.bcnames.Size() ); bcnames.SetSize( mesh2.bcnames.Size() );
for ( int i = 0; i < mesh2.bcnames.Size(); i++ ) for ( int i = 0; i < mesh2.bcnames.Size(); i++ )
{
if ( mesh2.bcnames[i] ) bcnames[i] = new string ( *mesh2.bcnames[i] ); if ( mesh2.bcnames[i] ) bcnames[i] = new string ( *mesh2.bcnames[i] );
else bcnames[i] = 0; else bcnames[i] = 0;
bcmap[mesh2.bcnames[i]] = bcnames[i];
}
// Remap string* members in FaceDescriptor to new mesh
for (auto & f : facedecoding)
f.SetBCName( bcmap[&f.GetBCName()] );
cd2names.SetSize(mesh2.cd2names.Size()); cd2names.SetSize(mesh2.cd2names.Size());
@ -1112,18 +1119,7 @@ namespace netgen
bcnames[bcnrs[i-1]-1] = new string(nextbcname); bcnames[bcnrs[i-1]-1] = new string(nextbcname);
} }
if ( GetDimension() == 2 ) if ( GetDimension() == 3 )
{
for (i = 1; i <= GetNSeg(); i++)
{
Segment & seg = LineSegment (i);
if ( seg.si <= n )
seg.SetBCName (bcnames[seg.si-1]);
else
seg.SetBCName(0);
}
}
else
{ {
for (SurfaceElementIndex sei = 0; sei < GetNSE(); sei++) for (SurfaceElementIndex sei = 0; sei < GetNSE(); sei++)
{ {
@ -1156,17 +1152,6 @@ namespace netgen
{ {
throw NgException("co dim 2 elements not implemented for dimension 2"); throw NgException("co dim 2 elements not implemented for dimension 2");
} }
else
{
for (i = 1; i<= GetNSeg(); i++)
{
Segment & seg = LineSegment(i);
if ( seg.edgenr <= n )
seg.SetBCName (cd2names[seg.edgenr-1]);
else
seg.SetBCName(0);
}
}
} }
if (strcmp (str, "singular_points") == 0) if (strcmp (str, "singular_points") == 0)

View File

@ -80,8 +80,6 @@ namespace netgen
epgeominfo[1].edgenr = 1; epgeominfo[1].edgenr = 1;
epgeominfo[1].dist = 0; epgeominfo[1].dist = 0;
*/ */
bcname = nullptr;
} }
Segment::Segment (const Segment & other) Segment::Segment (const Segment & other)
@ -109,7 +107,6 @@ namespace netgen
geominfo[1] = other.geominfo[1]; geominfo[1] = other.geominfo[1];
epgeominfo[0] = other.epgeominfo[0]; epgeominfo[0] = other.epgeominfo[0];
epgeominfo[1] = other.epgeominfo[1]; epgeominfo[1] = other.epgeominfo[1];
bcname = other.bcname;
} }
Segment& Segment::operator=(const Segment & other) Segment& Segment::operator=(const Segment & other)
@ -135,7 +132,6 @@ namespace netgen
pnums[2] = other.pnums[2]; pnums[2] = other.pnums[2];
meshdocval = other.meshdocval; meshdocval = other.meshdocval;
hp_elnr = other.hp_elnr; hp_elnr = other.hp_elnr;
bcname = other.bcname;
is_curved = other.is_curved; is_curved = other.is_curved;
} }
@ -144,11 +140,12 @@ namespace netgen
void Segment :: DoArchive (Archive & ar) void Segment :: DoArchive (Archive & ar)
{ {
string * bcname_dummy = nullptr;
ar & pnums[0] & pnums[1] & pnums[2] ar & pnums[0] & pnums[1] & pnums[2]
& edgenr & singedge_left & singedge_right & edgenr & singedge_left & singedge_right
& si & cd2i & domin & domout & tlosurf & si & cd2i & domin & domout & tlosurf
& surfnr1 & surfnr2 & surfnr1 & surfnr2
& bcname & bcname_dummy // keep this for backward compatiblity
& epgeominfo[0].edgenr & epgeominfo[1].edgenr; & epgeominfo[0].edgenr & epgeominfo[1].edgenr;
} }

View File

@ -1031,7 +1031,6 @@ namespace netgen
// #endif // #endif
private: private:
string* bcname;
bool is_curved; bool is_curved;
public: public:
@ -1048,24 +1047,6 @@ namespace netgen
int hp_elnr; int hp_elnr;
void SetBCName ( string * abcname )
{
bcname = abcname;
}
string * BCNamePtr ()
{ return bcname; }
const string * BCNamePtr () const
{ return bcname; }
const string & GetBCName () const
{
static string defaultstring = "default";
if (! bcname ) return defaultstring;
return *bcname;
}
int GetNP() const int GetNP() const
{ {
return pnums[2].IsValid() ? 3 : 2; return pnums[2].IsValid() ? 3 : 2;