feat(mean_field): added dimensions, discritization, and start of eos
The full rewrite of mean_field into something maintainable is progressing. dimensions is mostly done, discritization (domain, blocks, and fields) is done, and eos is progressing quickly
This commit is contained in:
15
src/include/serif/utils/misc/concepts/exceptions.hpp
Normal file
15
src/include/serif/utils/misc/concepts/exceptions.hpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <exception>
|
||||
#include <type_traits>
|
||||
#include <string>
|
||||
|
||||
#include "serif/utils/misc/concepts/numeric.hpp"
|
||||
|
||||
namespace serif::utils::misc::concepts {
|
||||
template <typename ExceptionCandidate>
|
||||
concept IsException = std::is_base_of_v<std::exception, ExceptionCandidate>;
|
||||
|
||||
template <typename ExceptionCandidate, typename ErrorCode>
|
||||
concept IsExceptionWithErrorCode = IsException<ExceptionCandidate> &&
|
||||
std::constructible_from<ExceptionCandidate, ErrorCode, std::string>;
|
||||
}
|
||||
26
src/include/serif/utils/misc/concepts/numeric.hpp
Normal file
26
src/include/serif/utils/misc/concepts/numeric.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <concepts>
|
||||
#include <type_traits>
|
||||
|
||||
namespace serif::utils::misc::concepts {
|
||||
template <typename T>
|
||||
concept IsNumeric = std::integral<T> || std::floating_point<T>;
|
||||
|
||||
template <typename T>
|
||||
concept IsOrderable = std::totally_ordered<T>;
|
||||
|
||||
template <typename T>
|
||||
concept IsComparableToNumeric = std::totally_ordered_with<T, float> ||
|
||||
std::totally_ordered_with<T, double> ||
|
||||
std::totally_ordered_with<T, long double> ||
|
||||
std::totally_ordered_with<T, int> ||
|
||||
std::totally_ordered_with<T, long> ||
|
||||
std::totally_ordered_with<T, long long>;
|
||||
|
||||
template <typename...Ts>
|
||||
concept SetOfOneOrTwo = (sizeof...(Ts) == 1) || (sizeof...(Ts) == 2);
|
||||
|
||||
template <typename EnumCandidate>
|
||||
concept IsEnum = std::is_enum_v<EnumCandidate>;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "serif/utils/misc/traits/type_uniqueness.hpp"
|
||||
|
||||
namespace serif::utils::misc::concepts {
|
||||
template <typename...Ts>
|
||||
concept AllTypesAreUnique = traits::all_unique_types_v<Ts...>;
|
||||
}
|
||||
44
src/include/serif/utils/misc/finite.hpp
Normal file
44
src/include/serif/utils/misc/finite.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
#include <format>
|
||||
|
||||
#include "serif/utils/misc/concepts/numeric.hpp"
|
||||
#include "serif/utils/misc/concepts/exceptions.hpp"
|
||||
|
||||
namespace serif::utils::misc {
|
||||
template <typename ExceptionType, concepts::IsNumeric Scalar, concepts::IsEnum ErrorCode>
|
||||
requires concepts::IsExceptionWithErrorCode<ExceptionType, ErrorCode>
|
||||
void validate_finite(const Scalar value, ErrorCode error_code) {
|
||||
if (!std::isfinite(value)) {
|
||||
throw ExceptionType(error_code, std::format("The value must be finite. Instead a value of {} has been provided", value));
|
||||
};
|
||||
}
|
||||
|
||||
template <typename ExceptionType, concepts::IsComparableToNumeric Scalar, concepts::IsEnum ErrorCode>
|
||||
requires concepts::IsExceptionWithErrorCode<ExceptionType, ErrorCode>
|
||||
void validate_greater_than(const Scalar value, const Scalar predicate, ErrorCode error_code) {
|
||||
validate_finite<ExceptionType>(value, error_code);
|
||||
if (value < predicate) {
|
||||
throw ExceptionType(error_code, std::format("The value must be finite and greater than {}. While the value is finite it is also less than {}. A value of {} has been provided", predicate, predicate, value));
|
||||
};
|
||||
}
|
||||
|
||||
template <typename ExceptionType, concepts::IsComparableToNumeric Scalar, concepts::IsEnum ErrorCode>
|
||||
requires concepts::IsExceptionWithErrorCode<ExceptionType, ErrorCode>
|
||||
void validate_less_than(const Scalar value, const Scalar predicate, ErrorCode error_code) {
|
||||
validate_finite<ExceptionType>(value, error_code);
|
||||
if (value > predicate) {
|
||||
throw ExceptionType(error_code, std::format("The value must be finite and less than {}. While the value is finite it is also greater than {}. A value of {} has been provided", predicate, predicate, value));
|
||||
};
|
||||
}
|
||||
|
||||
template <typename ExceptionType, concepts::IsComparableToNumeric Scalar, concepts::IsEnum ErrorCode>
|
||||
requires concepts::IsExceptionWithErrorCode<ExceptionType, ErrorCode>
|
||||
void validate_nonnegativity(const Scalar value, ErrorCode error_code) {
|
||||
validate_finite<ExceptionType>(value, error_code);
|
||||
validate_greater_than<ExceptionType>(value,static_cast<Scalar>(0), error_code);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
17
src/include/serif/utils/misc/std_helper/cleaning.hpp
Normal file
17
src/include/serif/utils/misc/std_helper/cleaning.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
namespace serif::utils::misc::std_helper {
|
||||
template< class T >
|
||||
using NeitherConstNorVolatile = std::remove_cv_t<T>;
|
||||
|
||||
template <class T>
|
||||
using NeitherConstNorVolatileReference = std::remove_cvref_t<T>;
|
||||
|
||||
template<class Child, class Parent>
|
||||
constexpr bool AIsBaseClassOfB = std::is_base_of_v<Parent, Child>;
|
||||
|
||||
template <class Ta, class Tb>
|
||||
constexpr bool SameType = std::is_same_v<Ta, Tb>;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
|
||||
namespace serif::utils::misc::std_helper {
|
||||
template <typename...Ts>
|
||||
[[nodiscard]] consteval std::size_t CountVariadicArguments() noexcept {
|
||||
return sizeof...(Ts);
|
||||
}
|
||||
}
|
||||
19
src/include/serif/utils/misc/traits/type_uniqueness.hpp
Normal file
19
src/include/serif/utils/misc/traits/type_uniqueness.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "serif/utils/misc/std_helper/cleaning.hpp"
|
||||
|
||||
namespace serif::utils::misc::traits {
|
||||
template <typename... Ts>
|
||||
constexpr bool all_unique_types_v = true;
|
||||
|
||||
|
||||
// This can be a bit confusing. Whats going on here is that !SameType<First, Rest> && ...
|
||||
// is preforming variadic folding. That is we check if First is the same as all types in
|
||||
// the rest type list. If First is the same as any of those this will eval to true and then be negated to false.
|
||||
// The only way for the first term (!SameType<First, Rest> && ...) to be true is if First is not the same as any of the types in Rest.
|
||||
// Then we recursively call all_unique_types_v<Rest...> to check the rest. This ensures that this is only true if
|
||||
// every single type in the type list is unique.
|
||||
template <typename First, typename... Rest>
|
||||
constexpr bool all_unique_types_v<First, Rest...> = (!std_helper::SameType<First, Rest> && ...) && all_unique_types_v<Rest...>;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user