26typedef std::function<
StencilVec(
const PetscInt &,
const PetscInt &,
31typedef std::function<
type::RealVec1D(
const PetscInt &,
const PetscInt &,
37 const PetscBool &normalize)
39 PetscFunctionBeginUser;
43 std::vector<GetNeighborFunc> getNeighbor(3);
45 std::vector<Kernel> kernel(3);
48 getNeighbor[0] = [](
const PetscInt &i,
const PetscInt &j,
49 const PetscInt &k) -> std::vector<MatStencil> {
50 return {{k, j, i, 0}, {k, j, i + 1, 0}};
53 getNeighbor[1] = [](
const PetscInt &i,
const PetscInt &j,
54 const PetscInt &k) -> std::vector<MatStencil> {
55 return {{k, j, i, 0}, {k, j + 1, i, 0}};
58 getNeighbor[2] = [](
const PetscInt &i,
const PetscInt &j,
59 const PetscInt &k) -> std::vector<MatStencil> {
60 return {{k, j, i, 0}, {k + 1, j, i, 0}};
70 kernel[0] = [&mesh](
const PetscInt &i,
const PetscInt &j,
72 PetscReal
v = 1.0 / mesh->dL[0][0][i];
76 kernel[1] = [&mesh](
const PetscInt &i,
const PetscInt &j,
78 PetscReal
v = 1.0 / mesh->dL[1][1][j];
82 kernel[2] = [&mesh](
const PetscInt &i,
const PetscInt &j,
84 PetscReal
v = 1.0 / mesh->dL[2][2][k];
90 ierr = MatCreate(mesh->comm, &G); CHKERRQ(ierr);
91 ierr = MatSetSizes(G, mesh->UNLocal, mesh->pNLocal, PETSC_DETERMINE,
92 PETSC_DETERMINE); CHKERRQ(ierr);
93 ierr = MatSetFromOptions(G); CHKERRQ(ierr);
94 ierr = MatSeqAIJSetPreallocation(G, 2,
nullptr); CHKERRQ(ierr);
95 ierr = MatMPIAIJSetPreallocation(G, 2,
nullptr, 1,
nullptr); CHKERRQ(ierr);
96 ierr = MatSetUp(G); CHKERRQ(ierr);
97 ierr = MatSetOption(G, MAT_KEEP_NONZERO_PATTERN, PETSC_FALSE);
99 ierr = MatSetOption(G, MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE); CHKERRQ(ierr);
102 for (PetscInt field = 0; field < mesh->dim; ++field)
103 for (PetscInt k = mesh->bg[field][2]; k < mesh->ed[field][2]; ++k)
104 for (PetscInt j = mesh->bg[field][1]; j < mesh->ed[field][1]; ++j)
105 for (PetscInt i = mesh->bg[field][0]; i < mesh->ed[field][0];
115 ierr = mesh->getPackedGlobalIndex(field, loc[0], rId);
119 for (PetscInt n = 0; n < 2; ++n)
121 ierr = mesh->getPackedGlobalIndex(3, loc[n], cId);
125 MatSetValue(G, rId, cId, values[n], INSERT_VALUES);
131 ierr = MatAssemblyBegin(G, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
132 ierr = MatAssemblyEnd(G, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
134 PetscFunctionReturn(0);
std::shared_ptr< mesh::MeshBase > Mesh
Type definition of Mesh.
PetscErrorCode createGradient(const type::Mesh &mesh, Mat &G, const PetscBool &normalize=PETSC_TRUE)
Create a gradient operator, , for pressure field.
std::vector< PetscReal > RealVec1D
1D std::vector holding PetscReal.
Prototype of mesh::MeshBase, type::Mesh, and factory function.
std::function< StencilVec(const PetscInt &, const PetscInt &, const PetscInt &)> GetNeighborFunc
a function type for functions returning neighbors' stencils.
std::function< type::RealVec1D(const PetscInt &, const PetscInt &, const PetscInt &)> Kernel
a function type for functions computing matrix entries' values.
std::vector< MatStencil > StencilVec
STL vector holding MatStencil.
A toolbox for building flow solvers.
Definition of user-defined types for convenience.