OGS
MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations > Class Template Reference

Detailed Description

template<int DisplacementDim, typename ForcesGradsCombinations>
class MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >

Provides convenient access to the individual blocks of MFront's tangent operator data.

Template Parameters
DisplacementDimthe displacement dimension
ForcesGradsCombinationsa list of pairs types corresponding to the tangent operator blocks' variables. See ForcesGradsCombinations template for details.

MFront's tangent operator blocks are stored in a single vector of double values. The implementer of an MFront behaviour can decide which blocks she wants to provide and in which order.

Definition at line 93 of file TangentOperatorBlocksView.h.

#include <TangentOperatorBlocksView.h>

Public Member Functions

 OGSMFrontTangentOperatorBlocksView (std::vector< std::pair< mgis::behaviour::Variable, mgis::behaviour::Variable > > const &to_blocks)
 
template<typename Force , typename GradOrExtStateVar >
auto block (Force, GradOrExtStateVar, OGSMFrontTangentOperatorData const &data) const
 

Static Private Member Functions

static constexpr std::size_t size (mgis::behaviour::Variable::Type vt)
 
template<typename Force , typename GradOrExtStateVar >
static constexpr std::size_t blockIndex ()
 Computes the index of a tangent operator block in the offsets_ array.
 

Private Attributes

std::array< std::size_t, boost::mp11::mp_size< ForcesGradsCombinations >::value > offsets_
 

Static Private Attributes

static constexpr std::size_t invalid_offset_ = -1
 

Constructor & Destructor Documentation

◆ OGSMFrontTangentOperatorBlocksView()

template<int DisplacementDim, typename ForcesGradsCombinations >
MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::OGSMFrontTangentOperatorBlocksView ( std::vector< std::pair< mgis::behaviour::Variable, mgis::behaviour::Variable > > const & to_blocks)
inlineexplicit

Constructs a view for the tangent operator blocks to_blocks of some MFront behaviour.

Definition at line 104 of file TangentOperatorBlocksView.h.

107 {
109
110 std::vector<bool> used_blocks(
111 to_blocks.size(), false); // checked after creation of all offsets.
112
113 boost::mp11::mp_for_each<ForcesGradsCombinations>(
114 [&to_blocks,
115 &used_blocks,
116 this]<typename Force, typename GradOrExtStateVar>(
117 boost::mp11::mp_list<Force, GradOrExtStateVar>)
118 {
119 std::size_t data_offset = 0;
120 for (auto [block, is_used] :
121 ranges::views::zip(to_blocks, used_blocks))
122 {
123 auto const& [force, grad] = block;
124 if (force.name == Force::name &&
125 grad.name == GradOrExtStateVar::name)
126 {
127 auto constexpr block_idx =
129 offsets_[block_idx] = data_offset;
130 is_used = true;
131 return;
132 }
133
134 data_offset += size(force.type) * size(grad.type);
135 }
136 });
137
138 // Indices of unused blocks.
139 auto indices = ranges::views::enumerate(used_blocks) |
140 ranges::views::filter([](auto const& pair)
141 { return !pair.second; }) |
142 ranges::views::keys;
143
144 if (!indices.empty())
145 {
146 ERR("There are unused tangent operator blocks provided by MFront. "
147 "Following blocks are unused:");
148
149 for (auto const i : indices)
150 {
151 auto const& [force, grad] = to_blocks[i];
152 ERR("\t{}/{}", force.name, grad.name);
153 }
154 OGS_FATAL("All tangent operator blocks must be used.");
155 }
156 }
#define OGS_FATAL(...)
Definition Error.h:26
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
static constexpr std::size_t size(mgis::behaviour::Variable::Type vt)
static constexpr std::size_t blockIndex()
Computes the index of a tangent operator block in the offsets_ array.
std::array< std::size_t, boost::mp11::mp_size< ForcesGradsCombinations >::value > offsets_
auto block(Force, GradOrExtStateVar, OGSMFrontTangentOperatorData const &data) const

References MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::block(), MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::blockIndex(), ERR(), MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::invalid_offset_, MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::offsets_, OGS_FATAL, and MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::size().

Member Function Documentation

◆ block()

template<int DisplacementDim, typename ForcesGradsCombinations >
template<typename Force , typename GradOrExtStateVar >
auto MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::block ( Force ,
GradOrExtStateVar ,
OGSMFrontTangentOperatorData const & data ) const
inline

Read access to the block dForce/dGradOrExtStateVar.

Returns an Eigen::Map, or a double value in the 1x1 case.

If the block is not provided by the MFront behavior, the returned data is all zero.

Definition at line 165 of file TangentOperatorBlocksView.h.

168 {
169 static_assert(
170 boost::mp11::mp_contains<
171 ForcesGradsCombinations,
172 boost::mp11::mp_list<Force, GradOrExtStateVar>>::value,
173 "Requested tangent block was not created in the "
174 "OGSMFrontTangentOperatorBlocksView.");
175
176 constexpr auto index = blockIndex<Force, GradOrExtStateVar>();
177 const auto offset = offsets_[index];
178
179 constexpr auto force_size = Force::template size<DisplacementDim>();
180 constexpr auto grad_size =
181 GradOrExtStateVar::template size<DisplacementDim>();
182
183 if constexpr (grad_size == 1 && force_size == 1)
184 {
185 if (offset == invalid_offset_)
186 {
187 return 0.0;
188 }
189
190 return data.data[offset];
191 }
192 else
193 {
194 constexpr auto order =
195 grad_size == 1 ? Eigen::ColMajor : Eigen::RowMajor;
196
197 using Result = Eigen::Map<
198 const Eigen::Matrix<double, force_size, grad_size, order>>;
199
200 if (offset == invalid_offset_)
201 {
202 return Result{
204 }
205
206 return Result{data.data.data() + offset};
207 }
208 }
static constexpr std::array< double, 3 *3 *3 *3 > OGSMFrontTangentOperatorBlocksViewZeroes

References MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::blockIndex(), MaterialLib::Solids::MFront::OGSMFrontTangentOperatorData::data, MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::invalid_offset_, MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::offsets_, MaterialLib::Solids::MFront::detail::OGSMFrontTangentOperatorBlocksViewZeroes, and MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::size().

Referenced by MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::OGSMFrontTangentOperatorBlocksView().

◆ blockIndex()

template<int DisplacementDim, typename ForcesGradsCombinations >
template<typename Force , typename GradOrExtStateVar >
static constexpr std::size_t MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::blockIndex ( )
inlinestaticconstexprprivate

Computes the index of a tangent operator block in the offsets_ array.

Definition at line 233 of file TangentOperatorBlocksView.h.

234 {
235 return boost::mp11::mp_find<
236 ForcesGradsCombinations,
237 boost::mp11::mp_list<Force, GradOrExtStateVar>>::value;
238 }

Referenced by MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::OGSMFrontTangentOperatorBlocksView(), and MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::block().

◆ size()

template<int DisplacementDim, typename ForcesGradsCombinations >
static constexpr std::size_t MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::size ( mgis::behaviour::Variable::Type vt)
inlinestaticconstexprprivate

Definition at line 211 of file TangentOperatorBlocksView.h.

212 {
213 using VT = mgis::behaviour::Variable::Type;
214
215 switch (vt)
216 {
217 case VT::SCALAR:
218 return 1;
219 case VT::STENSOR:
221 DisplacementDim);
222 case VT::VECTOR:
223 return DisplacementDim;
224 case VT::TENSOR:
225 return MaterialPropertyLib::tensorSize(DisplacementDim);
226 }
227
228 OGS_FATAL("Unsupported variable type {}", BaseLib::to_underlying(vt));
229 }
constexpr auto to_underlying(E e) noexcept
Converts an enumeration to its underlying type.
Definition cpp23.h:29
constexpr int tensorSize(int dim)
See Tensor type for details.
Definition Tensor.h:19
constexpr int kelvin_vector_dimensions(int const displacement_dim)
Kelvin vector dimensions for given displacement dimension.

References MathLib::KelvinVector::kelvin_vector_dimensions(), OGS_FATAL, MaterialPropertyLib::tensorSize(), and BaseLib::to_underlying().

Referenced by MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::OGSMFrontTangentOperatorBlocksView(), and MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::block().

Member Data Documentation

◆ invalid_offset_

◆ offsets_

template<int DisplacementDim, typename ForcesGradsCombinations >
std::array<std::size_t, boost::mp11::mp_size<ForcesGradsCombinations>::value> MaterialLib::Solids::MFront::OGSMFrontTangentOperatorBlocksView< DisplacementDim, ForcesGradsCombinations >::offsets_
private

The documentation for this class was generated from the following file: