$extrastylesheet
parameter_vector.C
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 
00020 // C++ Includes   -----------------------------------
00021 
00022 // Local Includes -----------------------------------
00023 #include "libmesh/parameter_vector.h"
00024 
00025 namespace libMesh
00026 {
00027 
00028 // ------------------------------------------------------------
00029 // ParameterVector implementation
00030 
00031 
00032 
00033 void ParameterVector::deep_copy(ParameterVector &target) const
00034 {
00035   const unsigned int Np = cast_int<unsigned int>
00036     (this->_params.size());
00037   target.clear();
00038   target._params.resize(Np);
00039   target._my_data.resize(Np);
00040   for (unsigned int i=0; i != Np; ++i)
00041     {
00042       target._params[i] =
00043         new ParameterPointer<Number>(&target._my_data[i]);
00044       target._my_data[i] = *(*this)[i];
00045     }
00046 }
00047 
00048 
00049 
00050 void ParameterVector::shallow_copy(ParameterVector &target) const
00051 {
00052   target._my_data.clear();
00053   target._params = this->_params;
00054   target._is_shallow_copy = true;
00055 }
00056 
00057 
00058 
00059 void ParameterVector::value_copy(ParameterVector &target) const
00060 {
00061   const unsigned int Np = cast_int<unsigned int>
00062     (this->_params.size());
00063   libmesh_assert_equal_to (target._params.size(), Np);
00064 
00065   for (unsigned int i=0; i != Np; ++i)
00066     *target[i] = *(*this)[i];
00067 }
00068 
00069 
00070 
00071 void ParameterVector::resize(unsigned int s)
00072 {
00073   libmesh_assert(!_is_shallow_copy);
00074 
00075   const std::size_t old_size = this->_params.size();
00076 
00077   // If we're shrinking the vector, we don't want to leak memory.
00078   // Note that we're using < in these for loops, not !=
00079   // We don't know a priori if we're shrinking or growing
00080   for (unsigned int i=s; i < old_size; ++i)
00081     delete _params[i];
00082 
00083   this->_params.resize(s);
00084 
00085   for (unsigned int i=old_size; i < s; ++i)
00086     this->_params[i] =
00087       new ParameterPointer<Number>(NULL);
00088 }
00089 
00090 
00091 
00092 void ParameterVector::deep_resize(unsigned int s)
00093 {
00094   libmesh_assert(!_is_shallow_copy);
00095 
00096   this->_params.resize(s);
00097   this->_my_data.resize(s);
00098   for (unsigned int i=0; i != s; ++i)
00099     this->_params[i] =
00100       new ParameterPointer<Number>(&this->_my_data[i]);
00101 }
00102 
00103 
00104 
00105 ParameterVector& ParameterVector::operator *= (const Number a)
00106 {
00107   const unsigned int Np = cast_int<unsigned int>
00108     (this->_params.size());
00109   for (unsigned int i=0; i != Np; ++i)
00110     *(*this)[i] *= a;
00111   return *this;
00112 }
00113 
00114 
00115 
00116 ParameterVector& ParameterVector::operator += (const ParameterVector& a)
00117 {
00118   const unsigned int Np = cast_int<unsigned int>
00119     (this->_params.size());
00120   libmesh_assert_equal_to (a._params.size(), Np);
00121   for (unsigned int i=0; i != Np; ++i)
00122     *(*this)[i] += *a[i];
00123   return *this;
00124 }
00125 
00126 
00127 } // namespace libMesh