Proto  3.2
Proto_BoundaryCondition.H
Go to the documentation of this file.
1 #pragma once
2 #ifndef __PROTO_BOUNDARY_CONDITION__
3 #define __PROTO_BOUNDARY_CONDITION__
4 
5 #include "Proto.H"
6 namespace Proto {
7 
8  /// @brief A variation of Stencil used for applying boundary conditions.
9  /// Consider the diagram below. BCStencil is designed to extrapolate the
10  /// value of a ghost cell (A) using interior data (C) in addition to an edge centered
11  /// value on the boundary (B). Note that a different MBStencil is needed to fill
12  /// ghost cells at different distances from the boundary. The updated value (A)
13  /// may have different units than the source values (B, C, D, ...); for example, A might
14  /// be a flux while the source values have units of the associated state.
15  /// The diagram below corresponds to the case where a ghost cell in the second layer of
16  /// a low-face is being filled.
17  ///
18  /// ghost <-|-> interior
19  /// +---+---+---+---+- ...
20  /// | A | B C | D | ...
21  /// +---+---+---+---+ ...
22  ///
23  /// As an equation:
24  /// A = B*coef + stencil(C, D,...)
25  ///
26  /// This structure is used primarily in the implementations to follow and is
27  /// not recommended for public use.
28  template<class T>
29  struct BCStencil {
31  T coef;
32  };
33 
34  /// @brief Library of utility functions for assisiting in the application of boundary conditions
36  public:
37 
38  /// @brief Returns the Box corresponding to the boundary of domainBox on face.
39  /// For low-faces along the axis dir, the output is domainBox.edge(dir).
40  /// For high-faces, the output is domainBox.adjacent(dir). That is to say,
41  /// Low boundaries are contained within domainBox and high boundaries are just
42  /// outside of domainBox. This is the convention used in all of Proto.
43  /// @param domainBox - The Box corresponding to the interior of a domain
44  /// @param face - The face of domainBox whose boundary Box is to be computed
45  static inline Box Boundary(Box domainBox, Face face);
46 
47  /// @brief Generates the BCStencil object needed to apply a dirichlet boundary
48  /// condition to a flux in direction dir on a specified face
49  /// @param dx - Grid spacing
50  /// @param face - The face corresponding to the boundary condition
51  /// @param fluxDir - Coordinate of the flux being updated. Can be normal or tangential
52  template<class T>
53  static inline BCStencil<T> DirichletStencil(T dx, Face face, int fluxCoord);
54 
55  /// @brief Applies a constant dirichlet boundary condition on a specified face by updating
56  /// the fluxes in all directions
57  /// @param fluxes - flux data which will be updated on the appropriate boundary to apply the BC
58  /// @param state - state data used to apply the BC
59  /// @param dirichletBCValue - constant value of the state on the boundary. Note that the same constant
60  /// Will be applied to every component of each flux. Alias as needed to apply BCs componentwise.
61  /// @param face - the face on which the boundary condition will be applied
62  /// @param interiorBox - defines which elements of state and fluxes are interior to the domain.
63  /// This can be larger than the Boxes defining the state / fluxes. In practice, fluxes and state
64  /// are patch scoped values and interiorBox is the Box associated with a ProblemDomain.
65  /// @param dx - anisotropic grid spacing
66  template<class T, unsigned int C, MemType MEM, unsigned int D, unsigned int E>
67  static inline void Dirichlet(
68  Array<BoxData<T,C,MEM,D,E>,DIM>& fluxes,
69  const BoxData<T,C,MEM,D,E>& state,
70  T dirichletBCValue,
71  Face face,
72  Box interiorBox,
74 
75  /// @brief Applies a variable dirichlet boundary condition on a specified face by updating
76  /// the fluxes in all directions
77  /// @param fluxes - flux data which will be updated on the appropriate boundary to apply the BC
78  /// @param state - state data used to apply the BC
79  /// @param dirichletBCValues - values of the state on the boundary
80  /// @param face - the face on which the boundary condition will be applied
81  /// @param interiorBox - defines which elements of state and fluxes are interior to the domain.
82  /// This can be larger than the Boxes defining the state / fluxes. In practice, fluxes and state
83  /// are patch scoped values and interiorBox is the Box associated with a ProblemDomain.
84  /// @param dx - anisotropic grid spacing
85  template<class T, unsigned int C, MemType MEM, unsigned int D, unsigned int E>
86  static inline void Dirichlet(
87  Array<BoxData<T,C,MEM,D,E>,DIM>& fluxes,
88  const BoxData<T,C,MEM,D,E>& state,
89  const BoxData<T,C,MEM,D,E>& dirichletBCvalues,
90  Face face,
91  Box interiorBox,
92  Array<T,DIM> dx);
93 
94  #ifdef PR_LAPACK
95 
96  /// @brief Creates a BCStencil which is used to extrapolate ghost cell values a specified
97  /// distance from a specified face. The number of source data points can also be specified.
98  /// @tparam T
99  /// @param dist - distance of the extrapolated ghost cell from the boundary.
100  /// dist = 1 is a cell directly adjacent to the boundary
101  /// @param face - the face from which extrapolation is computed
102  /// @param npoints - the number of interior data points used to compute the extrapolation.
103  template<class T>
104  static inline BCStencil<T> DirichletExtrapStencil(int dist, Face face, int npoints);
105 
106  /// @brief Extrapolates state data into a ghost region in accordance to a specified constant
107  /// dirichlet boundary condition. This function should only be used for data which is very smoothly
108  /// varying near the boundary in question.
109  /// @param state - data updated by and used as a source for the extrapolation. Elements inside of
110  /// interiorBox are inputs to the extrapolation and elements outside of interiorBox are assumed to be
111  /// in the ghost region and will be computed by the extrapolation.
112  /// @param dirichletBCValue - constant value of the dirichlet boundary condition
113  /// @param face - face on which the dirichlet boundary condition is applied
114  /// @param interiorBox - Box which defines which elements of state are in the interior or ghost region
115  template<class T, unsigned int C, MemType MEM, unsigned int D, unsigned int E>
116  static inline void DirichletFillGhost(
117  BoxData<T,C,MEM,D,E>& state,
118  T dirichletBCValue,
119  Face face,
120  Box interiorBox);
121 
122  /// @brief Extrapolates ghost region data in boundary regions of codimension 2 or greater (e.g. hyper-corners).
123  /// This function assumes that ghost data in boundaries of codimension 1 have already been computed using e.g.
124  /// DirichletFillGhost or some other boundary filling strategy.
125  /// @param state - data updated by and used as a source for the extrapolation. Elements which are in boundary regions
126  /// - as defined by interiorBox - of codimension 2 or greater are updated while elements in boundary regions of codimension
127  /// 1 are used as source data. Interior data are not used or updated.
128  /// @param interiorBox - used to define which elements of state are interior cells, boundary cells, etc.
129  template<class T, unsigned int C, MemType MEM, unsigned int D, unsigned int E>
130  static inline void ExtrapolateCorners(
131  BoxData<T,C,MEM,D,E>& state,
132  Box interiorBox);
133  #endif
134 
135  };
136 
137 // The following code is part of an old policy-based implementation wherein boundary conditions were implemented as first class
138 // objects. This may still be a good approach, but I suspect it's more flexible and user-friendly to require users to manually apply
139 // their own boundary conditions and supply helpful functions like those above to make this process as concise and expressive as possible.
140 // - Chris Bozhart - 8/21/2025
141 #if 0
142  template<class T, unsigned int C=1, MemType MEM=HOST, unsigned int D=1, unsigned int E=1>
143  class BC_ConstDirichlet : public BoundaryCondition<T,C,MEM,D,E> {
144  public:
145  typedef BoxData<T,C,MEM,D,E> StateData;
146 
147  BC_ConstDirichlet(Face a_face, T a_value, T a_dx)
148  : BoundaryCondition<T,C,MEM,D,E>(a_face), m_value(a_value), m_dx(a_dx) {}
149 
150  virtual void apply(
151  StateData& a_flux,
152  const StateData& a_state,
153  Box a_domainBox) const
154  {
155  this->Dirichlet(a_flux, a_state, a_domainBox, m_value, m_dx, this->face());
156  }
157 
158  T& data() { return m_value; }
159 
160  private:
161  T m_value;
162  const T m_dx;
163  };
164 
165  template<class T, unsigned int C=1, MemType MEM=HOST, unsigned int D=1, unsigned int E=1>
166  class BC_VariableDirichlet : public BoundaryCondition<T,C,MEM,D,E> {
167  public:
168  typedef BoxData<T,C,MEM,D,E> StateData;
169 
170  BC_VariableDirichlet(Face a_face, BoxData<T,C,MEM,D,E>& a_values, T a_dx)
171  : m_values(a_values), m_dx(a_dx) { this->m_face = a_face; }
172 
173  virtual void apply(
174  StateData& a_flux,
175  const StateData& a_state,
176  Box a_domainBox) const
177  {
178  this->Dirichlet(a_flux, a_state, a_domainBox, m_values, m_dx, this->face());
179  }
180 
181  BoxData<T,C,MEM,D,E>& data() { return m_values; }
182 
183  private:
184  BoxData<T,C,MEM,D,E>& m_values;
185  const T m_dx;
186  };
187  #endif
188  #include "implem/Proto_BoundaryConditionImplem.H"
189 } // end namespace Proto
190 #endif //end include guard
Definition: Proto_Face.H:122
static void Dirichlet(Array< BoxData< T, C, MEM, D, E >, DIM > &fluxes, const BoxData< T, C, MEM, D, E > &state, const BoxData< T, C, MEM, D, E > &dirichletBCvalues, Face face, Box interiorBox, Array< T, DIM > dx)
Applies a variable dirichlet boundary condition on a specified face by updating the fluxes in all dir...
Definition: Proto_BoundaryCondition.H:73
Multidimensional Rectangular Array.
Definition: Proto_BoxData.H:314
A Linear Stencil Operation.
Definition: Proto_BoxData.H:76
static void Dirichlet(Array< BoxData< T, C, MEM, D, E >, DIM > &fluxes, const BoxData< T, C, MEM, D, E > &state, T dirichletBCValue, Face face, Box interiorBox, Array< T, DIM > dx)
Applies a constant dirichlet boundary condition on a specified face by updating the fluxes in all dir...
Definition: Proto_BoundaryCondition.H:47
An interval in DIM dimensional space.
Definition: Proto_Box.H:29
A variation of Stencil used for applying boundary conditions. Consider the diagram below...
Definition: Proto_BoundaryCondition.H:29
T coef
Definition: Proto_BoundaryCondition.H:31
Definition: Proto_Array.H:17
A templated constant size array object similar to std::array, but with the ability to be used inside ...
Definition: Proto_Array.H:28
Stencil< T > stencil
Definition: Proto_BoundaryCondition.H:30
Library of utility functions for assisiting in the application of boundary conditions.
Definition: Proto_BoundaryCondition.H:35