11 #include "PanzerDiscFE_config.hpp"
23 #include "Epetra_CrsMatrix.h"
24 #include "Epetra_MpiComm.h"
25 #include "Epetra_LocalMap.h"
31 #include "Thyra_EpetraOperatorWrapper.hpp"
32 #include "Thyra_EpetraThyraWrappers.hpp"
33 #include "Thyra_VectorStdOps.hpp"
34 #include "Thyra_ProductVectorBase.hpp"
35 #include "Thyra_SpmdVectorBase.hpp"
36 #include "Thyra_DefaultProductVector.hpp"
37 #include "Thyra_ProductVectorSpaceBase.hpp"
48 : W_graph_(lof.getGraph(0,0)) {}
64 bool build_transient_support)
67 , responseLibrary_(rLibrary)
69 , global_data_(global_data)
70 , build_transient_support_(build_transient_support)
72 , oneTimeDirichletBeta_on_(false)
73 , oneTimeDirichletBeta_(0.0)
76 using Teuchos::rcp_dynamic_cast;
79 ae_tm_.buildObjects(builder);
90 if(ep_lof!=Teuchos::null)
104 bool build_transient_support)
107 , responseLibrary_(rLibrary)
109 , global_data_(global_data)
110 , build_transient_support_(build_transient_support)
112 , oneTimeDirichletBeta_on_(false)
113 , oneTimeDirichletBeta_(0.0)
116 using Teuchos::rcp_dynamic_cast;
119 ae_tm_.buildObjects(builder);
132 using Teuchos::rcp_dynamic_cast;
135 "panzer::ModelEvaluator_Epetra::initializeEpetraObjs: The response library "
136 "was not correctly initialized before calling initializeEpetraObjs.");
141 x_dot_init_->PutScalar(0.0);
144 for (
int i=0; i < parameter_vector_.size(); i++) {
146 p_map_.push_back(local_map);
149 ep_vec->PutScalar(0.0);
151 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++)
152 (*ep_vec)[j] = parameter_vector_[i][j].baseValue;
154 p_init_.push_back(ep_vec);
158 epetraOperatorFactory_ =
Teuchos::rcp(
new EpetraLOF_EOpFactory(lof));
166 parameter_vector_.resize(p_names.size());
167 is_distributed_parameter_.resize(p_names.size(),
false);
169 p < p_names.
size(); ++p) {
172 for(
int i=0;i<p_names[p]->size();i++)
177 for(
int i=0;i<p_names[p]->size();i++) {
178 parameter_vector_[p][i].baseValue = (*p_values[p])[i];
179 parameter_vector_[p][i].family->setRealValueForAllTypes((*p_values[p])[i]);
193 int index =
static_cast<int>(p_map_.size());
195 p_map_.push_back(global_map);
197 ep_vec->PutScalar(0.0);
198 p_init_.push_back(ep_vec);
202 tmp_names->push_back(name);
203 p_names_.push_back(tmp_names);
205 is_distributed_parameter_.push_back(
true);
212 distributed_parameter_container_.push_back(std::make_tuple(name,index,importer,ghosted_vector));
252 return epetraOperatorFactory_->create();
285 if (build_transient_support_) {
291 inArgs.
set_Np(p_init_.size());
301 outArgs.
set_Np_Ng(p_init_.size(), g_map_.size());
306 DERIV_LINEARITY_NONCONST
313 for(std::size_t i=0;i<p_init_.size();i++) {
314 if(!is_distributed_parameter_[i])
319 for(std::size_t i=0;i<g_names_.size();i++) {
324 if(respJacBase!=Teuchos::null) {
329 if(resp->supportsDerivative())
346 using Teuchos::rcp_dynamic_cast;
350 ghostedContainer_ = lof_->buildGhostedLinearObjContainer();
356 ae_inargs.
container_ = lof_->buildLinearObjContainer();
358 ae_inargs.
alpha = 0.0;
359 ae_inargs.
beta = 1.0;
377 Thyra::assign(thGhostedContainer->get_f_th().
ptr(),0.0);
386 thGlobalContainer->set_x_th(x);
401 lof_->applyDirichletBCs(*counter,*result);
408 using Teuchos::rcp_dynamic_cast;
410 evalModel_basic(inArgs,outArgs);
417 using Teuchos::rcp_dynamic_cast;
422 bool has_x_dot =
false;
428 "ModelEvaluator was not built with transient support enabled!");
435 bool requiredResponses = required_basic_g(outArgs);
436 bool requiredSensitivities = required_basic_dfdp(outArgs);
440 !requiredResponses && !requiredSensitivities) {
449 ghostedContainer_ = lof_->buildGhostedLinearObjContainer();
463 ae_inargs.
container_ = lof_->buildLinearObjContainer();
465 ae_inargs.
alpha = 0.0;
466 ae_inargs.
beta = 1.0;
468 if (build_transient_support_) {
481 if(oneTimeDirichletBeta_on_) {
485 oneTimeDirichletBeta_on_ =
false;
489 for (
int i=0; i<inArgs.
Np(); i++) {
491 if (
nonnull(p) && !is_distributed_parameter_[i]) {
492 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++) {
493 parameter_vector_[i][j].baseValue = (*p)[j];
499 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++) {
500 parameter_vector_[i][j].family->setRealValueForAllTypes(parameter_vector_[i][j].baseValue);
506 distributed_parameter_container_.begin(); i != distributed_parameter_container_.end(); ++i) {
513 std::get<3>(*i)->Import(*global_vec,*importer,
Insert);
519 container->
set_x(std::get<3>(*i));
542 epGlobalContainer->
set_x(Teuchos::rcp_const_cast<Epetra_Vector>(x));
544 epGlobalContainer->
set_dxdt(Teuchos::rcp_const_cast<Epetra_Vector>(x_dot));
548 PANZER_FUNC_TIME_MONITOR(
"panzer::ModelEvaluator::evalModel(f and J)");
551 epGlobalContainer->
set_f(f_out);
552 epGlobalContainer->
set_A(Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W_out));
555 epGhostedContainer->
get_f()->PutScalar(0.0);
562 PANZER_FUNC_TIME_MONITOR(
"panzer::ModelEvaluator::evalModel(f)");
564 epGlobalContainer->
set_f(f_out);
567 epGhostedContainer->
get_f()->PutScalar(0.0);
571 f_out->Update(1.0, *(epGlobalContainer->
get_f()), 0.0);
575 PANZER_FUNC_TIME_MONITOR(
"panzer::ModelEvaluator::evalModel(J)");
580 epGlobalContainer->
set_f(dummy_f_);
581 epGlobalContainer->
set_A(Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W_out));
591 epGlobalContainer->
set_A(Teuchos::null);
594 if(requiredResponses) {
595 evalModel_basic_g(ae_inargs,inArgs,outArgs);
598 if(required_basic_dgdx(outArgs))
599 evalModel_basic_dgdx(ae_inargs,inArgs,outArgs);
602 if(required_basic_dfdp(outArgs))
603 evalModel_basic_dfdp(ae_inargs,inArgs,outArgs);
607 epGlobalContainer->
set_x(Teuchos::null);
608 epGlobalContainer->
set_dxdt(Teuchos::null);
609 epGlobalContainer->
set_f(Teuchos::null);
610 epGlobalContainer->
set_A(Teuchos::null);
624 for(std::size_t i=0;i<g_names_.size();i++) {
626 if(vec!=Teuchos::null) {
627 std::string responseName = g_names_[i];
630 resp->setVector(vec);
646 for(std::size_t i=0;i<g_names_.size();i++) {
654 if(vec!=Teuchos::null) {
655 std::string responseName = g_names_[i];
658 resp->setDerivative(vec);
672 using Teuchos::rcp_dynamic_cast;
679 std::vector<std::string> activeParameters;
682 int totalParameterCount = 0;
691 TEUCHOS_ASSERT(mVec->NumVectors()==int(parameter_vector_[i].size()));
693 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++) {
703 thGlobalContainer->set_f_th(Thyra::create_Vector(vec,glblVS));
706 std::string name =
"PARAMETER_SENSITIVIES: "+(*p_names_[i])[j];
710 activeParameters.push_back(name);
711 totalParameterCount++;
725 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++) {
733 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++) {
735 p.fastAccessDx(paramIndex) = 1.0;
745 if(totalParameterCount>0) {
753 bool activeGArgs =
false;
754 for(
int i=0;i<outArgs.
Ng();i++)
755 activeGArgs |= (outArgs.
get_g(i)!=Teuchos::null);
757 return activeGArgs | required_basic_dgdx(outArgs);
763 bool activeGArgs =
false;
764 for(
int i=0;i<outArgs.
Ng();i++) {
766 if(outArgs.
supports(OUT_ARG_DgDx,i).none())
779 bool activeFPArgs =
false;
780 for(
int i=0;i<outArgs.
Np();i++) {
782 if(outArgs.
supports(OUT_ARG_DfDp,i).none())
801 using Teuchos::rcpFromRef;
802 using Teuchos::rcp_dynamic_cast;
805 using Teuchos::rcp_dynamic_cast;
807 const int numVecs = x.NumVectors();
810 "epetraToThyra does not work with MV dimension != 1");
813 Thyra::castOrCreateProductVectorBase(rcpFromRef(thyraVec));
818 std::size_t offset = 0;
819 const int numBlocks = prodThyraVec->productSpace()->numBlocks();
820 for (
int b = 0; b < numBlocks; ++b) {
823 rcp_dynamic_cast<
const Thyra::SpmdVectorBase<double> >(vec_b,
true);
826 spmd_b->getLocalData(Teuchos::ptrFromRef(thyraData));
829 epetraData[i+offset] = thyraData[i];
831 offset += thyraData.
size();
842 using Teuchos::rcpFromPtr;
843 using Teuchos::rcp_dynamic_cast;
845 const int numVecs = x.NumVectors();
848 "ModelEvaluator_Epetra::copyEpetraToThyra does not work with MV dimension != 1");
851 Thyra::castOrCreateNonconstProductVectorBase(rcpFromPtr(thyraVec));
858 std::size_t offset = 0;
859 const int numBlocks = prodThyraVec->productSpace()->numBlocks();
860 for (
int b = 0; b < numBlocks; ++b) {
863 rcp_dynamic_cast<Thyra::SpmdVectorBase<double> >(vec_b,
true);
866 spmd_b->getNonconstLocalData(Teuchos::ptrFromRef(thyraData));
869 thyraData[i] = epetraData[i+offset];
871 offset += thyraData.
size();
884 bool build_transient_support)
887 using Teuchos::rcp_dynamic_cast;
890 std::stringstream ss;
891 ss <<
"panzer::buildEpetraME: Linear object factory is incorrect type. Should be one of: ";
897 if(ep_lof!=Teuchos::null)
900 ss <<
"\"BlockedEpetraLinearObjFactory\", ";
908 oneTimeDirichletBeta_on_ =
true;
909 oneTimeDirichletBeta_ = beta;
bool supports(EOutArgsMembers arg) const
void applyDirichletBCs(const Teuchos::RCP< Thyra::VectorBase< double > > &x, const Teuchos::RCP< Thyra::VectorBase< double > > &f) const
void set_W_properties(const DerivativeProperties &properties)
bool evaluate_transient_terms
Evaluation< Epetra_Vector > get_g(int j) const
void set_f(const Teuchos::RCP< Epetra_Vector > &in)
Teuchos::RCP< const Epetra_Vector > get_p_init(int l) const
Teuchos::RCP< const Epetra_Vector > get_x_init() const
Derivative get_DfDp(int l) const
void setSupports(EOutArgsMembers arg, bool supports=true)
OutArgs createOutArgs() const
Teuchos::RCP< panzer::ParamLib > pl
Sacado scalar parameter library.
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
bool is_null(const std::shared_ptr< T > &p)
Teuchos::RCP< Epetra_Operator > get_W() const
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< LinearObjContainer > getGlobalLOC() const
void setSupports(EInArgsMembers arg, bool supports=true)
void set_A(const Teuchos::RCP< Epetra_CrsMatrix > &in)
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
Teuchos::RCP< const Epetra_Vector > get_p(int l) const
Teuchos::RCP< panzer::LinearObjContainer > ghostedContainer_
bool required_basic_g(const OutArgs &outArgs) const
Are their required responses in the out args? g and DgDx.
Derivative get_DgDx(int j) const
const Teuchos::RCP< Epetra_CrsMatrix > get_A() const
double get_t_init() const
void set_t_init(double t)
Set initial time value.
void set_dxdt(const Teuchos::RCP< Epetra_Vector > &in)
Teuchos::RCP< LinearObjContainer > getGhostedLOC() const
int PutScalar(double ScalarConstant)
Teuchos::RCP< panzer::LinearObjContainer > container_
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)
void addGlobalEvaluationData(const std::string &key, const Teuchos::RCP< GlobalEvaluationData > &ged)
Teuchos::RCP< Epetra_MultiVector > getMultiVector() const
PHX::MDField< ScalarT, panzer::Cell, panzer::IP > result
A field that will be used to build up the result of the integral we're performing.
virtual const Teuchos::RCP< Epetra_Map > getMap(int i) const
get the map from the matrix
void setModelEvalDescription(const std::string &modelEvalDescription)
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< const Epetra_Vector > get_x_dot() const
bool supports(EInArgsMembers arg) const
InArgs createInArgs() const
const Teuchos::RCP< Epetra_Vector > get_f() const
void setModelEvalDescription(const std::string &modelEvalDescription)
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 > ¶meter_library)
panzer::AssemblyEngine_TemplateManager< panzer::Traits > ae_tm_
bool nonnull(const boost::shared_ptr< T > &p)
void evalModel(const InArgs &inArgs, const OutArgs &outArgs) const
void set_x(const Teuchos::RCP< Epetra_Vector > &in)
virtual obj_ptr_t create() const =0
bool required_basic_dfdp(const OutArgs &outArgs) const
Are derivatives of the residual with respect to the parameters in the out args? DfDp.
bool apply_dirichlet_beta
void evalModel_basic(const InArgs &inArgs, const OutArgs &outArgs) const
for evaluation and handling of normal quantities, x,f,W, etc
std::vector< Teuchos::RCP< Teuchos::Array< std::string > > > p_names_
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< const Epetra_Map > get_f_map() const
void evalModel_basic_g(AssemblyEngineInArgs ae_inargs, const InArgs &inArgs, const OutArgs &outArgs) const
Evaluation< Epetra_Vector > get_f() const
void copyEpetraIntoThyra(const Epetra_MultiVector &x, const Teuchos::Ptr< Thyra::VectorBase< double > > &thyraVec) const
void registerScalarParameter(const std::string name, panzer::ParamLib &pl, double realValue)
Teuchos::RCP< const Epetra_Vector > get_x() const
bool required_basic_dgdx(const OutArgs &outArgs) const
Are their required responses in the out args? DgDx.
void set_Np_Ng(int Np, int Ng)
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
void setOneTimeDirichletBeta(const double &beta) const