PetIBM 0.5.4
Toolbox and applications of the immersed-boundary method for distributed-memory architectures
probes.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <petscis.h>
11#include <petscsys.h>
12
13#include <yaml-cpp/yaml.h>
14
15#include <petibm/lininterp.h>
16#include <petibm/mesh.h>
17#include <petibm/type.h>
18#include <petibm/solution.h>
19
20namespace petibm
21{
22namespace misc
23{
31{
32public:
34 ProbeBase() = default;
35
41 ProbeBase(const MPI_Comm &comm,
42 const YAML::Node &node,
43 const type::Mesh &mesh);
44
46 virtual ~ProbeBase();
47
49 virtual PetscErrorCode destroy();
50
59 PetscErrorCode monitor(const type::Solution &solution,
60 const type::Mesh &mesh,
61 const PetscInt &n,
62 const PetscReal &t);
63
64protected:
66 std::string name;
67
69 std::string path;
70
73
75 PetscInt n_monitor;
76
78 PetscReal t_start;
79
81 PetscReal t_end;
82
84 PetscViewer viewer;
85
87 PetscViewerType viewerType;
88
90 MPI_Comm comm;
91
93 PetscMPIInt commSize;
94
96 PetscMPIInt commRank;
97
104 virtual PetscErrorCode init(const MPI_Comm &comm,
105 const YAML::Node &node,
106 const type::Mesh &mesh) = 0;
107
116 virtual PetscErrorCode monitorVec(const DM &da,
117 const Vec &fvec,
118 const PetscInt &n,
119 const PetscReal &t) = 0;
120
121}; // ProbeBase
122
129class ProbeVolume : public ProbeBase
130{
131public:
133 ProbeVolume(const MPI_Comm &comm,
134 const YAML::Node &node,
135 const type::Mesh &mesh);
136
138 virtual ~ProbeVolume() = default;
139
141 PetscErrorCode destroy();
142
143protected:
146
149
152
154 Vec dvec;
155
158
161
163 PetscInt nPts;
164
167
169 PetscReal atol;
170
172 PetscInt n_sum;
173
175 PetscInt count = 0;
176
178 PetscErrorCode init(const MPI_Comm &comm,
179 const YAML::Node &node,
180 const type::Mesh &mesh);
181
188 PetscErrorCode getInfo(const type::Mesh &mesh,
189 const type::RealVec2D &box);
190
196 PetscErrorCode createIS(const type::Mesh &mesh);
197
203 PetscErrorCode createGrid(const type::Mesh &mesh);
204
212 PetscErrorCode writeGrid(const std::string &filePath);
213
219 PetscErrorCode writeGrid_ASCII(const std::string &filePath);
220
226 PetscErrorCode writeGrid_HDF5(const std::string &filePath);
227
235 PetscErrorCode writeIS(const std::string &filePath);
236
242 PetscErrorCode writeIS_HDF5(const std::string &filePath);
243
249 PetscErrorCode writeIS_ASCII(const std::string &filePath);
250
252 PetscErrorCode monitorVec(const DM &da,
253 const Vec &fvec,
254 const PetscInt &n,
255 const PetscReal &t);
256
265 PetscErrorCode writeVec(const Vec &vec, const PetscReal &t);
266
273 PetscErrorCode writeVec_ASCII(const Vec &vec, const PetscReal &t);
274
281 PetscErrorCode writeVec_HDF5(const Vec &vec, const PetscReal &t);
282
283}; // ProbeVolume
284
291class ProbePoint : public ProbeBase
292{
293public:
295 ProbePoint(const MPI_Comm &comm,
296 const YAML::Node &node,
297 const type::Mesh &mesh);
298
300 virtual ~ProbePoint() = default;
301
303 PetscErrorCode destroy();
304
305protected:
308
311
313 Vec svec;
314
316 PetscReal value;
317
320
322 PetscErrorCode init(const MPI_Comm &comm,
323 const YAML::Node &node,
324 const type::Mesh &mesh);
325
327 PetscErrorCode monitorVec(const DM &da,
328 const Vec &fvec,
329 const PetscInt &n,
330 const PetscReal &t);
331
332}; // ProbePoint
333
334} // end of namespace misc
335
336namespace type
337{
357typedef std::shared_ptr<misc::ProbeBase> Probe;
358
359} // end of namespace type
360
361namespace misc
362{
375PetscErrorCode createProbe(const MPI_Comm &comm,
376 const YAML::Node &node,
377 const type::Mesh &mesh,
378 type::Probe &probe);
379
380} // end of namespace misc
381
382} // end of namespace petibm
Abstract Base Class of a probe.
Definition: probes.h:31
ProbeBase()=default
Default constructor.
virtual PetscErrorCode destroy()
Manually destroy data in the object.
Definition: probes.cpp:98
PetscReal t_end
Monitoring ending time.
Definition: probes.h:81
std::string path
Path of the file to output the solution.
Definition: probes.h:69
PetscErrorCode monitor(const type::Solution &solution, const type::Mesh &mesh, const PetscInt &n, const PetscReal &t)
Monitor the field solution and output data to file.
Definition: probes.cpp:114
PetscReal t_start
Monitoring starting time.
Definition: probes.h:78
PetscMPIInt commRank
Rank of the local process in the MPI communicator.
Definition: probes.h:96
type::Field field
Type of the field to monitor.
Definition: probes.h:72
virtual PetscErrorCode init(const MPI_Comm &comm, const YAML::Node &node, const type::Mesh &mesh)=0
Initialize the probe.
Definition: probes.cpp:57
PetscViewerType viewerType
Type of the PETSc viewer to use.
Definition: probes.h:87
PetscMPIInt commSize
Number of processes in the MPI communicator.
Definition: probes.h:93
PetscViewer viewer
PETSc viewer to output the solution.
Definition: probes.h:84
virtual ~ProbeBase()
Destructor.
Definition: probes.cpp:84
PetscInt n_monitor
Frequency of monitoring the solution (number of time steps).
Definition: probes.h:75
virtual PetscErrorCode monitorVec(const DM &da, const Vec &fvec, const PetscInt &n, const PetscReal &t)=0
Monitor a sub-region of a vector and possibly output data to file.
ProbeBase(const MPI_Comm &comm, const YAML::Node &node, const type::Mesh &mesh)
Constructor. Initialize the probe.
MPI_Comm comm
MPI communicator.
Definition: probes.h:90
std::string name
Name of the probe as a string.
Definition: probes.h:66
Probe class to monitor the solution at a single point.
Definition: probes.h:292
PetscReal value
Interpolated value.
Definition: probes.h:316
PetscErrorCode destroy()
Manually destroy the data.
Definition: probes.cpp:645
Vec svec
Local (ghosted) PETSc Vec object with neighboring values.
Definition: probes.h:313
type::LinInterp interp
Interpolating object to monitor at a single point.
Definition: probes.h:319
PetscErrorCode monitorVec(const DM &da, const Vec &fvec, const PetscInt &n, const PetscReal &t)
Monitor a sub-region of a vector and possibly output data to file.
Definition: probes.cpp:662
virtual ~ProbePoint()=default
Default destructor.
PetscErrorCode init(const MPI_Comm &comm, const YAML::Node &node, const type::Mesh &mesh)
Initialize the probe.
Definition: probes.cpp:604
ProbePoint(const MPI_Comm &comm, const YAML::Node &node, const type::Mesh &mesh)
Default constructor.
Definition: probes.cpp:596
type::RealVec1D loc
Coordinates of the point to monitor around.
Definition: probes.h:307
PetscBool pointOnLocalProc
True if target point located on local sub-domain.
Definition: probes.h:310
Probe class to monitor a volume region of the domain.
Definition: probes.h:130
PetscErrorCode init(const MPI_Comm &comm, const YAML::Node &node, const type::Mesh &mesh)
Initialize the probe.
Definition: probes.cpp:163
PetscErrorCode writeGrid_HDF5(const std::string &filePath)
Write the sub mesh into a HDF5 file.
Definition: probes.cpp:356
type::RealVec2D coord
Grid point coordinates in the volume.
Definition: probes.h:157
ProbeVolume(const MPI_Comm &comm, const YAML::Node &node, const type::Mesh &mesh)
Default constructor.
Definition: probes.cpp:155
PetscErrorCode writeIS_ASCII(const std::string &filePath)
Write index set (natural ordering) into a HDF5 file.
Definition: probes.cpp:471
PetscErrorCode writeGrid(const std::string &filePath)
Write the sub mesh grid points into a file.
Definition: probes.cpp:332
PetscErrorCode getInfo(const type::Mesh &mesh, const type::RealVec2D &box)
Get information about the sub-mesh area to monitor.
Definition: probes.cpp:240
type::IntVec1D nPtsDir
Number of grid points along each direction in the volume.
Definition: probes.h:160
PetscInt n_sum
Frequency of saving the data to file.
Definition: probes.h:172
PetscErrorCode writeIS_HDF5(const std::string &filePath)
Write index set (natural ordering) into a HDF5 file.
Definition: probes.cpp:454
PetscErrorCode monitorVec(const DM &da, const Vec &fvec, const PetscInt &n, const PetscReal &t)
Monitor a sub-region of a vector and possibly output data to file.
Definition: probes.cpp:487
Vec dvec
Sub-vector of the region to monitor.
Definition: probes.h:154
PetscErrorCode destroy()
Manually destroy the data.
Definition: probes.cpp:225
PetscErrorCode writeGrid_ASCII(const std::string &filePath)
Write the sub mesh into an ASCII file.
Definition: probes.cpp:392
PetscInt nPts
Number of grid points in the volume.
Definition: probes.h:163
PetscErrorCode createIS(const type::Mesh &mesh)
Create the index set for the points to monitor.
Definition: probes.cpp:267
PetscErrorCode writeIS(const std::string &filePath)
Write index set (natural ordering) into a file.
Definition: probes.cpp:431
IS isPetsc
Index set for the grid points to monitor (PETSc ordering).
Definition: probes.h:148
PetscErrorCode writeVec_ASCII(const Vec &vec, const PetscReal &t)
Output a PETSc Vec object to an ASCII file.
Definition: probes.cpp:573
type::RealVec2D box
Limits of the volume.
Definition: probes.h:145
PetscReal atol
Absolute tolerance criterion when comparing values.
Definition: probes.h:169
PetscErrorCode createGrid(const type::Mesh &mesh)
Get the sub-mesh area to monitor.
Definition: probes.cpp:313
PetscInt count
Counter to know when to flush to the data to file.
Definition: probes.h:175
PetscErrorCode writeVec(const Vec &vec, const PetscReal &t)
Output a PETSc Vec object to file.
Definition: probes.cpp:527
type::IntVec1D startIdxDir
Index of the first point in the volume in each direction.
Definition: probes.h:166
virtual ~ProbeVolume()=default
Default destructor.
PetscErrorCode writeVec_HDF5(const Vec &vec, const PetscReal &t)
Output a PETSc Vec object to a HDF5 file.
Definition: probes.cpp:551
IS isNatural
Index set for the grid points to monitor (Natural ordering).
Definition: probes.h:151
std::shared_ptr< mesh::MeshBase > Mesh
Type definition of Mesh.
Definition: mesh.h:348
std::shared_ptr< misc::LinInterpBase > LinInterp
Type definition of LinInterp.
Definition: lininterp.h:172
std::shared_ptr< misc::ProbeBase > Probe
Type definition of Probe.
Definition: probes.h:357
PetscErrorCode createProbe(const MPI_Comm &comm, const YAML::Node &node, const type::Mesh &mesh, type::Probe &probe)
Factory function to create a probe to monitor the solution.
Definition: probes.cpp:23
std::shared_ptr< solution::SolutionBase > Solution
Type definition of solution object.
Definition: solution.h:210
Field
Legal fields.
Definition: type.h:80
std::vector< RealVec1D > RealVec2D
2D std::vector holding PetscReal.
Definition: type.h:142
std::vector< PetscInt > IntVec1D
1D std::vector holding PetscInt.
Definition: type.h:133
std::vector< PetscReal > RealVec1D
1D std::vector holding PetscReal.
Definition: type.h:140
Prototype of the linear interpolation classes, definition of type::LinInterp, and factory function.
Prototype of mesh::MeshBase, type::Mesh, and factory function.
A toolbox for building flow solvers.
Definition: bodypack.h:52
Definition of the class petibm::solution::SolutionBase, the type definition petibm::type::Solution,...
Definition of user-defined types for convenience.