From 29c6b8e06fa7525ef93aac050d8379cc66f89e1c Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Mon, 25 Mar 2024 18:00:26 +0100 Subject: [PATCH] Fix Mesh::operator= bcnames are now stored in FaceDescriptor (as string members, no pointers), so the name mapping must be applied to materials/bcnames (depending on the mesh dimension). --- libsrc/meshing/meshclass.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index c51c0ae16..ac8277b22 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -319,26 +319,27 @@ namespace netgen hmin = mesh2.hmin; maxhdomain = mesh2.maxhdomain; + // Remap string* values to new mesh + std::map names_map; + for (auto fi : Range(facedecoding)) + names_map[&mesh2.facedecoding[fi].bcname] = &facedecoding[fi].bcname; materials.SetSize( mesh2.materials.Size() ); for ( int i = 0; i < mesh2.materials.Size(); i++ ) - if ( mesh2.materials[i] ) materials[i] = new string ( *mesh2.materials[i] ); + { + const string * old_name = mesh2.materials[i]; + if ( old_name ) materials[i] = dimension == 2 ? names_map[old_name] : new string ( *old_name ); else materials[i] = 0; + } - std::map bcmap; bcnames.SetSize( mesh2.bcnames.Size() ); for ( int i = 0; i < mesh2.bcnames.Size(); i++ ) { - if ( mesh2.bcnames[i] ) bcnames[i] = new string ( *mesh2.bcnames[i] ); + const string * old_name = mesh2.bcnames[i]; + if ( old_name ) bcnames[i] = dimension == 3 ? names_map[old_name] : new string ( *old_name ); 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()); for (int i=0; i < mesh2.cd2names.Size(); i++) if (mesh2.cd2names[i]) cd2names[i] = new string(*mesh2.cd2names[i]);