31#include <boost/multi_array.hpp>
52template <
typename Field>
struct field_params_impl;
54template <
typename T, std::
size_t codim>
55struct field_params_impl<Constant<T, codim>> {
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>> {
73 return AffineMap<T, codim>{
74 get_value<jacobian_type>(
params,
"A"),
75 get_value_or<value_type>(
params,
"b", value_type{})};
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>> {
91 return PlaneWave<T, codim>{get_value<value_type>(
params,
"amplitude"),
92 get_value<value_type>(
params,
"wave_vector"),
93 get_value<T>(
params,
"frequency"),
94 get_value_or<T>(
params,
"phase", 0.)};
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>> {
113 auto const field_data =
114 get_value<std::vector<double>>(
params,
"_field_data");
115 auto const field_shape = get_value<Utils::Vector3i>(
params,
"_field_shape");
116 auto const field_codim = get_value<int>(
params,
"_field_codim");
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::min_element(field_shape.begin(), field_shape.end()) < 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 =
130 get_value<Utils::Vector3d>(
params,
"grid_spacing");
131 auto const origin = -0.5 * grid_spacing;
133 using field_data_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 &
params) {
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
std::unordered_map< std::string, Variant > VariantMap
static SteepestDescentParameters params
Currently active steepest descent instance.
static constexpr const ReadOnly read_only
Meta function to turns a Vector<1, T> into T.