19#include "libmesh/euler_solver.h"
21#include "libmesh/adjoint_refinement_estimator.h"
22#include "libmesh/diff_system.h"
23#include "libmesh/error_vector.h"
24#include "libmesh/int_range.h"
25#include "libmesh/numeric_vector.h"
106 ResFuncType time_deriv,
107 ResFuncType constraint,
108 ReinitFuncType reinit_func,
109 bool compute_second_order_eqns)
116 if (request_jacobian)
121 for (
unsigned int i=0; i != n_dofs; ++i)
122 old_elem_solution(i) =
139 theta_solution *=
theta;
140 theta_solution.
add(1. -
theta, old_elem_solution);
153 (context.*reinit_func)(
theta);
156 bool jacobian_computed =
174 (context.*reinit_func)(1);
181 jacobian_computed = (
_system.
get_physics()->*constraint)(jacobian_computed, context) &&
185 if (request_jacobian)
187 if (jacobian_computed)
193 return jacobian_computed;
207 std::vector<Number> left_contribution(
_system.
n_qois(), 0.0);
209 std::vector<Number> right_contribution(
_system.
n_qois(), 0.0);
249 _system.
set_qoi(j, ( ((1.0 -
theta)*left_contribution[j]) + (
theta*right_contribution[j]) )*(time_right - time_left));
253#ifdef LIBMESH_ENABLE_AMR
258 libmesh_not_implemented();
264 std::vector<Number> qoi_error_estimates_left(
_system.
n_qois());
265 std::vector<Number> qoi_error_estimates_right(
_system.
n_qois());
315 QoI_elementwise_error_left[i] = 0.0;
331 qoi_error_estimates_left[j] = 0.0;
399 QoI_elementwise_error[i] =
float(((QoI_elementwise_error_right[i] + QoI_elementwise_error_left[i])/2)
400 * (time_right - time_left));
This class implements a "brute force" goal-oriented error estimator which computes an estimate of err...
QoISet & qoi_set()
Access to the QoISet (default: weight all QoIs equally) to use when computing errors.
Number & get_global_QoI_error_estimate(unsigned int qoi_index)
This is an accessor function to access the computed global QoI error estimates.
virtual void estimate_error(const System &system, ErrorVector &error_per_cell, const NumericVector< Number > *solution_vector=nullptr, bool estimate_parent_error=false) override
This function does uniform refinements and an adjoint solve to get an adjoint solution on each cell,...
Defines a dense matrix for use in Finite Element-type computations.
void swap(DenseMatrix< T > &other_matrix)
STL-like swap method.
Defines a dense vector for use in Finite Element-type computations.
std::enable_if< ScalarTraits< T2 >::value, void >::type add(const T2 factor, const DenseVector< T3 > &vec)
Adds factor times vec to this vector.
void swap(DenseVector< T > &other_vector)
STL-like swap method.
virtual unsigned int size() const override final
This class provides all data required for a physics package (e.g.
Real elem_solution_derivative
The derivative of elem_solution with respect to the current nonlinear solution.
const DenseVector< Number > & get_elem_solution_rate() const
Accessor for element solution rate of change w.r.t.
virtual void elem_reinit(Real)
Gives derived classes the opportunity to reinitialize data (FE objects in FEMSystem,...
virtual void elem_side_reinit(Real)
Gives derived classes the opportunity to reinitialize data needed for a side integration at a new poi...
const std::vector< dof_id_type > & get_dof_indices() const
Accessor for element dof indices.
Real elem_solution_rate_derivative
The derivative of elem_solution_rate with respect to the current nonlinear solution,...
const DenseVector< Number > & get_elem_solution() const
Accessor for element solution.
Real fixed_solution_derivative
The derivative of elem_fixed_solution with respect to the nonlinear solution, for use by systems cons...
const DenseVector< Number > & get_elem_fixed_solution() const
Accessor for element fixed solution.
virtual void nonlocal_reinit(Real)
Gives derived classes the opportunity to reinitialize data needed for nonlocal calculations at a new ...
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
virtual bool element_constraint(bool request_jacobian, DiffContext &)
Adds the constraint contribution on elem to elem_residual.
virtual bool side_mass_residual(bool request_jacobian, DiffContext &)
Subtracts a mass vector contribution on side of elem from elem_residual.
virtual bool side_time_derivative(bool request_jacobian, DiffContext &)
Adds the time derivative contribution on side of elem to elem_residual.
virtual bool side_constraint(bool request_jacobian, DiffContext &)
Adds the constraint contribution on side of elem to elem_residual.
virtual bool nonlocal_constraint(bool request_jacobian, DiffContext &)
Adds any nonlocal constraint contributions (e.g.
virtual bool nonlocal_time_derivative(bool request_jacobian, DiffContext &)
Adds any nonlocal time derivative contributions (e.g.
virtual bool nonlocal_damping_residual(bool request_jacobian, DiffContext &)
Subtracts any nonlocal damping vector contributions (e.g.
bool have_second_order_vars() const
virtual bool damping_residual(bool request_jacobian, DiffContext &)
Subtracts a damping vector contribution on elem from elem_residual.
bool _eulerian_time_deriv(bool request_jacobian, DiffContext &)
This method simply combines element_time_derivative() and eulerian_residual(), which makes its addres...
virtual bool side_damping_residual(bool request_jacobian, DiffContext &)
Subtracts a damping vector contribution on side of elem from elem_residual.
virtual bool mass_residual(bool request_jacobian, DiffContext &)
Subtracts a mass vector contribution on elem from elem_residual.
virtual bool nonlocal_mass_residual(bool request_jacobian, DiffContext &c)
Subtracts any nonlocal mass vector contributions (e.g.
This class provides a specific system class.
const DifferentiablePhysics * get_physics() const
Real deltat
For time-dependent problems, this is the amount delta t to advance the solution in time.
bool have_second_order_scalar_vars() const
Check for any second order vars that are also belong to FEFamily::SCALAR.
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
virtual ~EulerSolver()
Destructor.
virtual bool nonlocal_residual(bool request_jacobian, DiffContext &) override
This method uses the DifferentiablePhysics' nonlocal_time_derivative() and nonlocal_constraint() to b...
virtual Real error_order() const override
Error convergence order: 2 for Crank-Nicolson, 1 otherwise.
virtual void integrate_qoi_timestep() override
A method to integrate the system::QoI functionals.
virtual bool side_residual(bool request_jacobian, DiffContext &) override
This method uses the DifferentiablePhysics' side_time_derivative() and side_constraint() to build a f...
virtual void integrate_adjoint_refinement_error_estimate(AdjointRefinementEstimator &adjoint_refinement_error_estimator, ErrorVector &QoI_elementwise_error) override
A method to compute the adjoint refinement error estimate at the current timestep.
EulerSolver(sys_type &s)
Constructor.
Real theta
The value for the theta method to employ: 1.0 corresponds to backwards Euler, 0.0 corresponds to forw...
virtual bool element_residual(bool request_jacobian, DiffContext &) override
This method uses the DifferentiablePhysics' element_time_derivative() and element_constraint() to bui...
virtual bool _general_residual(bool request_jacobian, DiffContext &, ResFuncType mass, ResFuncType damping, ResFuncType time_deriv, ResFuncType constraint, ReinitFuncType reinit, bool compute_second_order_eqns)
This method is the underlying implementation of the public residual methods.
virtual void assemble_qoi(const QoISet &qoi_indices=QoISet()) override
Prepares qoi for quantity of interest assembly, then calls user qoi function.
Generic class from which first order UnsteadySolvers should subclass.
bool compute_second_order_eqns(bool compute_jacobian, DiffContext &c)
If there are second order variables, then we need to compute their residual equations and correspondi...
void prepare_accel(DiffContext &context)
If there are second order variables in the system, then we also prepare the accel for those variables...
virtual void swap(NumericVector< T > &v)
Swaps the contents of this with v.
virtual std::unique_ptr< NumericVector< T > > clone() const =0
bool has_index(std::size_t) const
Return whether or not this index is in the set to be calculated.
bool use_fixed_solution
A boolean to be set to true by systems using elem_fixed_solution, for optional use by e....
void set_qoi(unsigned int qoi_index, Number qoi_value)
Number get_qoi_value(unsigned int qoi_index) const
Real time
For time-dependent problems, this is the time t at the beginning of the current timestep.
unsigned int n_qois() const
Number of currently active quantities of interest.
virtual void update()
Update the local values to reflect the solution on neighboring processors.
void set_qoi_error_estimate(unsigned int qoi_index, Number qoi_error_estimate)
NumericVector< Number > & get_adjoint_solution(unsigned int i=0)
sys_type & _system
A reference to the system we are solving.
std::vector< std::unique_ptr< NumericVector< Number > > > old_adjoints
A vector of pointers to vectors holding the adjoint solution at the last time step.
virtual void retrieve_timestep() override
This method retrieves all the stored solutions at the current system.time.
Number old_nonlinear_solution(const dof_id_type global_dof_number) const
Real last_step_deltat
We will need to move the system.time around to ensure that residuals are built with the right deltat ...
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...