GEOSX
FieldSpecificationManager.hpp
Go to the documentation of this file.
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 
19 #ifndef GEOSX_MANAGERS_FIELDSPECIFICATION_FIELDSPECIFICATIONMANAGER_HPP_
20 #define GEOSX_MANAGERS_FIELDSPECIFICATION_FIELDSPECIFICATIONMANAGER_HPP_
21 
22 #include "codingUtilities/StringUtilities.hpp"
24 #include "common/DataTypes.hpp"
25 #include "common/TimingMacros.hpp"
28 
29 namespace geosx
30 {
31 namespace dataRepository
32 {
33 namespace keys
34 {
39 string const boundaryConditionManager( "BoundaryConditionManager" );
40 }
41 }
42 
49 {
50 public:
51 
52 
58  static FieldSpecificationManager & get();
59 
66  virtual Group * CreateChild( string const & childKey, string const & childName ) override;
67 
69  virtual void ExpandObjectCatalogs() override;
70 
96  template< typename POLICY=parallelHostPolicy >
97  void ApplyFieldValue( real64 const time,
98  dataRepository::Group * domain,
99  string const & fieldPath,
100  string const & fieldName ) const
101  {
102  GEOSX_MARK_FUNCTION;
103 
104  ApplyFieldValue< POLICY >( time, domain, fieldPath, fieldName,
105  [&]( FieldSpecificationBase const * const,
107  }
108 
138  template< typename POLICY=parallelHostPolicy, typename LAMBDA=void >
139  void ApplyFieldValue( real64 const time,
140  dataRepository::Group * domain,
141  string const & fieldPath,
142  string const & fieldName,
143  LAMBDA && lambda ) const;
144 
179  template< typename POLICY=parallelHostPolicy, typename PRELAMBDA=void, typename POSTLAMBDA=void >
180  void ApplyFieldValue( real64 const time,
181  dataRepository::Group * domain,
182  string const & fieldPath,
183  string const & fieldName,
184  PRELAMBDA && preLambda,
185  POSTLAMBDA && postLambda ) const;
186 
187 
192  void ApplyInitialConditions( dataRepository::Group * domain ) const;
193 
194 
218  template< typename LAMBDA >
219  void Apply( real64 const time,
220  dataRepository::Group * domain,
221  string const & fieldPath,
222  string const & fieldName,
223  LAMBDA && lambda ) const
224  {
225  GEOSX_MARK_FUNCTION;
226  // loop over all FieldSpecificationBase objects
227  for( auto & subGroup : this->GetSubGroups() )
228  {
229  FieldSpecificationBase const * fs = subGroup.second->group_cast< FieldSpecificationBase const * >();
230  int const isInitialCondition = fs->initialCondition();
231 
232  if( ( isInitialCondition && fieldPath=="" ) ||
233  ( !isInitialCondition && fs->GetObjectPath().find( fieldPath ) != string::npos ) )
234  {
235  string_array const targetPath = stringutilities::Tokenize( fs->GetObjectPath(), "/" );
236  localIndex const targetPathLength = LvArray::integerConversion< localIndex >( targetPath.size());
237  string const targetName = fs->GetFieldName();
238 
239  if( ( isInitialCondition && fieldName=="" ) ||
240  ( !isInitialCondition && time >= fs->GetStartTime() && time < fs->GetEndTime() && targetName==fieldName ) )
241  {
242  MeshLevel * const meshLevel = domain->group_cast< DomainPartition * >()->
243  getMeshBody( 0 )->getMeshLevel( 0 );
244 
245  dataRepository::Group * targetGroup = meshLevel;
246 
247  string processedPath;
248  for( localIndex pathLevel=0; pathLevel<targetPathLength; ++pathLevel )
249  {
251  if( elemRegionSubGroup!=nullptr )
252  {
253  targetGroup = elemRegionSubGroup;
254  }
255 
256  dataRepository::Group * const elemSubRegionSubGroup = targetGroup->GetGroup( ElementRegionBase::viewKeyStruct::elementSubRegions );
257  if( elemSubRegionSubGroup!=nullptr )
258  {
259  targetGroup = elemSubRegionSubGroup;
260  }
261 
262  if( targetPath[pathLevel] == ElementRegionManager::groupKeyStruct::elementRegionsGroup ||
263  targetPath[pathLevel] == ElementRegionBase::viewKeyStruct::elementSubRegions )
264  {
265  continue;
266  }
267 
268  targetGroup = targetGroup->GetGroup( targetPath[pathLevel] );
269  processedPath += "/" + targetPath[pathLevel];
270 
271  GEOSX_ERROR_IF( targetGroup == nullptr,
272  "ApplyBoundaryCondition(): Last entry in objectPath ("<<processedPath<<") is not found" );
273  }
274  ApplyOnTargetRecursive( targetGroup, fs, targetName, lambda );
275  }
276  }
277  }
278  }
279 
280 private:
286  FieldSpecificationManager( string const & name, dataRepository::Group * const parent );
287  virtual ~FieldSpecificationManager() override;
288 
289  template< typename LAMBDA >
290  void ApplyOnTargetRecursive( Group * target,
291  FieldSpecificationBase const * fs,
292  string const & targetName,
293  LAMBDA && lambda
294  ) const
295  {
297  || target->getName() == "nodeManager"
298  || target->getName() == "FaceManager"
299  || target->getName() == "edgeManager" ) // TODO these 3 strings are harcoded because for the moment, there are
300  // inconsistencies with the name of the Managers...
303  {
305  string_array setNames = fs->GetSetNames();
306  for( auto & setName : setNames )
307  {
308  dataRepository::Wrapper< SortedArray< localIndex > > const * const setWrapper = setGroup->getWrapper< SortedArray< localIndex > >( setName );
309  if( setWrapper != nullptr )
310  {
311  SortedArrayView< localIndex const > const & targetSet = setWrapper->reference();
312  lambda( fs, setName, targetSet, target, targetName );
313  }
314  }
315  }
316  else
317  {
318  target->forSubGroups( [&]( Group & subTarget )
319  {
320  ApplyOnTargetRecursive( &subTarget, fs, targetName, lambda );
321  } );
322  }
323  }
324 };
325 
326 template< typename POLICY, typename LAMBDA >
327 void
330  dataRepository::Group * domain,
331  string const & fieldPath,
332  string const & fieldName,
333  LAMBDA && lambda ) const
334 {
335  GEOSX_MARK_FUNCTION;
336 
337  Apply( time, domain, fieldPath, fieldName,
338  [&]( FieldSpecificationBase const * const fs,
339  string const &,
340  SortedArrayView< localIndex const > const & targetSet,
341  Group * const targetGroup,
342  string const & targetField )
343  {
344  fs->ApplyFieldValue< FieldSpecificationEqual, POLICY >( targetSet, time, targetGroup, targetField );
345  lambda( fs, targetSet );
346  } );
347 }
348 
349 template< typename POLICY, typename PRELAMBDA, typename POSTLAMBDA >
350 void
353  dataRepository::Group * domain,
354  string const & fieldPath,
355  string const & fieldName,
356  PRELAMBDA && preLambda,
357  POSTLAMBDA && postLambda ) const
358 {
359  GEOSX_MARK_FUNCTION;
360 
361  Apply( time, domain, fieldPath, fieldName,
362  [&]( FieldSpecificationBase const * const fs,
363  string const &,
364  SortedArrayView< localIndex const > const & targetSet,
365  Group * const targetGroup,
366  string const & targetField )
367  {
368  preLambda( fs, targetSet );
369  fs->ApplyFieldValue< FieldSpecificationEqual, POLICY >( targetSet, time, targetGroup, targetField );
370  postLambda( fs, targetSet );
371  } );
372 }
373 
374 } /* namespace geosx */
375 
376 #endif /* GEOSX_MANAGERS_FIELDSPECIFICATION_FIELDSPECIFICATIONMANAGER_HPP_ */
void ApplyFieldValue(SortedArrayView< localIndex const > const &targetSet, real64 const time, dataRepository::Group *dataGroup, string const &fieldname) const
virtual const string & GetObjectPath() const
Group * getParent()
Access the group&#39;s parent.
Definition: Group.hpp:1326
Class facilitating the representation of a multi-level discretization of a MeshBody.
Definition: MeshLevel.hpp:38
INDEX_TYPE size() const noexcept
Definition: ArrayView.hpp:361
string_array const & GetSetNames() const
string const boundaryConditionManager("BoundaryConditionManager")
The key for BoundaryConditionManager.
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
static constexpr auto setsString
String key to the Group holding the object sets.
static constexpr auto neighborDataString
String key to the Groupholding all the NeighborData objects.
virtual const string & GetFieldName() const
static constexpr auto elementSubRegions
String key for the element subregions.
static T group_cast(Group *group)
Downcast a Group *.
Definition: Group.hpp:308
Wrapper< T > const * getWrapper(LOOKUP_TYPE const &index) const
Retrieve a Wrapper stored in this group.
Definition: Group.hpp:1157
void ApplyFieldValue(real64 const time, dataRepository::Group *domain, string const &fieldPath, string const &fieldName) const
Function to apply a value directly to a field variable.
const string getName() const
Get group name.
Definition: Group.hpp:1317
void Apply(real64 const time, dataRepository::Group *domain, string const &fieldPath, string const &fieldName, LAMBDA &&lambda) const
This function is the main driver for the field applications.
T & reference()
Accessor for m_data.
Definition: Wrapper.hpp:588
std::ptrdiff_t localIndex
Local index type (for indexing objects within an MPI partition).
Definition: DataTypes.hpp:125
void forSubGroups(LAMBDA lambda)
Apply the given functor to subgroups that can be casted to one of specified types.
Definition: Group.hpp:593
#define GEOSX_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
Definition: Logger.hpp:103
static constexpr auto elementRegionsGroup
element regions group string key
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
Definition: Array.hpp:55
Partition of the decomposed physical domain. It also manages the connexion information to its neighbo...
T * GetGroup(localIndex index)
Retrieve a sub-group from the current Group using an index.
Definition: Group.hpp:374