14#include <petscviewerhdf5.h>
15#include <yaml-cpp/yaml.h>
46 std::vector<DM> &wDMs,
47 std::vector<std::string> &names,
48 std::vector<Vec> &vecs);
53 const std::vector<DM> &wDm,
59 const std::vector<DM> &wDm,
62int main(
int argc,
char **argv)
66 ierr = PetscInitialize(&argc, &argv,
nullptr,
nullptr); CHKERRQ(ierr);
81 std::vector<std::string> wNames;
98 if (mesh->mpiRank == 0)
100 for (
unsigned int i = 0; i < wNames.size(); ++i)
104 setting[
"output"].as<std::string>() +
"/grid.h5", wNames[i],
105 {
"x",
"y",
"z"}, wCoord[i], FILE_MODE_APPEND); CHKERRQ(ierr);
108 ierr = MPI_Barrier(PETSC_COMM_WORLD); CHKERRQ(ierr);
111 ierr = PetscOptionsGetInt(
nullptr,
nullptr,
"-bg", &bg, &isSet);
113 if (!isSet) bg = setting[
"parameters"][
"startStep"].as<PetscInt>(0);
114 ierr = PetscOptionsGetInt(
nullptr,
nullptr,
"-ed", &ed, &isSet);
116 if (!isSet) ed = bg + setting[
"parameters"][
"nt"].as<PetscInt>();
117 ierr = PetscOptionsGetInt(
nullptr,
nullptr,
"-step", &step, &isSet);
119 if (!isSet) step = setting[
"parameters"][
"nsave"].as<PetscInt>();
122 ierr = PetscPrintf(PETSC_COMM_WORLD,
123 "====================================\n"
124 "Start to calculate vorticity fields!\n"
125 "====================================\n\n");
128 ierr = PetscPrintf(PETSC_COMM_WORLD,
132 bg, ed, step); CHKERRQ(ierr);
134 for (
int i = bg; i <= ed; i += step)
136 ierr = PetscPrintf(PETSC_COMM_WORLD,
137 "Calculating vorticity fields for time step %d ... ",
141 std::stringstream ss;
142 ss << setting[
"output"].as<std::string>() <<
"/" << std::setfill(
'0')
143 << std::setw(7) << i <<
".h5";
144 ierr = soln->read(ss.str()); CHKERRQ(ierr);
147 ierr = bc->setGhostICs(soln); CHKERRQ(ierr);
163 FILE_MODE_APPEND); CHKERRQ(ierr);
165 ierr = PetscPrintf(PETSC_COMM_WORLD,
"done.\n"); CHKERRQ(ierr);
169 for (
unsigned int f = 0; f <
w.size(); ++f)
171 ierr = VecDestroy(&
w[f]); CHKERRQ(ierr);
172 ierr = DMDestroy(&wDMs[f]); CHKERRQ(ierr);
176 ierr = soln->destroy(); CHKERRQ(ierr);
177 ierr = bc->destroy(); CHKERRQ(ierr);
178 ierr = mesh->destroy(); CHKERRQ(ierr);
180 ierr = PetscFinalize(); CHKERRQ(ierr);
188 const std::vector<DM> &wDm,
193 PetscFunctionBeginUser;
195 std::vector<Vec> uLocals;
196 std::vector<PetscReal **> uLocalArrys;
201 ierr = DMDAGetLocalInfo(wDm[0], &info); CHKERRQ(ierr);
204 uLocals.resize(mesh->dim);
205 uLocalArrys.resize(mesh->dim);
208 for (PetscInt f = 0; f < mesh->dim; ++f)
210 ierr = DMCreateLocalVector(mesh->da[f], &uLocals[f]); CHKERRQ(ierr);
214 ierr = DMCompositeScatterArray(mesh->UPack, soln->UGlobal, uLocals.data());
218 ierr = bds->copyValues2LocalVecs(uLocals); CHKERRQ(ierr);
221 for (PetscInt f = 0; f < mesh->dim; ++f)
223 ierr = DMDAVecGetArrayRead(mesh->da[f], uLocals[f], &uLocalArrys[f]);
228 ierr = DMDAVecGetArray(wDm[0],
w[0], &wArray); CHKERRQ(ierr);
231 for (PetscInt j = info.ys; j < info.ys + info.ym; ++j)
233 for (PetscInt i = info.xs; i < info.xs + info.xm; ++i)
236 (uLocalArrys[1][j - 1][i] - uLocalArrys[1][j - 1][i - 1]) /
237 (mesh->coord[1][0][i] - mesh->coord[1][0][i - 1]) -
238 (uLocalArrys[0][j][i - 1] - uLocalArrys[0][j - 1][i - 1]) /
239 (mesh->coord[0][1][j] - mesh->coord[0][1][j - 1]);
244 ierr = DMDAVecRestoreArray(wDm[0],
w[0], &wArray); CHKERRQ(ierr);
247 for (PetscInt f = 0; f < mesh->dim; ++f)
250 DMDAVecRestoreArrayRead(mesh->da[f], uLocals[f], &uLocalArrys[f]);
253 ierr = VecDestroy(&uLocals[f]); CHKERRQ(ierr);
256 PetscFunctionReturn(0);
262 const std::vector<DM> &wDm,
267 PetscFunctionBeginUser;
269 std::vector<Vec> uLocals;
270 std::vector<PetscReal ***> uLocalArrys;
271 std::vector<DMDALocalInfo> info;
275 info.resize(mesh->dim);
276 uLocals.resize(mesh->dim);
277 uLocalArrys.resize(mesh->dim);
280 for (PetscInt f = 0; f < mesh->dim; ++f)
282 ierr = DMDAGetLocalInfo(wDm[f], &info[f]); CHKERRQ(ierr);
283 ierr = DMCreateLocalVector(mesh->da[f], &uLocals[f]); CHKERRQ(ierr);
287 ierr = DMCompositeScatterArray(mesh->UPack, soln->UGlobal, uLocals.data());
291 ierr = bds->copyValues2LocalVecs(uLocals); CHKERRQ(ierr);
294 for (PetscInt f = 0; f < mesh->dim; ++f)
296 ierr = DMDAVecGetArrayRead(mesh->da[f], uLocals[f], &uLocalArrys[f]);
301 ierr = DMDAVecGetArray(wDm[0],
w[0], &wArray); CHKERRQ(ierr);
302 for (PetscInt k = info[0].zs; k < info[0].zs + info[0].zm; ++k)
304 for (PetscInt j = info[0].ys; j < info[0].ys + info[0].ym; ++j)
306 for (PetscInt i = info[0].xs; i < info[0].xs + info[0].xm; ++i)
309 (uLocalArrys[2][k - 1][j][i - 1] -
310 uLocalArrys[2][k - 1][j - 1][i - 1]) /
311 (mesh->coord[2][1][j] - mesh->coord[2][1][j - 1]) -
312 (uLocalArrys[1][k][j - 1][i - 1] -
313 uLocalArrys[1][k - 1][j - 1][i - 1]) /
314 (mesh->coord[1][2][k] - mesh->coord[1][2][k - 1]);
318 ierr = DMDAVecRestoreArray(wDm[0],
w[0], &wArray); CHKERRQ(ierr);
321 ierr = DMDAVecGetArray(wDm[1],
w[1], &wArray); CHKERRQ(ierr);
322 for (PetscInt k = info[1].zs; k < info[1].zs + info[1].zm; ++k)
324 for (PetscInt j = info[1].ys; j < info[1].ys + info[1].ym; ++j)
326 for (PetscInt i = info[1].xs; i < info[1].xs + info[1].xm; ++i)
329 (uLocalArrys[0][k][j - 1][i - 1] -
330 uLocalArrys[0][k - 1][j - 1][i - 1]) /
331 (mesh->coord[0][2][k] - mesh->coord[0][2][k - 1]) -
332 (uLocalArrys[2][k - 1][j - 1][i] -
333 uLocalArrys[2][k - 1][j - 1][i - 1]) /
334 (mesh->coord[2][0][i] - mesh->coord[2][0][i - 1]);
338 ierr = DMDAVecRestoreArray(wDm[1],
w[1], &wArray); CHKERRQ(ierr);
341 ierr = DMDAVecGetArray(wDm[2],
w[2], &wArray); CHKERRQ(ierr);
342 for (PetscInt k = info[2].zs; k < info[2].zs + info[2].zm; ++k)
344 for (PetscInt j = info[2].ys; j < info[2].ys + info[2].ym; ++j)
346 for (PetscInt i = info[2].xs; i < info[2].xs + info[2].xm; ++i)
349 (uLocalArrys[1][k][j - 1][i] -
350 uLocalArrys[1][k][j - 1][i - 1]) /
351 (mesh->coord[1][0][i] - mesh->coord[1][0][i - 1]) -
352 (uLocalArrys[0][k][j][i - 1] -
353 uLocalArrys[0][k][j - 1][i - 1]) /
354 (mesh->coord[0][1][j] - mesh->coord[0][1][j - 1]);
358 ierr = DMDAVecRestoreArray(wDm[2],
w[2], &wArray); CHKERRQ(ierr);
361 for (PetscInt f = 0; f < mesh->dim; ++f)
364 DMDAVecRestoreArrayRead(mesh->da[f], uLocals[f], &uLocalArrys[f]);
367 ierr = VecDestroy(&uLocals[f]); CHKERRQ(ierr);
370 PetscFunctionReturn(0);
376 std::vector<DM> &wDMs,
377 std::vector<std::string> &names,
378 std::vector<Vec> &vecs)
382 PetscFunctionBeginUser;
390 n[0][0] = mesh->n[4][0];
391 n[0][1] = mesh->n[4][1];
392 n[0][2] = mesh->n[3][2];
398 coord[0][0].assign(mesh->coord[4][0], mesh->coord[4][0] + n[0][0]);
399 coord[0][1].assign(mesh->coord[4][1], mesh->coord[4][1] + n[0][1]);
400 coord[0][2].assign(mesh->coord[3][2], mesh->coord[3][2] + n[0][2]);
403 names = std::vector<std::string>(1);
409 wDMs = std::vector<DM>(1);
410 vecs = std::vector<Vec>(1);
413 ierr = DMDACreate2d(mesh->comm, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,
414 DMDA_STENCIL_BOX, n[0][0], n[0][1], mesh->nProc[0],
415 mesh->nProc[1], 1, 1,
nullptr,
nullptr, &wDMs[0]);
418 ierr = DMSetUp(wDMs[0]); CHKERRQ(ierr);
421 ierr = DMCreateGlobalVector(wDMs[0], &vecs[0]); CHKERRQ(ierr);
424 ierr = PetscObjectSetName(PetscObject(vecs[0]),
"wz"); CHKERRQ(ierr);
432 n[0][0] = mesh->n[3][0];
433 n[0][1] = mesh->n[4][1];
434 n[0][2] = mesh->n[4][2];
436 n[1][0] = mesh->n[4][0];
437 n[1][1] = mesh->n[3][1];
438 n[1][2] = mesh->n[4][2];
440 n[2][0] = mesh->n[4][0];
441 n[2][1] = mesh->n[4][1];
442 n[2][2] = mesh->n[3][2];
448 coord[0][0].assign(mesh->coord[3][0], mesh->coord[3][0] + n[0][0]);
449 coord[0][1].assign(mesh->coord[4][1], mesh->coord[4][1] + n[0][1]);
450 coord[0][2].assign(mesh->coord[4][2], mesh->coord[4][2] + n[0][2]);
452 coord[1][0].assign(mesh->coord[4][0], mesh->coord[4][0] + n[1][0]);
453 coord[1][1].assign(mesh->coord[3][1], mesh->coord[3][1] + n[1][1]);
454 coord[1][2].assign(mesh->coord[4][2], mesh->coord[4][2] + n[1][2]);
456 coord[2][0].assign(mesh->coord[4][0], mesh->coord[4][0] + n[2][0]);
457 coord[2][1].assign(mesh->coord[4][1], mesh->coord[4][1] + n[2][1]);
458 coord[2][2].assign(mesh->coord[3][2], mesh->coord[3][2] + n[2][2]);
461 names = std::vector<std::string>(3);
470 wDMs = std::vector<DM>(3);
471 vecs = std::vector<Vec>(3);
473 for (PetscInt f = 0; f < 3; ++f)
476 ierr = DMDACreate3d(mesh->comm, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE,
477 DM_BOUNDARY_NONE, DMDA_STENCIL_BOX, n[f][0],
478 n[f][1], n[f][2], mesh->nProc[0],
479 mesh->nProc[1], mesh->nProc[2], 1, 1,
nullptr,
480 nullptr,
nullptr, &wDMs[f]); CHKERRQ(ierr);
482 ierr = DMSetUp(wDMs[f]); CHKERRQ(ierr);
485 ierr = DMCreateGlobalVector(wDMs[f], &vecs[f]); CHKERRQ(ierr);
488 ierr = PetscObjectSetName(PetscObject(vecs[f]), names[f].c_str());
493 PetscFunctionReturn(0);
int main(int argc, char **argv)
PetscErrorCode calculateVorticity2D(const petibm::type::Mesh &mesh, const petibm::type::Boundary &bds, const petibm::type::Solution &soln, const std::vector< DM > &wDm, std::vector< Vec > &w)
PetscErrorCode calculateVorticity3D(const petibm::type::Mesh &mesh, const petibm::type::Boundary &bds, const petibm::type::Solution &soln, const std::vector< DM > &wDm, std::vector< Vec > &w)
PetscErrorCode initVorticityMesh(const petibm::type::Mesh &mesh, petibm::type::IntVec2D &n, petibm::type::RealVec3D &coord, std::vector< DM > &wDMs, std::vector< std::string > &names, std::vector< Vec > &vecs)
boundary::BoundaryBase, type::Boundary, and factory function.
PetscErrorCode createBoundary(const type::Mesh &mesh, const YAML::Node &node, type::Boundary &boundary)
Create a Boundary object.
std::shared_ptr< boundary::BoundaryBase > Boundary
Type definition of petibm::type::Boundary.
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.
PetscErrorCode writeHDF5Vecs(const MPI_Comm comm, const std::string &filePath, const std::string &loc, const std::vector< std::string > &names, const std::vector< Vec > &vecs, const PetscFileMode mode=FILE_MODE_WRITE)
Write a vector of Vec objects to a HDF5 file.
std::shared_ptr< solution::SolutionBase > Solution
Type definition of solution object.
PetscErrorCode createSolution(const type::Mesh &mesh, type::Solution &solution)
Factory function to create a petibm::solution::Solution object.
std::vector< IntVec1D > IntVec2D
2D std::vector holding PetscInt.
std::vector< RealVec1D > RealVec2D
2D std::vector holding PetscReal.
std::vector< PetscInt > IntVec1D
1D std::vector holding PetscInt.
std::vector< RealVec2D > RealVec3D
3D std::vector holding PetscReal.
Prototypes of I/O functions.
Prototype of mesh::MeshBase, type::Mesh, and factory function.
Prototypes of parser functions.
Definition of the class petibm::solution::SolutionBase, the type definition petibm::type::Solution,...
Definition of user-defined types for convenience.