1#include <libmesh/dof_map.h>
2#include <libmesh/enum_solver_type.h>
3#include <libmesh/enum_preconditioner_type.h>
4#include <libmesh/fem_system.h>
5#include <libmesh/newton_solver.h>
6#include <libmesh/numeric_vector.h>
7#include <libmesh/parallel.h>
16template<
typename TimeSolverType>
27 template<
typename SystemType>
33 SystemType & system = es.
add_system<SystemType>(
"ScalarSystem");
35 system.time_solver = std::make_unique<TimeSolverType>(system);
39 DiffSolver & solver = *(system.time_solver->diff_solver().get());
44 NewtonSolver & newton = cast_ref<NewtonSolver &>(solver);
51 system.deltat = deltat;
53 TimeSolverType * time_solver = cast_ptr<TimeSolverType *>(system.time_solver.get());
60 std::vector<dof_id_type> solution_index;
61 solution_index.push_back(0);
62 const bool has_solution = system.get_dof_map().all_semilocal_indices(solution_index);
64 for (
unsigned int t_step=0; t_step != n_timesteps; ++t_step)
67 system.time_solver->advance_timestep();
73 Number exact_soln = system.u(system.time);
74 rel_error = std::abs((exact_soln - (*system.solution)(0))/exact_soln);
76 system.comm().max(rel_error);
79 LIBMESH_ASSERT_FP_EQUAL( rel_error,
81 std::numeric_limits<Real>::epsilon()*10 );
96 const std::string & name_in,
97 const unsigned int number_in)
115 FEMSystem::init_data();
122 FEMContext & c = cast_ref<FEMContext &>(context);
125 const unsigned int n_u_dofs =
129 for (
unsigned int qp=0; qp != n_qpoints; qp++)
133 for (
unsigned int i=0; i != n_u_dofs; i++)
137 return request_jacobian;
144 FEMContext & c = cast_ref<FEMContext &>(context);
148 const unsigned int n_u_dofs =
152 for (
unsigned int qp=0; qp != n_qpoints; qp++)
159 for (
unsigned int i=0; i != n_u_dofs; i++)
163 if (request_jacobian)
164 for (
unsigned int j=0; j != n_u_dofs; j++)
169 return request_jacobian;
186 const std::string & name_in,
187 const unsigned int number_in)
195 FEMSystem::init_data();
205 FEMContext & c = cast_ref<FEMContext &>(context);
209 const unsigned int n_u_dofs =
213 for (
unsigned int qp=0; qp != n_qpoints; qp++)
220 for (
unsigned int i=0; i != n_u_dofs; i++)
224 if (request_jacobian)
225 for (
unsigned int j=0; j != n_u_dofs; j++)
230 return request_jacobian;
236 FEMContext & c = cast_ref<FEMContext &>(context);
240 const unsigned int n_u_dofs =
244 for (
unsigned int qp=0; qp != n_qpoints; qp++)
251 for (
unsigned int i=0; i != n_u_dofs; i++)
255 if (request_jacobian)
256 for (
unsigned int j=0; j != n_u_dofs; j++)
261 return request_jacobian;
276 const std::string & name_in,
277 const unsigned int number_in)
285 FEMContext & c = cast_ref<FEMContext &>(context);
291 const unsigned int n_u_dofs =
295 for (
unsigned int qp=0; qp != n_qpoints; qp++)
299 for (
unsigned int i=0; i != n_u_dofs; i++)
303 return request_jacobian;
310 FEMContext & c = cast_ref<FEMContext &>(context);
318 const unsigned int n_u_dofs =
322 for (
unsigned int qp=0; qp != n_qpoints; qp++)
329 for (
unsigned int i=0; i != n_u_dofs; i++)
333 if (request_jacobian)
334 for (
unsigned int j=0; j != n_u_dofs; j++)
339 return request_jacobian;
345 FEMContext & c = cast_ref<FEMContext &>(context);
352 const unsigned int n_u_dofs =
356 for (
unsigned int qp=0; qp != n_qpoints; qp++)
363 for (
unsigned int i=0; i != n_u_dofs; i++)
367 if (request_jacobian)
368 for (
unsigned int j=0; j != n_u_dofs; j++)
373 return request_jacobian;
FEMSystem-based class for testing of TimeSolvers using first order SCALARs.
FirstOrderScalarSystemBase(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
virtual Number u(Real t)=0
Exact solution as a function of time t.
virtual bool element_time_derivative(bool request_jacobian, DiffContext &context) override
Note the nonlinear residual is F(u)-M(u)
virtual void init_data() override
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used.
virtual Number F(FEMContext &context, unsigned int qp)=0
Value of F(u)
virtual Number M(FEMContext &context, unsigned int qp)=0
Value of M(u).
virtual bool mass_residual(bool request_jacobian, DiffContext &context) override
Note the nonlinear residual is F(u)-M(u)
FEMSystem-based class for testing of TimeSolvers using second order SCALARs.
virtual bool mass_residual(bool request_jacobian, DiffContext &context) override
Note the nonlinear residual is F(u)-M(u)
virtual bool element_time_derivative(bool request_jacobian, DiffContext &context) override
Note the nonlinear residual is M(u)
SecondOrderScalarSystemFirstOrderTimeSolverBase(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
virtual bool damping_residual(bool request_jacobian, DiffContext &context) override
Note the nonlinear residual is M(u)
FEMSystem-based class for testing of TimeSolvers using second order SCALARs.
virtual bool mass_residual(bool request_jacobian, DiffContext &context) override
Note the nonlinear residual is F(u)-M(u)
virtual Number C(FEMContext &context, unsigned int qp)=0
Value of C(u).
virtual void init_data() override
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used.
SecondOrderScalarSystemSecondOrderTimeSolverBase(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
virtual bool damping_residual(bool request_jacobian, DiffContext &context) override
Note the nonlinear residual is M(u)\ddot{u} + C(u)
virtual void aux_time_solver_init(TimeSolverType &)
void run_test_with_exact_soln(Real deltat, unsigned int n_timesteps)
Defines a dense submatrix for use in Finite Element-type computations.
Defines a dense subvector for use in finite element computations.
This class provides all data required for a physics package (e.g.
const std::vector< dof_id_type > & get_dof_indices() const
Accessor for element dof indices.
Real get_elem_solution_accel_derivative() const
The derivative of the current elem_solution_accel w.r.t.
Real get_elem_solution_rate_derivative() const
The derivative of the current elem_solution_rate w.r.t.
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
This is a generic class that defines a solver to handle ImplicitSystem classes, including NonlinearIm...
Real absolute_residual_tolerance
The DiffSolver should exit after the residual is reduced to either less than absolute_residual_tolera...
Real relative_residual_tolerance
Real relative_step_tolerance
virtual void time_evolving(unsigned int var, unsigned int order)
Tells the DiffSystem that variable var is evolving with respect to time.
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...
This is the EquationSystems class.
virtual void init()
Initialize all the systems.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
This class provides all data required for a physics package (e.g.
void interior_rate(unsigned int var, unsigned int qp, OutputType &u) const
const QBase & get_element_qrule() const
Accessor for element interior quadrature rule for the dimension of the current _elem.
void interior_accel(unsigned int var, unsigned int qp, OutputType &u) const
This class provides a specific system class.
void set_preconditioner_type(const PreconditionerType pct)
Sets the type of preconditioner to use.
void set_solver_type(const SolverType st)
Sets the type of solver to use.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
This class defines a solver which uses the default libMesh linear solver in a quasiNewton method to h...
LinearSolver< Number > & get_linear_solver()
unsigned int n_points() const
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.
Communicator * TestCommWorld
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real