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:
64
libmeanfield/interface/surface/isobaric.cppm
Normal file
64
libmeanfield/interface/surface/isobaric.cppm
Normal file
@@ -0,0 +1,64 @@
|
||||
module;
|
||||
|
||||
#include <cmath>
|
||||
#include <format>
|
||||
#include <stdexcept>
|
||||
|
||||
export module mean_field:surface.isobaric;
|
||||
|
||||
export import :surface.base;
|
||||
|
||||
export namespace mean_field::surface {
|
||||
class Isobaric final : public SurfaceBase {
|
||||
public:
|
||||
explicit Isobaric(const double targetPressure = 0.0) : m_targetPressure(targetPressure) {
|
||||
validateTargetPressure();
|
||||
}
|
||||
|
||||
[[nodiscard]] double targetPressure() const noexcept {
|
||||
return m_targetPressure;
|
||||
}
|
||||
|
||||
[[nodiscard]] ResolvedSurfaceCondition
|
||||
resolve(const mean_field::eos::EquationOfState &equationOfState) const override {
|
||||
return ResolvedSurfaceCondition{resolveTargetEnthalpy(equationOfState)};
|
||||
}
|
||||
|
||||
void validate(const mean_field::eos::EquationOfState &equationOfState) const override {
|
||||
static_cast<void>(resolveTargetEnthalpy(equationOfState));
|
||||
}
|
||||
|
||||
private:
|
||||
[[nodiscard]] double resolveTargetEnthalpy(const mean_field::eos::EquationOfState &equationOfState) const {
|
||||
validateTargetPressure();
|
||||
|
||||
const double targetEnthalpy = equationOfState.enthalpy_from_pressure(m_targetPressure);
|
||||
|
||||
if (!std::isfinite(targetEnthalpy) || targetEnthalpy < 0.0) {
|
||||
throw std::domain_error(
|
||||
std::format(
|
||||
"The equation of state resolved the isobaric "
|
||||
"target P = {} to the invalid enthalpy h = {}.",
|
||||
m_targetPressure, targetEnthalpy
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return targetEnthalpy;
|
||||
}
|
||||
|
||||
void validateTargetPressure() const {
|
||||
if (!std::isfinite(m_targetPressure) || m_targetPressure < 0.0) {
|
||||
throw std::invalid_argument(
|
||||
std::format(
|
||||
"The target surface pressure must be finite and "
|
||||
"non-negative. Instead P = {} was provided.",
|
||||
m_targetPressure
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
double m_targetPressure;
|
||||
};
|
||||
} // namespace mean_field::surface
|
||||
53
libmeanfield/interface/surface/surface_base.cppm
Normal file
53
libmeanfield/interface/surface/surface_base.cppm
Normal file
@@ -0,0 +1,53 @@
|
||||
module;
|
||||
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
|
||||
export module mean_field:surface.base;
|
||||
|
||||
export import :eos.base;
|
||||
|
||||
export namespace mean_field::surface {
|
||||
struct ResolvedSurfaceCondition final {
|
||||
double targetEnthalpy{0.0};
|
||||
|
||||
explicit ResolvedSurfaceCondition(const double requestedTargetEnthalpy)
|
||||
: targetEnthalpy(requestedTargetEnthalpy) {
|
||||
if (!std::isfinite(targetEnthalpy) || targetEnthalpy < 0.0) {
|
||||
throw std::invalid_argument(
|
||||
"A resolved surface enthalpy must be finite and "
|
||||
"non-negative."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] double residual(const double enthalpy) const {
|
||||
if (!std::isfinite(enthalpy)) {
|
||||
throw std::invalid_argument("A surface enthalpy value must be finite.");
|
||||
}
|
||||
|
||||
return enthalpy - targetEnthalpy;
|
||||
}
|
||||
|
||||
[[nodiscard]] static double jacobianAction(const double enthalpyVariation) {
|
||||
if (!std::isfinite(enthalpyVariation)) {
|
||||
throw std::invalid_argument("A surface enthalpy variation must be finite.");
|
||||
}
|
||||
|
||||
return enthalpyVariation;
|
||||
}
|
||||
};
|
||||
|
||||
class SurfaceBase {
|
||||
public:
|
||||
virtual ~SurfaceBase() = default;
|
||||
|
||||
[[nodiscard]] virtual ResolvedSurfaceCondition
|
||||
resolve(const mean_field::eos::EquationOfState &equationOfState) const = 0;
|
||||
|
||||
virtual void validate(const mean_field::eos::EquationOfState &equationOfState) const = 0;
|
||||
|
||||
protected:
|
||||
SurfaceBase() = default;
|
||||
};
|
||||
} // namespace mean_field::surface
|
||||
Reference in New Issue
Block a user