本文整理汇总了C++中meb::InArgs类的典型用法代码示例。如果您正苦于以下问题:C++ InArgs类的具体用法?C++ InArgs怎么用?C++ InArgs使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assertValidModel
void assertValidModel(
const StepperBase<Scalar>& stepper,
const Thyra::ModelEvaluator<Scalar>& model
)
{
typedef Thyra::ModelEvaluatorBase MEB;
TEUCHOS_ASSERT(stepper.acceptsModel());
const MEB::InArgs<Scalar> inArgs = model.createInArgs();
const MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
//TEUCHOS_ASSERT(inArgs.supports(MEB::IN_ARG_t));
TEUCHOS_ASSERT(inArgs.supports(MEB::IN_ARG_x));
TEUCHOS_ASSERT(outArgs.supports(MEB::OUT_ARG_f));
if (stepper.isImplicit()) { // implicit stepper
TEUCHOS_ASSERT( inArgs.supports(MEB::IN_ARG_x_dot) );
TEUCHOS_ASSERT( inArgs.supports(MEB::IN_ARG_alpha) );
TEUCHOS_ASSERT( inArgs.supports(MEB::IN_ARG_beta) );
TEUCHOS_ASSERT( outArgs.supports(MEB::OUT_ARG_W) );
}
//else { // explicit stepper
// TEUCHOS_ASSERT( !inArgs.supports(MEB::IN_ARG_x_dot) );
// TEUCHOS_ASSERT( !inArgs.supports(MEB::IN_ARG_alpha) );
// TEUCHOS_ASSERT( !inArgs.supports(MEB::IN_ARG_beta) );
// TEUCHOS_ASSERT( !outArgs.supports(MEB::OUT_ARG_W) );
//}
}
示例2: sinCosModel
TEUCHOS_UNIT_TEST( Rythmos_ForwardSensitivityExplicitModelEvaluator, args ) {
RCP<ForwardSensitivityExplicitModelEvaluator<double> > model =
forwardSensitivityExplicitModelEvaluator<double>();
RCP<SinCosModel> innerModel = sinCosModel();
{
RCP<ParameterList> pl = Teuchos::parameterList();
pl->set("Accept model parameters",true);
pl->set("Implicit model formulation",false);
innerModel->setParameterList(pl);
}
model->initializeStructure(innerModel, 0 );
typedef Thyra::ModelEvaluatorBase MEB;
{
MEB::InArgs<double> inArgs = model->createInArgs();
TEST_EQUALITY_CONST( inArgs.supports(MEB::IN_ARG_t), true );
TEST_EQUALITY_CONST( inArgs.supports(MEB::IN_ARG_x), true );
TEST_EQUALITY_CONST( inArgs.supports(MEB::IN_ARG_x_dot), false );
TEST_EQUALITY_CONST( inArgs.supports(MEB::IN_ARG_alpha), false );
TEST_EQUALITY_CONST( inArgs.supports(MEB::IN_ARG_beta), true );
}
{
MEB::OutArgs<double> outArgs = model->createOutArgs();
TEST_EQUALITY_CONST( outArgs.supports(MEB::OUT_ARG_f), true );
TEST_EQUALITY_CONST( outArgs.supports(MEB::OUT_ARG_W_op), false );
TEST_EQUALITY_CONST( outArgs.supports(MEB::OUT_ARG_W), false );
}
}
开发者ID:haripandey,项目名称:trilinos,代码行数:27,代码来源:Rythmos_ForwardSensitivityExplicitModelEvaluator_UnitTest.cpp
示例3:
int TriKota::ThyraDirectApplicInterface::derived_map_ac(const Dakota::String& ac_name)
{
if (App != Teuchos::null) {
// Test for consistency of problem definition between ModelEval and Dakota
TEST_FOR_EXCEPTION(numVars > numParameters, std::logic_error,
"TriKota_Dakota Adapter Error: ");
TEST_FOR_EXCEPTION(numFns > numResponses, std::logic_error,
"TriKota_Dakota Adapter Error: ");
TEST_FOR_EXCEPTION(hessFlag, std::logic_error,
"TriKota_Dakota Adapter Error: ");
MEB::InArgs<double> inArgs = App->createInArgs();
MEB::OutArgs<double> outArgs = App->createOutArgs();
TEST_FOR_EXCEPTION(gradFlag && !supportsSensitivities, std::logic_error,
"TriKota_Dakota Adapter Error: ");
// Load parameters from Dakota to ModelEval data structure
{
Thyra::DetachedVectorView<double> my_p(model_p);
for (unsigned int i=0; i<numVars; i++) my_p[i]=xC[i];
}
// Evaluate model
inArgs.set_p(0,model_p);
outArgs.set_g(0,model_g);
if (gradFlag) outArgs.set_DgDp(0,0,
MEB::DerivativeMultiVector<double>(model_dgdp,orientation));
App->evalModel(inArgs, outArgs);
Thyra::DetachedVectorView<double> my_g(model_g);
for (unsigned int j=0; j<numFns; j++) fnVals[j]= my_g[j];
if (gradFlag) {
if (orientation == MEB::DERIV_MV_BY_COL) {
for (unsigned int j=0; j<numVars; j++) {
Thyra::DetachedVectorView<double>
my_dgdp_j(model_dgdp->col(j));
for (unsigned int i=0; i<numFns; i++) fnGrads[i][j]= my_dgdp_j[i];
}
}
else {
for (unsigned int j=0; j<numFns; j++) {
Thyra::DetachedVectorView<double>
my_dgdp_j(model_dgdp->col(j));
for (unsigned int i=0; i<numVars; i++) fnGrads[j][i]= my_dgdp_j[i];
}
}
}
}
else {
TEST_FOR_EXCEPTION(parallelLib.parallel_configuration().ea_parallel_level().server_intra_communicator()
!= MPI_COMM_NULL, std::logic_error,
"\nTriKota Parallelism Error: ModelEvaluator=null, but analysis_comm != MPI_COMMM_NULL");
}
return 0;
}
示例4: if
void ExplicitModelEvaluator<Scalar>::
buildInverseMassMatrix() const
{
typedef Thyra::ModelEvaluatorBase MEB;
using Teuchos::RCP;
using Thyra::createMember;
RCP<const Thyra::ModelEvaluator<Scalar> > me = this->getUnderlyingModel();
// first allocate space for the mass matrix
RCP<Thyra::LinearOpBase<Scalar> > mass = me->create_W_op();
// intialize a zero to get rid of the x-dot
if(zero_==Teuchos::null) {
zero_ = Thyra::createMember(*me->get_x_space());
Thyra::assign(zero_.ptr(),0.0);
}
// request only the mass matrix from the physics
// Model evaluator builds: alpha*u_dot + beta*F(u) = 0
MEB::InArgs<Scalar> inArgs = me->createInArgs();
inArgs.set_x(createMember(me->get_x_space()));
inArgs.set_x_dot(zero_);
inArgs.set_alpha(-1.0);
inArgs.set_beta(0.0);
// set the one time beta to ensure dirichlet conditions
// are correctly included in the mass matrix: do it for
// both epetra and Tpetra. If a panzer model evaluator has
// not been passed in...oh well you get what you asked for!
if(panzerModel_!=Teuchos::null)
panzerModel_->setOneTimeDirichletBeta(-1.0);
else if(panzerEpetraModel_!=Teuchos::null)
panzerEpetraModel_->setOneTimeDirichletBeta(-1.0);
// set only the mass matrix
MEB::OutArgs<Scalar> outArgs = me->createOutArgs();
outArgs.set_W_op(mass);
// this will fill the mass matrix operator
me->evalModel(inArgs,outArgs);
if(!massLumping_) {
invMassMatrix_ = Thyra::inverse<Scalar>(*me->get_W_factory(),mass);
}
else {
// build lumped mass matrix (assumes all positive mass entries, does a simple sum)
Teuchos::RCP<Thyra::VectorBase<Scalar> > ones = Thyra::createMember(*mass->domain());
Thyra::assign(ones.ptr(),1.0);
RCP<Thyra::VectorBase<Scalar> > invLumpMass = Thyra::createMember(*mass->range());
Thyra::apply(*mass,Thyra::NOTRANS,*ones,invLumpMass.ptr());
Thyra::reciprocal(*invLumpMass,invLumpMass.ptr());
invMassMatrix_ = Thyra::diagonal(invLumpMass);
}
}
示例5: createInArgs
Thyra::ModelEvaluatorBase::InArgs<Scalar> ExplicitModelEvaluator<Scalar>::
getNominalValues() const
{
typedef Thyra::ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> nomVals = createInArgs();
nomVals.setArgs(this->getUnderlyingModel()->getNominalValues(),true);
return nomVals;
}
示例6:
ModelEvaluatorBase::InArgs<Scalar>
DefaultStateEliminationModelEvaluator<Scalar>::createInArgs() const
{
typedef ModelEvaluatorBase MEB;
const Teuchos::RCP<const ModelEvaluator<Scalar> >
thyraModel = this->getUnderlyingModel();
const MEB::InArgs<Scalar> wrappedInArgs = thyraModel->createInArgs();
MEB::InArgsSetup<Scalar> inArgs;
inArgs.setModelEvalDescription(this->description());
inArgs.set_Np(wrappedInArgs.Np());
inArgs.setSupports(wrappedInArgs);
inArgs.setUnsupportsAndRelated(MEB::IN_ARG_x); // Wipe out x, x_dot ...
return inArgs;
}
示例7:
Thyra::ModelEvaluatorBase::InArgs<Scalar>
ForwardSensitivityExplicitModelEvaluator<Scalar>::createInArgs() const
{
TEUCHOS_ASSERT( !is_null(stateModel_) );
typedef Thyra::ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> stateModelInArgs = stateModel_->createInArgs();
MEB::InArgsSetup<Scalar> inArgs;
inArgs.setModelEvalDescription(this->description());
inArgs.setSupports( MEB::IN_ARG_x );
inArgs.setSupports( MEB::IN_ARG_t );
inArgs.setSupports( MEB::IN_ARG_beta,
stateModelInArgs.supports(MEB::IN_ARG_beta) );
return inArgs;
}
示例8:
RCP<Thyra::VectorBase<Scalar> > eval_f_t(
const Thyra::ModelEvaluator<Scalar>& me,
Scalar t
) {
typedef Teuchos::ScalarTraits<Scalar> ST;
typedef Thyra::ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = me.createInArgs();
inArgs.set_t(t);
MEB::OutArgs<Scalar> outArgs = me.createOutArgs();
RCP<Thyra::VectorBase<Scalar> > f_out = Thyra::createMember(me.get_f_space());
V_S(outArg(*f_out),ST::zero());
outArgs.set_f(f_out);
me.evalModel(inArgs,outArgs);
return f_out;
}
示例9: eval_model_explicit
void eval_model_explicit(
const Thyra::ModelEvaluator<Scalar> &model,
Thyra::ModelEvaluatorBase::InArgs<Scalar> &basePoint,
const VectorBase<Scalar>& x_in,
const typename Thyra::ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t_in,
const Ptr<VectorBase<Scalar> >& f_out
)
{
typedef Thyra::ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
inArgs.setArgs(basePoint);
inArgs.set_x(Teuchos::rcp(&x_in,false));
if (inArgs.supports(MEB::IN_ARG_t)) {
inArgs.set_t(t_in);
}
// For model evaluators whose state function f(x, x_dot, t) describes
// an implicit ODE, and which accept an optional x_dot input argument,
// make sure the latter is set to null in order to request the evaluation
// of a state function corresponding to the explicit ODE formulation
// x_dot = f(x, t)
if (inArgs.supports(MEB::IN_ARG_x_dot)) {
inArgs.set_x_dot(Teuchos::null);
}
outArgs.set_f(Teuchos::rcp(&*f_out,false));
model.evalModel(inArgs,outArgs);
}
示例10: eval_model_explicit
void eval_model_explicit(
const Thyra::ModelEvaluator<Scalar> &model,
Thyra::ModelEvaluatorBase::InArgs<Scalar> &basePoint,
const VectorBase<Scalar>& x_in,
const typename Thyra::ModelEvaluatorBase::InArgs<Scalar>::ScalarMag &t_in,
const Ptr<VectorBase<Scalar> >& f_out
)
{
typedef Thyra::ModelEvaluatorBase MEB;
MEB::InArgs<Scalar> inArgs = model.createInArgs();
MEB::OutArgs<Scalar> outArgs = model.createOutArgs();
inArgs.setArgs(basePoint);
inArgs.set_x(Teuchos::rcp(&x_in,false));
if (inArgs.supports(MEB::IN_ARG_t)) {
inArgs.set_t(t_in);
}
outArgs.set_f(Teuchos::rcp(&*f_out,false));
model.evalModel(inArgs,outArgs);
}
示例11: stateModel_outputTempState
void ForwardSensitivityExplicitModelEvaluator<Scalar>::computeDerivativeMatrices(
const Thyra::ModelEvaluatorBase::InArgs<Scalar> &point
) const
{
TEUCHOS_ASSERT( !is_null(stateModel_) );
typedef Thyra::ModelEvaluatorBase MEB;
typedef Teuchos::VerboseObjectTempState<MEB> VOTSME;
Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
MEB::InArgs<Scalar> inArgs = stateBasePoint_;
MEB::OutArgs<Scalar> outArgs = stateModel_->createOutArgs();
if (is_null(DfDx_)) {
DfDx_ = stateModel_->create_W_op();
}
if (inArgs.supports(MEB::IN_ARG_beta)) {
inArgs.set_beta(1.0);
}
outArgs.set_W_op(DfDx_);
if (is_null(DfDp_)) {
DfDp_ = Thyra::create_DfDp_mv(
*stateModel_,p_index_,
MEB::DERIV_MV_BY_COL
).getMultiVector();
}
outArgs.set_DfDp(
p_index_,
MEB::Derivative<Scalar>(DfDp_,MEB::DERIV_MV_BY_COL)
);
VOTSME stateModel_outputTempState(stateModel_,out,verbLevel);
stateModel_->evalModel(inArgs,outArgs);
}
示例12: restart
void restart( StepperBase<Scalar> *stepper )
{
#ifdef RYTHMOS_DEBUG
TEST_FOR_EXCEPT(0==stepper);
#endif // RYTHMOS_DEBUG
typedef Thyra::ModelEvaluatorBase MEB;
const Rythmos::StepStatus<double>
stepStatus = stepper->getStepStatus();
const RCP<const Thyra::ModelEvaluator<Scalar> >
model = stepper->getModel();
// First, copy all of the model's state, including parameter values etc.
MEB::InArgs<double> initialCondition = model->createInArgs();
initialCondition.setArgs(model->getNominalValues());
// Set the current values of the state and time
RCP<const Thyra::VectorBase<double> > x, x_dot;
Rythmos::get_x_and_x_dot(*stepper,stepStatus.time,&x,&x_dot);
initialCondition.set_x(x);
initialCondition.set_x_dot(x_dot);
initialCondition.set_t(stepStatus.time);
// Set the new initial condition back on the stepper. This will effectively
// reset the stepper to think that it is starting over again (which it is).
stepper->setInitialCondition(initialCondition);
}
示例13: setDefaultInitialConditionFromNominalValues
bool setDefaultInitialConditionFromNominalValues(
const Thyra::ModelEvaluator<Scalar>& model,
const Ptr<StepperBase<Scalar> >& stepper
)
{
typedef ScalarTraits<Scalar> ST;
typedef Thyra::ModelEvaluatorBase MEB;
if (isInitialized(*stepper))
return false; // Already has an initial condition
MEB::InArgs<Scalar> initCond = model.getNominalValues();
if (!is_null(initCond.get_x())) {
// IC has x, we will assume that initCont.get_t() is the valid start time.
// Therefore, we just need to check that x_dot is also set or we will
// create a zero x_dot
#ifdef RYTHMOS_DEBUG
THYRA_ASSERT_VEC_SPACES( "setInitialConditionIfExists(...)",
*model.get_x_space(), *initCond.get_x()->space() );
#endif
if (initCond.supports(MEB::IN_ARG_x_dot)) {
if (is_null(initCond.get_x_dot())) {
const RCP<Thyra::VectorBase<Scalar> > x_dot =
createMember(model.get_x_space());
assign(x_dot.ptr(), ST::zero());
}
else {
#ifdef RYTHMOS_DEBUG
THYRA_ASSERT_VEC_SPACES( "setInitialConditionIfExists(...)",
*model.get_x_space(), *initCond.get_x_dot()->space() );
#endif
}
}
stepper->setInitialCondition(initCond);
return true;
}
// The model has not nominal values for which to set the initial
// conditions so wo don't do anything! The stepper will still have not
return false;
}
示例14: main
//.........这里部分代码省略.........
stateStepper = Rythmos::implicitRKStepper<double>(
stateModel, nonlinearSolver, irk_W_factory, irkbt
);
}
else {
stateStepper = rcp(
new Rythmos::BackwardEulerStepper<double>(
stateModel, nonlinearSolver
)
);
}
*out <<"\nstateStepper:\n" << describe(*stateStepper,verbLevel);
*out <<"\nstateStepper valid options:\n";
stateStepper->getValidParameters()->print(
*out, PLPrintOptions().indent(2).showTypes(true).showDoc(true)
);
stateStepper->setParameterList(sublist(paramList,RythmosStepper_name));
//
// Setup finite difference objects that will be used for tests
//
Thyra::DirectionalFiniteDiffCalculator<Scalar> fdCalc;
fdCalc.setParameterList(sublist(paramList,FdCalc_name));
fdCalc.setOStream(out);
fdCalc.setVerbLevel(verbLevel);
//
// Use a StepperAsModelEvaluator to integrate the state
//
const MEB::InArgs<Scalar>
state_ic = stateModel->getNominalValues();
*out << "\nstate_ic:\n" << describe(state_ic,verbLevel);
RCP<Rythmos::IntegratorBase<Scalar> > integrator;
{
RCP<ParameterList>
integratorPL = sublist(paramList,RythmosIntegrator_name);
integratorPL->set( "Take Variable Steps", as<bool>(numTimeSteps < 0) );
integratorPL->set( "Fixed dt", as<double>((finalTime - state_ic.get_t())/numTimeSteps) );
RCP<Rythmos::IntegratorBase<Scalar> >
defaultIntegrator = Rythmos::controlledDefaultIntegrator<Scalar>(
Rythmos::simpleIntegrationControlStrategy<Scalar>(integratorPL)
);
integrator = defaultIntegrator;
}
RCP<Rythmos::StepperAsModelEvaluator<Scalar> >
stateIntegratorAsModel = Rythmos::stepperAsModelEvaluator(
stateStepper, integrator, state_ic
);
stateIntegratorAsModel->setVerbLevel(verbLevel);
*out << "\nUse the StepperAsModelEvaluator to integrate state x(p,finalTime) ... \n";
RCP<Thyra::VectorBase<Scalar> > x_final;
{
Teuchos::OSTab tab(out);
x_final = createMember(stateIntegratorAsModel->get_g_space(0));
示例15: createMember
void ImplicitRKModelEvaluator<Scalar>::evalModelImpl(
const Thyra::ModelEvaluatorBase::InArgs<Scalar>& inArgs_bar,
const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs_bar
) const
{
using Teuchos::rcp_dynamic_cast;
typedef ScalarTraits<Scalar> ST;
typedef Thyra::ModelEvaluatorBase MEB;
typedef Thyra::VectorBase<Scalar> VB;
typedef Thyra::ProductVectorBase<Scalar> PVB;
typedef Thyra::BlockedLinearOpBase<Scalar> BLWB;
TEST_FOR_EXCEPTION( !isInitialized_, std::logic_error,
"Error! initializeIRKModel must be called before evalModel\n"
);
TEST_FOR_EXCEPTION( !setTimeStepPointCalled_, std::logic_error,
"Error! setTimeStepPoint must be called before evalModel"
);
THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_GEN_BEGIN(
"Rythmos::ImplicitRKModelEvaluator",inArgs_bar,outArgs_bar,daeModel_
);
//
// A) Unwrap the inArgs and outArgs to get at product vectors and block op
//
const RCP<const PVB> x_bar = rcp_dynamic_cast<const PVB>(inArgs_bar.get_x(), true);
const RCP<PVB> f_bar = rcp_dynamic_cast<PVB>(outArgs_bar.get_f(), true);
const RCP<BLWB> W_op_bar = rcp_dynamic_cast<BLWB>(outArgs_bar.get_W_op(), true);
//
// B) Assemble f_bar and W_op_bar by looping over stages
//
MEB::InArgs<Scalar> daeInArgs = daeModel_->createInArgs();
MEB::OutArgs<Scalar> daeOutArgs = daeModel_->createOutArgs();
const RCP<VB> x_i = createMember(daeModel_->get_x_space());
daeInArgs.setArgs(basePoint_);
const int numStages = irkButcherTableau_->numStages();
for ( int i = 0; i < numStages; ++i ) {
// B.1) Setup the DAE's inArgs for stage f(i) ...
assembleIRKState( i, irkButcherTableau_->A(), delta_t_, *x_old_, *x_bar, outArg(*x_i) );
daeInArgs.set_x( x_i );
daeInArgs.set_x_dot( x_bar->getVectorBlock(i) );
daeInArgs.set_t( t_old_ + irkButcherTableau_->c()(i) * delta_t_ );
Scalar alpha = ST::zero();
if (i == 0) {
alpha = ST::one();
} else {
alpha = ST::zero();
}
Scalar beta = delta_t_ * irkButcherTableau_->A()(i,0);
daeInArgs.set_alpha( alpha );
daeInArgs.set_beta( beta );
// B.2) Setup the DAE's outArgs for stage f(i) ...
if (!is_null(f_bar))
daeOutArgs.set_f( f_bar->getNonconstVectorBlock(i) );
if (!is_null(W_op_bar)) {
daeOutArgs.set_W_op(W_op_bar->getNonconstBlock(i,0));
}
// B.3) Compute f_bar(i) and/or W_op_bar(i,0) ...
daeModel_->evalModel( daeInArgs, daeOutArgs );
daeOutArgs.set_f(Teuchos::null);
daeOutArgs.set_W_op(Teuchos::null);
// B.4) Evaluate the rest of the W_op_bar(i,j=1...numStages-1) ...
if (!is_null(W_op_bar)) {
for ( int j = 1; j < numStages; ++j ) {
alpha = ST::zero();
if (i == j) {
alpha = ST::one();
} else {
alpha = ST::zero();
}
beta = delta_t_ * irkButcherTableau_->A()(i,j);
daeInArgs.set_alpha( alpha );
daeInArgs.set_beta( beta );
daeOutArgs.set_W_op(W_op_bar->getNonconstBlock(i,j));
daeModel_->evalModel( daeInArgs, daeOutArgs );
daeOutArgs.set_W_op(Teuchos::null);
}
}
}
THYRA_MODEL_EVALUATOR_DECORATOR_EVAL_MODEL_END();
}