GEOSX
FieldIdentifiers.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 TotalEnergies
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 GEOS_MESH_MPICOMMUNICATIONS_FIELDIDENTIFIERS_HPP_
20 #define GEOS_MESH_MPICOMMUNICATIONS_FIELDIDENTIFIERS_HPP_
21 
22 #include "common/DataTypes.hpp"
23 #include "codingUtilities/StringUtilities.hpp"
24 
25 namespace geos
26 {
31 enum class FieldLocation
32 {
33  Elem,
34  Face,
35  Edge,
36  Node
37 };
38 
39 
44 {
45 public:
46 
53  void addFields( FieldLocation const location, std::vector< string > const & fieldNames )
54  {
55  string key;
56  generateKey( location, key );
57  addFields( fieldNames, key );
58  }
65  template< typename T = std::vector< string > >
66  void addElementFields( std::vector< string > const & fieldNames, T const & regionNames )
67  {
68  for( auto const & regionName : regionNames )
69  {
70  addFields( fieldNames, generateKey( regionName ) );
71  }
72  }
73 
79  std::map< string, array1d< string > > const & getFields() const
80  {
81  return m_fields;
82  }
89  string getRegionName( string const & key ) const
90  {
91  string regionName( key );
92  regionName.erase( 0, std::string( m_locationKeys.elemsKey()).length());
93  return regionName;
94  }
101  void getLocation( string const & key,
102  FieldLocation & location ) const
103  {
104  if( key.find( m_locationKeys.nodesKey() ) != string::npos )
105  {
106  location = FieldLocation::Node;
107  }
108  else if( key.find( m_locationKeys.edgesKey()) != string::npos )
109  {
110  location = FieldLocation::Edge;
111  }
112  else if( key.find( m_locationKeys.facesKey()) != string::npos )
113  {
114  location = FieldLocation::Face;
115  }
116  else if( key.find( m_locationKeys.elemsKey()) != string::npos )
117  {
118  location = FieldLocation::Elem;
119  }
120  else
121  {
122  GEOS_ERROR( GEOS_FMT( "Invalid key, {}, was provided. Location cannot be retrieved.", key ) );
123  }
124  }
125 
126 private:
128  std::map< string, array1d< string > > m_fields;
129 
130  struct keysStruct
131  {
133  static constexpr char const * nodesKey() { return "nodes"; }
135  static constexpr char const * edgesKey() { return "edges"; }
137  static constexpr char const * facesKey() { return "faces"; }
139  static constexpr char const * elemsKey() { return "elems/"; }
140  } m_locationKeys;
141 
148  void generateKey( FieldLocation const location,
149  string & key ) const
150 
151  {
152  switch( location )
153  {
154  case FieldLocation::Node:
155  {
156  key = m_locationKeys.nodesKey();
157  break;
158  }
159  case FieldLocation::Edge:
160  {
161  key = m_locationKeys.edgesKey();
162  break;
163  }
164  case FieldLocation::Face:
165  {
166  key = m_locationKeys.facesKey();
167  break;
168  }
169  case FieldLocation::Elem:
170  {
171  GEOS_ERROR( "An element located field also requires a region name to be specified." );
172  break;
173  }
174  }
175  }
182  string generateKey( string const & regionName ) const
183  {
184  return stringutilities::concat( "", m_locationKeys.elemsKey(), regionName );
185  }
192  void addFields( std::vector< string > const fieldNames, string const key )
193  {
194  for( string const & field : fieldNames )
195  {
196  m_fields[key].emplace_back( field );
197  }
198  }
199 };
200 
201 } /* namespace geos */
202 
203 #endif /* GEOS_MESH_MPICOMMUNICATIONS_FIELDIDENTIFIERS_HPP_ */
#define GEOS_ERROR(msg)
Raise a hard error and terminate the program.
Definition: Logger.hpp:122
void getLocation(string const &key, FieldLocation &location) 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:131
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)