https://mooseframework.inl.gov
Loading...
Searching...
No Matches
SerialAccess.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12// MOOSE includes
13#include "Moose.h"
14#include "MooseTypes.h"
17
18#include <tuple>
19
20namespace Moose
21{
22
27template <typename T>
29{
30 static_assert(always_false<T>, "Specialize SerialAccess for this type.");
31};
32
33// Specializations for scalar types
34#define SERIAL_ACCESS_SCALAR(type) \
35 template <> \
36 struct SerialAccess<type> \
37 { \
38 static type * data(type & obj) { return &obj; } \
39 static constexpr std::size_t size(type &) { return 1u; } \
40 static constexpr std::size_t size() { return 1u; } \
41 }
42
44SERIAL_ACCESS_SCALAR(const Real);
47
48// constant size containers
49#define SERIAL_ACCESS_CONST_SIZE(type, dataptr, sizeval) \
50 template <typename T> \
51 struct SerialAccess<type<T>> \
52 { \
53 static auto * data(type<T> & obj) { return dataptr; } \
54 static constexpr std::size_t size(type<T> &) { return sizeval; } \
55 static constexpr std::size_t size() { return sizeval; } \
56 }
57
64 &obj(0u, 0u, 0u, 0u),
66
67// dynamic size containers (determining size requires an object instance)
68#define SERIAL_ACCESS_DYNAMIC_SIZE(type, dataptr, sizeval) \
69 template <typename T> \
70 struct SerialAccess<type<T>> \
71 { \
72 static auto * data(type<T> & obj) { return dataptr; } \
73 static constexpr std::size_t size(type<T> & obj) { return sizeval; } \
74 }
75
76SERIAL_ACCESS_DYNAMIC_SIZE(DenseVector, &obj(0u), obj.size());
77
82template <typename T>
84{
85 typedef typename T::value_type value_type;
86};
87template <>
92template <>
94{
95 typedef Real value_type;
96};
97
98template <typename T>
100{
101public:
105 typedef typename std::conditional<std::is_const_v<T>, const R, R>::type V;
106
108 {
109 public:
110 iterator(V * i) : _i(i) {}
111
112 V & operator*() const { return *_i; }
113
115 {
116 ++_i;
117 return *this;
118 }
119
121 {
122 iterator returnval(*this);
123 ++_i;
124 return returnval;
125 }
126
127 bool operator==(const iterator & j) const { return (_i == j._i); }
128 bool operator!=(const iterator & j) const { return !(*this == j); }
129
130 private:
131 V * _i;
132 };
133
135 : _begin(SerialAccess<T>::data(obj)),
136 _end(SerialAccess<T>::data(obj) + SerialAccess<T>::size(obj))
137 {
138 }
139
140 iterator begin() const { return _begin; }
141 iterator end() const { return _end; }
142
143 V & operator[](int i) { return *(&*_begin + i); }
144
145private:
147};
148
149template <typename T>
152{
153 return SerialAccessRange<T>(obj);
154}
155
157template <typename... Ts>
159{
160 typedef std::tuple<Ts...> Tuple;
161 typedef std::tuple<Ts *...> PointerTuple;
162 static constexpr std::size_t size = sizeof...(Ts);
163};
164
166template <template <typename, int> class L, int I, typename T, typename... Ts, typename... As>
167void
169{
170 L<T, I>::apply(args...);
171 if constexpr (sizeof...(Ts) > 0)
172 typeLoopInternal<L, I + 1>(TypeList<Ts...>{}, args...);
173}
174
176template <template <typename, int> class L, typename... Ts, typename... As>
177void
179{
180 typeLoopInternal<L, 0>(TypeList<Ts...>{}, args...);
181}
182
183} // namespace Moose;
DualNumber< Real, DNDerivativeType, true > ADReal
bool operator==(const iterator &j) const
bool operator!=(const iterator &j) const
iterator begin() const
std::conditional< std::is_const_v< T >, constR, R >::type V
Value type with the correct constness.
SerialAccessValueTypeHelper< typenamestd::remove_const< T >::type >::value_type R
Value type of the components of T.
RankFourTensorTempl is designed to handle any N-dimensional fourth order tensor, C.
RankTwoTensorTempl is designed to handle the Stress or Strain Tensor for a fully anisotropic material...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
SERIAL_ACCESS_DYNAMIC_SIZE(DenseVector, &obj(0u), obj.size())
void typeLoopInternal(TypeList< T, Ts... >, As... args)
Type loop.
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition Moose.h:165
void typeLoop(TypeList< Ts... >, As... args)
Type loop.
SERIAL_ACCESS_SCALAR(Real)
SerialAccessRange< T > serialAccess(T &obj)
SERIAL_ACCESS_CONST_SIZE(libMesh::VectorValue, &obj(0u), Moose::dim)
Value type helper (necessary for any type that does not have a value_type member or where value_type ...
Serial access requires object data to be stored contiguously.
Helper structure to hold a list of types.
static constexpr std::size_t size
std::tuple< Ts... > Tuple
std::tuple< Ts *... > PointerTuple