23 base_g_maps(base_g_maps_),
26 block_map(block_map_),
30 InArgs me_inargs =
me->createInArgs();
31 OutArgs me_outargs =
me->createOutArgs();
32 num_p = me_inargs.Np();
33 num_g = me_outargs.Ng();
57 l >= num_p || l < 0, std::logic_error,
59 "Error! Stokhos::ResponseStatisticModelEvaluator::get_p_map(): " <<
60 "Invalid parameter index l = " << l << std::endl);
62 return me->get_p_map(l);
70 l >= 3*num_g || l < 0, std::logic_error,
72 "Error! Stokhos::ResponseStatisticModelEvaluator::get_g_map(): " <<
73 "Invalid response index l = " << l << std::endl);
76 return me->get_g_map(l);
78 return base_g_maps[l-num_g];
80 return base_g_maps[l-2*num_g];
88 l >= num_p || l < 0, std::logic_error,
90 "Error! Stokhos::ResponseStatisticModelEvaluator::get_p_names(): " <<
91 "Invalid parameter index l = " << l << std::endl);
93 return me->get_p_names(l);
101 l >= num_p || l < 0, std::logic_error,
103 "Error! Stokhos::ResponseStatisticModelEvaluator::get_p_init(): " <<
104 "Invalid parameter index l = " << l << std::endl);
106 return me->get_p_init(l);
109 EpetraExt::ModelEvaluator::InArgs
113 InArgs me_inargs = me->createInArgs();
115 inArgs.setModelEvalDescription(this->description());
116 inArgs.set_Np(num_p);
119 inArgs.setSupports(IN_ARG_sg_basis, me_inargs.supports(IN_ARG_sg_basis));
120 inArgs.setSupports(IN_ARG_sg_quadrature,
121 me_inargs.supports(IN_ARG_sg_quadrature));
122 inArgs.setSupports(IN_ARG_sg_expansion,
123 me_inargs.supports(IN_ARG_sg_expansion));
128 EpetraExt::ModelEvaluator::OutArgs
131 OutArgsSetup outArgs;
132 OutArgs me_outargs = me->createOutArgs();
134 outArgs.setModelEvalDescription(this->description());
136 outArgs.set_Np_Ng(num_p, 3*num_g);
137 for (
int i=0; i<num_g; i++) {
138 for (
int j=0;
j<num_p;
j++) {
139 outArgs.setSupports(OUT_ARG_DgDp, i,
j,
140 me_outargs.supports(OUT_ARG_DgDp, i,
j));
142 DerivativeSupport ds = me_outargs.supports(OUT_ARG_DgDp, i,
j);
143 DerivativeSupport ds_stat;
144 if (ds.supports(DERIV_MV_BY_COL))
145 ds_stat.plus(DERIV_MV_BY_COL);
146 if (ds.supports(DERIV_TRANS_MV_BY_ROW))
147 ds_stat.plus(DERIV_TRANS_MV_BY_ROW);
148 if (ds.supports(DERIV_LINEAR_OP))
149 ds_stat.plus(DERIV_TRANS_MV_BY_ROW);
150 outArgs.setSupports(OUT_ARG_DgDp, i+num_g,
j, ds_stat);
151 outArgs.setSupports(OUT_ARG_DgDp, i+2*num_g,
j, ds_stat);
160 const OutArgs& outArgs)
const
163 InArgs me_inargs = me->createInArgs();
166 for (
int i=0; i<num_p; i++)
167 me_inargs.set_p(i, inArgs.get_p(i));
170 if (me_inargs.supports(IN_ARG_sg_basis))
171 me_inargs.set_sg_basis(inArgs.get_sg_basis());
172 if (me_inargs.supports(IN_ARG_sg_quadrature))
173 me_inargs.set_sg_quadrature(inArgs.get_sg_quadrature());
174 if (me_inargs.supports(IN_ARG_sg_expansion))
175 me_inargs.set_sg_expansion(inArgs.get_sg_expansion());
178 OutArgs me_outargs = me->createOutArgs();
183 for (
int i=0; i<num_g; i++) {
186 need_g_var[i] =
false;
187 for (
int j=0;
j<num_p;
j++)
188 if (!outArgs.supports(OUT_ARG_DgDp, i,
j).none())
189 if (!outArgs.get_DgDp(i+2*num_g,
j).isEmpty())
190 need_g_var[i] =
true;
200 me_outargs.set_g(i, g);
203 for (
int j=0;
j<num_p;
j++) {
204 if (!outArgs.supports(OUT_ARG_DgDp, i,
j).none()) {
205 Derivative dgdp = outArgs.get_DgDp(i,
j);
207 outArgs.get_DgDp(i+num_g,
j).getMultiVector();
209 outArgs.get_DgDp(i+2*num_g,
j).getMultiVector();
214 DerivativeSupport ds = me_outargs.supports(OUT_ARG_DgDp,i,
j);
215 EDerivativeMultiVectorOrientation mvOrientation;
217 mvOrientation = outArgs.get_DgDp(i+num_g,
j).getMultiVectorOrientation();
219 mvOrientation = outArgs.get_DgDp(i+2*num_g,
j).getMultiVectorOrientation();
220 if (mvOrientation == DERIV_TRANS_MV_BY_ROW &&
221 ds.supports(DERIV_LINEAR_OP))
222 dgdp = Derivative(me->create_DgDp_op(i,
j));
223 else if (mvOrientation == DERIV_TRANS_MV_BY_ROW)
228 DERIV_TRANS_MV_BY_ROW);
237 me_outargs.set_DgDp(i,
j, dgdp);
242 me_outargs.set_g(i, g);
250 me->evalModel(me_inargs, me_outargs);
253 for (
int i=0; i<num_g; i++) {
264 sg_basis, block_map, base_g_maps[i], me->get_g_map(i),
274 for (
int j=0;
j<num_p;
j++) {
275 if (!outArgs.supports(OUT_ARG_DgDp, i,
j).none()) {
276 Derivative dgdp = me_outargs.get_DgDp(i,
j);
278 outArgs.get_DgDp(i+num_g,
j).getMultiVector();
280 outArgs.get_DgDp(i+2*num_g,
j).getMultiVector();
284 int n = base_g_maps[i]->NumMyElements();
286 base_g_maps[i], sg_comm, n);
290 for (
int l=0; l<n; l++)
293 outArgs.get_DgDp(i+num_g,
j).getMultiVectorOrientation() == DERIV_MV_BY_COL,
295 "Error! ResponseStatisticModelEvaluator does not support " <<
296 " dg/dp DERIV_MV_BY_COL for underlying operator dg/dp");
301 for (
int k=1; k<sg_basis->size(); k++)
302 for (
int l=0; l<n; l++)
303 X_sg[k][l][l] = 2.0*(*g_sg)[k][l]*sg_basis->norm_squared(k);
305 outArgs.get_DgDp(i+2*num_g,
j).getMultiVectorOrientation() == DERIV_MV_BY_COL,
307 "Error! ResponseStatisticModelEvaluator does not support " <<
308 " dg/dp DERIV_MV_BY_COL for underlying operator dg/dp");
315 dgdp.getMultiVector();
317 if (dgdp.getMultiVectorOrientation() == DERIV_MV_BY_COL)
318 row_map = me->get_g_map(i);
320 row_map = me->get_p_map(
j);
322 sg_basis, block_map, row_map, Teuchos::rcpFromRef(dgdp_mv->
Map()),
323 sg_comm,
View, *dgdp_mv);
327 dgdp_var->PutScalar(0.0);
328 for (
int k=1; k<sg_basis->size(); k++)
329 for (
int m=0; m<dgdp_var->NumVectors(); m++)
331 (*dgdp_var)[m][l] += 2.0*(*g_sg)[k][l]*dgdp_sg[k][m][l]*
332 sg_basis->norm_squared(k);
void computeVariance(Epetra_Vector &v) const
Compute variance.
Teuchos::RCP< const Epetra_Map > get_g_map(int l) const
Return response map.
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Return initial parameters.
virtual int SetUseTranspose(bool UseTranspose)=0
void computeMean(Epetra_MultiVector &v) const
Compute mean.
void computeMean(Epetra_Vector &v) const
Compute mean.
void init(const value_type &val)
Initialize coefficients.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
InArgs createInArgs() const
Create InArgs.
int NumMyElements() const
virtual int Apply(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const =0
OutArgs createOutArgs() const
Create OutArgs.
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on InArgs.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
virtual const Epetra_BlockMap & Map() const =0
Teuchos::RCP< EpetraExt::BlockMultiVector > getBlockMultiVector()
Get block vector.
Teuchos::RCP< const Epetra_Map > get_f_map() const
Return residual vector map.
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Return array of parameter names.
Teuchos::RCP< const Epetra_Map > get_p_map(int l) const
Return parameter vector map.
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
int num_g
Number of responses.
ResponseStatisticModelEvaluator(const Teuchos::RCP< EpetraExt::ModelEvaluator > &me, const Teuchos::Array< Teuchos::RCP< const Epetra_Map > > &base_g_maps, const Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > &sg_basis, const Teuchos::RCP< const EpetraExt::MultiComm > &sg_comm, const Teuchos::RCP< const Epetra_BlockMap > &block_map)
Teuchos::RCP< EpetraExt::ModelEvaluator > me
Underlying model evaluator.
ScalarType g(const Teuchos::Array< ScalarType > &x, const ScalarType &y)
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
int num_p
Number of parameters.