Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Stokhos_SGModelEvaluator.hpp
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 
42 #ifndef STOKHOS_SGMODELEVALUATOR_HPP
43 #define STOKHOS_SGMODELEVALUATOR_HPP
44 
45 #include <vector>
46 
47 #include "EpetraExt_ModelEvaluator.h"
48 #include "EpetraExt_MultiComm.h"
49 #include "EpetraExt_BlockVector.h"
50 
51 #include "Teuchos_RCP.hpp"
52 #include "Teuchos_Array.hpp"
53 #include "Teuchos_ParameterList.hpp"
54 #include "Stokhos_ParallelData.hpp"
60 #include "Stokhos_SGOperator.hpp"
63 
64 namespace Stokhos {
65 
67 
89  class SGModelEvaluator : public EpetraExt::ModelEvaluator {
90  public:
91 
92  // Constructor
94  const Teuchos::RCP<EpetraExt::ModelEvaluator>& me,
95  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> >& sg_basis,
96  const Teuchos::RCP<const Stokhos::Quadrature<int,double> >& sg_quad,
98  const Teuchos::RCP<const Stokhos::ParallelData>& sg_parallel_data,
99  const Teuchos::RCP<Teuchos::ParameterList>& params,
100  bool scaleOP = true);
101 
104 
106  Teuchos::RCP<const Epetra_Map> get_x_map() const;
107 
109  Teuchos::RCP<const Epetra_Map> get_f_map() const;
110 
112  Teuchos::RCP<const Epetra_Map> get_p_map(int l) const;
113 
115  Teuchos::RCP<const Epetra_Map> get_g_map(int l) const;
116 
118  Teuchos::RCP<const Teuchos::Array<std::string> >
119  get_p_names(int l) const;
120 
122  Teuchos::RCP<const Epetra_Vector> get_x_init() const;
123 
125  Teuchos::RCP<const Epetra_Vector> get_p_init(int l) const;
126 
128  Teuchos::RCP<Epetra_Operator> create_W() const;
129 
131  Teuchos::RCP<EpetraExt::ModelEvaluator::Preconditioner> create_WPrec() const;
132 
134  Teuchos::RCP<Epetra_Operator> create_DgDx_dot_op(int j) const;
135 
137  Teuchos::RCP<Epetra_Operator> create_DgDx_op(int j) const;
138 
140  Teuchos::RCP<Epetra_Operator> create_DgDp_op(int j, int i) const;
141 
143  Teuchos::RCP<Epetra_Operator> create_DfDp_op(int i) const;
144 
146  InArgs createInArgs() const;
147 
149  OutArgs createOutArgs() const;
150 
152  void evalModel(const InArgs& inArgs, const OutArgs& outArgs) const;
153 
155 
157  void set_x_sg_init(const Stokhos::EpetraVectorOrthogPoly& x_sg_in);
158 
160  Teuchos::RCP<const Stokhos::EpetraVectorOrthogPoly> get_x_sg_init() const;
161 
163  void set_p_sg_init(int i, const Stokhos::EpetraVectorOrthogPoly& p_sg_in);
164 
166  Teuchos::RCP<const Stokhos::EpetraVectorOrthogPoly> get_p_sg_init(int l) const;
167 
169 
172  Teuchos::Array<int> get_p_sg_map_indices() const;
173 
175 
178  Teuchos::Array<int> get_g_sg_map_indices() const;
179 
181  Teuchos::Array< Teuchos::RCP<const Epetra_Map> > get_g_sg_base_maps() const;
182 
184  Teuchos::RCP<const Epetra_BlockMap> get_overlap_stochastic_map() const;
185 
187  Teuchos::RCP<const Epetra_BlockMap> get_x_sg_overlap_map() const;
188 
190  Teuchos::RCP<const Epetra_Import> get_x_sg_importer() const;
191 
193  Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly>
194  create_x_sg(Epetra_DataAccess CV = Copy,
195  const Epetra_Vector* v = NULL) const;
196 
198  Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly>
199  create_x_sg_overlap(Epetra_DataAccess CV = Copy,
200  const Epetra_Vector* v = NULL) const;
201 
203  Teuchos::RCP<Stokhos::EpetraMultiVectorOrthogPoly>
204  create_x_mv_sg(int num_vecs,
205  Epetra_DataAccess CV = Copy,
206  const Epetra_MultiVector* v = NULL) const;
207 
209  Teuchos::RCP<Stokhos::EpetraMultiVectorOrthogPoly>
210  create_x_mv_sg_overlap(int num_vecs,
211  Epetra_DataAccess CV = Copy,
212  const Epetra_MultiVector* v = NULL) const;
213 
215  Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly>
216  create_p_sg(int l, Epetra_DataAccess CV = Copy,
217  const Epetra_Vector* v = NULL) const;
218 
220  Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly>
221  create_f_sg(Epetra_DataAccess CV = Copy,
222  const Epetra_Vector* v = NULL) const;
223 
225  Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly>
226  create_f_sg_overlap(Epetra_DataAccess CV = Copy,
227  const Epetra_Vector* v = NULL) const;
228 
230  Teuchos::RCP<Stokhos::EpetraMultiVectorOrthogPoly>
231  create_f_mv_sg(int num_vecs, Epetra_DataAccess CV = Copy,
232  const Epetra_MultiVector* v = NULL) const;
233 
235  Teuchos::RCP<Stokhos::EpetraMultiVectorOrthogPoly>
236  create_f_mv_sg_overlap(int num_vecs, Epetra_DataAccess CV = Copy,
237  const Epetra_MultiVector* v = NULL) const;
238 
240  Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly>
241  create_g_sg(int l, Epetra_DataAccess CV = Copy,
242  const Epetra_Vector* v = NULL) const;
243 
245  Teuchos::RCP<Stokhos::EpetraMultiVectorOrthogPoly>
246  create_g_mv_sg(int l, int num_vecs, Epetra_DataAccess CV = Copy,
247  const Epetra_MultiVector* v = NULL) const;
248 
250  Teuchos::RCP<EpetraExt::BlockVector>
251  import_solution(const Epetra_Vector& x) const;
252 
254  Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly>
255  import_solution_poly(const Epetra_Vector& x) const;
256 
258  Teuchos::RCP<EpetraExt::BlockVector>
259  export_solution(const Epetra_Vector& x_overlapped) const;
260 
262  Teuchos::RCP<EpetraExt::BlockVector>
263  import_residual(const Epetra_Vector& f) const;
264 
266  Teuchos::RCP<EpetraExt::BlockVector>
267  export_residual(const Epetra_Vector& f_overlapped) const;
268 
269  protected:
270 
272  Teuchos::RCP<EpetraExt::ModelEvaluator> me;
273 
275  Teuchos::RCP<const Stokhos::OrthogPolyBasis<int, double> > sg_basis;
276 
278  Teuchos::RCP<const Stokhos::Quadrature<int,double> > sg_quad;
279 
281  Teuchos::RCP<Stokhos::OrthogPolyExpansion<int,double> > sg_exp;
282 
284  Teuchos::RCP<Teuchos::ParameterList> params;
285 
287  unsigned int num_sg_blocks;
288 
290  unsigned int num_W_blocks;
291 
293  unsigned int num_p_blocks;
294 
297 
299  Teuchos::RCP<const Epetra_Map> x_map;
300 
302  Teuchos::RCP<const Epetra_Map> f_map;
303 
305  Teuchos::RCP<const Stokhos::ParallelData> sg_parallel_data;
306 
308  Teuchos::RCP<const EpetraExt::MultiComm> sg_comm;
309 
311  Teuchos::RCP<const Stokhos::EpetraSparse3Tensor> epetraCijk;
312 
314  Teuchos::RCP<const Stokhos::EpetraSparse3Tensor> serialCijk;
315 
317  Teuchos::RCP<const Epetra_BlockMap> stoch_row_map;
318 
320  Teuchos::RCP<const Epetra_BlockMap> overlapped_stoch_row_map;
321 
323  Teuchos::RCP<const Epetra_BlockMap> overlapped_stoch_p_map;
324 
326  Teuchos::RCP<const Epetra_Map> sg_x_map;
327 
329  Teuchos::RCP<const Epetra_Map> sg_overlapped_x_map;
330 
332  Teuchos::RCP<const Epetra_Map> sg_f_map;
333 
335  Teuchos::RCP<const Epetra_Map> sg_overlapped_f_map;
336 
338  Teuchos::RCP<Epetra_Import> sg_overlapped_x_importer;
339 
341  Teuchos::RCP<Epetra_Export> sg_overlapped_f_exporter;
342 
344  int num_p;
345 
347  int num_p_sg;
348 
350  Teuchos::Array<int> sg_p_index_map;
351 
353  Teuchos::Array< Teuchos::RCP<const Epetra_Map> > sg_p_map;
354 
356  Teuchos::Array< Teuchos::RCP< Teuchos::Array<std::string> > > sg_p_names;
357 
359  int num_g;
360 
362  int num_g_sg;
363 
365  Teuchos::Array<int> sg_g_index_map;
366 
368  Teuchos::Array< Teuchos::RCP<const Epetra_Map> > sg_g_map;
369 
371  Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > x_dot_sg_blocks;
372 
374  Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > x_sg_blocks;
375 
377  mutable Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > f_sg_blocks;
378 
380  mutable Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > W_sg_blocks;
381 
383  Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly> sg_x_init;
384 
386  Teuchos::Array< Teuchos::RCP<Stokhos::EpetraVectorOrthogPoly> > sg_p_init;
387 
390 
392  mutable Teuchos::RCP<Stokhos::SGOperator> my_W;
393 
395  mutable Teuchos::RCP<Epetra_Vector> my_x;
396 
397  bool scaleOP;
398 
400  Teuchos::RCP< Stokhos::SGPreconditionerFactory > sg_prec_factory;
401 
402  };
403 
404 }
405 
406 #endif // FEAPP_MODELEVALUATOR_HPP
Teuchos::RCP< const Stokhos::EpetraSparse3Tensor > epetraCijk
Epetra Cijk.
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > import_solution_poly(const Epetra_Vector &x) const
Import parallel solution vector.
Teuchos::RCP< EpetraExt::BlockVector > import_residual(const Epetra_Vector &f) const
Import parallel residual vector.
Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > W_sg_blocks
W stochastic Galerkin components.
Teuchos::RCP< const Epetra_Map > sg_overlapped_f_map
Block SG overlapped residual map.
Teuchos::RCP< const Epetra_Vector > get_x_init() const
Return initial solution.
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > sg_x_init
SG initial x.
Teuchos::Array< int > sg_g_index_map
Index map between block-g and g_sg maps.
unsigned int num_sg_blocks
Number of stochastic blocks.
Teuchos::RCP< const Epetra_Map > x_map
Underlying unknown map.
Teuchos::RCP< const Stokhos::EpetraVectorOrthogPoly > get_p_sg_init(int l) const
Return initial SG parameters.
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > x_sg_blocks
x stochastic Galerkin components
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > f_sg_blocks
f stochastic Galerkin components
int num_p_sg
Number of stochastic parameter vectors.
bool eval_W_with_f
Whether to always evaluate W with f.
Teuchos::RCP< const Epetra_Map > sg_overlapped_x_map
Block SG overlapped unknown map.
SGModelEvaluator(const Teuchos::RCP< EpetraExt::ModelEvaluator > &me, const Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > &sg_basis, const Teuchos::RCP< const Stokhos::Quadrature< int, double > > &sg_quad, const Teuchos::RCP< Stokhos::OrthogPolyExpansion< int, double > > &sg_exp, const Teuchos::RCP< const Stokhos::ParallelData > &sg_parallel_data, const Teuchos::RCP< Teuchos::ParameterList > &params, bool scaleOP=true)
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Evaluate model on InArgs.
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.
Teuchos::Array< Teuchos::RCP< const Epetra_Map > > sg_g_map
Block SG response map.
Teuchos::RCP< Stokhos::EpetraMultiVectorOrthogPoly > create_f_mv_sg(int num_vecs, Epetra_DataAccess CV=Copy, const Epetra_MultiVector *v=NULL) const
Create multi-vector orthog poly using f map and owned sg map.
Teuchos::RCP< const Epetra_BlockMap > get_overlap_stochastic_map() const
Return overlap stochastic map.
Teuchos::RCP< EpetraExt::ModelEvaluator::Preconditioner > create_WPrec() const
Create preconditioner operator.
unsigned int num_p_blocks
Number of p stochastic blocks (may be smaller than num_sg_blocks)
Teuchos::RCP< const Epetra_Map > get_f_map() const
Return residual vector map.
Teuchos::RCP< Stokhos::EpetraMultiVectorOrthogPoly > create_g_mv_sg(int l, int num_vecs, Epetra_DataAccess CV=Copy, const Epetra_MultiVector *v=NULL) const
Create multi-vector orthog poly using g map.
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > create_g_sg(int l, Epetra_DataAccess CV=Copy, const Epetra_Vector *v=NULL) const
Create vector orthog poly using g map.
Teuchos::RCP< const Stokhos::ParallelData > sg_parallel_data
Parallel SG data.
Teuchos::RCP< const Epetra_BlockMap > overlapped_stoch_p_map
Overlapped map for p stochastic blocks (local map)
Teuchos::RCP< const Stokhos::EpetraVectorOrthogPoly > get_x_sg_init() const
Return initial SG x.
Nonlinear, stochastic Galerkin ModelEvaluator.
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > create_p_sg(int l, Epetra_DataAccess CV=Copy, const Epetra_Vector *v=NULL) const
Create vector orthog poly using p map.
Teuchos::Array< Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > > sg_p_init
SG initial p.
Teuchos::RCP< const Stokhos::EpetraSparse3Tensor > serialCijk
Serial Epetra Cijk for dgdx*.
Teuchos::RCP< Epetra_Operator > create_DfDp_op(int i) const
Create SG operator representing df/dp.
Teuchos::RCP< const Epetra_Map > sg_f_map
Block SG residual map.
Abstract base class for orthogonal polynomial-based expansions.
Teuchos::RCP< const Epetra_Map > get_x_map() const
Return solution vector map.
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > create_f_sg(Epetra_DataAccess CV=Copy, const Epetra_Vector *v=NULL) const
Create vector orthog poly using f map and owned sg map.
Teuchos::RCP< const Epetra_BlockMap > get_x_sg_overlap_map() const
Return x sg overlap map.
Teuchos::RCP< Stokhos::EpetraMultiVectorOrthogPoly > create_f_mv_sg_overlap(int num_vecs, Epetra_DataAccess CV=Copy, const Epetra_MultiVector *v=NULL) const
Create multi-vector orthog poly using f map and overlap sg map.
int num_g_sg
Number of stochastic response vectors.
Teuchos::RCP< const Epetra_BlockMap > stoch_row_map
Map for stochastic blocks.
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > x_dot_sg_blocks
x_dot stochastic Galerkin components
Teuchos::Array< Teuchos::RCP< const Epetra_Map > > get_g_sg_base_maps() const
Get base maps of SG responses.
Abstract base class for quadrature methods.
Teuchos::RCP< Stokhos::SGPreconditionerFactory > sg_prec_factory
Preconditioner factory.
Teuchos::RCP< Stokhos::EpetraMultiVectorOrthogPoly > create_x_mv_sg_overlap(int num_vecs, Epetra_DataAccess CV=Copy, const Epetra_MultiVector *v=NULL) const
Create vector orthog poly using x map and overlap sg map.
Teuchos::RCP< Epetra_Operator > create_DgDx_dot_op(int j) const
Create SG operator representing dg/dxdot.
A container class storing an orthogonal polynomial whose coefficients are vectors, operators, or in general any type that would have an expensive copy constructor.
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Return initial parameters.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > sg_basis
Stochastic Galerkin basis.
Top-level namespace for Stokhos classes and functions.
Teuchos::RCP< EpetraExt::BlockVector > import_solution(const Epetra_Vector &x) const
Import parallel solution vector.
Teuchos::Array< Teuchos::RCP< const Epetra_Map > > sg_p_map
Block SG parameter map.
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > create_x_sg(Epetra_DataAccess CV=Copy, const Epetra_Vector *v=NULL) const
Create vector orthog poly using x map and owned sg map.
bool supports_x
Whether we support x (and thus f and W)
void set_p_sg_init(int i, const Stokhos::EpetraVectorOrthogPoly &p_sg_in)
Set initial parameter polynomial.
Teuchos::RCP< Stokhos::SGOperator > my_W
W pointer for evaluating W with f.
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Return array of parameter names.
Teuchos::RCP< Epetra_Export > sg_overlapped_f_exporter
Exporter from SG-overlapped to SG maps.
expr expr expr expr j
Teuchos::RCP< EpetraExt::BlockVector > export_residual(const Epetra_Vector &f_overlapped) const
Export parallel residual vector.
Teuchos::RCP< EpetraExt::BlockVector > export_solution(const Epetra_Vector &x_overlapped) const
Export parallel solution vector.
Teuchos::Array< Teuchos::RCP< Teuchos::Array< std::string > > > sg_p_names
SG coefficient parameter names.
Teuchos::RCP< EpetraExt::ModelEvaluator > me
Underlying model evaluator.
unsigned int num_W_blocks
Number of W stochastic blocks (may be smaller than num_sg_blocks)
OutArgs createOutArgs() const
Create OutArgs.
void set_x_sg_init(const Stokhos::EpetraVectorOrthogPoly &x_sg_in)
Set initial solution polynomial.
InArgs createInArgs() const
Create InArgs.
Teuchos::Array< int > get_p_sg_map_indices() const
Get indices of SG parameters.
Teuchos::RCP< Epetra_Operator > create_DgDp_op(int j, int i) const
Create SG operator representing dg/dp.
Teuchos::RCP< const Epetra_BlockMap > overlapped_stoch_row_map
Overlapped map for stochastic blocks (local map)
ScalarType f(const Teuchos::Array< ScalarType > &x, double a, double b)
int num_g
Number of response vectors of underlying model evaluator.
int num_p
Number of parameter vectors of underlying model evaluator.
Teuchos::RCP< Epetra_Import > sg_overlapped_x_importer
Importer from SG to SG-overlapped maps.
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > create_f_sg_overlap(Epetra_DataAccess CV=Copy, const Epetra_Vector *v=NULL) const
Create vector orthog poly using f map and overlap sg map.
Teuchos::RCP< Stokhos::EpetraMultiVectorOrthogPoly > create_x_mv_sg(int num_vecs, Epetra_DataAccess CV=Copy, const Epetra_MultiVector *v=NULL) const
Create vector orthog poly using x map and owned sg map.
Teuchos::RCP< const Epetra_Import > get_x_sg_importer() const
Return x sg importer.
Teuchos::RCP< Epetra_Operator > create_W() const
Create W = alpha*M + beta*J matrix.
Teuchos::RCP< Epetra_Vector > my_x
x pointer for evaluating preconditioner
Teuchos::RCP< Teuchos::ParameterList > params
Algorithmic parameters.
Teuchos::Array< int > sg_p_index_map
Index map between block-p and p_sg maps.
Teuchos::RCP< const Epetra_Map > f_map
Underlying residual map.
Teuchos::RCP< Stokhos::EpetraVectorOrthogPoly > create_x_sg_overlap(Epetra_DataAccess CV=Copy, const Epetra_Vector *v=NULL) const
Create vector orthog poly using x map and overlap sg map.
Teuchos::RCP< Epetra_Operator > create_DgDx_op(int j) const
Create SG operator representing dg/dx.
Teuchos::RCP< Stokhos::OrthogPolyExpansion< int, double > > sg_exp
Stochastic Galerkin expansion.
Teuchos::Array< int > get_g_sg_map_indices() const
Get indices of SG responses.
Teuchos::RCP< const Stokhos::Quadrature< int, double > > sg_quad
Stochastic Galerkin quadrature.
Teuchos::RCP< const Epetra_Map > sg_x_map
Block SG unknown map.
Teuchos::RCP< const EpetraExt::MultiComm > sg_comm
Parallel SG communicator.