本文整理汇总了C++中meb::InArgs::set_p方法的典型用法代码示例。如果您正苦于以下问题:C++ InArgs::set_p方法的具体用法?C++ InArgs::set_p怎么用?C++ InArgs::set_p使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meb::InArgs
的用法示例。
在下文中一共展示了InArgs::set_p方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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;
}
示例2: sinCosModel
TEUCHOS_UNIT_TEST( Rythmos_ForwardSensitivityExplicitModelEvaluator, evalModel ) {
typedef Thyra::ModelEvaluatorBase MEB;
RCP<ForwardSensitivityExplicitModelEvaluator<double> > model =
forwardSensitivityExplicitModelEvaluator<double>();
RCP<SinCosModel> innerModel = sinCosModel(false);
double a = 0.4;
double f = 1.5;
double L = 1.6;
{
RCP<ParameterList> pl = Teuchos::parameterList();
pl->set("Accept model parameters",true);
pl->set("Implicit model formulation",false);
pl->set("Coeff a", a );
pl->set("Coeff f", f );
pl->set("Coeff L", L );
innerModel->setParameterList(pl);
}
model->initializeStructure(innerModel, 0 );
RCP<VectorBase<double> > x;
MEB::InArgs<double> pointInArgs; // Used to change the solution for re-evaluation
RCP<StepperBase<double> > stepper; // Used for initializePointState
{
pointInArgs = innerModel->createInArgs();
pointInArgs.set_t(0.1);
x = Thyra::createMember(innerModel->get_x_space());
{
Thyra::DetachedVectorView<double> x_view( *x );
x_view[0] = 2.0;
x_view[1] = 3.0;
}
pointInArgs.set_x(x);
RCP<VectorBase<double> > p0 = Thyra::createMember(innerModel->get_p_space(0));
{
Thyra::DetachedVectorView<double> p0_view( *p0 );
p0_view[0] = a;
p0_view[1] = f;
p0_view[2] = L;
}
pointInArgs.set_p(0,p0);
{
// Create a stepper with these initial conditions to use to call
// initializePointState on this ME:
stepper = forwardEulerStepper<double>();
stepper->setInitialCondition(pointInArgs);
model->initializePointState(Teuchos::inOutArg(*stepper),false);
}
}
MEB::InArgs<double> inArgs = model->createInArgs();
RCP<VectorBase<double> > x_bar = Thyra::createMember(model->get_x_space());
RCP<Thyra::DefaultMultiVectorProductVector<double> >
s_bar = Teuchos::rcp_dynamic_cast<Thyra::DefaultMultiVectorProductVector<double> >(
x_bar, true
);
RCP<Thyra::MultiVectorBase<double> >
S = s_bar->getNonconstMultiVector();
// Fill S with data
{
TEST_EQUALITY_CONST( S->domain()->dim(), 3 );
TEST_EQUALITY_CONST( S->range()->dim(), 2 );
RCP<VectorBase<double> > S0 = S->col(0);
RCP<VectorBase<double> > S1 = S->col(1);
RCP<VectorBase<double> > S2 = S->col(2);
TEST_EQUALITY_CONST( S0->space()->dim(), 2 );
TEST_EQUALITY_CONST( S1->space()->dim(), 2 );
TEST_EQUALITY_CONST( S2->space()->dim(), 2 );
Thyra::DetachedVectorView<double> S0_view( *S0 );
S0_view[0] = 7.0;
S0_view[1] = 8.0;
Thyra::DetachedVectorView<double> S1_view( *S1 );
S1_view[0] = 9.0;
S1_view[1] = 10.0;
Thyra::DetachedVectorView<double> S2_view( *S2 );
S2_view[0] = 11.0;
S2_view[1] = 12.0;
}
inArgs.set_x(x_bar);
MEB::OutArgs<double> outArgs = model->createOutArgs();
RCP<VectorBase<double> > f_bar = Thyra::createMember(model->get_f_space());
RCP<Thyra::DefaultMultiVectorProductVector<double> >
f_sens = Teuchos::rcp_dynamic_cast<Thyra::DefaultMultiVectorProductVector<double> >(
f_bar, true
);
RCP<Thyra::MultiVectorBase<double> >
F_sens = f_sens->getNonconstMultiVector().assert_not_null();
V_S(Teuchos::outArg(*f_bar),0.0);
outArgs.set_f(f_bar);
inArgs.set_t(0.1);
model->evalModel(inArgs,outArgs);
// Verify F_sens = df/dx*S = df/dp
// df/dx = [ 0 1 ]
// [ -(f/L)*(f/L) 0 ]
// S = [ 7 9 11 ] x = [ 2 ]
// [ 8 10 12 ] [ 3 ]
// df/dp = [ 0 0 0 ]
// [ (f/L)*(f/L) 2*f/(L*L)*(a-x_0) -2*f*f/(L*L*L)*(a-x_0) ]
// F_sens_0 =
// [ 8 ]
//.........这里部分代码省略.........
开发者ID:haripandey,项目名称:trilinos,代码行数:101,代码来源:Rythmos_ForwardSensitivityExplicitModelEvaluator_UnitTest.cpp
示例3: main
//.........这里部分代码省略.........
Teuchos::OSTab tab(out);
RCP<const Thyra::VectorBase<Scalar> >
x_in_x_bar_final = productVectorBase<Scalar>(x_bar_final)->getVectorBlock(0);
result = Thyra::testRelNormDiffErr<Scalar>(
"x_final", *x_final,
"x_in_x_bar_final", *x_in_x_bar_final,
"maxRestateError", maxRestateError,
"warningTol", 1.0, // Don't warn
&*out, solnVerbLevel
);
if (!result) success = false;
}
//
// Compute DxDp using finite differences
//
*out << "\nApproximating DxDp(p,t) using directional finite differences of integrator for x(p,t) ...\n";
RCP<Thyra::MultiVectorBase<Scalar> > DxDp_fd_final;
{
Teuchos::OSTab tab(out);
MEB::InArgs<Scalar>
fdBasePoint = stateIntegratorAsModel->createInArgs();
fdBasePoint.set_t(finalTime);
fdBasePoint.set_p(0,stateModel->getNominalValues().get_p(0));
DxDp_fd_final = createMembers(
stateIntegratorAsModel->get_g_space(0),
stateIntegratorAsModel->get_p_space(0)->dim()
);
typedef Thyra::DirectionalFiniteDiffCalculatorTypes::SelectedDerivatives
SelectedDerivatives;
MEB::OutArgs<Scalar> fdOutArgs =
fdCalc.createOutArgs(
*stateIntegratorAsModel,
SelectedDerivatives().supports(MEB::OUT_ARG_DgDp,0,0)
);
fdOutArgs.set_DgDp(0,0,DxDp_fd_final);
// Silence the model evaluators that are called. The fdCal object
// will show all of the inputs and outputs for each call.
stateStepper->setVerbLevel(Teuchos::VERB_NONE);
stateIntegratorAsModel->setVerbLevel(Teuchos::VERB_NONE);
fdCalc.calcDerivatives(
*stateIntegratorAsModel, fdBasePoint,
stateIntegratorAsModel->createOutArgs(), // Don't bother with function value
fdOutArgs
);
*out
<< "\nFinite difference DxDp_fd_final = DxDp(p,finalTime): "
<< describe(*DxDp_fd_final,solnVerbLevel);
}