65 else if(newsize<
size()) conservativeResize(newsize);
66 else (*
this)=VectorXd::Zero(newsize);
71 if(n==
size()){
_DBG(
"rwv/AFTER");
return; }
73 VectorXd::conservativeResize(n);
74 (*this).tail(
size()-size0).array()=0.;
80 VectorXd::conservativeResize(n);
81 (*this).tail(
size()-size0).array()=0.;
87 if ( (newsize) < this->
size() ) {
88 this->
values.resize((newsize));
89 }
else if ( (newsize) > this->
size() ) {
90 this->
values.assign((newsize), 0.);
94 void FloatArray :: resize(
int n)
103 void FloatArray :: resizeWithValues(
Index n, std::size_t allocChunk)
106 if ( allocChunk < 0 ) {
107 OOFEM_FATAL(
"allocChunk must be non-negative; %ld", allocChunk);
112 if ( allocChunk > 0 && (
Index)this->
values.capacity() < n ) {
113 this->
values.reserve(n + allocChunk);
126 for(
const double& x: lst) ret(i++)=x;
134 for(
size_t i=0; i<v.size(); i++) ret(i)=v[i];
142 for(
const double& x: ini) ret(i++)=x;
147 int len=0;
for(
const auto& a: ini) len+=a.
size();
150 for(
const auto& a: ini){
151 for(
Index i=0; i<a.size(); i++) ret[ix++]=a[i];
159bool FloatArray :: isAllFinite()
const {
return this->array().isFinite().all(); }
160void FloatArray :: beScaled(
double s,
const FloatArray &b){ *
this=b*s; }
161void FloatArray :: add(
const FloatArray &b){
if(b.isEmpty())
return;
if(this->isEmpty()){ *
this=b;
return; } *
this+=b; }
162void FloatArray :: add(
double offset){ this->array()+=offset; }
163void FloatArray :: add(
double factor,
const FloatArray &b) {
if(this->isEmpty()){ *
this=factor*b;
return; } *
this+=factor*b; }
164void FloatArray :: plusProduct(
const FloatMatrix &b,
const FloatArray &s,
double dV){
if(this->isEmpty()){ *
this=b.transpose()*s*dV;
return; } *
this+=b.transpose()*s*dV; }
165void FloatArray :: subtract(
const FloatArray &src){
if(src.isEmpty())
return;
if(this->isEmpty()){ *
this=-src;
return; } *
this-=src; }
166void FloatArray :: beMaxOf(
const FloatArray &a,
const FloatArray &b){
if(a.isEmpty()){ *
this=b;
return; }
if(b.isEmpty()){ *
this=a;
return; } *
this=a.array().max(b.array()).matrix(); }
167void FloatArray :: beMinOf(
const FloatArray &a,
const FloatArray &b){
if(a.isEmpty()){ *
this=b;
return; }
if(b.isEmpty()){ *
this=a;
return; } *
this=a.array().min(b.array()).matrix(); }
170void FloatArray :: beSubArrayOf(
const FloatArray &src,
const IntArray &indx){ *
this=src(indx.minusOne()); }
171void FloatArray :: addSubVector(
const FloatArray &src,
Index si){ {
int req=(si-1)+src.size();
if(this->size()<req) this->resizeWithValues(req); } this->segment(si-1,src.size())=src; }
172void FloatArray :: beVectorProductOf(
const FloatArray &v1,
const FloatArray &v2){ Eigen::Ref<const Eigen::Vector3d> v1r(v1), v2r(v2); *
this=v1r.cross(v2r); }
173int FloatArray :: giveIndexMinElem(){ Eigen::Index ix; this->minCoeff(&ix);
return ix+1; }
174int FloatArray :: giveIndexMaxElem(){ Eigen::Index ix; this->maxCoeff(&ix);
return ix+1; }
176double FloatArray :: dotProduct(
const FloatArray &x)
const {
return this->
dot(x); }
178double FloatArray :: dotProduct(
const FloatArray &x,
Index size)
const {
return this->head(size).dot(x.head(size)); }
179double FloatArray :: distance_square(
const FloatArray &from)
const {
return (from-(*
this)).squaredNorm(); }
180void FloatArray :: checkSizeTowards(
const IntArray &loc){
int sz=loc.maximum();
if(this->size()<sz) this->resize(sz); }
181bool FloatArray :: containsOnlyZeroes()
const {
return (this->array()==0.).all(); }
182void FloatArray :: zero() { this->array()=0.; }
183void FloatArray :: beProductOf(
const FloatMatrix &aMatrix,
const FloatArray &anArray){ *
this=aMatrix*anArray; }
184void FloatArray :: beTProductOf(
const FloatMatrix &aMatrix,
const FloatArray &anArray){ *
this=anArray.transpose()*aMatrix; }
185void FloatArray :: negated() { *
this*=-1; }
186void FloatArray :: times(
double factor){ this->array()*=factor; }
187double FloatArray :: sum()
const {
return this->array().sum(); }
188double FloatArray :: product()
const {
return this->array().prod(); }
189void FloatArray :: copySubVector(
const FloatArray &src,
int si){ this->resizeWithValues(src.size()+si-1); this->tail(src.size())=src; }
190void FloatArray :: power(
const double exponent){ *
this=this->array().pow(exponent).matrix(); }
191void FloatArray :: beColumnOf(
const FloatMatrix &mat,
int col){ *
this=mat.col(col-1); }
192void FloatArray :: beRowOf(
const FloatMatrix &mat,
Index row){ *
this=mat.row(row-1).transpose(); }
195bool FloatArray :: isAllFinite()
const
197 for(
Index i=0; i<this->size(); i++){
198 if(!std::isfinite((*
this)[i])) {
212 for (
Index i = 0; i < this->size(); ++i ) {
213 (*this) [ i ] = s * b [ i ];
227 if ( !this->size() ) {
233 if ( this->size() != b.
size() ) {
239#ifdef __LAPACK_MODULE
245 for (
Index i = 0; i < this->size(); i++ ) {
246 (*this) [ i ] += b [ i ];
252void FloatArray :: add(
double offset)
254 for (
double &x: *
this ) {
270 if ( this->size() != b.
size() ) {
276#ifdef __LAPACK_MODULE
281 for (
Index i = 0; i < this->size(); ++i ) {
282 (*this) [ i ] += factor * b [ i ];
304#ifdef __LAPACK_MODULE
307 dgemv_(
"t", & nRows, & nColumns, & dV, b.
givePointer(), & nRows, s.
givePointer(), & inc, & beta, this->givePointer(), & inc, nColumns, nColumns, nRows);
309 for (
Index i = 1; i <= nColumns; i++ ) {
311 for (
Index j = 1; j <= nRows; j++ ) {
314 this->
at(i) +=
sum * dV;
330 for (
Index i = 0; i < this->size(); ++i ) {
331 (*this) [ i ] = -src [ i ];
338 if ( this->size() != src.
size() ) {
344 for (
Index i = 0; i < this->size(); ++i ) {
345 (*this) [ i ] -= src [ i ];
354 if ( a.
size() == 0 ) {
357 }
else if ( b.
size() == 0 ) {
363 if ( n != b.
size() ) {
371 for (
Index i = 0; i < n; i++ ) {
372 (*this) [ i ] =
max( a [ i ], b [ i ] );
381 if ( a.
size() == 0 ) {
384 }
else if ( b.
size() == 0 ) {
390 if ( n != b.
size() ) {
397 for (
Index i = 0; i < n; i++ ) {
398 (*this) [ i ] =
min( a [ i ], b [ i ] );
413 for (
int i = 0; i < this->
giveSize(); ++i ) {
414 (*this) [ i ] = a [ i ] - b [ i ];
419 (*this)[i]=a[i] - b[i];
428 if ( a.
size() < n || b.
size() < n ) {
434 for (
Index i = 0; i < n; ++i ) {
435 (*this) [ i ] = a [ i ] - b [ i ];
454 for (
Index i = 1; i <= n; i++ ) {
455 this->
at(i) = src.
at( indx.
at(i) );
466 if ( this->size() < reqSize ) {
470 for (
Index i = 0; i < n; i++ ) {
471 (*this) [si + i] += src [ i ];
481 OOFEM_ERROR(
"size mismatch, size is not equal to 3");
487 this->
at(1) = v1.
at(2) * v2.
at(3) - v1.
at(3) * v2.
at(2);
488 this->
at(2) = v1.
at(3) * v2.
at(1) - v1.
at(1) * v2.
at(3);
489 this->
at(3) = v1.
at(1) * v2.
at(2) - v1.
at(2) * v2.
at(1);
492int FloatArray :: giveIndexMinElem()
498 double val = (*this) [ 0 ];
499 for (
Index i = 1; i < this->size(); i++ ) {
500 if ( val > (*
this) [ i ] ) {
508int FloatArray :: giveIndexMaxElem()
514 double val = (*this) [ 0 ];
515 for (
Index i = 1; i < this->size(); i++ ) {
516 if ( val < (*
this) [ i ] ) {
527 if ( this->size() != x.
size() ) {
533 return std::inner_product(this->
begin(), this->
end(), x.
begin(), 0.);
556double FloatArray :: distance(
const FloatArray &iP1,
const FloatArray &iP2,
double &oXi,
double &oXiUnbounded)
const
561double FloatArray :: distance_square(
const FloatArray &iP1,
const FloatArray &iP2,
double &oXi,
double &oXiUnbounded)
const
583 const FloatArray q = ( 1.0 - oXi ) * iP1 + oXi * iP2;
599double FloatArray :: distance_square(
const FloatArray &from)
const
604 Index s =
min(this->size(), from.size());
605 for (
Index i = 1; i <= s; ++i ) {
606 double dx = this->
at(i) - from.at(i);
628 for (
Index i = 1; i <= n; i++ ) {
631 this->
at(ii) += fe.
at(i);
649 for (
Index i = 1; i <= n; i++ ) {
652 this->
at(ii) += fe.
at(i) * fe.
at(i);
658void FloatArray :: checkSizeTowards(
const IntArray &loc)
671bool FloatArray :: containsOnlyZeroes()
const
673 for (
double x : *
this ) {
683void FloatArray :: zero()
685 std::fill(this->
begin(), this->
end(), 0.);
704#ifdef __LAPACK_MODULE
705 double alpha = 1., beta = 0.;
707 dgemv_(
"n", & nRows, & nColumns, & alpha, aMatrix.
givePointer(), & nRows, anArray.
givePointer(), & inc, & beta, this->givePointer(), & inc, nColumns, nColumns, nRows);
709 for (
Index i = 1; i <= nRows; i++ ) {
711 for (
Index j = 1; j <= nColumns; j++ ) {
712 sum += aMatrix.
at(i, j) * anArray.
at(j);
735#ifdef __LAPACK_MODULE
736 double alpha = 1., beta = 0.;
738 dgemv_(
"t", & nRows, & nColumns, & alpha, aMatrix.
givePointer(), & nRows, anArray.
givePointer(), & inc, & beta, this->givePointer(), & inc, nColumns, nColumns, nRows);
740 for (
Index i = 1; i <= nColumns; i++ ) {
742 for (
Index j = 1; j <= nRows; j++ ) {
743 sum += aMatrix.
at(j, i) * anArray.
at(j);
752void FloatArray :: negated()
754 for (
double &x: *
this ) {
762void FloatArray :: printYourself() const
765 printf(
"FloatArray of size : %d \n", (
int)this->
giveSize());
766 for (
double x: *
this ) {
767 printf(
"%10.3e ", x );
774void FloatArray :: printYourself(
const std::string &name)
const
777 printf(
"%s (%d): \n", name.c_str(), (
int)this->giveSize());
778 for (
double x: *
this ) {
779 printf(
"%10.3e ", x );
785void FloatArray :: printYourselfToFile(
const std::string filename,
const bool showDimensions)
const
788 std :: ofstream arrayfile (filename);
789 if (arrayfile.is_open()) {
791 arrayfile <<
"FloatArray of size : " << this->
giveSize() <<
"\n";
792 arrayfile << std::scientific << std::right << std::setprecision(3);
793 for (
double x: *
this ) {
794 arrayfile << std::setw(10) << x <<
"\t";
802void FloatArray :: pY() const
806 for (
double x: *
this ) {
807 printf(
"%20.14e; ", x );
823 }
else if ( mode ==
'n' ) {
834void FloatArray :: times(
double factor)
838 for (
double &x : *
this ) {
845void FloatArray :: normalize(){
850double FloatArray :: normalize_giveNorm()
853 if (
norm < 1.e-80 ) {
854 OOFEM_ERROR(
"cannot norm receiver, norm is too small");
861double FloatArray :: computeNorm()
const
867double FloatArray :: computeSquaredNorm()
const
869 return std::inner_product(this->
begin(), this->
end(), this->
begin(), 0.);
874double FloatArray :: sum()
const
876 return std::accumulate(this->
begin(), this->
end(), 0.);
880double FloatArray :: product()
const
882 return std::accumulate(this->
begin(), this->
end(), 1.0, [](
double a,
double b) {
return a*b; });
886void FloatArray :: copySubVector(
const FloatArray &src,
int si)
890 std :: copy( src.
begin(), src.
end(), this->begin() + si);
902 if ( !stream.write(
size) ) {
908 if ( !stream.write(this->givePointer(),
size) ) {
933 if ( !stream.
read(this->givePointer(),
size) ) {
1095 ( aMatrix.
at(2, 3) + aMatrix.
at(3, 2) ),
1096 ( aMatrix.
at(1, 3) + aMatrix.
at(3, 1) ),
1097 ( aMatrix.
at(1, 2) + aMatrix.
at(2, 1) )
1116 0.5 * ( aMatrix.
at(2, 3) + aMatrix.
at(3, 2) ),
1117 0.5 * ( aMatrix.
at(1, 3) + aMatrix.
at(3, 1) ),
1118 0.5 * ( aMatrix.
at(1, 2) + aMatrix.
at(2, 1) )
1122void FloatArray :: changeComponentOrder()
1128 std :: swap( this->
at(4), this->
at(6) );
1129 }
else if ( this->
giveSize() == 9 ) {
1132 const int abq2oo [ 9 ] = {
1133 1, 2, 3, 6, 5, 4, 7, 9, 8
1137 for (
int i = 0; i < 9; i++ ) {
1138 tmp(i) = this->
at(abq2oo [ i ]);
1149 for (
double xi : x ) {
1173void FloatArray :: power(
const double exponent)
1175 for (
double &x : *
this ) {
1176 x = std::pow(x, exponent);
1195 OOFEM_ERROR(
"dimension mismatch, matrix rows = %d, wanted row = %d", nRows, row)
1200 for (
Index i = 1; i <= nColumns; i++ ) {
1201 this->
at(i) = mat.
at(row,i);
virtual int read(int *data, std::size_t count)=0
Reads count integer values into array pointed by data.
virtual int givePackSizeOfDouble(std::size_t count)=0
virtual int givePackSizeOfSizet(std::size_t count)=0
double computeNorm() const
bool containsOnlyZeroes() const
static FloatArray fromIniList(std::initializer_list< double > ini)
double distance(const FloatArray &x) const
double computeSquaredNorm() const
std::vector< double > values
Stored values.
double dotProduct(const FloatArray &x) const
bool isAllFinite() const
Returns true if no element is NAN or infinite.
std::vector< double >::iterator begin()
Index giveSize() const
Returns the size of receiver.
void resizeWithValues(Index s, std::size_t allocChunk=0)
static FloatArray fromVector(const std::vector< double > &v)
void _resize_internal(Index newsize)
void beDifferenceOf(const FloatArray &a, const FloatArray &b)
static FloatArray fromConcatenated(std::initializer_list< FloatArray > ini)
double distance_square(const FloatArray &iP1, const FloatArray &iP2, double &oXi, double &oXiUnbounded) const
void beProductOf(const FloatMatrix &aMatrix, const FloatArray &anArray)
double normalize_giveNorm()
void beScaled(double s, const FloatArray &b)
bool isEmpty() const
Returns true if receiver is empty.
void beTProductOf(const FloatMatrix &aMatrix, const FloatArray &anArray)
static FloatArray fromList(const std::list< double > &l)
void add(const FloatArray &src)
const double * givePointer() const
void subtract(const FloatArray &src)
std::vector< double >::iterator end()
FloatArray(int n=0)
Constructor for sized array. Data is zeroed.
const double * givePointer() const
void copyColumn(FloatArray &dest, int c) const
int giveNumberOfColumns() const
Returns number of columns of receiver.
int giveNumberOfRows() const
Returns number of rows of receiver.
double at(std::size_t i, std::size_t j) const
FloatArray operator+(const FloatArray &x, const FloatArray &y)
double norm(const FloatArray &x)
FloatArrayF< N > min(const FloatArrayF< N > &a, const FloatArrayF< N > &b)
double norm_square(const FloatArray &x)
bool iszero(const FloatArray &x)
FloatArray operator-(const FloatArray &x, const FloatArray &y)
FloatArrayF< N > max(const FloatArrayF< N > &a, const FloatArrayF< N > &b)
FloatArray & operator/=(FloatArray &x, const double &a)
FloatArray & operator+=(FloatArray &x, const FloatArray &y)
std::ostream & operator<<(std ::ostream &out, const Dictionary &r)
double sum(const FloatArray &x)
double dot(const FloatArray &x, const FloatArray &y)
bool isfinite(const FloatArray &x)
FloatArray & operator-=(FloatArray &x, const FloatArray &y)
double product(const FloatArray &x)
FloatArray operator*(const double &a, const FloatArray &x)
FloatArray & operator*=(FloatArray &x, const double &a)
Vector multiplication by scalar.
double distance(const FloatArray &x, const FloatArray &y)
double distance_square(const FloatArray &x, const FloatArray &y)
@ CIO_IOERR
General IO error.