GEOS
StencilAccessors.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_PHYSICSSOLVERS_FLUIDFLOW_STENCILACCESSORS_HPP_
21 #define GEOS_PHYSICSSOLVERS_FLUIDFLOW_STENCILACCESSORS_HPP_
22 
24 #include "codingUtilities/traits.hpp"
25 #include "codingUtilities/Utilities.hpp"
26 
27 #include <tuple>
28 
29 namespace geos
30 {
31 
37 template< typename ... TRAITS >
39 {
40 public:
41 
46  template< typename TRAIT >
47  auto get( TRAIT ) const
48  {
49  constexpr std::size_t idx = traits::type_list_index< TRAIT, std::tuple< TRAITS ... > >;
50  static_assert( idx != std::tuple_size< std::tuple< TRAITS... > >::value, "input trait/stencil does not match the available traits/stencils." );
51  return std::get< idx >( m_accessors ).toNestedViewConst();
52  }
53 
54  template< typename TRAIT >
55  auto get() const
56  {
57  return get( TRAIT{} );
58  }
59 
65  StencilAccessors( ElementRegionManager const & elemManager,
66  string const & solverName )
67  {
68  forEachArgInTuple( std::tuple< TRAITS ... >{}, [&]( auto t, auto idx )
69  {
70  GEOS_UNUSED_VAR( t );
71  using TRAIT = TYPEOFREF( t );
72 
73  auto & acc = std::get< idx() >( m_accessors );
74  acc = elemManager.constructFieldAccessor< TRAIT >();
75  acc.setName( solverName + "/accessors/" + TRAIT::key() );
76  } );
77  }
78 
79 protected:
80 
82  std::tuple< ElementRegionManager::ElementViewAccessor< traits::ViewTypeConst< typename TRAITS::type > > ... > m_accessors;
83 
87  StencilAccessors() = default;
88 };
89 
96 template< typename MATERIAL_TYPE, typename ... TRAITS >
97 class StencilMaterialAccessors : public StencilAccessors< TRAITS ... >
98 {
99 public:
100 
101  using StencilAccessors< TRAITS ... >::m_accessors;
102 
110  string const & solverName ):
111  StencilAccessors< TRAITS ... >()
112  {
113  forEachArgInTuple( std::tuple< TRAITS ... >{}, [&]( auto t, auto idx )
114  {
115  GEOS_UNUSED_VAR( t );
116  using TRAIT = TYPEOFREF( t );
117 
118  auto & acc = std::get< idx() >( m_accessors );
119  bool const allowMissingViews = false;
120  acc = elemManager.constructMaterialFieldAccessor< MATERIAL_TYPE, TRAIT >( allowMissingViews );
121  acc.setName( solverName + "/accessors/" + TRAIT::key() );
122  } );
123  }
124 };
125 
126 
127 }
128 
129 #endif //GEOS_PHYSICSSOLVERS_FLUIDFLOW_STENCILACCESSORS_HPP_
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
Definition: GeosxMacros.hpp:84
The ElementRegionManager class provides an interface to ObjectManagerBase in order to manage ElementR...
ElementViewAccessor< traits::ViewTypeConst< typename FIELD_TRAIT::type > > constructFieldAccessor(string const &neighborName=string()) const
This is a const function to construct a ElementViewAccessor to access the data registered on the mesh...
ElementViewAccessor< traits::ViewTypeConst< typename FIELD_TRAIT::type > > constructMaterialFieldAccessor(arrayView1d< string const > const &regionNames, arrayView1d< string const > const &materialNames, bool const allowMissingViews=false) const
This is a const function to construct a MaterialViewAccessor to access the material data for specifie...
A struct to automatically construct and store element view accessors.
StencilAccessors(ElementRegionManager const &elemManager, string const &solverName)
Constructor for the struct.
StencilAccessors()=default
Constructor for the struct.
std::tuple< ElementRegionManager::ElementViewAccessor< traits::ViewTypeConst< typename TRAITS::type > > ... > m_accessors
the tuple storing all the accessors
A struct to automatically construct and store element view accessors.
StencilMaterialAccessors(ElementRegionManager const &elemManager, string const &solverName)
Constructor for the struct.
std::size_t size_t
Unsigned size type.
Definition: DataTypes.hpp:79