module; #include #include #include 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(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