Skip to content

Commit

Permalink
Merge Pull Request #13431 from kliegeois/Trilinos/piro_finalObjective
Browse files Browse the repository at this point in the history
Automatically Merged using Trilinos Pull Request AutoTester
PR Title: b'Piro: update FinalObjective and fix the tempus redirection'
PR Author: kliegeois
  • Loading branch information
trilinos-autotester committed Sep 7, 2024
2 parents 49ed6a0 + 9d05eb0 commit 44ab14d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
11 changes: 7 additions & 4 deletions packages/piro/src/Piro_PerformAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,9 @@ Piro::PerformROLTransientAnalysis(
auto algo = ROL::TypeB::AlgorithmFactory<double>(rolParams.sublist("ROL Options"));

std::streambuf *coutbuf;
std::ofstream out_file;
if(rolParams.get<bool>("Redirect Tempus Output", true)) {
std::ofstream out_file(rolParams.get<string>("Tempus Output Filename", "log_tempus.txt"));
out_file.open(rolParams.get<string>("Tempus Output Filename", "log_tempus.txt"));
coutbuf = std::cout.rdbuf();
std::cout.rdbuf(out_file.rdbuf());
}
Expand All @@ -955,8 +956,9 @@ Piro::PerformROLTransientAnalysis(
auto algo = ROL::TypeU::AlgorithmFactory<double>(rolParams.sublist("ROL Options"));

std::streambuf *coutbuf;
if(rolParams.get<bool>("Redirect Tempus Output", true)) {
std::ofstream out_file(rolParams.get<string>("Tempus Output Filename", "log_tempus.txt"));
std::ofstream out_file;
if(rolParams.get<bool>("", true)) {
out_file.open(rolParams.get<string>("Tempus Output Filename", "log_tempus.txt"));
coutbuf = std::cout.rdbuf();
std::cout.rdbuf(out_file.rdbuf());
}
Expand Down Expand Up @@ -1044,8 +1046,9 @@ Piro::PerformROLTransientAnalysis(
}

std::streambuf *coutbuf;
std::ofstream out_file;
if(rolParams.get<bool>("Redirect Tempus Output", true)) {
std::ofstream out_file(rolParams.get<string>("Tempus Output Filename", "log_tempus.txt"));
out_file.open(rolParams.get<string>("Tempus Output Filename", "log_tempus.txt"));
coutbuf = std::cout.rdbuf();
std::cout.rdbuf(out_file.rdbuf());
}
Expand Down
18 changes: 11 additions & 7 deletions packages/piro/src/Piro_ThyraProductME_Tempus_FinalObjective.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ run_tempus(const Thyra::ModelEvaluatorBase::InArgs<Real>& inArgs,

// Override nominal values in model to supplied inArgs
RCP<DNBOME> wrapped_model = rcp(new DNBOME(thyra_model_, rcpFromRef(inArgs)));
RCP<DNBOME> wrapped_adjoint_model = rcp(new DNBOME(thyra_adjoint_model_, rcpFromRef(inArgs)));


Real t;
RCP<const Thyra::VectorBase<Real> > x, x_dot;
Expand All @@ -280,26 +282,28 @@ run_tempus(const Thyra::ModelEvaluatorBase::InArgs<Real>& inArgs,

// Create and run integrator
if (compute_dgdp && sensitivity_method_ == "Adjoint") {
const bool integratorStatus = piroTempusIntegrator_->advanceTime(time_final_);
RCP<Tempus::IntegratorAdjointSensitivity<Real> > integrator =
Tempus::createIntegratorAdjointSensitivity<Real>(tempus_params_, wrapped_model, wrapped_adjoint_model);
const bool integratorStatus = integrator->advanceTime(time_final_);
TEUCHOS_TEST_FOR_EXCEPTION(
!integratorStatus, std::logic_error, "Integrator failed!");

// Get final state
t = piroTempusIntegrator_->getTime();
x = piroTempusIntegrator_->getX();
x_dot = piroTempusIntegrator_->getXDot();
t = integrator->getTime();
x = integrator->getX();
x_dot = integrator->getXDot();
if(!dgdp_mv.is_null())
Thyra::assign(dgdp_mv.ptr(), *(piroTempusIntegrator_->getDgDp()));
Thyra::assign(dgdp_mv.ptr(), *(integrator->getDgDp()));
else {
//dgdp_op->setBlock(0, 0, piroTempusIntegrator->getDgDp());
dgdp_mv = Teuchos::rcp_dynamic_cast<Thyra::MultiVectorBase<Real>>( Teuchos::rcp_dynamic_cast<Thyra::DefaultScaledAdjointLinearOp<Real>>(dgdp_op->getNonconstBlock(0, 0))->getNonconstOp() );
Thyra::assign(dgdp_mv.ptr(), *(piroTempusIntegrator_->getDgDp()));
Thyra::assign(dgdp_mv.ptr(), *(integrator->getDgDp()));
}
}
else {
RCP<Tempus::IntegratorBasic<Real> > integrator =
Tempus::createIntegratorBasic<Real>(tempus_params_, wrapped_model);
const bool integratorStatus = integrator->advanceTime();
const bool integratorStatus = integrator->advanceTime(time_final_);
TEUCHOS_TEST_FOR_EXCEPTION(
!integratorStatus, std::logic_error, "Integrator failed!");

Expand Down
1 change: 0 additions & 1 deletion packages/piro/test/Main_AnalysisDriver_Tempus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ int main(int argc, char *argv[]) {
if (mockModel=="MassSpringDamperModel") {
p_exact[0] = 1.;
p_exact[1] = 0.5;
tol = 1e-3;
}

double l2_diff = std::sqrt(std::pow(p_view(0)-p_exact[0],2) + std::pow(p_view(1)-p_exact[1],2));
Expand Down

0 comments on commit 44ab14d

Please sign in to comment.