13#include <MGIS/Behaviour/Variable.hxx>
14#include <boost/mp11.hpp>
15#include <range/v3/view/enumerate.hpp>
16#include <range/v3/view/filter.hpp>
17#include <range/v3/view/map.hpp>
18#include <range/v3/view/zip.hpp>
31static constexpr std::array<double, 3 * 3 * 3 * 3>
63template <
typename Gradients,
typename TDynForces,
typename ExtStateVars>
66 static_assert(boost::mp11::mp_is_set<Gradients>::value);
67 static_assert(boost::mp11::mp_is_set<TDynForces>::value);
68 static_assert(boost::mp11::mp_is_set<ExtStateVars>::value);
71 boost::mp11::mp_append<Gradients, ExtStateVars>;
73 static_assert(boost::mp11::mp_is_set<GradientsAndExtStateVars>::value);
76 mp_product<boost::mp11::mp_list, TDynForces, GradientsAndExtStateVars>;
92template <
int DisplacementDim,
typename ForcesGradsCombinations>
95 static_assert(boost::mp11::mp_is_set<ForcesGradsCombinations>::value);
105 std::vector<std::pair<mgis::behaviour::Variable,
106 mgis::behaviour::Variable>>
const& to_blocks)
110 std::vector<bool> used_blocks(
111 to_blocks.size(),
false);
113 boost::mp11::mp_for_each<ForcesGradsCombinations>(
116 this]<
typename Force,
typename GradOrExtStateVar>(
117 boost::mp11::mp_list<Force, GradOrExtStateVar>)
119 std::size_t data_offset = 0;
120 for (
auto [
block, is_used] :
121 ranges::views::zip(to_blocks, used_blocks))
123 auto const& [force, grad] =
block;
124 if (force.name == Force::name &&
125 grad.name == GradOrExtStateVar::name)
127 auto constexpr block_idx =
134 data_offset +=
size(force.type) *
size(grad.type);
139 auto indices = ranges::views::enumerate(used_blocks) |
140 ranges::views::filter([](
auto const& pair)
141 {
return !pair.second; }) |
144 if (!indices.empty())
146 ERR(
"There are unused tangent operator blocks provided by MFront. "
147 "Following blocks are unused:");
149 for (
auto const i : indices)
151 auto const& [force, grad] = to_blocks[i];
152 ERR(
"\t{}/{}", force.name, grad.name);
154 OGS_FATAL(
"All tangent operator blocks must be used.");
164 template <
typename Force,
typename GradOrExtStateVar>
170 boost::mp11::mp_contains<
172 boost::mp11::mp_list<Force, GradOrExtStateVar>>::value,
173 "Requested tangent block was not created in the "
174 "OGSMFrontTangentOperatorBlocksView.");
177 const auto offset =
offsets_[index];
180 constexpr auto grad_size =
183 if constexpr (grad_size == 1 && force_size == 1)
190 return data.
data[offset];
194 constexpr auto order =
195 grad_size == 1 ? Eigen::ColMajor : Eigen::RowMajor;
197 using Result = Eigen::Map<
198 const Eigen::Matrix<double, force_size, grad_size, order>>;
206 return Result{data.
data.data() + offset};
211 static constexpr std::size_t
size(mgis::behaviour::Variable::Type vt)
213 using VT = mgis::behaviour::Variable::Type;
223 return DisplacementDim;
232 template <
typename Force,
typename GradOrExtStateVar>
235 return boost::mp11::mp_find<
237 boost::mp11::mp_list<Force, GradOrExtStateVar>>::value;
244 std::array<std::size_t,
245 boost::mp11::mp_size<ForcesGradsCombinations>::value>
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
OGSMFrontTangentOperatorBlocksView(std::vector< std::pair< mgis::behaviour::Variable, mgis::behaviour::Variable > > const &to_blocks)
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.
static constexpr std::size_t invalid_offset_
std::array< std::size_t, boost::mp11::mp_size< ForcesGradsCombinations >::value > offsets_
auto block(Force, GradOrExtStateVar, OGSMFrontTangentOperatorData const &data) const
constexpr auto to_underlying(E e) noexcept
Converts an enumeration to its underlying type.
static constexpr std::array< double, 3 *3 *3 *3 > OGSMFrontTangentOperatorBlocksViewZeroes
constexpr int tensorSize(int dim)
See Tensor type for details.
constexpr int kelvin_vector_dimensions(int const displacement_dim)
Kelvin vector dimensions for given displacement dimension.
boost::mp11:: mp_product< boost::mp11::mp_list, TDynForces, GradientsAndExtStateVars > type
boost::mp11::mp_append< Gradients, ExtStateVars > GradientsAndExtStateVars
Used for disambiguation with MFront's thermodynamic forces data.
std::vector< double > data