GEOS
FieldIdentifiers.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_MESH_MPICOMMUNICATIONS_FIELDIDENTIFIERS_HPP_
21 #define GEOS_MESH_MPICOMMUNICATIONS_FIELDIDENTIFIERS_HPP_
22 
23 #include "common/DataTypes.hpp"
25 #include "common/logger/Logger.hpp"
26 
27 namespace geos
28 {
33 enum class FieldLocation
34 {
35  Elem,
36  Face,
37  Edge,
38  Node
39 };
40 
41 
46 {
47 public:
48 
55  void addFields( FieldLocation const location, std::vector< string > const & fieldNames )
56  {
57  string key;
58  generateKey( location, key );
59  addFields( fieldNames, key );
60  }
67  template< typename T = std::vector< string > >
68  void addElementFields( std::vector< string > const & fieldNames, T const & regionNames )
69  {
70  for( auto const & regionName : regionNames )
71  {
72  addFields( fieldNames, generateKey( regionName ) );
73  }
74  }
75 
81  std::map< string, array1d< string > > const & getFields() const
82  {
83  return m_fields;
84  }
91  string getRegionName( string const & key ) const
92  {
93  string regionName( key );
94  regionName.erase( 0, std::string( m_locationKeys.elemsKey()).length());
95  return regionName;
96  }
103  FieldLocation getLocation( string const & key ) const
104  {
105  FieldLocation location{};
106  if( key.find( m_locationKeys.nodesKey() ) != string::npos )
107  {
108  location = FieldLocation::Node;
109  }
110  else if( key.find( m_locationKeys.edgesKey()) != string::npos )
111  {
112  location = FieldLocation::Edge;
113  }
114  else if( key.find( m_locationKeys.facesKey()) != string::npos )
115  {
116  location = FieldLocation::Face;
117  }
118  else if( key.find( m_locationKeys.elemsKey()) != string::npos )
119  {
120  location = FieldLocation::Elem;
121  }
122  else
123  {
124  GEOS_ERROR( GEOS_FMT( "Invalid key, {}, was provided. Location cannot be retrieved.", key ) );
125  }
126  return location;
127  }
128 
129 private:
131  std::map< string, array1d< string > > m_fields;
132 
133  struct keysStruct
134  {
136  static constexpr char const * nodesKey() { return "nodes"; }
138  static constexpr char const * edgesKey() { return "edges"; }
140  static constexpr char const * facesKey() { return "faces"; }
142  static constexpr char const * elemsKey() { return "elems/"; }
143  } m_locationKeys;
144 
151  void generateKey( FieldLocation const location,
152  string & key ) const
153 
154  {
155  switch( location )
156  {
157  case FieldLocation::Node:
158  {
159  key = m_locationKeys.nodesKey();
160  break;
161  }
162  case FieldLocation::Edge:
163  {
164  key = m_locationKeys.edgesKey();
165  break;
166  }
167  case FieldLocation::Face:
168  {
169  key = m_locationKeys.facesKey();
170  break;
171  }
172  case FieldLocation::Elem:
173  {
174  GEOS_ERROR( "An element located field also requires a region name to be specified." );
175  break;
176  }
177  }
178  }
185  string generateKey( string const & regionName ) const
186  {
187  return stringutilities::concat( "", m_locationKeys.elemsKey(), regionName );
188  }
195  void addFields( std::vector< string > const fieldNames, string const key )
196  {
197  for( string const & field : fieldNames )
198  {
199  m_fields[key].emplace_back( field );
200  }
201  }
202 };
203 
204 } /* namespace geos */
205 
206 #endif /* GEOS_MESH_MPICOMMUNICATIONS_FIELDIDENTIFIERS_HPP_ */
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:157
FieldLocation getLocation(string const &key) const
Get the Location object.
string getRegionName(string const &key) const
Get the Region Name object.
void addFields(FieldLocation const location, std::vector< string > const &fieldNames)
adds fields to the fields map using the location to define a convenient key.
void addElementFields(std::vector< string > const &fieldNames, T const &regionNames)
adds element-based fields to the fields map using the element region names to define keys.
std::map< string, array1d< string > > const & getFields() const
Get the Fields object which is the map containing the fields existing for each location.
std::string string
String type.
Definition: DataTypes.hpp:91
FieldLocation
Enum defining the possible location of a field on the mesh.
@ Node
location is node (like displacements in finite elements)
@ Face
location is face (like flux in mixed finite elements)
@ Elem
location is element (like pressure in finite volumes)
@ Edge
location is edge (like flux between fracture elements)