40 #include "libmesh/dof_map.h" 
   41 #include "libmesh/parameter_vector.h" 
   42 #include "libmesh/qoi_set.h" 
   43 #include "libmesh/sensitivity_data.h" 
   49                           SimulationBuilder& sim_builder,
 
   50                           const libMesh::Parallel::Communicator &comm )
 
   51     :  _mesh( sim_builder.build_mesh(input, comm) ),
 
   52        _equation_system( new 
libMesh::EquationSystems( *_mesh ) ),
 
   53        _solver( sim_builder.build_solver(input) ),
 
   54        _system_name( input(
"screen-options/system_name", 
"GRINS" ) ),
 
   55        _multiphysics_system( &(_equation_system->add_system<MultiphysicsSystem>( _system_name )) ),
 
   56        _vis( sim_builder.build_vis(input, comm) ),
 
   57        _postprocessing( sim_builder.build_postprocessing(input) ),
 
   58        _print_mesh_info( input(
"screen-options/print_mesh_info", false ) ),
 
   59        _print_log_info( input(
"screen-options/print_log_info", false ) ),
 
   60        _print_equation_system_info( input(
"screen-options/print_equation_system_info", false ) ),
 
   61        _print_qoi( input(
"screen-options/print_qoi", false ) ),
 
   62        _print_scalars( input(
"screen-options/print_scalars", false ) ),
 
   63        _output_vis( input(
"vis-options/output_vis", false ) ),
 
   64        _output_adjoint( input(
"vis-options/output_adjoint", false ) ),
 
   65        _output_residual( input( 
"vis-options/output_residual", false ) ),
 
   66        _output_residual_sensitivities( input( 
"vis-options/output_residual_sensitivities", false ) ),
 
   67        _output_solution_sensitivities( input( 
"vis-options/output_solution_sensitivities", false ) ),
 
   68        _timesteps_per_vis( input(
"vis-options/timesteps_per_vis", 1 ) ),
 
   69        _timesteps_per_perflog( input(
"screen-options/timesteps_per_perflog", 0 ) ),
 
   70        _error_estimator_options(input),
 
   72        _do_adjoint_solve(false), 
 
   77     this->init_multiphysics_system(input);
 
   79     this->init_qois(input,sim_builder);
 
   81     this->init_params(input,sim_builder);
 
   83     this->init_adjoint_solve(input,_output_adjoint);
 
   86     this->build_error_estimator(input);
 
   89         this->init_restart(input,sim_builder,comm);
 
   91     this->check_for_unused_vars(input, 
false );
 
   97                           SimulationBuilder& sim_builder,
 
   98                           const libMesh::Parallel::Communicator &comm )
 
   99     :  _mesh( sim_builder.build_mesh(input, comm) ),
 
  100        _equation_system( new 
libMesh::EquationSystems( *_mesh ) ),
 
  101        _solver( sim_builder.build_solver(input) ),
 
  102        _system_name( input(
"screen-options/system_name", 
"GRINS" ) ),
 
  103        _multiphysics_system( &(_equation_system->add_system<MultiphysicsSystem>( _system_name )) ),
 
  104        _vis( sim_builder.build_vis(input, comm) ),
 
  105        _postprocessing( sim_builder.build_postprocessing(input) ),
 
  106        _print_mesh_info( input(
"screen-options/print_mesh_info", false ) ),
 
  107        _print_log_info( input(
"screen-options/print_log_info", false ) ),
 
  108        _print_equation_system_info( input(
"screen-options/print_equation_system_info", false ) ),
 
  109        _print_qoi( input(
"screen-options/print_qoi", false ) ),
 
  110        _print_scalars( input(
"screen-options/print_scalars", false ) ),
 
  111        _output_vis( input(
"vis-options/output_vis", false ) ),
 
  112        _output_adjoint( input(
"vis-options/output_adjoint", false ) ),
 
  113        _output_residual( input( 
"vis-options/output_residual", false ) ),
 
  114        _output_residual_sensitivities( input( 
"vis-options/output_residual_sensitivities", false ) ),
 
  115        _output_solution_sensitivities( input( 
"vis-options/output_solution_sensitivities", false ) ),
 
  116        _timesteps_per_vis( input(
"vis-options/timesteps_per_vis", 1 ) ),
 
  117        _timesteps_per_perflog( input(
"screen-options/timesteps_per_perflog", 0 ) ),
 
  118        _error_estimator_options(input),
 
  120        _do_adjoint_solve(false), 
 
  123     this->init_multiphysics_system(input);
 
  125     this->init_qois(input,sim_builder);
 
  127     this->init_params(input,sim_builder);
 
  129     this->init_adjoint_solve(input,_output_adjoint);
 
  132     this->build_error_estimator(input);
 
  135         this->init_restart(input,sim_builder,comm);
 
  137     bool warning_only = command_line.search(
"--warn-only-unused-var");
 
  138     this->check_for_unused_vars(input, warning_only );
 
  145     libMesh::perflog.disable_logging();
 
  163     if( input(
"screen-options/print_dof_constraints", 
false ) )
 
  176     SharedPtr<CompositeQoI> qois = sim_builder.
build_qoi( input );
 
  177     if( qois->n_qois() > 0 )
 
  188         std::cout << 
"Error: print_qoi is specified but\n" <<
 
  189           "no QoIs have been specified.\n" << std::endl;
 
  199     unsigned int n_adjoint_parameters =
 
  200       input.vector_variable_size(
"QoI/adjoint_sensitivity_parameters");
 
  202     unsigned int n_forward_parameters =
 
  203       input.vector_variable_size(
"QoI/forward_sensitivity_parameters");
 
  207     if ( n_adjoint_parameters )
 
  212           libMesh::cast_ptr<CompositeQoI*>
 
  218               "Error: adjoint_sensitivity_parameters are specified but\n" 
  219               << 
"no QoIs have been specified.\n" << std::endl;
 
  224           (input, 
"QoI/adjoint_sensitivity_parameters",
 
  228     if ( n_forward_parameters )
 
  243           (input, 
"QoI/forward_sensitivity_parameters",
 
  250                                  const libMesh::Parallel::Communicator &comm )
 
  269     std::vector<std::string> unused_vars = input.unidentified_variables();
 
  271     bool unused_vars_detected = 
false;
 
  274     std::string mat_string = 
"Materials/";
 
  278     if( !unused_vars.empty() )
 
  280         int n_total = unused_vars.size();
 
  284         for( 
int v = 0; v < n_total; v++ )
 
  285             if( (unused_vars[v]).find(mat_string) != std::string::npos )
 
  288         libmesh_assert_greater_equal( n_total, n_mats );
 
  290         if( n_mats < n_total )
 
  291           unused_vars_detected = 
true;
 
  294     if( unused_vars_detected )
 
  296         libMesh::err << 
"==========================================================" << std::endl;
 
  298           libMesh::err << 
"Warning: ";
 
  300           libMesh::err << 
"Error: ";
 
  302         libMesh::err << 
"Found unused variables!" << std::endl;
 
  304         for( std::vector<std::string>::const_iterator it = unused_vars.begin();
 
  305              it != unused_vars.end(); ++it )
 
  308             if( (*it).find(mat_string) != std::string::npos )
 
  311             libMesh::err << *it << std::endl;
 
  313         libMesh::err << 
"==========================================================" << std::endl;
 
  349         "Error: output_residual_sensitivities is specified but\n" <<
 
  350         "no forward sensitivity parameters have been specified.\n" <<
 
  359         "Error: output_solution_sensitivities is specified but\n" <<
 
  360         "no forward sensitivity parameters have been specified.\n" <<
 
  377         libMesh::QoISet qois;
 
  379         const libMesh::ParameterVector & params =
 
  382         libMesh::SensitivityData sensitivities
 
  385         _solver->adjoint_qoi_parameter_sensitivity
 
  386           (context, qois, params, sensitivities);
 
  388         std::cout << 
"Adjoint sensitivities:" << std::endl;
 
  390         for (
unsigned int q=0;
 
  393             for (
unsigned int p=0; p != params.size(); ++p)
 
  395                 std::cout << 
"dq" << q << 
"/dp" << p << 
" = " <<
 
  396                         sensitivities[q][p] << std::endl;
 
  404         libMesh::QoISet qois;
 
  406         const libMesh::ParameterVector & params =
 
  409         libMesh::SensitivityData sensitivities
 
  412         _solver->forward_qoi_parameter_sensitivity
 
  413           (context, qois, params, sensitivities);
 
  415         std::cout << 
"Forward sensitivities:" << std::endl;
 
  417         for (
unsigned int q=0;
 
  420             for (
unsigned int p=0; p != params.size(); ++p)
 
  422                 std::cout << 
"dq" << q << 
"/dp" << p << 
" = " <<
 
  423                         sensitivities[q][p] << std::endl;
 
  458     if (restart_file != 
"none")
 
  460         std::cout << 
" ====== Restarting from " << restart_file << std::endl;
 
  463         if (restart_file.rfind(
".xdr") < restart_file.size())
 
  466                                  libMesh::EquationSystems::READ_DATA |
 
  467                                  libMesh::EquationSystems::READ_ADDITIONAL_DATA);
 
  469         else if  (restart_file.rfind(
".xda") < restart_file.size())
 
  472                                  libMesh::EquationSystems::READ_DATA |
 
  473                                  libMesh::EquationSystems::READ_ADDITIONAL_DATA);
 
  477             std::cerr << 
"Error: Restart filename must have .xdr or .xda extension!" << std::endl;
 
  483         const std::string system_name = input(
"screen-options/system_name", 
"GRINS" );
 
  507         libmesh_error_msg(
"Error: Adjoint solve requested, but no QoIs detected.");
 
  514         libmesh_error_msg(
"Error: Adjoint output requested, but no adjoint solve requested.");
 
  522     bool do_adjoint_solve = 
false;
 
  526       do_adjoint_solve = 
true;
 
  530       do_adjoint_solve = 
true;
 
  535       do_adjoint_solve = 
true;
 
  537     return do_adjoint_solve;
 
  543     if( estimator_type != std::string(
"none") )
 
  548         _error_estimator.reset( (ErrorEstimatorFactoryBase::build(estimator_type)).release() );
 
  552 #ifdef GRINS_USE_GRVY_TIMERS 
  553   void Simulation::attach_grvy_timer( GRVY::GRVY_Timer_Class* grvy_timer )
 
static PhysicsList build_physics_map(const GetPot &input)
Returns container of constructed Physics objects. 
 
static bool do_adjoint_solve(const GetPot &input)
Option to let user manually trigger adjoint solve. 
 
void attach_physics_list(PhysicsList physics_list)
PhysicsList gets built by GRINS::PhysicsFactory and attached here. 
 
void read_restart(const GetPot &input)
 
static void set_estimator_options(const ErrorEstimatorOptions &estimator_options)
 
SharedPtr< libMesh::EquationSystems > equation_system
 
SharedPtr< libMesh::EquationSystems > get_equation_system()
 
const std::string & estimator_type() const 
 
void register_postprocessing_vars(const GetPot &input, PostProcessedQuantities< libMesh::Real > &postprocessing)
Each Physics will register their postprocessed quantities with this call. 
 
bool estimator_requires_adjoint() const 
 
void init_multiphysics_system(const GetPot &input)
Helper function. 
 
ParameterManager _forward_parameters
 
SharedPtr< PostProcessedQuantities< libMesh::Real > > postprocessing
 
void init_params(const GetPot &input, SimulationBuilder &sim_builder)
Helper function. 
 
unsigned int _timesteps_per_vis
 
static void set_getpot(const GetPot &input)
 
static bool have_restart(const GetPot &input)
 
SharedPtr< PostProcessedQuantities< libMesh::Real > > _postprocessing
 
SharedPtr< libMesh::ErrorEstimator > error_estimator
 
SharedPtr< CompositeQoI > build_qoi(const GetPot &input)
 
unsigned int timesteps_per_perflog
 
void build_error_estimator(const GetPot &input)
 
static int extra_quadrature_order(const GetPot &input)
 
SharedPtr< libMesh::ErrorEstimator > _error_estimator
 
bool _print_equation_system_info
 
libMesh::Number get_qoi_value(unsigned int qoi_index) const 
 
const MeshBuilder & mesh_builder() const 
 
unsigned int timesteps_per_vis
 
SharedPtr< GRINS::Solver > _solver
 
bool output_residual_sensitivities
 
static void set_system(MultiphysicsSystem &system)
 
libMesh::ParameterVector parameter_vector
 
void init_adjoint_solve(const GetPot &input, bool output_adjoint)
Helper function. 
 
GRINS::MultiphysicsSystem * system
 
SharedPtr< GRINS::Visualization > vis
 
void init_qois(const GetPot &input, SimulationBuilder &sim_builder)
Helper function. 
 
Interface with libMesh for solving Multiphysics problems. 
 
ParameterManager _adjoint_parameters
 
std::map< std::string, SharedPtr< GRINS::Physics > > PhysicsList
Container for GRINS::Physics object pointers. 
 
bool _output_residual_sensitivities
 
bool _output_solution_sensitivities
 
void output_qoi(std::ostream &out) const 
Basic output for computed QoI's. 
 
ErrorEstimatorOptions _error_estimator_options
 
void check_for_unused_vars(const GetPot &input, bool warning_only)
Helper function. 
 
static std::string restart_file(const GetPot &input)
 
void init_restart(const GetPot &input, SimulationBuilder &sim_builder, const libMesh::Parallel::Communicator &comm)
Helper function. 
 
Simple class to hold objects passed to Solver::solve. 
 
SharedPtr< libMesh::UnstructuredMesh > _mesh
 
GRINS::MultiphysicsSystem * _multiphysics_system
 
unsigned int _timesteps_per_perflog
 
void do_mesh_refinement_from_input(const GetPot &input, const libMesh::Parallel::Communicator &comm, libMesh::UnstructuredMesh &mesh) const 
Refine the mesh based on user input parameters. 
 
SharedPtr< GRINS::Visualization > _vis
 
virtual void read_input_options(const GetPot &input)
Reads input options for this class and all physics that are enabled. 
 
libMesh::Number get_qoi_value(unsigned int qoi_index) const 
Accessor for value of QoI for given qoi_index. 
 
bool output_solution_sensitivities
 
virtual void initialize(const GetPot &input, const std::string ¶meters_varname, GRINS::MultiphysicsSystem &system, GRINS::CompositeQoI *qoi)
 
bool check_for_adjoint_solve(const GetPot &input) const 
Helper function. 
 
SharedPtr< libMesh::EquationSystems > _equation_system