LCOV - code coverage report
Current view: top level - src/systems - parameter_vector.C (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 0 53 0.0 %
Date: 2025-08-19 19:27:09 Functions: 0 10 0.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/parameter_vector.h"
      22             : 
      23             : #include "libmesh/int_range.h"
      24             : #include "libmesh/parameter_pointer.h"
      25             : 
      26             : namespace libMesh
      27             : {
      28             : 
      29           0 : ParameterVector::ParameterVector(const std::vector<Number *> &params)
      30             : #ifndef NDEBUG
      31           0 :   : _is_shallow_copy(false)
      32             : #endif
      33             : {
      34           0 :   _params.reserve(params.size());
      35             : 
      36           0 :   for (auto p : params)
      37           0 :     _params.push_back(std::make_unique<ParameterPointer<Number>>(p));
      38           0 : }
      39             : 
      40             : 
      41             : 
      42           0 : void ParameterVector::deep_copy(ParameterVector & target) const
      43             : {
      44           0 :   const std::size_t Np = this->_params.size();
      45           0 :   target.clear();
      46           0 :   target._params.resize(Np);
      47           0 :   target._my_data.resize(Np);
      48             : #ifndef NDEBUG
      49           0 :   target._is_shallow_copy = false;
      50             : #endif
      51           0 :   for (std::size_t i=0; i != Np; ++i)
      52             :     {
      53           0 :       target._params[i] =
      54             :         std::make_unique<ParameterPointer<Number>>
      55           0 :           (&target._my_data[i]);
      56           0 :       target._my_data[i] = *(*this)[i];
      57             :     }
      58           0 : }
      59             : 
      60             : 
      61             : 
      62           0 : void ParameterVector::shallow_copy(ParameterVector & target) const
      63             : {
      64           0 :   target._my_data.clear();
      65           0 :   target._params.resize(this->_params.size());
      66           0 :   for (auto i : index_range(this->_params))
      67           0 :     target._params[i] = this->_params[i]->clone();
      68             : #ifndef NDEBUG
      69           0 :   target._is_shallow_copy = true;
      70             : #endif
      71           0 : }
      72             : 
      73             : 
      74             : 
      75           0 : void ParameterVector::value_copy(ParameterVector & target) const
      76             : {
      77           0 :   const std::size_t Np = this->_params.size();
      78           0 :   libmesh_assert_equal_to (target._params.size(), Np);
      79             : 
      80           0 :   for (std::size_t i=0; i != Np; ++i)
      81           0 :     *target[i] = *(*this)[i];
      82           0 : }
      83             : 
      84             : 
      85             : 
      86           0 : void ParameterVector::resize(std::size_t s)
      87             : {
      88           0 :   libmesh_assert(!_is_shallow_copy);
      89             : 
      90           0 :   this->_params.resize(s);
      91             : 
      92             :   // We used to make nullptr ParameterPointers here, but that was just
      93             :   // to keep our destructor happy; users couldn't reseat them so
      94             :   // shouldn't have code depending on them
      95           0 : }
      96             : 
      97             : 
      98             : 
      99           0 : void ParameterVector::deep_resize(std::size_t s)
     100             : {
     101           0 :   libmesh_assert(!_is_shallow_copy);
     102             : 
     103           0 :   this->_params.resize(s);
     104           0 :   this->_my_data.resize(s);
     105           0 :   for (std::size_t i=0; i != s; ++i)
     106           0 :     this->_params[i] =
     107           0 :       std::make_unique<ParameterPointer<Number>>(&this->_my_data[i]);
     108           0 : }
     109             : 
     110             : 
     111             : 
     112           0 : ParameterVector & ParameterVector::operator *= (const Number a)
     113             : {
     114           0 :   const std::size_t Np = this->_params.size();
     115           0 :   for (std::size_t i=0; i != Np; ++i)
     116           0 :     *(*this)[i] *= a;
     117           0 :   return *this;
     118             : }
     119             : 
     120             : 
     121             : 
     122           0 : ParameterVector & ParameterVector::operator += (const ParameterVector & a)
     123             : {
     124           0 :   const std::size_t Np = this->_params.size();
     125           0 :   libmesh_assert_equal_to (a._params.size(), Np);
     126           0 :   for (std::size_t i=0; i != Np; ++i)
     127           0 :     *(*this)[i] += *a[i];
     128           0 :   return *this;
     129             : }
     130             : 
     131             : 
     132             : } // namespace libMesh

Generated by: LCOV version 1.14