31 mp_block_map(mp_block_map_),
55 InArgs me_inargs =
me->createInArgs();
56 if (me_inargs.supports(IN_ARG_x_dot)) {
57 x_map =
me->get_x_map();
61 if (me_inargs.supports(IN_ARG_x)) {
62 x_map =
me->get_x_map();
68 num_p = me_inargs.Np();
69 for (
int i=0; i<
num_p; i++) {
70 if (me_inargs.supports(IN_ARG_p_mp, i))
82 OutArgs me_outargs =
me->createOutArgs();
85 if (me_outargs.supports(OUT_ARG_f)) {
86 f_map =
me->get_f_map();
91 if (me_outargs.supports(OUT_ARG_W)) {
94 for (
int i=0; i<num_qp; i++)
95 W_mp->setCoeffPtr(i,
me->create_W());
101 for (
int i=0; i<
num_p; i++) {
103 DerivativeSupport ds = me_outargs.supports(OUT_ARG_DfDp_mp,i);
104 if (ds.supports(DERIV_MV_BY_COL))
105 dfdp_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
109 else if (ds.supports(DERIV_TRANS_MV_BY_ROW))
110 dfdp_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
114 else if (ds.supports(DERIV_LINEAR_OP)) {
119 for (
int j=0;
j<num_qp;
j++)
120 dfdp_mp_op->setCoeffPtr(
j,
me->create_DfDp_op(i));
121 dfdp_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(dfdp_mp_op);
127 num_g = me_outargs.Ng();
128 for (
int i=0; i<
num_g; i++) {
129 if (me_outargs.supports(OUT_ARG_g_mp, i))
147 DerivativeSupport ds_x = me_outargs.supports(OUT_ARG_DgDx_mp, ii);
148 if (ds_x.supports(DERIV_TRANS_MV_BY_ROW))
149 dgdx_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
152 else if (ds_x.supports(DERIV_MV_BY_COL))
153 dgdx_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
156 else if (ds_x.supports(DERIV_LINEAR_OP)) {
160 for (
int j=0;
j<num_qp;
j++)
161 dgdx_mp_op->setCoeffPtr(
j,
me->create_DgDx_op(ii));
162 dgdx_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(dgdx_mp_op);
166 DerivativeSupport ds_xdot = me_outargs.supports(OUT_ARG_DgDx_dot_mp, ii);
167 if (ds_xdot.supports(DERIV_TRANS_MV_BY_ROW))
168 dgdx_dot_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
171 else if (ds_xdot.supports(DERIV_MV_BY_COL))
172 dgdx_dot_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
175 else if (ds_xdot.supports(DERIV_LINEAR_OP)) {
179 for (
int j=0;
j<num_qp;
j++)
180 dgdx_dot_mp_op->setCoeffPtr(
j,
me->create_DgDx_dot_op(ii));
181 dgdx_dot_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(dgdx_dot_mp_op);
189 DerivativeSupport ds_p = me_outargs.supports(OUT_ARG_DgDp_mp, ii,
j);
190 if (ds_p.supports(DERIV_TRANS_MV_BY_ROW))
191 dgdp_mp[i][
j] = EpetraExt::ModelEvaluator::MPDerivative(
195 else if (ds_p.supports(DERIV_MV_BY_COL))
196 dgdp_mp[i][
j] = EpetraExt::ModelEvaluator::MPDerivative(
200 else if (ds_p.supports(DERIV_LINEAR_OP)) {
204 for (
int k=0; k<num_qp; k++)
205 dgdp_mp_op->setCoeffPtr(k,
me->create_DgDp_op(ii,
j));
206 dgdp_mp[i][
j] = EpetraExt::ModelEvaluator::MPDerivative(dgdp_mp_op);
218 return me->get_x_map();
225 return me->get_f_map();
232 return me->get_p_map(l);
239 return me->get_g_map(l);
246 return me->get_p_names(l);
253 return me->get_x_init();
260 return me->get_p_init(l);
267 return me->create_W();
270 EpetraExt::ModelEvaluator::InArgs
275 InArgs me_inargs = me->createInArgs();
277 inArgs.setModelEvalDescription(this->description());
278 inArgs.set_Np(num_p);
279 inArgs.setSupports(IN_ARG_x_dot, me_inargs.supports(IN_ARG_x_dot));
280 inArgs.setSupports(IN_ARG_x, me_inargs.supports(IN_ARG_x));
281 inArgs.setSupports(IN_ARG_t, me_inargs.supports(IN_ARG_t));
282 inArgs.setSupports(IN_ARG_alpha, me_inargs.supports(IN_ARG_alpha));
283 inArgs.setSupports(IN_ARG_beta, me_inargs.supports(IN_ARG_beta));
285 for (
int i=0; i<num_p_mp; i++)
286 inArgs.setSupports(IN_ARG_p_sg, mp_p_index_map[i],
true);
287 inArgs.setSupports(IN_ARG_x_sg, me_inargs.supports(IN_ARG_x));
288 inArgs.setSupports(IN_ARG_x_dot_sg, me_inargs.supports(IN_ARG_x_dot));
289 inArgs.setSupports(IN_ARG_sg_basis,
true);
290 inArgs.setSupports(IN_ARG_sg_quadrature,
true);
295 EpetraExt::ModelEvaluator::OutArgs
299 OutArgsSetup outArgs;
300 OutArgs me_outargs = me->createOutArgs();
302 outArgs.setModelEvalDescription(this->description());
303 outArgs.set_Np_Ng(num_p, num_g);
304 outArgs.setSupports(OUT_ARG_f, me_outargs.supports(OUT_ARG_f));
305 outArgs.setSupports(OUT_ARG_W, me_outargs.supports(OUT_ARG_W));
306 for (
int j=0;
j<num_p;
j++)
307 outArgs.setSupports(OUT_ARG_DfDp,
j,
308 me_outargs.supports(OUT_ARG_DfDp,
j));
309 for (
int i=0; i<num_g; i++) {
310 outArgs.setSupports(OUT_ARG_DgDx, i,
311 me_outargs.supports(OUT_ARG_DgDx, i));
312 outArgs.setSupports(OUT_ARG_DgDx_dot, i,
313 me_outargs.supports(OUT_ARG_DgDx_dot, i));
314 for (
int j=0;
j<num_p;
j++)
315 outArgs.setSupports(OUT_ARG_DgDp, i,
j,
316 me_outargs.supports(OUT_ARG_DgDp, i,
j));
319 outArgs.setSupports(OUT_ARG_f_sg, me_outargs.supports(OUT_ARG_f_mp));
320 if (me_outargs.supports(OUT_ARG_W_mp)) {
321 outArgs.set_W_properties(me_outargs.get_W_properties());
322 outArgs.setSupports(OUT_ARG_W_sg,
true);
324 for (
int i=0; i<num_g_mp; i++)
325 outArgs.setSupports(OUT_ARG_g_sg, mp_g_index_map[i],
true);
326 for (
int j=0;
j<num_p;
j++)
327 outArgs.setSupports(OUT_ARG_DfDp_sg,
j,
328 me_outargs.supports(OUT_ARG_DfDp_mp,
j));
329 for (
int i=0; i<num_g_mp; i++) {
330 int ii = mp_g_index_map[i];
331 outArgs.setSupports(OUT_ARG_DgDx_sg, ii,
332 me_outargs.supports(OUT_ARG_DgDx_mp, ii));
333 outArgs.setSupports(OUT_ARG_DgDx_dot_sg, ii,
334 me_outargs.supports(OUT_ARG_DgDx_dot_mp, ii));
335 for (
int j=0;
j<num_p;
j++)
336 outArgs.setSupports(OUT_ARG_DgDp_sg, ii,
j,
337 me_outargs.supports(OUT_ARG_DgDp_mp, ii,
j));
345 evalModel(
const InArgs& inArgs,
const OutArgs& outArgs)
const
348 InArgs me_inargs = me->createInArgs();
349 if (me_inargs.supports(IN_ARG_x))
350 me_inargs.set_x(inArgs.get_x());
351 if (me_inargs.supports(IN_ARG_x_dot))
352 me_inargs.set_x_dot(inArgs.get_x_dot());
353 if (me_inargs.supports(IN_ARG_alpha))
354 me_inargs.set_alpha(inArgs.get_alpha());
355 if (me_inargs.supports(IN_ARG_beta))
356 me_inargs.set_beta(inArgs.get_beta());
357 if (me_inargs.supports(IN_ARG_t))
358 me_inargs.set_t(inArgs.get_t());
359 for (
int i=0; i<num_p; i++)
360 me_inargs.set_p(i, inArgs.get_p(i));
363 OutArgs me_outargs = me->createOutArgs();
364 if (me_outargs.supports(OUT_ARG_f))
365 me_outargs.set_f(outArgs.get_f());
366 if (me_outargs.supports(OUT_ARG_W))
367 me_outargs.set_W(outArgs.get_W());
368 for (
int j=0;
j<num_p;
j++)
369 if (!outArgs.supports(OUT_ARG_DfDp,
j).none())
370 me_outargs.set_DfDp(
j, outArgs.get_DfDp(
j));
371 for (
int i=0; i<num_g; i++) {
372 me_outargs.set_g(i, outArgs.get_g(i));
373 if (!outArgs.supports(OUT_ARG_DgDx, i).none())
374 me_outargs.set_DgDx(i, outArgs.get_DgDx(i));
375 if (!outArgs.supports(OUT_ARG_DgDx_dot, i).none())
376 me_outargs.set_DgDx(i, outArgs.get_DgDx_dot(i));
377 for (
int j=0;
j<outArgs.Np();
j++)
378 if (!outArgs.supports(OUT_ARG_DgDp, i,
j).none())
379 me_outargs.set_DgDp(i,
j, outArgs.get_DgDp(i,
j));
382 bool do_quad =
false;
383 InArgs::sg_const_vector_t x_sg;
384 InArgs::sg_const_vector_t x_dot_sg;
386 OutArgs::sg_vector_t f_sg;
387 OutArgs::sg_operator_t W_sg;
395 "Error! Stokhos::SGQuadModelEvaluator::evalModel(): " <<
396 "SG basis inArg cannot be null!");
399 "Error! Stokhos::SGQuadModelEvaluator::evalModel(): " <<
400 "SG quadrature inArg cannot be null!");
402 inArgs.get_sg_basis();
404 inArgs.get_sg_quadrature();
406 if (inArgs.supports(IN_ARG_x_sg)) {
407 x_sg = inArgs.get_x_sg();
412 if (inArgs.supports(IN_ARG_x_dot_sg)) {
413 x_dot_sg = inArgs.get_x_dot_sg();
418 for (
int i=0; i<num_p_mp; i++) {
419 p_sg[i] = inArgs.get_p_sg(mp_p_index_map[i]);
424 if (outArgs.supports(OUT_ARG_f_sg)) {
425 f_sg = outArgs.get_f_sg();
429 if (outArgs.supports(OUT_ARG_W_sg)) {
430 W_sg = outArgs.get_W_sg();
434 for (
int i=0; i<num_p; i++) {
435 if (!outArgs.supports(OUT_ARG_DfDp_sg, i).none()) {
436 dfdp_sg[i] = outArgs.get_DfDp_sg(i);
438 dfdp_sg[i].getMultiVector()->init(0.0);
440 dfdp_sg[i].getLinearOp()->init(0.0);
444 for (
int i=0; i<num_g_mp; i++) {
445 int ii = mp_g_index_map[i];
446 g_sg[i] = outArgs.get_g_sg(ii);
450 if (!outArgs.supports(OUT_ARG_DgDx_sg, ii).none()) {
451 dgdx_sg[i] = outArgs.get_DgDx_sg(ii);
453 dgdx_sg[i].getMultiVector()->init(0.0);
455 dgdx_sg[i].getLinearOp()->init(0.0);
458 if (!outArgs.supports(OUT_ARG_DgDx_dot_sg, ii).none()) {
459 dgdx_dot_sg[i] = outArgs.get_DgDx_dot_sg(ii);
461 dgdx_dot_sg[i].getMultiVector()->init(0.0);
463 dgdx_dot_sg[i].getLinearOp()->init(0.0);
467 for (
int j=0;
j<num_p;
j++) {
468 if (!outArgs.supports(OUT_ARG_DgDp_sg, ii,
j).none()) {
469 dgdp_sg[i][
j] = outArgs.get_DgDp_sg(ii,
j);
471 dgdp_sg[i][
j].getMultiVector()->init(0.0);
473 dgdp_sg[i][
j].getLinearOp()->init(0.0);
481 quad->getQuadWeights();
483 quad->getBasisAtQuadPoints();
487 int nqp = mp_block_map->NumMyElements();
488 for (
int qp=0; qp<nqp; qp++) {
489 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
491 "Stokhos: SGQuadMPModelEvaluator -- Polynomial Evaluation",
495 int gqp = mp_block_map->GID(qp);
498 x_sg->evaluate(quad_values[gqp], (*x_mp)[qp]);
499 me_inargs.set_x_mp(x_mp);
502 x_dot_sg->evaluate(quad_values[gqp], (*x_dot_mp)[qp]);
503 me_inargs.set_x_dot_mp(x_mp);
505 for (
int i=0; i<num_p_mp; i++) {
507 p_sg[i]->evaluate(quad_values[gqp], (*(p_mp[i]))[qp]);
508 me_inargs.set_p_mp(mp_p_index_map[i], p_mp[i]);
516 me_outargs.set_f_mp(f_mp);
518 me_outargs.set_W_mp(W_mp);
519 for (
int i=0; i<num_p_mp; i++) {
520 if (!dfdp_sg[i].isEmpty())
521 me_outargs.set_DfDp_mp(i, dfdp_mp[i]);
523 for (
int i=0; i<num_g_mp; i++) {
524 int ii = mp_g_index_map[i];
526 me_outargs.set_g_mp(ii, g_mp[i]);
527 if (!dgdx_dot_sg[i].isEmpty())
528 me_outargs.set_DgDx_dot_mp(ii, dgdx_dot_mp[i]);
529 if (!dgdx_sg[i].isEmpty())
530 me_outargs.set_DgDx_mp(ii, dgdx_mp[i]);
531 for (
int j=0;
j<num_p;
j++)
532 if (!dgdp_sg[i][
j].isEmpty())
533 me_outargs.set_DgDp_mp(ii,
j, dgdp_mp[i][
j]);
538 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
543 me->evalModel(me_inargs, me_outargs);
548 for (
int qp=0; qp<nqp; qp++) {
549 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
551 "Stokhos: SGQuadMPModelEvaluator -- Polynomial Integration", Integration);
554 int gqp = mp_block_map->GID(qp);
558 f_sg->sumIntoAllTerms(quad_weights[gqp], quad_values[gqp], basis_norms,
562 W_sg->sumIntoAllTerms(quad_weights[gqp], quad_values[gqp], basis_norms,
565 for (
int j=0;
j<num_p;
j++) {
566 if (!dfdp_sg[
j].isEmpty()) {
568 dfdp_sg[
j].getMultiVector()->sumIntoAllTerms(
569 quad_weights[gqp], quad_values[gqp], basis_norms,
570 (*(dfdp_mp[
j].getMultiVector()))[qp]);
573 dfdp_sg[
j].getLinearOp()->sumIntoAllTerms(
574 quad_weights[gqp], quad_values[gqp], basis_norms,
575 (*(dfdp_mp[
j].getLinearOp()))[qp]);
579 for (
int i=0; i<num_g_mp; i++) {
581 g_sg[i]->sumIntoAllTerms(quad_weights[gqp], quad_values[gqp],
582 basis_norms, (*g_mp[i])[qp]);
584 if (!dgdx_dot_sg[i].isEmpty()) {
586 dgdx_dot_sg[i].getMultiVector()->sumIntoAllTerms(
587 quad_weights[gqp], quad_values[gqp], basis_norms,
588 (*(dgdx_dot_mp[i].getMultiVector()))[qp]);
591 dgdx_dot_sg[i].getLinearOp()->sumIntoAllTerms(
592 quad_weights[gqp], quad_values[gqp], basis_norms,
593 (*(dgdx_dot_mp[i].getLinearOp()))[qp]);
596 if (!dgdx_sg[i].isEmpty()) {
598 dgdx_sg[i].getMultiVector()->sumIntoAllTerms(
599 quad_weights[gqp], quad_values[gqp], basis_norms,
600 (*(dgdx_mp[i].getMultiVector()))[qp]);
603 dgdx_sg[i].getLinearOp()->sumIntoAllTerms(
604 quad_weights[gqp], quad_values[gqp], basis_norms,
605 (*(dgdx_mp[i].getLinearOp()))[qp]);
608 for (
int j=0;
j<num_p;
j++) {
609 if (!dgdp_sg[i][
j].isEmpty()) {
611 dgdp_sg[i][
j].getMultiVector()->sumIntoAllTerms(
612 quad_weights[gqp], quad_values[gqp], basis_norms,
613 (*(dgdp_mp[i][
j].getMultiVector()))[qp]);
616 dgdp_sg[i][
j].getLinearOp()->sumIntoAllTerms(
617 quad_weights[gqp], quad_values[gqp], basis_norms,
618 (*(dgdp_mp[i][
j].getLinearOp()))[qp]);
627 if (mp_block_map->DistributedGlobal()) {
628 for (
int i=0; i<num_g_mp; i++) {
640 me->evalModel(me_inargs, me_outargs);
int NumGlobalElements() const
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
mp_vector_t x_dot_mp
Time derivative vector.
int num_g
Number of response vectors.
Teuchos::RCP< Epetra_Operator > create_W() const
Create W = alpha*M + beta*J matrix.
Teuchos::Array< mp_vector_t > p_mp
Parameter vectors.
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Return array of parameter names.
SGQuadMPModelEvaluator(const Teuchos::RCP< EpetraExt::ModelEvaluator > &me, const Teuchos::RCP< const EpetraExt::MultiComm > &mp_comm, const Teuchos::RCP< const Epetra_Map > &mp_block_map)
A container class for products of Epetra_Vector's.
OutArgs createOutArgs() const
Create OutArgs.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::Array< int > mp_p_index_map
Index map between block-p and p_mp maps.
mp_operator_t W_mp
W operator.
Teuchos::RCP< const EpetraExt::MultiComm > mp_comm
Parallel MP communicator.
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Return initial parameters.
mp_vector_t x_mp
Solution vector.
Teuchos::RCP< const Epetra_Vector > get_x_init() const
Return initial solution.
int NumMyElements() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Array< MPDerivative > dgdx_dot_mp
Response derivative.
Teuchos::RCP< const Epetra_Map > get_f_map() const
Return residual vector map.
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
int num_g_mp
Number of multipoint response vectors.
Teuchos::Array< MPDerivative > dfdp_mp
Residual derivatives.
A container class for products of Epetra_Vector's.
Teuchos::RCP< const Epetra_Map > mp_block_map
Map for layout of parallel MP blocks.
void resize(size_type new_size, const value_type &x=value_type())
A container class storing products of Epetra_MultiVector's.
Teuchos::Array< int > mp_g_index_map
Index map between block-g and g_mp maps.
void push_back(const value_type &x)
InArgs createInArgs() const
Create InArgs.
Teuchos::RCP< const Epetra_Map > get_g_map(int l) const
Return observation vector map.
Teuchos::RCP< const Epetra_Map > get_p_map(int l) const
Return parameter vector map.
Teuchos::RCP< EpetraExt::ModelEvaluator > me
Underlying model evaluator.
int num_p_mp
Number of multipoint parameter vectors.
Teuchos::Array< mp_vector_t > g_mp
Response vectors.
Teuchos::Array< MPDerivative > dgdx_mp
Response derivative.
mp_vector_t f_mp
Residual vector.
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on InArgs.
int num_p
Number of parameter vectors.
#define TEUCHOS_FUNC_TIME_MONITOR_DIFF(FUNCNAME, DIFF)
Teuchos::Array< Teuchos::Array< MPDerivative > > dgdp_mp
Response sensitivities.