libMesh
Loading...
Searching...
No Matches
diff_physics.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19#include "libmesh/diff_context.h"
20#include "libmesh/diff_physics.h"
21#include "libmesh/system.h"
22#include "libmesh/variable.h"
23
24namespace libMesh
25{
26
28
33
34
35
37{
38 // give us flags for every variable that might be time evolving
39 _time_evolving.resize(sys.n_vars(), false);
40}
41
43 unsigned int order)
44{
45 libmesh_error_msg_if(order != 1 && order != 2, "Input order must be 1 or 2!");
46
47 if (_time_evolving.size() <= var)
48 _time_evolving.resize(var+1, 0);
49
50 _time_evolving[var] = order;
51
52 if (order == 1)
53 _first_order_vars.insert(var);
54 else
55 _second_order_vars.insert(var);
56}
57
59 DiffContext & c)
60{
61 FEMContext & context = cast_ref<FEMContext &>(c);
62
63 for (auto var : make_range(context.n_vars()))
64 {
65 if (!this->is_time_evolving(var))
66 continue;
67
68 if (c.get_system().variable(var).type().family != SCALAR)
69 continue;
70
71 const std::vector<dof_id_type> & dof_indices =
72 context.get_dof_indices(var);
73
74 const unsigned int n_dofs = cast_int<unsigned int>
75 (dof_indices.size());
76
77 DenseSubVector<Number> & Fs = context.get_elem_residual(var);
78 DenseSubMatrix<Number> & Kss = context.get_elem_jacobian( var, var );
79
81 context.get_elem_solution(var);
82
83 for (unsigned int i=0; i != n_dofs; ++i)
84 {
85 Fs(i) -= Us(i);
86
87 if (request_jacobian)
88 Kss(i,i) -= context.elem_solution_rate_derivative;
89 }
90 }
91
92 return request_jacobian;
93}
94
95
96
98 DiffContext & context)
99{
100 // For any problem we need time derivative terms
101 request_jacobian =
102 this->element_time_derivative(request_jacobian, context);
103
104 // For a moving mesh problem we may need the pseudoconvection term too
105 return this->eulerian_residual(request_jacobian, context) &&
106 request_jacobian;
107}
108
109} // namespace libMesh
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.
unsigned int n_vars() const
Number of variables in solution.
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.
const System & get_system() const
Accessor for associated system.
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
virtual bool element_time_derivative(bool request_jacobian, DiffContext &)
Adds the time derivative contribution on elem to elem_residual.
virtual void clear_physics()
Clear any data structures associated with the physics.
bool is_time_evolving(unsigned int var) const
virtual bool eulerian_residual(bool request_jacobian, DiffContext &)
Adds a pseudo-convection contribution on elem to elem_residual, if the nodes of elem are being transl...
virtual void init_physics(const System &sys)
Initialize any data structures associated with the physics.
std::set< unsigned int > _first_order_vars
Variable indices for those variables that are first order in time.
std::set< unsigned int > _second_order_vars
Variable indices for those variables that are second order in time.
std::vector< unsigned int > _time_evolving
Stores unsigned int to tell us which variables are evolving as first order in time (1),...
bool _eulerian_time_deriv(bool request_jacobian, DiffContext &)
This method simply combines element_time_derivative() and eulerian_residual(), which makes its addres...
virtual void time_evolving(unsigned int var, unsigned int order)
Tells the DiffSystem that variable var is evolving with respect to time.
virtual ~DifferentiablePhysics()
Destructor.
virtual bool nonlocal_mass_residual(bool request_jacobian, DiffContext &c)
Subtracts any nonlocal mass vector contributions (e.g.
This class provides all data required for a physics package (e.g.
Definition fem_context.h:63
FEFamily family
The type of finite element.
Definition fe_type.h:228
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition system.C:2704
unsigned int n_vars() const
Definition system.C:2674
const FEType & type() const
Definition variable.h:144
The libMesh namespace provides an interface to certain functionality in the library.
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...
Definition int_range.h:176