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

Generated by: LCOV version 1.14