43 #include "PanzerDiscFE_config.hpp"
55 #include "Epetra_CrsMatrix.h"
56 #include "Epetra_MpiComm.h"
57 #include "Epetra_LocalMap.h"
63 #include "Thyra_EpetraOperatorWrapper.hpp"
64 #include "Thyra_EpetraThyraWrappers.hpp"
65 #include "Thyra_VectorStdOps.hpp"
66 #include "Thyra_ProductVectorBase.hpp"
67 #include "Thyra_SpmdVectorBase.hpp"
68 #include "Thyra_DefaultProductVector.hpp"
69 #include "Thyra_ProductVectorSpaceBase.hpp"
80 : W_graph_(lof.getGraph(0,0)) {}
96 bool build_transient_support)
99 , responseLibrary_(rLibrary)
101 , global_data_(global_data)
102 , build_transient_support_(build_transient_support)
104 , oneTimeDirichletBeta_on_(false)
105 , oneTimeDirichletBeta_(0.0)
108 using Teuchos::rcp_dynamic_cast;
111 ae_tm_.buildObjects(builder);
122 if(ep_lof!=Teuchos::null)
136 bool build_transient_support)
139 , responseLibrary_(rLibrary)
141 , global_data_(global_data)
142 , build_transient_support_(build_transient_support)
144 , oneTimeDirichletBeta_on_(false)
145 , oneTimeDirichletBeta_(0.0)
148 using Teuchos::rcp_dynamic_cast;
151 ae_tm_.buildObjects(builder);
164 using Teuchos::rcp_dynamic_cast;
167 "panzer::ModelEvaluator_Epetra::initializeEpetraObjs: The response library "
168 "was not correctly initialized before calling initializeEpetraObjs.");
173 x_dot_init_->PutScalar(0.0);
176 for (
int i=0; i < parameter_vector_.size(); i++) {
178 p_map_.push_back(local_map);
181 ep_vec->PutScalar(0.0);
183 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++)
184 (*ep_vec)[j] = parameter_vector_[i][j].baseValue;
186 p_init_.push_back(ep_vec);
190 epetraOperatorFactory_ =
Teuchos::rcp(
new EpetraLOF_EOpFactory(lof));
198 parameter_vector_.resize(p_names.size());
199 is_distributed_parameter_.resize(p_names.size(),
false);
201 p < p_names.
size(); ++p) {
204 for(
int i=0;i<p_names[p]->size();i++)
209 for(
int i=0;i<p_names[p]->size();i++) {
210 parameter_vector_[p][i].baseValue = (*p_values[p])[i];
211 parameter_vector_[p][i].family->setRealValueForAllTypes((*p_values[p])[i]);
225 int index =
static_cast<int>(p_map_.size());
227 p_map_.push_back(global_map);
229 ep_vec->PutScalar(0.0);
230 p_init_.push_back(ep_vec);
234 tmp_names->push_back(name);
235 p_names_.push_back(tmp_names);
237 is_distributed_parameter_.push_back(
true);
244 distributed_parameter_container_.push_back(std::make_tuple(name,index,importer,ghosted_vector));
284 return epetraOperatorFactory_->create();
317 if (build_transient_support_) {
323 inArgs.
set_Np(p_init_.size());
333 outArgs.
set_Np_Ng(p_init_.size(), g_map_.size());
338 DERIV_LINEARITY_NONCONST
345 for(std::size_t i=0;i<p_init_.size();i++) {
346 if(!is_distributed_parameter_[i])
351 for(std::size_t i=0;i<g_names_.size();i++) {
356 if(respJacBase!=Teuchos::null) {
361 if(resp->supportsDerivative())
378 using Teuchos::rcp_dynamic_cast;
382 ghostedContainer_ = lof_->buildGhostedLinearObjContainer();
388 ae_inargs.
container_ = lof_->buildLinearObjContainer();
390 ae_inargs.
alpha = 0.0;
391 ae_inargs.
beta = 1.0;
409 Thyra::assign(thGhostedContainer->get_f_th().
ptr(),0.0);
418 thGlobalContainer->set_x_th(x);
433 lof_->applyDirichletBCs(*counter,*result);
440 using Teuchos::rcp_dynamic_cast;
442 evalModel_basic(inArgs,outArgs);
449 using Teuchos::rcp_dynamic_cast;
454 bool has_x_dot =
false;
460 "ModelEvaluator was not built with transient support enabled!");
467 bool requiredResponses = required_basic_g(outArgs);
468 bool requiredSensitivities = required_basic_dfdp(outArgs);
472 !requiredResponses && !requiredSensitivities) {
481 ghostedContainer_ = lof_->buildGhostedLinearObjContainer();
495 ae_inargs.
container_ = lof_->buildLinearObjContainer();
497 ae_inargs.
alpha = 0.0;
498 ae_inargs.
beta = 1.0;
500 if (build_transient_support_) {
513 if(oneTimeDirichletBeta_on_) {
517 oneTimeDirichletBeta_on_ =
false;
521 for (
int i=0; i<inArgs.
Np(); i++) {
523 if (
nonnull(p) && !is_distributed_parameter_[i]) {
524 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++) {
525 parameter_vector_[i][j].baseValue = (*p)[j];
531 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++) {
532 parameter_vector_[i][j].family->setRealValueForAllTypes(parameter_vector_[i][j].baseValue);
538 distributed_parameter_container_.begin(); i != distributed_parameter_container_.end(); ++i) {
545 std::get<3>(*i)->Import(*global_vec,*importer,
Insert);
551 container->
set_x(std::get<3>(*i));
574 epGlobalContainer->
set_x(Teuchos::rcp_const_cast<Epetra_Vector>(x));
576 epGlobalContainer->
set_dxdt(Teuchos::rcp_const_cast<Epetra_Vector>(x_dot));
580 PANZER_FUNC_TIME_MONITOR(
"panzer::ModelEvaluator::evalModel(f and J)");
583 epGlobalContainer->
set_f(f_out);
584 epGlobalContainer->
set_A(Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W_out));
587 epGhostedContainer->
get_f()->PutScalar(0.0);
594 PANZER_FUNC_TIME_MONITOR(
"panzer::ModelEvaluator::evalModel(f)");
596 epGlobalContainer->
set_f(f_out);
599 epGhostedContainer->
get_f()->PutScalar(0.0);
603 f_out->Update(1.0, *(epGlobalContainer->
get_f()), 0.0);
607 PANZER_FUNC_TIME_MONITOR(
"panzer::ModelEvaluator::evalModel(J)");
612 epGlobalContainer->
set_f(dummy_f_);
613 epGlobalContainer->
set_A(Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W_out));
623 epGlobalContainer->
set_A(Teuchos::null);
626 if(requiredResponses) {
627 evalModel_basic_g(ae_inargs,inArgs,outArgs);
630 if(required_basic_dgdx(outArgs))
631 evalModel_basic_dgdx(ae_inargs,inArgs,outArgs);
634 if(required_basic_dfdp(outArgs))
635 evalModel_basic_dfdp(ae_inargs,inArgs,outArgs);
641 epGlobalContainer->
set_x(Teuchos::null);
642 epGlobalContainer->
set_dxdt(Teuchos::null);
643 epGlobalContainer->
set_f(Teuchos::null);
644 epGlobalContainer->
set_A(Teuchos::null);
658 for(std::size_t i=0;i<g_names_.size();i++) {
660 if(vec!=Teuchos::null) {
661 std::string responseName = g_names_[i];
664 resp->setVector(vec);
680 for(std::size_t i=0;i<g_names_.size();i++) {
688 if(vec!=Teuchos::null) {
689 std::string responseName = g_names_[i];
692 resp->setDerivative(vec);
706 using Teuchos::rcp_dynamic_cast;
713 std::vector<std::string> activeParameters;
716 int totalParameterCount = 0;
725 TEUCHOS_ASSERT(mVec->NumVectors()==int(parameter_vector_[i].size()));
727 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++) {
737 thGlobalContainer->set_f_th(Thyra::create_Vector(vec,glblVS));
740 std::string name =
"PARAMETER_SENSITIVIES: "+(*p_names_[i])[j];
744 activeParameters.push_back(name);
745 totalParameterCount++;
759 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++) {
767 for (
unsigned int j=0; j < parameter_vector_[i].size(); j++) {
769 p.fastAccessDx(paramIndex) = 1.0;
779 if(totalParameterCount>0) {
787 bool activeGArgs =
false;
788 for(
int i=0;i<outArgs.
Ng();i++)
789 activeGArgs |= (outArgs.
get_g(i)!=Teuchos::null);
791 return activeGArgs | required_basic_dgdx(outArgs);
797 bool activeGArgs =
false;
798 for(
int i=0;i<outArgs.
Ng();i++) {
800 if(outArgs.
supports(OUT_ARG_DgDx,i).none())
813 bool activeFPArgs =
false;
814 for(
int i=0;i<outArgs.
Np();i++) {
816 if(outArgs.
supports(OUT_ARG_DfDp,i).none())
835 using Teuchos::rcpFromRef;
836 using Teuchos::rcp_dynamic_cast;
839 using Teuchos::rcp_dynamic_cast;
841 const int numVecs = x.NumVectors();
844 "epetraToThyra does not work with MV dimension != 1");
847 Thyra::castOrCreateProductVectorBase(rcpFromRef(thyraVec));
852 std::size_t offset = 0;
853 const int numBlocks = prodThyraVec->productSpace()->numBlocks();
854 for (
int b = 0; b < numBlocks; ++b) {
857 rcp_dynamic_cast<
const Thyra::SpmdVectorBase<double> >(vec_b,
true);
860 spmd_b->getLocalData(Teuchos::ptrFromRef(thyraData));
863 epetraData[i+offset] = thyraData[i];
865 offset += thyraData.
size();
876 using Teuchos::rcpFromPtr;
877 using Teuchos::rcp_dynamic_cast;
879 const int numVecs = x.NumVectors();
882 "ModelEvaluator_Epetra::copyEpetraToThyra does not work with MV dimension != 1");
885 Thyra::castOrCreateNonconstProductVectorBase(rcpFromPtr(thyraVec));
892 std::size_t offset = 0;
893 const int numBlocks = prodThyraVec->productSpace()->numBlocks();
894 for (
int b = 0; b < numBlocks; ++b) {
897 rcp_dynamic_cast<Thyra::SpmdVectorBase<double> >(vec_b,
true);
900 spmd_b->getNonconstLocalData(Teuchos::ptrFromRef(thyraData));
903 thyraData[i] = epetraData[i+offset];
905 offset += thyraData.
size();
918 bool build_transient_support)
921 using Teuchos::rcp_dynamic_cast;
924 std::stringstream ss;
925 ss <<
"panzer::buildEpetraME: Linear object factory is incorrect type. Should be one of: ";
931 if(ep_lof!=Teuchos::null)
934 ss <<
"\"BlockedEpetraLinearObjFactory\", ";
942 oneTimeDirichletBeta_on_ =
true;
943 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