Thank you for your answer. Your strategy worked perfectly. I ended up using the following block of code to renumber the mesh.
// The mapping is stored in the vector new_to_old, where // new_to_old[elem_old_id] = elem_new_id. // Also _mesh.prepare_for_use is already called once because // it was needed to find the mapping. // add an element to increase the size const int n_elem = _mesh.n_elem(); Elem *e = new Edge2; e->set_id( n_elem*2); _mesh.add_elem(e); // shift all elements for(int ie = 0 ; ie < n_elem ; ie++) { _mesh.renumber_elem(ie, ie+n_elem); } // move elements back to their new numbering for(int inew = 0 ; inew < n_elem ; inew++) { const int iold = new_to_old[inew]+n_elem; _mesh.renumber_elem(iold, inew); } // delete the dummy element _mesh.delete_elem(e); // remove the extra elements _mesh.prepare_for_use(...); On Sat, Aug 6, 2016 at 9:01 AM, Roy Stogner <royst...@ices.utexas.edu> wrote: > > On Fri, 5 Aug 2016, Shayan Hoshyari wrote: > > Is there any functionality in libMesh for renumbering the elements in a >> SerialMesh? Given that I already know the mapping old_id -> new_id ? >> > > The renumber_elem() API is probably what you're looking for. You may > need to use a "placeholder" number, though, to avoid overwrites. E.g. > if you wanted to swap elements 0 and 1 in a 2 element mesh then you'd > need > renumber_elem(0,2); > renumber_elem(1,0); > renumber_elem(2,1); > > Because if you just tried "renumber_elem(0,1);" then you'd fail an > assert in devel mode or have a corrupt mesh in opt mode. > > You'll also want to set allow_renumbering(false) on the mesh so > libMesh doesn't override your preferences during any subsequent > reinits. > > We'd appreciate bug reports if that doesn't work and/or unit tests if > it does work; AFAIK renumber_elem() is currently only used internally. > --- > Roy > -- Shayan Hoshyari MASC MECH Student UBC, Canada http://tetra.mech.ubc.ca/projects/ANSLab/ ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. http://sdm.link/zohodev2dev _______________________________________________ Libmesh-users mailing list Libmesh-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libmesh-users