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)
277 #endif // LIBMESH_ENABLE_DIRICHLET 286 #ifdef LIBMESH_ENABLE_DEPRECATED 288 dq->init_qoi( this->
qoi );
291 dq->init_qoi_count( *
this );
296 std::vector<Number> deprecated_vector;
297 dq->init_qoi( deprecated_vector );
302 dq->init_qoi_count( *
this );
309 unsigned int dot_var = var;
314 cast_ref<const UnsteadySolver &>(*(
time_solver.get()));
349 #ifdef LIBMESH_ENABLE_DEPRECATED 355 libmesh_deprecated();
361 std::unique_ptr<DifferentiablePhysics> scary_hack(
swap_physics);
375 swap_physics = old_p;
395 #endif // LIBMESH_ENABLE_DEPRECATED 427 this->
time_solver->diff_solver()->set_exact_constraint_enforcement(enable);
This is the EquationSystems class.
virtual void clear_physics()
Clear any data structures associated with the physics.
virtual void assemble() override
Prepares matrix and rhs for matrix assembly.
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
bool _constrain_in_solver
_constrain_in_solver defaults to true; if false then we apply constraints only via residual terms in ...
ConstFunction that simply returns 0.
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 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...
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.
virtual void init_data()
Initializes the data for the system.
std::unique_ptr< TimeSolver > time_solver
A pointer to the solver object we're going to use.
void add_second_order_dot_vars()
Helper function to add "velocity" variables that are cousins to second order-in-time variables in the...
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...
The libMesh namespace provides an interface to certain functionality in the library.
virtual void time_evolving(unsigned int var, unsigned int order)
Tells the DiffSystem that variable var is evolving with respect to time.
virtual std::unique_ptr< DiffContext > build_context()
Builds a DiffContext object with enough information to do evaluations on each element.
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...
void pop_physics()
Pop a physics object off of our stack.
virtual void reinit() override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
virtual void init_physics(const System &sys)
Initialize any data structures associated with the physics.
bool have_second_order_vars() const
void swap_physics(DifferentiablePhysics *&swap_physics)
Swap current physics object with external object.
void set_is_adjoint(bool _is_adjoint_value)
Accessor for setting whether we need to do a primal or adjoint solve.
virtual unsigned int time_order() const =0
const std::set< unsigned int > & get_second_order_vars() const
This class defines the notion of a variable in the system.
const std::set< subdomain_id_type > & active_subdomains() const
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 std::set< unsigned int > & get_first_order_vars() const
std::vector< Number > qoi
Values of the quantities of interest.
Real deltat
For time-dependent problems, this is the amount delta t to advance the solution in time...
bool use_fixed_solution
A boolean to be set to true by systems using elem_fixed_solution, for optional use by e...
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.
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.
We're using a class instead of a typedef to allow forward declarations and future flexibility...
virtual void clear_qoi()
Clear all the data structures associated with the QoI.
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.
void attach_qoi(DifferentiableQoI *qoi_in)
Attach external QoI object.
bool have_first_order_vars() const
virtual void disable_cache() override
Avoids use of any cached data that might affect any solve result.
const DirichletBoundaries * get_dirichlet_boundaries() const
bool have_second_order_scalar_vars() const
Check for any second order vars that are also belong to FEFamily::SCALAR.
virtual std::unique_ptr< DifferentiableQoI > clone()=0
Copy of this object.
This class provides a specific system class.
DifferentiableSystem(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
This class provides a specific system class.
virtual void init_data() override
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used...
This is a generic class that defines a solver to handle time integration of DifferentiableSystems.
virtual LinearSolver< Number > * get_linear_solver() const override
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const override
virtual std::unique_ptr< DifferentiablePhysics > clone_physics()=0
Copy of this object.
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
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...
virtual void solve() override
Invokes the solver associated with the system.
virtual void clear() override
Clear all the data structures associated with the system.
const std::string & name() const
bool have_first_order_scalar_vars() const
Check for any first order vars that are also belong to FEFamily::SCALAR.
const DofMap & get_dof_map() const
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...
virtual ~DifferentiableSystem()
TimeSolver & get_time_solver()
const FEType & type() const
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...