22 PetscFunctionBeginUser;
27 interp = std::make_shared<BiLinInterp>(comm, point, mesh, field);
30 interp = std::make_shared<TriLinInterp>(comm, point, mesh, field);
33 SETERRQ(comm, PETSC_ERR_ARG_UNKNOWN_TYPE,
34 "Unknown number of dimensions. Accepted values are: 2 and 3");
37 PetscFunctionReturn(0);
50 PetscFunctionBeginUser;
52 ierr = PetscFinalized(&finalized); CHKERRV(ierr);
53 if (finalized)
return;
55 ierr =
destroy(); CHKERRV(ierr);
61 PetscFunctionBeginUser;
66 PetscFunctionReturn(0);
77 PetscFunctionBeginUser;
90 PetscFunctionReturn(0);
97 PetscFunctionBeginUser;
99 std::vector<PetscReal>::iterator low;
100 for (PetscInt d = 0; d < mesh->dim; ++d)
103 mesh->coord[field][d] + mesh->n[field][d]);
104 low = std::lower_bound(line.begin(), line.end(),
target[d]);
105 idxDirs[d] = low - line.begin() - 1;
108 PetscFunctionReturn(0);
117 PetscFunctionBeginUser;
121 for (PetscInt d = 0; d < mesh->dim; ++d)
123 bl[d] = mesh->coord[field][d][
idxDirs[d]];
124 tr[d] = mesh->coord[field][d][
idxDirs[d] + 1];
127 PetscFunctionReturn(0);
148 PetscReal c00, c01, c10, c11, c0, c1;
151 PetscReal &x0 =
bl[0], &y0 =
bl[1], &z0 =
bl[2],
152 &x1 =
tr[0], &y1 =
tr[1], &z1 =
tr[2];
153 PetscReal xd, yd, zd;
155 PetscFunctionBeginUser;
157 ierr = DMDAVecGetArrayRead(da, vec, &a); CHKERRQ(ierr);
158 xd = (
x - x0) / (x1 - x0);
159 yd = (
y - y0) / (y1 - y0);
160 zd = (
z - z0) / (z1 - z0);
161 c00 = (1 - xd) * a[ko][jo][io] + xd * a[ko][jo][io+1];
162 c01 = (1 - xd) * a[ko][jo+1][io] + xd * a[ko][jo+1][io+1];
163 c10 = (1 - xd) * a[ko+1][jo][io] + xd * a[ko+1][jo][io+1];
164 c11 = (1 - xd) * a[ko+1][jo+1][io] + xd * a[ko+1][jo+1][io+1];
165 c0 = (1 - yd) * c00 + yd * c01;
166 c1 = (1 - yd) * c10 + yd * c11;
167 v = (1 - zd) * c0 + zd * c1;
168 ierr = DMDAVecRestoreArrayRead(da, vec, &a); CHKERRQ(ierr);
170 PetscFunctionReturn(0);
194 PetscReal &x0 =
bl[0], &y0 =
bl[1],
195 &x1 =
tr[0], &y1 =
tr[1];
198 PetscFunctionBeginUser;
200 ierr = DMDAVecGetArrayRead(da, vec, &a); CHKERRQ(ierr);
201 xd = (
x - x0) / (x1 - x0);
202 yd = (
y - y0) / (y1 - y0);
203 c0 = (1 - xd) * a[jo][io] + xd * a[jo][io + 1];
204 c1 = (1 - xd) * a[jo + 1][io] + xd * a[jo + 1][io + 1];
205 v = (1 - yd) * c0 + yd * c1;
206 ierr = DMDAVecRestoreArrayRead(da, vec, &a); CHKERRQ(ierr);
208 PetscFunctionReturn(0);
PetscErrorCode interpolate(const DM &da, const Vec &vec, PetscReal &v)
BiLinInterp(const MPI_Comm &comm, const type::RealVec1D &point, const type::Mesh &mesh, const type::Field &field)
Constructor. Initialize the linear interpolation object.
type::RealVec1D bl
Coordinates of the front-bottom-left neighbor.
PetscMPIInt commSize
Size of the MPI communicator.
type::RealVec1D target
Coordinates of the point to interpolate.
~LinInterpBase()
Destructor.
type::RealVec1D tr
Coordinates of the back-top-right neighbor.
MPI_Comm comm
MPI communicator.
PetscErrorCode getBoxCoords(const type::Mesh &mesh, const type::Field &field)
Get the coordinates of the neighbors.
PetscMPIInt commRank
Rank of the local process in the communicator.
PetscErrorCode init(const MPI_Comm &comm, const type::RealVec1D &point, const type::Mesh &mesh, const type::Field &field)
Initialize the linear interpolation object.
PetscErrorCode getBLGridlineIndices(const type::Mesh &mesh, const type::Field &field)
Get the gridline indices of the front-bottom-left neighbor.
type::IntVec1D idxDirs
Gridline indices of the front-bottom-left neighbor.
PetscErrorCode destroy()
Manually destroy data in the object.
PetscErrorCode interpolate(const DM &da, const Vec &vec, PetscReal &v)
TriLinInterp(const MPI_Comm &comm, const type::RealVec1D &point, const type::Mesh &mesh, const type::Field &field)
Constructor. Initialize the linear interpolation object.
std::shared_ptr< mesh::MeshBase > Mesh
Type definition of Mesh.
std::shared_ptr< misc::LinInterpBase > LinInterp
Type definition of LinInterp.
PetscErrorCode createLinInterp(const MPI_Comm &comm, const type::RealVec1D &point, const type::Mesh &mesh, const type::Field &field, type::LinInterp &interp)
Factory function to create a linear interpolation object.
std::vector< PetscInt > IntVec1D
1D std::vector holding PetscInt.
std::vector< PetscReal > RealVec1D
1D std::vector holding PetscReal.
Prototype of the linear interpolation classes, definition of type::LinInterp, and factory function.
A toolbox for building flow solvers.