/usr/include/trilinos/Rythmos_BasicDiscreteAdjointStepperTester_def.hpp is in libtrilinos-rythmos-dev 12.10.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | //@HEADER
// ***********************************************************************
//
// Rythmos Package
// Copyright (2006) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
// USA
// Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
//
// ***********************************************************************
//@HEADER
#ifndef Rythmos_BASIC_DISCRETE_ADJOINT_STEPPER_TESTER_DEF_H
#define Rythmos_BASIC_DISCRETE_ADJOINT_STEPPER_TESTER_DEF_H
#include "Rythmos_BasicDiscreteAdjointStepperTester_decl.hpp"
#include "Rythmos_ForwardSensitivityStepper.hpp"
#include "Rythmos_AdjointModelEvaluator.hpp"
#include "Rythmos_DefaultIntegrator.hpp" // ToDo: Remove when we can!
#include "Thyra_LinearNonlinearSolver.hpp"
#include "Thyra_VectorBase.hpp"
#include "Thyra_VectorStdOps.hpp"
#include "Thyra_TestingTools.hpp"
template<class Scalar>
Teuchos::RCP<Rythmos::BasicDiscreteAdjointStepperTester<Scalar> >
Rythmos::basicDiscreteAdjointStepperTester()
{
return Teuchos::rcp(new BasicDiscreteAdjointStepperTester<Scalar>);
}
template<class Scalar>
Teuchos::RCP<Rythmos::BasicDiscreteAdjointStepperTester<Scalar> >
Rythmos::basicDiscreteAdjointStepperTester(const RCP<ParameterList> ¶mList)
{
const RCP<Rythmos::BasicDiscreteAdjointStepperTester<Scalar> > bdast =
basicDiscreteAdjointStepperTester<Scalar>();
bdast->setParameterList(paramList);
return bdast;
}
namespace Rythmos {
// Overridden from ParameterListAcceptor
template<class Scalar>
void BasicDiscreteAdjointStepperTester<Scalar>::setParameterList(
RCP<ParameterList> const& paramList
)
{
namespace BDASTU = BasicDiscreteAdjointStepperTesterUtils;
paramList->validateParametersAndSetDefaults(*this->getValidParameters());
this->setMyParamList(paramList);
errorTol_ = Teuchos::getParameter<double>(*paramList, BDASTU::ErrorTol_name);
}
template<class Scalar>
RCP<const ParameterList>
BasicDiscreteAdjointStepperTester<Scalar>::getValidParameters() const
{
namespace BDASTU = BasicDiscreteAdjointStepperTesterUtils;
static RCP<const ParameterList> validPL;
if (is_null(validPL)) {
const RCP<ParameterList> pl = Teuchos::parameterList();
pl->set(BDASTU::ErrorTol_name, BDASTU::ErrorTol_default);
validPL = pl;
}
return validPL;
}
template<class Scalar>
bool BasicDiscreteAdjointStepperTester<Scalar>::testAdjointStepper(
Thyra::ModelEvaluator<Scalar>& adjointModel,
const Ptr<IntegratorBase<Scalar> >& forwardIntegrator
)
{
using Teuchos::describe;
using Teuchos::outArg;
using Teuchos::rcp_dynamic_cast;
using Teuchos::dyn_cast;
using Teuchos::dyn_cast;
using Teuchos::OSTab;
using Teuchos::sublist;
typedef Thyra::ModelEvaluatorBase MEB;
using Thyra::createMember;
namespace BDASTU = BasicDiscreteAdjointStepperTesterUtils;
const RCP<Teuchos::FancyOStream> out = this->getOStream();
const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
const RCP<ParameterList> paramList = this->getMyNonconstParamList();
bool success = true;
OSTab tab(out);
//
*out << "\n*** Entering BasicDiscreteAdjointStepperTester<Scalar>::testAdjointStepper(...) ...\n";
//
const TimeRange<Scalar> fwdTimeRange = forwardIntegrator->getFwdTimeRange();
const RCP<Rythmos::StepperBase<Scalar> > fwdStepper =
forwardIntegrator->getNonconstStepper();
const RCP<const Thyra::ModelEvaluator<Scalar> > fwdModel =
fwdStepper->getModel();
const RCP<const Thyra::VectorSpaceBase<Scalar> > f_space = fwdModel->get_f_space();
//
*out << "\nA) Construct the IC basis B ...\n";
//
const RCP<Thyra::MultiVectorBase<Scalar> > B =
createMembers(fwdModel->get_x_space(), 1, "B");
Thyra::seed_randomize<Scalar>(0);
Thyra::randomize<Scalar>( -1.0, +1.0, B.ptr() );
*out << "\nB: " << describe(*B, verbLevel);
//
*out << "\nB) Construct the forward sensitivity integrator ...\n";
//
const RCP<ForwardSensitivityStepper<Scalar> > fwdSensStepper =
forwardSensitivityStepper<Scalar>();
fwdSensStepper->initializeSyncedSteppersInitCondOnly(
fwdModel,
B->domain(), // p_space
fwdStepper->getInitialCondition(),
fwdStepper,
dyn_cast<SolverAcceptingStepperBase<Scalar> >(*fwdStepper).getNonconstSolver()
);
*out << "\nfwdSensStepper: " << describe(*fwdSensStepper, verbLevel);
const MEB::InArgs<Scalar> fwdIC =
forwardIntegrator->getStepper()->getInitialCondition();
MEB::InArgs<Scalar> fwdSensIC =
createStateAndSensInitialCondition<Scalar>(*fwdSensStepper, fwdIC, B);
fwdSensStepper->setInitialCondition(fwdSensIC);
const RCP<IntegratorBase<Scalar> > fwdSensIntegrator =
forwardIntegrator->cloneIntegrator();
fwdSensIntegrator->setStepper(fwdSensStepper,
forwardIntegrator->getFwdTimeRange().upper());
*out << "\nfwdSensIntegrator: " << describe(*fwdSensIntegrator, verbLevel);
//
*out << "\nC) Construct the adjoint sensitivity integrator ...\n";
//
RCP<AdjointModelEvaluator<Scalar> > adjModel =
adjointModelEvaluator<Scalar>(fwdModel, fwdTimeRange);
adjModel->setFwdStateSolutionBuffer(
dyn_cast<DefaultIntegrator<Scalar> >(*forwardIntegrator).getTrailingInterpolationBuffer()
);
/** \todo 2009/09/16: above: Replace dynamic cast to get trailing interp
* buffer with the base integator itself. ToDo this, we will need to get
* DefaultIntegrator::getPoints(...) to get points off off the
* trailingInterpBuffer object also.
*/
*out << "\nadjModel: " << describe(*adjModel, verbLevel);
// lambda(t_final) = 0.0 (for now)
const RCP<Thyra::VectorBase<Scalar> > lambda_ic = createMember(f_space);
V_S( lambda_ic.ptr(), 0.0 );
// lambda_dot(t_final,i) = 0.0
const RCP<Thyra::VectorBase<Scalar> > lambda_dot_ic = createMember(f_space);
Thyra::V_S( lambda_dot_ic.ptr(), 0.0 );
MEB::InArgs<Scalar> adj_ic = adjModel->getNominalValues();
adj_ic.set_x(lambda_ic);
adj_ic.set_x_dot(lambda_dot_ic);
*out << "\nadj_ic: " << describe(adj_ic, Teuchos::VERB_EXTREME);
const RCP<Thyra::LinearNonlinearSolver<Scalar> > adjTimeStepSolver =
Thyra::linearNonlinearSolver<Scalar>();
const RCP<Rythmos::StepperBase<Scalar> > adjStepper =
forwardIntegrator->getStepper()->cloneStepperAlgorithm();
*out << "\nadjStepper: " << describe(*adjStepper, verbLevel);
adjStepper->setInitialCondition(adj_ic);
const RCP<IntegratorBase<Scalar> > adjIntegrator = forwardIntegrator->cloneIntegrator();
adjIntegrator->setStepper(adjStepper, forwardIntegrator->getFwdTimeRange().length());
//
*out << "\nD) Solve the forawrd problem storing the state along the way ...\n";
//
const double t_final = fwdTimeRange.upper();
RCP<const Thyra::VectorBase<Scalar> > x_final, x_dot_final;
get_fwd_x_and_x_dot( *forwardIntegrator, t_final, outArg(x_final), outArg(x_dot_final) );
*out << "\nt_final = " << t_final << "\n";
*out << "\nx_final: " << *x_final;
*out << "\nx_dot_final: " << *x_dot_final;
//
*out << "\nE) Solve the forawrd sensitivity equations and compute fwd reduced sens ...\n";
//
// Set the initial condition
TEUCHOS_TEST_FOR_EXCEPT(true);
// Solve the fwd sens equations
TEUCHOS_TEST_FOR_EXCEPT(true);
// Compute the reduced gradient at t_f
TEUCHOS_TEST_FOR_EXCEPT(true);
//
*out << "\nF) Solve the adjoint equations and compute adj reduced sens ...\n";
//
// Compute and set the adjoint initial condition
TEUCHOS_TEST_FOR_EXCEPT(true);
// Solve the adjoint equations
TEUCHOS_TEST_FOR_EXCEPT(true);
// Compute the reduced gradient at t_0
TEUCHOS_TEST_FOR_EXCEPT(true);
//
*out << "\nG) Compare forward and adjoint reduced sens ...\n";
//
TEUCHOS_TEST_FOR_EXCEPT(true);
//
*out << "\n*** Leaving BasicDiscreteAdjointStepperTester<Scalar>::testAdjointStepper(...) ...\n";
//
return success;
}
// private:
template<class Scalar>
BasicDiscreteAdjointStepperTester<Scalar>::BasicDiscreteAdjointStepperTester()
: errorTol_(BasicDiscreteAdjointStepperTesterUtils::ErrorTol_default)
{}
} // namespace Rythmos
//
// Explicit Instantiation macro
//
// Must be expanded from within the Rythmos namespace!
//
#define FORWARD_SENSITIVITY_STEPPER_INSTANT(SCALAR) \
\
template class BasicDiscreteAdjointStepperTester<SCALAR >; \
\
template RCP<BasicDiscreteAdjointStepperTester<SCALAR > > \
basicDiscreteAdjointStepperTester(); \
\
template RCP<BasicDiscreteAdjointStepperTester<SCALAR> > \
basicDiscreteAdjointStepperTester(const RCP<ParameterList> ¶mList);
#endif //Rythmos_BASIC_DISCRETE_ADJOINT_STEPPER_TESTER_DEF_H
|