20 #ifndef LIBMESH_DOF_OBJECT_H
21 #define LIBMESH_DOF_OBJECT_H
24 #include "libmesh/id_types.h"
25 #include "libmesh/int_range.h"
26 #include "libmesh/libmesh_config.h"
27 #include "libmesh/libmesh_common.h"
28 #include "libmesh/libmesh.h"
29 #include "libmesh/reference_counted_object.h"
56 #ifdef LIBMESH_IS_UNIT_TESTING
75 #ifdef LIBMESH_ENABLE_AMR
85 #ifndef LIBMESH_ENABLE_DEPRECATED
162 unsigned int n_dofs (
const unsigned int s,
163 const unsigned int var =
197 { this->
set_id() = dofid; }
280 template <
typename T>
289 template <
typename T>
308 unsigned int n_vars(
const unsigned int s,
309 const unsigned int vg)
const;
315 unsigned int n_vars(
const unsigned int s)
const;
325 const std::vector<unsigned int> & nvpg);
336 unsigned int n_comp(
const unsigned int s,
337 const unsigned int var)
const;
349 const unsigned int vg)
const;
356 const unsigned int var,
357 const unsigned int ncomp);
364 const unsigned int vg,
365 const unsigned int ncomp);
376 const unsigned int var,
377 const unsigned int comp)
const;
388 const unsigned int vg,
389 const unsigned int vig,
390 const unsigned int comp,
391 const unsigned int n_comp)
const;
398 std::pair<unsigned int, unsigned int>
400 const unsigned int var)
const;
407 const unsigned int var,
408 const unsigned int comp,
423 const unsigned int vg,
432 const unsigned int vg)
const;
458 const std::vector<dof_id_type> & default_values);
501 (std::vector<largest_id_type>::const_iterator begin);
508 void unpack_indexing(std::vector<largest_id_type>::const_iterator begin);
515 void pack_indexing(std::back_insert_iterator<std::vector<largest_id_type>> target)
const;
545 std::unique_ptr<DofObject>
557 unsigned int var_to_vg (
const unsigned int s,
558 const unsigned int var)
const;
565 const unsigned int vg,
566 const unsigned int var)
const;
571 #ifdef LIBMESH_ENABLE_UNIQUE_ID
692 unsigned int start_idx(
const unsigned int s)
const;
697 unsigned int end_idx(
const unsigned int s)
const;
710 #ifdef LIBMESH_IS_UNIT_TESTING
723 #ifdef LIBMESH_ENABLE_UNIQUE_ID
724 _unique_id (invalid_unique_id),
735 std::unique_ptr<DofObject>
739 ? std::unique_ptr<DofObject>(
new DofObject(*other))
740 : std::unique_ptr<DofObject>(
new DofObject());
748 const unsigned int n_sys = this->
n_systems();
750 if (sys_num >= n_sys)
752 for (
auto s : make_range(n_sys))
802 const unsigned int var)
const
804 libmesh_assert_less (s, this->
n_systems());
806 unsigned int num = 0;
810 for (
auto v : make_range(this->
n_vars(s)))
815 num = this->
n_comp(s,var);
841 #ifdef LIBMESH_ENABLE_UNIQUE_ID
854 #ifdef LIBMESH_ENABLE_UNIQUE_ID
855 libmesh_deprecated();
858 libmesh_not_implemented();
867 #ifdef LIBMESH_ENABLE_UNIQUE_ID
871 libmesh_not_implemented();
888 #ifdef LIBMESH_ENABLE_UNIQUE_ID
934 return hdr >= 0 ? hdr : (-hdr-1);
952 libmesh_assert_less (s, this->
n_systems());
961 const unsigned int vg)
const
963 libmesh_assert_less (s, this->
n_systems());
966 const unsigned int start_idx_sys = this->
start_idx(s);
968 libmesh_assert_less ((start_idx_sys + 2*vg),
_idx_buf.size());
970 return (cast_int<unsigned int>
979 libmesh_assert_less (s, this->
n_systems());
985 for (
unsigned int vg=0; vg<nvg; vg++)
986 val += this->
n_vars(s,vg);
996 const unsigned int var)
const
998 libmesh_assert_less (s, this->
n_systems());
999 libmesh_assert_less (var, this->
n_vars(s));
1009 const unsigned int vg)
const
1011 libmesh_assert_less (s, this->
n_systems());
1017 libmesh_assert_less ((start_idx_sys + 2*vg),
_idx_buf.size());
1026 const unsigned int var,
1027 const unsigned int comp)
const
1029 libmesh_assert_less (s, this->
n_systems());
1030 libmesh_assert_less (var, this->
n_vars(s));
1031 libmesh_assert_less (comp, this->
n_comp(s,var));
1033 const std::pair<unsigned int, unsigned int>
1039 return this->
dof_number(s, vg_vig.first, vg_vig.second,
1047 const unsigned int vg,
1048 const unsigned int vig,
1049 const unsigned int comp,
1050 const unsigned int n_comp)
const
1052 libmesh_assert_less (s, this->
n_systems());
1054 libmesh_assert_less (vig, this->
n_vars(s,vg));
1059 libmesh_assert_less ((start_idx_sys + 2*vg + 1),
_idx_buf.size());
1062 base_idx =
_idx_buf[start_idx_sys + 2*vg + 1];
1072 return cast_int<dof_id_type>(base_idx + vig*n_comp + comp);
1087 libmesh_assert_less(start_idx_i+index,
_idx_buf.size());
1088 _idx_buf[start_idx_i+index] = value;
1102 libmesh_assert_less(start_idx_i+index,
_idx_buf.size());
1103 return _idx_buf[start_idx_i+index];
1112 #include "libmesh/ignore_warnings.h"
1116 template <
typename T>
1123 const unsigned int n_more_integers = (
sizeof(T)-1)/
sizeof(
dof_id_type);
1130 libmesh_assert_less(start_idx_i+index+n_more_integers,
_idx_buf.size());
1131 std::memcpy(&
_idx_buf[start_idx_i+index], &value,
sizeof(T));
1136 template <
typename T>
1142 const unsigned int n_more_integers = (
sizeof(T)-1)/
sizeof(
dof_id_type);
1149 libmesh_assert_less(start_idx_i+index+n_more_integers,
_idx_buf.size());
1151 std::memcpy(&returnval, &
_idx_buf[start_idx_i+index],
sizeof(T));
1157 #include "libmesh/restore_warnings.h"
1174 return _idx_buf.size() - start_idx_i;
1192 std::pair<unsigned int, unsigned int>
1194 const unsigned int var)
const
1196 std::pair<unsigned int, unsigned int> returnval(0,0);
1198 unsigned int & vg = returnval.first;
1199 unsigned int & offset = returnval.second;
1201 unsigned int vg_start = 0;
1206 const unsigned int vg_end = vg_start + this->
n_vars(s,vg);
1209 offset = var - vg_start;
1223 for (
auto s : make_range(this->
n_systems()))
1230 libmesh_assert_less (sys, this->
n_systems());
1244 libmesh_assert_less (s, this->
n_systems());
1245 libmesh_assert_less (s,
_idx_buf.size());
1255 libmesh_assert_less (s, this->
n_systems());
1256 libmesh_assert_less (s,
_idx_buf.size());
1259 cast_int<unsigned int>(
_idx_buf.size()) :
1260 cast_int<unsigned int>(
_idx_buf[s+1]);
1284 return cast_int<unsigned int>(
_idx_buf.size());
1291 const unsigned int vg,
1294 libmesh_assert_less (s, this->
n_systems());
1300 libmesh_assert_less ((start_idx_sys + 2*vg + 1),
_idx_buf.size());
1302 _idx_buf[start_idx_sys + 2*vg + 1] = db;
1304 libmesh_assert_equal_to (this->
vg_dof_base(s,vg), db);
1311 const unsigned int vg)
const
1313 libmesh_assert_less (s, this->
n_systems());
1319 libmesh_assert_less ((start_idx_sys + 2*vg + 1),
_idx_buf.size());
1328 return _idx_buf[start_idx_sys + 2*vg + 1];
1335 const unsigned int var)
const
1340 for (
unsigned int vg=0, vg_end=0; vg<nvg; vg++)
1342 vg_end += this->
n_vars(s,vg);
1343 if (var < vg_end)
return vg;
1346 libmesh_error_msg(
"Error: could not map variable " << var <<
" to variable group.");
1353 const unsigned int vg,
1354 const unsigned int var)
const
1356 unsigned int accumulated_sum=0;
1358 for (
unsigned int vgc=0; vgc<vg; vgc++)
1359 accumulated_sum += this->
n_vars(s,vgc);
1361 libmesh_assert_less_equal (accumulated_sum, var);
1363 return (var - accumulated_sum);
1379 return a->
id() < b->
id();
1396 return a->
id() < b->
id();
1403 #endif // #ifndef LIBMESH_DOF_OBJECT_H
unsigned int n_comp_group(const unsigned int s, const unsigned int vg) const
bool has_dofs(const unsigned int s=libMesh::invalid_uint) const
void set_n_comp(const unsigned int s, const unsigned int var, const unsigned int ncomp)
Sets the number of components for Variable var of system s associated with this DofObject.
unique_id_type & set_unique_id()
std::unique_ptr< DofObject > construct(const DofObject *other=nullptr)
Convenient factory function that calls either the (deep) copy constructor or the default constructor ...
void set_old_dof_object()
Sets the old_dof_object to a copy of this.
void clear_dofs()
Clear the DofMap data structures holding degree of freedom data.
static unsigned int unpackable_indexing_size(std::vector< largest_id_type >::const_iterator begin)
If we have indices packed into an buffer for communications, how much of that buffer applies to this ...
Comparison object to use with DofObject pointers.
T get_extra_datum(const unsigned int index) const
Gets the value on this object of the extra datum associated with index, which should have been obtain...
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
unsigned int n_vars(const unsigned int s, const unsigned int vg) const
bool has_extra_integers() const
Returns whether extra integers are associated to the DofObject.
bool operator()(const DofObject *a, const DofObject *b) const
void set_id(const dof_id_type dofid)
Sets the id for this DofObject.
unsigned int n_dofs(const unsigned int s, const unsigned int var=libMesh::invalid_uint) const
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
dof_id_type _id
The id of the DofObject.
void invalidate()
Invalidates all the indices for this DofObject.
unsigned int system_var_to_vg_var(const unsigned int s, const unsigned int vg, const unsigned int var) const
Utility function - for variable var in system s, figure out what variable group it lives in...
std::pair< unsigned int, unsigned int > var_to_vg_and_offset(const unsigned int s, const unsigned int var) const
const DofObject * get_old_dof_object() const
void print_dof_info() const
Print out info for debugging.
void set_vg_dof_base(const unsigned int s, const unsigned int vg, const dof_id_type db)
VariableGroup DoF indices are indexed as id = base + var_in_vg*ncomp + comp This method allows for di...
const DofObject & get_old_dof_object_ref() const
uint8_t processor_id_type
bool valid_unique_id() const
unsigned int end_idx(const unsigned int s) const
The ending index for system s.
dof_id_type index_t
DoF index information.
unique_id_type _unique_id
A globally unique id, guaranteed not to change as the mesh is repartitioned or adapted.
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
计算自动微分实数向量的绝对值。
void add_system()
Adds an additional system to the DofObject.
void pack_indexing(std::back_insert_iterator< std::vector< largest_id_type >> target) const
A method for creating packed data from our index buffer - basically a copy with prepended size with o...
dof_id_type vg_dof_base(const unsigned int s, const unsigned int vg) const
VariableGroup DoF indices are indexed as id = base + var_in_vg*ncomp + comp This method allows for di...
unsigned int n_extra_integers() const
Returns how many extra integers are associated to the DofObject.
bool valid_processor_id() const
void libmesh_ignore(const Args &...)
void set_buffer(const std::vector< dof_id_type > &buf)
DofObject & operator=(const DofObject &dof_obj)
Deep-copying assignment operator.
static const unique_id_type invalid_unique_id
An invalid unique_id to distinguish an uninitialized DofObject.
static const processor_id_type invalid_processor_id
An invalid processor_id to distinguish DoFs that have not been assigned to a processor.
void set_dof_number(const unsigned int s, const unsigned int var, const unsigned int comp, const dof_id_type dn)
Sets the global degree of freedom number for variable var, component comp for system s associated wit...
unsigned int n_var_groups(const unsigned int s) const
processor_id_type _processor_id
The local processor id.
void clear_old_dof_object()
Sets the old_dof_object to nullptr.
void invalidate_id()
Sets the id to invalid_id.
bool operator()(const DofObject *a, const DofObject *b) const
static const dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
int8_t dof_id_signed_type
unsigned int n_pseudo_systems() const
void set_extra_datum(const unsigned int index, const T value)
Sets the value on this object of the extra datum associated with index, which should have been obtain...
unsigned int start_idx(const unsigned int s) const
The starting index for system s.
DofObject * get_old_dof_object()
Pointer accessor for previously public old_dof_object.
This class implements reference counting.
void invalidate_processor_id()
Sets the processor id to invalid_processor_id.
std::vector< index_t > index_buffer_t
void set_n_comp_group(const unsigned int s, const unsigned int vg, const unsigned int ncomp)
Sets the number of components for VariableGroup vg of system s associated with this DofObject...
DofObject & get_old_dof_object_ref()
As above, but do not use in situations where the old_dof_object may be nullptr, since this function a...
unsigned int packed_indexing_size() const
If we pack our indices into an buffer for communications, how many ints do we need?
void set_n_systems(const unsigned int s)
Sets the number of systems for this DofObject.
~DofObject()=default
Destructor.
unsigned int var_to_vg(const unsigned int s, const unsigned int var) const
Utility function - for variable var in system s, figure out what variable group it lives in...
unsigned int start_idx_ints() const
The starting index for an extra_integers pseudosystem.
void set_n_vars_per_group(const unsigned int s, const std::vector< unsigned int > &nvpg)
Sets number of variables in each group associated with system s for this DofObject.
std::unique_ptr< DofObject > old_dof_object
This object on the last mesh.
void invalidate_dofs(const unsigned int sys_num=libMesh::invalid_uint)
Sets all degree of freedom numbers to invalid_id.
void unpack_indexing(std::vector< largest_id_type >::const_iterator begin)
A method for creating our index buffer from packed data - basically with our current implementation w...
The DofObject defines an abstract base class for objects that have degrees of freedom associated with...
void add_extra_integers(const unsigned int n_integers)
Assigns a set of extra integers to this DofObject.
dof_id_type get_extra_integer(const unsigned int index) const
Gets the value on this object of the extra integer associated with index, which should have been obta...
unsigned int n_comp(const unsigned int s, const unsigned int var) const
unsigned int n_systems() const
void debug_buffer() const
Print our buffer for debugging.
unique_id_type unique_id() const
processor_id_type _processor_id
The processor_id of the DofObject.
static const index_t ncv_magic_exp
void set_extra_integer(const unsigned int index, const dof_id_type value)
Sets the value on this object of the extra integer associated with index, which should have been obta...
unsigned int end_idx_ints() const
The ending index for an extra_integers pseudosystem.
processor_id_type processor_id() const
static const index_t ncv_magic
Above we introduced the chimera ncv, which is a hybrid of the form ncv = ncv_magic*nv + nc where nv a...