libMesh
diff_physics.h
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 
20 #ifndef LIBMESH_DIFF_PHYSICS_H
21 #define LIBMESH_DIFF_PHYSICS_H
22 
23 // Local Includes
24 #include "libmesh/libmesh.h"
25 
26 // C++ includes
27 #include <map>
28 #include <memory>
29 #include <set>
30 #include <vector>
31 
32 namespace libMesh
33 {
34 
35 // Forward Declarations
36 class System;
37 class DiffContext;
38 
77 {
78 public:
79 
85  compute_internal_sides (false),
86  _mesh_sys (nullptr),
90  {}
91 
95  virtual ~DifferentiablePhysics ();
96 
100  virtual std::unique_ptr<DifferentiablePhysics> clone_physics() = 0;
101 
105  virtual void clear_physics ();
106 
110  virtual void init_physics (const System & sys);
111 
125  virtual bool element_time_derivative (bool request_jacobian,
126  DiffContext &) {
127  return request_jacobian;
128  }
129 
143  virtual bool element_constraint (bool request_jacobian,
144  DiffContext &) {
145  return request_jacobian;
146  }
147 
155 
172  virtual bool side_time_derivative (bool request_jacobian,
173  DiffContext &) {
174  return request_jacobian;
175  }
176 
192  virtual bool side_constraint (bool request_jacobian,
193  DiffContext &) {
194  return request_jacobian;
195  }
196 
210  virtual bool nonlocal_time_derivative (bool request_jacobian,
211  DiffContext &) {
212  return request_jacobian;
213  }
214 
228  virtual bool nonlocal_constraint (bool request_jacobian,
229  DiffContext &) {
230  return request_jacobian;
231  }
232 
233 
249 #ifdef LIBMESH_ENABLE_DEPRECATED
250  virtual void time_evolving (unsigned int var)
251  {
252  libmesh_deprecated();
253  this->time_evolving(var,1);
254  }
255 #endif
256 
269  virtual void time_evolving (unsigned int var, unsigned int order);
270 
278  bool is_time_evolving (unsigned int var) const
279  {
280  libmesh_assert_less(var,_time_evolving.size());
281  libmesh_assert( _time_evolving[var] == 0 ||
282  _time_evolving[var] == 1 ||
283  _time_evolving[var] == 2 );
284  return _time_evolving[var];
285  }
286 
295  virtual bool eulerian_residual (bool request_jacobian,
296  DiffContext &) {
297  return request_jacobian;
298  }
299 
319  virtual bool mass_residual (bool request_jacobian,
320  DiffContext &) {
321  return request_jacobian;
322  }
323 
336  virtual bool side_mass_residual (bool request_jacobian,
337  DiffContext &) {
338  return request_jacobian;
339  }
340 
357  virtual bool nonlocal_mass_residual (bool request_jacobian,
358  DiffContext & c);
359 
375  virtual bool damping_residual (bool request_jacobian,
376  DiffContext &) {
377  return request_jacobian;
378  }
379 
392  virtual bool side_damping_residual (bool request_jacobian,
393  DiffContext &) {
394  return request_jacobian;
395  }
396 
407  virtual bool nonlocal_damping_residual (bool request_jacobian,
408  DiffContext &) {
409  return request_jacobian;
410  }
411 
412  /*
413  * Prepares the result of a build_context() call for use.
414  *
415  * Most FEMSystem-based problems will need to reimplement this in order to
416  * call FE::get_*() as their particular physics requires.
417  */
418  virtual void init_context(DiffContext &) {}
419 
443  virtual void set_mesh_system(System * sys);
444 
450  const System * get_mesh_system() const;
451 
457 
472  virtual void set_mesh_x_var(unsigned int var);
473 
478  unsigned int get_mesh_x_var() const;
479 
484  virtual void set_mesh_y_var(unsigned int var);
485 
490  unsigned int get_mesh_y_var() const;
491 
496  virtual void set_mesh_z_var(unsigned int var);
497 
502  unsigned int get_mesh_z_var() const;
503 
509  bool _eulerian_time_deriv (bool request_jacobian,
510  DiffContext &);
511 
513  { return !_first_order_vars.empty(); }
514 
518  const std::set<unsigned int> & get_first_order_vars() const
519  { return _first_order_vars; }
520 
521  bool is_first_order_var( unsigned int var ) const
522  { return _first_order_vars.find(var) != _first_order_vars.end(); }
523 
524 
526  { return !_second_order_vars.empty(); }
527 
531  const std::set<unsigned int> & get_second_order_vars() const
532  { return _second_order_vars; }
533 
534  bool is_second_order_var( unsigned int var ) const
535  { return _second_order_vars.find(var) != _second_order_vars.end(); }
536 
537 
538 protected:
539 
544 
549 
555  std::vector<unsigned int> _time_evolving;
556 
560  std::set<unsigned int> _first_order_vars;
561 
565  std::set<unsigned int> _second_order_vars;
566 
572  std::map<unsigned int,unsigned int> _second_order_dot_vars;
573 
574 };
575 
576 // ------------------------------------------------------------
577 // DifferentiablePhysics inline methods
578 
579 
580 inline
582 {
583  // For now we assume that we're doing fully coupled mesh motion
584  // if (sys && sys != this)
585  // libmesh_not_implemented();
586 
587  // For the foreseeable future we'll assume that we keep these
588  // Systems in the same EquationSystems
589  // libmesh_assert_equal_to (&this->get_equation_systems(),
590  // &sys->get_equation_systems());
591 
592  // And for the immediate future this code may not even work
593  libmesh_experimental();
594 
595  _mesh_sys = sys;
596 }
597 
598 
599 
600 inline
602 {
603  _mesh_x_var = var;
604 }
605 
606 
607 
608 inline
610 {
611  _mesh_y_var = var;
612 }
613 
614 
615 
616 inline
618 {
619  _mesh_z_var = var;
620 }
621 
622 
623 
624 inline
626 {
627  return _mesh_sys;
628 }
629 
630 inline
632 {
633  return _mesh_sys;
634 }
635 
636 inline
638 {
639  return _mesh_x_var;
640 }
641 
642 inline
644 {
645  return _mesh_y_var;
646 }
647 
648 inline
650 {
651  return _mesh_z_var;
652 }
653 
654 
655 
656 } // namespace libMesh
657 
658 
659 #endif // LIBMESH_DIFF_PHYSICS_H
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::DifferentiablePhysics::side_constraint
virtual bool side_constraint(bool request_jacobian, DiffContext &)
Adds the constraint contribution on side of elem to elem_residual.
Definition: diff_physics.h:192
libMesh::invalid_uint
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:249
libMesh::DifferentiablePhysics::_mesh_x_var
unsigned int _mesh_x_var
Variables from which to acquire moving mesh information.
Definition: diff_physics.h:548
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::DifferentiablePhysics::set_mesh_system
virtual void set_mesh_system(System *sys)
Tells the DifferentiablePhysics that system sys contains the isoparametric Lagrangian variables which...
Definition: diff_physics.h:581
libMesh::DifferentiablePhysics::set_mesh_z_var
virtual void set_mesh_z_var(unsigned int var)
Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the z...
Definition: diff_physics.h:617
libMesh::DifferentiablePhysics
This class provides a specific system class.
Definition: diff_physics.h:76
libMesh::DifferentiablePhysics::is_first_order_var
bool is_first_order_var(unsigned int var) const
Definition: diff_physics.h:521
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::DifferentiablePhysics::nonlocal_constraint
virtual bool nonlocal_constraint(bool request_jacobian, DiffContext &)
Adds any nonlocal constraint contributions (e.g.
Definition: diff_physics.h:228
libMesh::DifferentiablePhysics::side_damping_residual
virtual bool side_damping_residual(bool request_jacobian, DiffContext &)
Subtracts a damping vector contribution on side of elem from elem_residual.
Definition: diff_physics.h:392
libMesh::DifferentiablePhysics::set_mesh_x_var
virtual void set_mesh_x_var(unsigned int var)
Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the x...
Definition: diff_physics.h:601
libMesh::DifferentiablePhysics::_mesh_sys
System * _mesh_sys
System from which to acquire moving mesh information.
Definition: diff_physics.h:543
libMesh::DifferentiablePhysics::_second_order_dot_vars
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...
Definition: diff_physics.h:572
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::DifferentiablePhysics::set_mesh_y_var
virtual void set_mesh_y_var(unsigned int var)
Tells the DifferentiablePhysics that variable var from the mesh system should be used to update the y...
Definition: diff_physics.h:609
libMesh::DifferentiablePhysics::nonlocal_time_derivative
virtual bool nonlocal_time_derivative(bool request_jacobian, DiffContext &)
Adds any nonlocal time derivative contributions (e.g.
Definition: diff_physics.h:210
libMesh::DifferentiablePhysics::get_mesh_system
const System * get_mesh_system() const
Definition: diff_physics.h:625
libMesh::DifferentiablePhysics::element_constraint
virtual bool element_constraint(bool request_jacobian, DiffContext &)
Adds the constraint contribution on elem to elem_residual.
Definition: diff_physics.h:143
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::DifferentiablePhysics::is_second_order_var
bool is_second_order_var(unsigned int var) const
Definition: diff_physics.h:534
libMesh::DifferentiablePhysics::_mesh_y_var
unsigned int _mesh_y_var
Definition: diff_physics.h:548
libMesh::DifferentiablePhysics::get_second_order_vars
const std::set< unsigned int > & get_second_order_vars() const
Definition: diff_physics.h:531
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::DifferentiablePhysics::get_mesh_x_var
unsigned int get_mesh_x_var() const
Definition: diff_physics.h:637
libMesh::DifferentiablePhysics::side_mass_residual
virtual bool side_mass_residual(bool request_jacobian, DiffContext &)
Subtracts a mass vector contribution on side of elem from elem_residual.
Definition: diff_physics.h:336
libMesh::DifferentiablePhysics::DifferentiablePhysics
DifferentiablePhysics()
Constructor.
Definition: diff_physics.h:84
libMesh::DiffContext
This class provides all data required for a physics package (e.g.
Definition: diff_context.h:55
libMesh::DifferentiablePhysics::have_first_order_vars
bool have_first_order_vars() const
Definition: diff_physics.h:512
libMesh::DifferentiablePhysics::get_mesh_z_var
unsigned int get_mesh_z_var() const
Definition: diff_physics.h:649
libMesh::DifferentiablePhysics::_mesh_z_var
unsigned int _mesh_z_var
Definition: diff_physics.h:548
libMesh::DifferentiablePhysics::clear_physics
virtual void clear_physics()
Clear any data structures associated with the physics.
Definition: diff_physics.C:33
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::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::DifferentiablePhysics::have_second_order_vars
bool have_second_order_vars() const
Definition: diff_physics.h:525
libMesh::DifferentiablePhysics::get_first_order_vars
const std::set< unsigned int > & get_first_order_vars() const
Definition: diff_physics.h:518
libMesh::DifferentiablePhysics::init_context
virtual void init_context(DiffContext &)
Definition: diff_physics.h:418
libMesh::DifferentiablePhysics::mass_residual
virtual bool mass_residual(bool request_jacobian, DiffContext &)
Subtracts a mass vector contribution on elem from elem_residual.
Definition: diff_physics.h:319
libMesh::DifferentiablePhysics::side_time_derivative
virtual bool side_time_derivative(bool request_jacobian, DiffContext &)
Adds the time derivative contribution on side of elem to elem_residual.
Definition: diff_physics.h:172
libMesh::DifferentiablePhysics::get_mesh_y_var
unsigned int get_mesh_y_var() const
Definition: diff_physics.h:643
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::DifferentiablePhysics::clone_physics
virtual std::unique_ptr< DifferentiablePhysics > clone_physics()=0
Copy of this object.
libMesh::DifferentiablePhysics::damping_residual
virtual bool damping_residual(bool request_jacobian, DiffContext &)
Subtracts a damping vector contribution on elem from elem_residual.
Definition: diff_physics.h:375
libMesh::DifferentiablePhysics::compute_internal_sides
bool compute_internal_sides
compute_internal_sides is false by default, indicating that side_* computations will only be done on ...
Definition: diff_physics.h:154
libMesh::DifferentiablePhysics::nonlocal_damping_residual
virtual bool nonlocal_damping_residual(bool request_jacobian, DiffContext &)
Subtracts any nonlocal damping vector contributions (e.g.
Definition: diff_physics.h:407