25 #include <queso/Defines.h>
27 #ifdef QUESO_HAS_TRILINOS
29 #include <queso/TeuchosVector.h>
38 TeuchosVector::TeuchosVector() :
43 "TeuchosVector::constructor(), default",
44 "should not be used by user");
49 TeuchosVector::TeuchosVector(
const BaseEnvironment& env,
const Map& map)
53 m_vec.size(map.NumGlobalElements());
57 "TeuchosVector::constructor(1)",
58 "null vector generated");
62 "TeuchosVector::constructor(1)",
63 "incompatible local vec size");
67 "TeuchosVector::constructor(1)",
68 "incompatible global vec size");
72 "TeuchosVector::constructor(1)",
73 "incompatible own vec size");
83 TeuchosVector::TeuchosVector(
const BaseEnvironment& env,
const Map& map,
double value)
87 m_vec.size(map.NumGlobalElements());
92 "TeuchosVector::constructor(2)",
93 "null vector generated");
97 "TeuchosVector::constructor(2)",
98 "incompatible local vec size");
102 "TeuchosVector::constructor(2)",
103 "incompatible global vec size");
107 "TeuchosVector::constructor(2)",
108 "incompatible own vec size");
112 TeuchosVector::TeuchosVector(
const BaseEnvironment& env,
double d1,
double d2,
const Map& map)
116 m_vec.size(map.NumGlobalElements());
120 "TeuchosVector::constructor(3), linspace",
121 "null vector generated");
125 "TeuchosVector::constructor(3)",
126 "incompatible local vec size");
130 "TeuchosVector::constructor(3)",
131 "incompatible global vec size");
133 for (
int i = 0; i < m_vec.length(); ++i) {
134 double alpha = (double) i / ((
double) m_vec.length() - 1.);
135 (*this)[i] = (1.-alpha)*d1 + alpha*d2;
140 "TeuchosVector::constructor(3)",
141 "incompatible own vec size");
145 TeuchosVector::TeuchosVector(
const TeuchosVector& v,
double d1,
double d2)
147 Vector(v.env(),v.map())
149 m_vec.size(v.sizeLocal());
153 "TeuchosVector::constructor(4), linspace",
154 "null vector generated");
158 "TeuchosVector::constructor(4)",
159 "incompatible local vec size");
163 "TeuchosVector::constructor(4)",
164 "incompatible global vec size");
166 for (
int i = 0; i < m_vec.length(); ++i) {
167 double alpha = (double) i / ((
double) m_vec.length() - 1.);
168 (*this)[i] = (1.-alpha)*d1 + alpha*d2;
173 "TeuchosVector::constructor(4)",
174 "incompatible own vec size");
178 TeuchosVector::TeuchosVector(
const TeuchosVector& v)
180 Vector(v.env(),v.map())
182 m_vec.size(v.sizeLocal());
186 "TeuchosVector::constructor(5), copy",
187 "null vector generated");
191 "TeuchosVector::constructor(5)",
192 "incompatible local vec size");
196 "TeuchosVector::constructor(5)",
197 "incompatible global vec size");
202 "TeuchosVector::constructor(5)",
203 "incompatible own vec size");
208 TeuchosVector::~TeuchosVector()
215 TeuchosVector& TeuchosVector::operator=(
double a)
222 TeuchosVector& TeuchosVector::operator=(
const TeuchosVector& rhs)
224 unsigned int size1 = m_vec.length();
225 unsigned int size2 = rhs.sizeLocal();
229 "TeuchosVector::operator=()",
230 "the vectors do NOT have the same size.\n");
233 for (
unsigned int i=0;i<size1;i++){
242 TeuchosVector& TeuchosVector::operator*=(
double a)
249 TeuchosVector& TeuchosVector::operator/=(
double a)
256 TeuchosVector& TeuchosVector::operator*=(
const TeuchosVector& rhs)
258 unsigned int size1 = this->sizeLocal();
259 unsigned int size2 = rhs.sizeLocal();
262 "TeuchosVector::operator*=()",
263 "the vectors do NOT have the same size.\n");
265 for (
unsigned int i = 0; i < size1; ++i) {
266 (*this)[i] *= rhs[i];
273 TeuchosVector& TeuchosVector::operator/=(
const TeuchosVector& rhs)
275 unsigned int size1 = this->sizeLocal();
276 unsigned int size2 = rhs.sizeLocal();
280 "TeuchosVector::operator/=()",
281 "the vectors do NOT have the same size.\n");
283 for (
unsigned int i = 0; i < size1; ++i) {
284 (*this)[i] /= rhs[i];
291 TeuchosVector& TeuchosVector::operator+=(
const TeuchosVector& rhs)
293 unsigned int size1 = this->sizeLocal();
294 unsigned int size2 = rhs.sizeLocal();
298 "TeuchosVector::operator+=()",
299 "the vectors do NOT have the same size.\n");
302 for (
unsigned int i = 0; i < size1; ++i) {
303 (*this)[i] += rhs[i];
310 TeuchosVector& TeuchosVector::operator-=(
const TeuchosVector& rhs)
312 unsigned int size1 = this->sizeLocal();
313 unsigned int size2 = rhs.sizeLocal();
317 "TeuchosVector::operator-=()",
318 "the vectors do NOT have the same size.\n");
321 for (
unsigned int i = 0; i < size1; ++i) {
322 (*this)[i] -= rhs[i];
332 double& TeuchosVector::operator[](
unsigned int i)
338 const double& TeuchosVector::operator[](
unsigned int i)
const
345 unsigned int TeuchosVector::sizeLocal()
const
349 "TeuchosVector::sizeLocal()",
350 "incompatible vec size");
352 return m_vec.length();
356 unsigned int TeuchosVector::sizeGlobal()
const
360 "TeuchosVector::sizeGlobal()",
361 "incompatible vec size");
362 return m_vec.length();
368 TeuchosVector::values()
370 return m_vec.values();
375 double TeuchosVector::getMaxValue( ) const
377 const unsigned int size = this->sizeLocal();
378 std::vector<double> aux;
380 for (
unsigned int i=0; i<size; i++ ) {
381 aux.push_back((*
this)[i]) ;
384 return *max_element (aux.begin(),aux.end());
388 double TeuchosVector::getMinValue( ) const
390 const unsigned int size = this->sizeLocal();
391 std::vector<double> aux;
393 for (
unsigned int i=0; i<size; i++ ) {
394 aux.push_back((*
this)[i]) ;
397 return *min_element (aux.begin(),aux.end());
402 int TeuchosVector::getMaxValueIndex( ) const
404 const unsigned int size = this->sizeLocal();
405 std::vector<double> vect;
407 for (
unsigned int i=0; i<size; i++ ) {
408 vect.push_back((*
this)[i]) ;
410 std::vector<double>::iterator iter_max = max_element(vect.begin(), vect.end());
411 return distance(vect.begin(), iter_max);
415 int TeuchosVector::getMinValueIndex( ) const
417 const unsigned int size = this->sizeLocal();
418 std::vector<double> vect;
420 for (
unsigned int i=0; i<size; i++ ) {
421 vect.push_back((*
this)[i]) ;
423 std::vector<double>::iterator iter_min = min_element(vect.begin(), vect.end());
424 return distance(vect.begin(), iter_min);
428 void TeuchosVector::getMaxValueAndIndex(
double& max_value,
int& max_value_index )
430 const unsigned int size = this->sizeLocal();
431 std::vector<double> vect;
433 for (
unsigned int i=0; i<size; i++ ) {
434 vect.push_back((*
this)[i]) ;
436 std::vector<double>::iterator iter_max = max_element(vect.begin(), vect.end());
438 max_value = *iter_max;
439 max_value_index = distance(vect.begin(), iter_max);
445 void TeuchosVector::getMinValueAndIndex(
double& min_value,
int& min_value_index )
447 const unsigned int size = this->sizeLocal();
448 std::vector<double> vect;
450 for (
unsigned int i=0; i<size; i++ ) {
451 vect.push_back((*
this)[i]) ;
453 std::vector<double>::iterator iter_min = min_element(vect.begin(), vect.end());
455 min_value = *iter_min;
456 min_value_index = distance(vect.begin(), iter_min);
463 double TeuchosVector::norm2Sq()
const
465 return (m_vec).dot(m_vec );
469 double TeuchosVector::norm2()
const
471 return std::sqrt(this->norm2Sq());
475 double TeuchosVector::norm1()
const
479 unsigned int size = this->sizeLocal();
480 for (
unsigned int i = 0; i < size; ++i) {
481 result += fabs((*
this)[i]);
488 double TeuchosVector::normInf()
const
492 unsigned int size = this->sizeLocal();
494 for (
unsigned int i = 0; i < size; ++i) {
495 aux = fabs((*
this)[i]);
496 if (aux > result) result = aux;
505 TeuchosVector::atLeastOneComponentSmallerThan(
const TeuchosVector& rhs)
const
509 "TeuchosVector::atLeastOneComponentSmallerThan()",
510 "vectors have different sizes");
514 unsigned int size = this->sizeLocal();
515 while ((i < size) && (result ==
false)) {
516 result = ( (*this)[i] < rhs[i] );
525 TeuchosVector::atLeastOneComponentBiggerThan(
const TeuchosVector& rhs)
const
529 "TeuchosVector::atLeastOneComponentBiggerThan()",
530 "vectors have different sizes");
534 unsigned int size = this->sizeLocal();
535 while ((i < size) && (result ==
false)) {
536 result = ( (*this)[i] > rhs[i] );
545 TeuchosVector::atLeastOneComponentSmallerOrEqualThan(
const TeuchosVector& rhs)
const
549 "TeuchosVector::atLeastOneComponentSmallerOrEqualThan()",
550 "vectors have different sizes");
554 unsigned int size = this->sizeLocal();
555 while ((i < size) && (result ==
false)) {
556 result = ( (*this)[i] <= rhs[i] );
565 TeuchosVector::atLeastOneComponentBiggerOrEqualThan(
const TeuchosVector& rhs)
const
569 "TeuchosVector::atLeastOneComponentBiggerOrEqualThan()",
570 "vectors have different sizes");
574 unsigned int size = this->sizeLocal();
575 while ((i < size) && (result ==
false)) {
576 result = ( (*this)[i] >= rhs[i] );
586 void TeuchosVector::cwSet(
double value)
594 void TeuchosVector::cwSet(
unsigned int initialPos,
const TeuchosVector& vec)
598 "TeuchosVector::cwSet()",
599 "invalid initialPos");
603 "TeuchosVector::cwSet()",
604 "invalid vec.sizeLocal()");
606 for (
unsigned int i = 0; i < vec.sizeLocal(); ++i) {
607 (*this)[initialPos+i] = vec[i];
616 void TeuchosVector::cwExtract(
unsigned int initialPos, TeuchosVector& vec)
const
620 "TeuchosVector::cwExtract()",
621 "invalid initialPos");
625 "TeuchosVector::cwExtract()",
626 "invalid vec.sizeLocal()");
628 for (
unsigned int i = 0; i < vec.sizeLocal(); ++i) {
629 vec[i] = (*this)[initialPos+i];
636 void TeuchosVector::cwInvert()
638 unsigned int size = this->sizeLocal();
639 for (
unsigned int i = 0; i < size; ++i) {
640 (*this)[i] = 1./(*this)[i];
647 void TeuchosVector::cwSqrt()
649 unsigned int size = this->sizeLocal();
650 for (
unsigned int i = 0; i < size; ++i) {
651 (*this)[i] = sqrt((*
this)[i]);
659 TeuchosVector::cwSetConcatenated(
const TeuchosVector& v1,
const TeuchosVector& v2)
663 "TeuchosVector::cwSetConcatenated(1)",
664 "incompatible vector sizes");
674 for (
unsigned int i = 0; i < v1.sizeLocal(); ++i) {
678 for (
unsigned int i = 0; i < v2.sizeLocal(); ++i) {
679 (*this)[v1.sizeLocal()+i] = v2[i];
687 void TeuchosVector::cwSetGaussian(
double mean,
double stdDev)
689 for (
unsigned int i = 0; i < this->sizeLocal(); ++i) {
690 (*this)[i] = mean + m_env.rngObject()->gaussianSample(stdDev);
697 void TeuchosVector::cwSetGaussian(
const TeuchosVector& meanVec,
const TeuchosVector& stdDevVec)
699 for (
unsigned int i = 0; i < this->sizeLocal(); ++i) {
700 (*this)[i] = meanVec[i] + m_env.rngObject()->gaussianSample(stdDevVec[i]);
709 void TeuchosVector::cwSetUniform(
const TeuchosVector& aVec,
const TeuchosVector& bVec)
711 for (
unsigned int i = 0; i < this->sizeLocal(); ++i) {
712 (*this)[i] = aVec[i] + (bVec[i]-aVec[i])*m_env.rngObject()->uniformSample();
720 void TeuchosVector::cwSetBeta(
const TeuchosVector& alpha,
const TeuchosVector& beta)
724 "TeuchosVector::cwSetBeta()",
725 "incompatible alpha size");
729 "TeuchosVector::cwSetBeta()",
730 "incompatible beta size");
732 for (
unsigned int i = 0; i < this->sizeLocal(); ++i)
734 (*this)[i] = m_env.rngObject()->betaSample(alpha[i],beta[i]);
736 if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 99))
738 *m_env.subDisplayFile() <<
"In TeuchosVector::cwSetBeta()"
739 <<
": fullRank " << m_env.fullRank()
741 <<
", alpha[i] = " << alpha[i]
742 <<
", beta[i] = " << beta[i]
743 <<
", sample = " << (*this)[i]
752 void TeuchosVector::cwSetGamma(
const TeuchosVector& aVec,
const TeuchosVector& bVec)
756 "TeuchosVector::cwSetGamma()",
757 "incompatible a size");
761 "TeuchosVector::cwSetGamma()",
762 "incompatible b size");
764 for (
unsigned int i = 0; i < this->sizeLocal(); ++i) {
765 (*this)[i] = m_env.rngObject()->gammaSample(aVec[i],bVec[i]);
774 void TeuchosVector::cwSetInverseGamma(
const TeuchosVector& alpha,
const TeuchosVector& beta)
778 "TeuchosVector::cwSetInverseGamma()",
779 "incompatible alpha size");
783 "TeuchosVector::cwSetInverseGamma()",
784 "incompatible beta size");
786 for (
unsigned int i = 0; i < this->sizeLocal(); ++i) {
787 (*this)[i] = 1./m_env.rngObject()->gammaSample(alpha[i],1./beta[i]);
797 TeuchosVector::abs()
const
799 TeuchosVector abs_of_this_vec( *
this );
801 unsigned int size = abs_of_this_vec.sizeLocal();
803 for(
unsigned int i = 0; i < size; ++i )
805 abs_of_this_vec[i] = std::fabs( (*
this)[i] );
808 return abs_of_this_vec;
814 TeuchosVector::copy_to_std_vector(std::vector<double>& vec)
816 unsigned int size = this->sizeLocal();
819 for (
unsigned int i = 0; i < size; ++i)
827 TeuchosVector::copy_from_std_vector(
const std::vector<double> vec)
829 unsigned int size1 = vec.size(), size2= this->sizeLocal();
833 "In TeuchosVector::copy_from_std_vector()",
834 "vectors have different sizes");
836 for (
unsigned int i = 0; i < size1; ++i)
843 void TeuchosVector::sort()
845 std::vector<double> vec;
847 (*this).copy_to_std_vector(vec);
850 std::sort (vec.begin(), vec.end());
852 (*this).copy_from_std_vector(vec);
856 double TeuchosVector::sumOfComponents()
const
859 unsigned int size = this->sizeLocal();
860 for (
unsigned int i = 0; i < size; ++i) {
861 result += (*this)[i];
870 TeuchosVector::mpiBcast(
int srcRank,
const MpiComm& bcastComm)
873 if (bcastComm.MyPID() < 0)
return;
878 "TeuchosVector::mpiBcast()",
882 double localNumNodes = 1.;
883 double totalNumNodes = 0.;
885 "TeuchosVector::mpiBcast()",
886 "failed MPI.Allreduce() for numNodes");
889 "TeuchosVector::mpiBcast()",
890 "inconsistent numNodes");
893 double localVectorSize = this->sizeLocal();
894 double sumOfVectorSizes = 0.;
896 "TeuchosVector::mpiBcast()",
897 "failed MPI.Allreduce() for vectorSize");
899 if ( ((
unsigned int) sumOfVectorSizes) != ((
unsigned int)(totalNumNodes*localVectorSize)) ) {
900 std::cerr <<
"rank " << bcastComm.MyPID()
901 <<
": sumOfVectorSizes = " << sumOfVectorSizes
902 <<
", totalNumNodes = " << totalNumNodes
903 <<
", localVectorSize = " << localVectorSize
907 UQ_FATAL_TEST_MACRO(((
unsigned int) sumOfVectorSizes) != ((
unsigned int)(totalNumNodes*localVectorSize)),
909 "TeuchosVector::mpiBcast()",
910 "inconsistent vectorSize");
913 std::vector<double> dataBuffer((
unsigned int) localVectorSize, 0.);
914 if (bcastComm.MyPID() == srcRank) {
915 for (
unsigned int i = 0; i < dataBuffer.size(); ++i) {
916 dataBuffer[i] = (*this)[i];
920 bcastComm.Bcast((
void *) &dataBuffer[0], (
int) localVectorSize,
RawValue_MPI_DOUBLE, srcRank,
921 "TeuchosVector::mpiBcast()",
922 "failed MPI.Bcast()");
924 if (bcastComm.MyPID() != srcRank) {
925 for (
unsigned int i = 0; i < dataBuffer.size(); ++i) {
926 (*this)[i] = dataBuffer[i];
936 TeuchosVector::mpiAllReduce(
RawType_MPI_Op mpiOperation,
const MpiComm& opComm, TeuchosVector& resultVec)
const
939 if (opComm.MyPID() < 0)
return;
941 unsigned int size = this->sizeLocal();
944 "TeuchosVector::mpiAllReduce()",
945 "different vector sizes");
947 for (
unsigned int i = 0; i < size; ++i) {
948 double srcValue = (*this)[i];
949 double resultValue = 0.;
950 opComm.Allreduce((
void *) &srcValue, (
void *) &resultValue, (
int) 1,
RawValue_MPI_DOUBLE, mpiOperation,
951 "TeuchosVector::mpiAllReduce()",
952 "failed MPI.Allreduce()");
953 resultVec[i] = resultValue;
962 TeuchosVector::mpiAllQuantile(
double probability,
const MpiComm& opComm, TeuchosVector& resultVec)
const
965 if (opComm.MyPID() < 0)
return;
969 "TeuchosVector::mpiAllQuantile()",
972 unsigned int size = this->sizeLocal();
975 "TeuchosVector::mpiAllQuantile()",
976 "different vector sizes");
978 for (
unsigned int i = 0; i < size; ++i) {
979 double auxDouble = (int) (*
this)[i];
980 std::vector<double> vecOfDoubles(opComm.NumProc(),0.);
982 "TeuchosVector::mpiAllQuantile()",
983 "failed MPI.Gather()");
985 std::sort(vecOfDoubles.begin(), vecOfDoubles.end());
987 double result = vecOfDoubles[(
unsigned int)( probability*((
double)(vecOfDoubles.size()-1)) )];
990 "TeuchosVector::mpiAllQuantile()",
991 "failed MPI.Bcast()");
993 resultVec[i] = result;
1002 TeuchosVector::matlabLinearInterpExtrap(
1003 const TeuchosVector& x1Vec,
1004 const TeuchosVector& y1Vec,
1005 const TeuchosVector& x2Vec)
1009 "TeuchosVector::matlabLinearInterpExtrap()",
1010 "invalid 'x1' size");
1014 "TeuchosVector::matlabLinearInterpExtrap()",
1015 "invalid 'x1' and 'y1' sizes");
1019 "TeuchosVector::matlabLinearInterpExtrap()",
1020 "invalid 'x2' and 'this' sizes");
1022 for (
unsigned int i = 1; i < x1Vec.sizeLocal(); ++i) {
1025 "TeuchosVector::matlabLinearInterpExtrap()",
1026 "invalid 'x1' values");
1029 for (
unsigned int id2 = 0; id2 < x2Vec.sizeLocal(); ++id2) {
1030 double x2 = x2Vec[id2];
1031 unsigned int id1 = 0;
1032 bool found1 =
false;
1033 for (id1 = 0; id1 < x1Vec.sizeLocal(); ++id1) {
1034 if (x2 <= x1Vec[id1]) {
1039 bool makeLinearModel =
false;
1044 if (x2 == x1Vec[id1]) {
1045 (*this)[id2] = y1Vec[id1];
1047 else if (x2 < x1Vec[0]) {
1049 makeLinearModel =
true;
1055 else if (found1 ==
true) {
1057 makeLinearModel =
true;
1065 makeLinearModel =
true;
1066 xa = x1Vec[x1Vec.sizeLocal()-2];
1067 xb = x1Vec[x1Vec.sizeLocal()-1];
1068 ya = y1Vec[x1Vec.sizeLocal()-2];
1069 yb = y1Vec[x1Vec.sizeLocal()-1];
1072 if (makeLinearModel) {
1073 double rate = (yb-ya)/(xb-xa);
1074 (*this)[id2] = ya + (x2-xa)*rate;
1083 TeuchosVector::matlabDiff(
1084 unsigned int firstPositionToStoreDiff,
1085 double valueForRemainderPosition,
1086 TeuchosVector& outputVec)
const
1088 unsigned int size = this->sizeLocal();
1092 "TeuchosVector::matlabDiff()",
1093 "invalid firstPositionToStoreDiff");
1097 "TeuchosVector::matlabDiff()",
1098 "invalid size of outputVecs");
1100 for (
unsigned int i = 0; i < (size-1); ++i) {
1101 outputVec[firstPositionToStoreDiff+i] = (*this)[i+1]-(*this)[i];
1103 if (firstPositionToStoreDiff == 0) {
1104 outputVec[size-1] = valueForRemainderPosition;
1107 outputVec[0] = valueForRemainderPosition;
1116 TeuchosVector::print(std::ostream& os)
const
1118 unsigned int size = this->sizeLocal();
1120 std::ostream::fmtflags curr_fmt = os.flags();
1122 if (m_printScientific) {
1123 unsigned int savedPrecision = os.precision();
1126 if (m_printHorizontally) {
1127 for (
unsigned int i = 0; i < size; ++i) {
1128 os << std::scientific << (*this)[i]
1133 for (
unsigned int i = 0; i < size; ++i) {
1134 os << std::scientific << (*this)[i]
1139 os.precision(savedPrecision);
1142 if (m_printHorizontally) {
1143 for (
unsigned int i = 0; i < size; ++i) {
1144 os << std::dec << (*this)[i]
1149 for (
unsigned int i = 0; i < size; ++i) {
1150 os << std::dec << (*this)[i]
1162 TeuchosVector::subReadContents(
1163 const std::string& fileName,
1164 const std::string& fileType,
1165 const std::set<unsigned int>& allowedSubEnvIds)
1169 "TeuchosVector::subReadContents()",
1170 "unexpected subRank");
1174 "TeuchosVector::subReadContents()",
1175 "implemented just for sequential vectors for now");
1177 FilePtrSetStruct filePtrSet;
1178 if (m_env.openInputFile(fileName,
1182 double subReadSize = this->sizeLocal();
1185 unsigned int idOfMyFirstLine = 1;
1186 unsigned int idOfMyLastLine = this->sizeLocal();
1187 unsigned int numParams = 1;
1191 std::string tmpString;
1194 *filePtrSet.ifsVar >> tmpString;
1198 *filePtrSet.ifsVar >> tmpString;
1202 "TeuchosVector::subReadContents()",
1203 "string should be the '=' sign");
1206 *filePtrSet.ifsVar >> tmpString;
1208 unsigned int posInTmpString = 6;
1211 char nPositionsString[tmpString.size()-posInTmpString+1];
1212 unsigned int posInPositionsString = 0;
1216 "TeuchosVector::subReadContents()",
1217 "symbol ',' not found in first line of file");
1218 nPositionsString[posInPositionsString++] = tmpString[posInTmpString++];
1219 }
while (tmpString[posInTmpString] !=
',');
1220 nPositionsString[posInPositionsString] =
'\0';
1224 char nParamsString[tmpString.size()-posInTmpString+1];
1225 unsigned int posInParamsString = 0;
1229 "TeuchosVector::subReadContents()",
1230 "symbol ')' not found in first line of file");
1231 nParamsString[posInParamsString++] = tmpString[posInTmpString++];
1232 }
while (tmpString[posInTmpString] !=
')');
1233 nParamsString[posInParamsString] =
'\0';
1236 unsigned int sizeOfVecInFile = (
unsigned int) strtod(nPositionsString,NULL);
1237 unsigned int numParamsInFile = (
unsigned int) strtod(nParamsString, NULL);
1238 if (m_env.subDisplayFile()) {
1239 *m_env.subDisplayFile() <<
"In TeuchosVector::subReadContents()"
1240 <<
": fullRank " << m_env.fullRank()
1241 <<
", sizeOfVecInFile = " << sizeOfVecInFile
1242 <<
", numParamsInFile = " << numParamsInFile
1243 <<
", this->sizeLocal() = " << this->sizeLocal()
1250 "TeuchosVector::subReadContents()",
1251 "size of vec in file is not big enough");
1256 "TeuchosVector::subReadContents()",
1257 "number of parameters of vec in file is different than number of parameters in this vec object");
1260 unsigned int maxCharsPerLine = 64*numParams;
1262 unsigned int lineId = 0;
1263 while (lineId < idOfMyFirstLine) {
1264 filePtrSet.ifsVar->ignore(maxCharsPerLine,
'\n');
1268 if (m_env.subDisplayFile()) {
1269 *m_env.subDisplayFile() <<
"In TeuchosVector::subReadContents()"
1270 <<
": beginning to read input actual data"
1277 *filePtrSet.ifsVar >> tmpString;
1281 *filePtrSet.ifsVar >> tmpString;
1285 "TeuchosVector::subReadContents()",
1286 "in core 0, string should be the '=' sign");
1289 std::streampos tmpPos = filePtrSet.ifsVar->tellg();
1290 filePtrSet.ifsVar->seekg(tmpPos+(std::streampos)2);
1292 if (m_env.subDisplayFile()) {
1293 *m_env.subDisplayFile() <<
"In TeuchosVector::subReadContents()"
1294 <<
": beginning to read lines with numbers only"
1295 <<
", lineId = " << lineId
1296 <<
", idOfMyFirstLine = " << idOfMyFirstLine
1297 <<
", idOfMyLastLine = " << idOfMyLastLine
1301 while (lineId <= idOfMyLastLine) {
1302 *filePtrSet.ifsVar >> (*this)[lineId - idOfMyFirstLine];
1306 m_env.closeFile(filePtrSet,fileType);
1314 TeuchosVector::subWriteContents(
1315 const std::string& varNamePrefix,
1316 const std::string& fileName,
1317 const std::string& fileType,
1318 const std::set<unsigned int>& allowedSubEnvIds)
const
1322 "TeuchosVector::subWriteContents()",
1323 "unexpected subRank");
1327 "TeuchosVector::subWriteContents()",
1328 "implemented just for sequential vectors for now");
1330 FilePtrSetStruct filePtrSet;
1331 if (m_env.openOutputFile(fileName,
1336 *filePtrSet.ofsVar << varNamePrefix <<
"_sub" << m_env.subIdString() <<
" = zeros(" << this->sizeLocal()
1340 *filePtrSet.ofsVar << varNamePrefix <<
"_sub" << m_env.subIdString() <<
" = [";
1342 bool savedVectorPrintScientific = this->getPrintScientific();
1343 bool savedVectorPrintHorizontally = this->getPrintHorizontally();
1344 this->setPrintScientific (
true);
1345 this->setPrintHorizontally(
false);
1346 *filePtrSet.ofsVar << *
this;
1348 this->setPrintHorizontally(savedVectorPrintHorizontally);
1349 this->setPrintScientific (savedVectorPrintScientific);
1351 *filePtrSet.ofsVar <<
"];\n";
1353 m_env.closeFile(filePtrSet,fileType);
1365 TeuchosVector::copy(
const TeuchosVector& rhs)
1369 unsigned int size1 = m_vec.length();
1370 unsigned int size2 = rhs.sizeLocal();
1373 for (
unsigned int i=0;i<size1;i++){
1386 TeuchosVector
operator/(
double a,
const TeuchosVector& x)
1388 TeuchosVector answer(x);
1395 TeuchosVector
operator/(
const TeuchosVector& x,
const TeuchosVector& y)
1397 TeuchosVector answer(x);
1403 TeuchosVector
operator*(
double a,
const TeuchosVector& x)
1405 TeuchosVector answer(x);
1411 TeuchosVector
operator*(
const TeuchosVector& x,
const TeuchosVector& y)
1413 TeuchosVector answer(x);
1419 double scalarProduct(
const TeuchosVector& x,
const TeuchosVector& y)
1421 unsigned int size1 = x.sizeLocal();
1422 unsigned int size2 = y.sizeLocal();
1425 x.env().worldRank(),
1427 "different sizes of x and y");
1429 for (
unsigned int i = 0; i < size1; ++i) {
1430 result += x[i]*y[i];
1437 TeuchosVector
operator+(
const TeuchosVector& x,
const TeuchosVector& y)
1439 TeuchosVector answer(x);
1445 TeuchosVector
operator-(
const TeuchosVector& x,
const TeuchosVector& y)
1447 TeuchosVector answer(x);
1454 operator== (
const TeuchosVector& lhs,
const TeuchosVector& rhs)
1457 unsigned int size1 = lhs.sizeLocal();
1458 unsigned int size2 = rhs.sizeLocal();
1461 lhs.env().worldRank(),
1463 "different sizes of lhs and rhs");
1465 for (
unsigned int i = 0; i < size1; ++i) {
1466 if (lhs[i] != rhs[i]) {
1477 operator<<(std::ostream& os,
const TeuchosVector& obj)
1488 #endif // ifdef QUESO_HAS_TRILINOS
#define RawValue_MPI_DOUBLE
GslMatrix operator+(const GslMatrix &m1, const GslMatrix &m2)
GslMatrix operator-(const GslMatrix &m1, const GslMatrix &m2)
double scalarProduct(const GslVector &x, const GslVector &y)
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
bool operator==(const GslVector &lhs, const GslVector &rhs)
GslVector operator/(double a, const GslVector &x)
GslMatrix operator*(double a, const GslMatrix &mat)
virtual void copy(const Vector &src)
Copies vector src to this matrix.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)