Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_MPInverseModelEvaluator.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
43 
44 #include "Teuchos_Assert.hpp"
48 #include "Epetra_Map.h"
49 
52  const Teuchos::Array<int>& mp_p_index_map_,
53  const Teuchos::Array<int>& mp_g_index_map_,
54  const Teuchos::Array< Teuchos::RCP<const Epetra_Map> >& base_g_maps_) :
55  me(me_),
56  mp_p_index_map(mp_p_index_map_),
57  mp_g_index_map(mp_g_index_map_),
58  base_g_maps(base_g_maps_),
59  num_p(0),
60  num_g(0),
61  num_p_mp(mp_p_index_map.size()),
62  num_g_mp(mp_g_index_map.size())
63 {
64  InArgs me_inargs = me->createInArgs();
65  OutArgs me_outargs = me->createOutArgs();
66  num_p = me_inargs.Np() - num_p_mp;
67  num_g = me_outargs.Ng();
68 
70  base_g_maps.size() != num_g_mp, std::logic_error,
71  std::endl
72  << "Error! Stokhos::MPInverseModelEvaluator::MPInverseModelEvaluator():"
73  << " Base response map array size does not match size of index array!");
74 }
75 
76 // Overridden from EpetraExt::ModelEvaluator
77 
80 get_x_map() const
81 {
82  return Teuchos::null;
83 }
84 
87 get_f_map() const
88 {
89  return Teuchos::null;
90 }
91 
94 get_p_map(int l) const
95 {
97  l >= num_p || l < 0, std::logic_error,
98  std::endl << "Error! Stokhos::MPInverseModelEvaluator::get_p_map():"
99  << " Invalid parameter index l = " << l << std::endl);
100  return me->get_p_map(l);
101 }
102 
105 get_g_map(int l) const
106 {
108  l >= num_g || l < 0, std::logic_error,
109  std::endl << "Error! Stokhos::MPInverseModelEvaluator::get_g_map():"
110  << " Invalid response index l = " << l << std::endl);
111  return base_g_maps[l];
112 }
113 
116 get_p_names(int l) const
117 {
119  l >= num_p || l < 0, std::logic_error,
120  std::endl << "Error! Stokhos::MPInverseModelEvaluator::get_p_names():"
121  << " Invalid parameter index l = " << l << std::endl);
122  return me->get_p_names(l);
123 }
124 
127 get_p_init(int l) const
128 {
130  l >= num_p || l < 0, std::logic_error,
131  std::endl << "Error! Stokhos::MPInverseModelEvaluator::get_p_init():"
132  << " Invalid parameter index l = " << l << std::endl);
133  return me->get_p_init(l);
134 }
135 
136 EpetraExt::ModelEvaluator::InArgs
138 {
139  InArgsSetup inArgs;
140  InArgs me_inargs = me->createInArgs();
141 
142  inArgs.setModelEvalDescription(this->description());
143  inArgs.set_Np(num_p);
144  for (int i=0; i<num_p_mp; i++)
145  inArgs.setSupports(IN_ARG_p_mp, mp_p_index_map[i], true);
146 
147  return inArgs;
148 }
149 
150 EpetraExt::ModelEvaluator::OutArgs
152 {
153  OutArgsSetup outArgs;
154  OutArgs me_outargs = me->createOutArgs();
155 
156  outArgs.setModelEvalDescription(this->description());
157 
158  outArgs.set_Np_Ng(num_p, num_g);
159  for (int i=0; i<num_g_mp; i++) {
160  outArgs.setSupports(OUT_ARG_g_mp, mp_g_index_map[i], true);
161  for (int j=0; j<num_p; j++)
162  outArgs.setSupports(OUT_ARG_DgDp_mp, mp_g_index_map[i], j,
163  me_outargs.supports(OUT_ARG_DgDp,i,j));
164  }
165 
166  return outArgs;
167 }
168 
169 void
171  const OutArgs& outArgs) const
172 {
173  // Create underlying inargs
174  InArgs me_inargs = me->createInArgs();
175 
176  // Pass parameters
177  for (int i=0; i<num_p; i++)
178  me_inargs.set_p(i, inArgs.get_p(i));
179 
180  // Pass MP parameters
181  for (int i=0; i<num_p_mp; i++) {
182  mp_const_vector_t p_mp = inArgs.get_p_mp(mp_p_index_map[i]);
183  if (p_mp != Teuchos::null) {
184  me_inargs.set_p(i+num_p, p_mp->getBlockVector());
185  }
186  }
187 
188  // Create underlying outargs
189  OutArgs me_outargs = me->createOutArgs();
190 
191 
192  // MP Responses
193  for (int i=0; i<num_g_mp; i++) {
194  int ii = mp_g_index_map[i];
195 
196  // g
197  mp_vector_t g_mp = outArgs.get_g_mp(ii);
198  if (g_mp != Teuchos::null) {
199  me_outargs.set_g(i, Teuchos::rcp_dynamic_cast<Epetra_Vector>(g_mp->getBlockVector()));
200  }
201 
202  // dg/dp
203  for (int j=0; j<num_p; j++) {
204  if (!outArgs.supports(OUT_ARG_DgDp_mp, ii, j).none()) {
205  MPDerivative dgdp_mp = outArgs.get_DgDp_mp(ii,j);
207  dgdp_mp.getMultiVector();
208  Teuchos::RCP<Epetra_Operator> dgdp_mp_op =
209  dgdp_mp.getLinearOp();
210  if (dgdp_mp_mv != Teuchos::null) {
211  me_outargs.set_DgDp(
212  i, j, Derivative(dgdp_mp_mv->getBlockMultiVector(),
213  dgdp_mp.getMultiVectorOrientation()));
214  }
215  else if (dgdp_mp_op != Teuchos::null) {
216  me_outargs.set_DgDp(i, j, Derivative(dgdp_mp_op));
217  }
218  }
219  }
220 
221  }
222 
223  // Compute the functions
224  me->evalModel(me_inargs, me_outargs);
225 
226 }
OutArgs createOutArgs() const
Create OutArgs.
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on InArgs.
int num_g_mp
Number of multi-point response vectors.
MPInverseModelEvaluator(const Teuchos::RCP< EpetraExt::ModelEvaluator > &me, const Teuchos::Array< int > &mp_p_index_map, const Teuchos::Array< int > &mp_g_index_map, const Teuchos::Array< Teuchos::RCP< const Epetra_Map > > &base_g_maps)
int num_p_mp
Number of multi-point parameter vectors.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const Epetra_Map > get_f_map() const
Return residual vector map.
Teuchos::Array< Teuchos::RCP< const Epetra_Map > > base_g_maps
Base maps of block g vectors.
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
Teuchos::RCP< EpetraExt::BlockMultiVector > getBlockMultiVector()
Get block vector.
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Return initial parameters.
Teuchos::RCP< EpetraExt::ModelEvaluator > me
Underlying model evaluator.
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Return array of parameter names.
Teuchos::RCP< const Epetra_Map > get_g_map(int l) const
Return response map.
Teuchos::RCP< const Epetra_Map > get_p_map(int l) const
Return parameter vector map.