Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_ModelEvaluator_Epetra.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
43 #ifndef PANZER_MODEL_EVALUATOR_EPETRA_HPP
44 #define PANZER_MODEL_EVALUATOR_EPETRA_HPP
45 
47 
48 #include "Epetra_Map.h"
49 #include "Epetra_Vector.h"
50 #include "Epetra_Comm.h"
51 #include "Epetra_CrsGraph.h"
52 
53 #include "Teuchos_RCP.hpp"
54 #include "Teuchos_AbstractFactory.hpp"
55 
56 #include "Panzer_Traits.hpp"
62 
63 #include "Thyra_VectorBase.hpp"
64 
65 #include <tuple>
66 #include <vector>
67 #include <string>
68 
69 namespace panzer {
70 
71  class FieldManagerBuilder;
72  struct GlobalData;
73 
75  public:
76 
80  const std::vector<Teuchos::RCP<Teuchos::Array<std::string> > >& p_names,
81  const std::vector<Teuchos::RCP<Teuchos::Array<double> > >& p_values,
82  const Teuchos::RCP<panzer::GlobalData>& global_data,
83  bool build_transient_support);
84 
88  const std::vector<Teuchos::RCP<Teuchos::Array<std::string> > >& p_names,
89  const std::vector<Teuchos::RCP<Teuchos::Array<double> > >& p_values,
90  const Teuchos::RCP<panzer::GlobalData>& global_data,
91  bool build_transient_support);
92 
95 
100  double get_t_init() const;
106 
107  InArgs createInArgs() const;
108  OutArgs createOutArgs() const;
109  void evalModel( const InArgs& inArgs, const OutArgs& outArgs ) const;
110 
112 
114  void set_t_init(double t);
115 
118  { return responseLibrary_; }
119 
122 
150  int addDistributedParameter(const std::string name,
151  const Teuchos::RCP<Epetra_Map>& global_map,
152  const Teuchos::RCP<Epetra_Import>& importer,
153  const Teuchos::RCP<Epetra_Vector>& ghosted_vector);
154 
170  template <typename ResponseEvaluatorFactory_BuilderT>
171  int addResponse(const std::string & responseName,
172  const std::vector<WorksetDescriptor> & wkst_desc,
173  const ResponseEvaluatorFactory_BuilderT & builder);
174 
179  const std::vector<Teuchos::RCP<panzer::PhysicsBlock> >& physicsBlocks,
180  const panzer::EquationSetFactory & eqset_factory,
182  const Teuchos::ParameterList& closure_models,
183  const Teuchos::ParameterList& user_data,
184  const bool write_graphviz_file=false,
185  const std::string& graphviz_file_prefix="")
186  { responseLibrary_->buildResponseEvaluators(physicsBlocks,eqset_factory,cm_factory,closure_models,user_data,write_graphviz_file,graphviz_file_prefix); }
187 
192  const std::vector<Teuchos::RCP<panzer::PhysicsBlock> >& physicsBlocks,
194  const Teuchos::ParameterList& closure_models,
195  const Teuchos::ParameterList& user_data,
196  const bool write_graphviz_file=false,
197  const std::string& graphviz_file_prefix="")
198  { responseLibrary_->buildResponseEvaluators(physicsBlocks,cm_factory,closure_models,user_data,write_graphviz_file,graphviz_file_prefix); }
199 
201 
209  void setOneTimeDirichletBeta(const double & beta) const;
210 
215  const Teuchos::RCP<Thyra::VectorBase<double> > & f) const;
216 
217  private:
218 
219  // /////////////////////////////////////
220  // Private methods
221 
227 
229  void initializeParameterVector(const std::vector<Teuchos::RCP<Teuchos::Array<std::string> > >& p_names,
230  const std::vector<Teuchos::RCP<Teuchos::Array<double> > >& p_values,
231  const Teuchos::RCP<panzer::ParamLib>& parameter_library);
232 
233  // /////////////////////////////////////
234  // Private evaluation methods
235 
237  void evalModel_basic( const InArgs& inArgs, const OutArgs& outArgs ) const;
238 
244  void evalModel_basic_g(AssemblyEngineInArgs ae_inargs,const InArgs & inArgs,const OutArgs & outArgs) const;
245 
251  void evalModel_basic_dgdx(AssemblyEngineInArgs ae_inargs,const InArgs & inArgs,const OutArgs & outArgs) const;
252 
258  void evalModel_basic_dfdp(AssemblyEngineInArgs ae_inargs,const InArgs & inArgs,const OutArgs & outArgs) const;
259 
261  bool required_basic_g(const OutArgs & outArgs) const;
262 
264  bool required_basic_dgdx(const OutArgs & outArgs) const;
265 
267  bool required_basic_dfdp(const OutArgs & outArgs) const;
268 
269  void copyEpetraIntoThyra(const Epetra_MultiVector& x, const Teuchos::Ptr<Thyra::VectorBase<double> > &thyraVec) const;
270  void copyThyraIntoEpetra(const Thyra::VectorBase<double>& thyraVec, Epetra_MultiVector& x) const;
271 
272  // /////////////////////////////////////
273  // Private member data
274 
281  double t_init_;
283 
287  mutable panzer::AssemblyEngine_TemplateManager<panzer::Traits> ae_tm_; // they control and provide access to evaluate
288 
289  // responses
290  mutable Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > responseLibrary_; // These objects are basically the same
291  std::vector<Teuchos::RCP<const Epetra_Map> > g_map_;
292  std::vector<std::string> g_names_;
293 
294  // parameters
295  std::vector<Teuchos::RCP<Epetra_Map> > p_map_;
296  std::vector<Teuchos::RCP<Epetra_Vector> > p_init_;
297 
298  std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names_;
299  //Teuchos::RCP<panzer::ParamLib> parameter_library_;
303 
306  std::vector<bool> is_distributed_parameter_;
307 
315  std::vector<std::tuple<std::string,int,Teuchos::RCP<Epetra_Import>,Teuchos::RCP<Epetra_Vector> > > distributed_parameter_container_;
316 
317  // basic specific linear object objects
320 
322 
324  mutable double oneTimeDirichletBeta_;
325  };
326 
327  // Inline definition of the add response (its template on the builder type)
328  template <typename ResponseEvaluatorFactory_BuilderT>
330  addResponse(const std::string & responseName,
331  const std::vector<WorksetDescriptor> & wkst_desc,
332  const ResponseEvaluatorFactory_BuilderT & builder)
333  {
334  // see if the response evaluators have been constucted yet
335  TEUCHOS_TEST_FOR_EXCEPTION(responseLibrary_->responseEvaluatorsBuilt(),std::logic_error,
336  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
337  "cannot be added to the model evaluator because evalModel has already been called!");
338 
339  // add the response, and then push back its name for safe keeping
340  responseLibrary_->addResponse(responseName,wkst_desc,builder);
341 
342  // check that the response can be found
343  TEUCHOS_TEST_FOR_EXCEPTION(std::find(g_names_.begin(),g_names_.end(),responseName)!=g_names_.end(),std::logic_error,
344  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
345  "has already been added to the model evaluator!");
346 
347  // handle panzer::Traits::Residual
348  {
349  // check that at least there is a response value
351  TEUCHOS_TEST_FOR_EXCEPTION(respBase==Teuchos::null,std::logic_error,
352  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
353  "has no residual type! Not sure what is going on!");
354 
355  // check that the response supports interactions with the model evaluator
357  TEUCHOS_TEST_FOR_EXCEPTION(resp==Teuchos::null,std::logic_error,
358  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
359  "resulted in bad cast to panzer::ResponseMESupportBase<Residual>, the type of the response is incompatible!");
360 
361  // set the response in the model evaluator
362  Teuchos::RCP<const Epetra_Map> eMap = resp->getMap();
363  g_map_.push_back(eMap);
364 
365  // lets be cautious and set a vector on the response
366  resp->setVector(Teuchos::rcp(new Epetra_Vector(*eMap)));
367  }
368 
369  // handle panzer::Traits::Jacobian (do a quick safety check, response is null or appropriate for jacobian)
370  Teuchos::RCP<panzer::ResponseBase> respJacBase = responseLibrary_->getResponse<panzer::Traits::Jacobian>(responseName);
371  if(respJacBase!=Teuchos::null) {
372  typedef panzer::Traits::Jacobian RespEvalT;
373 
374  // check that the response supports interactions with the model evaluator
376  TEUCHOS_TEST_FOR_EXCEPTION(resp==Teuchos::null,std::logic_error,
377  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
378  "resulted in bad cast to panzer::ResponseMESupportBase<Jacobian>, the type of the response is incompatible!");
379 
380  // setup the vector (register response as epetra)
381  if(resp->supportsDerivative())
382  resp->setDerivative(resp->buildEpetraDerivative());
383  }
384 
385 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
386  // handle panzer::Traits::Hessian (do a quick safety check, response is null or appropriate for jacobian)
387  Teuchos::RCP<panzer::ResponseBase> respHesBase = responseLibrary_->getResponse<panzer::Traits::Hessian>(responseName);
388  std::cout << "******************************************************" << std::endl;
389  std::cout << "EPETRA DOING IT " << respHesBase << std::endl;
390  std::cout << "******************************************************" << std::endl;
391  if(respHesBase!=Teuchos::null) {
392  typedef panzer::Traits::Hessian RespEvalT;
393 
394  // check that the response supports interactions with the model evaluator
396  TEUCHOS_TEST_FOR_EXCEPTION(resp==Teuchos::null,std::logic_error,
397  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
398  "resulted in bad cast to panzer::ResponseMESupportBase<Hessian>, the type of the response is incompatible!");
399 
400  // setup the vector (register response as epetra)
401  if(resp->supportsDerivative())
402  resp->setDerivative(resp->buildDerivative());
403  }
404 #endif
405 
406  g_names_.push_back(responseName);
407 
408  return g_names_.size()-1;
409  }
410 
419  const std::vector<Teuchos::RCP<Teuchos::Array<std::string> > >& p_names,
420  const std::vector<Teuchos::RCP<Teuchos::Array<double> > >& p_values,
421  const Teuchos::RCP<panzer::GlobalData>& global_data,
422  bool build_transient_support);
423 
424 }
425 
426 #endif
int addResponse(const std::string &responseName, const std::vector< WorksetDescriptor > &wkst_desc, const ResponseEvaluatorFactory_BuilderT &builder)
void applyDirichletBCs(const Teuchos::RCP< Thyra::VectorBase< double > > &x, const Teuchos::RCP< Thyra::VectorBase< double > > &f) const
void buildResponses(const std::vector< Teuchos::RCP< panzer::PhysicsBlock > > &physicsBlocks, const panzer::ClosureModelFactory_TemplateManager< panzer::Traits > &cm_factory, const Teuchos::ParameterList &closure_models, const Teuchos::ParameterList &user_data, const bool write_graphviz_file=false, const std::string &graphviz_file_prefix="")
Allocates and initializes an equation set template manager.
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Teuchos::RCP< const Epetra_Vector > get_x_init() const
void copyThyraIntoEpetra(const Thyra::VectorBase< double > &thyraVec, Epetra_MultiVector &x) const
Teuchos::RCP< ModelEvaluator_Epetra > buildEpetraME(const Teuchos::RCP< FieldManagerBuilder > &fmb, const Teuchos::RCP< ResponseLibrary< panzer::Traits > > &rLibrary, const Teuchos::RCP< LinearObjFactory< panzer::Traits > > &lof, const std::vector< Teuchos::RCP< Teuchos::Array< std::string > > > &p_names, const std::vector< Teuchos::RCP< Teuchos::Array< double > > > &p_values, const Teuchos::RCP< panzer::GlobalData > &global_data, bool build_transient_support)
Teuchos::RCP< const Epetra_Vector > get_x_dot_init() const
Teuchos::RCP< const Epetra_Map > get_p_map(int l) const
Teuchos::RCP< Epetra_Operator > create_W() const
Teuchos::RCP< Epetra_Vector > x_dot_init_
void initializeEpetraObjs(panzer::BlockedEpetraLinearObjFactory< panzer::Traits, int > &lof)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< const Epetra_Map > get_g_map(int l) const
Teuchos::RCP< panzer::LinearObjFactory< panzer::Traits > > lof_
void evalModel_basic_dfdp(AssemblyEngineInArgs ae_inargs, const InArgs &inArgs, const OutArgs &outArgs) const
void evalModel_basic_dgdx(AssemblyEngineInArgs ae_inargs, const InArgs &inArgs, const OutArgs &outArgs) const
bool required_basic_g(const OutArgs &outArgs) const
Are their required responses in the out args? g and DgDx.
Teuchos::RCP< panzer::GlobalData > global_data_
Teuchos::RCP< LinearObjContainer > ghostedContainer_
Teuchos::RCP< Teuchos::AbstractFactory< Epetra_Operator > > epetraOperatorFactory_
void set_t_init(double t)
Set initial time value.
ModelEvaluator_Epetra(const Teuchos::RCP< panzer::FieldManagerBuilder > &fmb, const Teuchos::RCP< panzer::ResponseLibrary< panzer::Traits > > &rLibrary, const Teuchos::RCP< panzer::LinearObjFactory< panzer::Traits > > &lof, const std::vector< Teuchos::RCP< Teuchos::Array< std::string > > > &p_names, const std::vector< Teuchos::RCP< Teuchos::Array< double > > > &p_values, const Teuchos::RCP< panzer::GlobalData > &global_data, bool build_transient_support)
std::vector< Teuchos::RCP< const Epetra_Map > > g_map_
void buildResponses(const std::vector< Teuchos::RCP< panzer::PhysicsBlock > > &physicsBlocks, const panzer::EquationSetFactory &eqset_factory, const panzer::ClosureModelFactory_TemplateManager< panzer::Traits > &cm_factory, const Teuchos::ParameterList &closure_models, const Teuchos::ParameterList &user_data, const bool write_graphviz_file=false, const std::string &graphviz_file_prefix="")
Teuchos::RCP< Epetra_Vector > dummy_f_
Teuchos::RCP< const Epetra_Map > get_x_map() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
int addDistributedParameter(const std::string name, const Teuchos::RCP< Epetra_Map > &global_map, const Teuchos::RCP< Epetra_Import > &importer, const Teuchos::RCP< Epetra_Vector > &ghosted_vector)
Teuchos::RCP< panzer::ResponseLibrary< panzer::Traits > > getResponseLibrary() const
Get the response library used by this evaluator.
void initializeParameterVector(const std::vector< Teuchos::RCP< Teuchos::Array< std::string > > > &p_names, const std::vector< Teuchos::RCP< Teuchos::Array< double > > > &p_values, const Teuchos::RCP< panzer::ParamLib > &parameter_library)
panzer::AssemblyEngine_TemplateManager< panzer::Traits > ae_tm_
Teuchos::RCP< const Epetra_Map > map_x_
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
Teuchos::RCP< panzer::ResponseLibrary< panzer::Traits > > responseLibrary_
bool required_basic_dfdp(const OutArgs &outArgs) const
Are derivatives of the residual with respect to the parameters in the out args? DfDp.
std::vector< Teuchos::RCP< Epetra_Vector > > p_init_
std::vector< std::tuple< std::string, int, Teuchos::RCP< Epetra_Import >, Teuchos::RCP< Epetra_Vector > > > distributed_parameter_container_
void evalModel_basic(const InArgs &inArgs, const OutArgs &outArgs) const
for evaluation and handling of normal quantities, x,f,W, etc
Teuchos::Array< panzer::ParamVec > parameter_vector_
std::vector< Teuchos::RCP< Teuchos::Array< std::string > > > p_names_
Teuchos::RCP< panzer::FieldManagerBuilder > fmb_
Teuchos::RCP< const Epetra_Map > get_f_map() const
void evalModel_basic_g(AssemblyEngineInArgs ae_inargs, const InArgs &inArgs, const OutArgs &outArgs) const
void copyEpetraIntoThyra(const Epetra_MultiVector &x, const Teuchos::Ptr< Thyra::VectorBase< double > > &thyraVec) const
bool required_basic_dgdx(const OutArgs &outArgs) const
Are their required responses in the out args? DgDx.
std::vector< Teuchos::RCP< Epetra_Map > > p_map_
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
void setOneTimeDirichletBeta(const double &beta) const