feat(field-support): added field support system, mid migration
currently the barotope and the pressure force operator are migrated to the new support system
This commit is contained in:
@@ -23,8 +23,7 @@ export namespace mean_field::utils::blocks {
|
||||
struct field { };
|
||||
|
||||
template <typename Residual, typename... Values> struct block_row { };
|
||||
template <int index_value>
|
||||
struct residual_block final : residual_block_base {
|
||||
template <int index_value> struct residual_block final : residual_block_base {
|
||||
static constexpr int index = index_value;
|
||||
|
||||
// ReSharper disable once CppNonExplicitConversionOperator
|
||||
@@ -110,43 +109,33 @@ export namespace mean_field::utils::blocks {
|
||||
|
||||
template <typename Query, typename List> struct contains_type;
|
||||
|
||||
template <typename Query>
|
||||
struct contains_type<Query, type_list<>> : std::false_type { };
|
||||
template <typename Query> struct contains_type<Query, type_list<>> : std::false_type { };
|
||||
|
||||
template <typename Query, typename Head, typename... Tail>
|
||||
struct contains_type<Query, type_list<Head, Tail...>>
|
||||
: std::conditional_t<
|
||||
std::is_same_v<Query, Head>,
|
||||
std::true_type,
|
||||
contains_type<Query, type_list<Tail...>>> { };
|
||||
: std::conditional_t<std::is_same_v<Query, Head>, std::true_type, contains_type<Query, type_list<Tail...>>> { };
|
||||
|
||||
template <typename Query, typename List>
|
||||
inline constexpr bool contains_type_v = contains_type<Query, List>::value;
|
||||
template <typename Query, typename List> inline constexpr bool contains_type_v = contains_type<Query, List>::value;
|
||||
|
||||
template <typename Query, typename List> struct type_count;
|
||||
|
||||
template <typename Query>
|
||||
struct type_count<Query, type_list<>> : std::integral_constant<int, 0> { };
|
||||
template <typename Query> struct type_count<Query, type_list<>> : std::integral_constant<int, 0> { };
|
||||
|
||||
template <typename Query, typename Head, typename... Tail>
|
||||
struct type_count<Query, type_list<Head, Tail...>>
|
||||
: std::integral_constant<
|
||||
int,
|
||||
(std::is_same_v<Query, Head> ? 1 : 0) +
|
||||
type_count<Query, type_list<Tail...>>::value> { };
|
||||
(std::is_same_v<Query, Head> ? 1 : 0) + type_count<Query, type_list<Tail...>>::value> { };
|
||||
|
||||
template <typename Query, typename List>
|
||||
inline constexpr int type_count_v = type_count<Query, List>::value;
|
||||
template <typename Query, typename List> inline constexpr int type_count_v = type_count<Query, List>::value;
|
||||
|
||||
template <typename List> struct types_are_unique;
|
||||
|
||||
template <typename... Types>
|
||||
struct types_are_unique<type_list<Types...>>
|
||||
: std::bool_constant<
|
||||
((type_count_v<Types, type_list<Types...>> == 1) && ...)> { };
|
||||
: std::bool_constant<((type_count_v<Types, type_list<Types...>> == 1) && ...)> { };
|
||||
|
||||
template <typename List>
|
||||
inline constexpr bool types_are_unique_v = types_are_unique<List>::value;
|
||||
template <typename List> inline constexpr bool types_are_unique_v = types_are_unique<List>::value;
|
||||
|
||||
template <typename Row> struct block_row_traits {
|
||||
using residual = void;
|
||||
@@ -156,8 +145,7 @@ export namespace mean_field::utils::blocks {
|
||||
static constexpr bool is_block_row = false;
|
||||
};
|
||||
|
||||
template <typename Residual, typename... Values>
|
||||
struct block_row_traits<block_row<Residual, Values...>> {
|
||||
template <typename Residual, typename... Values> struct block_row_traits<block_row<Residual, Values...>> {
|
||||
using residual = Residual;
|
||||
using values = type_list<Values...>;
|
||||
|
||||
@@ -167,19 +155,15 @@ export namespace mean_field::utils::blocks {
|
||||
|
||||
template <typename Query, typename List> struct type_index;
|
||||
|
||||
template <typename Query, typename... Tail>
|
||||
struct type_index<Query, type_list<Query, Tail...>> {
|
||||
template <typename Query, typename... Tail> struct type_index<Query, type_list<Query, Tail...>> {
|
||||
static constexpr int value = 0;
|
||||
};
|
||||
|
||||
template <typename Query, typename Head, typename... Tail>
|
||||
struct type_index<Query, type_list<Head, Tail...>> {
|
||||
static constexpr int value =
|
||||
1 + type_index<Query, type_list<Tail...>>::value;
|
||||
template <typename Query, typename Head, typename... Tail> struct type_index<Query, type_list<Head, Tail...>> {
|
||||
static constexpr int value = 1 + type_index<Query, type_list<Tail...>>::value;
|
||||
};
|
||||
|
||||
template <typename Query, typename List>
|
||||
inline constexpr int type_index_v = type_index<Query, List>::value;
|
||||
template <typename Query, typename List> inline constexpr int type_index_v = type_index<Query, List>::value;
|
||||
|
||||
template <typename ValueBlocks, typename ResidualBlocks> struct block_form {
|
||||
using value_blocks = ValueBlocks;
|
||||
@@ -192,36 +176,22 @@ export namespace mean_field::utils::blocks {
|
||||
template <typename Form> struct block_form_is_valid : std::false_type { };
|
||||
|
||||
template <typename... Values, typename... Residuals>
|
||||
struct block_form_is_valid<
|
||||
block_form<type_list<Values...>, type_list<Residuals...>>>
|
||||
struct block_form_is_valid<block_form<type_list<Values...>, type_list<Residuals...>>>
|
||||
: std::bool_constant<
|
||||
(std::is_base_of_v<value_block_base, Values> && ...) &&
|
||||
(std::is_base_of_v<residual_block_base, Residuals> && ...) &&
|
||||
types_are_unique_v<type_list<Values...>> &&
|
||||
(std::is_base_of_v<residual_block_base, Residuals> && ...) && types_are_unique_v<type_list<Values...>> &&
|
||||
types_are_unique_v<type_list<Residuals...>>> { };
|
||||
|
||||
template <typename Form>
|
||||
inline constexpr bool block_form_is_valid_v =
|
||||
block_form_is_valid<Form>::value;
|
||||
template <typename Form> inline constexpr bool block_form_is_valid_v = block_form_is_valid<Form>::value;
|
||||
|
||||
template <typename Row, typename ValueBlocks, typename ResidualBlocks>
|
||||
struct block_row_is_valid : std::false_type { };
|
||||
|
||||
template <
|
||||
typename Residual,
|
||||
typename... Values,
|
||||
typename ValueBlocks,
|
||||
typename ResidualBlocks>
|
||||
struct block_row_is_valid<
|
||||
block_row<Residual, Values...>,
|
||||
ValueBlocks,
|
||||
ResidualBlocks>
|
||||
template <typename Residual, typename... Values, typename ValueBlocks, typename ResidualBlocks>
|
||||
struct block_row_is_valid<block_row<Residual, Values...>, ValueBlocks, ResidualBlocks>
|
||||
: std::bool_constant<
|
||||
std::is_base_of_v<residual_block_base, Residual> &&
|
||||
contains_type_v<Residual, ResidualBlocks> &&
|
||||
((std::is_base_of_v<value_block_base, Values> &&
|
||||
contains_type_v<Values, ValueBlocks>) &&
|
||||
...) &&
|
||||
std::is_base_of_v<residual_block_base, Residual> && contains_type_v<Residual, ResidualBlocks> &&
|
||||
((std::is_base_of_v<value_block_base, Values> && contains_type_v<Values, ValueBlocks>) && ...) &&
|
||||
types_are_unique_v<type_list<Values...>>> { };
|
||||
|
||||
template <typename Rows> struct row_residual_list;
|
||||
@@ -230,73 +200,50 @@ export namespace mean_field::utils::blocks {
|
||||
using type = type_list<typename block_row_traits<Rows>::residual...>;
|
||||
};
|
||||
|
||||
template <typename Rows>
|
||||
using row_residual_list_t = typename row_residual_list<Rows>::type;
|
||||
template <typename Rows> using row_residual_list_t = typename row_residual_list<Rows>::type;
|
||||
|
||||
template <typename Form, typename JacobianForm>
|
||||
struct jacobian_form_is_valid : std::false_type { };
|
||||
template <typename Form, typename JacobianForm> struct jacobian_form_is_valid : std::false_type { };
|
||||
|
||||
template <typename... Values, typename... Residuals, typename... Rows>
|
||||
struct jacobian_form_is_valid<
|
||||
block_form<type_list<Values...>, type_list<Residuals...>>,
|
||||
type_list<Rows...>> {
|
||||
using form_type =
|
||||
block_form<type_list<Values...>, type_list<Residuals...>>;
|
||||
struct jacobian_form_is_valid<block_form<type_list<Values...>, type_list<Residuals...>>, type_list<Rows...>> {
|
||||
using form_type = block_form<type_list<Values...>, type_list<Residuals...>>;
|
||||
|
||||
using value_blocks = type_list<Values...>;
|
||||
using residual_blocks = type_list<Residuals...>;
|
||||
using rows = type_list<Rows...>;
|
||||
using value_blocks = type_list<Values...>;
|
||||
using residual_blocks = type_list<Residuals...>;
|
||||
using rows = type_list<Rows...>;
|
||||
|
||||
static constexpr bool value =
|
||||
block_form_is_valid_v<form_type> &&
|
||||
(block_row_is_valid<Rows, value_blocks, residual_blocks>::value &&
|
||||
...) &&
|
||||
std::is_same_v<row_residual_list_t<rows>, residual_blocks>;
|
||||
static constexpr bool value = block_form_is_valid_v<form_type> &&
|
||||
(block_row_is_valid<Rows, value_blocks, residual_blocks>::value && ...) &&
|
||||
std::is_same_v<row_residual_list_t<rows>, residual_blocks>;
|
||||
};
|
||||
|
||||
template <typename Form, typename JacobianForm>
|
||||
inline constexpr bool jacobian_form_is_valid_v =
|
||||
jacobian_form_is_valid<Form, JacobianForm>::value;
|
||||
inline constexpr bool jacobian_form_is_valid_v = jacobian_form_is_valid<Form, JacobianForm>::value;
|
||||
|
||||
template <typename Form, typename JacobianForm>
|
||||
concept valid_jacobian_form = jacobian_form_is_valid_v<Form, JacobianForm>;
|
||||
|
||||
template <typename Residual, typename Value, typename JacobianForm>
|
||||
struct has_jacobian_coupling;
|
||||
template <typename Residual, typename Value, typename JacobianForm> struct has_jacobian_coupling;
|
||||
|
||||
template <typename Residual, typename Value>
|
||||
struct has_jacobian_coupling<Residual, Value, type_list<>>
|
||||
: std::false_type { };
|
||||
struct has_jacobian_coupling<Residual, Value, type_list<>> : std::false_type { };
|
||||
|
||||
template <
|
||||
typename Residual,
|
||||
typename Value,
|
||||
typename RowResidual,
|
||||
typename... RowValues,
|
||||
typename... RemainingRows>
|
||||
struct has_jacobian_coupling<
|
||||
Residual,
|
||||
Value,
|
||||
type_list<block_row<RowResidual, RowValues...>, RemainingRows...>>
|
||||
template <typename Residual, typename Value, typename RowResidual, typename... RowValues, typename... RemainingRows>
|
||||
struct has_jacobian_coupling<Residual, Value, type_list<block_row<RowResidual, RowValues...>, RemainingRows...>>
|
||||
: std::conditional_t<
|
||||
std::is_same_v<Residual, RowResidual>,
|
||||
std::bool_constant<(std::is_same_v<Value, RowValues> || ...)>,
|
||||
has_jacobian_coupling<
|
||||
Residual,
|
||||
Value,
|
||||
type_list<RemainingRows...>>> { };
|
||||
has_jacobian_coupling<Residual, Value, type_list<RemainingRows...>>> { };
|
||||
|
||||
template <typename Residual, typename Value, typename JacobianForm>
|
||||
inline constexpr bool has_jacobian_coupling_v =
|
||||
has_jacobian_coupling<Residual, Value, JacobianForm>::value;
|
||||
inline constexpr bool has_jacobian_coupling_v = has_jacobian_coupling<Residual, Value, JacobianForm>::value;
|
||||
|
||||
template <
|
||||
typename Form,
|
||||
typename Term>
|
||||
consteval auto get_value_block(const Term &) {
|
||||
using value_type = typename Term::value;
|
||||
constexpr int index =
|
||||
type_index_v<value_type, typename Form::value_blocks>;
|
||||
using value_type = typename Term::value;
|
||||
constexpr int index = type_index_v<value_type, typename Form::value_blocks>;
|
||||
return value_block<index>{};
|
||||
}
|
||||
|
||||
@@ -305,8 +252,7 @@ export namespace mean_field::utils::blocks {
|
||||
typename Term>
|
||||
consteval auto get_residual_block(const Term &) {
|
||||
using residual_type = typename Term::residual;
|
||||
constexpr int index =
|
||||
type_index_v<residual_type, typename Form::residual_blocks>;
|
||||
constexpr int index = type_index_v<residual_type, typename Form::residual_blocks>;
|
||||
return residual_block<index>{};
|
||||
}
|
||||
|
||||
@@ -320,32 +266,24 @@ export namespace mean_field::utils::blocks {
|
||||
int,
|
||||
Form::residual_block_count> &residual_sizes
|
||||
) {
|
||||
build_offsets(
|
||||
m_value_offsets, value_sizes, typename Form::value_blocks{}
|
||||
);
|
||||
build_offsets(m_value_offsets, value_sizes, typename Form::value_blocks{});
|
||||
|
||||
build_offsets(
|
||||
m_residual_offsets, residual_sizes,
|
||||
typename Form::residual_blocks{}
|
||||
);
|
||||
build_offsets(m_residual_offsets, residual_sizes, typename Form::residual_blocks{});
|
||||
}
|
||||
|
||||
template <int index> [[nodiscard]] int size(value_block<index>) const {
|
||||
return m_value_offsets[index + 1] - m_value_offsets[index];
|
||||
}
|
||||
|
||||
template <int index>
|
||||
[[nodiscard]] int size(residual_block<index>) const {
|
||||
template <int index> [[nodiscard]] int size(residual_block<index>) const {
|
||||
return m_residual_offsets[index + 1] - m_residual_offsets[index];
|
||||
}
|
||||
|
||||
template <int index>
|
||||
[[nodiscard]] int offset(value_block<index>) const {
|
||||
template <int index> [[nodiscard]] int offset(value_block<index>) const {
|
||||
return m_value_offsets[index];
|
||||
}
|
||||
|
||||
template <int index>
|
||||
[[nodiscard]] int offset(residual_block<index>) const {
|
||||
template <int index> [[nodiscard]] int offset(residual_block<index>) const {
|
||||
return m_residual_offsets[index];
|
||||
}
|
||||
|
||||
@@ -391,8 +329,7 @@ export namespace mean_field::utils::blocks {
|
||||
int block_index = 0;
|
||||
|
||||
((offsets[block_index + 1] =
|
||||
offsets[block_index] +
|
||||
resolve_block_size<BlockTypes>(requested_sizes[block_index]),
|
||||
offsets[block_index] + resolve_block_size<BlockTypes>(requested_sizes[block_index]),
|
||||
++block_index),
|
||||
...);
|
||||
}
|
||||
@@ -463,10 +400,12 @@ export namespace mean_field::utils::blocks {
|
||||
enthalpy::specific::value,
|
||||
displacement::geometry::value>,
|
||||
|
||||
// R_d(d, h)
|
||||
// R_d(rho, d, g, h)
|
||||
block_row<
|
||||
displacement::geometry::residual,
|
||||
density::mass::value,
|
||||
displacement::geometry::value,
|
||||
gravity::gradient::value,
|
||||
enthalpy::specific::value>,
|
||||
|
||||
// R_h(h, Phi, d, C)
|
||||
@@ -483,6 +422,15 @@ export namespace mean_field::utils::blocks {
|
||||
density::mass::value,
|
||||
displacement::geometry::value>>;
|
||||
|
||||
// Columns: [d, h]
|
||||
// Rows: [R_d]
|
||||
using pressure_force_form = block_form<
|
||||
type_list<displacement::geometry::value, enthalpy::specific::value>,
|
||||
type_list<displacement::geometry::residual>>;
|
||||
|
||||
using pressure_force_jacobian_form = type_list<
|
||||
block_row<displacement::geometry::residual, displacement::geometry::value, enthalpy::specific::value>>;
|
||||
|
||||
static_assert(valid_jacobian_form<
|
||||
gravity_field_form,
|
||||
gravity_jacobian_form>);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -66,15 +66,13 @@ export namespace mean_field::utils {
|
||||
[[maybe_unused]] constexpr int PORT = 19916;
|
||||
|
||||
template <typename T>
|
||||
concept is_xad = std::is_same_v<T, xad::AReal<long double>> ||
|
||||
std::is_same_v<T, xad::AReal<double>> ||
|
||||
concept is_xad = std::is_same_v<T, xad::AReal<long double>> || std::is_same_v<T, xad::AReal<double>> ||
|
||||
std::is_same_v<T, xad::AReal<float>>;
|
||||
|
||||
template <typename T>
|
||||
concept is_real = std::is_floating_point_v<T> || is_xad<T>;
|
||||
concept is_real = std::is_floating_point_v<T> || is_xad<T>;
|
||||
|
||||
template <is_real T>
|
||||
using EOS_P = std::function<T(const T &rho, const T &temp)>;
|
||||
template <is_real T> using EOS_P = std::function<T(const T &rho, const T &temp)>;
|
||||
|
||||
enum class DOMAINS : uint8_t {
|
||||
CORE = 1 << 0,
|
||||
|
||||
@@ -32,8 +32,7 @@ export namespace mean_field::utils {
|
||||
double mass{};
|
||||
double c{};
|
||||
DomainMapperStatelessOptions domain_mapper_options{};
|
||||
mapping::compactification::options::KelvinCompactificationOptions
|
||||
kelvin_options{};
|
||||
mapping::compactification::options::KelvinCompactificationOptions kelvin_options{};
|
||||
int max_iters{};
|
||||
double tol{};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user