/home/runner/work/kynema-sgf/kynema-sgf/src/core/FieldUtils.H Source File

Kynema-SGF API: /home/runner/work/kynema-sgf/kynema-sgf/src/core/FieldUtils.H Source File
Kynema-SGF API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
FieldUtils.H
Go to the documentation of this file.
1#ifndef FIELDUTILS_H
2#define FIELDUTILS_H
3
5#include "AMReX_MultiFab.H"
6#include "AMReX_Interpolater.H"
7
9
10// Boundary scratch grids can be subsets of the repository's grids.
11AMREX_INLINE int
12matching_grid_index(const amrex::MFIter& mfi, const amrex::MultiFab& source)
13{
14 const auto box = amrex::enclosedCells(mfi.validbox());
15 const int index = mfi.index();
16 if (index < source.boxArray().size() &&
17 source.DistributionMap()[index] ==
18 amrex::ParallelDescriptor::MyProc() &&
19 amrex::enclosedCells(source.boxArray()[index]).contains(box)) {
20 return index;
21 }
22 for (const int idx : source.IndexArray()) {
23 if (amrex::enclosedCells(source.boxArray()[idx]).contains(box)) {
24 return idx;
25 }
26 }
27 amrex::Abort("Boundary scratch grid has no local repository grid");
28 return -1;
29}
30
34AMREX_INLINE amrex::IndexType index_type(const FieldLoc floc)
35{
36 switch (floc) {
37 case FieldLoc::CELL:
38 return amrex::IndexType::TheCellType();
39
40 case FieldLoc::NODE:
41 return amrex::IndexType::TheNodeType();
42
43 case FieldLoc::XFACE:
44 return amrex::IndexType(amrex::IntVect::TheDimensionVector(0));
45
46 case FieldLoc::YFACE:
47 return amrex::IndexType(amrex::IntVect::TheDimensionVector(1));
48
49 case FieldLoc::ZFACE:
50 return amrex::IndexType(amrex::IntVect::TheDimensionVector(2));
51 }
52
53 // Suppress warnings when compiling with CUDA
54 return amrex::IndexType::TheCellType();
55}
56
61AMREX_INLINE std::string
62field_name_with_state(const std::string& fname, const FieldState fstate)
63{
64 switch (fstate) {
65 case FieldState::NP1:
66 return fname;
67
68 case FieldState::N:
69 return fname + "__FS_Old";
70
71 case FieldState::NM1:
72 return fname + "__FS_NM1";
73
74 case FieldState::NPH:
75 return fname + "__FS_NPH";
76
77 case FieldState::NMH:
78 return fname + "__FS_NMH";
79 }
80
81 // Suppress warnings when compiling with CUDA
82 return fname;
83}
84
94AMREX_INLINE bool is_valid_field_name(const std::string& name)
95{
96 // Else make sure that our guard is not in the last 8 characters
97 auto found = name.rfind("__FS_");
98 return found == std::string::npos;
99}
100
105AMREX_INLINE amrex::Interpolater*
107{
108 switch (itype) {
110 return &amrex::pc_interp;
111
113 return &amrex::cell_cons_interp;
114
116 return &amrex::node_bilinear_interp;
117
119 return &amrex::face_divfree_interp;
120
122 return &amrex::face_linear_interp;
123
124 default:
125 amrex::Abort("Unrecognized FieldInterpolator type");
126 }
127
128 return &amrex::cell_cons_interp;
129}
130
131AMREX_INLINE FieldState dof_state(const FieldState fstate)
132{
133 return (fstate == FieldState::New) ? FieldState::New : FieldState::Old;
134}
135
136AMREX_INLINE FieldState phi_state(const FieldState fstate)
137{
138 return (fstate == FieldState::Old) ? FieldState::Old : FieldState::NPH;
139}
140
141} // namespace kynema_sgf::field_impl
142
143#endif /* FIELDUTILS_H */
AMREX_INLINE std::string field_name_with_state(const std::string &fname, const FieldState fstate)
Definition FieldUtils.H:62
AMREX_INLINE bool is_valid_field_name(const std::string &name)
Definition FieldUtils.H:94
AMREX_INLINE amrex::Interpolater * get_interpolation_operator(const FieldInterpolator itype)
Definition FieldUtils.H:106
AMREX_INLINE amrex::IndexType index_type(const FieldLoc floc)
Definition FieldUtils.H:34
FieldLoc
Definition FieldDescTypes.H:29
FieldState
Definition FieldDescTypes.H:16
FieldInterpolator
Coarse-to-fine field interpolation options.
Definition FieldDescTypes.H:39
@ NODE
Node-centered (e.g., for pressure)
Definition FieldDescTypes.H:31
@ ZFACE
Face-centered in z-direction.
Definition FieldDescTypes.H:34
@ XFACE
Face-centered in x-direction (e.g., face normal velocity)
Definition FieldDescTypes.H:32
@ CELL
Cell-centered (default)
Definition FieldDescTypes.H:30
@ YFACE
Face-centered in y-direction.
Definition FieldDescTypes.H:33
@ New
Same as FieldState::NP1.
Definition FieldDescTypes.H:22
@ NP1
Latest state, also aliased to New
Definition FieldDescTypes.H:17
@ NMH
State at (n - 1/2) timestep.
Definition FieldDescTypes.H:21
@ NPH
State at (n + 1/2) (intermediate) timestep.
Definition FieldDescTypes.H:20
@ N
Previous state, also aliased to Old
Definition FieldDescTypes.H:18
@ NM1
State at (n - 1) th timestep.
Definition FieldDescTypes.H:19
@ Old
Same as FieldState::N.
Definition FieldDescTypes.H:23
@ PiecewiseConstant
Constant across cell.
Definition FieldDescTypes.H:40
@ NodeBilinear
Bilinear nodal interpolation.
Definition FieldDescTypes.H:42
@ FaceLinear
Linear face interpolation.
Definition FieldDescTypes.H:44
@ FaceDivFree
Divergence free face interpolation.
Definition FieldDescTypes.H:43
@ CellConsLinear
Linear interpolation.
Definition FieldDescTypes.H:41
Definition FieldUtils.H:8
AMREX_INLINE FieldState dof_state(const FieldState fstate)
Definition FieldUtils.H:131
AMREX_INLINE int matching_grid_index(const amrex::MFIter &mfi, const amrex::MultiFab &source)
Definition FieldUtils.H:12
AMREX_INLINE FieldState phi_state(const FieldState fstate)
Definition FieldUtils.H:136