dof_map.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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_DOF_MAP_H
21 #define LIBMESH_DOF_MAP_H
22 
23 // Local Includes
24 #include "libmesh/libmesh_common.h"
25 #include "libmesh/auto_ptr.h" // deprecated
27 #include "libmesh/libmesh.h" // libMesh::invalid_uint
28 #include "libmesh/variable.h"
29 #include "libmesh/threads.h"
31 #include "libmesh/elem_range.h"
35 #include "libmesh/point.h"
36 
37 #ifdef LIBMESH_FORWARD_DECLARE_ENUMS
38 namespace libMesh
39 {
40 enum Order : int;
41 }
42 #else
43 #include "libmesh/enum_order.h"
44 #endif
45 
46 // C++ Includes
47 #include <algorithm>
48 #include <cstddef>
49 #include <iterator>
50 #include <map>
51 #include <string>
52 #include <vector>
53 #include <memory>
54 
55 namespace libMesh
56 {
57 
58 // Forward Declarations
59 class CouplingMatrix;
60 class DefaultCoupling;
61 class DirichletBoundary;
62 class DirichletBoundaries;
63 class DofMap;
64 class DofObject;
65 class Elem;
66 class FEType;
67 class MeshBase;
68 class PeriodicBoundaryBase;
69 class PeriodicBoundaries;
70 class System;
71 template <typename T> class DenseVectorBase;
72 template <typename T> class DenseVector;
73 template <typename T> class DenseMatrix;
74 template <typename T> class SparseMatrix;
75 template <typename T> class NumericVector;
76 
77 
78 
79 // ------------------------------------------------------------
80 // Do we need constraints for anything?
81 
82 #if defined(LIBMESH_ENABLE_AMR) || \
83  defined(LIBMESH_ENABLE_PERIODIC) || \
84  defined(LIBMESH_ENABLE_DIRICHLET)
85 # define LIBMESH_ENABLE_CONSTRAINTS 1
86 #endif
87 
88 // ------------------------------------------------------------
89 // AMR constraint matrix types
90 
91 #ifdef LIBMESH_ENABLE_CONSTRAINTS
92 
95 typedef std::map<dof_id_type, Real,
96  std::less<dof_id_type>,
98 
105 class DofConstraints : public std::map<dof_id_type,
106  DofConstraintRow,
107  std::less<dof_id_type>,
108  Threads::scalable_allocator<std::pair<const dof_id_type, DofConstraintRow>>>
109 {
110 };
111 
118  public std::map<dof_id_type, Number,
119  std::less<dof_id_type>,
120  Threads::scalable_allocator<std::pair<const dof_id_type, Number>>>
121 {
122 };
123 
129  public std::map<unsigned int, DofConstraintValueMap,
130  std::less<unsigned int>,
131  Threads::scalable_allocator
132  <std::pair<const unsigned int, DofConstraintValueMap>>>
133 {
134 };
135 
136 #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
137 
143 typedef std::map<const Node *, Real,
144  std::less<const Node *>,
146 
153 class NodeConstraints : public std::map<const Node *,
154  std::pair<NodeConstraintRow,Point>,
155  std::less<const Node *>,
156  Threads::scalable_allocator<std::pair<const Node * const, std::pair<NodeConstraintRow,Point>>>>
157 {
158 };
159 #endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
160 
161 #endif // LIBMESH_ENABLE_CONSTRAINTS
162 
163 
164 
176 class DofMap : public ReferenceCountedObject<DofMap>,
177  public ParallelObject
178 {
179 public:
180 
186  explicit
187  DofMap(const unsigned int sys_number,
188  MeshBase & mesh);
189 
193  ~DofMap();
194 
200  {
201  public:
203 
207  virtual void augment_sparsity_pattern (SparsityPattern::Graph & sparsity,
208  std::vector<dof_id_type> & n_nz,
209  std::vector<dof_id_type> & n_oz) = 0;
210  };
211 
217  {
218  public:
219  virtual ~AugmentSendList () {}
220 
224  virtual void augment_send_list (std::vector<dof_id_type> & send_list) = 0;
225  };
226 
232  void attach_matrix (SparseMatrix<Number> & matrix);
233 
238  bool is_attached (SparseMatrix<Number> & matrix);
239 
245  void distribute_dofs (MeshBase &);
246 
252  void compute_sparsity (const MeshBase &);
253 
257  void clear_sparsity();
258 
273 
278  void add_default_ghosting();
279 
304  void add_coupling_functor(GhostingFunctor & coupling_functor,
305  bool to_mesh = true);
306 
312  void remove_coupling_functor(GhostingFunctor & coupling_functor);
313 
317  std::set<GhostingFunctor *>::const_iterator coupling_functors_begin() const
318  { return _coupling_functors.begin(); }
319 
323  std::set<GhostingFunctor *>::const_iterator coupling_functors_end() const
324  { return _coupling_functors.end(); }
325 
330 
354  void add_algebraic_ghosting_functor(GhostingFunctor & evaluable_functor,
355  bool to_mesh = true);
356 
362  void remove_algebraic_ghosting_functor(GhostingFunctor & evaluable_functor);
363 
367  std::set<GhostingFunctor *>::const_iterator algebraic_ghosting_functors_begin() const
368  { return _algebraic_ghosting_functors.begin(); }
369 
373  std::set<GhostingFunctor *>::const_iterator algebraic_ghosting_functors_end() const
374  { return _algebraic_ghosting_functors.end(); }
375 
380 
392  {
394  }
395 
407  std::vector<dof_id_type> & n_nz,
408  std::vector<dof_id_type> & n_oz,
409  void *),
410  void * context = nullptr)
412 
421  {
422  _augment_send_list = &asl;
423  }
424 
429  void attach_extra_send_list_function(void (*func)(std::vector<dof_id_type> &, void *),
430  void * context = nullptr)
432 
439  void prepare_send_list ();
440 
450  const std::vector<dof_id_type> & get_send_list() const { return _send_list; }
451 
459  const std::vector<dof_id_type> & get_n_nz() const
460  {
461  libmesh_assert(_n_nz);
462  return *_n_nz;
463  }
464 
472  const std::vector<dof_id_type> & get_n_oz() const
473  {
474  libmesh_assert(_n_oz);
475  return *_n_oz;
476  }
477 
478  // /**
479  // * Add an unknown of order \p order and finite element type
480  // * \p type to the system of equations.
481  // */
482  // void add_variable (const Variable & var);
483 
488  void add_variable_group (const VariableGroup & var_group);
489 
496  void set_error_on_cyclic_constraint(bool error_on_cyclic_constraint);
497 
501  const VariableGroup & variable_group (const unsigned int c) const;
502 
506  const Variable & variable (const unsigned int c) const;
507 
511  Order variable_order (const unsigned int c) const;
512 
516  Order variable_group_order (const unsigned int vg) const;
517 
521  const FEType & variable_type (const unsigned int c) const;
522 
526  const FEType & variable_group_type (const unsigned int vg) const;
527 
533  unsigned int n_variable_groups() const
534  { return cast_int<unsigned int>(_variable_groups.size()); }
535 
541  unsigned int n_variables() const
542  { return cast_int<unsigned int>(_variables.size()); }
543 
550  {
551 #ifdef LIBMESH_ENABLE_BLOCKED_STORAGE
552  return ((this->n_variable_groups() == 1) && (this->n_variables() > 1));
553 #else
554  return false;
555 #endif
556  }
557 
562  unsigned int block_size() const
563  {
564 #ifdef LIBMESH_ENABLE_BLOCKED_STORAGE
565  return (this->has_blocked_representation() ? this->n_variables() : 1);
566 #else
567  return 1;
568 #endif
569  }
570 
574  dof_id_type n_dofs() const { return _n_dfs; }
575 
580 
585  { return this->n_dofs_on_processor (this->processor_id()); }
586 
590  dof_id_type n_dofs_on_processor(const processor_id_type proc) const
591  {
592  libmesh_assert_less (proc, _first_df.size());
593  return cast_int<dof_id_type>(_end_df[proc] - _first_df[proc]);
594  }
595 
600  { libmesh_assert_less (proc, _first_df.size()); return _first_df[proc]; }
601 
603  { return this->first_dof(this->processor_id()); }
604 
605 #ifdef LIBMESH_ENABLE_AMR
606 
609  dof_id_type first_old_dof(const processor_id_type proc) const
610  { libmesh_assert_less (proc, _first_old_df.size()); return _first_old_df[proc]; }
611 
613  { return this->first_old_dof(this->processor_id()); }
614 
615 #endif //LIBMESH_ENABLE_AMR
616 
623 #ifdef LIBMESH_ENABLE_DEPRECATED
624  dof_id_type last_dof(const processor_id_type proc) const
625  {
626  libmesh_deprecated();
627  libmesh_assert_less (proc, _end_df.size());
628  return cast_int<dof_id_type>(_end_df[proc] - 1);
629  }
630 
632  { return this->last_dof(this->processor_id()); }
633 #endif
634 
641  dof_id_type end_dof(const processor_id_type proc) const
642  { libmesh_assert_less (proc, _end_df.size()); return _end_df[proc]; }
643 
645  { return this->end_dof(this->processor_id()); }
646 
651  { std::vector<dof_id_type>::const_iterator ub =
652  std::upper_bound(_end_df.begin(), _end_df.end(), dof);
653  libmesh_assert (ub != _end_df.end());
654  return cast_int<processor_id_type>(ub - _end_df.begin());
655  }
656 
657 #ifdef LIBMESH_ENABLE_AMR
658 
665  { libmesh_assert_less (proc, _end_old_df.size()); return _end_old_df[proc]; }
666 
668  { return this->end_old_dof(this->processor_id()); }
669 
670 #endif //LIBMESH_ENABLE_AMR
671 
676  void dof_indices (const Elem * const elem,
677  std::vector<dof_id_type> & di) const;
678 
684  void dof_indices (const Elem * const elem,
685  std::vector<dof_id_type> & di,
686  const unsigned int vn,
687  int p_level = -12345) const;
688 
693  void dof_indices (const Node * const node,
694  std::vector<dof_id_type> & di) const;
695 
700  void dof_indices (const Node * const node,
701  std::vector<dof_id_type> & di,
702  const unsigned int vn) const;
703 
712  void SCALAR_dof_indices (std::vector<dof_id_type> & di,
713  const unsigned int vn,
714  const bool old_dofs=false) const;
715 
723  bool semilocal_index (dof_id_type dof_index) const;
724 
732  bool all_semilocal_indices (const std::vector<dof_id_type> & dof_indices) const;
733 
738  bool local_index (dof_id_type dof_index) const
739  { return (dof_index >= this->first_dof()) && (dof_index < this->end_dof()); }
740 
746  template <typename DofObjectSubclass>
747  bool is_evaluable(const DofObjectSubclass & obj,
748  unsigned int var_num = libMesh::invalid_uint) const;
749 
757  void set_implicit_neighbor_dofs(bool implicit_neighbor_dofs);
758 
765  bool use_coupled_neighbor_dofs(const MeshBase & mesh) const;
766 
778  const std::vector<dof_id_type> & dof_indices,
779  DenseVectorBase<Number> & Ue) const;
780 
785  void local_variable_indices(std::vector<dof_id_type> & idx,
786  const MeshBase & mesh,
787  unsigned int var_num) const;
788 
789 #ifdef LIBMESH_ENABLE_CONSTRAINTS
790 
791  //--------------------------------------------------------------------
792  // Constraint-specific methods
798 
804 
805 #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
806 
811  { return cast_int<dof_id_type>(_node_constraints.size()); }
812 #endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
813 
819  void create_dof_constraints (const MeshBase &, Real time=0);
820 
825 
829  void scatter_constraints (MeshBase &);
830 
845  std::set<dof_id_type> & unexpanded_dofs,
846  bool look_for_constrainees);
847 
855  void process_constraints (MeshBase &);
856 
863 
868  void add_constraint_row (const dof_id_type dof_number,
869  const DofConstraintRow & constraint_row,
870  const Number constraint_rhs,
871  const bool forbid_constraint_overwrite);
872 
883  void add_adjoint_constraint_row (const unsigned int qoi_index,
884  const dof_id_type dof_number,
885  const DofConstraintRow & constraint_row,
886  const Number constraint_rhs,
887  const bool forbid_constraint_overwrite);
888 
894  void add_constraint_row (const dof_id_type dof_number,
895  const DofConstraintRow & constraint_row,
896  const bool forbid_constraint_overwrite = true)
897  { add_constraint_row(dof_number, constraint_row, 0., forbid_constraint_overwrite); }
898 
902  DofConstraints::const_iterator constraint_rows_begin() const
903  { return _dof_constraints.begin(); }
904 
908  DofConstraints::const_iterator constraint_rows_end() const
909  { return _dof_constraints.end(); }
910 
912  {
913  libmesh_assert(_stashed_dof_constraints.empty());
915  }
916 
918  {
919  libmesh_assert(_dof_constraints.empty());
921  }
922 
923 #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
924 
927  NodeConstraints::const_iterator node_constraint_rows_begin() const
928  { return _node_constraints.begin(); }
929 
933  NodeConstraints::const_iterator node_constraint_rows_end() const
934  { return _node_constraints.end(); }
935 #endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
936 
941  bool is_constrained_dof (const dof_id_type dof) const;
942 
947  bool has_heterogenous_adjoint_constraints (const unsigned int qoi_num) const;
948 
954  Number has_heterogenous_adjoint_constraint (const unsigned int qoi_num,
955  const dof_id_type dof) const;
956 
962 
967  bool is_constrained_node (const Node * node) const;
968 
975  void print_dof_constraints(std::ostream & os=libMesh::out,
976  bool print_nonlocal=false) const;
977 
983  std::string get_local_constraints(bool print_nonlocal=false) const;
984 
985 
994  std::pair<Real, Real> max_constraint_error(const System & system,
995  NumericVector<Number> * v = nullptr) const;
996 
997 #endif // LIBMESH_ENABLE_CONSTRAINTS
998 
999  //--------------------------------------------------------------------
1000  // Constraint-specific methods
1001  // Some of these methods are enabled (but inlined away to nothing)
1002  // when constraints are disabled at configure-time. This is to
1003  // increase API compatibility of user code with different library
1004  // builds.
1005 
1020  std::vector<dof_id_type> & elem_dofs,
1021  bool asymmetric_constraint_rows = true) const;
1022 
1030  std::vector<dof_id_type> & row_dofs,
1031  std::vector<dof_id_type> & col_dofs,
1032  bool asymmetric_constraint_rows = true) const;
1033 
1038  std::vector<dof_id_type> & dofs,
1039  bool asymmetric_constraint_rows = true) const;
1040 
1050  DenseVector<Number> & rhs,
1051  std::vector<dof_id_type> & elem_dofs,
1052  bool asymmetric_constraint_rows = true) const;
1053 
1078  DenseVector<Number> & rhs,
1079  std::vector<dof_id_type> & elem_dofs,
1080  bool asymmetric_constraint_rows = true,
1081  int qoi_index = -1) const;
1082 
1105  DenseVector<Number> & rhs,
1106  std::vector<dof_id_type> & elem_dofs,
1107  bool asymmetric_constraint_rows = true,
1108  int qoi_index = -1) const;
1109 
1110 
1111 
1121  DenseVector<Number> & w,
1122  std::vector<dof_id_type> & row_dofs,
1123  bool asymmetric_constraint_rows = true) const;
1124 
1131  void constrain_nothing (std::vector<dof_id_type> & dofs) const;
1132 
1146  void enforce_constraints_exactly (const System & system,
1147  NumericVector<Number> * v = nullptr,
1148  bool homogeneous = false) const;
1149 
1157  unsigned int q) const;
1158 
1159 
1160 
1161 #ifdef LIBMESH_ENABLE_PERIODIC
1162 
1163  //--------------------------------------------------------------------
1164  // PeriodicBoundary-specific methods
1165 
1169  void add_periodic_boundary (const PeriodicBoundaryBase & periodic_boundary);
1170 
1177  void add_periodic_boundary (const PeriodicBoundaryBase & boundary, const PeriodicBoundaryBase & inverse_boundary);
1178 
1183  bool is_periodic_boundary (const boundary_id_type boundaryid) const;
1184 
1186  {
1187  return _periodic_boundaries.get();
1188  }
1189 
1190 #endif // LIBMESH_ENABLE_PERIODIC
1191 
1192 
1193 #ifdef LIBMESH_ENABLE_DIRICHLET
1194 
1195  //--------------------------------------------------------------------
1196  // DirichletBoundary-specific methods
1197 
1201  void add_dirichlet_boundary (const DirichletBoundary & dirichlet_boundary);
1202 
1208  void add_adjoint_dirichlet_boundary (const DirichletBoundary & dirichlet_boundary,
1209  unsigned int q);
1210 
1214  void remove_dirichlet_boundary (const DirichletBoundary & dirichlet_boundary);
1215 
1220  void remove_adjoint_dirichlet_boundary (const DirichletBoundary & dirichlet_boundary,
1221  unsigned int q);
1222 
1224  {
1225  return _dirichlet_boundaries.get();
1226  }
1227 
1229  {
1230  return _dirichlet_boundaries.get();
1231  }
1232 
1233  bool has_adjoint_dirichlet_boundaries(unsigned int q) const;
1234 
1235  const DirichletBoundaries *
1236  get_adjoint_dirichlet_boundaries(unsigned int q) const;
1237 
1239  get_adjoint_dirichlet_boundaries(unsigned int q);
1240 
1241 #endif // LIBMESH_ENABLE_DIRICHLET
1242 
1243 
1244 #ifdef LIBMESH_ENABLE_AMR
1245 
1246  //--------------------------------------------------------------------
1247  // AMR-specific methods
1248 
1257  // void augment_send_list_for_projection(const MeshBase &);
1258 
1265  void old_dof_indices (const Elem * const elem,
1266  std::vector<dof_id_type> & di,
1267  const unsigned int vn = libMesh::invalid_uint) const;
1271  dof_id_type n_old_dofs() const { return _n_old_dfs; }
1272 
1278  void constrain_p_dofs (unsigned int var,
1279  const Elem * elem,
1280  unsigned int s,
1281  unsigned int p);
1282 
1283 #endif // LIBMESH_ENABLE_AMR
1284 
1288  void reinit (MeshBase & mesh);
1289 
1294  void clear ();
1295 
1299  void print_info(std::ostream & os=libMesh::out) const;
1300 
1304  std::string get_info() const;
1305 
1320 
1324  unsigned int sys_number() const;
1325 
1326 private:
1327 
1338  void _dof_indices (const Elem & elem,
1339  int p_level,
1340  std::vector<dof_id_type> & di,
1341  const unsigned int vg,
1342  const unsigned int vig,
1343  const Node * const * nodes,
1344  unsigned int n_nodes
1345 #ifdef DEBUG
1346  ,
1347  const unsigned int v,
1348  std::size_t & tot_size
1349 #endif
1350  ) const;
1351 
1355  std::unique_ptr<SparsityPattern::Build> build_sparsity(const MeshBase & mesh) const;
1356 
1360  void invalidate_dofs(MeshBase & mesh) const;
1361 
1365  DofObject * node_ptr(MeshBase & mesh, dof_id_type i) const;
1366 
1370  DofObject * elem_ptr(MeshBase & mesh, dof_id_type i) const;
1371 
1375  typedef DofObject * (DofMap::*dofobject_accessor)
1376  (MeshBase & mesh, dof_id_type i) const;
1377 
1381  template<typename iterator_type>
1382  void set_nonlocal_dof_objects(iterator_type objects_begin,
1383  iterator_type objects_end,
1384  MeshBase & mesh,
1385  dofobject_accessor objects);
1386 
1395  void distribute_local_dofs_var_major (dof_id_type & next_free_dof,
1396  MeshBase & mesh);
1397 
1409  void distribute_local_dofs_node_major (dof_id_type & next_free_dof,
1410  MeshBase & mesh);
1411 
1412  /*
1413  * A utility method for obtaining a set of elements to ghost along
1414  * with merged coupling matrices.
1415  */
1416  static void
1418  std::set<CouplingMatrix *> & temporary_coupling_matrices,
1419  const std::set<GhostingFunctor *>::iterator & gf_begin,
1420  const std::set<GhostingFunctor *>::iterator & gf_end,
1421  const MeshBase::const_element_iterator & elems_begin,
1422  const MeshBase::const_element_iterator & elems_end,
1423  processor_id_type p);
1424 
1430 
1431 #ifdef LIBMESH_ENABLE_CONSTRAINTS
1432 
1444  std::vector<dof_id_type> & elem_dofs,
1445  const bool called_recursively=false) const;
1446 
1463  DenseVector<Number> & H,
1464  std::vector<dof_id_type> & elem_dofs,
1465  int qoi_index = -1,
1466  const bool called_recursively=false) const;
1467 
1472  void find_connected_dofs (std::vector<dof_id_type> & elem_dofs) const;
1473 
1478  void find_connected_dof_objects (std::vector<const DofObject *> & objs) const;
1479 
1486 
1487 #endif // LIBMESH_ENABLE_CONSTRAINTS
1488 
1494 
1498  std::vector<Variable> _variables;
1499 
1503  std::vector<VariableGroup> _variable_groups;
1504 
1508  std::vector<unsigned int> _variable_group_numbers;
1509 
1513  const unsigned int _sys_number;
1514 
1519 
1525  std::vector<SparseMatrix<Number> * > _matrices;
1526 
1530  std::vector<dof_id_type> _first_df;
1531 
1535  std::vector<dof_id_type> _end_df;
1536 
1541  std::vector<dof_id_type> _first_scalar_df;
1542 
1547  std::vector<dof_id_type> _send_list;
1548 
1553 
1558  std::vector<dof_id_type> & n_nz,
1559  std::vector<dof_id_type> & n_oz,
1560  void *);
1565 
1570 
1574  void (*_extra_send_list_function)(std::vector<dof_id_type> &, void *);
1575 
1580 
1587  std::unique_ptr<DefaultCoupling> _default_coupling;
1588 
1595  std::unique_ptr<DefaultCoupling> _default_evaluating;
1596 
1605  std::set<GhostingFunctor *> _algebraic_ghosting_functors;
1606 
1618  std::set<GhostingFunctor *> _coupling_functors;
1619 
1625 
1630  std::unique_ptr<SparsityPattern::Build> _sp;
1631 
1638  std::vector<dof_id_type> * _n_nz;
1639 
1644  std::vector<dof_id_type> * _n_oz;
1645 
1650 
1656 
1657 #ifdef LIBMESH_ENABLE_AMR
1658 
1663 
1667  std::vector<dof_id_type> _first_old_df;
1668 
1672  std::vector<dof_id_type> _end_old_df;
1673 
1678  std::vector<dof_id_type> _first_old_scalar_df;
1679 
1680 #endif
1681 
1682 #ifdef LIBMESH_ENABLE_CONSTRAINTS
1683 
1688 
1690 
1692 #endif
1693 
1694 #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
1695 
1699 #endif // LIBMESH_ENABLE_NODE_CONSTRAINTS
1700 
1701 
1702 #ifdef LIBMESH_ENABLE_PERIODIC
1703 
1707  std::unique_ptr<PeriodicBoundaries> _periodic_boundaries;
1708 #endif
1709 
1710 #ifdef LIBMESH_ENABLE_DIRICHLET
1711 
1716  const DirichletBoundary & boundary) const;
1721  std::unique_ptr<DirichletBoundaries> _dirichlet_boundaries;
1722 
1727  std::vector<DirichletBoundaries *> _adjoint_dirichlet_boundaries;
1728 #endif
1729 
1731 
1738 };
1739 
1740 
1741 // ------------------------------------------------------------
1742 // Dof Map inline member functions
1743 inline
1744 unsigned int DofMap::sys_number() const
1745 {
1746  return _sys_number;
1747 }
1748 
1749 
1750 
1751 inline
1752 const VariableGroup & DofMap::variable_group (const unsigned int g) const
1753 {
1754  libmesh_assert_less (g, _variable_groups.size());
1755 
1756  return _variable_groups[g];
1757 }
1758 
1759 
1760 
1761 inline
1762 const Variable & DofMap::variable (const unsigned int c) const
1763 {
1764  libmesh_assert_less (c, _variables.size());
1765 
1766  return _variables[c];
1767 }
1768 
1769 
1770 
1771 inline
1772 Order DofMap::variable_order (const unsigned int c) const
1773 {
1774  libmesh_assert_less (c, _variables.size());
1775 
1776  return _variables[c].type().order;
1777 }
1778 
1779 
1780 
1781 inline
1782 Order DofMap::variable_group_order (const unsigned int vg) const
1783 {
1784  libmesh_assert_less (vg, _variable_groups.size());
1785 
1786  return _variable_groups[vg].type().order;
1787 }
1788 
1789 
1790 
1791 inline
1792 const FEType & DofMap::variable_type (const unsigned int c) const
1793 {
1794  libmesh_assert_less (c, _variables.size());
1795 
1796  return _variables[c].type();
1797 }
1798 
1799 
1800 
1801 inline
1802 const FEType & DofMap::variable_group_type (const unsigned int vg) const
1803 {
1804  libmesh_assert_less (vg, _variable_groups.size());
1805 
1806  return _variable_groups[vg].type();
1807 }
1808 
1809 
1810 
1811 inline
1813 #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
1814  node
1815 #endif
1816  ) const
1817 {
1818 #ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
1819  if (_node_constraints.count(node))
1820  return true;
1821 #endif
1822 
1823  return false;
1824 }
1825 
1826 #ifdef LIBMESH_ENABLE_CONSTRAINTS
1827 
1828 inline
1830 {
1831  if (_dof_constraints.count(dof))
1832  return true;
1833 
1834  return false;
1835 }
1836 
1837 
1838 inline
1839 bool DofMap::has_heterogenous_adjoint_constraints (const unsigned int qoi_num) const
1840 {
1841  AdjointDofConstraintValues::const_iterator it =
1842  _adjoint_constraint_values.find(qoi_num);
1843  if (it == _adjoint_constraint_values.end())
1844  return false;
1845  if (it->second.empty())
1846  return false;
1847 
1848  return true;
1849 }
1850 
1851 
1852 inline
1854  const dof_id_type dof) const
1855 {
1856  AdjointDofConstraintValues::const_iterator it =
1857  _adjoint_constraint_values.find(qoi_num);
1858  if (it != _adjoint_constraint_values.end())
1859  {
1860  DofConstraintValueMap::const_iterator rhsit =
1861  it->second.find(dof);
1862  if (rhsit == it->second.end())
1863  return 0;
1864  else
1865  return rhsit->second;
1866  }
1867 
1868  return 0;
1869 }
1870 
1871 
1872 
1873 inline
1875 {
1877 }
1878 
1879 
1880 
1881 #else
1882 
1883 //--------------------------------------------------------------------
1884 // Constraint-specific methods get inlined into nothing if
1885 // constraints are disabled, so there's no reason for users not to
1886 // use them.
1887 
1889  std::vector<dof_id_type> &,
1890  bool) const {}
1891 
1892 inline void DofMap::constrain_element_matrix (DenseMatrix<Number> &,
1893  std::vector<dof_id_type> &,
1894  std::vector<dof_id_type> &,
1895  bool) const {}
1896 
1897 inline void DofMap::constrain_element_vector (DenseVector<Number> &,
1898  std::vector<dof_id_type> &,
1899  bool) const {}
1900 
1901 inline void DofMap::constrain_element_matrix_and_vector (DenseMatrix<Number> &,
1902  DenseVector<Number> &,
1903  std::vector<dof_id_type> &,
1904  bool) const {}
1905 
1906 inline void DofMap::constrain_element_dyad_matrix (DenseVector<Number> &,
1907  DenseVector<Number> &,
1908  std::vector<dof_id_type> &,
1909  bool) const {}
1910 
1911 inline void DofMap::enforce_constraints_exactly (const System &,
1912  NumericVector<Number> *,
1913  bool = false) const {}
1914 
1915 inline void DofMap::enforce_adjoint_constraints_exactly (NumericVector<Number> &,
1916  unsigned int) const {}
1917 
1918 #endif // LIBMESH_ENABLE_CONSTRAINTS
1919 
1920 } // namespace libMesh
1921 
1922 #endif // LIBMESH_DOF_MAP_H
std::vector< VariableGroup > _variable_groups
Definition: dof_map.h:1503
void remove_adjoint_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary, unsigned int q)
void find_connected_dofs(std::vector< dof_id_type > &elem_dofs) const
Definition: dof_map.C:2633
std::unique_ptr< SparsityPattern::Build > _sp
Definition: dof_map.h:1630
Manages the family, order, etc. parameters for a given FE.
Definition: fe_type.h:179
std::string get_local_constraints(bool print_nonlocal=false) const
void constrain_element_dyad_matrix(DenseVector< Number > &v, DenseVector< Number > &w, std::vector< dof_id_type > &row_dofs, bool asymmetric_constraint_rows=true) const
bool _error_on_cyclic_constraint
Definition: dof_map.h:1493
bool _implicit_neighbor_dofs_initialized
Definition: dof_map.h:1736
void distribute_local_dofs_node_major(dof_id_type &next_free_dof, MeshBase &mesh)
Definition: dof_map.C:1163
void _dof_indices(const Elem &elem, int p_level, std::vector< dof_id_type > &di, const unsigned int vg, const unsigned int vig, const Node *const *nodes, unsigned int n_nodes #ifdef DEBUG, const unsigned int v, std::size_t &tot_size #endif) const
Definition: dof_map.C:2209
bool is_constrained_node(const Node *node) const
Definition: dof_map.h:1812
void local_variable_indices(std::vector< dof_id_type > &idx, const MeshBase &mesh, unsigned int var_num) const
Definition: dof_map.C:1076
unsigned int n_variable_groups() const
Definition: dof_map.h:533
void add_adjoint_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary, unsigned int q)
const unsigned int _sys_number
Definition: dof_map.h:1513
bool _implicit_neighbor_dofs
Definition: dof_map.h:1737
DofConstraintValueMap & get_primal_constraint_values()
Definition: dof_map.h:1874
void check_dirichlet_bcid_consistency(const MeshBase &mesh, const DirichletBoundary &boundary) const
dof_id_type n_local_dofs() const
Definition: dof_map.h:584
DefaultCoupling & default_coupling()
Definition: dof_map.h:329
const std::vector< dof_id_type > & get_n_oz() const
Definition: dof_map.h:472
A geometric point in (x,y,z) space associated with a DOF.
Definition: node.h:52
dof_id_type n_SCALAR_dofs() const
Definition: dof_map.h:579
std::set< GhostingFunctor * >::const_iterator coupling_functors_begin() const
Definition: dof_map.h:317
void build_constraint_matrix_and_vector(DenseMatrix< Number > &C, DenseVector< Number > &H, std::vector< dof_id_type > &elem_dofs, int qoi_index=-1, const bool called_recursively=false) const
const unsigned int invalid_uint
Definition: libmesh.h:245
dof_id_type n_dofs_on_processor(const processor_id_type proc) const
Definition: dof_map.h:590
processor_id_type dof_owner(const dof_id_type dof) const
Definition: dof_map.h:650
void scatter_constraints(MeshBase &)
void add_periodic_boundary(const PeriodicBoundaryBase &periodic_boundary)
void add_adjoint_constraint_row(const unsigned int qoi_index, const dof_id_type dof_number, const DofConstraintRow &constraint_row, const Number constraint_rhs, const bool forbid_constraint_overwrite)
void * _extra_sparsity_context
Definition: dof_map.h:1564
void extract_local_vector(const NumericVector< Number > &Ug, const std::vector< dof_id_type > &dof_indices, DenseVectorBase< Number > &Ue) const
Definition: dof_map.C:1848
void constrain_element_matrix_and_vector(DenseMatrix< Number > &matrix, DenseVector< Number > &rhs, std::vector< dof_id_type > &elem_dofs, bool asymmetric_constraint_rows=true) const
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition: dof_map.C:1930
void set_implicit_neighbor_dofs(bool implicit_neighbor_dofs)
Definition: dof_map.C:1675
void add_default_ghosting()
Definition: dof_map.C:1800
Maps between boundary ids and PeriodicBoundaryBase objects.
bool is_periodic_boundary(const boundary_id_type boundaryid) const
Definition: dof_map.C:219
Number has_heterogenous_adjoint_constraint(const unsigned int qoi_num, const dof_id_type dof) const
Definition: dof_map.h:1853
dof_id_type last_dof() const
Definition: dof_map.h:631
dof_id_type n_local_constrained_dofs() const
void remove_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
const FEType & variable_group_type(const unsigned int vg) const
Definition: dof_map.h:1802
NodeConstraints::const_iterator node_constraint_rows_begin() const
Definition: dof_map.h:927
std::vector< dof_id_type > _send_list
Definition: dof_map.h:1547
const FEType & variable_type(const unsigned int c) const
Definition: dof_map.h:1792
unsigned int block_size() const
Definition: dof_map.h:562
bool is_attached(SparseMatrix< Number > &matrix)
Definition: dof_map.C:298
void attach_matrix(SparseMatrix< Number > &matrix)
Definition: dof_map.C:262
The base class for all geometric element types.
Definition: elem.h:100
MeshBase & mesh
void gather_constraints(MeshBase &mesh, std::set< dof_id_type > &unexpanded_dofs, bool look_for_constrainees)
uint8_t processor_id_type
Definition: id_types.h:99
unsigned int n_variables() const
Definition: dof_map.h:541
DefaultCoupling & default_algebraic_ghosting()
Definition: dof_map.h:379
AugmentSparsityPattern * _augment_sparsity_pattern
Definition: dof_map.h:1552
std::unique_ptr< DirichletBoundaries > _dirichlet_boundaries
Definition: dof_map.h:1721
Class for specifying Dirichlet boundary conditions as constraints.
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
Definition: diff_context.h:40
std::set< GhostingFunctor * > _algebraic_ghosting_functors
Definition: dof_map.h:1605
std::vector< dof_id_type > _end_old_df
Definition: dof_map.h:1672
bool use_coupled_neighbor_dofs(const MeshBase &mesh) const
Definition: dof_map.C:1682
virtual void augment_send_list(std::vector< dof_id_type > &send_list)=0
dof_id_type n_old_dofs() const
Definition: dof_map.h:1271
void add_constraint_row(const dof_id_type dof_number, const DofConstraintRow &constraint_row, const bool forbid_constraint_overwrite=true)
Definition: dof_map.h:894
void add_coupling_functor(GhostingFunctor &coupling_functor, bool to_mesh=true)
Definition: dof_map.C:1809
std::vector< dof_id_type > _first_old_df
Definition: dof_map.h:1667
void old_dof_indices(const Elem *const elem, std::vector< dof_id_type > &di, const unsigned int vn=libMesh::invalid_uint) const
Definition: dof_map.C:2434
std::string get_info() const
Definition: dof_map.C:2703
void attach_extra_sparsity_object(DofMap::AugmentSparsityPattern &asp)
Definition: dof_map.h:391
unsigned int sys_number() const
Definition: dof_map.h:1744
void SCALAR_dof_indices(std::vector< dof_id_type > &di, const unsigned int vn, const bool old_dofs=false) const
Definition: dof_map.C:2348
Base class for Mesh.
Definition: mesh_base.h:77
std::vector< dof_id_type > _first_scalar_df
Definition: dof_map.h:1541
void enforce_adjoint_constraints_exactly(NumericVector< Number > &v, unsigned int q) const
AdjointDofConstraintValues _adjoint_constraint_values
Definition: dof_map.h:1691
std::vector< dof_id_type > * _n_nz
Definition: dof_map.h:1638
AugmentSendList * _augment_send_list
Definition: dof_map.h:1569
std::vector< dof_id_type > * _n_oz
Definition: dof_map.h:1644
void heterogenously_constrain_element_vector(const DenseMatrix< Number > &matrix, DenseVector< Number > &rhs, std::vector< dof_id_type > &elem_dofs, bool asymmetric_constraint_rows=true, int qoi_index=-1) const
bool need_full_sparsity_pattern
Definition: dof_map.h:1624
Manages the degrees of freedom (DOFs) in a simulation.
Definition: dof_map.h:176
const dof_id_type n_nodes
Definition: tecplot_io.C:68
dof_id_type end_old_dof() const
Definition: dof_map.h:667
dof_id_type n_dofs() const
Definition: dof_map.h:574
A variable which is solved for in a System of equations.
Definition: variable.h:49
void add_neighbors_to_send_list(MeshBase &mesh)
Definition: dof_map.C:1499
std::vector< dof_id_type > _first_old_scalar_df
Definition: dof_map.h:1678
const Variable & variable(const unsigned int c) const
Definition: dof_map.h:1762
int8_t boundary_id_type
Definition: id_types.h:51
bool has_adjoint_dirichlet_boundaries(unsigned int q) const
void(* _extra_sparsity_function)(SparsityPattern::Graph &, std::vector< dof_id_type > &n_nz, std::vector< dof_id_type > &n_oz, void *)
Definition: dof_map.h:1557
dof_id_type _n_SCALAR_dofs
Definition: dof_map.h:1655
PeriodicBoundaries * get_periodic_boundaries()
Definition: dof_map.h:1185
void set_nonlocal_dof_objects(iterator_type objects_begin, iterator_type objects_end, MeshBase &mesh, dofobject_accessor objects)
Definition: dof_map.C:321
void add_constraint_row(const dof_id_type dof_number, const DofConstraintRow &constraint_row, const Number constraint_rhs, const bool forbid_constraint_overwrite)
DofConstraints::const_iterator constraint_rows_begin() const
Definition: dof_map.h:902
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:92
NodeConstraints::const_iterator node_constraint_rows_end() const
Definition: dof_map.h:933
std::unique_ptr< SparsityPattern::Build > build_sparsity(const MeshBase &mesh) const
Definition: dof_map.C:58
dof_id_type n_constrained_nodes() const
Definition: dof_map.h:810
void print_dof_constraints(std::ostream &os=libMesh::out, bool print_nonlocal=false) const
DirichletBoundaries * get_dirichlet_boundaries()
Definition: dof_map.h:1228
bool is_constrained_dof(const dof_id_type dof) const
Definition: dof_map.h:1829
std::unordered_map< const Elem *, const CouplingMatrix * > map_type
void clear()
Definition: dof_map.C:828
void allgather_recursive_constraints(MeshBase &)
void distribute_dofs(MeshBase &)
Definition: dof_map.C:902
const VariableGroup & variable_group(const unsigned int c) const
Definition: dof_map.h:1752
dof_id_type end_old_dof(const processor_id_type proc) const
Definition: dof_map.h:664
DofConstraints _dof_constraints
Definition: dof_map.h:1687
void reinit(MeshBase &mesh)
Definition: dof_map.C:474
DofMap(const unsigned int sys_number, MeshBase &mesh)
Definition: dof_map.C:130
CouplingMatrix * _dof_coupling
Definition: dof_map.h:1319
std::vector< DirichletBoundaries * > _adjoint_dirichlet_boundaries
Definition: dof_map.h:1727
void print_info(std::ostream &os=libMesh::out) const
Definition: dof_map.C:2696
void * _extra_send_list_context
Definition: dof_map.h:1579
const DirichletBoundaries * get_dirichlet_boundaries() const
Definition: dof_map.h:1223
An object whose state is distributed along a set of processors.
bool is_evaluable(const DofObjectSubclass &obj, unsigned int var_num=libMesh::invalid_uint) const
Definition: dof_map.C:2413
dof_id_type end_dof() const
Definition: dof_map.h:644
std::pair< Real, Real > max_constraint_error(const System &system, NumericVector< Number > *v=nullptr) const
std::vector< SparseMatrix< Number > *> _matrices
Definition: dof_map.h:1525
DofObject * elem_ptr(MeshBase &mesh, dof_id_type i) const
Definition: dof_map.C:313
std::set< GhostingFunctor * >::const_iterator algebraic_ghosting_functors_end() const
Definition: dof_map.h:373
DofConstraints::const_iterator constraint_rows_end() const
Definition: dof_map.h:908
virtual void augment_sparsity_pattern(SparsityPattern::Graph &sparsity, std::vector< dof_id_type > &n_nz, std::vector< dof_id_type > &n_oz)=0
std::unique_ptr< PeriodicBoundaries > _periodic_boundaries
Definition: dof_map.h:1707
void heterogenously_constrain_element_matrix_and_vector(DenseMatrix< Number > &matrix, DenseVector< Number > &rhs, std::vector< dof_id_type > &elem_dofs, bool asymmetric_constraint_rows=true, int qoi_index=-1) const
bool has_heterogenous_adjoint_constraints(const unsigned int qoi_num) const
Definition: dof_map.h:1839
void unstash_dof_constraints()
Definition: dof_map.h:917
dof_id_type first_old_dof() const
Definition: dof_map.h:612
void remove_coupling_functor(GhostingFunctor &coupling_functor)
Definition: dof_map.C:1820
DofObject *(DofMap::* dofobject_accessor)(MeshBase &mesh, dof_id_type i) const
Definition: dof_map.h:1376
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void process_constraints(MeshBase &)
void stash_dof_constraints()
Definition: dof_map.h:911
dof_id_type n_constrained_dofs() const
void constrain_element_vector(DenseVector< Number > &rhs, std::vector< dof_id_type > &dofs, bool asymmetric_constraint_rows=true) const
const std::vector< dof_id_type > & get_n_nz() const
Definition: dof_map.h:459
void invalidate_dofs(MeshBase &mesh) const
Definition: dof_map.C:813
const DirichletBoundaries * get_adjoint_dirichlet_boundaries(unsigned int q) const
void attach_extra_send_list_function(void(*func)(std::vector< dof_id_type > &, void *), void *context=nullptr)
Definition: dof_map.h:429
std::unique_ptr< DefaultCoupling > _default_coupling
Definition: dof_map.h:1587
DofConstraintValueMap _primal_constraint_values
Definition: dof_map.h:1689
std::vector< Variable > _variables
Definition: dof_map.h:1498
DofConstraints _stashed_dof_constraints
Definition: dof_map.h:1687
void remove_default_ghosting()
Definition: dof_map.C:1792
dof_id_type first_dof() const
Definition: dof_map.h:602
void attach_extra_sparsity_function(void(*func)(SparsityPattern::Graph &sparsity, std::vector< dof_id_type > &n_nz, std::vector< dof_id_type > &n_oz, void *), void *context=nullptr)
Definition: dof_map.h:406
void find_connected_dof_objects(std::vector< const DofObject *> &objs) const
std::map< dof_id_type, Real, std::less< dof_id_type >, Threads::scalable_allocator< std::pair< const dof_id_type, Real > > > DofConstraintRow
Definition: dof_map.h:97
dof_id_type _n_old_dfs
Definition: dof_map.h:1662
void clear_sparsity()
Definition: dof_map.C:1771
Order variable_order(const unsigned int c) const
Definition: dof_map.h:1772
dof_id_type last_dof(const processor_id_type proc) const
Definition: dof_map.h:624
std::set< GhostingFunctor * > _coupling_functors
Definition: dof_map.h:1618
std::vector< dof_id_type > _end_df
Definition: dof_map.h:1535
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
void build_constraint_matrix(DenseMatrix< Number > &C, std::vector< dof_id_type > &elem_dofs, const bool called_recursively=false) const
std::vector< dof_id_type > _first_df
Definition: dof_map.h:1530
void(* _extra_send_list_function)(std::vector< dof_id_type > &, void *)
Definition: dof_map.h:1574
DofObject * node_ptr(MeshBase &mesh, dof_id_type i) const
Definition: dof_map.C:306
Base class for all PeriodicBoundary implementations.
void create_dof_constraints(const MeshBase &, Real time=0)
std::set< GhostingFunctor * >::const_iterator coupling_functors_end() const
Definition: dof_map.h:323
std::map< const Node *, Real, std::less< const Node * >, Threads::scalable_allocator< std::pair< const Node *const, Real > > > NodeConstraintRow
Definition: dof_map.h:145
MeshBase & _mesh
Definition: dof_map.h:1518
void prepare_send_list()
Definition: dof_map.C:1639
bool all_semilocal_indices(const std::vector< dof_id_type > &dof_indices) const
Definition: dof_map.C:2400
std::unique_ptr< DefaultCoupling > _default_evaluating
Definition: dof_map.h:1595
std::vector< unsigned int > _variable_group_numbers
Definition: dof_map.h:1508
dof_id_type first_dof(const processor_id_type proc) const
Definition: dof_map.h:599
void remove_algebraic_ghosting_functor(GhostingFunctor &evaluable_functor)
Definition: dof_map.C:1840
void attach_extra_send_list_object(DofMap::AugmentSendList &asl)
Definition: dof_map.h:420
dof_id_type end_dof(const processor_id_type proc) const
Definition: dof_map.h:641
Order variable_group_order(const unsigned int vg) const
Definition: dof_map.h:1782
std::set< GhostingFunctor * >::const_iterator algebraic_ghosting_functors_begin() const
Definition: dof_map.h:367
void compute_sparsity(const MeshBase &)
Definition: dof_map.C:1739
void add_algebraic_ghosting_functor(GhostingFunctor &evaluable_functor, bool to_mesh=true)
Definition: dof_map.C:1829
processor_id_type processor_id() const
OStreamProxy out(std::cout)
void set_error_on_cyclic_constraint(bool error_on_cyclic_constraint)
Definition: dof_map.C:238
void add_variable_group(const VariableGroup &var_group)
Definition: dof_map.C:245
bool has_blocked_representation() const
Definition: dof_map.h:549
const std::vector< dof_id_type > & get_send_list() const
Definition: dof_map.h:450
void constrain_nothing(std::vector< dof_id_type > &dofs) const
void distribute_local_dofs_var_major(dof_id_type &next_free_dof, MeshBase &mesh)
Definition: dof_map.C:1302
dof_id_type first_old_dof(const processor_id_type proc) const
Definition: dof_map.h:609
static void merge_ghost_functor_outputs(GhostingFunctor::map_type &elements_to_ghost, std::set< CouplingMatrix *> &temporary_coupling_matrices, const std::set< GhostingFunctor *>::iterator &gf_begin, const std::set< GhostingFunctor *>::iterator &gf_end, const MeshBase::const_element_iterator &elems_begin, const MeshBase::const_element_iterator &elems_end, processor_id_type p)
Definition: dof_map.C:1432
bool semilocal_index(dof_id_type dof_index) const
Definition: dof_map.C:2384
void constrain_p_dofs(unsigned int var, const Elem *elem, unsigned int s, unsigned int p)
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
uint8_t dof_id_type
Definition: id_types.h:64
dof_id_type _n_dfs
Definition: dof_map.h:1649
bool local_index(dof_id_type dof_index) const
Definition: dof_map.h:738
NodeConstraints _node_constraints
Definition: dof_map.h:1698
void enforce_constraints_exactly(const System &system, NumericVector< Number > *v=nullptr, bool homogeneous=false) const
Defines the coupling between variables of a System.
void constrain_element_matrix(DenseMatrix< Number > &matrix, std::vector< dof_id_type > &elem_dofs, bool asymmetric_constraint_rows=true) const