feat(surface): major work on implementing surface constraints in a presciption agnostic manner
This commit is contained in:
128
libmeanfield/interface/eos/pressure_surface.cppm
Normal file
128
libmeanfield/interface/eos/pressure_surface.cppm
Normal file
@@ -0,0 +1,128 @@
|
||||
module;
|
||||
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
export module mean_field:eos.pressure_surface;
|
||||
|
||||
export import :eos.evaluation;
|
||||
|
||||
export namespace mean_field::eos {
|
||||
namespace detail {
|
||||
template <
|
||||
ThermodynamicQuantityType InputQuantity,
|
||||
typename SurfaceState>
|
||||
[[nodiscard]] constexpr auto pressureSurfaceRelationInput(
|
||||
const PressureValue targetPressure,
|
||||
const SurfaceState &state
|
||||
) {
|
||||
if constexpr (std::same_as<InputQuantity, quantity::Pressure>) {
|
||||
return targetPressure;
|
||||
} else {
|
||||
return state.value(InputQuantity{});
|
||||
}
|
||||
}
|
||||
|
||||
template <typename RelationType> struct PressureSurfaceRelationOperations;
|
||||
|
||||
template <typename CarrierQuantity, typename... InputQuantities>
|
||||
struct PressureSurfaceRelationOperations<Relation<CarrierQuantity, InputQuantities...>> {
|
||||
template <
|
||||
typename EquationOfState,
|
||||
typename SurfaceState>
|
||||
[[nodiscard]] static QuantityValue<CarrierQuantity> requiredCarrierValue(
|
||||
const EquationOfState &equationOfState,
|
||||
const PressureValue targetPressure,
|
||||
const SurfaceState &state
|
||||
) {
|
||||
return evaluate<CarrierQuantity>(
|
||||
equationOfState, pressureSurfaceRelationInput<InputQuantities>(targetPressure, state)...
|
||||
);
|
||||
}
|
||||
|
||||
template <
|
||||
typename InputQuantity,
|
||||
typename EquationOfState,
|
||||
typename SurfaceState,
|
||||
typename SurfaceVariation>
|
||||
[[nodiscard]] static double inputJacobianContribution(
|
||||
const EquationOfState &equationOfState,
|
||||
const PressureValue targetPressure,
|
||||
const SurfaceState &state,
|
||||
const SurfaceVariation &variation
|
||||
) {
|
||||
if constexpr (std::same_as<InputQuantity, quantity::Pressure>) {
|
||||
return 0.0;
|
||||
} else {
|
||||
const auto derivative = partialDerivative<CarrierQuantity, InputQuantity>(
|
||||
equationOfState, pressureSurfaceRelationInput<InputQuantities>(targetPressure, state)...
|
||||
);
|
||||
return derivative.value() * variation.value(InputQuantity{}).value();
|
||||
}
|
||||
}
|
||||
|
||||
template <
|
||||
typename EquationOfState,
|
||||
typename SurfaceState,
|
||||
typename SurfaceVariation>
|
||||
[[nodiscard]] static double carrierCorrectionJacobianAction(
|
||||
const EquationOfState &equationOfState,
|
||||
const PressureValue targetPressure,
|
||||
const SurfaceState &state,
|
||||
const SurfaceVariation &variation
|
||||
) {
|
||||
return (
|
||||
0.0 + ... +
|
||||
inputJacobianContribution<InputQuantities>(equationOfState, targetPressure, state, variation)
|
||||
);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
/*
|
||||
* EOS-owned resolution of a constant-pressure condition into the carrier
|
||||
* quantity used by an equation formulation. No field or solver concepts
|
||||
* enter this type.
|
||||
*/
|
||||
template <EquationOfStateModel EquationOfState, ThermodynamicRelationType SelectedRelation>
|
||||
class ResolvedPressureSurfaceRelation final {
|
||||
public:
|
||||
using RelationType = SelectedRelation;
|
||||
using CarrierQuantity = RelationOutputT<RelationType>;
|
||||
|
||||
ResolvedPressureSurfaceRelation(
|
||||
const EquationOfState &equationOfState,
|
||||
const PressureValue targetPressure
|
||||
) noexcept
|
||||
: m_equationOfState(std::addressof(equationOfState)),
|
||||
m_targetPressure(targetPressure) {
|
||||
}
|
||||
|
||||
[[nodiscard]] PressureValue targetPressure() const noexcept {
|
||||
return m_targetPressure;
|
||||
}
|
||||
|
||||
template <typename SurfaceState>
|
||||
[[nodiscard]] QuantityValue<CarrierQuantity> requiredCarrierValue(const SurfaceState &state) const {
|
||||
return detail::PressureSurfaceRelationOperations<RelationType>::requiredCarrierValue(
|
||||
*m_equationOfState, m_targetPressure, state
|
||||
);
|
||||
}
|
||||
|
||||
template <
|
||||
typename SurfaceState,
|
||||
typename SurfaceVariation>
|
||||
[[nodiscard]] double carrierCorrectionJacobianAction(
|
||||
const SurfaceState &state,
|
||||
const SurfaceVariation &variation
|
||||
) const {
|
||||
return detail::PressureSurfaceRelationOperations<RelationType>::carrierCorrectionJacobianAction(
|
||||
*m_equationOfState, m_targetPressure, state, variation
|
||||
);
|
||||
}
|
||||
|
||||
private:
|
||||
const EquationOfState *m_equationOfState;
|
||||
PressureValue m_targetPressure;
|
||||
};
|
||||
} // namespace mean_field::eos
|
||||
Reference in New Issue
Block a user