LCOV - code coverage report
Current view: top level - src/base - dof_object.C (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4256 (26f7e2) with base d735cc Lines: 202 269 75.1 %
Date: 2025-10-01 13:47:18 Functions: 14 20 70.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 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             : // Local includes
      21             : #include "libmesh/dof_object.h"
      22             : 
      23             : namespace libMesh
      24             : {
      25             : 
      26             : // Copy Constructor
      27    14586106 : DofObject::DofObject (const DofObject & dof_obj) :
      28             :   ReferenceCountedObject<DofObject>(),
      29             : #ifdef LIBMESH_ENABLE_UNIQUE_ID
      30    14586106 :   _unique_id     (dof_obj._unique_id),
      31             : #endif
      32    14586106 :   _id            (dof_obj._id),
      33    14586106 :   _processor_id  (dof_obj._processor_id),
      34    14586106 :   _idx_buf       (dof_obj._idx_buf)
      35             : {
      36             :   // DO NOT copy old_dof_object, because this isn't a *real* copy
      37             :   // constructor, it's a "copy almost everything" constructor that
      38             :   // is intended to be used solely for internal construction of
      39             :   // old_dof_object, never for a true deep copy where the newly
      40             :   // created object really matches the source object.
      41             : 
      42             :   // Check that everything worked
      43             : #ifdef DEBUG
      44             : 
      45      815180 :   libmesh_assert_equal_to (this->n_systems(), dof_obj.n_systems());
      46             : 
      47     1635472 :   for (auto s : make_range(this->n_systems()))
      48             :     {
      49      820292 :       libmesh_assert_equal_to (this->n_vars(s),       dof_obj.n_vars(s));
      50      820292 :       libmesh_assert_equal_to (this->n_var_groups(s), dof_obj.n_var_groups(s));
      51             : 
      52     1679968 :       for (auto vg : make_range(this->n_var_groups(s)))
      53      859676 :         libmesh_assert_equal_to (this->n_vars(s,vg), dof_obj.n_vars(s,vg));
      54             : 
      55     1714272 :       for (auto v : make_range(this->n_vars(s)))
      56             :         {
      57      893980 :           libmesh_assert_equal_to (this->n_comp(s,v), dof_obj.n_comp(s,v));
      58             : 
      59     1373890 :           for (auto c : make_range(this->n_comp(s,v)))
      60      479910 :             libmesh_assert_equal_to (this->dof_number(s,v,c), dof_obj.dof_number(s,v,c));
      61             :         }
      62             :     }
      63             : 
      64             : #endif
      65    14586106 : }
      66             : 
      67             : 
      68             : // Deep-copying assignment operator
      69           0 : DofObject & DofObject::operator= (const DofObject & dof_obj)
      70             : {
      71           0 :   if (&dof_obj == this)
      72           0 :     return *this;
      73             : 
      74             : #ifdef LIBMESH_ENABLE_AMR
      75           0 :   this->clear_old_dof_object();
      76           0 :   this->old_dof_object = this->construct(dof_obj.get_old_dof_object());
      77             : #endif
      78             : 
      79           0 :   _id           = dof_obj._id;
      80             : #ifdef LIBMESH_ENABLE_UNIQUE_ID
      81           0 :   _unique_id    = dof_obj._unique_id;
      82             : #endif
      83           0 :   _processor_id = dof_obj._processor_id;
      84           0 :   _idx_buf      = dof_obj._idx_buf;
      85             : 
      86             : 
      87             :   // Check that everything worked
      88             : #ifdef DEBUG
      89             : 
      90           0 :   libmesh_assert_equal_to (this->n_systems(), dof_obj.n_systems());
      91             : 
      92           0 :   for (auto s : make_range(this->n_systems()))
      93             :     {
      94           0 :       libmesh_assert_equal_to (this->n_vars(s),       dof_obj.n_vars(s));
      95           0 :       libmesh_assert_equal_to (this->n_var_groups(s), dof_obj.n_var_groups(s));
      96             : 
      97           0 :       for (auto vg : make_range(this->n_var_groups(s)))
      98           0 :         libmesh_assert_equal_to (this->n_vars(s,vg), dof_obj.n_vars(s,vg));
      99             : 
     100           0 :       for (auto v : make_range(this->n_vars(s)))
     101             :         {
     102           0 :           libmesh_assert_equal_to (this->n_comp(s,v), dof_obj.n_comp(s,v));
     103             : 
     104           0 :           for (auto c : make_range(this->n_comp(s,v)))
     105           0 :             libmesh_assert_equal_to (this->dof_number(s,v,c), dof_obj.dof_number(s,v,c));
     106             :         }
     107             :     }
     108             : 
     109             : #endif
     110             : 
     111           0 :   return *this;
     112             : }
     113             : 
     114             : 
     115             : 
     116             : 
     117             : 
     118             : #ifdef LIBMESH_ENABLE_AMR
     119             : 
     120   214450443 : void  DofObject::clear_old_dof_object ()
     121             : {
     122     3640860 :   this->old_dof_object.reset(nullptr);
     123   214450443 : }
     124             : 
     125             : 
     126             : 
     127    14586106 : void DofObject::set_old_dof_object ()
     128             : {
     129    14586106 :   this->clear_old_dof_object();
     130             : 
     131      815180 :   libmesh_assert (!this->old_dof_object);
     132             : 
     133             :   // Make a new DofObject, assign a copy of \p this.
     134             :   // Make sure the copy ctor for DofObject works!!
     135    27541852 :   this->old_dof_object = this->construct(this);
     136    14586106 : }
     137             : 
     138             : #endif
     139             : 
     140             : 
     141             : 
     142   108506241 : void DofObject::set_n_systems (const unsigned int ns)
     143             : {
     144     6759233 :   const unsigned int old_ns = this->n_systems();
     145             : 
     146             :   // Check for trivial return
     147   108506241 :   if (ns == old_ns)
     148    83904224 :     return;
     149             : 
     150    24602017 :   const unsigned int nei = this->n_extra_integers();
     151    24602017 :   const dof_id_type header_size = ns + bool(nei);
     152    24602017 :   const dof_id_type hdr = nei ?
     153      175640 :     static_cast<dof_id_type>(-static_cast<std::ptrdiff_t>(header_size))
     154     1712754 :     : header_size;
     155    26314771 :   index_buffer_t new_buf(header_size + nei, hdr);
     156    24602017 :   if (nei)
     157             :     {
     158      221275 :       const unsigned int start_idx_ints = old_ns ?
     159          73 :         cast_int<unsigned int>(_idx_buf[old_ns]) :
     160       18254 :         1;
     161       18254 :       libmesh_assert_less(start_idx_ints, _idx_buf.size());
     162      184767 :       std::copy(_idx_buf.begin()+start_idx_ints,
     163             :                 _idx_buf.end(),
     164       18254 :                 new_buf.begin()+header_size);
     165      221275 :       if (ns)
     166      221275 :         std::fill(new_buf.begin()+1, new_buf.begin()+ns+1, ns+1);
     167             :     }
     168             : 
     169             :   // vector swap trick to force deallocation when shrinking
     170     1712754 :   new_buf.swap(_idx_buf);
     171             : 
     172             : #ifdef DEBUG
     173     1712754 :   libmesh_assert_equal_to(nei, this->n_extra_integers());
     174             : 
     175             :   // check that all systems now exist and that they have 0 size
     176     1712754 :   libmesh_assert_equal_to (ns, this->n_systems());
     177     3427962 :   for (auto s : make_range(this->n_systems()))
     178             :     {
     179     1715208 :       libmesh_assert_equal_to (this->n_vars(s),       0);
     180     1715208 :       libmesh_assert_equal_to (this->n_var_groups(s), 0);
     181             :     }
     182             : #endif
     183             : }
     184             : 
     185             : 
     186             : 
     187    22351370 : void DofObject::add_system()
     188             : {
     189             :   // quick return?
     190    22351370 :   if (this->n_systems() == 0)
     191             :     {
     192    19511644 :       this->set_n_systems(1);
     193     1289155 :       return;
     194             :     }
     195             : 
     196             :   // cache this value before we screw it up!
     197      170610 :   const unsigned int ns_orig = this->n_systems();
     198             : 
     199      170610 :   DofObject::index_buffer_t::iterator it = _idx_buf.begin() + ns_orig;
     200             : 
     201             :   // Create the entry for the new system indicating 0 variables.
     202             :   //
     203             :   // increment the number of systems and the offsets for each of
     204             :   // the systems including the new one we just added.
     205     2839726 :   if (this->has_extra_integers())
     206             :     {
     207             :       // this inserts the extra_integers' start position as the start
     208             :       // position for the new system.  We'll increment all those
     209             :       // counts in one sweep next, to account for header expansion.
     210       90532 :       _idx_buf.insert(it, *it);
     211             : 
     212       83376 :       _idx_buf[0]--;
     213      281286 :       for (unsigned int i=1; i<ns_orig+2; i++)
     214             :         {
     215       17140 :           libmesh_assert_less(i, _idx_buf.size());
     216      215050 :           _idx_buf[i]++;
     217             :         }
     218             :     }
     219             :   else
     220             :     {
     221             :       // this inserts the current vector size at the position for the
     222             :       // new system
     223     2919804 :       _idx_buf.insert(it, cast_int<dof_id_type>(_idx_buf.size()));
     224             : 
     225     8359466 :       for (unsigned int i=0; i<ns_orig+1; i++)
     226             :         {
     227      333744 :           libmesh_assert_less(i, _idx_buf.size());
     228     5936860 :           _idx_buf[i]++;
     229             :         }
     230             :     }
     231             : 
     232      170610 :   libmesh_assert_equal_to (this->n_systems(), (ns_orig+1));
     233      170610 :   libmesh_assert_equal_to (this->n_vars(ns_orig), 0);
     234      170610 :   libmesh_assert_equal_to (this->n_var_groups(ns_orig), 0);
     235             : }
     236             : 
     237             : 
     238             : 
     239    41786165 : void DofObject::set_n_vars_per_group(const unsigned int s,
     240             :                                      const std::vector<unsigned int> & nvpg)
     241             : {
     242     2709916 :   const unsigned int n_sys = this->n_systems();
     243             : 
     244     2709916 :   libmesh_assert_less (s, n_sys);
     245             : 
     246             :   // number of variable groups for this system - inferred
     247     5419776 :   const unsigned int nvg = cast_int<unsigned int>(nvpg.size());
     248             : 
     249             :   // BSK - note that for compatibility with the previous implementation
     250             :   // calling this method when (nvars == this->n_vars()) requires that
     251             :   // we invalidate the DOF indices and set the number of components to 0.
     252             :   // Note this was a bit of a surprise to me - there was no quick return in
     253             :   // the old method, which caused removal and readdition of the DOF indices
     254             :   // even in the case of (nvars == this->n_vars()), resulting in n_comp(s,v)
     255             :   // implicitly becoming 0 regardless of any previous value.
     256             :   // quick return?
     257    41786165 :   if (nvg == this->n_var_groups(s))
     258             :     {
     259    31042303 :       for (unsigned int vg=0; vg<nvg; vg++)
     260             :         {
     261    16074960 :           this->set_n_comp_group(s,vg,0);
     262      871650 :           libmesh_assert_equal_to (this->n_vars(s,vg), nvpg[vg]);
     263             :         }
     264      829428 :       return;
     265             :     }
     266             : 
     267     1880730 :   const bool hei = this->has_extra_integers();
     268             : 
     269             :   // since there is ample opportunity to screw up other systems, let us
     270             :   // cache their current sizes and later assert that they are unchanged.
     271             : #ifdef DEBUG
     272     1880730 :   const unsigned int nei = this->n_extra_integers();
     273             : 
     274     1880730 :   DofObject::index_buffer_t old_system_sizes, old_extra_integers;
     275     1880730 :   old_system_sizes.reserve(n_sys);
     276     1880730 :   old_extra_integers.reserve(nei);
     277             : 
     278     4120986 :   for (unsigned int s_ctr=0; s_ctr<n_sys; s_ctr++)
     279     2240256 :     old_system_sizes.push_back(this->n_var_groups(s_ctr));
     280             : 
     281     1933114 :   for (unsigned int ei=0; ei != nei; ++ei)
     282       52384 :     old_extra_integers.push_back(this->get_extra_integer(ei));
     283             : #endif
     284             : 
     285             :   // remove current indices if we have some
     286    26818822 :   if (this->n_var_groups(s) != 0)
     287             :     {
     288         242 :       const unsigned int old_nvg_s = this->n_var_groups(s);
     289             : 
     290             :       DofObject::index_buffer_t::iterator
     291        3502 :         it  = _idx_buf.begin(),
     292        3502 :         end = _idx_buf.begin();
     293             : 
     294         242 :       std::advance(it,  this->start_idx(s));
     295        3502 :       std::advance(end, this->end_idx(s));
     296        3744 :       _idx_buf.erase(it,end);
     297             : 
     298        3744 :       for (unsigned int ctr=(s+1); ctr<n_sys; ctr++)
     299           0 :         _idx_buf[ctr] -= 2*old_nvg_s;
     300             : 
     301        3744 :       if (hei)
     302           0 :         _idx_buf[n_sys] -= 2*old_nvg_s;
     303             :     }
     304             : 
     305             :   // better not have any now!
     306     1880730 :   libmesh_assert_equal_to (this->n_var_groups(s), 0);
     307             : 
     308             :   // Make sure we didn't screw up any of our sizes!
     309             : #ifdef DEBUG
     310     4120986 :   for (auto s_ctr : make_range(this->n_systems()))
     311     2240256 :     if (s_ctr != s)
     312      359526 :       libmesh_assert_equal_to (this->n_var_groups(s_ctr), old_system_sizes[s_ctr]);
     313             : 
     314     1880730 :   libmesh_assert_equal_to (nei, this->n_extra_integers());
     315             : 
     316     1933114 :   for (unsigned int ei=0; ei != nei; ++ei)
     317       52384 :     libmesh_assert_equal_to(old_extra_integers[ei], this->get_extra_integer(ei));
     318             : #endif
     319             : 
     320             :   // OK, if the user requested 0 that is what we have
     321    26818822 :   if (nvg == 0)
     322         242 :     return;
     323             : 
     324             :   {
     325             :     // array to hold new indices
     326    26815078 :     DofObject::index_buffer_t var_idxs(2*nvg);
     327    61867930 :     for (unsigned int vg=0; vg<nvg; vg++)
     328             :       {
     329    37593890 :         var_idxs[2*vg    ] = ncv_magic*nvpg[vg] + 0;
     330    37593890 :         var_idxs[2*vg + 1] = invalid_id - 1;
     331             :       }
     332             : 
     333    24934646 :     DofObject::index_buffer_t::iterator it = _idx_buf.begin();
     334    24934646 :     std::advance(it, this->end_idx(s));
     335    28695510 :     _idx_buf.insert(it, var_idxs.begin(), var_idxs.end());
     336             : 
     337    29660893 :     for (unsigned int ctr=(s+1); ctr<n_sys; ctr++)
     338     3024161 :       _idx_buf[ctr] += 2*nvg;
     339             : 
     340    26815078 :     if (hei)
     341      329842 :       _idx_buf[n_sys] += 2*nvg;
     342             : 
     343             :     // resize _idx_buf to fit so no memory is wasted.
     344    51749668 :     DofObject::index_buffer_t(_idx_buf).swap(_idx_buf);
     345             :   }
     346             : 
     347     1880488 :   libmesh_assert_equal_to (nvg, this->n_var_groups(s));
     348             : 
     349             : #ifdef DEBUG
     350             : 
     351     1880488 :   libmesh_assert_equal_to (this->n_var_groups(s), nvpg.size());
     352             : 
     353     4421582 :   for (auto vg : make_range(this->n_var_groups(s)))
     354             :     {
     355     2541094 :       libmesh_assert_equal_to (this->n_vars(s,vg), nvpg[vg]);
     356     2541094 :       libmesh_assert_equal_to (this->n_comp_group(s,vg), 0);
     357             :     }
     358             : 
     359     7787942 :   for (auto v : make_range(this->n_vars(s)))
     360     5907454 :     libmesh_assert_equal_to (this->n_comp(s,v), 0);
     361             : 
     362             :   // again, all other system sizes should be unchanged!
     363     4120018 :   for (auto s_ctr : make_range(this->n_systems()))
     364     2239530 :     if (s_ctr != s)
     365      359042 :       libmesh_assert_equal_to (this->n_var_groups(s_ctr), old_system_sizes[s_ctr]);
     366             : 
     367             :   // Extra integers count and values should also be unchanged!
     368     1880488 :   libmesh_assert_equal_to (nei, this->n_extra_integers());
     369             : 
     370     1932872 :   for (unsigned int ei=0; ei != nei; ++ei)
     371       52384 :     libmesh_assert_equal_to(old_extra_integers[ei], this->get_extra_integer(ei));
     372             : #endif
     373             : }
     374             : 
     375             : 
     376             : 
     377           0 : void DofObject::set_n_comp(const unsigned int s,
     378             :                            const unsigned int var,
     379             :                            const unsigned int ncomp)
     380             : {
     381           0 :   libmesh_assert_less (s,   this->n_systems());
     382           0 :   libmesh_assert_less (var, this->n_vars(s));
     383             : 
     384           0 :   this->set_n_comp_group(s, this->var_to_vg(s,var), ncomp);
     385           0 : }
     386             : 
     387             : 
     388             : 
     389   118299169 : void DofObject::set_n_comp_group(const unsigned int s,
     390             :                                  const unsigned int vg,
     391             :                                  const unsigned int ncomp)
     392             : {
     393     8122112 :   libmesh_assert_less (s,  this->n_systems());
     394     8122112 :   libmesh_assert_less (vg, this->n_var_groups(s));
     395             : 
     396             :   // Check for trivial return
     397   118299169 :   if (ncomp == this->n_comp_group(s,vg)) return;
     398             : 
     399             : #ifndef NDEBUG
     400     1721302 :   if (ncomp >= ncv_magic)
     401             :     {
     402           0 :       const index_t ncvm = ncv_magic;
     403           0 :       libmesh_error_msg("ERROR: ncomp must be less than DofObject::ncv_magic!\n" \
     404             :                         << "ncomp = "                                   \
     405             :                         << ncomp                                \
     406             :                         << ", ncv_magic = "                     \
     407             :                         << ncvm                                 \
     408             :                         << "\nrecompile and try again!");
     409             :     }
     410             : #endif
     411             : 
     412             :   const unsigned int
     413     1721302 :     start_idx_sys = this->start_idx(s),
     414     1721302 :     n_vars_group  = this->n_vars(s,vg),
     415     1721302 :     base_offset   = start_idx_sys + 2*vg;
     416             : 
     417     1721302 :   libmesh_assert_less ((base_offset + 1), _idx_buf.size());
     418             : 
     419             :   // if (ncomp)
     420             :   //   libMesh::out << "s,vg,ncomp="
     421             :   //       << s  << ","
     422             :   //       << vg << ","
     423             :   //       << ncomp << '\n';
     424             : 
     425             :   // set the number of components, maintaining the number
     426             :   // of variables in the group
     427    25522046 :   _idx_buf[base_offset] = ncv_magic*n_vars_group + ncomp;
     428             : 
     429             :   // We use (invalid_id - 1) to signify no
     430             :   // components for this object
     431    44474491 :   _idx_buf[base_offset + 1] = (ncomp == 0) ? invalid_id - 1 : invalid_id;
     432             : 
     433             :   // this->debug_buffer();
     434             :   // libMesh::out << "s,vg = " << s << "," << vg << '\n'
     435             :   //     << "base_offset=" << base_offset << '\n'
     436             :   //     << "this->n_comp(s,vg)=" << this->n_comp(s,vg) << '\n'
     437             :   //     << "this->n_comp_group(s,vg)=" << this->n_comp_group(s,vg) << '\n'
     438             :   //     << "this->n_vars(s,vg)=" << this->n_vars(s,vg) << '\n'
     439             :   //     << "this->n_var_groups(s)=" << this->n_var_groups(s) << '\n';
     440             : 
     441     1721302 :   libmesh_assert_equal_to (ncomp, this->n_comp_group(s,vg));
     442             : }
     443             : 
     444             : 
     445             : 
     446           0 : void DofObject::set_dof_number(const unsigned int s,
     447             :                                const unsigned int var,
     448             :                                const unsigned int comp,
     449             :                                const dof_id_type dn)
     450             : {
     451           0 :   libmesh_assert_less (s,    this->n_systems());
     452           0 :   libmesh_assert_less (var,  this->n_vars(s));
     453           0 :   libmesh_assert_less (comp, this->n_comp(s,var));
     454             : 
     455             :   const unsigned int
     456           0 :     vg            = this->var_to_vg(s,var),
     457             : #ifndef NDEBUG
     458           0 :     ncg           = this->n_comp_group(s,vg),
     459             : #endif
     460           0 :     vig           = this->system_var_to_vg_var(s,vg,var),
     461           0 :     start_idx_sys = this->start_idx(s);
     462             : 
     463           0 :   libmesh_assert_less ((start_idx_sys + 2*vg + 1), _idx_buf.size());
     464             : 
     465           0 :   dof_id_type & base_idx = _idx_buf[start_idx_sys + 2*vg + 1];
     466             : 
     467             :   // We intend to change all dof numbers together or not at all
     468           0 :   if (comp || vig)
     469           0 :     libmesh_assert ((dn == invalid_id && base_idx == invalid_id) ||
     470           0 :                     (dn == base_idx + vig*ncg + comp));
     471             : 
     472             :   // only explicitly store the base index for vig==0, comp==0
     473             :   else
     474           0 :     base_idx = dn;
     475             : 
     476           0 :   libmesh_assert_equal_to (this->dof_number(s, var, comp), dn);
     477           0 : }
     478             : 
     479             : 
     480             : 
     481             : void
     482   169228305 : DofObject::add_extra_integers (const unsigned int n_integers)
     483             : {
     484   169228305 :   if (_idx_buf.empty())
     485             :     {
     486   117156892 :       if (n_integers)
     487             :         {
     488      418032 :           _idx_buf.resize(n_integers+1, DofObject::invalid_id);
     489      418032 :           _idx_buf[0] = dof_id_type(-1);
     490             :         }
     491   117156892 :       return;
     492             :     }
     493             :   else
     494             :     {
     495    52071413 :       const int hdr = dof_id_signed_type(_idx_buf[0]);
     496             : 
     497             :       // We already have some extra integers, but may need more or
     498             :       // less now.
     499    52071413 :       if (hdr < 0)
     500             :         {
     501      717204 :           const unsigned int old_n_integers = this->n_extra_integers();
     502      717204 :           if (n_integers != old_n_integers)
     503             :             {
     504             :               // Make or remove space as needed by count change
     505       57104 :               _idx_buf.resize(_idx_buf.size()+n_integers-old_n_integers, DofObject::invalid_id);
     506             : 
     507             :               // The start index for the extra integers is unchanged.
     508             :             }
     509             :         }
     510    51354209 :       else if (n_integers)
     511             :       // We had no extra integers, but need to add some
     512             :         {
     513             :           // Mark the DofObject as holding extra integers
     514          71 :           _idx_buf[0] = dof_id_type(-hdr-1);
     515             : 
     516             :           // Insert the integer start position
     517           2 :           DofObject::index_buffer_t::iterator it = _idx_buf.begin() + hdr;
     518          73 :           _idx_buf.insert(it, _idx_buf.size()+1);
     519             : 
     520             :           // Increment the previous system start positions to account
     521             :           // for the new header entry creating an offset
     522         142 :           for (int i=1; i<hdr; i++)
     523          73 :             _idx_buf[i]++;
     524             : 
     525             :           // Append space for extra integers
     526          73 :           _idx_buf.resize(_idx_buf.size()+n_integers, DofObject::invalid_id);
     527             :         }
     528             :     }
     529             : }
     530             : 
     531             : 
     532             : 
     533             : void
     534   141203723 : DofObject::add_extra_integers (const unsigned int n_integers,
     535             :                                const std::vector<dof_id_type> & default_values)
     536             : {
     537     3104093 :   libmesh_assert_equal_to(n_integers, default_values.size());
     538             : 
     539   141203723 :   const unsigned int n_old_integers = this->n_extra_integers();
     540   141203723 :   this->add_extra_integers(n_integers);
     541   141203723 :   if (n_integers > n_old_integers)
     542             :     {
     543      463438 :       const unsigned int n_more_integers = n_integers - n_old_integers;
     544      441476 :       std::copy(default_values.begin()+n_old_integers,
     545             :                 default_values.end(),
     546       43924 :                 _idx_buf.end()-n_more_integers);
     547             :     }
     548   141203723 : }
     549             : 
     550             : 
     551             : 
     552   303121379 : unsigned int DofObject::packed_indexing_size() const
     553             : {
     554             :   return
     555   303121379 :     cast_int<unsigned int> (
     556             : #ifdef LIBMESH_ENABLE_AMR
     557   303121379 :                             ((old_dof_object == nullptr) ? 0 : old_dof_object->packed_indexing_size()) + 2 +
     558             : #else
     559             :                             1 +
     560             : #endif
     561   303816663 :                             _idx_buf.size());
     562             : }
     563             : 
     564             : 
     565             : 
     566             : unsigned int
     567   311337676 : DofObject::unpackable_indexing_size(std::vector<largest_id_type>::const_iterator begin)
     568             : {
     569             : #ifdef LIBMESH_ENABLE_AMR
     570   311337676 :   const bool has_old_dof_object = cast_int<bool>(*begin++);
     571             : 
     572             :   static const int dof_header_size = 2;
     573             : #else
     574             :   static const bool has_old_dof_object = false;
     575             :   static const int dof_header_size = 1;
     576             : #endif
     577             : 
     578   311337676 :   const largest_id_type this_indexing_size = *begin++;
     579             : 
     580             :   return cast_int<unsigned int>
     581   311337676 :     (dof_header_size + this_indexing_size +
     582   359976862 :      (has_old_dof_object ?
     583    49051492 :       unpackable_indexing_size(begin+this_indexing_size) : 0));
     584             : }
     585             : 
     586             : 
     587   158089180 : void DofObject::unpack_indexing(std::vector<largest_id_type>::const_iterator begin)
     588             : {
     589   158089180 :   _idx_buf.clear();
     590             : 
     591             : #ifdef LIBMESH_ENABLE_AMR
     592   158089180 :   this->clear_old_dof_object();
     593   158089180 :   const bool has_old_dof_object = cast_int<bool>(*begin++);
     594             : #endif
     595             : 
     596   158089180 :   const largest_id_type size = *begin++;
     597   158089180 :   _idx_buf.reserve(size);
     598      116378 :   std::copy(begin, begin+size, back_inserter(_idx_buf));
     599             : 
     600             :   // Check as best we can for internal consistency now
     601      116378 :   libmesh_assert(_idx_buf.empty() ||
     602             :                  (std::abs(dof_id_signed_type(_idx_buf[0])) <=
     603             :                   cast_int<dof_id_signed_type>(_idx_buf.size())));
     604             : #ifdef DEBUG
     605      116378 :   if (!_idx_buf.empty())
     606             :     {
     607       13116 :       const int hdr = cast_int<int>(dof_id_signed_type(_idx_buf[0]));
     608       13116 :       const unsigned int ns = hdr >= 0 ? hdr : (-hdr-1);
     609       13116 :       for (unsigned int i=1; i < ns; ++i)
     610             :         {
     611           0 :           if (hdr > 0 || i > 1)
     612           0 :             libmesh_assert_greater_equal (_idx_buf[i], _idx_buf[i-1]);
     613             :           else
     614           0 :             libmesh_assert_greater_equal (_idx_buf[i], ns);
     615           0 :           libmesh_assert_equal_to ((_idx_buf[i] - _idx_buf[i-1])%2, 0);
     616           0 :           libmesh_assert_less_equal (_idx_buf[i], _idx_buf.size());
     617             :         }
     618       13116 :       if (hdr < 0 && ns > 0)
     619           0 :         libmesh_assert_less_equal(_idx_buf[ns], _idx_buf.size());
     620             :     }
     621             : #endif
     622             : 
     623             : #ifdef LIBMESH_ENABLE_AMR
     624   158089180 :   if (has_old_dof_object)
     625             :     {
     626    25066677 :       this->old_dof_object = this->construct();
     627    12533493 :       this->old_dof_object->unpack_indexing(begin+size);
     628             :     }
     629             : #endif
     630   158089180 : }
     631             : 
     632             : 
     633             : void
     634    87797988 : DofObject::pack_indexing(std::back_insert_iterator<std::vector<largest_id_type>> target) const
     635             : {
     636             : #ifdef LIBMESH_ENABLE_AMR
     637             :   // We might need to pack old_dof_object too
     638    98088978 :   *target++ = (old_dof_object == nullptr) ? 0 : 1;
     639             : #endif
     640             : 
     641    93066788 :   *target++ = _idx_buf.size();
     642      247602 :   std::copy(_idx_buf.begin(), _idx_buf.end(), target);
     643             : 
     644             : #ifdef LIBMESH_ENABLE_AMR
     645    92942987 :   if (old_dof_object)
     646        1984 :     old_dof_object->pack_indexing(target);
     647             : #endif
     648    87797988 : }
     649             : 
     650             : 
     651             : 
     652           0 : void DofObject::debug_buffer () const
     653             : {
     654           0 :   libMesh::out << " [ ";
     655           0 :   for (const auto & idx : _idx_buf)
     656           0 :     libMesh::out << idx << " ";
     657           0 :   libMesh::out << "]\n";
     658           0 : }
     659             : 
     660             : 
     661             : 
     662           0 : void DofObject::print_dof_info() const
     663             : {
     664           0 :   libMesh::out << this->id() << " [ ";
     665             : 
     666           0 :   for (auto s : make_range(this->n_systems()))
     667             :     {
     668           0 :       libMesh::out << "s:" << s << " ";
     669           0 :       for (auto var : make_range(this->n_vars(s)))
     670             :         {
     671           0 :           libMesh::out << "v:" << var << " ";
     672           0 :           for (auto comp : make_range(this->n_comp(s,var)))
     673             :             {
     674           0 :               libMesh::out << "c:" << comp << " dof:" << this->dof_number(s,var,comp) << " ";
     675             :             }
     676             :         }
     677             :     }
     678             : 
     679           0 :   libMesh::out << "]\n";
     680           0 : }
     681             : 
     682             : 
     683             : 
     684             : } // namespace libMesh

Generated by: LCOV version 1.14