43 #include "libmesh/dof_map.h"
44 #include "libmesh/parameter_vector.h"
45 #include "libmesh/qoi_set.h"
46 #include "libmesh/sensitivity_data.h"
52 SimulationBuilder& sim_builder,
53 const libMesh::Parallel::Communicator &comm )
54 : _mesh( sim_builder.build_mesh(input, comm) ),
55 _equation_system( new
libMesh::EquationSystems( *_mesh ) ),
56 _system_name( input(
"screen-options/system_name",
"GRINS" ) ),
57 _multiphysics_system( &(_equation_system->add_system<MultiphysicsSystem>( _system_name )) ),
58 _vis( sim_builder.build_vis(input, comm) ),
59 _postprocessing( sim_builder.build_postprocessing(input) ),
60 _print_mesh_info( input(
"screen-options/print_mesh_info", false ) ),
61 _print_log_info( input(
"screen-options/print_log_info", false ) ),
62 _print_equation_system_info( input(
"screen-options/print_equation_system_info", false ) ),
63 _print_constraint_info( input(
"screen-options/print_constraint_info", false ) ),
64 _print_scalars( input(
"screen-options/print_scalars", false ) ),
65 _qoi_output( new QoIOutput(input) ),
66 _output_vis( input(
"vis-options/output_vis", false ) ),
67 _output_adjoint( input(
"vis-options/output_adjoint", false ) ),
68 _output_residual( input(
"vis-options/output_residual", false ) ),
69 _output_residual_sensitivities( input(
"vis-options/output_residual_sensitivities", false ) ),
70 _output_solution_sensitivities( input(
"vis-options/output_solution_sensitivities", false ) ),
71 _timesteps_per_vis( input(
"vis-options/timesteps_per_vis", 1 ) ),
72 _timesteps_per_perflog( input(
"screen-options/timesteps_per_perflog", 0 ) ),
73 _error_estimator_options(input),
75 _do_adjoint_solve(false),
80 this->build_solver(input);
82 this->init_multiphysics_system(input);
84 this->init_qois(input,sim_builder);
86 this->init_params(input,sim_builder);
88 this->init_adjoint_solve(input,_output_adjoint);
91 this->build_error_estimator(input);
94 this->init_restart(input,sim_builder,comm);
99 SimulationBuilder& sim_builder,
100 const libMesh::Parallel::Communicator &comm )
101 : _mesh( sim_builder.build_mesh(input, comm) ),
102 _equation_system( new
libMesh::EquationSystems( *_mesh ) ),
103 _system_name( input(
"screen-options/system_name",
"GRINS" ) ),
104 _multiphysics_system( &(_equation_system->add_system<MultiphysicsSystem>( _system_name )) ),
105 _vis( sim_builder.build_vis(input, comm) ),
106 _postprocessing( sim_builder.build_postprocessing(input) ),
107 _print_mesh_info( input(
"screen-options/print_mesh_info", false ) ),
108 _print_log_info( input(
"screen-options/print_log_info", false ) ),
109 _print_equation_system_info( input(
"screen-options/print_equation_system_info", false ) ),
110 _print_constraint_info( input(
"screen-options/print_constraint_info", false ) ),
111 _print_scalars( input(
"screen-options/print_scalars", false ) ),
112 _qoi_output( new QoIOutput(input) ),
113 _output_vis( input(
"vis-options/output_vis", false ) ),
114 _output_adjoint( input(
"vis-options/output_adjoint", false ) ),
115 _output_residual( input(
"vis-options/output_residual", false ) ),
116 _output_residual_sensitivities( input(
"vis-options/output_residual_sensitivities", false ) ),
117 _output_solution_sensitivities( input(
"vis-options/output_solution_sensitivities", false ) ),
118 _timesteps_per_vis( input(
"vis-options/timesteps_per_vis", 1 ) ),
119 _timesteps_per_perflog( input(
"screen-options/timesteps_per_perflog", 0 ) ),
120 _error_estimator_options(input),
122 _do_adjoint_solve(false),
125 this->build_solver(input);
127 this->init_multiphysics_system(input);
129 this->init_qois(input,sim_builder);
131 this->init_params(input,sim_builder);
133 this->init_adjoint_solve(input,_output_adjoint);
136 this->build_error_estimator(input);
139 this->init_restart(input,sim_builder,comm);
145 libMesh::perflog.disable_logging();
165 if( input(
"screen-options/print_dof_constraints",
false ) )
174 if (input(
"Strategies/MeshAdaptivity/disable_two_step_refinement",
false))
181 SharedPtr<CompositeQoI> qois = sim_builder.
build_qoi( input );
182 if( qois->n_qois() > 0 )
193 std::cout <<
"Error: print_qoi is specified but\n" <<
194 "no QoIs have been specified.\n" << std::endl;
202 unsigned int n_adjoint_parameters =
203 input.vector_variable_size(
"QoI/adjoint_sensitivity_parameters");
205 unsigned int n_forward_parameters =
206 input.vector_variable_size(
"QoI/forward_sensitivity_parameters");
210 if ( n_adjoint_parameters )
215 libMesh::cast_ptr<CompositeQoI*>
221 "Error: adjoint_sensitivity_parameters are specified but\n"
222 <<
"no QoIs have been specified.\n" << std::endl;
227 (input,
"QoI/adjoint_sensitivity_parameters",
231 if ( n_forward_parameters )
246 (input,
"QoI/forward_sensitivity_parameters",
253 const libMesh::Parallel::Communicator &comm )
294 "Error: output_residual_sensitivities is specified but\n" <<
295 "no forward sensitivity parameters have been specified.\n" <<
304 "Error: output_solution_sensitivities is specified but\n" <<
305 "no forward sensitivity parameters have been specified.\n" <<
322 libMesh::QoISet qois;
324 const libMesh::ParameterVector & params =
327 libMesh::SensitivityData sensitivities
330 _solver->adjoint_qoi_parameter_sensitivity
331 (context, qois, params, sensitivities);
333 std::cout <<
"Adjoint sensitivities:" << std::endl;
335 for (
unsigned int q=0;
338 for (
unsigned int p=0; p != params.size(); ++p)
340 std::cout <<
"dq" << q <<
"/dp" << p <<
" = " <<
341 sensitivities[q][p] << std::endl;
349 libMesh::QoISet qois;
351 const libMesh::ParameterVector & params =
354 libMesh::SensitivityData sensitivities
357 _solver->forward_qoi_parameter_sensitivity
358 (context, qois, params, sensitivities);
360 std::cout <<
"Forward sensitivities:" << std::endl;
362 for (
unsigned int q=0;
365 for (
unsigned int p=0; p != params.size(); ++p)
367 std::cout <<
"dq" << q <<
"/dp" << p <<
" = " <<
368 sensitivities[q][p] << std::endl;
380 this->
_mesh->print_info();
409 if (restart_file !=
"none")
411 std::cout <<
" ====== Restarting from " << restart_file << std::endl;
414 if (restart_file.rfind(
".xdr") < restart_file.size())
417 libMesh::EquationSystems::READ_DATA |
418 libMesh::EquationSystems::READ_ADDITIONAL_DATA);
420 else if (restart_file.rfind(
".xda") < restart_file.size())
423 libMesh::EquationSystems::READ_DATA |
424 libMesh::EquationSystems::READ_ADDITIONAL_DATA);
428 std::cerr <<
"Error: Restart filename must have .xdr or .xda extension!" << std::endl;
434 const std::string system_name = input(
"screen-options/system_name",
"GRINS" );
458 libmesh_error_msg(
"Error: Adjoint solve requested, but no QoIs detected.");
465 libmesh_error_msg(
"Error: Adjoint output requested, but no adjoint solve requested.");
473 bool do_adjoint_solve =
false;
477 do_adjoint_solve =
true;
481 do_adjoint_solve =
true;
486 do_adjoint_solve =
true;
488 return do_adjoint_solve;
494 if( estimator_type != std::string(
"none") )
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
static std::string solver_type(const GetPot &input)
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
static libMesh::UniquePtr< libMesh::ErrorEstimator > build(const std::string &name)
Use this method to build objects of type Base.
SharedPtr< libMesh::ErrorEstimator > error_estimator
SharedPtr< CompositeQoI > build_qoi(const GetPot &input)
bool _print_constraint_info
unsigned int timesteps_per_perflog
void build_error_estimator(const GetPot &input)
static int extra_quadrature_order(const GetPot &input)
SharedPtr< QoIOutput > _qoi_output
SharedPtr< libMesh::ErrorEstimator > _error_estimator
bool _print_equation_system_info
libMesh::Number get_qoi_value(unsigned int qoi_index) const
SharedPtr< QoIOutput > qoi_output
const MeshBuilder & mesh_builder() const
unsigned int timesteps_per_vis
static void build_variables(const GetPot &input, MultiphysicsSystem &system)
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.
libMesh::UniquePtr< GRINS::Solver > _solver
GRINS::MultiphysicsSystem * system
SharedPtr< GRINS::Visualization > vis
void init_qois(const GetPot &input, SimulationBuilder &sim_builder)
Helper function.
void build_solver(const GetPot &input)
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
ErrorEstimatorOptions _error_estimator_options
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