libMesh
diff_physics.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 
23 namespace libMesh
24 {
25 
27 {
29 }
30 
31 
32 
34 {
35  _time_evolving.resize(0);
36 }
37 
38 
39 
41 {
42  // give us flags for every variable that might be time evolving
43  _time_evolving.resize(sys.n_vars(), false);
44 }
45 
46 void DifferentiablePhysics::time_evolving (unsigned int var,
47  unsigned int order)
48 {
49  if (order != 1 && order != 2)
50  libmesh_error_msg("Input order must be 1 or 2!");
51 
52  if (_time_evolving.size() <= var)
53  _time_evolving.resize(var+1, 0);
54 
55  _time_evolving[var] = order;
56 
57  if (order == 1)
58  _first_order_vars.insert(var);
59  else
60  _second_order_vars.insert(var);
61 }
62 
64  DiffContext & c)
65 {
66  FEMContext & context = cast_ref<FEMContext &>(c);
67 
68  for (auto var : IntRange<unsigned int>(0, context.n_vars()))
69  {
70  if (!this->is_time_evolving(var))
71  continue;
72 
73  if (c.get_system().variable(var).type().family != SCALAR)
74  continue;
75 
76  const std::vector<dof_id_type> & dof_indices =
77  context.get_dof_indices(var);
78 
79  const unsigned int n_dofs = cast_int<unsigned int>
80  (dof_indices.size());
81 
82  DenseSubVector<Number> & Fs = context.get_elem_residual(var);
83  DenseSubMatrix<Number> & Kss = context.get_elem_jacobian( var, var );
84 
86  context.get_elem_solution(var);
87 
88  for (unsigned int i=0; i != n_dofs; ++i)
89  {
90  Fs(i) -= Us(i);
91 
92  if (request_jacobian)
93  Kss(i,i) -= context.elem_solution_rate_derivative;
94  }
95  }
96 
97  return request_jacobian;
98 }
99 
100 
101 
103  DiffContext & context)
104 {
105  // For any problem we need time derivative terms
106  request_jacobian =
107  this->element_time_derivative(request_jacobian, context);
108 
109  // For a moving mesh problem we may need the pseudoconvection term too
110  return this->eulerian_residual(request_jacobian, context) &&
111  request_jacobian;
112 }
113 
114 } // namespace libMesh
libMesh::DifferentiablePhysics::_first_order_vars
std::set< unsigned int > _first_order_vars
Variable indices for those variables that are first order in time.
Definition: diff_physics.h:560
libMesh::System
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:100
libMesh::DifferentiablePhysics::nonlocal_mass_residual
virtual bool nonlocal_mass_residual(bool request_jacobian, DiffContext &c)
Subtracts any nonlocal mass vector contributions (e.g.
Definition: diff_physics.C:63
libMesh::DiffContext::get_elem_residual
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual.
Definition: diff_context.h:249
libMesh::System::n_vars
unsigned int n_vars() const
Definition: system.h:2155
libMesh::DifferentiablePhysics::time_evolving
virtual void time_evolving(unsigned int var)
Tells the DiffSystem that variable var is evolving with respect to time.
Definition: diff_physics.h:250
libMesh::FEType::family
FEFamily family
The type of finite element.
Definition: fe_type.h:203
libMesh::DiffContext::get_dof_indices
const std::vector< dof_id_type > & get_dof_indices() const
Accessor for element dof indices.
Definition: diff_context.h:367
libMesh::DenseSubMatrix
Defines a dense submatrix for use in Finite Element-type computations.
Definition: dense_submatrix.h:45
libMesh::DifferentiablePhysics::is_time_evolving
bool is_time_evolving(unsigned int var) const
Definition: diff_physics.h:278
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::DiffContext::n_vars
unsigned int n_vars() const
Number of variables in solution.
Definition: diff_context.h:99
libMesh::DiffContext::get_system
const System & get_system() const
Accessor for associated system.
Definition: diff_context.h:105
libMesh::Variable::type
const FEType & type() const
Definition: variable.h:119
libMesh::System::variable
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition: system.h:2183
libMesh::DifferentiablePhysics::_eulerian_time_deriv
bool _eulerian_time_deriv(bool request_jacobian, DiffContext &)
This method simply combines element_time_derivative() and eulerian_residual(), which makes its addres...
Definition: diff_physics.C:102
libMesh::DifferentiablePhysics::_second_order_vars
std::set< unsigned int > _second_order_vars
Variable indices for those variables that are second order in time.
Definition: diff_physics.h:565
libMesh::IntRange
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
Definition: int_range.h:53
libMesh::DifferentiablePhysics::element_time_derivative
virtual bool element_time_derivative(bool request_jacobian, DiffContext &)
Adds the time derivative contribution on elem to elem_residual.
Definition: diff_physics.h:125
libMesh::DifferentiablePhysics::~DifferentiablePhysics
virtual ~DifferentiablePhysics()
Destructor.
Definition: diff_physics.C:26
libMesh::DiffContext
This class provides all data required for a physics package (e.g.
Definition: diff_context.h:55
libMesh::DenseSubVector< Number >
libMesh::DifferentiablePhysics::clear_physics
virtual void clear_physics()
Clear any data structures associated with the physics.
Definition: diff_physics.C:33
libMesh::DiffContext::elem_solution_rate_derivative
Real elem_solution_rate_derivative
The derivative of elem_solution_rate with respect to the current nonlinear solution,...
Definition: diff_context.h:507
libMesh::DiffContext::get_elem_jacobian
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian.
Definition: diff_context.h:283
libMesh::DifferentiablePhysics::eulerian_residual
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...
Definition: diff_physics.h:295
libMesh::DiffContext::get_elem_solution
const DenseVector< Number > & get_elem_solution() const
Accessor for element solution.
Definition: diff_context.h:111
libMesh::DifferentiablePhysics::_time_evolving
std::vector< unsigned int > _time_evolving
Stores unsigned int to tell us which variables are evolving as first order in time (1),...
Definition: diff_physics.h:555
libMesh::SCALAR
Definition: enum_fe_family.h:58
libMesh::DifferentiablePhysics::init_physics
virtual void init_physics(const System &sys)
Initialize any data structures associated with the physics.
Definition: diff_physics.C:40
libMesh::FEMContext
This class provides all data required for a physics package (e.g.
Definition: fem_context.h:62