77#include " apfNumbering.h"
88#include < map>
99#include < pcu_util.h>
10+ #include < iostream>
1011
1112namespace apf {
1213
@@ -31,6 +32,9 @@ class Converter
3132 convertFields ();
3233 convertNumberings ();
3334 convertGlobalNumberings ();
35+ // this must be called after anything that might create tags e.g. fields
36+ // or numberings to avoid problems with tag duplication
37+ convertTags ();
3438 outMesh->acceptChanges ();
3539 }
3640 ModelEntity* getNewModelFromOld (ModelEntity* oldC)
@@ -210,6 +214,48 @@ class Converter
210214 }
211215 }
212216 }
217+ void convertTag (Mesh* inMesh, MeshTag* in, Mesh* outMesh, MeshTag* out)
218+ {
219+ for (int d = 0 ; d <= 3 ; ++d) {
220+ int tagType = inMesh->getTagType (in);
221+ int tagSize = inMesh->getTagSize (in);
222+ PCU_DEBUG_ASSERT (tagType == outMesh->getTagType (out));
223+ PCU_DEBUG_ASSERT (tagSize == outMesh->getTagSize (out));
224+ MeshIterator* it = inMesh->begin (d);
225+ MeshEntity* e;
226+ while ((e = inMesh->iterate(it))) {
227+ if (inMesh->hasTag (e, in)) {
228+ // these initializations cannot go into the cases due to compiler
229+ // warnings on gcc 7.3.0
230+ double * dblData;
231+ int * intData;
232+ long * lngData;
233+ switch (tagType) {
234+ case apf::Mesh::TagType::DOUBLE:
235+ dblData = new double [tagSize];
236+ inMesh->getDoubleTag (e, in, dblData);
237+ outMesh->setDoubleTag (newFromOld[e], out, dblData);
238+ break ;
239+ case apf::Mesh::TagType::INT:
240+ intData = new int [tagSize];
241+ inMesh->getIntTag (e, in, intData);
242+ outMesh->setIntTag (newFromOld[e], out, intData);
243+ break ;
244+ case apf::Mesh::TagType::LONG:
245+ lngData = new long [tagSize];
246+ inMesh->getLongTag (e, in, lngData);
247+ outMesh->setLongTag (newFromOld[e], out, lngData);
248+ break ;
249+ default :
250+ std::cerr << " Tried to convert unknown tag type\n " ;
251+ abort ();
252+ break ;
253+ }
254+ }
255+ }
256+ inMesh->end (it);
257+ }
258+ }
213259 void convertFields ()
214260 {
215261 for (int i = 0 ; i < inMesh->countFields (); ++i) {
@@ -222,20 +268,76 @@ class Converter
222268 {
223269 for (int i = 0 ; i < inMesh->countNumberings (); ++i) {
224270 Numbering* in = inMesh->getNumbering (i);
225- Numbering* out = createNumbering (outMesh,
226- getName (in), getShape (in), countComponents (in));
271+ Numbering* out;
272+ if (getField (in)) {
273+ // here we assume that the fields have already been copied into the
274+ // mesh
275+ Field* outField = outMesh->findField (getName (getField (in)));
276+ PCU_DEBUG_ASSERT (outField);
277+ out = createNumbering (outField);
278+ }
279+ else {
280+ out = createNumbering (outMesh, getName (in), getShape (in),
281+ countComponents (in));
282+ }
227283 convertNumbering (in, out);
228284 }
229285 }
230286 void convertGlobalNumberings ()
231287 {
232288 for (int i = 0 ; i < inMesh->countGlobalNumberings (); ++i) {
233289 GlobalNumbering* in = inMesh->getGlobalNumbering (i);
234- GlobalNumbering* out = createGlobalNumbering (outMesh,
235- getName (in), getShape (in), countComponents (in));
290+ GlobalNumbering* out;
291+ if (getField (in)) {
292+ // here we assume that the fields have already been copied into the
293+ // mesh
294+ Field* outField = outMesh->findField (getName (getField (in)));
295+ PCU_DEBUG_ASSERT (outField);
296+ out = createGlobalNumbering (outField);
297+ }
298+ else {
299+ out = createGlobalNumbering (outMesh, getName (in), getShape (in),
300+ countComponents (in));
301+ }
236302 convertGlobalNumbering (in, out);
237303 }
238304 }
305+ void convertTags ()
306+ {
307+ DynamicArray<MeshTag*> tags;
308+ inMesh->getTags (tags);
309+ for (std::size_t i = 0 ; i < tags.getSize (); ++i) {
310+ apf::MeshTag* in = tags[i];
311+ PCU_DEBUG_ASSERT (in);
312+ // create a new tag on the outMesh
313+ int tagType = inMesh->getTagType (in);
314+ int tagSize = inMesh->getTagSize (in);
315+ const char * tagName = inMesh->getTagName (in);
316+ PCU_DEBUG_ASSERT (tagName);
317+ // need to make sure that the tag wasn't already created by a field or
318+ // numbering
319+ if (!outMesh->findTag (tagName)) {
320+ apf::MeshTag* out = NULL ;
321+ switch (tagType) {
322+ case apf::Mesh::TagType::DOUBLE:
323+ out = outMesh->createDoubleTag (tagName, tagSize);
324+ break ;
325+ case apf::Mesh::TagType::INT:
326+ out = outMesh->createIntTag (tagName, tagSize);
327+ break ;
328+ case apf::Mesh::TagType::LONG:
329+ out = outMesh->createLongTag (tagName, tagSize);
330+ break ;
331+ default :
332+ std::cerr << " Tried to convert unknown tag type\n " ;
333+ abort ();
334+ }
335+ PCU_DEBUG_ASSERT (out);
336+ // copy the tag on the inMesh to the outMesh
337+ convertTag (inMesh, in, outMesh, out);
338+ }
339+ }
340+ }
239341 void convertQuadratic ()
240342 {
241343 if (inMesh->getShape () != getLagrange (2 ) && inMesh->getShape () != getSerendipity ())
0 commit comments