20#include "libmesh/diff_solver.h"
21#include "libmesh/diff_system.h"
22#include "libmesh/time_solver.h"
23#include "libmesh/unsteady_solver.h"
24#include "libmesh/dirichlet_boundaries.h"
25#include "libmesh/dof_map.h"
26#include "libmesh/zero_function.h"
37 const std::string & name_in,
38 const unsigned int number_in) :
39 Parent (es, name_in, number_in),
42 postprocess_sides(false),
43 print_solution_norms(false),
44 print_solutions(false),
45 print_residual_norms(false),
46 print_residuals(false),
47 print_jacobian_norms(false),
48 print_jacobians(false),
49 print_element_solutions(false),
50 print_element_residuals(false),
51 print_element_jacobians(false),
52 _constrain_in_solver(true),
87 libmesh_assert_equal_to (&(
time_solver->system()),
this);
103 libmesh_assert_equal_to (&(
time_solver->system()),
this);
109 cast_ref<const UnsteadySolver &>(*(
time_solver.get()));
125 auto context = std::make_unique<DiffContext>(*
this);
126 context->set_deltat_pointer( &this->
deltat );
144 libmesh_assert_equal_to (&(
time_solver->system()),
this);
166 libmesh_assert_equal_to (&(
time_solver->system()),
this);
175 libmesh_assert_equal_to (&(
time_solver->system()),
this);
176 return std::make_pair(this->
time_solver->diff_solver()->max_linear_iterations,
177 this->time_solver->diff_solver()->relative_residual_tolerance);
185 if (!second_order_vars.empty())
187 for (
const auto & var_id : second_order_vars)
190 std::string new_var_name = std::string(
"dot_")+var.
name();
192 unsigned int v_var_idx;
204#ifdef LIBMESH_ENABLE_DIRICHLET
213#ifdef LIBMESH_ENABLE_DIRICHLET
215 unsigned int dot_var_idx )
229 std::vector<DirichletBoundary> new_dbcs;
231 for (
const auto & dbc : *all_dbcs)
237 std::vector<unsigned int>::const_iterator dbc_var_it =
238 std::find( dbc->variables.begin(), dbc->variables.end(), var_idx );
242 std::vector<unsigned int> vars_to_add;
243 if (dbc_var_it != dbc->variables.end())
244 vars_to_add.push_back(dot_var_idx);
246 if (!vars_to_add.empty())
254 bool is_time_evolving_bc =
false;
256 is_time_evolving_bc = dbc->f->is_time_dependent();
260 is_time_evolving_bc =
true;
262 libmesh_error_msg(
"Could not find valid boundary function!");
264 libmesh_error_msg_if(is_time_evolving_bc,
"Cannot currently support time-dependent Dirichlet BC for dot variables!");
265 libmesh_error_msg_if(!dbc->f,
"Expected valid DirichletBoundary function");
272 for (
const auto & dbc : new_dbcs)
285 dq->init_qoi_count( *
this );
291 unsigned int dot_var = var;
296 cast_ref<const UnsteadySolver &>(*(
time_solver.get()));
359 this->
time_solver->diff_solver()->set_exact_constraint_enforcement(enable);
This class provides a specific system class.
virtual void clear_physics()
Clear any data structures associated with the physics.
const std::set< unsigned int > & get_second_order_vars() const
virtual void init_physics(const System &sys)
Initialize any data structures associated with the physics.
virtual std::unique_ptr< DifferentiablePhysics > clone_physics()=0
Copy of this object.
const std::set< unsigned int > & get_first_order_vars() 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...
bool have_second_order_vars() const
virtual void time_evolving(unsigned int var, unsigned int order)
Tells the DiffSystem that variable var is evolving with respect to time.
bool have_first_order_vars() const
This class provides a specific system class.
virtual void clear_qoi()
Clear all the data structures associated with the QoI.
virtual std::unique_ptr< DifferentiableQoI > clone()=0
Copy of this object.
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...
void pop_physics()
Pop a physics object off of our stack.
Real deltat
For time-dependent problems, this is the amount delta t to advance the solution in time.
std::stack< std::unique_ptr< DifferentiablePhysics >, std::vector< std::unique_ptr< DifferentiablePhysics > > > _diff_physics
Stack of pointers to objects to use for physics assembly evaluations.
virtual void set_constrain_in_solver(bool enable)
set_constrain_in_solver to false to apply constraints only via residual terms in the systems to be so...
bool have_second_order_scalar_vars() const
Check for any second order vars that are also belong to FEFamily::SCALAR.
void push_physics(DifferentiablePhysics &new_physics)
Push a clone of a new physics object onto our stack, overriding the current physics until the new phy...
DifferentiableSystem(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
std::stack< std::unique_ptr< DifferentiableQoI >, std::vector< std::unique_ptr< DifferentiableQoI > > > _diff_qoi
Pointer to object to use for quantity of interest assembly evaluations.
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 ~DifferentiableSystem()
bool have_first_order_scalar_vars() const
Check for any first order vars that are also belong to FEFamily::SCALAR.
void attach_qoi(DifferentiableQoI *qoi_in)
Attach external QoI object.
void add_second_order_dot_vars()
Helper function to add "velocity" variables that are cousins to second order-in-time variables in the...
virtual LinearSolver< Number > * get_linear_solver() const override
bool _constrain_in_solver
_constrain_in_solver defaults to true; if false then we apply constraints only via residual terms in ...
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const override
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...
TimeSolver & get_time_solver()
virtual void clear() override
Clear all the data structures associated with the system.
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...
virtual void init_data() override
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used.
virtual std::unique_ptr< DiffContext > build_context()
Builds a DiffContext object with enough information to do evaluations on each element.
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we're going to use.
virtual void reinit() override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
virtual void solve() override
Invokes the solver associated with the system.
virtual void assemble() override
Prepares matrix and rhs for matrix assembly.
We're using a class instead of a typedef to allow forward declarations and future flexibility.
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.
This is the EquationSystems class.
FEFamily family
The type of finite element.
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...
virtual void disable_cache() override
Avoids use of any cached data that might affect any solve result.
This base class can be inherited from to provide interfaces to linear solvers from different packages...
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
virtual void reinit()
Reinitializes degrees of freedom and other required data on the current mesh.
bool use_fixed_solution
A boolean to be set to true by systems using elem_fixed_solution, for optional use by e....
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
unsigned int add_variable(std::string_view 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 init_data()
Initializes the data for the system.
const DofMap & get_dof_map() const
void set_is_adjoint(bool _is_adjoint_value)
Accessor for setting whether we need to do a primal or adjoint solve.
This is a generic class that defines a solver to handle time integration of DifferentiableSystems.
virtual unsigned int time_order() const =0
This class defines the notion of a variable in the system.
const std::set< subdomain_id_type > & active_subdomains() const
const std::string & name() const
const FEType & type() const
ConstFunction that simply returns 0.
The libMesh namespace provides an interface to certain functionality in the library.