31#include <boost/multi_array.hpp>
43using namespace ::FieldCoupling::Fields;
52template <
typename Field>
struct field_params_impl;
54template <
typename T, std::
size_t codim>
55struct field_params_impl<Constant<T, codim>> {
56 static Constant<T, codim> make(
const VariantMap ¶ms) {
57 return Constant<T, codim>{
58 get_value<typename Constant<T, codim>::value_type>(params,
"value")};
60 template <
typename This>
61 static std::vector<AutoParameter> params(
const This &this_) {
63 [this_]() {
return this_().value(); }}};
67template <
typename T, std::
size_t codim>
68struct field_params_impl<AffineMap<T, codim>> {
72 static AffineMap<T, codim> make(
const VariantMap ¶ms) {
73 return AffineMap<T, codim>{
78 template <
typename This>
79 static std::vector<AutoParameter> params(
const This &this_) {
85template <
typename T, std::
size_t codim>
86struct field_params_impl<PlaneWave<T, codim>> {
90 static PlaneWave<T, codim> make(
const VariantMap ¶ms) {
97 template <
typename This>
98 static std::vector<AutoParameter> params(
const This &this_) {
100 [this_]() {
return this_().amplitude(); }},
102 [this_]() {
return this_().k(); }},
104 [this_]() {
return this_().omega(); }},
106 [this_]() {
return this_().phase(); }}};
110template <
typename T, std::
size_t codim>
111struct field_params_impl<Interpolated<T, codim>> {
112 static Interpolated<T, codim> make(
const VariantMap ¶ms) {
113 auto const field_data =
118 if (field_codim != codim) {
119 throw std::runtime_error(
120 "Field data has the wrong dimensions, needs to be [n, m, o, " +
121 std::to_string(codim) +
']');
124 if (*std::ranges::min_element(field_shape) < 1) {
125 throw std::runtime_error(
"Field is too small, needs to be at least "
126 "one in all directions.");
129 auto const grid_spacing =
131 auto const origin = -0.5 * grid_spacing;
133 using field_data_type =
134 typename Utils::decay_to_scalar<Utils::Vector<T, codim>>::type;
135 auto array_ref = boost::const_multi_array_ref<field_data_type, 3>(
136 reinterpret_cast<const field_data_type *
>(field_data.data()),
139 return Interpolated<T, codim>{array_ref, grid_spacing, origin};
142 template <
typename This>
143 static std::vector<AutoParameter> params(
const This &this_) {
145 [this_]() {
return this_().grid_spacing(); }},
147 [this_]() {
return this_().origin(); }},
149 [this_]() {
return this_().shape(); }},
151 []() {
return static_cast<int>(codim); }},
153 [this_]() {
return this_().field_data_flat(); }}};
157template <
typename Field,
typename T>
158static std::vector<AutoParameter> field_parameters(
const T &this_) {
159 return field_params_impl<Field>::params(this_);
162template <
typename Field> Field make_field(
const VariantMap ¶ms) {
163 return field_params_impl<Field>::make(params);
Vector implementation and trait types for boost qvm interoperability.
detail::jacobian_type< T, codim > jacobian_type
typename Utils::decay_to_scalar< Utils::Vector< T, codim > >::type value_type
typename Utils::decay_to_scalar< Utils::Vector< T, codim > >::type value_type
detail::jacobian_type< T, codim > jacobian_type
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
T get_value_or(VariantMap const &vals, std::string const &name, T const &default_)
Get a value from a VariantMap by name, or return a default value if it does not exist.
std::unordered_map< std::string, Variant > VariantMap
static constexpr const ReadOnly read_only