Page MenuHomec4science

array.cc
No OneTemporary

File Metadata

Created
Sat, Mar 29, 16:12

array.cc

/**
* @file array.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Fri Jul 11 15:47:44 2014
*
* @brief This is a wrapper to a vector type to be used when algebra is needed
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* LibMultiScale is free software: you can redistribute it and/or modify it
* under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* LibMultiScale is distributed in the hope that it will be useful, but
* WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with LibMultiScale. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "array.hh"
#include "lm_common.hh"
/* -------------------------------------------------------------------------- */
#include <cstring>
#include <fstream>
#include <iomanip>
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
Array::Array(UInt t) { vector.resize(t); }
/* -------------------------------------------------------------------------- */
Array::Array() {}
/* -------------------------------------------------------------------------- */
Array::~Array() {}
/* -------------------------------------------------------------------------- */
void Array::add(UInt i, Real val) { vector[i] += val; }
/* -------------------------------------------------------------------------- */
void Array::close() {}
/* -------------------------------------------------------------------------- */
void Array::printToFile(char *f, UInt step) {
std::ofstream file(f);
printToFile(file, step);
}
/* -------------------------------------------------------------------------- */
UInt Array::printToFile(std::ofstream &f, UInt step) {
for (UInt i = 0; i < vector.size(); ++i) {
f << i << "\t" << step << "\t" << std::setprecision(15) << std::scientific
<< vector[i] << std::endl;
}
return 0;
}
/* -------------------------------------------------------------------------- */
Real *Array::getArray() { return &vector[0]; }
/* -------------------------------------------------------------------------- */
UInt Array::zero() {
vector.assign(vector.size(), 0); // mise a zero
return 0;
}
/* -------------------------------------------------------------------------- */
extern "C" {
::libmultiscale::UInt scaleArray(::libmultiscale::Real *vector,
::libmultiscale::UInt taille,
::libmultiscale::Real alpha);
}
/* -------------------------------------------------------------------------- */
void Array::scale(Real a) { scaleArray(&vector[0], vector.size(), a); }
/* -------------------------------------------------------------------------- */
UInt Array::size() { return vector.size(); }
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__

Event Timeline