63 mp_block_map(mp_block_map_),
87 InArgs me_inargs =
me->createInArgs();
88 if (me_inargs.supports(IN_ARG_x_dot)) {
89 x_map =
me->get_x_map();
93 if (me_inargs.supports(IN_ARG_x)) {
94 x_map =
me->get_x_map();
100 num_p = me_inargs.Np();
101 for (
int i=0; i<
num_p; i++) {
102 if (me_inargs.supports(IN_ARG_p_mp, i))
114 OutArgs me_outargs =
me->createOutArgs();
117 if (me_outargs.supports(OUT_ARG_f)) {
118 f_map =
me->get_f_map();
123 if (me_outargs.supports(OUT_ARG_W)) {
126 for (
int i=0; i<num_qp; i++)
127 W_mp->setCoeffPtr(i,
me->create_W());
133 for (
int i=0; i<
num_p; i++) {
135 DerivativeSupport ds = me_outargs.supports(OUT_ARG_DfDp_mp,i);
136 if (ds.supports(DERIV_MV_BY_COL))
137 dfdp_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
141 else if (ds.supports(DERIV_TRANS_MV_BY_ROW))
142 dfdp_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
146 else if (ds.supports(DERIV_LINEAR_OP)) {
151 for (
int j=0;
j<num_qp;
j++)
152 dfdp_mp_op->setCoeffPtr(
j,
me->create_DfDp_op(i));
153 dfdp_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(dfdp_mp_op);
159 num_g = me_outargs.Ng();
160 for (
int i=0; i<
num_g; i++) {
161 if (me_outargs.supports(OUT_ARG_g_mp, i))
179 DerivativeSupport ds_x = me_outargs.supports(OUT_ARG_DgDx_mp, ii);
180 if (ds_x.supports(DERIV_TRANS_MV_BY_ROW))
181 dgdx_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
184 else if (ds_x.supports(DERIV_MV_BY_COL))
185 dgdx_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
188 else if (ds_x.supports(DERIV_LINEAR_OP)) {
192 for (
int j=0;
j<num_qp;
j++)
193 dgdx_mp_op->setCoeffPtr(
j,
me->create_DgDx_op(ii));
194 dgdx_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(dgdx_mp_op);
198 DerivativeSupport ds_xdot = me_outargs.supports(OUT_ARG_DgDx_dot_mp, ii);
199 if (ds_xdot.supports(DERIV_TRANS_MV_BY_ROW))
200 dgdx_dot_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
203 else if (ds_xdot.supports(DERIV_MV_BY_COL))
204 dgdx_dot_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(
207 else if (ds_xdot.supports(DERIV_LINEAR_OP)) {
211 for (
int j=0;
j<num_qp;
j++)
212 dgdx_dot_mp_op->setCoeffPtr(
j,
me->create_DgDx_dot_op(ii));
213 dgdx_dot_mp[i] = EpetraExt::ModelEvaluator::MPDerivative(dgdx_dot_mp_op);
221 DerivativeSupport ds_p = me_outargs.supports(OUT_ARG_DgDp_mp, ii,
j);
222 if (ds_p.supports(DERIV_TRANS_MV_BY_ROW))
223 dgdp_mp[i][
j] = EpetraExt::ModelEvaluator::MPDerivative(
227 else if (ds_p.supports(DERIV_MV_BY_COL))
228 dgdp_mp[i][
j] = EpetraExt::ModelEvaluator::MPDerivative(
232 else if (ds_p.supports(DERIV_LINEAR_OP)) {
236 for (
int k=0; k<num_qp; k++)
237 dgdp_mp_op->setCoeffPtr(k,
me->create_DgDp_op(ii,
j));
238 dgdp_mp[i][
j] = EpetraExt::ModelEvaluator::MPDerivative(dgdp_mp_op);
250 return me->get_x_map();
257 return me->get_f_map();
264 return me->get_p_map(l);
271 return me->get_g_map(l);
278 return me->get_p_names(l);
285 return me->get_x_init();
292 return me->get_p_init(l);
299 return me->create_W();
302 EpetraExt::ModelEvaluator::InArgs
307 InArgs me_inargs = me->createInArgs();
309 inArgs.setModelEvalDescription(this->description());
310 inArgs.set_Np(num_p);
311 inArgs.setSupports(IN_ARG_x_dot, me_inargs.supports(IN_ARG_x_dot));
312 inArgs.setSupports(IN_ARG_x, me_inargs.supports(IN_ARG_x));
313 inArgs.setSupports(IN_ARG_t, me_inargs.supports(IN_ARG_t));
314 inArgs.setSupports(IN_ARG_alpha, me_inargs.supports(IN_ARG_alpha));
315 inArgs.setSupports(IN_ARG_beta, me_inargs.supports(IN_ARG_beta));
317 for (
int i=0; i<num_p_mp; i++)
318 inArgs.setSupports(IN_ARG_p_sg, mp_p_index_map[i],
true);
319 inArgs.setSupports(IN_ARG_x_sg, me_inargs.supports(IN_ARG_x));
320 inArgs.setSupports(IN_ARG_x_dot_sg, me_inargs.supports(IN_ARG_x_dot));
321 inArgs.setSupports(IN_ARG_sg_basis,
true);
322 inArgs.setSupports(IN_ARG_sg_quadrature,
true);
327 EpetraExt::ModelEvaluator::OutArgs
331 OutArgsSetup outArgs;
332 OutArgs me_outargs = me->createOutArgs();
334 outArgs.setModelEvalDescription(this->description());
335 outArgs.set_Np_Ng(num_p, num_g);
336 outArgs.setSupports(OUT_ARG_f, me_outargs.supports(OUT_ARG_f));
337 outArgs.setSupports(OUT_ARG_W, me_outargs.supports(OUT_ARG_W));
338 for (
int j=0;
j<num_p;
j++)
339 outArgs.setSupports(OUT_ARG_DfDp,
j,
340 me_outargs.supports(OUT_ARG_DfDp,
j));
341 for (
int i=0; i<num_g; i++) {
342 outArgs.setSupports(OUT_ARG_DgDx, i,
343 me_outargs.supports(OUT_ARG_DgDx, i));
344 outArgs.setSupports(OUT_ARG_DgDx_dot, i,
345 me_outargs.supports(OUT_ARG_DgDx_dot, i));
346 for (
int j=0;
j<num_p;
j++)
347 outArgs.setSupports(OUT_ARG_DgDp, i,
j,
348 me_outargs.supports(OUT_ARG_DgDp, i,
j));
351 outArgs.setSupports(OUT_ARG_f_sg, me_outargs.supports(OUT_ARG_f_mp));
352 if (me_outargs.supports(OUT_ARG_W_mp)) {
353 outArgs.set_W_properties(me_outargs.get_W_properties());
354 outArgs.setSupports(OUT_ARG_W_sg,
true);
356 for (
int i=0; i<num_g_mp; i++)
357 outArgs.setSupports(OUT_ARG_g_sg, mp_g_index_map[i],
true);
358 for (
int j=0;
j<num_p;
j++)
359 outArgs.setSupports(OUT_ARG_DfDp_sg,
j,
360 me_outargs.supports(OUT_ARG_DfDp_mp,
j));
361 for (
int i=0; i<num_g_mp; i++) {
362 int ii = mp_g_index_map[i];
363 outArgs.setSupports(OUT_ARG_DgDx_sg, ii,
364 me_outargs.supports(OUT_ARG_DgDx_mp, ii));
365 outArgs.setSupports(OUT_ARG_DgDx_dot_sg, ii,
366 me_outargs.supports(OUT_ARG_DgDx_dot_mp, ii));
367 for (
int j=0;
j<num_p;
j++)
368 outArgs.setSupports(OUT_ARG_DgDp_sg, ii,
j,
369 me_outargs.supports(OUT_ARG_DgDp_mp, ii,
j));
377 evalModel(
const InArgs& inArgs,
const OutArgs& outArgs)
const
380 InArgs me_inargs = me->createInArgs();
381 if (me_inargs.supports(IN_ARG_x))
382 me_inargs.set_x(inArgs.get_x());
383 if (me_inargs.supports(IN_ARG_x_dot))
384 me_inargs.set_x_dot(inArgs.get_x_dot());
385 if (me_inargs.supports(IN_ARG_alpha))
386 me_inargs.set_alpha(inArgs.get_alpha());
387 if (me_inargs.supports(IN_ARG_beta))
388 me_inargs.set_beta(inArgs.get_beta());
389 if (me_inargs.supports(IN_ARG_t))
390 me_inargs.set_t(inArgs.get_t());
391 for (
int i=0; i<num_p; i++)
392 me_inargs.set_p(i, inArgs.get_p(i));
395 OutArgs me_outargs = me->createOutArgs();
396 if (me_outargs.supports(OUT_ARG_f))
397 me_outargs.set_f(outArgs.get_f());
398 if (me_outargs.supports(OUT_ARG_W))
399 me_outargs.set_W(outArgs.get_W());
400 for (
int j=0;
j<num_p;
j++)
401 if (!outArgs.supports(OUT_ARG_DfDp,
j).none())
402 me_outargs.set_DfDp(
j, outArgs.get_DfDp(
j));
403 for (
int i=0; i<num_g; i++) {
404 me_outargs.set_g(i, outArgs.get_g(i));
405 if (!outArgs.supports(OUT_ARG_DgDx, i).none())
406 me_outargs.set_DgDx(i, outArgs.get_DgDx(i));
407 if (!outArgs.supports(OUT_ARG_DgDx_dot, i).none())
408 me_outargs.set_DgDx(i, outArgs.get_DgDx_dot(i));
409 for (
int j=0;
j<outArgs.Np();
j++)
410 if (!outArgs.supports(OUT_ARG_DgDp, i,
j).none())
411 me_outargs.set_DgDp(i,
j, outArgs.get_DgDp(i,
j));
414 bool do_quad =
false;
415 InArgs::sg_const_vector_t x_sg;
416 InArgs::sg_const_vector_t x_dot_sg;
418 OutArgs::sg_vector_t f_sg;
419 OutArgs::sg_operator_t W_sg;
427 "Error! Stokhos::SGQuadModelEvaluator::evalModel(): " <<
428 "SG basis inArg cannot be null!");
431 "Error! Stokhos::SGQuadModelEvaluator::evalModel(): " <<
432 "SG quadrature inArg cannot be null!");
434 inArgs.get_sg_basis();
436 inArgs.get_sg_quadrature();
438 if (inArgs.supports(IN_ARG_x_sg)) {
439 x_sg = inArgs.get_x_sg();
444 if (inArgs.supports(IN_ARG_x_dot_sg)) {
445 x_dot_sg = inArgs.get_x_dot_sg();
450 for (
int i=0; i<num_p_mp; i++) {
451 p_sg[i] = inArgs.get_p_sg(mp_p_index_map[i]);
456 if (outArgs.supports(OUT_ARG_f_sg)) {
457 f_sg = outArgs.get_f_sg();
461 if (outArgs.supports(OUT_ARG_W_sg)) {
462 W_sg = outArgs.get_W_sg();
466 for (
int i=0; i<num_p; i++) {
467 if (!outArgs.supports(OUT_ARG_DfDp_sg, i).none()) {
468 dfdp_sg[i] = outArgs.get_DfDp_sg(i);
470 dfdp_sg[i].getMultiVector()->init(0.0);
472 dfdp_sg[i].getLinearOp()->init(0.0);
476 for (
int i=0; i<num_g_mp; i++) {
477 int ii = mp_g_index_map[i];
478 g_sg[i] = outArgs.get_g_sg(ii);
482 if (!outArgs.supports(OUT_ARG_DgDx_sg, ii).none()) {
483 dgdx_sg[i] = outArgs.get_DgDx_sg(ii);
485 dgdx_sg[i].getMultiVector()->init(0.0);
487 dgdx_sg[i].getLinearOp()->init(0.0);
490 if (!outArgs.supports(OUT_ARG_DgDx_dot_sg, ii).none()) {
491 dgdx_dot_sg[i] = outArgs.get_DgDx_dot_sg(ii);
493 dgdx_dot_sg[i].getMultiVector()->init(0.0);
495 dgdx_dot_sg[i].getLinearOp()->init(0.0);
499 for (
int j=0;
j<num_p;
j++) {
500 if (!outArgs.supports(OUT_ARG_DgDp_sg, ii,
j).none()) {
501 dgdp_sg[i][
j] = outArgs.get_DgDp_sg(ii,
j);
503 dgdp_sg[i][
j].getMultiVector()->init(0.0);
505 dgdp_sg[i][
j].getLinearOp()->init(0.0);
513 quad->getQuadWeights();
515 quad->getBasisAtQuadPoints();
519 int nqp = mp_block_map->NumMyElements();
520 for (
int qp=0; qp<nqp; qp++) {
521 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
523 "Stokhos: SGQuadMPModelEvaluator -- Polynomial Evaluation",
527 int gqp = mp_block_map->GID(qp);
530 x_sg->evaluate(quad_values[gqp], (*x_mp)[qp]);
531 me_inargs.set_x_mp(x_mp);
534 x_dot_sg->evaluate(quad_values[gqp], (*x_dot_mp)[qp]);
535 me_inargs.set_x_dot_mp(x_mp);
537 for (
int i=0; i<num_p_mp; i++) {
539 p_sg[i]->evaluate(quad_values[gqp], (*(p_mp[i]))[qp]);
540 me_inargs.set_p_mp(mp_p_index_map[i], p_mp[i]);
548 me_outargs.set_f_mp(f_mp);
550 me_outargs.set_W_mp(W_mp);
551 for (
int i=0; i<num_p_mp; i++) {
552 if (!dfdp_sg[i].isEmpty())
553 me_outargs.set_DfDp_mp(i, dfdp_mp[i]);
555 for (
int i=0; i<num_g_mp; i++) {
556 int ii = mp_g_index_map[i];
558 me_outargs.set_g_mp(ii, g_mp[i]);
559 if (!dgdx_dot_sg[i].isEmpty())
560 me_outargs.set_DgDx_dot_mp(ii, dgdx_dot_mp[i]);
561 if (!dgdx_sg[i].isEmpty())
562 me_outargs.set_DgDx_mp(ii, dgdx_mp[i]);
563 for (
int j=0;
j<num_p;
j++)
564 if (!dgdp_sg[i][
j].isEmpty())
565 me_outargs.set_DgDp_mp(ii,
j, dgdp_mp[i][
j]);
570 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
575 me->evalModel(me_inargs, me_outargs);
580 for (
int qp=0; qp<nqp; qp++) {
581 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
583 "Stokhos: SGQuadMPModelEvaluator -- Polynomial Integration", Integration);
586 int gqp = mp_block_map->GID(qp);
590 f_sg->sumIntoAllTerms(quad_weights[gqp], quad_values[gqp], basis_norms,
594 W_sg->sumIntoAllTerms(quad_weights[gqp], quad_values[gqp], basis_norms,
597 for (
int j=0;
j<num_p;
j++) {
598 if (!dfdp_sg[
j].isEmpty()) {
600 dfdp_sg[
j].getMultiVector()->sumIntoAllTerms(
601 quad_weights[gqp], quad_values[gqp], basis_norms,
602 (*(dfdp_mp[
j].getMultiVector()))[qp]);
605 dfdp_sg[
j].getLinearOp()->sumIntoAllTerms(
606 quad_weights[gqp], quad_values[gqp], basis_norms,
607 (*(dfdp_mp[
j].getLinearOp()))[qp]);
611 for (
int i=0; i<num_g_mp; i++) {
613 g_sg[i]->sumIntoAllTerms(quad_weights[gqp], quad_values[gqp],
614 basis_norms, (*g_mp[i])[qp]);
616 if (!dgdx_dot_sg[i].isEmpty()) {
618 dgdx_dot_sg[i].getMultiVector()->sumIntoAllTerms(
619 quad_weights[gqp], quad_values[gqp], basis_norms,
620 (*(dgdx_dot_mp[i].getMultiVector()))[qp]);
623 dgdx_dot_sg[i].getLinearOp()->sumIntoAllTerms(
624 quad_weights[gqp], quad_values[gqp], basis_norms,
625 (*(dgdx_dot_mp[i].getLinearOp()))[qp]);
628 if (!dgdx_sg[i].isEmpty()) {
630 dgdx_sg[i].getMultiVector()->sumIntoAllTerms(
631 quad_weights[gqp], quad_values[gqp], basis_norms,
632 (*(dgdx_mp[i].getMultiVector()))[qp]);
635 dgdx_sg[i].getLinearOp()->sumIntoAllTerms(
636 quad_weights[gqp], quad_values[gqp], basis_norms,
637 (*(dgdx_mp[i].getLinearOp()))[qp]);
640 for (
int j=0;
j<num_p;
j++) {
641 if (!dgdp_sg[i][
j].isEmpty()) {
643 dgdp_sg[i][
j].getMultiVector()->sumIntoAllTerms(
644 quad_weights[gqp], quad_values[gqp], basis_norms,
645 (*(dgdp_mp[i][
j].getMultiVector()))[qp]);
648 dgdp_sg[i][
j].getLinearOp()->sumIntoAllTerms(
649 quad_weights[gqp], quad_values[gqp], basis_norms,
650 (*(dgdp_mp[i][
j].getLinearOp()))[qp]);
659 if (mp_block_map->DistributedGlobal()) {
660 for (
int i=0; i<num_g_mp; i++) {
672 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.