Created
January 12, 2017 01:41
-
-
Save bgranzow/98087114166956646da684ed98acab02 to your computer and use it in GitHub Desktop.
Convert from a mesh tag to a mesh field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gmi_mesh.h> | |
#include <apfMDS.h> | |
#include <apfMesh2.h> | |
#include <apf.h> | |
#include <PCU.h> | |
#include <cassert> | |
apf::MeshTag* create_my_tag(apf::Mesh* m) { | |
apf::MeshTag* tag = m->createDoubleTag("my_tag", 1); | |
apf::MeshEntity* vtx; | |
apf::MeshIterator* it = m->begin(0); | |
double vals[1]; | |
vals[0] = 1.0; | |
while ((vtx = m->iterate(it))) | |
m->setDoubleTag(vtx, tag, vals); | |
m->end(it); | |
return tag; | |
} | |
apf::Field* convert_my_tag(apf::Mesh* m, apf::MeshTag* t) { | |
apf::MeshEntity* vtx; | |
apf::MeshIterator* it = m->begin(0); | |
apf::Field* f = apf::createLagrangeField(m, "my_field", apf::SCALAR, 1); | |
double vals[1]; | |
while ((vtx = m->iterate(it))) { | |
m->getDoubleTag(vtx, t, vals); | |
apf::setComponents(f, vtx, 0, vals); | |
} | |
m->end(it); | |
return f; | |
} | |
int main(int argc, char** argv) { | |
assert(argc==3); | |
MPI_Init(&argc, &argv); | |
PCU_Comm_Init(); | |
gmi_register_mesh(); | |
apf::Mesh2* m = apf::loadMdsMesh(argv[1],argv[2]); | |
m->verify(); | |
apf::MeshTag* my_tag = create_my_tag(m); | |
convert_my_tag(m, my_tag); | |
apf::writeVtkFiles("output", m); | |
m->destroyNative(); | |
apf::destroyMesh(m); | |
PCU_Comm_Free(); | |
MPI_Finalize(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment