perf(jacobian-action): major updates to jacobian action application by removing redudant quadrature work. ~5x increase in speed

This commit is contained in:
2026-09-02 17:01:50 -04:00
parent 85500fef3b
commit 25510008dd
74 changed files with 8967 additions and 814 deletions

View File

@@ -2,132 +2,42 @@ module;
#include <compare>
#include <concepts>
#include <string_view>
#include <type_traits>
export module mean_field:eos.quantities;
export import :dimensions.quantities;
export namespace mean_field::eos {
struct ThermodynamicQuantity { };
// Compatibility names for the thermodynamic subset now owned by the
// general dimensions partition.
using ThermodynamicQuantity = dimensions::ThermodynamicQuantity;
template <typename Candidate>
concept ThermodynamicQuantityType =
std::same_as<Candidate, std::remove_cv_t<Candidate>> && std::derived_from<Candidate, ThermodynamicQuantity>;
concept ThermodynamicQuantityType = dimensions::ThermodynamicQuantityType<Candidate>;
namespace quantity {
struct Density final : ThermodynamicQuantity {
static constexpr std::string_view identifier = "density";
};
struct Pressure final : ThermodynamicQuantity {
static constexpr std::string_view identifier = "pressure";
};
struct SpecificEnthalpy final : ThermodynamicQuantity {
static constexpr std::string_view identifier = "specific_enthalpy";
};
using Density = dimensions::quantity::Density;
using Pressure = dimensions::quantity::Pressure;
using SpecificEnthalpy = dimensions::quantity::SpecificEnthalpy;
} // namespace quantity
template <typename T>
concept Numeric = std::integral<T> || std::floating_point<T>;
concept Numeric = dimensions::Numeric<T>;
template <ThermodynamicQuantityType Quantity> class QuantityValue final {
public:
explicit constexpr QuantityValue(const double value) noexcept : m_value(value) {
}
template <ThermodynamicQuantityType Quantity> using QuantityValue = dimensions::QuantityValue<Quantity>;
[[nodiscard]] constexpr double value() const noexcept {
return m_value;
}
using DensityValue = dimensions::DensityValue;
using PressureValue = dimensions::PressureValue;
using SpecificEnthalpyValue = dimensions::SpecificEnthalpyValue;
[[nodiscard]] friend constexpr bool operator==(
const QuantityValue &,
const QuantityValue &
) noexcept = default;
friend constexpr QuantityValue<Quantity> operator+(
const QuantityValue<Quantity> &lhs,
const QuantityValue<Quantity> &rhs
) noexcept {
return QuantityValue<Quantity>{lhs.m_value + rhs.m_value};
}
friend constexpr QuantityValue<Quantity> operator-(
const QuantityValue<Quantity> &lhs,
const QuantityValue<Quantity> &rhs
) noexcept {
return QuantityValue<Quantity>{lhs.m_value - rhs.m_value};
}
template <Numeric rhsT>
friend constexpr QuantityValue<Quantity> operator*(
const QuantityValue<Quantity> &lhs,
rhsT rhs
) noexcept {
return QuantityValue<Quantity>{lhs.m_value * static_cast<double>(rhs)};
}
template <Numeric lhsT>
friend constexpr QuantityValue<Quantity> operator*(
lhsT lhs,
const QuantityValue<Quantity> &rhs
) noexcept {
return QuantityValue<Quantity>{static_cast<double>(lhs) * rhs.m_value};
}
template <Numeric rhsT>
friend constexpr QuantityValue<Quantity> operator/(
const QuantityValue<Quantity> &lhs,
rhsT rhs
) noexcept {
return QuantityValue<Quantity>{lhs.m_value / static_cast<double>(rhs)};
}
template <Numeric compT>
friend constexpr std::partial_ordering operator<=>(
const QuantityValue<Quantity> &lhs,
compT rhs
) noexcept {
return lhs.m_value <=> static_cast<double>(rhs);
}
template <Numeric compT>
friend constexpr std::partial_ordering operator<=>(
compT lhs,
const QuantityValue<Quantity> &rhs
) noexcept {
return static_cast<double>(lhs) <=> rhs.m_value;
}
friend constexpr std::partial_ordering operator<=>(
const QuantityValue<Quantity> &lhs,
const QuantityValue<Quantity> &rhs
) noexcept {
return lhs.m_value <=> rhs.m_value;
}
private:
double m_value;
};
using DensityValue = QuantityValue<quantity::Density>;
using PressureValue = QuantityValue<quantity::Pressure>;
using SpecificEnthalpyValue = QuantityValue<quantity::SpecificEnthalpy>;
template <typename Candidate> struct IsQuantityValue : std::false_type { };
template <ThermodynamicQuantityType Quantity> struct IsQuantityValue<QuantityValue<Quantity>> : std::true_type { };
template <typename Candidate> using IsQuantityValue = dimensions::IsQuantityValue<Candidate>;
template <typename Candidate>
concept QuantityValueType = IsQuantityValue<std::remove_cvref_t<Candidate>>::value;
concept QuantityValueType =
dimensions::QuantityValueType<Candidate> && ThermodynamicQuantityType<dimensions::QuantityOfT<Candidate>>;
template <typename Candidate> struct QuantityOf;
template <typename Candidate> using QuantityOf = dimensions::QuantityOf<Candidate>;
template <ThermodynamicQuantityType Quantity> struct QuantityOf<QuantityValue<Quantity>> {
using Type = Quantity;
};
template <QuantityValueType Value> using QuantityOfT = typename QuantityOf<std::remove_cvref_t<Value>>::Type;
template <QuantityValueType Value> using QuantityOfT = dimensions::QuantityOfT<Value>;
template <ThermodynamicQuantityType OutputQuantity, ThermodynamicQuantityType InputQuantity>
class PartialDerivative final {
@@ -163,7 +73,7 @@ export namespace mean_field::eos {
InputQuantity> &rhs
) noexcept;
template <Numeric rhsT>
template <Numeric Scalar>
friend constexpr PartialDerivative<
OutputQuantity,
InputQuantity>
@@ -171,21 +81,21 @@ export namespace mean_field::eos {
const PartialDerivative<
OutputQuantity,
InputQuantity> &,
rhsT
Scalar
) noexcept;
template <Numeric lhsT>
template <Numeric Scalar>
friend constexpr PartialDerivative<
OutputQuantity,
InputQuantity>
operator*(
lhsT,
Scalar,
const PartialDerivative<
OutputQuantity,
InputQuantity> &
) noexcept;
template <Numeric rhsT>
template <Numeric Scalar>
friend constexpr PartialDerivative<
OutputQuantity,
InputQuantity>
@@ -193,22 +103,22 @@ export namespace mean_field::eos {
const PartialDerivative<
OutputQuantity,
InputQuantity> &,
rhsT
Scalar
) noexcept;
template <Numeric cmpT>
template <Numeric Scalar>
friend constexpr std::partial_ordering operator<=>(
const PartialDerivative<
OutputQuantity,
InputQuantity> &lhs,
cmpT rhs
Scalar rhs
) noexcept {
return lhs.m_value <=> static_cast<double>(rhs);
}
template <Numeric cmpT>
template <Numeric Scalar>
friend constexpr std::partial_ordering operator<=>(
cmpT lhs,
Scalar lhs,
const PartialDerivative<
OutputQuantity,
InputQuantity> &rhs