46 #include "Teuchos_DefaultComm.hpp"
47 #include "Teuchos_CommHelpers.hpp"
51 #include "Teuchos_FancyOStream.hpp"
52 #include "Teuchos_oblackholestream.hpp"
53 #include "Teuchos_Assert.hpp"
58 #include "Phalanx_KokkosUtilities.hpp"
67 #ifdef Panzer_BUILD_PAPI_SUPPORT
71 #include "user_app_ClosureModel_Factory_TemplateBuilder.hpp"
72 #include "user_app_EquationSetFactory.hpp"
73 #include "user_app_BCStrategy_Factory.hpp"
78 #include <Ioss_SerializeIO.h>
83 int main(
int argc,
char *argv[])
85 PHX::InitializeKokkosDevice();
99 #ifdef Panzer_BUILD_PAPI_SUPPORT
101 papi_counter.
start();
114 std::string input_file_name =
"user_app.xml";
115 int exodus_io_num_procs = 0;
116 bool pauseToAttachOn =
false;
117 bool fluxCalculation =
false;
121 clp.
setOption(
"i", &input_file_name,
"User_App input xml filename");
122 clp.
setOption(
"exodus-io-num-procs", &exodus_io_num_procs,
"Number of processes that can access the file system at the same time to read their portion of a sliced exodus file in parallel. Defaults to 0 - implies all processes for the run can access the file system at the same time.");
123 clp.
setOption(
"pause-to-attach",
"disable-pause-to-attach", &pauseToAttachOn,
"Call pause to attach, default is off.");
124 clp.
setOption(
"flux-calc",
"disable-flux-calc", &fluxCalculation,
"Enable the flux calculation.");
127 clp.
parse(argc,argv,&std::cerr);
130 std::runtime_error,
"Failed to parse command line!");
137 if (exodus_io_num_procs != 0)
138 Ioss::SerializeIO::setGroupFactor(exodus_io_num_procs);
142 Teuchos::updateParametersFromXmlFileAndBroadcast(input_file_name, input_params.
ptr(), *
comm);
144 *out << *input_params << std::endl;
147 input_params->
remove(
"Solver Factories");
153 user_app::MyModelFactory_TemplateBuilder cm_builder;
155 cm_factory.buildObjects(cm_builder);
158 user_app::BCFactory bc_factory;
164 input_params->
sublist(
"User Data").
set(
"Comm", comm);
168 input_params->
remove(
"Responses");
176 std::vector<Teuchos::RCP<panzer::PhysicsBlock> > physicsBlocks;
178 std::map<int,std::string> responseIndexToName;
183 me_factory.
buildObjects(comm,global_data,eqset_factory,bc_factory,cm_factory);
187 const std::string name = responses.
name(itr);
194 builder.
comm = MPI_COMM_WORLD;
195 builder.cubatureDegree = 2;
196 builder.requiresCellIntegral = lst.isType<
bool>(
"Requires Cell Integral") ? lst.get<
bool>(
"Requires Cell Integral"):
false;
197 builder.quadPointField = lst.get<std::string>(
"Field Name");
200 std::vector<std::string> eblocks;
203 std::vector<panzer::WorksetDescriptor> wkst_descs;
204 for(std::size_t i=0;i<eblocks.size();i++)
207 int respIndex = me_factory.
addResponse(name,wkst_descs,builder);
208 responseIndexToName[respIndex] = name;
223 bool useCoordinateUpdate =
false;
224 for(std::size_t p=0;p<physicsBlocks.size();p++) {
225 if(physicsBlocks[p]->getCoordinateDOFs().size()>0) {
226 useCoordinateUpdate =
true;
244 Teuchos::parameterList(solver_factories.
sublist(
"NOX Observers"));
259 stkIOResponseLibrary->initialize(*rLibrary);
266 user_data.
set<
int>(
"Workset Size",input_params->
sublist(
"Assembly").
get<
int>(
"Workset Size"));
268 stkIOResponseLibrary->buildResponseEvaluators(physicsBlocks,
270 input_params->
sublist(
"Closure Models"),
280 if(fluxCalculation) {
281 fluxResponseLibrary->initialize(*rLibrary);
286 builder.
comm = MPI_COMM_WORLD;
289 std::vector<panzer::WorksetDescriptor> sidesets;
292 fluxResponseLibrary->addResponse(
"HO-Flux",sidesets,builder);
297 user_data.
set<
int>(
"Workset Size",input_params->
sublist(
"Assembly").
get<
int>(
"Workset Size"));
299 fluxResponseLibrary->buildResponseEvaluators(physicsBlocks,
302 input_params->
sublist(
"Closure Models"),
312 resp->setVector(vec);
322 Thyra::ModelEvaluatorBase::InArgs<double> inArgs = solver->createInArgs();
323 const Thyra::ModelEvaluatorBase::InArgs<double> inArgsNominal = solver->getNominalValues();
326 Thyra::ModelEvaluatorBase::OutArgs<double> outArgs = solver->createOutArgs();
330 for(
int i=0;i<outArgs.Ng()-1;i++)
331 outArgs.set_g(i,Teuchos::null);
332 outArgs.set_g(outArgs.Ng()-1,gx);
335 solver->evalModel(inArgs, outArgs);
339 if(physics->Ng()>0) {
341 Thyra::ModelEvaluatorBase::InArgs<double> respInArgs = physics->createInArgs();
342 Thyra::ModelEvaluatorBase::OutArgs<double> respOutArgs = physics->createOutArgs();
346 respInArgs.set_x(gx);
349 for(
int i=0;i<respOutArgs.Ng();i++) {
351 respOutArgs.set_g(i,response);
355 physics->evalModel(respInArgs, respOutArgs);
358 for(
int i=0;i<respOutArgs.Ng();i++) {
363 *out <<
"Response Value \"" << responseIndexToName[i] <<
"\": " << *response << std::endl;
367 if(fluxCalculation) {
370 ae_inargs.
container_ = linObjFactory->buildLinearObjContainer();
372 ae_inargs.
alpha = 0.0;
373 ae_inargs.
beta = 1.0;
388 *out <<
"\nFlux values: \n";
390 std::string currentRespName =
"HO-Flux";
395 *out <<
" " << currentRespName <<
" = " << resp->value << std::endl;
400 catch (std::exception& e) {
401 *out <<
"*********** Caught Exception: Begin Error Report ***********" << std::endl;
402 *out << e.what() << std::endl;
403 *out <<
"************ Caught Exception: End Error Report ************" << std::endl;
406 catch (std::string& msg) {
407 *out <<
"*********** Caught Exception: Begin Error Report ***********" << std::endl;
408 *out << msg << std::endl;
409 *out <<
"************ Caught Exception: End Error Report ************" << std::endl;
413 *out <<
"*********** Caught Exception: Begin Error Report ***********" << std::endl;
414 *out <<
"Caught UNKOWN exception" << std::endl;
415 *out <<
"************ Caught Exception: End Error Report ************" << std::endl;
421 #ifdef Panzer_BUILD_PAPI_SUPPORT
423 papi_counter.report(std::cout);
427 *out <<
"panzer::MainDriver run completed." << std::endl;
429 PHX::FinalizeKokkosDevice();
const std::string & name() const
bool evaluate_transient_terms
ConstIterator end() const
int addResponse(const std::string &responseName, const std::vector< panzer::WorksetDescriptor > &wkstDesc, const BuilderT &builder)
basic_FancyOStream & setShowProcRank(const bool showProcRank)
T & get(const std::string &name, T def_value)
virtual void set_x_th(const Teuchos::RCP< Thyra::VectorBase< double > > &in)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
void buildObjects(const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< panzer::GlobalData > &global_data, const Teuchos::RCP< const panzer::EquationSetFactory > &eqset_factory, const panzer::BCStrategyFactory &bc_factory, const panzer::ClosureModelFactory_TemplateManager< panzer::Traits > &cm_factory, bool meConstructionOn=true)
Builds the model evaluators for a panzer assembly.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void buildResponses(const panzer::ClosureModelFactory_TemplateManager< panzer::Traits > &cm_factory, const bool write_graphviz_file=false, const std::string &graphviz_file_prefix="")
Teuchos::RCP< panzer::GlobalData > createGlobalData(bool build_default_os, int print_process)
static Teuchos::RCP< const Comm< OrdinalType > > getComm()
Teuchos::RCP< panzer::LinearObjContainer > ghostedContainer_
Teuchos::RCP< panzer::GlobalData > global_data
const std::vector< Teuchos::RCP< panzer::PhysicsBlock > > & getPhysicsBlocks() const
static RCP< Time > getNewTimer(const std::string &name)
Teuchos::RCP< panzer::LinearObjFactory< panzer::Traits > > getLinearObjFactory() const
Get linear object factory used to build model evaluator.
Teuchos::RCP< panzer::LinearObjContainer > container_
bool remove(std::string const &name, bool throwIfNotExists=true)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static void summarize(Ptr< const Comm< int > > comm, std::ostream &out=std::cout, const bool alwaysWriteLocal=false, const bool writeGlobalStats=true, const bool writeZeroTimers=true, const ECounterSetOp setOp=Intersection, const std::string &filter="", const bool ignoreZeroTimers=false)
Teuchos::RCP< Thyra::ModelEvaluator< ScalarT > > buildResponseOnlyModelEvaluator(const Teuchos::RCP< Thyra::ModelEvaluator< ScalarT > > &thyra_me, const Teuchos::RCP< panzer::GlobalData > &global_data, const Teuchos::RCP< Piro::RythmosSolver< ScalarT > > rythmosSolver=Teuchos::null, const Teuchos::Ptr< const panzer_stk_classic::NOXObserverFactory > &in_nox_observer_factory=Teuchos::null, const Teuchos::Ptr< const panzer_stk_classic::RythmosObserverFactory > &in_rythmos_observer_factory=Teuchos::null)
void setOption(const char option_true[], const char option_false[], bool *option_val, const char documentation[]=NULL)
WorksetDescriptor sidesetVolumeDescriptor(const std::string &eBlock, const std::string &sideset)
params_t::ConstIterator ConstIterator
EParseCommandLineReturn parse(int argc, char *argv[], std::ostream *errout=&std::cerr) const
ConstIterator begin() const
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
const ParameterEntry & entry(ConstIterator i) const
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
Teuchos::RCP< const Teuchos::Comm< int > > comm
void pauseToAttach(MPI_Comm mpicomm)
WorksetDescriptor blockDescriptor(const std::string &eBlock)
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
void StringTokenizer(std::vector< std::string > &tokens, const std::string &str, const std::string delimiters, bool trim)
Tokenize a string, put tokens in a vector.
int main(int argc, char *argv[])
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< Thyra::ModelEvaluator< ScalarT > > getPhysicsModelEvaluator()
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const ¶mList)
Teuchos::RCP< panzer::ResponseLibrary< panzer::Traits > > getResponseLibrary()