GEOS
FieldSpecificationManager.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 TotalEnergies
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
20 #ifndef GEOS_FIELDSPECIFICATION_FIELDSPECIFICATIONMANAGER_HPP_
21 #define GEOS_FIELDSPECIFICATION_FIELDSPECIFICATIONMANAGER_HPP_
22 
23 #include "FieldSpecification.hpp"
25 
27 #include "common/DataTypes.hpp"
28 #include "common/TimingMacros.hpp"
29 
30 namespace geos
31 {
32 namespace dataRepository
33 {
34 namespace keys
35 {
40 string const boundaryConditionManager( "BoundaryConditionManager" );
41 }
42 }
43 
50 {
51 public:
52 
58  FieldSpecificationManager( string const & name, dataRepository::Group * const parent );
59 
60  virtual ~FieldSpecificationManager() override;
61 
66 
73  virtual Group * createChild( string const & childKey, string const & childName ) override;
74 
76  virtual void expandObjectCatalogs() override;
77 
97  template< typename POLICY=parallelHostPolicy >
98  void applyFieldValue( real64 const time,
99  MeshLevel & mesh,
100  string const & fieldName ) const
101  {
103 
104  applyFieldValue< POLICY >( time, mesh, fieldName,
105  [&]( FieldSpecification const &,
107  }
108 
133  template< typename POLICY=parallelHostPolicy, typename LAMBDA=void >
134  void applyFieldValue( real64 const time,
135  MeshLevel & mesh,
136  string const & fieldName,
137  LAMBDA && lambda ) const;
138 
168  template< typename POLICY=parallelHostPolicy, typename PRELAMBDA=void, typename POSTLAMBDA=void >
169  void applyFieldValue( real64 const time,
170  MeshLevel & mesh,
171  string const & fieldName,
172  PRELAMBDA && preLambda,
173  POSTLAMBDA && postLambda ) const;
174 
175 
180  void applyInitialConditions( MeshLevel & mesh ) const;
181 
186  void validateBoundaryConditions( MeshLevel & mesh ) const;
187 
188 
208  template< typename OBJECT_TYPE=dataRepository::Group,
209  typename BCTYPE = FieldSpecification,
210  typename LAMBDA >
211  void apply( real64 const time,
212  MeshLevel & mesh,
213  string const & fieldName,
214  LAMBDA && lambda ) const
215  {
217 
218  string const meshBodyName = mesh.getParent().getParent().getName();
219  string const meshLevelName = mesh.getName();
220 
221  // loop over all FieldSpecification objects
222  this->forSubGroups< BCTYPE >( [&] ( BCTYPE const & fs )
223  {
224  FieldSpecificationImpl::apply< OBJECT_TYPE, BCTYPE, LAMBDA >( fs,
225  mesh,
226  std::forward< LAMBDA >( lambda ),
227  time,
228  fieldName );
229  } );
230  }
231 
236  void setIsSurfaceGenerationCase( bool isSurfaceGenerationCase )
237  {
238  m_isSurfaceGenerationCase = isSurfaceGenerationCase;
239  }
240 
241 private:
242  static FieldSpecificationManager * m_instance;
244  bool m_isSurfaceGenerationCase = false;
245 
246 };
247 
248 template< typename POLICY, typename LAMBDA >
249 void
251  applyFieldValue( real64 const time,
252  MeshLevel & mesh,
253  string const & fieldName,
254  LAMBDA && lambda ) const
255 {
257 
258  apply( time, mesh, fieldName,
259  [&]( FieldSpecification const & fs,
260  string const &,
261  SortedArrayView< localIndex const > const & targetSet,
262  Group & targetGroup,
263  string const & targetField )
264  {
265  FieldSpecificationImpl::applyFieldValue< FieldSpecificationEqual, POLICY >( fs,
266  targetSet,
267  time,
268  targetGroup,
269  targetField );
270  lambda( fs, targetSet );
271  } );
272 }
273 
274 template< typename POLICY, typename PRELAMBDA, typename POSTLAMBDA >
275 void
277  applyFieldValue( real64 const time,
278  MeshLevel & mesh,
279  string const & fieldName,
280  PRELAMBDA && preLambda,
281  POSTLAMBDA && postLambda ) const
282 {
284 
285  apply( time, mesh, fieldName,
286  [&]( FieldSpecification const & fs,
287  string const &,
288  SortedArrayView< localIndex const > const & targetSet,
289  Group & targetGroup,
290  string const & targetField )
291  {
292  preLambda( fs, targetSet );
293  FieldSpecificationImpl::applyFieldValue< FieldSpecificationEqual, POLICY >( fs,
294  targetSet,
295  time,
296  targetGroup,
297  targetField );
298  postLambda( fs, targetSet );
299  } );
300 }
301 
302 } /* namespace geos */
303 
304 #endif /* GEOS_FIELDSPECIFICATION_FIELDSPECIFICATIONMANAGER_HPP_ */
string const boundaryConditionManager("BoundaryConditionManager")
The key for BoundaryConditionManager.
#define GEOS_MARK_FUNCTION
Mark function with both Caliper and NVTX if enabled.
void apply(real64 const time, MeshLevel &mesh, string const &fieldName, LAMBDA &&lambda) const
This function is the main driver for the field applications.
virtual Group * createChild(string const &childKey, string const &childName) override
Create a new FieldSpecification object as a child of this group.
void applyInitialConditions(MeshLevel &mesh) const
function to apply initial conditions
void applyFieldValue(real64 const time, MeshLevel &mesh, string const &fieldName) const
Function to apply a value directly to a field variable.
virtual void expandObjectCatalogs() override
This function is used to expand any catalogs in the data structure.
FieldSpecificationManager(string const &name, dataRepository::Group *const parent)
private constructor for the singleton BoundaryConditionManager.
void setIsSurfaceGenerationCase(bool isSurfaceGenerationCase)
void validateBoundaryConditions(MeshLevel &mesh) const
function to validate the application of boundary conditions
static FieldSpecificationManager & getInstance()
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:42
string const & getName() const
Get group name.
Definition: Group.hpp:1329
Group & getParent()
Access the group's parent.
Definition: Group.hpp:1362
double real64
64-bit floating point type.
Definition: DataTypes.hpp:98
LvArray::SortedArrayView< T, localIndex, LvArray::ChaiBuffer > SortedArrayView
A sorted array view of local indices.
Definition: DataTypes.hpp:270