15#include <yaml-cpp/yaml.h>
43 const std::string &name,
const PetscInt &dim,
45 const PetscInt &bg,
const PetscInt &ed,
46 const PetscInt &step);
48int main(
int argc,
char **argv)
52 ierr = PetscInitialize(&argc, &argv,
nullptr,
nullptr); CHKERRQ(ierr);
67 ierr = PetscOptionsGetInt(
nullptr,
nullptr,
"-bg", &bg, &isSet);
69 if (!isSet) bg = setting[
"parameters"][
"startStep"].as<PetscInt>(0);
70 ierr = PetscOptionsGetInt(
nullptr,
nullptr,
"-ed", &ed, &isSet);
72 if (!isSet) ed = bg + setting[
"parameters"][
"nt"].as<PetscInt>();
73 ierr = PetscOptionsGetInt(
nullptr,
nullptr,
"-step", &step, &isSet);
75 if (!isSet) step = setting[
"parameters"][
"nsave"].as<PetscInt>();
79 mesh->dim, mesh->n[0], bg, ed, step); CHKERRQ(ierr);
83 mesh->dim, mesh->n[1], bg, ed, step); CHKERRQ(ierr);
87 mesh->dim, mesh->n[3], bg, ed, step); CHKERRQ(ierr);
92 wn[0] = mesh->n[4][0];
93 wn[1] = mesh->n[4][1];
94 wn[2] = mesh->n[3][2];
96 mesh->dim, wn, bg, ed, step); CHKERRQ(ierr);
102 mesh->dim, mesh->n[2], bg, ed, step);
106 wn[0] = mesh->n[3][0];
107 wn[1] = mesh->n[4][1];
108 wn[2] = mesh->n[4][2];
110 mesh->dim, wn, bg, ed, step); CHKERRQ(ierr);
113 wn[0] = mesh->n[4][0];
114 wn[1] = mesh->n[3][1];
115 wn[2] = mesh->n[4][2];
117 mesh->dim, wn, bg, ed, step); CHKERRQ(ierr);
121 ierr = mesh->destroy(); CHKERRQ(ierr);
123 ierr = PetscFinalize(); CHKERRQ(ierr);
129 const std::string &name,
const PetscInt &dim,
131 const PetscInt &bg,
const PetscInt &ed,
132 const PetscInt &step)
136 PetscFunctionBeginUser;
140 std::string file = directory +
"/" + name +
".xmf";
142 ierr = PetscViewerASCIIOpen(PETSC_COMM_WORLD, file.c_str(), &viewer);
146 ierr = PetscViewerASCIIPrintf(viewer,
"<?xml version=\'1.0\' ?>\n\n");
150 ierr = PetscViewerASCIIPrintf(viewer,
151 "<!DOCTYPE Xdmf SYSTEM \"Xdmf.dtd\" [\n");
153 ierr = PetscViewerASCIIPrintf(viewer,
"\t<!ENTITY CaseDir \"./\">\n");
157 for (
int i = 0; i < 3; ++i)
159 ierr = PetscViewerASCIIPrintf(
160 viewer,
"\t<!ENTITY N%s \"%d\">\n",
166 ierr = PetscViewerASCIIPrintf(
168 "\t<!ENTITY Topo \"<Topology TopologyType=\'3DRectMesh\' "
169 "Dimensions=\'&Nz; &Ny; &Nx;\'/>\">\n"); CHKERRQ(ierr);
172 ierr = PetscViewerASCIIPrintf(viewer,
"\t<!ENTITY Geo\n"); CHKERRQ(ierr);
173 ierr = PetscViewerASCIIPrintf(viewer,
174 "\t\t\"<Geometry GeometryType=\'VXVYVZ\'>\n");
177 for (
int i = 0; i < dim; ++i)
180 ierr = PetscViewerASCIIPrintf(
183 "<DataItem Dimensions=\'&N%s;\' Format=\'HDF\' Precision=\'8\'>\n"
184 "\t\t\t\t&CaseDir;/grid.h5:/%s/%s\n"
185 "\t\t\t</DataItem>\n",
186 dir.c_str(), name.c_str(), dir.c_str()); CHKERRQ(ierr);
191 ierr = PetscViewerASCIIPrintf(
194 "<DataItem Dimensions=\'&Nz;\' Format=\'XML\' Precision=\'8\'>\n"
196 "\t\t\t</DataItem>\n"); CHKERRQ(ierr);
198 ierr = PetscViewerASCIIPrintf(viewer,
"\t\t</Geometry>\"\n");
200 ierr = PetscViewerASCIIPrintf(viewer,
"\t>\n"); CHKERRQ(ierr);
203 ierr = PetscViewerASCIIPrintf(viewer,
"]>\n\n"); CHKERRQ(ierr);
206 ierr = PetscViewerASCIIPrintf(viewer,
"<Xdmf Version=\"3.0\">\n");
210 ierr = PetscViewerASCIIPrintf(viewer,
"\t<Domain>\n"); CHKERRQ(ierr);
213 ierr = PetscViewerASCIIPrintf(
216 "<Grid GridType=\"Collection\" CollectionType=\"Temporal\">\n");
220 for (PetscInt t = bg; t <= ed; t += step)
222 ierr = PetscViewerASCIIPrintf(
225 "<Grid GridType=\"Uniform\" Name=\"%s Grid\">\n",
226 name.c_str()); CHKERRQ(ierr);
228 ierr = PetscViewerASCIIPrintf(viewer,
230 "<Time Value=\"%07d\" />\n",
232 ierr = PetscViewerASCIIPrintf(viewer,
"\t\t\t&Topo; &Geo;\n");
234 ierr = PetscViewerASCIIPrintf(
237 "<Attribute Name=\"%s\" AttributeType=\"Scalar\" "
238 "Center=\"Node\">\n",
239 name.c_str()); CHKERRQ(ierr);
241 PetscViewerASCIIPrintf(viewer,
243 "<DataItem Dimensions=\"&Nz; &Ny; &Nx;\" ");
245 ierr = PetscViewerASCIIPrintf(
246 viewer,
"Format=\"HDF\" NumberType=\"Float\" Precision=\"8\">\n");
248 ierr = PetscViewerASCIIPrintf(viewer,
250 "&CaseDir;/%07d.h5:/%s\n",
251 t, name.c_str()); CHKERRQ(ierr);
252 ierr = PetscViewerASCIIPrintf(viewer,
254 "</DataItem>\n"); CHKERRQ(ierr);
255 ierr = PetscViewerASCIIPrintf(viewer,
257 "</Attribute>\n"); CHKERRQ(ierr);
258 ierr = PetscViewerASCIIPrintf(viewer,
260 "</Grid>\n"); CHKERRQ(ierr);
263 ierr = PetscViewerASCIIPrintf(viewer,
"\t</Grid>\n"); CHKERRQ(ierr);
264 ierr = PetscViewerASCIIPrintf(viewer,
"\t</Domain>\n"); CHKERRQ(ierr);
265 ierr = PetscViewerASCIIPrintf(viewer,
"</Xdmf>\n"); CHKERRQ(ierr);
267 ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr);
269 PetscFunctionReturn(0);
int main(int argc, char **argv)
PetscErrorCode writeSingleXDMF(const std::string &directory, const std::string &name, const PetscInt &dim, const petibm::type::IntVec1D &n, const PetscInt &bg, const PetscInt &ed, const PetscInt &step)
std::shared_ptr< mesh::MeshBase > Mesh
Type definition of Mesh.
PetscErrorCode createMesh(const MPI_Comm &comm, const YAML::Node &node, type::Mesh &mesh)
Factory function for creating a Mesh object.
PetscErrorCode getSettings(YAML::Node &node)
Get configuration settings.
Dir
Legal physical directions.
std::vector< PetscInt > IntVec1D
1D std::vector holding PetscInt.
std::map< Dir, std::string > dir2str
Mapping between Dir and std::string.
Prototype of mesh::MeshBase, type::Mesh, and factory function.
Prototypes of parser functions.
Definition of user-defined types for convenience.