9#include <symengine/lambda_double.h>
34 PetscFunctionBeginUser;
48 ierr = DMCreateGlobalVector(
mesh->UPack, &
UGlobal); CHKERRQ(ierr);
51 ierr = DMCreateGlobalVector(
mesh->da[3], &
pGlobal); CHKERRQ(ierr);
56 PetscFunctionReturn(0);
65 PetscFunctionBeginUser;
70 ss << std::string(80,
'=') << std::endl;
71 ss <<
"Solution Vectors:" << std::endl;
72 ss << std::string(80,
'=') << std::endl;
73 ss <<
"\tDimension: " <<
dim << std::endl;
75 ierr = VecGetSize(
UGlobal, &size); CHKERRQ(ierr);
76 ss <<
"\tLength of Global Packed Velocity Vector: " << size
79 ierr = VecGetSize(
pGlobal, &size); CHKERRQ(ierr);
80 ss <<
"\tLength of Global Pressure Vector: " << size << std::endl;
86 PetscFunctionReturn(0);
94 PetscFunctionBeginUser;
97 ierr = VecDuplicate(
UGlobal, &U); CHKERRQ(ierr);
98 ierr = MatMult(RInv,
UGlobal, U); CHKERRQ(ierr);
99 ierr = VecSwap(
UGlobal, U); CHKERRQ(ierr);
100 ierr = VecDestroy(&U); CHKERRQ(ierr);
102 PetscFunctionReturn(0);
110 PetscFunctionBeginUser;
113 ierr = VecDuplicate(
UGlobal, &F); CHKERRQ(ierr);
114 ierr = MatMult(R,
UGlobal, F); CHKERRQ(ierr);
115 ierr = VecSwap(
UGlobal, F); CHKERRQ(ierr);
116 ierr = VecDestroy(&F); CHKERRQ(ierr);
118 PetscFunctionReturn(0);
126 std::vector<SymEngine::LambdaRealDoubleVisitor> ICs;
127 std::vector<Vec> UGlobalUnpacked(
dim);
133 arry_t(
double** inp):
dim(2), twod(inp) {};
134 arry_t(
double*** inp):
dim(3), threed(inp) {};
135 PetscErrorCode set(
double val,
int i,
int j,
int k) {
136 PetscFunctionBeginUser;
142 threed[k][j][i] = val;
145 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
"Wrong dim.\n");
147 PetscFunctionReturn(0);
150 double** twod =
nullptr;
151 double*** threed =
nullptr;
154 PetscFunctionBeginUser;
156 if (! node[
"flow"][
"nu"].IsDefined())
157 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_USER_INPUT,
158 "Could not find the key \"nu\" under the key "
159 "\"flow\" in the YAML node passed to parseICs.\n");
162 nu = node[
"flow"][
"nu"].as<PetscReal>();
168 ierr = DMCompositeGetAccessArray(
173 for (PetscInt field = 0; field <
dim; ++field)
175 ierr = DMDAVecGetArray(
mesh->da[field], UGlobalUnpacked[field], &raw_arry);
179 case 2: arry =
static_cast<PetscReal**
>(raw_arry);
break;
180 case 3: arry =
static_cast<PetscReal***
>(raw_arry);
break;
184 for (PetscInt k=
mesh->bg[field][2]; k<mesh->ed[field][2]; ++k) {
185 for (PetscInt j=
mesh->bg[field][1]; j<mesh->ed[field][1]; ++j) {
186 for (PetscInt i=
mesh->bg[field][0]; i<mesh->ed[field][0]; ++i) {
187 double value = ICs[field].call({
188 mesh->coord[field][0][i],
mesh->coord[field][1][j],
189 mesh->coord[field][2][k], 0.0, nu
191 arry.set(value, i, j, k);
196 ierr = DMDAVecRestoreArray(
mesh->da[field], UGlobalUnpacked[field], &raw_arry);
200 ierr = DMCompositeRestoreAccessArray(
205 ierr = DMDAVecGetArray(
mesh->da[3],
pGlobal, &raw_arry); CHKERRQ(ierr);
208 case 2: arry =
static_cast<PetscReal**
>(raw_arry);
break;
209 case 3: arry =
static_cast<PetscReal***
>(raw_arry);
break;
212 for (PetscInt k=
mesh->bg[3][2]; k<mesh->ed[3][2]; ++k) {
213 for (PetscInt j=
mesh->bg[3][1]; j<mesh->ed[3][1]; ++j) {
214 for (PetscInt i=
mesh->bg[3][0]; i<mesh->ed[3][0]; ++i) {
215 double value = ICs[3].call({
216 mesh->coord[3][0][i],
mesh->coord[3][1][j],
217 mesh->coord[3][2][k], 0.0, nu
219 arry.set(value, i, j, k);
223 ierr = DMDAVecRestoreArray(
mesh->da[3],
pGlobal, &raw_arry); CHKERRQ(ierr);
225 PetscFunctionReturn(0);
233 PetscFunctionBeginUser;
235 std::vector<Vec> vecs(
dim + 1);
236 std::vector<std::string> names(
dim + 1);
244 ierr = DMCompositeGetAccessArray(
mesh->UPack,
UGlobal,
dim,
nullptr,
245 vecs.data()); CHKERRQ(ierr);
253 vecs.back() = PETSC_NULL;
255 ierr = DMCompositeRestoreAccessArray(
mesh->UPack,
UGlobal,
dim,
nullptr,
256 vecs.data()); CHKERRQ(ierr);
258 PetscFunctionReturn(0);
266 PetscFunctionBeginUser;
268 std::vector<Vec> vecs(
dim + 1);
269 std::vector<std::string> names(
dim + 1);
277 ierr = DMCompositeGetAccessArray(
mesh->UPack,
UGlobal,
dim,
nullptr,
278 vecs.data()); CHKERRQ(ierr);
286 vecs.back() = PETSC_NULL;
288 ierr = DMCompositeRestoreAccessArray(
mesh->UPack,
UGlobal,
dim,
nullptr,
289 vecs.data()); CHKERRQ(ierr);
291 PetscFunctionReturn(0);
PetscMPIInt mpiRank
Rank of the local process.
MPI_Comm comm
MPI communicator.
PetscMPIInt mpiSize
Size of MPI communicator.
std::string info
String containing information about the solution.
Vec UGlobal
Packed PETSc Vec object for the velocity vector field.
type::Mesh mesh
Shared pointer to the underlying Cartesian mesh object.
Vec pGlobal
PETSc Vec for the pressure scalar field.
PetscInt dim
Number of dimensions.
virtual PetscErrorCode convert2Flux(const Mat &R)
Convert velocity components to velocity fluxes.
virtual PetscErrorCode write(const std::string &filePath) const
Write flow field solutions to a file.
virtual PetscErrorCode convert2Velocity(const Mat &Rinv)
Convert velocity fluxes to velocity components.
PetscErrorCode createInfoString()
Create a string with information about the solution.
virtual PetscErrorCode setInitialConditions(const YAML::Node &node)
Set initial conditions of the flow fields.
SolutionSimple(const type::Mesh &mesh)
Constructor using a Cartesian mesh.
virtual PetscErrorCode init(const type::Mesh &mesh)
Initialize the flow field solutions.
virtual ~SolutionSimple()
Default destructor.
virtual PetscErrorCode read(const std::string &filePath)
Read the flow field solutions from a file.
std::shared_ptr< mesh::MeshBase > Mesh
Type definition of Mesh.
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.
PetscErrorCode readHDF5Vecs(const MPI_Comm comm, const std::string &filePath, const std::string &loc, const std::vector< std::string > &names, std::vector< Vec > &vecs)
Read a vector of Vec objects from a HDF5 file.
PetscErrorCode parseICs(const YAML::Node &node, std::vector< SymEngine::LambdaRealDoubleVisitor > &ics)
Parse initial conditions from a YAML node.
std::map< Field, std::string > fd2str
Mapping between Field and std::string.
Prototypes of I/O functions.
A toolbox for building flow solvers.
Prototypes of parser functions.
Definition of class petibm::solution::SolutionSimple.