Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_SGInverseModelEvaluator.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
15 #include "Epetra_Map.h"
16 #include "Teuchos_Assert.hpp"
17 
20  const Teuchos::Array<int>& sg_p_index_map_,
21  const Teuchos::Array<int>& sg_g_index_map_,
22  const Teuchos::Array< Teuchos::RCP<const Epetra_Map> >& base_g_maps_) :
23  me(me_),
24  sg_p_index_map(sg_p_index_map_),
25  sg_g_index_map(sg_g_index_map_),
26  base_g_maps(base_g_maps_),
27  num_p(0),
28  num_g(0),
29  num_p_sg(sg_p_index_map.size()),
30  num_g_sg(sg_g_index_map.size())
31 {
32  InArgs me_inargs = me->createInArgs();
33  OutArgs me_outargs = me->createOutArgs();
34  num_p = me_inargs.Np() - num_p_sg;
35  num_g = me_outargs.Ng();
36 
38  base_g_maps.size() != num_g_sg, std::logic_error,
39  std::endl
40  << "Error! Stokhos::SGInverseModelEvaluator::SGInverseModelEvaluator():"
41  << " Base response map array size does not match size of index array!");
42 }
43 
44 // Overridden from EpetraExt::ModelEvaluator
45 
48 get_x_map() const
49 {
50  return Teuchos::null;
51 }
52 
55 get_f_map() const
56 {
57  return Teuchos::null;
58 }
59 
62 get_p_map(int l) const
63 {
65  l >= num_p || l < 0, std::logic_error,
66  std::endl << "Error! Stokhos::SGInverseModelEvaluator::get_p_map():"
67  << " Invalid parameter index l = " << l << std::endl);
68  return me->get_p_map(l);
69 }
70 
73 get_g_map(int l) const
74 {
76  l >= num_g || l < 0, std::logic_error,
77  std::endl << "Error! Stokhos::SGInverseModelEvaluator::get_g_map():"
78  << " Invalid response index l = " << l << std::endl);
79  return base_g_maps[l];
80 }
81 
84 get_p_names(int l) const
85 {
87  l >= num_p || l < 0, std::logic_error,
88  std::endl << "Error! Stokhos::SGInverseModelEvaluator::get_p_names():"
89  << " Invalid parameter index l = " << l << std::endl);
90  return me->get_p_names(l);
91 }
92 
95 get_p_init(int l) const
96 {
98  l >= num_p || l < 0, std::logic_error,
99  std::endl << "Error! Stokhos::SGInverseModelEvaluator::get_p_init():"
100  << " Invalid parameter index l = " << l << std::endl);
101  return me->get_p_init(l);
102 }
103 
104 EpetraExt::ModelEvaluator::InArgs
106 {
107  InArgsSetup inArgs;
108  InArgs me_inargs = me->createInArgs();
109 
110  inArgs.setModelEvalDescription(this->description());
111  inArgs.set_Np(num_p);
112  for (int i=0; i<num_p_sg; i++)
113  inArgs.setSupports(IN_ARG_p_sg, sg_p_index_map[i], true);
114  inArgs.setSupports(IN_ARG_sg_basis, me_inargs.supports(IN_ARG_sg_basis));
115  inArgs.setSupports(IN_ARG_sg_quadrature,
116  me_inargs.supports(IN_ARG_sg_quadrature));
117  inArgs.setSupports(IN_ARG_sg_expansion,
118  me_inargs.supports(IN_ARG_sg_expansion));
119 
120  return inArgs;
121 }
122 
123 EpetraExt::ModelEvaluator::OutArgs
125 {
126  OutArgsSetup outArgs;
127  OutArgs me_outargs = me->createOutArgs();
128 
129  outArgs.setModelEvalDescription(this->description());
130 
131  outArgs.set_Np_Ng(num_p, num_g);
132  for (int i=0; i<num_g_sg; i++) {
133  outArgs.setSupports(OUT_ARG_g_sg, sg_g_index_map[i], true);
134  for (int j=0; j<num_p; j++)
135  outArgs.setSupports(OUT_ARG_DgDp_sg, sg_g_index_map[i], j,
136  me_outargs.supports(OUT_ARG_DgDp, i, j));
137  }
138 
139  return outArgs;
140 }
141 
142 void
144  const OutArgs& outArgs) const
145 {
146  // Create underlying inargs
147  InArgs me_inargs = me->createInArgs();
148 
149  // Pass parameters
150  for (int i=0; i<num_p; i++)
151  me_inargs.set_p(i, inArgs.get_p(i));
152 
153  // Pass SG parameters
154  for (int i=0; i<num_p_sg; i++) {
155  InArgs::sg_const_vector_t p_sg = inArgs.get_p_sg(sg_p_index_map[i]);
156  if (p_sg != Teuchos::null) {
157  me_inargs.set_p(i+num_p, p_sg->getBlockVector());
158  }
159  }
160 
161  // Pass SG data
162  if (me_inargs.supports(IN_ARG_sg_basis))
163  me_inargs.set_sg_basis(inArgs.get_sg_basis());
164  if (me_inargs.supports(IN_ARG_sg_quadrature))
165  me_inargs.set_sg_quadrature(inArgs.get_sg_quadrature());
166  if (me_inargs.supports(IN_ARG_sg_expansion))
167  me_inargs.set_sg_expansion(inArgs.get_sg_expansion());
168 
169  // Create underlying outargs
170  OutArgs me_outargs = me->createOutArgs();
171 
172  // SG Responses
173  for (int i=0; i<num_g_sg; i++) {
174  int ii = sg_g_index_map[i];
175 
176  // g
177  OutArgs::sg_vector_t g_sg = outArgs.get_g_sg(ii);
178  if (g_sg != Teuchos::null) {
179  me_outargs.set_g(i, Teuchos::rcp_dynamic_cast<Epetra_Vector>(g_sg->getBlockVector()));
180  }
181 
182  // dg/dp
183  for (int j=0; j<num_p; j++) {
184  if (!outArgs.supports(OUT_ARG_DgDp_sg, ii, j).none()) {
185  SGDerivative dgdp_sg = outArgs.get_DgDp_sg(ii,j);
187  dgdp_sg.getMultiVector();
188  Teuchos::RCP<Epetra_Operator> dgdp_sg_op =
189  dgdp_sg.getLinearOp();
190  if (dgdp_sg_mv != Teuchos::null) {
191  me_outargs.set_DgDp(
192  i, j, Derivative(dgdp_sg_mv->getBlockMultiVector(),
193  dgdp_sg.getMultiVectorOrientation()));
194  }
195  else if (dgdp_sg_op != Teuchos::null) {
196  me_outargs.set_DgDp(i, j, Derivative(dgdp_sg_op));
197  }
198  }
199  }
200 
201  }
202 
203  // Compute the functions
204  me->evalModel(me_inargs, me_outargs);
205 
206 }
Teuchos::Array< Teuchos::RCP< const Epetra_Map > > base_g_maps
Base maps of block g vectors.
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.
SGInverseModelEvaluator(const Teuchos::RCP< EpetraExt::ModelEvaluator > &me, const Teuchos::Array< int > &sg_p_index_map, const Teuchos::Array< int > &sg_g_index_map, const Teuchos::Array< Teuchos::RCP< const Epetra_Map > > &base_g_maps)
Teuchos::RCP< EpetraExt::ModelEvaluator > me
Underlying model evaluator.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
OutArgs createOutArgs() const
Create OutArgs.
int num_g_sg
Number of stochastic response vectors.
int num_p_sg
Number of stochastic parameter vectors.
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on InArgs.
Teuchos::RCP< EpetraExt::BlockMultiVector > getBlockMultiVector()
Get block vector.
Teuchos::RCP< const Epetra_Map > get_f_map() const
Return residual vector map.
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.
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Return array of parameter names.