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 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #ifndef PANZER_MODEL_EVALUATOR_EPETRA_HPP
12 #define PANZER_MODEL_EVALUATOR_EPETRA_HPP
13 
15 
16 #include "Epetra_Map.h"
17 #include "Epetra_Vector.h"
18 #include "Epetra_Comm.h"
19 #include "Epetra_CrsGraph.h"
20 
21 #include "Teuchos_RCP.hpp"
22 #include "Teuchos_AbstractFactory.hpp"
23 
24 #include "Panzer_Traits.hpp"
30 
31 #include "Thyra_VectorBase.hpp"
32 
33 #include <tuple>
34 #include <vector>
35 #include <string>
36 
37 namespace panzer {
38 
39  class FieldManagerBuilder;
40  struct GlobalData;
41 
43  public:
44 
48  const std::vector<Teuchos::RCP<Teuchos::Array<std::string> > >& p_names,
49  const std::vector<Teuchos::RCP<Teuchos::Array<double> > >& p_values,
50  const Teuchos::RCP<panzer::GlobalData>& global_data,
51  bool build_transient_support);
52 
56  const std::vector<Teuchos::RCP<Teuchos::Array<std::string> > >& p_names,
57  const std::vector<Teuchos::RCP<Teuchos::Array<double> > >& p_values,
58  const Teuchos::RCP<panzer::GlobalData>& global_data,
59  bool build_transient_support);
60 
63 
68  double get_t_init() const;
74 
75  InArgs createInArgs() const;
76  OutArgs createOutArgs() const;
77  void evalModel( const InArgs& inArgs, const OutArgs& outArgs ) const;
78 
80 
82  void set_t_init(double t);
83 
86  { return responseLibrary_; }
87 
90 
118  int addDistributedParameter(const std::string name,
119  const Teuchos::RCP<Epetra_Map>& global_map,
120  const Teuchos::RCP<Epetra_Import>& importer,
121  const Teuchos::RCP<Epetra_Vector>& ghosted_vector);
122 
138  template <typename ResponseEvaluatorFactory_BuilderT>
139  int addResponse(const std::string & responseName,
140  const std::vector<WorksetDescriptor> & wkst_desc,
141  const ResponseEvaluatorFactory_BuilderT & builder);
142 
147  const std::vector<Teuchos::RCP<panzer::PhysicsBlock> >& physicsBlocks,
148  const panzer::EquationSetFactory & eqset_factory,
150  const Teuchos::ParameterList& closure_models,
151  const Teuchos::ParameterList& user_data,
152  const bool write_graphviz_file=false,
153  const std::string& graphviz_file_prefix="")
154  { responseLibrary_->buildResponseEvaluators(physicsBlocks,eqset_factory,cm_factory,closure_models,user_data,write_graphviz_file,graphviz_file_prefix); }
155 
160  const std::vector<Teuchos::RCP<panzer::PhysicsBlock> >& physicsBlocks,
162  const Teuchos::ParameterList& closure_models,
163  const Teuchos::ParameterList& user_data,
164  const bool write_graphviz_file=false,
165  const std::string& graphviz_file_prefix="")
166  { responseLibrary_->buildResponseEvaluators(physicsBlocks,cm_factory,closure_models,user_data,write_graphviz_file,graphviz_file_prefix); }
167 
169 
177  void setOneTimeDirichletBeta(const double & beta) const;
178 
183  const Teuchos::RCP<Thyra::VectorBase<double> > & f) const;
184 
185  private:
186 
187  // /////////////////////////////////////
188  // Private methods
189 
195 
197  void initializeParameterVector(const std::vector<Teuchos::RCP<Teuchos::Array<std::string> > >& p_names,
198  const std::vector<Teuchos::RCP<Teuchos::Array<double> > >& p_values,
199  const Teuchos::RCP<panzer::ParamLib>& parameter_library);
200 
201  // /////////////////////////////////////
202  // Private evaluation methods
203 
205  void evalModel_basic( const InArgs& inArgs, const OutArgs& outArgs ) const;
206 
212  void evalModel_basic_g(AssemblyEngineInArgs ae_inargs,const InArgs & inArgs,const OutArgs & outArgs) const;
213 
219  void evalModel_basic_dgdx(AssemblyEngineInArgs ae_inargs,const InArgs & inArgs,const OutArgs & outArgs) const;
220 
226  void evalModel_basic_dfdp(AssemblyEngineInArgs ae_inargs,const InArgs & inArgs,const OutArgs & outArgs) const;
227 
229  bool required_basic_g(const OutArgs & outArgs) const;
230 
232  bool required_basic_dgdx(const OutArgs & outArgs) const;
233 
235  bool required_basic_dfdp(const OutArgs & outArgs) const;
236 
237  void copyEpetraIntoThyra(const Epetra_MultiVector& x, const Teuchos::Ptr<Thyra::VectorBase<double> > &thyraVec) const;
238  void copyThyraIntoEpetra(const Thyra::VectorBase<double>& thyraVec, Epetra_MultiVector& x) const;
239 
240  // /////////////////////////////////////
241  // Private member data
242 
249  double t_init_;
251 
255  mutable panzer::AssemblyEngine_TemplateManager<panzer::Traits> ae_tm_; // they control and provide access to evaluate
256 
257  // responses
258  mutable Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > responseLibrary_; // These objects are basically the same
259  std::vector<Teuchos::RCP<const Epetra_Map> > g_map_;
260  std::vector<std::string> g_names_;
261 
262  // parameters
263  std::vector<Teuchos::RCP<Epetra_Map> > p_map_;
264  std::vector<Teuchos::RCP<Epetra_Vector> > p_init_;
265 
266  std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names_;
267  //Teuchos::RCP<panzer::ParamLib> parameter_library_;
271 
274  std::vector<bool> is_distributed_parameter_;
275 
283  std::vector<std::tuple<std::string,int,Teuchos::RCP<Epetra_Import>,Teuchos::RCP<Epetra_Vector> > > distributed_parameter_container_;
284 
285  // basic specific linear object objects
288 
290 
292  mutable double oneTimeDirichletBeta_;
293  };
294 
295  // Inline definition of the add response (its template on the builder type)
296  template <typename ResponseEvaluatorFactory_BuilderT>
298  addResponse(const std::string & responseName,
299  const std::vector<WorksetDescriptor> & wkst_desc,
300  const ResponseEvaluatorFactory_BuilderT & builder)
301  {
302  // see if the response evaluators have been constucted yet
303  TEUCHOS_TEST_FOR_EXCEPTION(responseLibrary_->responseEvaluatorsBuilt(),std::logic_error,
304  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
305  "cannot be added to the model evaluator because evalModel has already been called!");
306 
307  // add the response, and then push back its name for safe keeping
308  responseLibrary_->addResponse(responseName,wkst_desc,builder);
309 
310  // check that the response can be found
311  TEUCHOS_TEST_FOR_EXCEPTION(std::find(g_names_.begin(),g_names_.end(),responseName)!=g_names_.end(),std::logic_error,
312  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
313  "has already been added to the model evaluator!");
314 
315  // handle panzer::Traits::Residual
316  {
317  // check that at least there is a response value
319  TEUCHOS_TEST_FOR_EXCEPTION(respBase==Teuchos::null,std::logic_error,
320  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
321  "has no residual type! Not sure what is going on!");
322 
323  // check that the response supports interactions with the model evaluator
325  TEUCHOS_TEST_FOR_EXCEPTION(resp==Teuchos::null,std::logic_error,
326  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
327  "resulted in bad cast to panzer::ResponseMESupportBase<Residual>, the type of the response is incompatible!");
328 
329  // set the response in the model evaluator
330  Teuchos::RCP<const Epetra_Map> eMap = resp->getMap();
331  g_map_.push_back(eMap);
332 
333  // lets be cautious and set a vector on the response
334  resp->setVector(Teuchos::rcp(new Epetra_Vector(*eMap)));
335  }
336 
337  // handle panzer::Traits::Jacobian (do a quick safety check, response is null or appropriate for jacobian)
338  Teuchos::RCP<panzer::ResponseBase> respJacBase = responseLibrary_->getResponse<panzer::Traits::Jacobian>(responseName);
339  if(respJacBase!=Teuchos::null) {
340  typedef panzer::Traits::Jacobian RespEvalT;
341 
342  // check that the response supports interactions with the model evaluator
344  TEUCHOS_TEST_FOR_EXCEPTION(resp==Teuchos::null,std::logic_error,
345  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
346  "resulted in bad cast to panzer::ResponseMESupportBase<Jacobian>, the type of the response is incompatible!");
347 
348  // setup the vector (register response as epetra)
349  if(resp->supportsDerivative())
350  resp->setDerivative(resp->buildEpetraDerivative());
351  }
352 
353 #ifdef Panzer_BUILD_HESSIAN_SUPPORT
354  // handle panzer::Traits::Hessian (do a quick safety check, response is null or appropriate for jacobian)
355  Teuchos::RCP<panzer::ResponseBase> respHesBase = responseLibrary_->getResponse<panzer::Traits::Hessian>(responseName);
356  std::cout << "******************************************************" << std::endl;
357  std::cout << "EPETRA DOING IT " << respHesBase << std::endl;
358  std::cout << "******************************************************" << std::endl;
359  if(respHesBase!=Teuchos::null) {
360  typedef panzer::Traits::Hessian RespEvalT;
361 
362  // check that the response supports interactions with the model evaluator
364  TEUCHOS_TEST_FOR_EXCEPTION(resp==Teuchos::null,std::logic_error,
365  "panzer::ModelEvaluator_Epetra::addResponse: Response with name \"" << responseName << "\" "
366  "resulted in bad cast to panzer::ResponseMESupportBase<Hessian>, the type of the response is incompatible!");
367 
368  // setup the vector (register response as epetra)
369  if(resp->supportsDerivative())
370  resp->setDerivative(resp->buildDerivative());
371  }
372 #endif
373 
374  g_names_.push_back(responseName);
375 
376  return g_names_.size()-1;
377  }
378 
387  const std::vector<Teuchos::RCP<Teuchos::Array<std::string> > >& p_names,
388  const std::vector<Teuchos::RCP<Teuchos::Array<double> > >& p_values,
389  const Teuchos::RCP<panzer::GlobalData>& global_data,
390  bool build_transient_support);
391 
392 }
393 
394 #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