36 #include "libmesh/dof_map.h"
37 #include "libmesh/parameter_vector.h"
38 #include "libmesh/qoi_set.h"
39 #include "libmesh/sensitivity_data.h"
45 SimulationBuilder& sim_builder,
46 const libMesh::Parallel::Communicator &comm )
47 : _mesh( sim_builder.build_mesh(input, comm) ),
48 _equation_system( new
libMesh::EquationSystems( *_mesh ) ),
49 _solver( sim_builder.build_solver(input) ),
50 _system_name( input(
"screen-options/system_name",
"GRINS" ) ),
51 _multiphysics_system( &(_equation_system->add_system<MultiphysicsSystem>( _system_name )) ),
52 _vis( sim_builder.build_vis(input, comm) ),
53 _postprocessing( sim_builder.build_postprocessing(input) ),
54 _print_mesh_info( input(
"screen-options/print_mesh_info", false ) ),
55 _print_log_info( input(
"screen-options/print_log_info", false ) ),
56 _print_equation_system_info( input(
"screen-options/print_equation_system_info", false ) ),
57 _print_qoi( input(
"screen-options/print_qoi", false ) ),
58 _print_scalars( input(
"screen-options/print_scalars", false ) ),
59 _output_vis( input(
"vis-options/output_vis", false ) ),
60 _output_adjoint( input(
"vis-options/output_adjoint", false ) ),
61 _output_residual( input(
"vis-options/output_residual", false ) ),
62 _output_residual_sensitivities( input(
"vis-options/output_residual_sensitivities", false ) ),
63 _output_solution_sensitivities( input(
"vis-options/output_solution_sensitivities", false ) ),
64 _timesteps_per_vis( input(
"vis-options/timesteps_per_vis", 1 ) ),
65 _timesteps_per_perflog( input(
"screen-options/timesteps_per_perflog", 0 ) ),
67 _do_adjoint_solve(false)
71 this->init_multiphysics_system(input,sim_builder);
73 this->init_qois(input,sim_builder);
75 this->init_params(input,sim_builder);
77 this->init_adjoint_solve(input,_output_adjoint);
80 _error_estimator = sim_builder.build_error_estimator( input, libMesh::QoISet(*_multiphysics_system) );
82 if( input.have_variable(
"restart-options/restart_file") )
84 this->init_restart(input,sim_builder,comm);
87 this->check_for_unused_vars(input,
false );
94 SimulationBuilder& sim_builder,
95 const libMesh::Parallel::Communicator &comm )
96 : _mesh( sim_builder.build_mesh(input, comm) ),
97 _equation_system( new
libMesh::EquationSystems( *_mesh ) ),
98 _solver( sim_builder.build_solver(input) ),
99 _system_name( input(
"screen-options/system_name",
"GRINS" ) ),
100 _multiphysics_system( &(_equation_system->add_system<MultiphysicsSystem>( _system_name )) ),
101 _vis( sim_builder.build_vis(input, comm) ),
102 _postprocessing( sim_builder.build_postprocessing(input) ),
103 _print_mesh_info( input(
"screen-options/print_mesh_info", false ) ),
104 _print_log_info( input(
"screen-options/print_log_info", false ) ),
105 _print_equation_system_info( input(
"screen-options/print_equation_system_info", false ) ),
106 _print_qoi( input(
"screen-options/print_qoi", false ) ),
107 _print_scalars( input(
"screen-options/print_scalars", false ) ),
108 _output_vis( input(
"vis-options/output_vis", false ) ),
109 _output_adjoint( input(
"vis-options/output_adjoint", false ) ),
110 _output_residual( input(
"vis-options/output_residual", false ) ),
111 _output_residual_sensitivities( input(
"vis-options/output_residual_sensitivities", false ) ),
112 _output_solution_sensitivities( input(
"vis-options/output_solution_sensitivities", false ) ),
113 _timesteps_per_vis( input(
"vis-options/timesteps_per_vis", 1 ) ),
114 _timesteps_per_perflog( input(
"screen-options/timesteps_per_perflog", 0 ) ),
116 _do_adjoint_solve(false)
118 this->init_multiphysics_system(input,sim_builder);
120 this->init_qois(input,sim_builder);
122 this->init_params(input,sim_builder);
124 this->init_adjoint_solve(input,_output_adjoint);
127 _error_estimator = sim_builder.build_error_estimator( input, libMesh::QoISet(*_multiphysics_system) );
129 if( input.have_variable(
"restart-options/restart_file") )
131 this->init_restart(input,sim_builder,comm);
134 bool warning_only = command_line.search(
"--warn-only-unused-var");
135 this->check_for_unused_vars(input, warning_only );
149 libMesh::perflog.disable_logging();
170 if( input(
"screen-options/print_dof_constraints",
false ) )
184 std::tr1::shared_ptr<CompositeQoI> qois = sim_builder.
build_qoi( input );
185 if( qois->n_qois() > 0 )
196 std::cout <<
"Error: print_qoi is specified but\n" <<
197 "no QoIs have been specified.\n" << std::endl;
207 unsigned int n_adjoint_parameters =
208 input.vector_variable_size(
"QoI/adjoint_sensitivity_parameters");
210 unsigned int n_forward_parameters =
211 input.vector_variable_size(
"QoI/forward_sensitivity_parameters");
215 if ( n_adjoint_parameters )
220 libMesh::cast_ptr<CompositeQoI*>
226 "Error: adjoint_sensitivity_parameters are specified but\n"
227 <<
"no QoIs have been specified.\n" << std::endl;
232 (input,
"QoI/adjoint_sensitivity_parameters",
236 if ( n_forward_parameters )
251 (input,
"QoI/forward_sensitivity_parameters",
258 const libMesh::Parallel::Communicator &comm )
277 std::vector<std::string> unused_vars = input.unidentified_variables();
279 if( !unused_vars.empty() )
281 libMesh::err <<
"==========================================================" << std::endl;
283 libMesh::err <<
"Warning: ";
285 libMesh::err <<
"Error: ";
287 libMesh::err <<
"Found unused variables!" << std::endl;
289 for( std::vector<std::string>::const_iterator it = unused_vars.begin();
290 it != unused_vars.end(); ++it )
292 libMesh::err << *it << std::endl;
294 libMesh::err <<
"==========================================================" << std::endl;
329 "Error: output_residual_sensitivities is specified but\n" <<
330 "no forward sensitivity parameters have been specified.\n" <<
339 "Error: output_solution_sensitivities is specified but\n" <<
340 "no forward sensitivity parameters have been specified.\n" <<
357 libMesh::QoISet qois;
359 const libMesh::ParameterVector & params =
362 libMesh::SensitivityData sensitivities
365 _solver->adjoint_qoi_parameter_sensitivity
366 (context, qois, params, sensitivities);
368 std::cout <<
"Adjoint sensitivities:" << std::endl;
370 for (
unsigned int q=0;
373 for (
unsigned int p=0; p != params.size(); ++p)
375 std::cout <<
"dq" << q <<
"/dp" << p <<
" = " <<
376 sensitivities[q][p] << std::endl;
384 libMesh::QoISet qois;
386 const libMesh::ParameterVector & params =
389 libMesh::SensitivityData sensitivities
392 _solver->forward_qoi_parameter_sensitivity
393 (context, qois, params, sensitivities);
395 std::cout <<
"Forward sensitivities:" << std::endl;
397 for (
unsigned int q=0;
400 for (
unsigned int p=0; p != params.size(); ++p)
402 std::cout <<
"dq" << q <<
"/dp" << p <<
" = " <<
403 sensitivities[q][p] << std::endl;
435 const std::string restart_file = input(
"restart-options/restart_file",
"none" );
438 if (restart_file !=
"none")
440 std::cout <<
" ====== Restarting from " << restart_file << std::endl;
443 if (restart_file.rfind(
".xdr") < restart_file.size())
446 libMesh::EquationSystems::READ_DATA |
447 libMesh::EquationSystems::READ_ADDITIONAL_DATA);
449 else if (restart_file.rfind(
".xda") < restart_file.size())
452 libMesh::EquationSystems::READ_DATA |
453 libMesh::EquationSystems::READ_ADDITIONAL_DATA);
457 std::cerr <<
"Error: Restart filename must have .xdr or .xda extension!" << std::endl;
461 const std::string system_name = input(
"screen-options/system_name",
"GRINS" );
478 if( neumann_bcs.size() > 0 )
480 for( std::map< std::string, NBCContainer >::iterator bc = neumann_bcs.begin();
481 bc != neumann_bcs.end();
484 std::tr1::shared_ptr<Physics> physics = system->
get_physics( bc->first );
485 physics->attach_neumann_bound_func( bc->second );
495 for( std::multimap< PhysicsName, DBCContainer >::const_iterator it = dbc_map.begin();
499 std::tr1::shared_ptr<Physics> physics = system->
get_physics( it->first );
501 physics->attach_dirichlet_bound_func( it->second );
518 libmesh_error_msg(
"Error: Adjoint solve requested, but no QoIs detected.");
525 libmesh_error_msg(
"Error: Adjoint output requested, but no adjoint solve requested.");
532 std::string error_estimator = input(
"MeshAdaptivity/estimator_type",
"none");
534 bool do_adjoint_solve =
false;
537 if( error_estimator.find(
"adjoint") != std::string::npos )
539 do_adjoint_solve =
true;
544 if( input(
"linear-nonlinear-solver/do_adjoint_solve",
false ) )
546 do_adjoint_solve =
true;
549 return do_adjoint_solve;
552 #ifdef GRINS_USE_GRVY_TIMERS
553 void Simulation::attach_grvy_timer( GRVY::GRVY_Timer_Class* grvy_timer )
void init_multiphysics_system(const GetPot &input, SimulationBuilder &sim_builder)
Helper function.
void attach_neumann_bc_funcs(std::map< GRINS::PhysicsName, GRINS::NBCContainer > neumann_bcs, GRINS::MultiphysicsSystem *system)
void attach_physics_list(PhysicsList physics_list)
PhysicsList gets built by GRINS::PhysicsFactory and attached here.
std::tr1::shared_ptr< CompositeQoI > build_qoi(const GetPot &input)
std::map< std::string, std::tr1::shared_ptr< GRINS::Physics > > PhysicsList
Container for GRINS::Physics object pointers.
void read_restart(const GetPot &input)
std::tr1::shared_ptr< GRINS::Physics > get_physics(const std::string physics_name)
void register_postprocessing_vars(const GetPot &input, PostProcessedQuantities< libMesh::Real > &postprocessing)
Each Physics will register their postprocessed quantities with this call.
ParameterManager _forward_parameters
std::tr1::shared_ptr< PostProcessedQuantities< libMesh::Real > > _postprocessing
std::map< GRINS::PhysicsName, GRINS::NBCContainer > build_neumann_bcs(libMesh::EquationSystems &equation_system)
void init_params(const GetPot &input, SimulationBuilder &sim_builder)
Helper function.
unsigned int _timesteps_per_vis
std::tr1::shared_ptr< libMesh::EquationSystems > equation_system
void attach_dirichlet_bc_funcs(std::multimap< GRINS::PhysicsName, GRINS::DBCContainer > dbc_map, GRINS::MultiphysicsSystem *system)
std::tr1::shared_ptr< libMesh::EquationSystems > _equation_system
unsigned int timesteps_per_perflog
std::tr1::shared_ptr< libMesh::ErrorEstimator > error_estimator
GRINS::PhysicsList build_physics(const GetPot &input)
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
std::multimap< GRINS::PhysicsName, GRINS::DBCContainer > build_dirichlet_bcs()
bool output_residual_sensitivities
std::tr1::shared_ptr< libMesh::EquationSystems > get_equation_system()
libMesh::ParameterVector parameter_vector
void init_adjoint_solve(const GetPot &input, bool output_adjoint)
Helper function.
std::tr1::shared_ptr< GRINS::Visualization > _vis
GRINS::MultiphysicsSystem * system
void init_qois(const GetPot &input, SimulationBuilder &sim_builder)
Helper function.
Interface with libMesh for solving Multiphysics problems.
ParameterManager _adjoint_parameters
bool _output_residual_sensitivities
bool _output_solution_sensitivities
std::tr1::shared_ptr< PostProcessedQuantities< libMesh::Real > > postprocessing
void output_qoi(std::ostream &out) const
Basic output for computed QoI's.
std::tr1::shared_ptr< libMesh::UnstructuredMesh > _mesh
void check_for_unused_vars(const GetPot &input, bool warning_only)
Helper function.
std::tr1::shared_ptr< GRINS::Visualization > vis
std::tr1::shared_ptr< GRINS::Solver > _solver
void init_restart(const GetPot &input, SimulationBuilder &sim_builder, const libMesh::Parallel::Communicator &comm)
Helper function.
std::tr1::shared_ptr< libMesh::ErrorEstimator > _error_estimator
Simple class to hold objects passed to Solver::solve.
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.
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.