Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7188 app action interface for operator splitstepper #7258

Merged
merged 6 commits into from
Apr 27, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions packages/tempus/src/Tempus_StepperOperatorSplitAppAction.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// @HEADER
// ****************************************************************************
// Tempus: Copyright (2017) Sandia Corporation
//
// Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
// ****************************************************************************
// @HEADER

#ifndef Tempus_StepperOperatorSplitAppAction_hpp
#define Tempus_StepperOperatorSplitAppAction_hpp

#include "Tempus_config.hpp"
#include "Tempus_SolutionHistory.hpp"
#include "Tempus_StepperOperatorSplit.hpp"

namespace Tempus {

// Forward Declaration for recursive includes (this Observer <--> Stepper)
template<class Scalar> class StepperOperatorSplit;

/** \brief StepperOperatorSplitAppAction class for StepperOperatorSplit.
*
* This is a means for application developers to perform tasks
* during the time steps, e.g.,
* - Compute specific quantities
* - Output information
* - "Massage" the working solution state
* - ...
*
* <b>Design Considerations</b>
* - StepperOperatorSplitAppAction is not stateless! Developers may touch the
* solution state! Developers need to be careful not to break the
* restart (checkpoint) capability.
*/
template<class Scalar>
class StepperOperatorSplitAppAction
{
public:

enum ACTION_LOCATION {
BEGIN_STEP, ///< At the beginning of the step.
BEFORE_STEPPER, ///< Before a stepper evaluation.
AFTER_STEPPER, ///< After a stepper evaluation.
END_STEP ///< At the end of the step.
};

/// Constructor
StepperOperatorSplitAppAction(){}

/// Destructor
virtual ~StepperOperatorSplitAppAction(){}

/// Execute application action for OperatorSplit Stepper.
virtual void execute(
Teuchos::RCP<SolutionHistory<Scalar> > sh,
Teuchos::RCP<StepperOperatorSplit<Scalar> > stepper,
const typename StepperOperatorSplitAppAction<Scalar>::ACTION_LOCATION actLoc) = 0;
};
} // namespace Tempus
#endif // Tempus_StepperOperatorSplitAppAction_hpp




Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// @HEADER
// ****************************************************************************
// Tempus: Copyright (2017) Sandia Corporation
//
// Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
// ****************************************************************************
// @HEADER

#ifndef Tempus_StepperOperatorSplitAppActionComposite_hpp
#define Tempus_StepperOperatorSplitAppActionComposite_hpp

#include "Tempus_StepperOperatorSplitAppAction.hpp"
#include "Tempus_TimeStepControl.hpp"
#include <vector>

namespace Tempus {

/** \brief This composite AppAction loops over added AppActions.
*
* Inidividual AppActions are executed in the order in which they
* were added.
*/
template<class Scalar>
class StepperOperatorSplitAppActionComposite
: virtual public Tempus::StepperOperatorSplitAppAction<Scalar>
{
public:

/// Default constructor
StepperOperatorSplitAppActionComposite();

/// Destructor
virtual ~StepperOperatorSplitAppActionComposite();

/// Execute application action for OperatorSplit Stepper.
virtual void execute(
Teuchos::RCP<SolutionHistory<Scalar> > sh,
Teuchos::RCP<StepperOperatorSplit<Scalar> > stepper,
const typename StepperOperatorSplitAppAction<Scalar>::ACTION_LOCATION actLoc)
{
for(auto& a : appActions_)
a->execute(sh, stepper, actLoc);
}

// Add AppAction to the AppAction vector.
void addOperatorSplitAppAction(Teuchos::RCP<StepperOperatorSplitAppAction<Scalar> > appAction);
{
appActions_.push_back(appAction);
}

// Clear the AppAction vector.
void clearOperatorSplitAppActions();
{ appActions_.clear();}

// Return the size of the AppAction vector.
std::size_t getSize() const { return appActions_.size(); }

private:

std::vector<Teuchos::RCP<StepperOperatorSplitAppAction<Scalar > > > appActions_;

};

} // namespace Tempus
#endif // Tempus_StepperOperatorSplitAppActionComposite_hpp
65 changes: 65 additions & 0 deletions packages/tempus/src/Tempus_StepperOperatorSplitModifierBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// @HEADER
// ****************************************************************************
// Tempus: Copyright (2017) Sandia Corporation
//
// Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
// ****************************************************************************
// @HEADER

#ifndef Tempus_StepperOperatorSplitModifierBase_hpp
#define Tempus_StepperOperatorSplitModifierBase_hpp

#include "Tempus_SolutionHistory.hpp"
#include "Tempus_config.hpp"
#include "Tempus_StepperOperatorSplitAppAction.hpp"

namespace Tempus {

/** \brief Base modifier for OperatorSplit.
*
* This class provides a means to modify values (e.g., solution variables
* through SolutionHistory, and stepper member data through the Stepper),
* and can be very powerful and easy to make changes to the stepper and
* the solution.
*
* Users deriving from this class can access a lot of data, and it is
* expected that those users know what changes are allowable without
* affecting the Stepper correctness, performance, accuracy and stability.
* Thus the user should be careful when accessing data through classes
* derived from the default modifier (i.e., USER BEWARE!!).
*
*/
template<class Scalar>
class StepperOperatorSplitModifierBase
: virtual public Tempus::StepperOperatorSplitAppAction<Scalar>
{
private:
/* \brief Adaptor execute function
*
* This is an adaptor function to bridge between the AppAction
* interface and the Modifier interface. It is meant to be private
* and non-virtual as deriving from this class should only need to
* implement the modify function.
*
* For the Modifier interface, this adaptor is a "simple pass through".
*/
void execute(
Teuchos::RCP<SolutionHistory<Scalar> > sh,
Teuchos::RCP<StepperOperatorSplit<Scalar> > stepper,
const typename StepperOperatorSplitAppAction<Scalar>::ACTION_LOCATION actLoc)
{ this->modify(sh, stepper, actLoc); }
public:
/// Modify OperatorSplit Stepper.
virtual void modify(
Teuchos::RCP<SolutionHistory<Scalar> > /* sh */,
Teuchos::RCP<StepperOperatorSplit<Scalar> > /* stepper */,
const typename StepperOperatorSplitAppAction<Scalar>::ACTION_LOCATION actLoc) = 0;

};

} // namespace Tempus
#endif // Tempus_StepperOperatorModifierBase_hpp




Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// @HEADER
// ****************************************************************************
// Tempus: Copyright (2017) Sandia Corporation
//
// Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
// ****************************************************************************
// @HEADER

#ifndef Tempus_StepperOperatorSplitModifierDefault_hpp
#define Tempus_StepperOperatorSplitModifierDefault_hpp

#include "Tempus_config.hpp"
#include "Tempus_SolutionHistory.hpp"
#include "Tempus_StepperOperatorSplitModifierBase.hpp"


namespace Tempus {

/** \brief Default modifier for StepperOperatorSplit.
*
* The default modifier provides no-op functionality for the modifier.
* See StepperOperatorSplitModifierBase for details on the algorithm.
*/
template<class Scalar>
class StepperOperatorSplitModifierDefault
: virtual public Tempus::StepperOperatorSplitModifierBase<Scalar>
{
public:

/// Constructor
StepperOperatorSplitModifierDefault(){}

/// Destructor
virtual ~StepperOperatorSplitModifierDefault(){}

/// Modify OperatorSplit Stepper.
virtual void modify(
Teuchos::RCP<SolutionHistory<Scalar> > /* sh */,
Teuchos::RCP<StepperOperatorSplit<Scalar> > /* stepper */,
const typename StepperOperatorSplitAppAction<Scalar>::ACTION_LOCATION actLoc)
{
switch(actLoc) {
case StepperOperatorSplitAppAction<Scalar>::BEGIN_STEP:
case StepperOperatorSplitAppAction<Scalar>::BEFORE_STEPPER:
case StepperOperatorSplitAppAction<Scalar>::AFTER_STEPPER:
case StepperOperatorSplitAppAction<Scalar>::END_STEP:
{
// No-op.
break;
}
default:
TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
"Error - unknown action location.\n");
}
}

};

} // namespace Tempus

#endif // Tempus_StepperOperatorSplitModifierDefault_hpp
118 changes: 118 additions & 0 deletions packages/tempus/src/Tempus_StepperOperatorSplitModifierXBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// @HEADER
// ****************************************************************************
// Tempus: Copyright (2017) Sandia Corporation
//
// Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
// ****************************************************************************
// @HEADER

#ifndef Tempus_StepperOperatorSplitModifierXBase_hpp
#define Tempus_StepperOperatorSplitModifierXBase_hpp

#include "Tempus_config.hpp"
#include "Tempus_SolutionHistory.hpp"
#include "Tempus_StepperOperatorSplitAppAction.hpp"


namespace Tempus {

/** \brief Base ModifierX for StepperOperatorSplit.
*
* This class provides a means to modify just the solution values
* (i.e., \f$x\f$ and \f$dot{x}\f$), and nothing else, but time and
* timestep are also provided.
*
* Users deriving from this class can access and change the solution
* during the timestep (e.g., limiting the solution for monoticity).
* It is expected that the user knows what changes are allowable without
* affecting the Stepper correctness, performance, accuracy and stability
* (i.e., USER BEWARE!!).
*
*/

template<class Scalar>
class StepperOperatorSplitModifierXBase
: virtual public Tempus::StepperOperatorSplitAppAction<Scalar>
{
private:

/* \brief Adaptor execute function
*
* This is an adaptor function to bridge between the AppAction
* interface and the ModifierX interface. It is meant to be private
* and non-virtual as deriving from this class should only need to
* implement the modify function.
*
* For the ModifierX interface, this adaptor maps the
* StepperOperatorSplitAppAction::ACTION_LOCATION to the
* StepperOperatorSplitModifierX::MODIFIERX_TYPE, and only pass the solution
* (\f$x\f$ and/or \f$\dot{x}\f$ and other parameters to the modify
* function.
*/
void execute(
Teuchos::RCP<SolutionHistory<Scalar> > sh,
Teuchos::RCP<StepperOperatorSplit<Scalar> > stepper,
const typename StepperOperatorSplitAppAction<Scalar>::ACTION_LOCATION actLoc)
{
using Teuchos::RCP;

MODIFIER_TYPE modType = X_BEGIN_STEP;
RCP<SolutionState<Scalar> > workingState = sh->getWorkingState();
const Scalar time = workingState->getTime();
const Scalar dt = workingState->getTimeStep();
RCP<Thyra::VectorBase<Scalar> > x;

switch(actLoc) {
case StepperOperatorSplitAppAction<Scalar>::BEGIN_STEP:
{
modType = X_BEGIN_STEP;
x = workingState->getX();
break;
}
case StepperOperatorSplitAppAction<Scalar>::BEFORE_STEPPER:
{
modType = X_BEFORE_STEPPER;
x = workingState->getX();
break;
}
case StepperOperatorSplitAppAction<Scalar>::AFTER_STEPPER:
{
modType = X_AFTER_STEPPER;
x = workingState->getX();
break;
}
case StepperOperatorSplitAppAction<Scalar>::END_STEP:
{
modType = XDOT_END_STEP;
x = stepper->getStepperXDot(workingState);
break;
}
default:
TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
"Error - unknown action location.\n");
}

this->modify(x, time, dt, modType);
}

public:

/// Indicates the location of application action (see algorithm).
enum MODIFIER_TYPE {
X_BEGIN_STEP, ///< Modify \f$x\f$ at the beginning of the step.
X_BEFORE_STEPPER, ///< Modify \f$x\f$ before the implicit solve.
X_AFTER_STEPPER,
XDOT_END_STEP ///< Modify \f$\dot{x}\f$ at the end of the step.
};

/// Modify solution based on the MODIFIER_TYPE.
virtual void modify(
Teuchos::RCP<Thyra::VectorBase<Scalar> > /* x */,
const Scalar /* time */, const Scalar /* dt */,
const MODIFIER_TYPE modType) = 0;

};

} // namespace Tempus

#endif // Tempus_StepperOperatorSplitModifierXBase_hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define Tempus_StepperOperatorSplitObserver_hpp

#include "Tempus_SolutionHistory.hpp"

#include "Tempus_StepperObserver.hpp"

namespace Tempus {

Expand Down
Loading