Skip to content

Commit

Permalink
add mixed fom/rom for galerkin, revise lspg impl
Browse files Browse the repository at this point in the history
  • Loading branch information
fnrizzi committed Sep 11, 2023
1 parent c16b535 commit fe2ac01
Show file tree
Hide file tree
Showing 11 changed files with 688 additions and 190 deletions.
50 changes: 50 additions & 0 deletions include/pressio/rom/galerkin_unsteady_implicit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "impl/galerkin_unsteady_system_masked_rhs_and_jacobian.hpp"
#include "impl/galerkin_unsteady_system_fully_discrete_fom.hpp"
#include "impl/galerkin_unsteady_system_hypred_fully_discrete_fom.hpp"
#include "impl/mixed_fom_rom_unsteady_problem.hpp"
#include "impl/galerkin_unsteady_default_problem_mixed_fom.hpp"

namespace pressio{ namespace rom{ namespace galerkin{

Expand Down Expand Up @@ -207,5 +209,53 @@ auto create_unsteady_implicit_problem(const TrialSubspaceType & trialSpace, /
TotalNumberOfDesiredStates>(std::move(galSystem));
}

// -------------------------------------------------------------
// mixed fom/rom
// -------------------------------------------------------------
namespace experimental{

// because this is the mixed case FOM/ROM, we need to check that the FomSystem
// meets the API needed for ROM but also that needed for doing ode stepping directly on it
template<class TrialSubspaceType, class FomSystemType>
#ifdef PRESSIO_ENABLE_CXX20
requires PossiblyAffineRealValuedTrialColumnSubspace<TrialSubspaceType>
&& RealValuedSemiDiscreteFomWithJacobianAction<FomSystemType, typename TrialSubspaceType::basis_matrix_type>
&& std::same_as<typename TrialSubspaceType::full_state_type, typename FomSystemType::state_type>
&& ::pressio::ode::RealValuedOdeSystemFusingRhsAndJacobian<FomSystemType>
#endif
auto create_unsteady_implicit_problem_mixed_fom(::pressio::ode::StepScheme schemeName,
const TrialSubspaceType & trialSpace,
const FomSystemType & fomSystem)
{

#if !defined PRESSIO_ENABLE_CXX20
static_assert(PossiblyAffineTrialColumnSubspace<TrialSubspaceType>::value);
static_assert(RealValuedSemiDiscreteFomWithJacobianAction<
FomSystemType, typename TrialSubspaceType::basis_matrix_type>::value);
static_assert(::pressio::ode::RealValuedOdeSystemFusingRhsAndJacobian<FomSystemType>::value);
#endif

if ( schemeName != ::pressio::ode::StepScheme::BDF1
&& schemeName != ::pressio::ode::StepScheme::BDF2)
{
throw std::runtime_error("galerkin mixed fom/rom currently accepting BDF1 or BDF2");
}

using ind_var_type = typename FomSystemType::time_type;
using reduced_state_type = typename TrialSubspaceType::reduced_state_type;
using default_types = ImplicitGalerkinDefaultReducedOperatorsTraits<reduced_state_type>;
using reduced_residual_type = typename default_types::reduced_residual_type;
using reduced_jacobian_type = typename default_types::reduced_jacobian_type;

using galerkin_system = impl::GalerkinDefaultOdeSystemRhsAndJacobian<
ind_var_type, reduced_state_type, reduced_residual_type,
reduced_jacobian_type, TrialSubspaceType, FomSystemType>;

using return_type = impl::GalerkinUnsteadyDefaultProblemRomFom<
ind_var_type, FomSystemType, TrialSubspaceType, galerkin_system, impl::MixedFomRomStepper>;
return return_type(schemeName, trialSpace, fomSystem);
}
}//end namespace experimental

}}} // end pressio::rom::galerkin
#endif // ROM_GALERKIN_UNSTEADY_IMPLICIT_HPP_
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

#ifndef ROM_GALERKIN_UNSTEADY_DEFAULT_PROBLEM_MIXED_FOM_HPP_
#define ROM_GALERKIN_UNSTEADY_DEFAULT_PROBLEM_MIXED_FOM_HPP_

#include "mixed_fom_rom_unsteady_problem.hpp"

namespace pressio{ namespace rom{ namespace impl{

template <
class IndVarType,
class FomSystemType,
class TrialSubspaceType,
class GalerkinSystemType,
template<class ...> class MixedFomRomStepper
>
class GalerkinUnsteadyDefaultProblemRomFom
{

public:
using independent_variable_type = IndVarType;
using fom_state_type = typename FomSystemType::state_type;
using rom_state_type = typename GalerkinSystemType::state_type;
using rom_residual_type = typename GalerkinSystemType::rhs_type;
using rom_jacobian_type = typename GalerkinSystemType::jacobian_type;

using fom_stepper_type = decltype(ode::create_implicit_stepper(std::declval<ode::StepScheme>(),
std::declval<const FomSystemType&>()));
using rom_stepper_type = decltype(ode::create_implicit_stepper(std::declval<ode::StepScheme>(),
std::declval<GalerkinSystemType>()));

using mixed_stepper_t = MixedFomRomStepper<
FomSystemType, fom_stepper_type, TrialSubspaceType, rom_stepper_type>;

GalerkinUnsteadyDefaultProblemRomFom(ode::StepScheme odeSchemeName,
const TrialSubspaceType & trialSubspace,
const FomSystemType & fomSystem)
: fomStepper_(ode::create_implicit_stepper(odeSchemeName, fomSystem))
, trialSubspace_(trialSubspace)
, romStepper_(ode::create_implicit_stepper(odeSchemeName, GalerkinSystemType(trialSubspace, fomSystem)))
, mixed_(odeSchemeName, fomSystem, trialSubspace, fomStepper_, romStepper_)
{
assert(odeSchemeName_ == ode::StepScheme::BDF1 ||
odeSchemeName_ == ode::StepScheme::BDF2);
}

template<class Tag, class StateType, class SolverType, class ...ArgsOp>
mpl::enable_if_t< std::is_same_v<Tag, FomStepTag> || std::is_same_v<Tag, RomStepTag> >
operator()(Tag tag,
StateType & fomOrRomState,
pressio::ode::StepStartAt<independent_variable_type> sStart,
pressio::ode::StepCount sCount,
pressio::ode::StepSize<independent_variable_type> sSize,
SolverType & solver,
ArgsOp && ...argsop)
{
static_assert(std::is_same_v<StateType, rom_state_type> ||
std::is_same_v<StateType, fom_state_type>);
mixed_(tag, fomOrRomState, sStart, sCount, sSize,
solver, std::forward<ArgsOp>(argsop)...);
}

template<class Tag, class SolverType, class ...ArgsOp>
mpl::enable_if_t< std::is_same_v<Tag, TransitionToRomAndDoStepTag> ||
std::is_same_v<Tag, TransitionToFomAndDoStepTag> >
operator()(Tag tag,
fom_state_type & fomState,
rom_state_type & romState,
pressio::ode::StepStartAt<independent_variable_type> sStart,
pressio::ode::StepCount sCount,
pressio::ode::StepSize<independent_variable_type> sSize,
SolverType & solver,
ArgsOp && ...argsop)
{
mixed_(tag, fomState, romState, sStart, sCount, sSize,
solver, std::forward<ArgsOp>(argsop)...);
}

private:
fom_stepper_type fomStepper_;
std::reference_wrapper<const TrialSubspaceType> trialSubspace_;
rom_stepper_type romStepper_;
mixed_stepper_t mixed_;
};

}}} // end pressio::rom::impl
#endif // ROM_IMPL_LSPG_UNSTEADY_PROBLEM_HPP_
Loading

0 comments on commit fe2ac01

Please sign in to comment.