Go to the documentation of this file.
19 #include "libmesh/diff_solver.h"
20 #include "libmesh/diff_system.h"
21 #include "libmesh/time_solver.h"
22 #include "libmesh/unsteady_solver.h"
23 #include "libmesh/dirichlet_boundaries.h"
24 #include "libmesh/dof_map.h"
25 #include "libmesh/zero_function.h"
35 const std::string & name_in,
36 const unsigned int number_in) :
37 Parent (es, name_in, number_in),
40 print_solution_norms(false),
41 print_solutions(false),
42 print_residual_norms(false),
43 print_residuals(false),
44 print_jacobian_norms(false),
45 print_jacobians(false),
46 print_element_solutions(false),
47 print_element_residuals(false),
48 print_element_jacobians(false),
101 libmesh_assert_equal_to (&(
time_solver->system()),
this);
117 libmesh_assert_equal_to (&(
time_solver->system()),
this);
123 cast_ref<const UnsteadySolver &>(*(
time_solver.get()));
141 return std::unique_ptr<DiffContext>(context);
158 libmesh_assert_equal_to (&(
time_solver->system()),
this);
178 libmesh_assert_equal_to (&(
time_solver->system()),
this);
187 libmesh_assert_equal_to (&(
time_solver->system()),
this);
188 return std::make_pair(this->
time_solver->diff_solver()->max_linear_iterations,
189 this->
time_solver->diff_solver()->relative_residual_tolerance);
201 if (!second_order_vars.empty())
203 for (
const auto & var_id : second_order_vars)
206 std::string new_var_name = std::string(
"dot_")+var.
name();
208 unsigned int v_var_idx;
220 #ifdef LIBMESH_ENABLE_DIRICHLET
229 #ifdef LIBMESH_ENABLE_DIRICHLET
231 unsigned int dot_var_idx )
245 std::vector<DirichletBoundary *> new_dbcs;
247 for (
const auto & dbc : *all_dbcs)
253 std::vector<unsigned int>::const_iterator dbc_var_it =
254 std::find( dbc->variables.begin(), dbc->variables.end(), var_idx );
258 std::vector<unsigned int> vars_to_add;
259 if (dbc_var_it != dbc->variables.end())
260 vars_to_add.push_back(dot_var_idx);
262 if (!vars_to_add.empty())
270 bool is_time_evolving_bc =
false;
272 is_time_evolving_bc = dbc->f->is_time_dependent();
276 is_time_evolving_bc =
true;
278 libmesh_error_msg(
"Could not find valid boundary function!");
280 if (is_time_evolving_bc)
281 libmesh_error_msg(
"Cannot currently support time-dependent Dirichlet BC for dot variables!");
295 new_dbcs.push_back(new_dbc);
300 for (
const auto & dbc : new_dbcs)
308 #endif // LIBMESH_ENABLE_DIRICHLET
313 unsigned int dot_var = var;
318 cast_ref<const UnsteadySolver &>(*(
time_solver.get()));
void swap_physics(DifferentiablePhysics *&swap_physics)
Swap current physics object with external object.
Real deltat
For time-dependent problems, this is the amount delta t to advance the solution in time.
virtual void release_linear_solver(LinearSolver< Number > *) const override
Releases a pointer to a linear solver acquired by this->get_linear_solver()
virtual void time_evolving(unsigned int var)
Tells the DiffSystem that variable var is evolving with respect to time.
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...
const DirichletBoundaries * get_dirichlet_boundaries() const
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet()) override
Assembles & solves the linear system (dR/du)^T*z = dq/du, for those quantities of interest q specifie...
This class provides a specific system class.
virtual void reinit() override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
virtual void reinit() override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
The libMesh namespace provides an interface to certain functionality in the library.
DifferentiableSystem(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
virtual void clear_qoi()
Clear all the data structures associated with the QoI.
const FEType & type() const
std::map< unsigned int, unsigned int > _second_order_dot_vars
If the user adds any second order variables, then we need to also cache the map to their correspondin...
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
bool use_fixed_solution
A boolean to be set to true by systems using elem_fixed_solution, for optional use by e....
const std::set< subdomain_id_type > & active_subdomains() const
We're using a class instead of a typedef to allow forward declarations and future flexibility.
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we're going to use.
const std::string & name() const
DifferentiablePhysics * _diff_physics
Pointer to object to use for physics assembly evaluations.
const std::set< unsigned int > & get_second_order_vars() const
This is a generic class that defines a solver to handle time integration of DifferentiableSystems.
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
void set_deltat_pointer(Real *dt)
Points the _deltat member of this class at a timestep value stored in the creating System,...
unsigned int add_variable(const std::string &var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
virtual void solve() override
Invokes the solver associated with the system.
TimeSolver & get_time_solver()
This class defines the notion of a variable in the system.
virtual void assemble() override
Prepares matrix and rhs for matrix assembly.
virtual ~DifferentiableSystem()
Destructor.
virtual LinearSolver< Number > * get_linear_solver() const override
virtual void clear() override
Clear all the data structures associated with the system.
void set_is_adjoint(bool _is_adjoint_value)
Accessor for setting whether we need to do a primal or adjoint solve.
virtual std::pair< unsigned int, Real > adjoint_solve(const QoISet &qoi_indices=QoISet()) override
This function sets the _is_adjoint boolean member of TimeSolver to true and then calls the adjoint_so...
void add_second_order_dot_vars()
Helper function to add "velocity" variables that are cousins to second order-in-time variables in the...
ConstFunction that simply returns 0.
This class provides all data required for a physics package (e.g.
bool have_first_order_vars() const
This is the EquationSystems class.
bool have_first_order_scalar_vars() const
Check for any first order vars that are also belong to FEFamily::SCALAR.
DifferentiableQoI * diff_qoi
Pointer to object to use for quantity of interest assembly evaluations.
virtual void clear_physics()
Clear any data structures associated with the physics.
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=
virtual unsigned int time_order() const =0
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
virtual void assembly(bool get_residual, bool get_jacobian, bool apply_heterogeneous_constraints=false, bool apply_no_constraints=false) override=0
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
virtual void init_data() override
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used.
unsigned int get_second_order_dot_var(unsigned int var) const
For a given second order (in time) variable var, this method will return the index to the correspondi...
const DofMap & get_dof_map() const
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const override
bool have_second_order_vars() const
virtual void init_data() override
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used.
const std::set< unsigned int > & get_first_order_vars() const
virtual void init_physics(const System &sys)
Initialize any data structures associated with the physics.
virtual std::unique_ptr< DiffContext > build_context()
Builds a DiffContext object with enough information to do evaluations on each element.
void add_dot_var_dirichlet_bcs(unsigned int var_idx, unsigned int dot_var_idx)
Helper function to and Dirichlet boundary conditions to "dot" variable cousins of second order variab...
bool have_second_order_scalar_vars() const
Check for any second order vars that are also belong to FEFamily::SCALAR.