-
Notifications
You must be signed in to change notification settings - Fork 89
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
First iteration of adaptivity hooks #1105
Open
bartgol
wants to merge
13
commits into
master
Choose a base branch
from
bartgol/adaptivity-hooks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
535f33e
Fix compiler warnings
bartgol 1198020
Moved AdvDiff problem to corePDEs
bartgol 305e2f2
Add method to retrieve dxdp from the discretization
bartgol cabd555
Fix nano-bug in STK disc
bartgol a3cbe7b
Add disc interfaces for mesh adaptation
bartgol 7f84b40
Upgrade to SolutionManager
bartgol 8299b5f
Add calls to adaptivity hooks for time-dep problems
bartgol bef80b3
Add dummy problem to check that the adaptivity hooks work
bartgol 6b711ef
Some fixes related to const-ness
bartgol e2c9dc9
Better handle the rebuilding of the tempus stepper nonlinear solver d…
bartgol 2eb4abf
Fix adaptation unit test
bartgol dffb495
Remove stranded debug line
bartgol 0895ff5
Fix handling of Tempus state that stores sensitivities
bartgol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
//*****************************************************************// | ||
// Albany 3.0: Copyright 2016 Sandia Corporation // | ||
// This Software is released under the BSD license detailed // | ||
// in the file "license.txt" in the top-level Albany directory // | ||
//*****************************************************************// | ||
|
||
#include "Albany_PiroTempusObserver.hpp" | ||
|
||
#include <Tempus_IntegratorForwardSensitivity.hpp> | ||
#include <Tempus_Stepper.hpp> | ||
#include <Tempus_StepperImplicit.hpp> | ||
|
||
namespace Albany | ||
{ | ||
|
||
PiroTempusObserver:: | ||
PiroTempusObserver(const Teuchos::RCP<Application>& app, | ||
const Teuchos::RCP<const Thyra_ModelEvaluator>& model) | ||
: PiroObserver(app,model) | ||
, app_ (app) | ||
{ | ||
// Nothing else to do | ||
} | ||
|
||
void PiroTempusObserver:: | ||
observeEndTimeStep(const Tempus::Integrator<ST>& integrator) | ||
{ | ||
auto& integrator_nc = const_cast<Tempus::Integrator<ST>&>(integrator); | ||
auto history_nc = integrator_nc.getNonConstSolutionHistory(); | ||
auto state_nc = history_nc->getCurrentState(); | ||
|
||
TEUCHOS_TEST_FOR_EXCEPTION (state_nc.is_null(), std::runtime_error, | ||
"Error! Unexpectedly found a null current state in the tempus integrator.\n"); | ||
|
||
//Don't observe solution if step failed to converge | ||
if (state_nc->getSolutionStatus() == Tempus::Status::FAILED) { | ||
return; | ||
} | ||
|
||
// In order for the DISC to decide whether to adapt or not, | ||
// we need to write the solution in the mesh db. | ||
// HOWEVER, we don't want to do a regular "observation" step, | ||
// since we don't want to write the solution to file, or to observe responses | ||
Teuchos::RCP<const Thyra_MultiVector> dxdp; | ||
auto integrator_ptr = Teuchos::rcpFromRef(integrator); | ||
auto fwd_sens_integrator = Teuchos::rcp_dynamic_cast<const Tempus::IntegratorForwardSensitivity<ST>>(integrator_ptr); | ||
if (Teuchos::nonnull(fwd_sens_integrator)) { | ||
dxdp = fwd_sens_integrator->getDxDp(); | ||
} | ||
|
||
auto time = state_nc->getTime(); | ||
auto disc = app_->getDiscretization(); | ||
|
||
auto state = state_nc.getConst(); | ||
auto adaptData = disc->checkForAdaptation(state->getX(),state->getXDot(),state->getXDotDot(),dxdp); | ||
|
||
// Before observing the solution, check if we need to adapt | ||
if (adaptData->type!=AdaptationType::None) { | ||
disc->adapt (adaptData); | ||
// Make the solution manager import the new solution from the discretization | ||
app_->getAdaptSolMgr()->reset_solution_space(false); | ||
auto num_time_derivs = app_->getNumTimeDerivs(); | ||
|
||
// Get new solution | ||
auto sol = app_->getAdaptSolMgr()->getCurrentSolution(); | ||
|
||
// Reset vectors now that they have been adapted | ||
state_nc->setX(sol->col(0)); | ||
if (num_time_derivs>0) { | ||
state_nc->setXDot(sol->col(1)); | ||
if (num_time_derivs>1) { | ||
state_nc->setXDotDot(sol->col(2)); | ||
} | ||
} | ||
if (Teuchos::nonnull(dxdp)) { | ||
dxdp = app_->getAdaptSolMgr()->getCurrentDxDp(); | ||
} | ||
|
||
if (adaptData->type==AdaptationType::Topology) { | ||
// This should trigger the nonlinear solver to be rebuilt, which should create new linear | ||
// algebra objects (jac and residual) | ||
auto stepper = integrator.getStepper(); | ||
stepper->setModel(model_); | ||
stepper->initialize(); | ||
} | ||
} | ||
observeSolutionImpl (state->getX(),state->getXDot(),state->getXDotDot(),dxdp,time); | ||
} | ||
|
||
} // namespace Albany |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//*****************************************************************// | ||
// Albany 3.0: Copyright 2016 Sandia Corporation // | ||
// This Software is released under the BSD license detailed // | ||
// in the file "license.txt" in the top-level Albany directory // | ||
//*****************************************************************// | ||
|
||
#ifndef ALBANY_PIRO_TEMPUS_OBSERVER_HPP | ||
#define ALBANY_PIRO_TEMPUS_OBSERVER_HPP | ||
|
||
#include "Albany_PiroObserver.hpp" | ||
#include "Tempus_IntegratorObserverBasic.hpp" | ||
|
||
namespace Albany { | ||
|
||
class PiroTempusObserver : public PiroObserver, | ||
public Tempus::IntegratorObserverBasic<ST> | ||
{ | ||
public: | ||
PiroTempusObserver(const Teuchos::RCP<Application>& app, | ||
const Teuchos::RCP<const Thyra_ModelEvaluator>& model); | ||
|
||
// Observe the end of each time step in the time loop | ||
void observeEndTimeStep(const Tempus::Integrator<ST>& integrator) override; | ||
protected: | ||
|
||
Teuchos::RCP<Application> app_; | ||
}; | ||
|
||
} // namespace Albany | ||
|
||
#endif // ALBANY_PIRO_TEMPUS_OBSERVER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have some error handling here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. For instance, we may be using adaptive tempus timestepping, in which case the step may fail to converge without it being an issue, since tempus will try again with a smaller timestep.