arithmetic.hpp cmath concepts stdexcept string_view tuple utility serif/equations/concepts.hpp serif/utils/error/errors.hpp src/include/serif/equations/displacement_force.hpp src/include/serif/equations/equations.hpp src/include/serif/equations/sum.hpp serif::equations::EquationScale serif::equations::EquationSum serif::equations::EquationDifference serif serif::equations File containing the EquationScale and EquationSum templates, which allow for scaling and summing equations. Emily M. Boudreaux The astute observer will notice that none of the code in this file or indeed in in any part of the equations module actually implements summation or scaled addition more generally. Rather, the code to manage that is implemented in the operator/backend/mfem module. Effectively these templates are compile time tags telling that system how to combine weak contributions. The reason for this comes down to we dont really want to sum at the point wise level; rather, we generally want to sum already integrated contributions. Since equations, by design, do not know any details about the global system they are unable to manage this themselves. There is another, as yet unexplored case, where we introduce some point-wise summation equation. This could be implemented in a much more local fashion and would probably be easier to trace; however, it would be semantically different in its meaning. #pragmaonce #include<cmath> #include<concepts> #include<stdexcept> #include<string_view> #include<tuple> #include<utility> #include"serif/equations/concepts.hpp" #include"serif/utils/error/errors.hpp" namespaceserif::equations{ template<EquationEquationT> classEquationScalefinal{ public: usingTest=typenameEquationT::Test; staticconstexprstd::string_viewname="scaledequation"; explicitEquationScale( EquationTequation, constdoublecoefficient ): m_equation(std::move(equation)), m_coefficient(coefficient){ usingnamespaceutils::errors; serif_ensure<SERiFErrorCode::NON_FINITE_VALUE_ERROR,std::invalid_argument>(std::isfinite(coefficient),"Anequationcoefficientmustbefinite."); } [[nodiscard]]autocontributions()constnoexcept{ returnstd::tie(m_equation); } [[nodiscard]]doublecoefficient()constnoexcept{ returnm_coefficient; } private: EquationTm_equation; doublem_coefficient; }; template<EquationFirstT,Equation...RestTs> requires(std::same_as<typenameFirstT::Test,typenameRestTs::Test>&&...) classEquationSumfinal{ public: usingTest=typenameFirstT::Test; staticconstexprstd::string_viewname="equationsum"; explicitEquationSum( FirstTfirst, RestTs...rest ): m_equations(std::move(first),std::move(rest)...){} [[nodiscard]]constauto&contributions()constnoexcept{ returnm_equations; } private: std::tuple<FirstT,RestTs...>m_equations; }; template<EquationLeftT,EquationRightT> requiresstd::same_as<typenameLeftT::Test,typenameRightT::Test> classEquationDifferencefinal{ public: usingTest=typenameLeftT::Test; staticconstexprstd::string_viewname="equationdifference"; explicitEquationDifference( LeftTleft, RightTright ): m_equation(std::move(left),EquationScale{std::move(right),-1.0}){} [[nodiscard]]constauto&contributions()constnoexcept{ returnm_equation.contributions(); } private: EquationSum<LeftT, EquationScale<RightT>>m_equation; }; }//namespaceserif::equations