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 Total, S.A
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 
24 
26 #include "common/DataTypes.hpp"
27 #include "common/TimingMacros.hpp"
28 
29 namespace geos
30 {
31 namespace dataRepository
32 {
33 namespace keys
34 {
39 string const boundaryConditionManager( "BoundaryConditionManager" );
40 }
41 }
42 
49 {
50 public:
51 
57  FieldSpecificationManager( string const & name, dataRepository::Group * const parent );
58 
59  virtual ~FieldSpecificationManager() override;
60 
65 
72  virtual Group * createChild( string const & childKey, string const & childName ) override;
73 
75  virtual void expandObjectCatalogs() override;
76 
96  template< typename POLICY=parallelHostPolicy >
97  void applyFieldValue( real64 const time,
98  MeshLevel & mesh,
99  string const & fieldName ) const
100  {
102 
103  applyFieldValue< POLICY >( time, mesh, fieldName,
104  [&]( FieldSpecificationBase const &,
106  }
107 
132  template< typename POLICY=parallelHostPolicy, typename LAMBDA=void >
133  void applyFieldValue( real64 const time,
134  MeshLevel & mesh,
135  string const & fieldName,
136  LAMBDA && lambda ) const;
137 
167  template< typename POLICY=parallelHostPolicy, typename PRELAMBDA=void, typename POSTLAMBDA=void >
168  void applyFieldValue( real64 const time,
169  MeshLevel & mesh,
170  string const & fieldName,
171  PRELAMBDA && preLambda,
172  POSTLAMBDA && postLambda ) const;
173 
174 
179  void applyInitialConditions( MeshLevel & mesh ) const;
180 
185  void validateBoundaryConditions( MeshLevel & mesh ) const;
186 
187 
207  template< typename OBJECT_TYPE=dataRepository::Group,
208  typename BCTYPE = FieldSpecificationBase,
209  typename LAMBDA >
210  void apply( real64 const time,
211  MeshLevel & mesh,
212  string const & fieldName,
213  LAMBDA && lambda ) const
214  {
216 
217  string const meshBodyName = mesh.getParent().getParent().getName();
218  string const meshLevelName = mesh.getName();
219 
220  // loop over all FieldSpecificationBase objects
221  this->forSubGroups< BCTYPE >( [&] ( BCTYPE const & fs )
222  {
223  integer const isInitialCondition = fs.initialCondition();
224  if( ( isInitialCondition && fieldName=="") || // this only use case for this line is in the unit test for field specification
225  ( !isInitialCondition && time >= fs.getStartTime() && time < fs.getEndTime() && fieldName == fs.getFieldName() ) )
226  {
227  fs.template apply< OBJECT_TYPE, BCTYPE, LAMBDA >( mesh, std::forward< LAMBDA >( lambda ) );
228  }
229  } );
230  }
231 
232 private:
233  static FieldSpecificationManager * m_instance;
234 
235 };
236 
237 template< typename POLICY, typename LAMBDA >
238 void
240  applyFieldValue( real64 const time,
241  MeshLevel & mesh,
242  string const & fieldName,
243  LAMBDA && lambda ) const
244 {
246 
247  apply( time, mesh, fieldName,
248  [&]( FieldSpecificationBase const & fs,
249  string const &,
250  SortedArrayView< localIndex const > const & targetSet,
251  Group & targetGroup,
252  string const & targetField )
253  {
254  fs.applyFieldValue< FieldSpecificationEqual, POLICY >( targetSet, time, targetGroup, targetField );
255  lambda( fs, targetSet );
256  } );
257 }
258 
259 template< typename POLICY, typename PRELAMBDA, typename POSTLAMBDA >
260 void
262  applyFieldValue( real64 const time,
263  MeshLevel & mesh,
264  string const & fieldName,
265  PRELAMBDA && preLambda,
266  POSTLAMBDA && postLambda ) const
267 {
269 
270  apply( time, mesh, fieldName,
271  [&]( FieldSpecificationBase const & fs,
272  string const &,
273  SortedArrayView< localIndex const > const & targetSet,
274  Group & targetGroup,
275  string const & targetField )
276  {
277  preLambda( fs, targetSet );
278  fs.applyFieldValue< FieldSpecificationEqual, POLICY >( targetSet, time, targetGroup, targetField );
279  postLambda( fs, targetSet );
280  } );
281 }
282 
283 } /* namespace geos */
284 
285 #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 applyFieldValue(SortedArrayView< localIndex const > const &targetSet, real64 const time, dataRepository::Group &dataGroup, string const &fieldname) const
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 FieldSpecificationBase 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 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:99
std::int32_t integer
Signed integer type.
Definition: DataTypes.hpp:82
LvArray::SortedArrayView< T, localIndex, LvArray::ChaiBuffer > SortedArrayView
A sorted array view of local indices.
Definition: DataTypes.hpp:271