00001
00016 #include "OSMatrix.h"
00017 #include "OSGeneral.h"
00018 #include "OSParameters.h"
00019 #include "OSErrorClass.h"
00020 #include "OSMathUtil.h"
00021 #include "OSBase64.h"
00022 #include "OSOutput.h"
00023 #include "OSgLWriter.h"
00024
00025 #include <iostream>
00026 #include <sstream>
00027
00028
00029 using namespace std;
00030 using std::endl;
00031
00032
00033
00034
00035
00036
00037
00038
00040 MatrixNode::MatrixNode():
00041 matrixType(ENUM_MATRIX_TYPE_unknown),
00042 nType(ENUM_MATRIX_CONSTRUCTOR_TYPE_unknown),
00043 inumberOfChildren(),
00044 m_mChildren(NULL){
00045 #ifndef NDEBUG
00046 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "in MatrixNode constructor");
00047 #endif
00048 }
00049
00050 MatrixNode::~MatrixNode()
00051 {
00052 #ifndef NDEBUG
00053 std::ostringstream outStr;
00054 outStr << "inside MatrixNode destructor" << std::endl;
00055 outStr << "number of kids = " << inumberOfChildren << std::endl;
00056 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, outStr.str());
00057 #endif
00058 if (inumberOfChildren > 0 && m_mChildren != NULL)
00059 {
00060 for (int i=0; i<inumberOfChildren; i++)
00061 {
00062 if (m_mChildren[i] != NULL)
00063 {
00064 #ifndef NDEBUG
00065 outStr.str("");
00066 outStr.clear();
00067 outStr << "deleting Matrixnode->m_mChildren[" << i << "] at "
00068 << &m_mChildren[i] << std::endl;
00069 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
00070 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
00071 #endif
00072 delete m_mChildren[i];
00073 }
00074 m_mChildren[i] = NULL;
00075 }
00076 delete [] m_mChildren;
00077 m_mChildren = NULL;
00078 inumberOfChildren = 0;
00079 }
00080 else if (inumberOfChildren > 0 || m_mChildren != NULL)
00081 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_warning, "Warning: Possible memory leak");
00082 }
00083
00084 ENUM_MATRIX_CONSTRUCTOR_TYPE MatrixNode::getNodeType()
00085 {
00086 return nType;
00087 }
00088
00089 std::string MatrixNode::getMatrixNodeInXML()
00090 {
00091 return "";
00092 }
00093
00094 bool MatrixNode::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
00095 {
00096 return false;
00097 }
00098
00099 bool MatrixNode::IsEqual(MatrixNode *that)
00100 {
00101 #ifndef NDEBUG
00102 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in MatrixNode");
00103 #endif
00104 if (this == NULL)
00105 {
00106 if (that == NULL)
00107 return true;
00108 else
00109 {
00110 #ifndef NDEBUG
00111 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
00112 "First object is NULL, second is not");
00113 #endif
00114 return false;
00115 }
00116 }
00117 else
00118 {
00119 if (that == NULL)
00120 {
00121 #ifndef NDEBUG
00122 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
00123 "Second object is NULL, first is not");
00124 #endif
00125 return false;
00126 }
00127 else
00128 {
00129 if (this->inumberOfChildren != that->inumberOfChildren) return false;
00130 if (this->matrixType != that->matrixType) return false;
00131 if (this->nType != that->nType) return false;
00132
00133 for (int i=0; i < inumberOfChildren; i++)
00134 if (!this->m_mChildren[i]->IsEqual(that->m_mChildren[i]))
00135 return false;
00136
00137 return true;
00138 }
00139 }
00140 }
00141
00142
00143
00145 MatrixConstructor::MatrixConstructor()
00146 {
00147 #ifndef NDEBUG
00148 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixConstructor Constructor");
00149 #endif
00150 }
00151
00152 MatrixConstructor::~MatrixConstructor()
00153 {
00154 #ifndef NDEBUG
00155 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixConstructor Destructor");
00156 #endif
00157 }
00158
00159
00160
00162
00163 MatrixType::MatrixType():
00164 MatrixNode(),
00165 symmetry(ENUM_MATRIX_SYMMETRY_none),
00166 type(ENUM_MATRIX_TYPE_unknown),
00167 numberOfRows(0),
00168 numberOfColumns(0),
00169 ExpandedMatrixInRowMajorForm(NULL),
00170 ExpandedMatrixInColumnMajorForm(NULL),
00171 ExpandedMatrixByBlocks(NULL),
00172 m_miRowPartition(NULL),
00173 m_iRowPartitionSize(0),
00174 m_miColumnPartition(NULL),
00175 m_iColumnPartitionSize(0),
00176 m_bHaveRowPartition(false),
00177 m_bHaveColumnPartition(false)
00178 {
00179 #ifndef NDEBUG
00180 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixType Constructor");
00181 #endif
00182 }
00183
00184 MatrixType::~MatrixType()
00185 {
00186 #ifndef NDEBUG
00187 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixType Destructor");
00188 #endif
00189 }
00190
00191 bool MatrixType::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
00192 {
00193 return false;
00194 }
00195
00196 bool MatrixType::matrixHasBase()
00197 {
00198 return (inumberOfChildren > 0 && m_mChildren != NULL
00199 && m_mChildren[0]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix);
00200 }
00201
00202 bool MatrixType::matrixHasElements()
00203 {
00204 if (inumberOfChildren == 0 || m_mChildren == NULL) return false;
00205 for (int i=0; i < inumberOfChildren; i++)
00206 {
00207 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_constantElements) return true;
00208 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_varRefElements ) return true;
00209 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_linearElements ) return true;
00210 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_generalElements ) return true;
00211 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_objRefElements ) return true;
00212 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_conRefElements ) return true;
00213 }
00214 return false;
00215 }
00216
00217 bool MatrixType::matrixHasTransformations()
00218 {
00219 if (inumberOfChildren == 0 || m_mChildren == NULL) return false;
00220 for (int i=0; i < inumberOfChildren; i++)
00221 {
00222 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_transformation) return true;
00223 }
00224 return false;
00225 }
00226
00227 bool MatrixType::matrixHasBlocks()
00228 {
00229 if (inumberOfChildren == 0 || m_mChildren == NULL) return false;
00230 for (int i=0; i < inumberOfChildren; i++)
00231 {
00232 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks) return true;
00233 }
00234 return false;
00235 }
00236
00237 int MatrixType::getNumberOfElementConstructors()
00238 {
00239 int k = 0;
00240 if (inumberOfChildren == 0 || m_mChildren == NULL) return 0;
00241 for (int i=0; i < inumberOfChildren; i++)
00242 {
00243 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_constantElements) k++;
00244 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_varRefElements) k++;
00245 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_linearElements) k++;
00246 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_generalElements) k++;
00247 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_objRefElements) k++;
00248 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_conRefElements) k++;
00249 }
00250 return k++;
00251 }
00252
00253 int MatrixType::getNumberOfTransformationConstructors()
00254 {
00255 int k = 0;
00256 if (inumberOfChildren == 0 || m_mChildren == NULL) return 0;
00257 for (int i=0; i < inumberOfChildren; i++)
00258 {
00259 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_transformation) k++;
00260 }
00261 return k++;
00262 }
00263
00264 int MatrixType::getNumberOfBlocksConstructors()
00265 {
00266 int k = 0;
00267 if (inumberOfChildren == 0 || m_mChildren == NULL) return 0;
00268 for (int i=0; i < inumberOfChildren; i++)
00269 {
00270 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks) k++;
00271 }
00272 return k++;
00273 }
00274
00275 GeneralSparseMatrix* MatrixType::getMatrixCoefficientsInColumnMajor()
00276 {
00277 #ifndef NDEBUG
00278 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside getMatrixCoefficientsInColumnMajor()");
00279 #endif
00280 try
00281 {
00282
00283 if (ExpandedMatrixInColumnMajorForm != NULL)
00284 return ExpandedMatrixInColumnMajorForm;
00285 if (ExpandedMatrixInRowMajorForm != NULL)
00286 {
00287 ExpandedMatrixInColumnMajorForm = convertToOtherMajor(false);
00288 return ExpandedMatrixInColumnMajorForm;
00289 }
00290
00291
00292
00293 if (inumberOfChildren == 0)
00294 {
00295 ExpandedMatrixInColumnMajorForm = new GeneralSparseMatrix();
00296 ExpandedMatrixInColumnMajorForm->symmetry = symmetry;
00297 ExpandedMatrixInColumnMajorForm->valueSize = 0;
00298 ExpandedMatrixInColumnMajorForm->startSize = numberOfColumns + 1;
00299 ExpandedMatrixInColumnMajorForm->start = new int[numberOfColumns + 1];
00300 for (int i=0; i <= numberOfColumns; i++)
00301 ExpandedMatrixInColumnMajorForm->start[i] = 0;
00302 return ExpandedMatrixInColumnMajorForm;
00303 }
00304
00305
00306 else if (inumberOfChildren == 1)
00307 {
00308 if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix)
00309 {
00310 int baseMtxIdx = ((BaseMatrix*)m_mChildren[0])->baseMatrixIdx;
00311 OSMatrix* baseMtxPtr = ((BaseMatrix*)m_mChildren[0])->baseMatrix;
00312
00313 int iroff = ((BaseMatrix*)m_mChildren[0])->targetMatrixFirstRow;
00314 int icoff = ((BaseMatrix*)m_mChildren[0])->targetMatrixFirstCol;
00315
00316 int base_r0, base_c0, base_rN, base_cN;
00317
00318 GeneralSparseMatrix* baseMtx;
00319 if (((BaseMatrix*)m_mChildren[0])->baseTranspose)
00320 {
00321 baseMtx = baseMtxPtr->getMatrixCoefficientsInRowMajor();
00322 base_r0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartCol;
00323 base_c0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartRow;
00324 base_rN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndCol;
00325 base_cN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndRow;
00326 if (base_cN < 0)
00327 base_cN = baseMtxPtr->numberOfRows - 1;
00328 if (base_rN < 0)
00329 base_rN = baseMtxPtr->numberOfColumns - 1;
00330 }
00331 else
00332 {
00333 baseMtx = baseMtxPtr->getMatrixCoefficientsInColumnMajor();
00334 base_r0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartRow;
00335 base_c0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartCol;
00336 base_rN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndRow;
00337 base_cN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndCol;
00338 if (base_rN < 0)
00339 base_rN = baseMtxPtr->numberOfRows - 1;
00340 if (base_cN < 0)
00341 base_cN = baseMtxPtr->numberOfColumns - 1;
00342 }
00343
00344 double scaleMult = ((BaseMatrix*)m_mChildren[0])->scalarMultiplier;
00345
00346 ExpandedMatrixInColumnMajorForm = new GeneralSparseMatrix();
00347 ExpandedMatrixInColumnMajorForm->symmetry = symmetry;
00348 ExpandedMatrixInColumnMajorForm->startSize = numberOfColumns + 1;
00349
00350
00351 bool isShifted = (iroff > 0 || icoff > 0);
00352 bool isCropped = (base_c0 > 0 || base_r0 > 0 ||
00353 base_rN < baseMtxPtr->numberOfRows - 1 ||
00354 base_cN < baseMtxPtr->numberOfColumns - 1);
00355 bool isClipped = (iroff + base_rN - base_r0 >= numberOfRows ||
00356 icoff + base_cN - base_c0 >= numberOfColumns);
00357 bool isScaled = (scaleMult != 1);
00358 bool reTyped = (getMatrixType() != baseMtx->vType);
00359 bool hasGap = (icoff + base_cN - base_c0 < numberOfColumns - 1);
00360
00361
00362 if ( !isShifted && !isCropped && !isClipped && !isScaled && !reTyped )
00363 {
00364 ExpandedMatrixInColumnMajorForm->b_deleteStartArray = hasGap;
00365 ExpandedMatrixInColumnMajorForm->b_deleteIndexArray = false;
00366 ExpandedMatrixInColumnMajorForm->b_deleteValueArray = false;
00367 ExpandedMatrixInColumnMajorForm->isRowMajor = false;
00368 ExpandedMatrixInColumnMajorForm->valueSize = baseMtx->valueSize;
00369 ExpandedMatrixInColumnMajorForm->vType = baseMtx->vType;
00370 ExpandedMatrixInColumnMajorForm->index = baseMtx->index;
00371 ExpandedMatrixInColumnMajorForm->value = baseMtx->value;
00372
00373
00374 if (!hasGap)
00375 ExpandedMatrixInColumnMajorForm->start = baseMtx->start;
00376 else
00377 {
00378 ExpandedMatrixInColumnMajorForm->startSize = numberOfColumns + 1;
00379 ExpandedMatrixInColumnMajorForm->start =
00380 new int[ExpandedMatrixInColumnMajorForm->startSize];
00381 for (int i=0; i < baseMtx->startSize; i++)
00382 ExpandedMatrixInColumnMajorForm->start[i] = baseMtx->start[i];
00383 int lastStart = baseMtx->valueSize;
00384 for (int i=baseMtx->startSize;
00385 i < ExpandedMatrixInColumnMajorForm->startSize; i++)
00386 ExpandedMatrixInColumnMajorForm->start[i] = lastStart;
00387 }
00388
00389 return ExpandedMatrixInColumnMajorForm;
00390 }
00391 else
00392 {
00393
00394 if ( !isShifted && !isCropped && !isClipped )
00395 {
00396
00397 ExpandedMatrixInColumnMajorForm->b_deleteStartArray = hasGap;
00398 ExpandedMatrixInColumnMajorForm->b_deleteIndexArray = false;
00399 ExpandedMatrixInColumnMajorForm->b_deleteValueArray = true;
00400 ExpandedMatrixInColumnMajorForm->isRowMajor = false;
00401 ExpandedMatrixInColumnMajorForm->valueSize = baseMtx->valueSize;
00402 ExpandedMatrixInColumnMajorForm->vType = baseMtx->vType;
00403 ExpandedMatrixInColumnMajorForm->index = baseMtx->index;
00404
00405
00406 if (!hasGap)
00407 ExpandedMatrixInColumnMajorForm->start = baseMtx->start;
00408 else
00409 {
00410 ExpandedMatrixInColumnMajorForm->startSize = numberOfColumns + 1;
00411 ExpandedMatrixInColumnMajorForm->start =
00412 new int[ExpandedMatrixInColumnMajorForm->startSize];
00413 for (int i=0; i < baseMtx->startSize; i++)
00414 ExpandedMatrixInColumnMajorForm->start[i] = baseMtx->start[i];
00415 int lastStart = baseMtx->valueSize;
00416 for (int i=baseMtx->startSize;
00417 i < ExpandedMatrixInColumnMajorForm->startSize; i++)
00418 ExpandedMatrixInColumnMajorForm->start[i] = lastStart;
00419 }
00420
00421
00422 if ( baseMtx->vType == ENUM_MATRIX_TYPE_constant)
00423 {
00424 ExpandedMatrixInColumnMajorForm->value = new ConstantMatrixValues();
00425 ((ConstantMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el
00426 = new double[baseMtx->valueSize];
00427 for (int i = 0; i < baseMtx->valueSize; i++)
00428 ((ConstantMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el[i]
00429 = scaleMult*((ConstantMatrixValues*)baseMtx->value)->el[i];
00430 }
00431 else if (baseMtx->vType == ENUM_MATRIX_TYPE_varReference)
00432 {
00433
00434 LinearMatrixValues* tmpValues = new LinearMatrixValues();
00435 tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
00436 for (int i = 0; i < baseMtx->valueSize; i++)
00437 {
00438 tmpValues->el[i] = new LinearMatrixElement();
00439 tmpValues->el[i]->numberOfVarIdx = 1;
00440 tmpValues->el[i]->varIdx = new LinearMatrixElementTerm*[1];
00441 tmpValues->el[i]->varIdx[0] = new LinearMatrixElementTerm();
00442 tmpValues->el[i]->varIdx[0]->coef = scaleMult;
00443 tmpValues->el[i]->varIdx[0]->idx
00444 = ((VarReferenceMatrixValues*)baseMtx->value)->el[i];
00445 }
00446 ExpandedMatrixInColumnMajorForm->value = tmpValues;
00447 }
00448 else if (baseMtx->vType == ENUM_MATRIX_TYPE_linear)
00449 {
00450 LinearMatrixValues* tmpValues = new LinearMatrixValues();
00451 tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
00452 for (int i = 0; i < baseMtx->valueSize; i++)
00453 {
00454 tmpValues->el[i] = new LinearMatrixElement();
00455 if (!(tmpValues->el[i]
00456 ->deepCopyFrom(((LinearMatrixValues*)baseMtx->value)->el[i])))
00457 throw ErrorClass("failed copying linear element values in method getMatrixCoefficientsInColumnMajor()");
00458 for (int j=0; j<tmpValues->el[i]->numberOfVarIdx; j++)
00459 tmpValues->el[i]->varIdx[j]->coef *= scaleMult;
00460 }
00461 ExpandedMatrixInColumnMajorForm->value = tmpValues;
00462 }
00463 else if (baseMtx->vType == ENUM_MATRIX_TYPE_general)
00464 {
00465
00466 GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
00467 tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
00468 for (int i = 0; i < baseMtx->valueSize; i++)
00469 {
00470 tmpValues->el[i] = new ScalarExpressionTree();
00471 tmpValues->el[i]->m_treeRoot = new OSnLNodeTimes();
00472 tmpValues->el[i]->m_treeRoot->m_mChildren[0] = new OSnLNodeNumber();
00473 ((OSnLNodeNumber*)tmpValues->el[i]->m_treeRoot->m_mChildren[0])->value = scaleMult;
00474 tmpValues->el[i]->m_treeRoot->m_mChildren[1]
00475 = ((GeneralMatrixValues*)baseMtx->value)->el[i]->m_treeRoot
00476 ->copyNodeAndDescendants();
00477 }
00478 ExpandedMatrixInColumnMajorForm->value = tmpValues;
00479 }
00480 else if (baseMtx->vType == ENUM_MATRIX_TYPE_objReference)
00481 {
00482 throw ErrorClass("scalar multiple not defined for objReference elements in getMatrixCoefficientsInColumnMajor()");
00483 }
00484 else if (baseMtx->vType == ENUM_MATRIX_TYPE_conReference)
00485 {
00486 throw ErrorClass("scalar multiple not defined for conReference elements in getMatrixCoefficientsInColumnMajor()");
00487 }
00488 return ExpandedMatrixInColumnMajorForm;
00489 }
00490 else
00491 {
00492 ExpandedMatrixInColumnMajorForm->b_deleteStartArray = true;
00493 ExpandedMatrixInColumnMajorForm->b_deleteIndexArray = true;
00494 ExpandedMatrixInColumnMajorForm->b_deleteValueArray = true;
00495 ExpandedMatrixInColumnMajorForm->startSize = numberOfColumns + 1;
00496 ExpandedMatrixInColumnMajorForm->isRowMajor = false;
00497 ExpandedMatrixInColumnMajorForm->vType = baseMtx->vType;
00498
00499 int startSize = numberOfColumns + 1;
00500 int* tmpStarts = new int[startSize];
00501 for (int i=0; i < startSize; i++)
00502 tmpStarts[i] = 0;
00503
00504 int adjc = icoff - base_c0;
00505 int lastcol = icoff + base_cN - base_c0 + 1;
00506 if (lastcol > numberOfColumns)
00507 lastcol = numberOfColumns;
00508
00509
00510 for (int i=icoff; i<lastcol; i++)
00511 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
00512 {
00513 if (baseMtx->index[j] >= base_r0 &&
00514 baseMtx->index[j] <= base_rN &&
00515 baseMtx->index[j] < numberOfRows + base_r0 - iroff)
00516 tmpStarts[i+1]++;
00517 }
00518 for (int i=icoff+1; i < startSize; i++)
00519 tmpStarts[i] += tmpStarts[i-1];
00520
00521 int valueSize = tmpStarts[startSize-1];
00522 int* tmpIndexes = new int[valueSize];
00523
00524 ExpandedMatrixInColumnMajorForm->valueSize = valueSize;
00525 ExpandedMatrixInColumnMajorForm->start = tmpStarts;
00526
00527
00528 if ( baseMtx->vType == ENUM_MATRIX_TYPE_constant)
00529 {
00530 MatrixElementValues* tmpValues = new ConstantMatrixValues();
00531 ((ConstantMatrixValues*)tmpValues)->el = new double[valueSize];
00532
00533 int ival = 0;
00534 for (int i=icoff; i<lastcol; i++)
00535 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
00536 {
00537 if (baseMtx->index[j] >= base_r0 &&
00538 baseMtx->index[j] <= base_rN &&
00539 baseMtx->index[j] < numberOfRows + base_r0 - iroff)
00540 {
00541 tmpIndexes[ival] = baseMtx->index[j] - base_r0 + iroff;
00542 ((ConstantMatrixValues*)tmpValues)->el[ival]
00543 = scaleMult*((ConstantMatrixValues*)baseMtx->value)->el[j];
00544 ival++;
00545 }
00546 }
00547 ExpandedMatrixInColumnMajorForm->index = tmpIndexes;
00548 ExpandedMatrixInColumnMajorForm->value = tmpValues;
00549 }
00550
00551 else if (baseMtx->vType == ENUM_MATRIX_TYPE_varReference)
00552 {
00553 if (scaleMult == 1)
00554 {
00555 MatrixElementValues* tmpValues = new VarReferenceMatrixValues();
00556 ((VarReferenceMatrixValues*)tmpValues)->el = new int[valueSize];
00557
00558 int ival = 0;
00559 for (int i=icoff; i<lastcol; i++)
00560 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
00561 {
00562 if (baseMtx->index[j] >= base_r0 &&
00563 baseMtx->index[j] < numberOfRows + base_r0 - iroff)
00564 {
00565 tmpIndexes[ival] = baseMtx->index[j] - base_r0 + iroff;
00566 ((VarReferenceMatrixValues*)tmpValues)->el[ival]
00567 = ((VarReferenceMatrixValues*)baseMtx->value)->el[j];
00568 ival++;
00569 }
00570 }
00571 ExpandedMatrixInColumnMajorForm->index = tmpIndexes;
00572 ExpandedMatrixInColumnMajorForm->value = tmpValues;
00573 }
00574 else
00575 {
00576
00577 MatrixElementValues* tmpValues = new LinearMatrixValues();
00578 ((LinearMatrixValues*)tmpValues)->el
00579 = new LinearMatrixElement*[valueSize];
00580
00581 int ival = 0;
00582 for (int i=icoff; i<lastcol; i++)
00583 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
00584 {
00585 if (baseMtx->index[j] >= base_r0 &&
00586 baseMtx->index[j] < numberOfRows + base_r0 - iroff)
00587 {
00588 ((LinearMatrixValues*)tmpValues)->el[ival]
00589 = new LinearMatrixElement();
00590 ((LinearMatrixValues*)tmpValues)->el[ival]->numberOfVarIdx = 1;
00591 ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx
00592 = new LinearMatrixElementTerm*[1];
00593 ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]
00594 = new LinearMatrixElementTerm();
00595 ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]->coef
00596 = scaleMult;
00597 ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]->idx
00598 = ((VarReferenceMatrixValues*)baseMtx->value)->el[j];
00599 ival++;
00600 }
00601 }
00602 ExpandedMatrixInColumnMajorForm->index = tmpIndexes;
00603 ExpandedMatrixInColumnMajorForm->value = tmpValues;
00604 }
00605 }
00606 else if (baseMtx->vType == ENUM_MATRIX_TYPE_linear)
00607 {
00608 LinearMatrixValues* tmpValues = new LinearMatrixValues();
00609 tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
00610
00611 int ival = 0;
00612 for (int i=icoff; i<lastcol; i++)
00613 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
00614 {
00615 if (baseMtx->index[j] >= base_r0 &&
00616 baseMtx->index[j] < numberOfRows + base_r0 - iroff)
00617 {
00618 tmpValues->el[ival] = new LinearMatrixElement();
00619 if (!(tmpValues->el[ival]
00620 ->deepCopyFrom(((LinearMatrixValues*)baseMtx->value)->el[j])))
00621 throw ErrorClass("failed copying linear element values in method getMatrixCoefficientsInColumnMajor()");
00622 for (int k=0; k<tmpValues->el[ival]->numberOfVarIdx; k++)
00623 tmpValues->el[ival]->varIdx[k]->coef *= scaleMult;
00624 ival++;
00625 }
00626 }
00627 ExpandedMatrixInColumnMajorForm->index = tmpIndexes;
00628 ExpandedMatrixInColumnMajorForm->value = tmpValues;
00629 }
00630 else if (baseMtx->vType == ENUM_MATRIX_TYPE_general)
00631 {
00632 if (scaleMult == 1)
00633 {
00634 GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
00635 tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
00636
00637 int ival = 0;
00638 for (int i=icoff; i<lastcol; i++)
00639 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
00640 {
00641 if (baseMtx->index[j] >= base_r0 &&
00642 baseMtx->index[j] < numberOfRows + base_r0 - iroff)
00643 {
00644 ((GeneralMatrixValues*)tmpValues)->el[ival]
00645 = new ScalarExpressionTree();
00646
00647
00648 ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot
00649 = ((GeneralMatrixValues*)baseMtx->value)->el[j]->m_treeRoot
00650 ->copyNodeAndDescendants();
00651 ival++;
00652 }
00653 }
00654 ExpandedMatrixInColumnMajorForm->index = tmpIndexes;
00655 ExpandedMatrixInColumnMajorForm->value = tmpValues;
00656 }
00657 else
00658 {
00659
00660 GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
00661 tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
00662 int ival = 0;
00663 for (int i=icoff; i<lastcol; i++)
00664 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
00665 {
00666 if (baseMtx->index[j] >= base_r0 &&
00667 baseMtx->index[j] < numberOfRows + base_r0 - iroff)
00668 {
00669 ((GeneralMatrixValues*)tmpValues)->el[ival]
00670 = new ScalarExpressionTree();
00671 ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot
00672 = new OSnLNodeTimes();
00673 ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot->m_mChildren[0]
00674 = new OSnLNodeNumber();
00675 ((OSnLNodeNumber*)tmpValues->el[ival]->m_treeRoot->m_mChildren[0])->value = scaleMult;
00676 ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot->m_mChildren[1]
00677 = ((GeneralMatrixValues*)baseMtx->value)->el[j]->m_treeRoot->copyNodeAndDescendants();
00678 ival++;
00679
00680 }
00681 }
00682 ExpandedMatrixInColumnMajorForm->index = tmpIndexes;
00683 ExpandedMatrixInColumnMajorForm->value = tmpValues;
00684 }
00685 }
00686 else if (baseMtx->vType == ENUM_MATRIX_TYPE_objReference)
00687 {
00688 throw ErrorClass("scalar multiple not defined for objReference elements in getMatrixCoefficientsInColumnMajor()");
00689 }
00690 else if (baseMtx->vType == ENUM_MATRIX_TYPE_conReference)
00691 {
00692 throw ErrorClass("scalar multiple not defined for conReference elements in getMatrixCoefficientsInColumnMajor()");
00693 }
00694 }
00695 return ExpandedMatrixInColumnMajorForm;
00696 }
00697 }
00698
00699 else if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks)
00700 {
00701
00702 if (!processBlocks(false, symmetry))
00703 throw ErrorClass("error processing blocks in getMatrixCoefficientsInColumnMajor()");
00704
00705 ExpandedMatrixBlocks* currentBlocks
00706 = getBlocks(m_miRowPartition, m_iRowPartitionSize, m_miColumnPartition,
00707 m_iColumnPartitionSize, false, true);
00708
00709
00710 ExpandedMatrixInColumnMajorForm = new GeneralSparseMatrix();
00711 ExpandedMatrixInColumnMajorForm->b_deleteStartArray = true;
00712 ExpandedMatrixInColumnMajorForm->b_deleteIndexArray = true;
00713 ExpandedMatrixInColumnMajorForm->b_deleteValueArray = true;
00714 ExpandedMatrixInColumnMajorForm->vType = getMatrixType();
00715 ExpandedMatrixInColumnMajorForm->isRowMajor = false;
00716 ExpandedMatrixInColumnMajorForm->symmetry = symmetry;
00717 ExpandedMatrixInColumnMajorForm->startSize = numberOfColumns + 1;
00718 ExpandedMatrixInColumnMajorForm->start = new int[numberOfColumns + 1];
00719 for (int i=0; i <= numberOfColumns; i++)
00720 ExpandedMatrixInColumnMajorForm->start[i] = 0;
00721
00722
00723 for (int i=0; i < currentBlocks->blockNumber; i++)
00724 {
00725 int c0 = currentBlocks->colOffset[currentBlocks->blockColumns[i]];
00726 int cN = currentBlocks->colOffset[currentBlocks->blockColumns[i]+1];
00727 for (int j = c0; j < cN; j++)
00728 {
00729 ExpandedMatrixInColumnMajorForm->start[j+1] +=
00730 ( currentBlocks->blocks[i]->start[j+1-c0]
00731 - currentBlocks->blocks[i]->start[j -c0] );
00732 }
00733 }
00734
00735 for (int i=1; i <= numberOfColumns; i++)
00736 ExpandedMatrixInColumnMajorForm->start[i] +=
00737 ExpandedMatrixInColumnMajorForm->start[i-1];
00738 ExpandedMatrixInColumnMajorForm->valueSize =
00739 ExpandedMatrixInColumnMajorForm->start[numberOfColumns];
00740 int* tmpIndexes = new int[ExpandedMatrixInColumnMajorForm->valueSize];
00741
00742
00743 if (currentBlocks->blocks[0]->vType == ENUM_MATRIX_TYPE_constant)
00744 {
00745 ConstantMatrixValues* tmpValues = new ConstantMatrixValues();
00746 tmpValues->el
00747 = new double[ExpandedMatrixInColumnMajorForm->valueSize];
00748
00749 for (int i=0; i < currentBlocks->blockNumber; i++)
00750 {
00751 int c0 = currentBlocks->colOffset[currentBlocks->blockColumns[i]];
00752 int cN = currentBlocks->colOffset[currentBlocks->blockColumns[i]+1];
00753 int row_adj = currentBlocks->rowOffset[currentBlocks->blockRows[i]];
00754
00755 for (int j = c0; j < cN; j++)
00756 {
00757 int loc = ExpandedMatrixInColumnMajorForm->start[j];
00758 for (int k = currentBlocks->blocks[i]->start[j-c0];
00759 k < currentBlocks->blocks[i]->start[j-c0+1]; k++)
00760 {
00761 tmpIndexes[loc] = currentBlocks->blocks[i]->index[k] + row_adj;
00762 ((ConstantMatrixValues*)tmpValues)->el[loc]
00763 = ((ConstantMatrixValues*)currentBlocks->blocks[i]->value)->el[k];
00764 loc++;
00765 }
00766 ExpandedMatrixInColumnMajorForm->start[j] = loc;
00767 }
00768 }
00769 ExpandedMatrixInColumnMajorForm->index = tmpIndexes;
00770 ExpandedMatrixInColumnMajorForm->value = tmpValues;
00771 }
00772 else
00773 throw ErrorClass("getMatrixCoefficientsInColumnMajor: Can only handle constant values so far in blocks");
00774 for (int i=numberOfColumns; i > 0; i--)
00775 ExpandedMatrixInColumnMajorForm->start[i] =
00776 ExpandedMatrixInColumnMajorForm->start[i-1];
00777 ExpandedMatrixInColumnMajorForm->start[0] = 0;
00778 return ExpandedMatrixInColumnMajorForm;
00779 }
00780
00781 else if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_transformation)
00782 {
00783
00784
00785 throw ErrorClass("transformations not yet implemented in getMatrixCoefficientsInColumnMajor()");
00786 }
00787 else
00788 {
00789 if (!((MatrixElements*)m_mChildren[0])->rowMajor)
00790 {
00791 ExpandedMatrixInColumnMajorForm = new GeneralSparseMatrix();
00792 ExpandedMatrixInColumnMajorForm->symmetry = symmetry;
00793 ExpandedMatrixInColumnMajorForm->b_deleteStartArray = false;
00794 ExpandedMatrixInColumnMajorForm->b_deleteIndexArray = false;
00795 ExpandedMatrixInColumnMajorForm->b_deleteValueArray = false;
00796 ExpandedMatrixInColumnMajorForm->isRowMajor = false;
00797 ExpandedMatrixInColumnMajorForm->startSize = numberOfColumns + 1;
00798 ExpandedMatrixInColumnMajorForm->valueSize
00799 = ((MatrixElements*)m_mChildren[0])->numberOfValues;
00800 ExpandedMatrixInColumnMajorForm->start
00801 = ((MatrixElements*)m_mChildren[0])->start->el;
00802 ExpandedMatrixInColumnMajorForm->vType
00803 = getMatrixType();
00804 ExpandedMatrixInColumnMajorForm->index
00805 = ((MatrixElements*)m_mChildren[0])->index->el;
00806 if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_constant)
00807 ExpandedMatrixInColumnMajorForm->value
00808 = ((ConstantMatrixElements*)m_mChildren[0])->value;
00809 else if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_varReference)
00810 ExpandedMatrixInColumnMajorForm->value
00811 = ((VarReferenceMatrixElements*)m_mChildren[0])->value;
00812 else if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_linear)
00813 ExpandedMatrixInColumnMajorForm->value
00814 = ((LinearMatrixElements*)m_mChildren[0])->value;
00815 else if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_general)
00816 ExpandedMatrixInColumnMajorForm->value
00817 = ((GeneralMatrixElements*)m_mChildren[0])->value;
00818 else if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_objReference)
00819 ExpandedMatrixInColumnMajorForm->value
00820 = ((ObjReferenceMatrixElements*)m_mChildren[0])->value;
00821 else if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_conReference)
00822 ExpandedMatrixInColumnMajorForm->value
00823 = ((ConReferenceMatrixElements*)m_mChildren[0])->value;
00824 else
00825 throw ErrorClass("Unknown element type in getMatrixCoefficientsInColumnMajor()");
00826
00827 return ExpandedMatrixInColumnMajorForm;
00828 }
00829 else
00830 {
00831 MatrixElements* refMtx = (MatrixElements*)m_mChildren[0];
00832
00833 ExpandedMatrixInColumnMajorForm = new GeneralSparseMatrix();
00834 ExpandedMatrixInColumnMajorForm->symmetry = symmetry;
00835 ExpandedMatrixInColumnMajorForm->startSize = numberOfColumns + 1;
00836 ExpandedMatrixInColumnMajorForm->vType = getMatrixType();
00837 ExpandedMatrixInColumnMajorForm->start = new int[numberOfColumns + 1];
00838 for (int i=0; i <= numberOfColumns; i++)
00839 ExpandedMatrixInColumnMajorForm->start[i] = 0;
00840
00841
00842 if (refMtx == NULL || refMtx->numberOfValues == 0)
00843 {
00844 ExpandedMatrixInColumnMajorForm->valueSize = 0;
00845 return ExpandedMatrixInColumnMajorForm;
00846 }
00847
00848 ExpandedMatrixInColumnMajorForm->valueSize = refMtx->numberOfValues;
00849 ExpandedMatrixInColumnMajorForm->index = new int[refMtx->numberOfValues];
00850
00851 int i, j, iTemp;
00852 int iNumSource = numberOfRows;
00853
00854 for (i = 0; i < numberOfRows; i++)
00855 {
00856 for (j = refMtx->start->el[i]; j < refMtx->start->el[i + 1]; j++)
00857 {
00858 ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j] + 1] ++;
00859 }
00860 }
00861 ExpandedMatrixInColumnMajorForm->start[0] = 0;
00862
00863 for (i = 1; i <= numberOfColumns; i++ )
00864 {
00865 ExpandedMatrixInColumnMajorForm->start[i]
00866 += ExpandedMatrixInColumnMajorForm->start [i - 1] ;
00867 }
00868
00869
00870 if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_constant)
00871 {
00872 ExpandedMatrixInColumnMajorForm->value = new ConstantMatrixValues();
00873 ((ConstantMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el
00874 = new double[refMtx->numberOfValues];
00875
00876 for (i = 0; i < numberOfRows; i++)
00877 {
00878
00879 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
00880 {
00881 iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
00882 ExpandedMatrixInColumnMajorForm->index[ iTemp] = i;
00883 ((ConstantMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el[ iTemp]
00884 = ((ConstantMatrixValues*)((ConstantMatrixElements*)refMtx)->value)->el[j];
00885 ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]] ++;
00886 }
00887 }
00888 }
00889 else if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_varReference)
00890 {
00891 ExpandedMatrixInColumnMajorForm->value = new VarReferenceMatrixValues();
00892 ((VarReferenceMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el
00893 = new int[refMtx->numberOfValues];
00894
00895 for (i = 0; i < numberOfRows; i++)
00896 {
00897
00898 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
00899 {
00900 iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
00901 ExpandedMatrixInColumnMajorForm->index[ iTemp] = i;
00902 ((VarReferenceMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el[ iTemp]
00903 = ((VarReferenceMatrixValues*)((VarReferenceMatrixElements*)refMtx)->value)->el[j];
00904 ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]] ++;
00905 }
00906 }
00907 }
00908 else if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_linear)
00909 {
00910 ExpandedMatrixInColumnMajorForm->value = new LinearMatrixValues();
00911 ((LinearMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el
00912 = new LinearMatrixElement*[refMtx->numberOfValues];
00913 for (i = 0; i < refMtx->numberOfValues; i++)
00914 ((LinearMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el[i]
00915 = new LinearMatrixElement();
00916
00917 for (i = 0; i < numberOfRows; i++)
00918 {
00919
00920 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
00921 {
00922 iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
00923 ExpandedMatrixInColumnMajorForm->index[ iTemp] = i;
00924 if (!((LinearMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->
00925 el[ iTemp]->deepCopyFrom(((LinearMatrixValues*)
00926 ((LinearMatrixElements*)refMtx)->value)->el[j]))
00927 return NULL;
00928 ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]] ++;
00929 }
00930 }
00931 }
00932 else if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_general)
00933 {
00934 ExpandedMatrixInColumnMajorForm->value = new GeneralMatrixValues();
00935 ((GeneralMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el
00936 = new ScalarExpressionTree*[refMtx->numberOfValues];
00937 for (i = 0; i < refMtx->numberOfValues; i++)
00938 {
00939 ((GeneralMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el[i]
00940 = new ScalarExpressionTree();
00941 }
00942
00943 for (i = 0; i < numberOfRows; i++)
00944 {
00945
00946 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
00947 {
00948 iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
00949 ExpandedMatrixInColumnMajorForm->index[ iTemp] = i;
00950 ((GeneralMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el[ iTemp]->m_treeRoot
00951 = ((GeneralMatrixValues*)((GeneralMatrixElements*)refMtx)->value)->el[j]->m_treeRoot->copyNodeAndDescendants();
00952 ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]] ++;
00953 }
00954 }
00955 }
00956 else if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_objReference)
00957 {
00958 ExpandedMatrixInColumnMajorForm->value = new ObjReferenceMatrixValues();
00959 ((ObjReferenceMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el
00960 = new int[refMtx->numberOfValues];
00961
00962 for (i = 0; i < numberOfRows; i++)
00963 {
00964
00965 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
00966 {
00967 iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
00968 ExpandedMatrixInColumnMajorForm->index[ iTemp] = i;
00969 ((ObjReferenceMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el[ iTemp]
00970 = ((ObjReferenceMatrixValues*)((ObjReferenceMatrixElements*)refMtx)->value)->el[j];
00971 ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]] ++;
00972 }
00973 }
00974 }
00975 else if (ExpandedMatrixInColumnMajorForm->vType == ENUM_MATRIX_TYPE_conReference)
00976 {
00977 ExpandedMatrixInColumnMajorForm->value = new ConReferenceMatrixValues();
00978 ((ConReferenceMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el
00979 = new ConReferenceMatrixElement*[refMtx->numberOfValues];
00980 for (i = 0; i < refMtx->numberOfValues; i++)
00981 ((ConReferenceMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el[i]
00982 = new ConReferenceMatrixElement();
00983
00984 for (i = 0; i < numberOfRows; i++)
00985 {
00986
00987 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
00988 {
00989 iTemp = ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]];
00990 ExpandedMatrixInColumnMajorForm->index[ iTemp] = i;
00991 if (!((ConReferenceMatrixValues*)ExpandedMatrixInColumnMajorForm->value)->el[ iTemp]->deepCopyFrom(((ConReferenceMatrixValues*)((ConReferenceMatrixElements*)refMtx)->value)->el[j]))
00992 return NULL;
00993 ExpandedMatrixInColumnMajorForm->start[refMtx->index->el[j]] ++;
00994 }
00995 }
00996 }
00997
00998
00999 for (i = numberOfColumns; i >= 1; i--)
01000 {
01001 ExpandedMatrixInColumnMajorForm->start[i]
01002 = ExpandedMatrixInColumnMajorForm->start[i - 1];
01003 }
01004
01005 ExpandedMatrixInColumnMajorForm->start[0] = 0;
01006 return ExpandedMatrixInColumnMajorForm;
01007 }
01008 }
01009 }
01010
01011 else
01012 {
01013
01014
01015
01016
01017
01018 throw ErrorClass("Multiple constructors not yet implemented in getMatrixCoefficientsInColumnMajor()");
01019 }
01020 return NULL;
01021 }
01022 catch(const ErrorClass& eclass)
01023 {
01024 throw ErrorClass( eclass.errormsg);
01025 }
01026 }
01027
01028 GeneralSparseMatrix* MatrixType::getMatrixCoefficientsInRowMajor()
01029 {
01030 #ifndef NDEBUG
01031 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside getMatrixCoefficientsInRowMajor()");
01032 #endif
01033 try
01034 {
01035
01036 if (ExpandedMatrixInRowMajorForm != NULL)
01037 return ExpandedMatrixInRowMajorForm;
01038 if (ExpandedMatrixInColumnMajorForm != NULL)
01039 {
01040 ExpandedMatrixInRowMajorForm = convertToOtherMajor(true);
01041 return ExpandedMatrixInRowMajorForm;
01042 }
01043
01044
01045
01046 if (inumberOfChildren == 0)
01047 {
01048 ExpandedMatrixInRowMajorForm = new GeneralSparseMatrix();
01049 ExpandedMatrixInRowMajorForm->symmetry = symmetry;
01050 ExpandedMatrixInRowMajorForm->valueSize = 0;
01051 ExpandedMatrixInRowMajorForm->startSize = numberOfRows + 1;
01052 ExpandedMatrixInRowMajorForm->start = new int[numberOfRows + 1];
01053 for (int i=0; i <= numberOfRows; i++)
01054 ExpandedMatrixInRowMajorForm->start[i] = 0;
01055 return ExpandedMatrixInRowMajorForm;
01056 }
01057
01058
01059 else if (inumberOfChildren == 1)
01060 {
01061 if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix)
01062 {
01063 int baseMtxIdx = ((BaseMatrix*)m_mChildren[0])->baseMatrixIdx;
01064 OSMatrix* baseMtxPtr = ((BaseMatrix*)m_mChildren[0])->baseMatrix;
01065
01066 int iroff = ((BaseMatrix*)m_mChildren[0])->targetMatrixFirstRow;
01067 int icoff = ((BaseMatrix*)m_mChildren[0])->targetMatrixFirstCol;
01068 int base_r0, base_c0, base_rN, base_cN;
01069
01070 GeneralSparseMatrix* baseMtx;
01071 if (((BaseMatrix*)m_mChildren[0])->baseTranspose)
01072 {
01073 baseMtx = baseMtxPtr->getMatrixCoefficientsInColumnMajor();
01074 base_c0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartCol;
01075 base_r0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartRow;
01076 base_cN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndCol;
01077 base_cN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndRow;
01078 if (base_cN < 0)
01079 base_cN = baseMtxPtr->numberOfColumns - 1;
01080 if (base_rN < 0)
01081 base_rN = baseMtxPtr->numberOfRows - 1;
01082 }
01083 else
01084 {
01085 baseMtx = baseMtxPtr->getMatrixCoefficientsInRowMajor();
01086 base_c0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartRow;
01087 base_r0 = ((BaseMatrix*)m_mChildren[0])->baseMatrixStartCol;
01088 base_cN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndRow;
01089 base_rN = ((BaseMatrix*)m_mChildren[0])->baseMatrixEndCol;
01090 if (base_cN < 0)
01091 base_cN = baseMtxPtr->numberOfRows - 1;
01092 if (base_rN < 0)
01093 base_rN = baseMtxPtr->numberOfColumns - 1;
01094 }
01095
01096 double scaleMult = ((BaseMatrix*)m_mChildren[0])->scalarMultiplier;
01097
01098 ExpandedMatrixInRowMajorForm = new GeneralSparseMatrix();
01099 ExpandedMatrixInRowMajorForm->symmetry = symmetry;
01100 ExpandedMatrixInRowMajorForm->startSize = numberOfRows + 1;
01101
01102
01103 bool isShifted = (iroff > 0 || icoff > 0);
01104 bool isCropped = (base_c0 > 0 || base_r0 > 0 ||
01105 base_rN < baseMtxPtr->numberOfRows - 1 ||
01106 base_cN < baseMtxPtr->numberOfColumns - 1);
01107 bool isClipped = (iroff + base_rN - base_r0 >= numberOfRows ||
01108 icoff + base_cN - base_c0 >= numberOfColumns);
01109 bool isScaled = (scaleMult != 1);
01110 bool reTyped = (getMatrixType() != baseMtx->vType);
01111 bool hasGap = (icoff + base_cN - base_c0 < numberOfColumns - 1);
01112
01113
01114 if ( !isShifted && !isCropped && !isClipped && !isScaled && !reTyped )
01115 {
01116 ExpandedMatrixInRowMajorForm->b_deleteStartArray = false;
01117 ExpandedMatrixInRowMajorForm->b_deleteIndexArray = hasGap;
01118 ExpandedMatrixInRowMajorForm->b_deleteValueArray = false;
01119 ExpandedMatrixInRowMajorForm->isRowMajor = false;
01120 ExpandedMatrixInRowMajorForm->valueSize = baseMtx->valueSize;
01121 ExpandedMatrixInRowMajorForm->vType = baseMtx->vType;
01122 ExpandedMatrixInRowMajorForm->index = baseMtx->index;
01123 ExpandedMatrixInRowMajorForm->value = baseMtx->value;
01124
01125
01126 if (!hasGap)
01127 ExpandedMatrixInColumnMajorForm->start = baseMtx->start;
01128 else
01129 {
01130 ExpandedMatrixInRowMajorForm->startSize = numberOfRows + 1;
01131 ExpandedMatrixInRowMajorForm->start =
01132 new int[ExpandedMatrixInRowMajorForm->startSize];
01133 for (int i=0; i < baseMtx->startSize; i++)
01134 ExpandedMatrixInRowMajorForm->start[i] = baseMtx->start[i];
01135 int lastStart = baseMtx->valueSize;
01136 for (int i=baseMtx->startSize;
01137 i < ExpandedMatrixInRowMajorForm->startSize; i++)
01138 ExpandedMatrixInRowMajorForm->start[i] = lastStart;
01139 }
01140 return ExpandedMatrixInRowMajorForm;
01141 }
01142 else
01143 {
01144
01145 if ( !isShifted && !isCropped && !isClipped )
01146 {
01147
01148 ExpandedMatrixInRowMajorForm->b_deleteStartArray = hasGap;
01149 ExpandedMatrixInRowMajorForm->b_deleteIndexArray = false;
01150 ExpandedMatrixInRowMajorForm->b_deleteValueArray = true;
01151 ExpandedMatrixInRowMajorForm->isRowMajor = false;
01152 ExpandedMatrixInRowMajorForm->valueSize = baseMtx->valueSize;
01153 ExpandedMatrixInRowMajorForm->vType = baseMtx->vType;
01154 ExpandedMatrixInRowMajorForm->index = baseMtx->index;
01155
01156
01157 if (!hasGap)
01158 ExpandedMatrixInRowMajorForm->start = baseMtx->start;
01159 else
01160 {
01161 ExpandedMatrixInRowMajorForm->startSize = numberOfRows + 1;
01162 ExpandedMatrixInRowMajorForm->start =
01163 new int[ExpandedMatrixInRowMajorForm->startSize];
01164 for (int i=0; i < baseMtx->startSize; i++)
01165 ExpandedMatrixInRowMajorForm->start[i] = baseMtx->start[i];
01166 int lastStart = baseMtx->valueSize;
01167 for (int i=baseMtx->startSize;
01168 i < ExpandedMatrixInRowMajorForm->startSize; i++)
01169 ExpandedMatrixInRowMajorForm->start[i] = lastStart;
01170 }
01171
01172
01173 if ( baseMtx->vType == ENUM_MATRIX_TYPE_constant)
01174 {
01175 ExpandedMatrixInRowMajorForm->value = new ConstantMatrixValues();
01176 ((ConstantMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el
01177 = new double[baseMtx->valueSize];
01178 for (int i = 0; i < baseMtx->valueSize; i++)
01179 ((ConstantMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el[i]
01180 = scaleMult*((ConstantMatrixValues*)baseMtx->value)->el[i];
01181 }
01182 else if (baseMtx->vType == ENUM_MATRIX_TYPE_varReference)
01183 {
01184
01185 LinearMatrixValues* tmpValues = new LinearMatrixValues();
01186 tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
01187 for (int i = 0; i < baseMtx->valueSize; i++)
01188 {
01189 tmpValues->el[i] = new LinearMatrixElement();
01190 tmpValues->el[i]->numberOfVarIdx = 1;
01191 tmpValues->el[i]->varIdx = new LinearMatrixElementTerm*[1];
01192 tmpValues->el[i]->varIdx[0] = new LinearMatrixElementTerm();
01193 tmpValues->el[i]->varIdx[0]->coef = scaleMult;
01194 tmpValues->el[i]->varIdx[0]->idx
01195 = ((VarReferenceMatrixValues*)baseMtx->value)->el[i];
01196 }
01197 ExpandedMatrixInRowMajorForm->value = tmpValues;
01198 }
01199 else if (baseMtx->vType == ENUM_MATRIX_TYPE_linear)
01200 {
01201 LinearMatrixValues* tmpValues = new LinearMatrixValues();
01202 tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
01203 for (int i = 0; i < baseMtx->valueSize; i++)
01204 {
01205 tmpValues->el[i] = new LinearMatrixElement();
01206 if (!(tmpValues->el[i]
01207 ->deepCopyFrom(((LinearMatrixValues*)baseMtx->value)->el[i])))
01208 throw ErrorClass("failed copying linear element values in method getMatrixCoefficientsInRowMajor()");
01209 for (int j=0; j<tmpValues->el[i]->numberOfVarIdx; j++)
01210 tmpValues->el[i]->varIdx[j]->coef *= scaleMult;
01211 }
01212 ExpandedMatrixInRowMajorForm->value = tmpValues;
01213 }
01214 else if (baseMtx->vType == ENUM_MATRIX_TYPE_general)
01215 {
01216
01217 GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
01218 tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
01219 for (int i = 0; i < baseMtx->valueSize; i++)
01220 {
01221 tmpValues->el[i] = new ScalarExpressionTree();
01222 tmpValues->el[i]->m_treeRoot = new OSnLNodeTimes();
01223 tmpValues->el[i]->m_treeRoot->m_mChildren[0] = new OSnLNodeNumber();
01224 ((OSnLNodeNumber*)tmpValues->el[i]->m_treeRoot->m_mChildren[0])->value = scaleMult;
01225 tmpValues->el[i]->m_treeRoot->m_mChildren[1]
01226 = ((GeneralMatrixValues*)baseMtx->value)->el[i]->m_treeRoot
01227 ->copyNodeAndDescendants();
01228 }
01229 ExpandedMatrixInRowMajorForm->value = tmpValues;
01230 }
01231 else if (baseMtx->vType == ENUM_MATRIX_TYPE_objReference)
01232 {
01233 throw ErrorClass("scalar multiple not defined for objReference elements in getMatrixCoefficientsInRowMajor()");
01234 }
01235 else if (baseMtx->vType == ENUM_MATRIX_TYPE_conReference)
01236 {
01237 throw ErrorClass("scalar multiple not defined for conReference elements in getMatrixCoefficientsInRowMajor()");
01238 }
01239 return ExpandedMatrixInColumnMajorForm;
01240 }
01241 else
01242 {
01243 ExpandedMatrixInRowMajorForm->b_deleteStartArray = true;
01244 ExpandedMatrixInRowMajorForm->b_deleteIndexArray = true;
01245 ExpandedMatrixInRowMajorForm->b_deleteValueArray = true;
01246 ExpandedMatrixInRowMajorForm->startSize = numberOfRows + 1;
01247 ExpandedMatrixInRowMajorForm->isRowMajor = false;
01248 ExpandedMatrixInRowMajorForm->vType = baseMtx->vType;
01249
01250 int startSize = numberOfRows + 1;
01251 int* tmpStarts = new int[startSize];
01252 for (int i=0; i < startSize; i++)
01253 tmpStarts[i] = 0;
01254
01255 int adjc = icoff - base_c0;
01256 int lastcol = icoff + base_cN - base_c0 + 1;
01257 if (lastcol > numberOfRows)
01258 lastcol = numberOfRows;
01259
01260
01261 for (int i=icoff; i<lastcol; i++)
01262 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
01263 {
01264 if (baseMtx->index[j] >= base_r0 &&
01265 baseMtx->index[j] <= base_rN &&
01266 baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
01267 tmpStarts[i+1]++;
01268 }
01269 for (int i=icoff+1; i <= startSize; i++)
01270 tmpStarts[i] += tmpStarts[i-1];
01271
01272 int valueSize = tmpStarts[startSize-1];
01273 int* tmpIndexes = new int[valueSize];
01274
01275 ExpandedMatrixInRowMajorForm->valueSize = valueSize;
01276 ExpandedMatrixInRowMajorForm->start = tmpStarts;
01277
01278
01279 if ( baseMtx->vType == ENUM_MATRIX_TYPE_constant)
01280 {
01281 MatrixElementValues* tmpValues = new ConstantMatrixValues();
01282 ((ConstantMatrixValues*)tmpValues)->el = new double[valueSize];
01283
01284 int ival = 0;
01285 for (int i=icoff; i<lastcol; i++)
01286 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
01287 {
01288 if (baseMtx->index[j] >= base_r0 &&
01289 baseMtx->index[j] <= base_rN &&
01290 baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
01291 {
01292 tmpIndexes[ival] = baseMtx->index[j] - base_r0 + iroff;
01293 ((ConstantMatrixValues*)tmpValues)->el[ival]
01294 = scaleMult*((ConstantMatrixValues*)baseMtx->value)->el[j];
01295 ival++;
01296 }
01297 }
01298 ExpandedMatrixInRowMajorForm->index = tmpIndexes;
01299 ExpandedMatrixInRowMajorForm->value = tmpValues;
01300 }
01301
01302 else if (baseMtx->vType == ENUM_MATRIX_TYPE_varReference)
01303 {
01304 if (scaleMult == 1)
01305 {
01306 MatrixElementValues* tmpValues = new VarReferenceMatrixValues();
01307 ((VarReferenceMatrixValues*)tmpValues)->el = new int[valueSize];
01308
01309 int ival = 0;
01310 for (int i=icoff; i<lastcol; i++)
01311 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
01312 {
01313 if (baseMtx->index[j] >= base_r0 &&
01314 baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
01315 {
01316 tmpIndexes[ival] = baseMtx->index[j] + base_r0 - iroff;
01317 ((ConstantMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el[ival]
01318 = scaleMult*((ConstantMatrixValues*)baseMtx->value)->el[j];
01319 ival++;
01320 }
01321 }
01322 ExpandedMatrixInRowMajorForm->index = tmpIndexes;
01323 ExpandedMatrixInRowMajorForm->value = tmpValues;
01324 }
01325 else
01326 {
01327
01328 MatrixElementValues* tmpValues = new LinearMatrixValues();
01329 ((LinearMatrixValues*)tmpValues)->el
01330 = new LinearMatrixElement*[valueSize];
01331
01332 int ival = 0;
01333 for (int i=icoff; i<lastcol; i++)
01334 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
01335 {
01336 if (baseMtx->index[j] >= base_r0 &&
01337 baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
01338 {
01339 ((LinearMatrixValues*)tmpValues)->el[ival]
01340 = new LinearMatrixElement();
01341 ((LinearMatrixValues*)tmpValues)->el[ival]->numberOfVarIdx = 1;
01342 ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx
01343 = new LinearMatrixElementTerm*[1];
01344 ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]
01345 = new LinearMatrixElementTerm();
01346 ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]->coef
01347 = scaleMult;
01348 ((LinearMatrixValues*)tmpValues)->el[ival]->varIdx[0]->idx
01349 = ((VarReferenceMatrixValues*)baseMtx->value)->el[j];
01350 ival++;
01351 }
01352 }
01353 ExpandedMatrixInRowMajorForm->index = tmpIndexes;
01354 ExpandedMatrixInRowMajorForm->value = tmpValues;
01355 }
01356 }
01357 else if (baseMtx->vType == ENUM_MATRIX_TYPE_linear)
01358 {
01359 LinearMatrixValues* tmpValues = new LinearMatrixValues();
01360 tmpValues->el = new LinearMatrixElement*[baseMtx->valueSize];
01361
01362 int ival = 0;
01363 for (int i=icoff; i<lastcol; i++)
01364 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
01365 {
01366 if (baseMtx->index[j] >= base_r0 &&
01367 baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
01368 {
01369 tmpValues->el[ival] = new LinearMatrixElement();
01370 if (!(tmpValues->el[ival]
01371 ->deepCopyFrom(((LinearMatrixValues*)baseMtx->value)->el[j])))
01372 throw ErrorClass("failed copying linear element values in method getMatrixCoefficientsInRowMajor()");
01373 for (int k=0; k<tmpValues->el[ival]->numberOfVarIdx; k++)
01374 tmpValues->el[ival]->varIdx[k]->coef *= scaleMult;
01375 ival++;
01376 }
01377 }
01378 ExpandedMatrixInRowMajorForm->index = tmpIndexes;
01379 ExpandedMatrixInRowMajorForm->value = tmpValues;
01380 }
01381 else if (baseMtx->vType == ENUM_MATRIX_TYPE_general)
01382 {
01383 if (scaleMult == 1)
01384 {
01385 GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
01386 tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
01387
01388 int ival = 0;
01389 for (int i=icoff; i<lastcol; i++)
01390 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
01391 {
01392 if (baseMtx->index[j] >= base_r0 &&
01393 baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
01394 {
01395 ((GeneralMatrixValues*)tmpValues)->el[ival]
01396 = new ScalarExpressionTree();
01397
01398
01399 ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot
01400 = ((GeneralMatrixValues*)baseMtx->value)->el[j]->m_treeRoot
01401 ->copyNodeAndDescendants();
01402 ival++;
01403 }
01404 }
01405 ExpandedMatrixInRowMajorForm->index = tmpIndexes;
01406 ExpandedMatrixInRowMajorForm->value = tmpValues;
01407 }
01408 else
01409 {
01410
01411 GeneralMatrixValues* tmpValues = new GeneralMatrixValues();
01412 tmpValues->el = new ScalarExpressionTree*[baseMtx->valueSize];
01413 int ival = 0;
01414 for (int i=icoff; i<lastcol; i++)
01415 for (int j=baseMtx->start[i-adjc]; j<baseMtx->start[i-adjc+1]; j++)
01416 {
01417 if (baseMtx->index[j] >= base_r0 &&
01418 baseMtx->index[j] < numberOfColumns + base_r0 - iroff)
01419 {
01420 ((GeneralMatrixValues*)tmpValues)->el[ival]
01421 = new ScalarExpressionTree();
01422 ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot
01423 = new OSnLNodeTimes();
01424 ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot->m_mChildren[0]
01425 = new OSnLNodeNumber();
01426 ((OSnLNodeNumber*)tmpValues->el[ival]->m_treeRoot->m_mChildren[0])->value = scaleMult;
01427 ((GeneralMatrixValues*)tmpValues)->el[ival]->m_treeRoot->m_mChildren[1]
01428 = ((GeneralMatrixValues*)baseMtx->value)->el[j]->m_treeRoot->copyNodeAndDescendants();
01429 ival++;
01430
01431 }
01432 }
01433 ExpandedMatrixInRowMajorForm->index = tmpIndexes;
01434 ExpandedMatrixInRowMajorForm->value = tmpValues;
01435 }
01436 }
01437 else if (baseMtx->vType == ENUM_MATRIX_TYPE_objReference)
01438 {
01439 throw ErrorClass("scalar multiple not defined for objReference elements in getMatrixCoefficientsInRowMajor()");
01440 }
01441 else if (baseMtx->vType == ENUM_MATRIX_TYPE_conReference)
01442 {
01443 throw ErrorClass("scalar multiple not defined for conReference elements in getMatrixCoefficientsInRowMajor()");
01444 }
01445 }
01446 return ExpandedMatrixInRowMajorForm;
01447 }
01448 }
01449
01450 else if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks)
01451 {
01452
01453 if (!processBlocks(true, symmetry))
01454 throw ErrorClass("error processing blocks in getMatrixCoefficientsInRowMajor()");
01455
01456 ExpandedMatrixBlocks* currentBlocks
01457 = getBlocks(m_miRowPartition, m_iRowPartitionSize, m_miColumnPartition,
01458 m_iColumnPartitionSize, true, true);
01459
01460
01461 ExpandedMatrixInRowMajorForm = new GeneralSparseMatrix();
01462 ExpandedMatrixInRowMajorForm->b_deleteStartArray = true;
01463 ExpandedMatrixInRowMajorForm->b_deleteIndexArray = true;
01464 ExpandedMatrixInRowMajorForm->b_deleteValueArray = true;
01465 ExpandedMatrixInRowMajorForm->vType = getMatrixType();
01466 ExpandedMatrixInRowMajorForm->isRowMajor = false;
01467 ExpandedMatrixInRowMajorForm->symmetry = symmetry;
01468 ExpandedMatrixInRowMajorForm->startSize = numberOfRows + 1;
01469 ExpandedMatrixInRowMajorForm->start = new int[numberOfRows + 1];
01470 for (int i=0; i <= numberOfRows; i++)
01471 ExpandedMatrixInRowMajorForm->start[i] = 0;
01472
01473
01474 for (int i=0; i < currentBlocks->blockNumber; i++)
01475 {
01476 int c0 = currentBlocks->colOffset[currentBlocks->blockColumns[i]];
01477 int cN = currentBlocks->colOffset[currentBlocks->blockColumns[i]+1];
01478 for (int j = c0; j < cN; j++)
01479 {
01480 ExpandedMatrixInRowMajorForm->start[j+1] +=
01481 ( currentBlocks->blocks[i]->start[j+1-c0]
01482 - currentBlocks->blocks[i]->start[j -c0] );
01483 }
01484 }
01485
01486 for (int i=1; i <= numberOfRows; i++)
01487 ExpandedMatrixInRowMajorForm->start[i] +=
01488 ExpandedMatrixInRowMajorForm->start[i-1];
01489 ExpandedMatrixInRowMajorForm->valueSize =
01490 ExpandedMatrixInRowMajorForm->start[numberOfRows];
01491 int* tmpIndexes = new int[ExpandedMatrixInRowMajorForm->valueSize];
01492
01493
01494 if (currentBlocks->blocks[0]->vType == ENUM_MATRIX_TYPE_constant)
01495 {
01496 ConstantMatrixValues* tmpValues = new ConstantMatrixValues();
01497 tmpValues->el
01498 = new double[ExpandedMatrixInRowMajorForm->valueSize];
01499
01500 for (int i=0; i < currentBlocks->blockNumber; i++)
01501 {
01502 int c0 = currentBlocks->rowOffset[currentBlocks->blockRows[i]];
01503 int cN = currentBlocks->rowOffset[currentBlocks->blockRows[i]+1];
01504 int row_adj = currentBlocks->colOffset[currentBlocks->blockColumns[i]];
01505
01506 for (int j = c0; j < cN; j++)
01507 {
01508 int loc = ExpandedMatrixInRowMajorForm->start[j];
01509 for (int k = currentBlocks->blocks[i]->start[j-c0];
01510 k < currentBlocks->blocks[i]->start[j-c0+1]; k++)
01511 {
01512 tmpIndexes[loc] = currentBlocks->blocks[i]->index[k] + row_adj;
01513 ((ConstantMatrixValues*)tmpValues)->el[loc]
01514 = ((ConstantMatrixValues*)currentBlocks->blocks[i]->value)->el[k];
01515 loc++;
01516 }
01517 ExpandedMatrixInRowMajorForm->start[j] = loc;
01518 }
01519 }
01520 ExpandedMatrixInRowMajorForm->index = tmpIndexes;
01521 ExpandedMatrixInRowMajorForm->value = tmpValues;
01522 }
01523 else
01524 throw ErrorClass("getMatrixCoefficientsInRowMajor: Can only handle constant values so far in blocks");
01525 for (int i=numberOfColumns; i > 0; i--)
01526 ExpandedMatrixInRowMajorForm->start[i] =
01527 ExpandedMatrixInRowMajorForm->start[i-1];
01528 ExpandedMatrixInRowMajorForm->start[0] = 0;
01529 return ExpandedMatrixInColumnMajorForm;
01530 }
01531
01532 else if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_transformation)
01533 {
01534
01535
01536 throw ErrorClass("transformations not yet implemented in getMatrixCoefficientsInColumnMajor()");
01537 }
01538 else
01539 {
01540 if (((MatrixElements*)m_mChildren[0])->rowMajor)
01541 {
01542 ExpandedMatrixInRowMajorForm = new GeneralSparseMatrix();
01543 ExpandedMatrixInRowMajorForm->symmetry = symmetry;
01544 ExpandedMatrixInRowMajorForm->b_deleteStartArray = false;
01545 ExpandedMatrixInRowMajorForm->b_deleteIndexArray = false;
01546 ExpandedMatrixInRowMajorForm->b_deleteValueArray = false;
01547 ExpandedMatrixInRowMajorForm->isRowMajor = false;
01548 ExpandedMatrixInRowMajorForm->startSize = numberOfRows + 1;
01549 ExpandedMatrixInRowMajorForm->valueSize
01550 = ((MatrixElements*)m_mChildren[0])->numberOfValues;
01551 ExpandedMatrixInRowMajorForm->start
01552 = ((MatrixElements*)m_mChildren[0])->start->el;
01553 ExpandedMatrixInRowMajorForm->vType
01554 = getMatrixType();
01555 ExpandedMatrixInRowMajorForm->index
01556 = ((MatrixElements*)m_mChildren[0])->index->el;
01557 if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_constant)
01558 ExpandedMatrixInRowMajorForm->value
01559 = ((ConstantMatrixElements*)m_mChildren[0])->value;
01560 else if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_varReference)
01561 ExpandedMatrixInRowMajorForm->value
01562 = ((VarReferenceMatrixElements*)m_mChildren[0])->value;
01563 else if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_linear)
01564 ExpandedMatrixInRowMajorForm->value
01565 = ((LinearMatrixElements*)m_mChildren[0])->value;
01566 else if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_general)
01567 ExpandedMatrixInRowMajorForm->value
01568 = ((GeneralMatrixElements*)m_mChildren[0])->value;
01569 else if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_objReference)
01570 ExpandedMatrixInRowMajorForm->value
01571 = ((ObjReferenceMatrixElements*)m_mChildren[0])->value;
01572 else if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_conReference)
01573 ExpandedMatrixInRowMajorForm->value
01574 = ((ConReferenceMatrixElements*)m_mChildren[0])->value;
01575 else
01576 throw ErrorClass("Unknown element type in getMatrixCoefficientsInRowMajor()");
01577
01578 return ExpandedMatrixInRowMajorForm;
01579 }
01580
01581 else
01582 {
01583 MatrixElements* refMtx = (MatrixElements*)m_mChildren[0];
01584
01585 ExpandedMatrixInRowMajorForm = new GeneralSparseMatrix();
01586 ExpandedMatrixInRowMajorForm->symmetry = symmetry;
01587 ExpandedMatrixInRowMajorForm->startSize = numberOfRows + 1;
01588 ExpandedMatrixInRowMajorForm->vType = getMatrixType();
01589 ExpandedMatrixInRowMajorForm->start = new int[numberOfRows + 1];
01590 for (int i=0; i <= numberOfRows; i++)
01591 ExpandedMatrixInRowMajorForm->start[i] = 0;
01592
01593
01594 if (refMtx == NULL || refMtx->numberOfValues == 0)
01595 {
01596 ExpandedMatrixInRowMajorForm->valueSize = 0;
01597 return ExpandedMatrixInRowMajorForm;
01598 }
01599
01600 ExpandedMatrixInRowMajorForm->valueSize = refMtx->numberOfValues;
01601 ExpandedMatrixInRowMajorForm->index = new int[refMtx->numberOfValues];
01602
01603 int i, j, iTemp;
01604 int iNumSource = numberOfColumns;
01605
01606 for (i = 0; i < numberOfColumns; i++)
01607 {
01608 for (j = refMtx->start->el[i]; j < refMtx->start->el[i + 1]; j++)
01609 {
01610 ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j] + 1] ++;
01611 }
01612 }
01613 ExpandedMatrixInRowMajorForm->start[0] = 0;
01614
01615 for (i = 1; i <= numberOfRows; i++ )
01616 {
01617 ExpandedMatrixInRowMajorForm->start[i]
01618 += ExpandedMatrixInRowMajorForm->start [i - 1] ;
01619 }
01620
01621
01622 if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_constant)
01623 {
01624 ExpandedMatrixInRowMajorForm->value = new ConstantMatrixValues();
01625 ((ConstantMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el
01626 = new double[refMtx->numberOfValues];
01627
01628 for (i = 0; i < numberOfColumns; i++)
01629 {
01630
01631 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
01632 {
01633 iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
01634 ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
01635 ((ConstantMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el[ iTemp]
01636 = ((ConstantMatrixValues*)((ConstantMatrixElements*)refMtx)->value)->el[j];
01637 ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
01638 }
01639 }
01640 }
01641 else if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_varReference)
01642 {
01643 ExpandedMatrixInRowMajorForm->value = new VarReferenceMatrixValues();
01644 ((VarReferenceMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el
01645 = new int[refMtx->numberOfValues];
01646
01647 for (i = 0; i < numberOfColumns; i++)
01648 {
01649
01650 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
01651 {
01652 iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
01653 ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
01654 ((VarReferenceMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el[ iTemp]
01655 = ((VarReferenceMatrixValues*)((VarReferenceMatrixElements*)refMtx)->value)->el[j];
01656 ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
01657 }
01658 }
01659 }
01660 else if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_linear)
01661 {
01662 ExpandedMatrixInRowMajorForm->value = new LinearMatrixValues();
01663 ((LinearMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el
01664 = new LinearMatrixElement*[refMtx->numberOfValues];
01665 for (i = 0; i < refMtx->numberOfValues; i++)
01666 ((LinearMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el[i]
01667 = new LinearMatrixElement();
01668
01669 for (i = 0; i < numberOfColumns; i++)
01670 {
01671
01672 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
01673 {
01674 iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
01675 ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
01676 if (!((LinearMatrixValues*)ExpandedMatrixInRowMajorForm->value)->
01677 el[ iTemp]->deepCopyFrom(((LinearMatrixValues*)
01678 ((LinearMatrixElements*)refMtx)->value)->el[j]))
01679 return NULL;
01680 ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
01681 }
01682 }
01683 }
01684 else if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_general)
01685 {
01686 ExpandedMatrixInRowMajorForm->value = new GeneralMatrixValues();
01687 ((GeneralMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el
01688 = new ScalarExpressionTree*[refMtx->numberOfValues];
01689 for (i = 0; i < refMtx->numberOfValues; i++)
01690 {
01691 ((GeneralMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el[i]
01692 = new ScalarExpressionTree();
01693 }
01694
01695 for (i = 0; i < numberOfColumns; i++)
01696 {
01697
01698 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
01699 {
01700 iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
01701 ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
01702 ((GeneralMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el[ iTemp]->m_treeRoot
01703 = ((GeneralMatrixValues*)((GeneralMatrixElements*)refMtx)->value)->el[j]->m_treeRoot->copyNodeAndDescendants();
01704 ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
01705 }
01706 }
01707 }
01708 else if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_objReference)
01709 {
01710 ExpandedMatrixInRowMajorForm->value = new ObjReferenceMatrixValues();
01711 ((ObjReferenceMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el
01712 = new int[refMtx->numberOfValues];
01713
01714 for (i = 0; i < numberOfColumns; i++)
01715 {
01716
01717 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
01718 {
01719 iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
01720 ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
01721 ((ObjReferenceMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el[ iTemp]
01722 = ((ObjReferenceMatrixValues*)((ObjReferenceMatrixElements*)refMtx)->value)->el[j];
01723 ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
01724 }
01725 }
01726 }
01727 else if (ExpandedMatrixInRowMajorForm->vType == ENUM_MATRIX_TYPE_conReference)
01728 {
01729 ExpandedMatrixInRowMajorForm->value = new ConReferenceMatrixValues();
01730 ((ConReferenceMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el
01731 = new ConReferenceMatrixElement*[refMtx->numberOfValues];
01732 for (i = 0; i < refMtx->numberOfValues; i++)
01733 ((ConReferenceMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el[i]
01734 = new ConReferenceMatrixElement();
01735
01736 for (i = 0; i < numberOfColumns; i++)
01737 {
01738
01739 for (j = refMtx->start->el[i]; j < refMtx->start->el[ i + 1 ]; j++)
01740 {
01741 iTemp = ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]];
01742 ExpandedMatrixInRowMajorForm->index[ iTemp] = i;
01743 if (!((ConReferenceMatrixValues*)ExpandedMatrixInRowMajorForm->value)->el[ iTemp]->deepCopyFrom(((ConReferenceMatrixValues*)((ConReferenceMatrixElements*)refMtx)->value)->el[j]))
01744 return NULL;
01745 ExpandedMatrixInRowMajorForm->start[refMtx->index->el[j]] ++;
01746 }
01747 }
01748 }
01749
01750
01751 for (i = numberOfRows; i >= 1; i-- )
01752 {
01753 ExpandedMatrixInRowMajorForm->start[i]
01754 = ExpandedMatrixInRowMajorForm->start[i - 1] ;
01755 }
01756
01757 ExpandedMatrixInRowMajorForm->start[0] = 0;
01758 return ExpandedMatrixInRowMajorForm;
01759 }
01760 }
01761 }
01762
01763 else
01764 {
01765
01766
01767
01768
01769
01770 throw ErrorClass("Multiple constructors not yet implemented in getMatrixCoefficientsInRowMajor()");
01771 }
01772 return NULL;
01773 }
01774 catch(const ErrorClass& eclass)
01775 {
01776 throw ErrorClass( eclass.errormsg);
01777 }
01778 }
01779
01780 bool MatrixType::expandElements(bool rowMajor)
01781 {
01782 return NULL;
01783 }
01784
01785 bool MatrixType::printExpandedMatrix(bool rowMajor_)
01786 {
01787 try
01788 {
01789 GeneralSparseMatrix* tmp;
01790
01791 if (rowMajor_)
01792 {
01793 if (ExpandedMatrixInRowMajorForm == NULL)
01794 return false;
01795 tmp = ExpandedMatrixInRowMajorForm;
01796 }
01797 else
01798 {
01799 if (ExpandedMatrixInColumnMajorForm == NULL)
01800 return false;
01801 tmp = ExpandedMatrixInColumnMajorForm;
01802 }
01803
01804 std::ostringstream outStr;
01805
01806 ENUM_MATRIX_CONSTRUCTOR_TYPE type;
01807
01808 if (getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_matrix)
01809 {
01810 outStr << "matrix " << ((OSMatrix*)this)->idx;
01811 if (((OSMatrix*)this)->name != "")
01812 outStr << " (" << ((OSMatrix*)this)->name << ")";
01813 outStr << std::endl;
01814 }
01815 else if (getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_block)
01816 outStr << "matrix block" << std::endl;
01817 else
01818 throw ErrorClass("matrix type unknown or not set");
01819
01820 outStr << "number of rows " << numberOfRows << std::endl;
01821 outStr << "number of columns " << numberOfColumns << std::endl;
01822 outStr << "number of nonzeros " << tmp->valueSize << std::endl;
01823 outStr << "type of nonzeros " << returnMatrixTypeString(tmp->vType) << std::endl;
01824 outStr << "symmetry " << returnMatrixSymmetryString(symmetry) << std::endl;
01825
01826 outStr << std::endl << "These matrix arrays are organized ";
01827 if (rowMajor_)
01828 outStr << "by rows" << std::endl;
01829 else
01830 outStr << "by columns" << std::endl;
01831
01832 outStr << std::endl << "starts:";
01833 for (int i=0; i < tmp->startSize; i++)
01834 outStr << " " << tmp->start[i];
01835 outStr << std::endl;
01836
01837 outStr << std::endl << "indexes:";
01838 for (int i=0; i < tmp->valueSize; i++)
01839 outStr << " " << tmp->index[i];
01840 outStr << std::endl;
01841
01842 outStr << std::endl << "values:";
01843 if (tmp->vType == ENUM_MATRIX_TYPE_constant)
01844 {
01845 for (int i=0; i < tmp->valueSize; i++)
01846 outStr << " " << ((ConstantMatrixValues*)tmp->value)->el[i];
01847 outStr << std::endl;
01848 }
01849 else if (tmp->vType == ENUM_MATRIX_TYPE_varReference)
01850 {
01851 for (int i=0; i < tmp->valueSize; i++)
01852 outStr << " " << ((VarReferenceMatrixValues*)tmp->value)->el[i];
01853 outStr << std::endl;
01854 }
01855 else if (tmp->vType == ENUM_MATRIX_TYPE_objReference)
01856 {
01857 for (int i=0; i < tmp->valueSize; i++)
01858 outStr << " " << ((ObjReferenceMatrixValues*)tmp->value)->el[i];
01859 outStr << std::endl;
01860 }
01861 else if (tmp->vType == ENUM_MATRIX_TYPE_conReference)
01862 {
01863 for (int i=0; i < tmp->valueSize; i++)
01864 outStr << " " << ((ConReferenceMatrixValues*)tmp->value)->el[i]->conReference;
01865 outStr << std::endl;
01866 }
01867 else if (tmp->vType == ENUM_MATRIX_TYPE_general)
01868 {
01869 outStr << std::endl;
01870 for (int i=0; i < tmp->valueSize; i++)
01871 outStr << "element " << i << ": (general expression; not yet implemented)" << std::endl;
01872 outStr << std::endl;
01873 }
01874 else if (tmp->vType == ENUM_MATRIX_TYPE_linear)
01875 {
01876 outStr << std::endl;
01877 for (int i=0; i < tmp->valueSize; i++)
01878 {
01879 outStr << "element " << i << ": ";
01880
01881 double c = ((LinearMatrixElement*)((LinearMatrixValues*)tmp->value)->el[i])->constant;
01882 int m = ((LinearMatrixElement*)((LinearMatrixValues*)tmp->value)->el[i])->numberOfVarIdx;
01883 if (c != 0)
01884 {
01885 outStr << c;
01886 if (m > 0)
01887 outStr << " + ";
01888 }
01889
01890 LinearMatrixElementTerm* temp;
01891 for (int j=0; j<m; j++)
01892 {
01893 if (j > 0)
01894 outStr << " + ";
01895 temp = ((LinearMatrixElement*)((LinearMatrixValues*)tmp->value)->el[i])->varIdx[j];
01896 if (temp->coef != 1)
01897 outStr << temp->coef << "*";
01898 outStr << "x[" << temp->idx << "]";
01899 }
01900 outStr << std::endl;
01901 }
01902 outStr << std::endl;
01903 }
01904 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, outStr.str());
01905
01906 return true;
01907 }
01908 catch(const ErrorClass& eclass)
01909 {
01910 throw ErrorClass( eclass.errormsg);
01911 }
01912 }
01913
01914 GeneralSparseMatrix* MatrixType::convertToOtherMajor(bool isColumnMajor)
01915
01916
01917 {
01918 #ifndef NDEBUG
01919 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside convertToOtherMajor()");
01920 #endif
01921 GeneralSparseMatrix* refMtx;
01922 if (isColumnMajor)
01923 {
01924 refMtx = ExpandedMatrixInColumnMajorForm;
01925 if (ExpandedMatrixInRowMajorForm != NULL) return ExpandedMatrixInRowMajorForm;
01926 }
01927 else
01928 {
01929 refMtx = ExpandedMatrixInRowMajorForm;
01930 if (ExpandedMatrixInColumnMajorForm != NULL) return ExpandedMatrixInColumnMajorForm;
01931 }
01932 if (refMtx == NULL ) return NULL;
01933 if (refMtx->start == NULL || refMtx->startSize <= 1 ) return NULL;
01934
01935 int iStartSize = isColumnMajor ? numberOfRows+1 : numberOfColumns+1;
01936 GeneralSparseMatrix *matrix
01937 = new GeneralSparseMatrix( !isColumnMajor, iStartSize, refMtx->valueSize, refMtx->vType);
01938
01939 int i,j, iTemp;
01940 int iNumSource = refMtx->startSize - 1;
01941
01942 int* miStart = matrix->start;
01943 int* miIndex = matrix->index;
01944
01945 for ( i = 1; i < iStartSize; i++)
01946 {
01947 miStart [ i ] = 0;
01948 }
01949
01950
01951 for (i = 0; i < iNumSource; i++)
01952 {
01953 for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
01954 {
01955
01956
01957
01958 miStart[refMtx->index[j] + 1] ++;
01959 }
01960 }
01961
01962
01963
01964 miStart[0] = 0;
01965 for (i = 1; i < iStartSize; i++ )
01966 {
01967 miStart[i] += miStart [i - 1] ;
01968 }
01969
01970
01971
01972
01973
01974 if ( refMtx->vType == ENUM_MATRIX_TYPE_constant)
01975 {
01976 matrix->value = new ConstantMatrixValues();
01977 ((ConstantMatrixValues*)matrix->value)->el = new double[refMtx->valueSize];
01978
01979 for (i = 0; i < iNumSource; i++)
01980 {
01981
01982 for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
01983 {
01984 iTemp = miStart[refMtx->index[j]];
01985 miIndex [ iTemp] = i;
01986 ((ConstantMatrixValues*)matrix->value)->el[ iTemp]
01987 = ((ConstantMatrixValues*)refMtx->value)->el[j];
01988 miStart[refMtx->index[j]] ++;
01989 }
01990 }
01991 }
01992 else if (refMtx->vType == ENUM_MATRIX_TYPE_varReference)
01993 {
01994 matrix->value = new VarReferenceMatrixValues();
01995 ((VarReferenceMatrixValues*)matrix->value)->el = new int[refMtx->valueSize];
01996
01997 for (i = 0; i < iNumSource; i++)
01998 {
01999
02000 for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
02001 {
02002 iTemp = miStart[refMtx->index[j]];
02003 miIndex [ iTemp] = i;
02004 ((VarReferenceMatrixValues*)matrix->value)->el[ iTemp]
02005 = ((VarReferenceMatrixValues*)refMtx->value)->el[j];
02006 miStart[refMtx->index[j]] ++;
02007 }
02008 }
02009 }
02010 else if (refMtx->vType == ENUM_MATRIX_TYPE_linear)
02011 {
02012 matrix->value = new LinearMatrixValues();
02013 ((LinearMatrixValues*)matrix->value)->el = new LinearMatrixElement*[refMtx->valueSize];
02014 for (i = 0; i < refMtx->valueSize; i++)
02015 ((LinearMatrixValues*)matrix->value)->el[i] = new LinearMatrixElement();
02016
02017 for (i = 0; i < iNumSource; i++)
02018 {
02019
02020 for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
02021 {
02022 iTemp = miStart[refMtx->index[j]];
02023 miIndex [ iTemp] = i;
02024 if (!((LinearMatrixValues*)matrix->value)->el[ iTemp]->deepCopyFrom(((LinearMatrixValues*)refMtx->value)->el[j]))
02025 return NULL;
02026 miStart[refMtx->index[j]] ++;
02027 }
02028 }
02029 }
02030 else if (refMtx->vType == ENUM_MATRIX_TYPE_general)
02031 {
02032 matrix->value = new GeneralMatrixValues();
02033 ((GeneralMatrixValues*)matrix->value)->el = new ScalarExpressionTree*[refMtx->valueSize];
02034 for (i = 0; i < refMtx->valueSize; i++)
02035 {
02036 ((GeneralMatrixValues*)matrix->value)->el[i] = new ScalarExpressionTree();
02037 }
02038 for (i = 0; i < iNumSource; i++)
02039 {
02040
02041 for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
02042 {
02043 iTemp = miStart[refMtx->index[j]];
02044 miIndex [ iTemp] = i;
02045 ((GeneralMatrixValues*)matrix->value)->el[ iTemp]->m_treeRoot
02046 = ((GeneralMatrixValues*)refMtx->value)->el[j]->m_treeRoot->copyNodeAndDescendants();
02047 miStart[refMtx->index[j]] ++;
02048 }
02049 }
02050 }
02051 else if (refMtx->vType == ENUM_MATRIX_TYPE_objReference)
02052 {
02053 matrix->value = new ObjReferenceMatrixValues();
02054 ((ObjReferenceMatrixValues*)matrix->value)->el = new int[refMtx->valueSize];
02055
02056 for (i = 0; i < iNumSource; i++)
02057 {
02058
02059 for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
02060 {
02061 iTemp = miStart[refMtx->index[j]];
02062 miIndex [ iTemp] = i;
02063 ((ObjReferenceMatrixValues*)matrix->value)->el[ iTemp]
02064 = ((ObjReferenceMatrixValues*)refMtx->value)->el[j];
02065 miStart[refMtx->index[j]] ++;
02066 }
02067 }
02068 }
02069 else if (refMtx->vType == ENUM_MATRIX_TYPE_conReference)
02070 {
02071 matrix->value = new ConReferenceMatrixValues();
02072 ((ConReferenceMatrixValues*)matrix->value)->el
02073 = new ConReferenceMatrixElement*[refMtx->valueSize];
02074 for (i = 0; i < refMtx->valueSize; i++)
02075 ((ConReferenceMatrixValues*)matrix->value)->el[i] = new ConReferenceMatrixElement();
02076
02077 for (i = 0; i < iNumSource; i++)
02078 {
02079
02080 for (j = refMtx->start[i]; j < refMtx->start[ i + 1 ]; j++)
02081 {
02082 iTemp = miStart[refMtx->index[j]];
02083 miIndex [ iTemp] = i;
02084 if (!((ConReferenceMatrixValues*)matrix->value)->el[ iTemp]->deepCopyFrom(((ConReferenceMatrixValues*)refMtx->value)->el[j]))
02085 return NULL;
02086 miStart[refMtx->index[j]] ++;
02087 }
02088 }
02089 }
02090
02091
02092 for (i = iStartSize - 1; i >= 1; i-- )
02093 {
02094 miStart[i] = miStart [i - 1] ;
02095 }
02096
02097 miStart[0] = 0;
02098 return matrix;
02099 }
02100
02101 int MatrixType::getRowPartitionSize()
02102 {
02103 if (!m_bHaveRowPartition)
02104 {
02105 bool OK = processBlockPartition();
02106 if (!OK) throw ErrorClass("Error processing blocks");
02107 }
02108 return m_iRowPartitionSize;
02109 }
02110
02111 int* MatrixType::getRowPartition()
02112 {
02113 if (!m_bHaveRowPartition)
02114 {
02115 bool OK = processBlockPartition();
02116 if (!OK) throw ErrorClass("Error processing blocks");
02117 }
02118 return m_miRowPartition;
02119 }
02120
02121 int MatrixType::getColumnPartitionSize()
02122 {
02123 if (!m_bHaveColumnPartition)
02124 {
02125 bool OK = processBlockPartition();
02126 if (!OK) throw ErrorClass("Error processing blocks");
02127 }
02128 return m_iColumnPartitionSize;
02129 }
02130
02131 int* MatrixType::getColumnPartition()
02132 {
02133 if (!m_bHaveColumnPartition)
02134 {
02135 bool OK = processBlockPartition();
02136 if (!OK) throw ErrorClass("Error processing blocks");
02137 }
02138 return m_miColumnPartition;
02139 }
02140
02141
02142 bool MatrixType::processBlockPartition()
02143 {
02144 #ifndef NDEBUG
02145 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside processBlockPartition()");
02146 #endif
02147 if (matrixHasBlocks())
02148 {
02149 int nPartitions = 0;
02150 int imerge_R;
02151 int imerge_C;
02152
02153 for (int i=0; i < inumberOfChildren; i++)
02154 {
02155 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks)
02156 {
02157 if (nPartitions == 0)
02158 {
02159
02160 nPartitions++;
02161 m_iRowPartitionSize = ((MatrixBlocks*)m_mChildren[i])->rowOffset->numberOfEl;
02162 m_miRowPartition = new int[m_iRowPartitionSize];
02163 for (int j=0; j<m_iRowPartitionSize; j++)
02164 m_miRowPartition[j] = ((MatrixBlocks*)m_mChildren[i])->rowOffset->el[j];
02165 m_iColumnPartitionSize = ((MatrixBlocks*)m_mChildren[i])->colOffset->numberOfEl;
02166 m_miColumnPartition = new int[m_iColumnPartitionSize];
02167 for (int j=0; j<m_iColumnPartitionSize; j++)
02168 m_miColumnPartition[j] = ((MatrixBlocks*)m_mChildren[i])->colOffset->el[j];
02169 }
02170 else
02171 {
02172
02173 nPartitions++;
02174 int i0 = 0;
02175 int itemp = 0;
02176 imerge_R = 0;
02177 for (;;)
02178 {
02179 if (m_miRowPartition[i0] == ((MatrixBlocks*)m_mChildren[i])->rowOffset->el[itemp])
02180 {
02181 if (imerge_R != i0) m_miRowPartition[imerge_R] = m_miRowPartition[i0];
02182 i0++;
02183 itemp++;
02184 imerge_R++;
02185 }
02186 else
02187 {
02188 if (m_miRowPartition[i0] <
02189 ((MatrixBlocks*)m_mChildren[i])->rowOffset->el[itemp])
02190 i0++;
02191 else
02192 itemp++;
02193 }
02194 if (i0 >= m_iRowPartitionSize ||
02195 itemp >= ((MatrixBlocks*)m_mChildren[i])->rowOffset->numberOfEl)
02196 break;
02197 }
02198 m_iRowPartitionSize = imerge_R;
02199
02200
02201 i0 = 0;
02202 itemp = 0;
02203 imerge_C = 0;
02204 for (;;)
02205 {
02206 if (m_miColumnPartition[i0] ==
02207 ((MatrixBlocks*)m_mChildren[i])->colOffset->el[itemp])
02208 {
02209 if (imerge_C != i0) m_miColumnPartition[imerge_C] = m_miColumnPartition[i0];
02210 i0++;
02211 itemp++;
02212 imerge_C++;
02213 }
02214 else
02215 {
02216 if (m_miColumnPartition[i0] <
02217 ((MatrixBlocks*)m_mChildren[i])->colOffset->el[itemp])
02218 i0++;
02219 else
02220 itemp++;
02221 }
02222 if (i0 >= m_iColumnPartitionSize ||
02223 itemp >= ((MatrixBlocks*)m_mChildren[i])->colOffset->numberOfEl)
02224 break;
02225 }
02226 m_iColumnPartitionSize = imerge_C;
02227 }
02228 }
02229 }
02230 if (nPartitions > 1)
02231 {
02232 int* tempPartition = new int[imerge_R];
02233 for (int i=0; i < imerge_R; i++)
02234 tempPartition[i] = m_miRowPartition[i];
02235 delete [] m_miRowPartition;
02236 m_miRowPartition = tempPartition;
02237
02238 tempPartition = new int[imerge_C];
02239 for (int i=0; i < imerge_C; i++)
02240 tempPartition[i] = m_miColumnPartition[i];
02241 delete [] m_miColumnPartition;
02242 m_miColumnPartition = tempPartition;
02243 }
02244 }
02245 else
02246 {
02247 m_iRowPartitionSize = 2;
02248 m_miRowPartition = new int[2];
02249 m_miRowPartition[0] = 0;
02250 m_miRowPartition[1] = numberOfRows;
02251 m_iColumnPartitionSize = 2;
02252 m_miColumnPartition = new int[2];
02253 m_miColumnPartition[0] = 0;
02254 m_miColumnPartition[1] = numberOfColumns;
02255 }
02256 m_bHaveRowPartition = true;
02257 m_bHaveColumnPartition = true;
02258 return true;
02259 }
02260
02261 GeneralSparseMatrix* MatrixType::getMatrixBlockInColumnMajorForm(int columnIdx, int rowIdx)
02262 {
02263 #ifndef NDEBUG
02264 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside getMatrixBlockInColumnMajorForm()");
02265 #endif
02266 return NULL;
02267 }
02268
02269 ExpandedMatrixBlocks* MatrixType::getBlocks(int* rowPartition, int rowPartitionSize,
02270 int* colPartition, int colPartitionSize,
02271 bool rowMajor, bool appendToBlockArray)
02272 {
02273 #ifndef NDEBUG
02274 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside getBlocks()");
02275 #endif
02276
02277
02278 for (int kount = 0; kount < ExpandedMatrixByBlocks.size(); kount++)
02279 {
02280 if (rowPartitionSize != ExpandedMatrixByBlocks[kount]->rowOffsetSize ||
02281 colPartitionSize != ExpandedMatrixByBlocks[kount]->colOffsetSize ||
02282 rowMajor != ExpandedMatrixByBlocks[kount]->isRowMajor)
02283 continue;
02284
02285 for (int i=0; i < rowPartitionSize; i++)
02286 if (rowPartition[i] != ExpandedMatrixByBlocks[kount]->rowOffset[i])
02287 continue;
02288 for (int i=0; i < colPartitionSize; i++)
02289 if (colPartition[i] != ExpandedMatrixByBlocks[kount]->colOffset[i])
02290 continue;
02291
02292 return ExpandedMatrixByBlocks[kount];
02293 }
02294
02295
02296 if (!appendToBlockArray) return NULL;
02297
02298 if (!processBlocks(rowPartition, rowPartitionSize,
02299 colPartition, colPartitionSize, false, symmetry))
02300 return false;
02301 return ExpandedMatrixByBlocks.back();
02302 }
02303
02304 bool MatrixType::processBlocks(bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
02305 {
02306 int cSize = getColumnPartitionSize();
02307 int rSize = getRowPartitionSize();
02308 int* cPartition = getColumnPartition();
02309 int* rPartition = getRowPartition();
02310 return processBlocks(rPartition, rSize, cPartition, cSize, rowMajor, symmetry);
02311 }
02312
02313 bool MatrixType::processBlocks(int* rowOffset, int rowOffsetSize, int* colOffset,
02314 int colOffsetSize, bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
02315 {
02316 #ifndef NDEBUG
02317 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside processBlocks()");
02318 #endif
02319 try
02320 {
02321 ENUM_MATRIX_TYPE elType = getMatrixType();
02322
02323
02324 if (inumberOfChildren == 1)
02325 {
02326 if (m_mChildren[0]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks)
02327 {
02328 if (((MatrixBlocks*)m_mChildren[0])->rowOffset->numberOfEl != rowOffsetSize ||
02329 ((MatrixBlocks*)m_mChildren[0])->colOffset->numberOfEl != colOffsetSize)
02330 goto none_found;
02331
02332 for (int j=0; j < rowOffsetSize; j++)
02333 if (((MatrixBlocks*)m_mChildren[0])->rowOffset->el[j] != rowOffset[j])
02334 goto none_found;
02335
02336 for (int j=0; j < colOffsetSize; j++)
02337 if (((MatrixBlocks*)m_mChildren[0])->colOffset->el[j] != colOffset[j])
02338 goto none_found;
02339
02340
02341 ExpandedMatrixBlocks* tmpBlocks = new ExpandedMatrixBlocks();
02342
02343 tmpBlocks->bDeleteArrays = false;
02344 tmpBlocks->vType = elType;
02345 tmpBlocks->isRowMajor = rowMajor;
02346 tmpBlocks->rowOffsetSize = rowOffsetSize;
02347 tmpBlocks->colOffsetSize = colOffsetSize;
02348 tmpBlocks->rowOffset = rowOffset;
02349 tmpBlocks->colOffset = colOffset;
02350
02351
02352 MatrixBlock* tmpChild;
02353 int tmpBlockNumber = 0;
02354 int tmpBlockSize;
02355 for (int j=0; j<((MatrixBlocks*)m_mChildren[0])->inumberOfChildren; j++)
02356 {
02357 tmpChild = (MatrixBlock*)((MatrixBlocks*)m_mChildren[0])->m_mChildren[j];
02358 if (rowMajor)
02359 {
02360 tmpChild->getMatrixCoefficientsInRowMajor();
02361 if (tmpChild->ExpandedMatrixInRowMajorForm->valueSize > 0)
02362 tmpBlockNumber++;
02363 }
02364 else
02365 {
02366 tmpChild->getMatrixCoefficientsInColumnMajor();
02367 if (tmpChild->ExpandedMatrixInColumnMajorForm->valueSize > 0)
02368 tmpBlockNumber++;
02369 }
02370 }
02371
02372
02373 tmpBlocks->blockNumber = tmpBlockNumber;
02374 tmpBlocks->blocks = new GeneralSparseMatrix*[tmpBlockNumber];
02375 tmpBlocks->blockRows = new int[tmpBlockNumber];
02376 tmpBlocks->blockColumns = new int[tmpBlockNumber];
02377
02378
02379 tmpBlockNumber = 0;
02380 for (int j=0; j<((MatrixBlocks*)m_mChildren[0])->inumberOfChildren; j++)
02381 {
02382 tmpChild = (MatrixBlock*)((MatrixBlocks*)m_mChildren[0])->m_mChildren[j];
02383 if (rowMajor)
02384 {
02385 if (tmpChild->ExpandedMatrixInRowMajorForm->valueSize == 0)
02386 continue;
02387 tmpBlocks->blocks[tmpBlockNumber] = tmpChild->ExpandedMatrixInRowMajorForm;
02388 }
02389 else
02390 {
02391 if (tmpChild->ExpandedMatrixInColumnMajorForm->valueSize == 0)
02392 continue;
02393 tmpBlocks->blocks[tmpBlockNumber] = tmpChild->ExpandedMatrixInColumnMajorForm;
02394 }
02395 tmpBlocks->blockRows[tmpBlockNumber] = tmpChild->blockRowIdx;
02396 tmpBlocks->blockColumns[tmpBlockNumber] = tmpChild->blockColIdx;
02397
02398 #ifndef NDEBUG
02399 tmpChild->printExpandedMatrix(rowMajor);
02400 #endif
02401
02402 tmpBlockNumber++;
02403 }
02404 ExpandedMatrixByBlocks.push_back(tmpBlocks);
02405 return true;
02406 }
02407 }
02408
02409 none_found:
02410 if (inumberOfChildren == 0)
02411 {
02412
02413 ExpandedMatrixBlocks* tmpBlocks = new ExpandedMatrixBlocks();
02414
02415 tmpBlocks->bDeleteArrays = false;
02416 tmpBlocks->vType = elType;
02417 tmpBlocks->isRowMajor = rowMajor;
02418 tmpBlocks->rowOffsetSize = rowOffsetSize;
02419 tmpBlocks->colOffsetSize = colOffsetSize;
02420 tmpBlocks->rowOffset = rowOffset;
02421 tmpBlocks->colOffset = colOffset;
02422 tmpBlocks->blockNumber = 0;
02423 tmpBlocks->blocks = NULL;
02424 tmpBlocks->blockRows = NULL;
02425 tmpBlocks->blockColumns = NULL;
02426 ExpandedMatrixByBlocks.push_back(tmpBlocks);
02427 return true;
02428 }
02429
02430
02431 if ( (ExpandedMatrixInColumnMajorForm != NULL && !rowMajor) ||
02432 (ExpandedMatrixInRowMajorForm != NULL && rowMajor) ||
02433 ExpandedMatrixByBlocks.size() == 0)
02434 {
02435 ExpandedMatrixByBlocks.push_back(disassembleMatrix(rowOffset, rowOffsetSize, colOffset,
02436 colOffsetSize, rowMajor, symmetry));
02437 return true;
02438 }
02439
02440
02441
02442
02443
02444 int refinement = -1;
02445 int coarsening = -1;
02446 bool refinementCandidate;
02447 bool coarseningCandidate;
02448 int k = 0;
02449
02450 for (int k = 0; k < ExpandedMatrixByBlocks.size(); k++)
02451 {
02452 refinementCandidate = true;
02453 int itarget = 0;
02454 int itest = 0;
02455 for (;;)
02456 {
02457 if (rowOffset[itarget] == ExpandedMatrixByBlocks[k]->rowOffset[itest])
02458 {
02459 itest++;
02460 itarget++;
02461 }
02462 else
02463 {
02464 if (rowOffset[itarget] < ExpandedMatrixByBlocks[k]->rowOffset[itest])
02465 {
02466 itarget++;
02467 }
02468 else
02469 {
02470 refinementCandidate = false;
02471 continue;
02472 }
02473 }
02474 if (itarget >= rowOffsetSize || itest >= ExpandedMatrixByBlocks[k]->rowOffsetSize)
02475 break;
02476 }
02477
02478 if (refinementCandidate)
02479 {
02480 itarget = 0;
02481 itest = 0;
02482 for (;;)
02483 {
02484 if (colOffset[itarget] == ExpandedMatrixByBlocks[k]->colOffset[itest])
02485 {
02486 itest++;
02487 itarget++;
02488 }
02489 else
02490 {
02491 if (colOffset[itarget] < ExpandedMatrixByBlocks[k]->colOffset[itest])
02492 {
02493 itarget++;
02494 }
02495 else
02496 {
02497 refinementCandidate = false;
02498 continue;
02499 }
02500 }
02501 if (itarget >= colOffsetSize || itest >= ExpandedMatrixByBlocks[k]->colOffsetSize)
02502 break;
02503 }
02504 }
02505
02506 if (refinementCandidate)
02507 {
02508 refinement = k;
02509 break;
02510 }
02511
02512 coarseningCandidate = false;
02513 itarget = 0;
02514 itest = 0;
02515 for (;;)
02516 {
02517 if (rowOffset[itarget] == ExpandedMatrixByBlocks[k]->rowOffset[itest])
02518 {
02519 itest++;
02520 itarget++;
02521 }
02522 else
02523 {
02524 if (rowOffset[itarget] < ExpandedMatrixByBlocks[k]->rowOffset[itest])
02525 {
02526 itarget++;
02527 continue;
02528 }
02529 else
02530 {
02531 coarseningCandidate = true;
02532 itest++;
02533 }
02534 }
02535 if (itarget >= rowOffsetSize || itest >= ExpandedMatrixByBlocks[k]->rowOffsetSize)
02536 break;
02537 }
02538
02539 itarget = 0;
02540 itest = 0;
02541 for (;;)
02542 {
02543 if (colOffset[itarget] == ExpandedMatrixByBlocks[k]->colOffset[itest])
02544 {
02545 itest++;
02546 itarget++;
02547 }
02548 else
02549 {
02550 if (colOffset[itarget] < ExpandedMatrixByBlocks[k]->colOffset[itest])
02551 {
02552 itarget++;
02553 continue;
02554 }
02555 else
02556 {
02557 coarseningCandidate = true;
02558 itest++;
02559 }
02560 }
02561 if (itarget >= colOffsetSize || itest >= ExpandedMatrixByBlocks[k]->colOffsetSize)
02562 break;
02563 }
02564
02565 if (coarseningCandidate)
02566 {
02567 refinement = k;
02568 }
02569 }
02570
02571 if (refinement >= 0)
02572 {
02573 throw ErrorClass ("Not yet implemented: obtaining one block partition from a different one");
02574 return false;
02575 }
02576
02577 if (coarsening >= 0)
02578 {
02579 throw ErrorClass ("Not yet implemented: obtaining one block partition from a different one");
02580 return false;
02581 }
02582
02583
02584 throw ErrorClass ("Not yet implemented: obtaining one block partition from a different one");
02585
02586
02587 return false;
02588 }
02589 catch(const ErrorClass& eclass)
02590 {
02591 throw ErrorClass( eclass.errormsg);
02592 }
02593 }
02594
02595 ExpandedMatrixBlocks* MatrixType::disassembleMatrix(int* rowPartition, int rowPartitionSize,
02596 int* colPartition, int colPartitionSize,
02597 bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
02598 {
02599
02600
02601
02602
02603
02604
02605
02606
02607
02608
02609
02610 #ifndef NDEBUG
02611 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside disassembleMatrix()");
02612 #endif
02613 int currBlockRow, currBlockCol, lastBlock, currRow;
02614 int blockCount, firstBlockInCol, blockTotal;
02615 std::vector<GeneralSparseMatrix*> tmpBlocks;
02616 int* tmpBlockRows;
02617 int* tmpBlockColumns;
02618 bool found;
02619 int i, j, k;
02620 int* elCount;
02621 ENUM_MATRIX_TYPE vType = getMatrixType();
02622
02623
02624 if (!rowMajor)
02625 {
02626 firstBlockInCol = -1;
02627 if (ExpandedMatrixInColumnMajorForm == NULL)
02628 getMatrixCoefficientsInColumnMajor();
02629
02630
02631 blockCount = 0;
02632 elCount = new int[rowPartitionSize-1];
02633
02634 for (i=0; i < colPartitionSize-1; i++)
02635 {
02636
02637 for (j=0; j<rowPartitionSize-1; j++)
02638 elCount[j] = 0;
02639 lastBlock = i;
02640 if (lastBlock >= rowPartitionSize)
02641 lastBlock = rowPartitionSize - 1;
02642
02643 for (j=colPartition[i]; j<colPartition[i+1]; j++)
02644 {
02645 for ( k = ExpandedMatrixInColumnMajorForm->start[j];
02646 k < ExpandedMatrixInColumnMajorForm->start[j+1];
02647 k++ )
02648 {
02649 currRow = ExpandedMatrixInColumnMajorForm->index[k];
02650 if (currRow < rowPartition[lastBlock] || currRow >= rowPartition[lastBlock+1])
02651 {
02652 found = false;
02653 int n = lastBlock + 1;
02654 while (!found && n < rowPartitionSize - 1)
02655 {
02656
02657 if (currRow >= rowPartition[n+1])
02658 n++;
02659 else
02660 {
02661 found = true;
02662 lastBlock = n;
02663 break;
02664 }
02665 }
02666 if (!found)
02667 n = lastBlock - 1;
02668 while (!found && n >= 0)
02669 {
02670
02671 if (currRow < rowPartition[n])
02672 n--;
02673 else
02674 {
02675 found = true;
02676 lastBlock = n;
02677 break;
02678 }
02679 }
02680 if (!found)
02681 throw ErrorClass("Invalid row information detected in disassembleMatrix()");
02682
02683 elCount[lastBlock]++;
02684 if (elCount[lastBlock] == 1)
02685 {
02686
02687 GeneralSparseMatrix* tmpBlock = new GeneralSparseMatrix();
02688 blockCount++;
02689 if (firstBlockInCol < 0)
02690 firstBlockInCol = blockCount - 1;
02691 tmpBlock->b_deleteStartArray = true;
02692 tmpBlock->b_deleteIndexArray = true;
02693 tmpBlock->b_deleteValueArray = true;
02694 tmpBlock->isRowMajor = false;
02695 tmpBlock->symmetry = symmetry;
02696 tmpBlock->vType = vType;
02697 tmpBlock->startSize = colPartition[i+1] - colPartition[i] + 1;
02698 tmpBlock->start = new int[tmpBlock->startSize];
02699
02700 for (int n=0; n <= j - colPartition[i]; n++)
02701 tmpBlock->start[n] = 0;
02702
02703 tmpBlocks.push_back(tmpBlock);
02704 if (firstBlockInCol < 0)
02705 firstBlockInCol = blockCount - 1;
02706 }
02707 }
02708 }
02709
02710
02711 for (k=firstBlockInCol; k < blockCount; k++)
02712 tmpBlocks[k]->start[j-colPartition[i] + 1] = elCount[k];
02713
02714 }
02715
02716
02717 for (k=firstBlockInCol; k < blockCount; k++)
02718 {
02719 tmpBlocks[k]->valueSize = elCount[k];
02720 tmpBlocks[k]->index = new int[elCount[k]];
02721 tmpBlocks[k]->value = new MatrixElementValues[elCount[k]];
02722 }
02723 tmpBlockRows = new int[blockCount];
02724 tmpBlockColumns = new int[blockCount];
02725 for (j=0; j<blockCount; j++)
02726 {
02727 tmpBlockRows[j] = -1;
02728 }
02729
02730 lastBlock = i;
02731
02732
02733 for (j=colPartition[i]; j<colPartition[i+1]; j++)
02734 {
02735 for ( k = ExpandedMatrixInColumnMajorForm->start[j];
02736 k < ExpandedMatrixInColumnMajorForm->start[j+1];
02737 k++ )
02738 {
02739 currRow = ExpandedMatrixInColumnMajorForm->index[k];
02740 if (currRow < rowPartition[lastBlock] || currRow >= rowPartition[lastBlock+1])
02741 {
02742 found = false;
02743 int n;
02744 while (!found)
02745 {
02746 for (n=lastBlock+1; n < rowPartitionSize - 1; n++)
02747 if (currRow >= rowPartition[lastBlock] &&
02748 currRow < rowPartition[lastBlock+1])
02749 {
02750 found = true;
02751 lastBlock = n;
02752 break;
02753 }
02754 }
02755 while (!found)
02756 {
02757 for (n=lastBlock-1; k >= 0; k--)
02758 if (currRow >= rowPartition[lastBlock] &&
02759 currRow < rowPartition[lastBlock+1])
02760 {
02761 found = true;
02762 lastBlock = n;
02763 break;
02764 }
02765 }
02766 }
02767 if (tmpBlockRows[lastBlock] == -1)
02768 {
02769 tmpBlockRows[lastBlock] = j;
02770 tmpBlockColumns[lastBlock] = i;
02771 }
02772 }
02773
02774 int k0 = 0;
02775 tmpBlocks[lastBlock]->index[k-k0]
02776 = ExpandedMatrixInColumnMajorForm->index[k] - rowPartition[j];
02777 tmpBlocks[lastBlock]->value[k-k0] = ExpandedMatrixInColumnMajorForm->value[k];
02778 }
02779 }
02780
02781 }
02782 else
02783 throw ErrorClass("Row major not yet implemented in MatrixType::disassembleMatrix()");
02784
02785 ExpandedMatrixBlocks* returnArray = new ExpandedMatrixBlocks();
02786 returnArray->bDeleteArrays = true;
02787 returnArray->vType = vType;
02788 returnArray->isRowMajor = rowMajor;
02789 returnArray->blockNumber = tmpBlocks.size();
02790 returnArray->rowOffset = rowPartition;
02791 returnArray->colOffset = colPartition;
02792 returnArray->rowOffsetSize = rowPartitionSize;
02793 returnArray->colOffsetSize = colPartitionSize;
02794 returnArray->blocks = new GeneralSparseMatrix*[tmpBlocks.size()];
02795
02796 for (int i=0; i<tmpBlocks.size();i++);
02797 {
02798 returnArray->blocks[i] = tmpBlocks[i];
02799 returnArray->blockRows[i] = tmpBlockRows[i];
02800 returnArray->blockColumns[i] = tmpBlockColumns[i];
02801 }
02802
02803 return returnArray;
02804 }
02805
02806
02807 GeneralSparseMatrix* MatrixType::extractBlock(int firstrow, int firstcol, int nrows, int ncols,
02808 bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
02809 {
02810 #ifndef NDEBUG
02811 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside extractBlock()");
02812 #endif
02813 bool mustCopy = false;
02814 int n = inumberOfChildren;
02815 if (n > 1)
02816 mustCopy = true;
02817 else
02818 {
02819
02820 }
02821 for (int i=0; i < n; i++)
02822 if (m_mChildren[i]->nType != ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks)
02823 {
02824
02825 break;
02826 }
02827 else
02828 {
02829
02830 }
02831
02832 return NULL;
02833 }
02834
02835
02836
02838 MatrixElements::MatrixElements():
02839 rowMajor(false),
02840 numberOfValues(-1),
02841 start(NULL),
02842 index(NULL)
02843 {
02844 #ifndef NDEBUG
02845 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixElements Constructor");
02846 #endif
02847 }
02848
02849 MatrixElements::~MatrixElements()
02850 {
02851 ostringstream outStr;
02852 #ifndef NDEBUG
02853 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixElements Destructor");
02854 #endif
02855 if (start != NULL)
02856 {
02857 #ifndef NDEBUG
02858 outStr.str("");
02859 outStr.clear();
02860 outStr << "deleting MatrixElements->start at " << &start << std::endl;
02861 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
02862 #endif
02863 delete start;
02864 start = NULL;
02865 }
02866
02867 if (index != NULL)
02868 {
02869 #ifndef NDEBUG
02870 outStr.str("");
02871 outStr.clear();
02872 outStr << "deleting MatrixElements->index at " << &index << std::endl;
02873 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
02874 #endif
02875 delete index;
02876 index = NULL;
02877 }
02878 }
02879
02880 bool MatrixElements::getRowMajor()
02881 {
02882 return rowMajor;
02883 }
02884
02885 #if 0
02886 bool MatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
02887 {
02888 return false;
02889 }
02890
02891 std::string MatrixElements::getNodeName()
02892 {
02893 return "";
02894 }
02895 #endif
02896
02897 bool MatrixElements::IsEqual(MatrixElements *that)
02898 {
02899 #ifndef NDEBUG
02900 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in MatrixElements");
02901 #endif
02902 if (this == NULL)
02903 {
02904 if (that == NULL)
02905 return true;
02906 else
02907 {
02908 #ifndef NDEBUG
02909 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
02910 "First object is NULL, second is not");
02911 #endif
02912 return false;
02913 }
02914 }
02915 else
02916 {
02917 if (that == NULL)
02918 {
02919 #ifndef NDEBUG
02920 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
02921 "Second object is NULL, first is not");
02922 #endif
02923 return false;
02924 }
02925 else
02926 {
02927 if (this->rowMajor != that->rowMajor) return false;
02928 if (this->numberOfValues != that->numberOfValues) return false;
02929
02930 if (!this->start->IsEqual(that->start))
02931 return false;
02932
02933 if (!this->index->IsEqual(that->index))
02934 return false;
02935
02936 return true;
02937 }
02938 }
02939 }
02940
02941
02942
02944 MatrixElementValues::MatrixElementValues():
02945 numberOfEl(0)
02946 {
02947 #ifndef NDEBUG
02948 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixElementValues Constructor");
02949 #endif
02950 }
02951
02952 MatrixElementValues::~MatrixElementValues()
02953 {
02954 #ifndef NDEBUG
02955 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixElementValues Destructor");
02956 #endif
02957 }
02958
02959 bool MatrixElementValues::deepCopyFrom(MatrixElementValues* that)
02960 {
02961 return true;
02962 }
02963
02964
02965
02966
02968 OSMatrix::OSMatrix():
02969 MatrixType(),
02970 idx(-1),
02971 name("")
02972 {
02973 #ifndef NDEBUG
02974 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrix Constructor");
02975 #endif
02976 nType = ENUM_MATRIX_CONSTRUCTOR_TYPE_matrix;
02977 }
02978
02979 OSMatrix::~OSMatrix()
02980 {
02981 #ifndef NDEBUG
02982 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrix Destructor");
02983 #endif
02984 }
02985
02986
02987 OSMatrix* OSMatrix::createConstructorTreeFromPrefix(std::vector<MatrixNode*> mtxConstructorVec)
02988 {
02989 std::vector<MatrixNode*> stackVec;
02990 int kount = mtxConstructorVec.size() - 1;
02991 while(kount >= 0)
02992 {
02993 int numkids = mtxConstructorVec[kount]->inumberOfChildren;
02994 if(numkids > 0)
02995 {
02996 for(int i = 0; i < numkids; i++)
02997 {
02998 mtxConstructorVec[kount]->m_mChildren[i] = stackVec.back();
02999 stackVec.pop_back();
03000 }
03001 }
03002 stackVec.push_back( mtxConstructorVec[kount]);
03003 kount--;
03004 }
03005 stackVec.clear();
03006 return (OSMatrix*)mtxConstructorVec[ 0];
03007 }
03008
03009
03010 ENUM_MATRIX_CONSTRUCTOR_TYPE OSMatrix::getNodeType()
03011 {
03012 return ENUM_MATRIX_CONSTRUCTOR_TYPE_matrix;
03013 }
03014
03015 std::string OSMatrix::getNodeName()
03016 {
03017 return "matrix";
03018 }
03019
03020 ENUM_MATRIX_TYPE OSMatrix::getMatrixType()
03021 {
03022 if (matrixType == ENUM_MATRIX_TYPE_unknown)
03023 {
03024 matrixType = ENUM_MATRIX_TYPE_empty;
03025 for (int i=0; i<inumberOfChildren; i++)
03026 matrixType = mergeMatrixType(matrixType, m_mChildren[i]->getMatrixType());
03027 }
03028 return matrixType;
03029 }
03030
03031 bool OSMatrix::expandElements(bool rowMajor)
03032 {
03033 #if 0
03034
03035 if (rowMajor)
03036 {
03037 if (ExpandedMatrixInRowMajorForm != NULL) return true;
03038 }
03039 else
03040 {
03041 if (ExpandedMatrixInColumnMajorForm != NULL) return true;
03042 }
03043
03044
03045
03046 if (inumberOfChildren == 0)
03047 {
03048 if (rowMajor)
03049 {
03050 ExpandedMatrixInRowMajorForm = new GeneralSparseMatrix();
03051 ExpandedMatrixInRowMajorForm->symmetry = symmetry;
03052 ExpandedMatrixInRowMajorForm->valueSize = 0;
03053 ExpandedMatrixInRowMajorForm->startSize = numberOfRows + 1;
03054 ExpandedMatrixInRowMajorForm->starts = new int[numberOfRows + 1];
03055 for (int i=0; i <= numberOfRows; i++)
03056 ExpandedMatrixInRowMajorForm->starts[i] = 0;
03057 return true;
03058 }
03059 else
03060 {
03061 ExpandedMatrixInColumnMajorForm = new GeneralSparseMatrix();
03062 ExpandedMatrixInColumnMajorForm->symmetry = symmetry;
03063 ExpandedMatrixInColumnMajorForm->valueSize = 0;
03064 ExpandedMatrixInColumnMajorForm->startSize = numberOfColumns + 1;
03065 ExpandedMatrixInColumnMajorForm->starts = new int[numberOfColumns + 1];
03066 for (int i=0; i <= numberOfColumns; i++)
03067 ExpandedMatrixInColumnMajorForm->starts[i] = 0;
03068 return true;
03069 }
03070 }
03071
03072 else if (inumberOfChildren == 1)
03073 {
03074 if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix)
03075 {
03076 int baseMtxIdx = ((BaseMatrix*)m_mChildren[0])->baseMatrixIdx;
03077 OSMatrix* basematrix =
03078 bool haveRowForm = (baseMtx->ExpandedMatrixInRowMajorForm != NULL);
03079 bool haveColumnForm = (baseMtx->ExpandedMatrixInColumnMajorForm != NULL);
03080
03081 m_mChildren[0]->expandElements(rowMajor);
03082 if (targetMatrixFirstRow == 0 && targetMatrixFirstCol == 0 &&
03083 baseMatrixStartRow == 0 && baseMatrixStartCol == 0 &&
03084 baseMatrixEndRow == numberOfRows - 1 &&
03085 baseMatrixEndCol == numberOfColumns - 1 &&
03086 scalarMultiplier == 1)
03087 {
03088 if (rowmajor)
03089 {
03090 ExpandedMatrixInRowMajorForm = new GeneralSparseMatrix();
03091 ExpandedMatrixInRowMajorForm = m_mChildren[0]->ExpandedMatrixInRowMajorForm;
03092 ExpandedMatrixInRowMajorForm->symmetry = symmetry;
03093 ExpandedMatrixInRowMajorForm->startSize = numberOfRows + 1;
03094 ExpandedMatrixInRowMajorForm->starts = new int[numberOfRows + 1];
03095 }
03096 else
03097 {
03098 ExpandedMatrixInColumnMajorForm = new GeneralSparseMatrix();
03099 ExpandedMatrixInColumnMajorForm = m_mChildren[0]->ExpandedMatrixInColumnMajorForm;
03100 ExpandedMatrixInColumnMajorForm->symmetry = symmetry;
03101 ExpandedMatrixInColumnMajorForm->startSize = numberOfColumns + 1;
03102 ExpandedMatrixInColumnMajorForm->starts = new int[numberOfColumns + 1];
03103 }
03104 }
03105 return true;
03106 }
03107
03108 else if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks)
03109 {
03110 ExpandedMatrixBlocks* currentBlocks =
03111 processBlocks(int* rowOffsets, int* colOffsets,
03112 bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry);
03113 ExpandedMatrixByBlocks.push_back(currentBlocks);
03114
03115 if (rowmajor)
03116 {
03117 ExpandedMatrixInRowMajorForm = new GeneralSparseMatrix*();
03118 ExpandedMatrixInRowMajorForm->startSize = numberOfRows + 1;
03119 ExpandedMatrixInRowMajorForm->starts = new int[numberOfRows + 1];
03120 for (int i=0; i <= numberOfRows; i++)
03121 ExpandedMatrixInRowMajorForm->starts[i] = 0;
03122 }
03123 else
03124 {
03125 ExpandedMatrixInColumnMajorForm = new GeneralSparseMatrix*();
03126 ExpandedMatrixInColumnMajorForm->startSize = numberOfColumns + 1;
03127 ExpandedMatrixInColumnMajorForm->starts = new int[numberOfColumns + 1];
03128 for (int i=0; i <= numberOfColumns; i++)
03129 ExpandedMatrixInColumnMajorForm->starts[i] = 0;
03130
03131 for (int j=0; j < currentBlocks->numberOfBlocks; j++)
03132 {
03133 }
03134
03135 }
03136 }
03137
03138 else if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_transformation)
03139 {
03140 }
03141 }
03142
03143 else
03144 {
03145 }
03146 #endif
03147
03148
03149
03150
03151
03152
03153
03154
03155
03156 return false;
03157 }
03158
03159 #if 0
03160 bool OSMatrix::processBlocks(int* rowOffsets, int* colOffsets,
03161 bool rowMajor, ENUM_MATRIX_SYMMETRY symmetry)
03162 {
03177 bool haveBlocks;
03178 bool haveTemp;
03179 bool mustSynchronize;
03180 int* temp;
03181 int tempSize;
03182 int iconst;
03183
03184
03185
03186
03187 if (inumberOfChildren == 0)
03188 {
03189 m_miRowPartition = new int[2];
03190 m_miColumnPartition = new int[2];
03191 m_iRowPartitionSize = 2;
03192 m_iColumnPartitionSize = 2;
03193 m_miRowPartition[0] = 0;
03194 m_miRowPartition[1] = numberOfRows;
03195 m_miColumnPartition[0] = 0;
03196 m_miColumnPartition[1] = numberOfColumns;
03197 m_bBlockPartitionProcessed = true;
03198 return true;
03199 }
03200
03201
03202 haveBlocks = false;
03203 haveTemp = false;
03204 mustSynchronize = false;
03205
03206 if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix)
03207 {
03208 tempSize = ((BaseMatrix*)m_mChildren[0])->baseMatrix->getRowPartitionSize();
03209 if (tempSize > 2)
03210 {
03211 m_miRowPartition = ((BaseMatrix*)m_mChildren[0])->baseMatrix->getRowPartition();
03212 m_iRowPartitionSize = tempSize;
03213 mustSynchronize = true;
03214 haveBlocks = true;
03215 }
03216 iconst = 1;
03217 }
03218 else
03219 iconst = 0;
03220
03221
03222 int jproc;
03223 int jcand;
03224 int nsync;
03225
03226 for (int i=iconst; i < inumberOfChildren; i++)
03227 {
03228 if (m_mChildren[i]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks)
03229 {
03230 if (((MatrixBlocks*)m_mChildren[i])->rowOffsets->el[0] != 0)
03231 return false;
03232
03233 if (haveBlocks == false)
03234 {
03235 m_miRowPartition = ((MatrixBlocks*)m_mChildren[i])->rowOffsets->el;
03236 m_iRowPartitionSize = ((MatrixBlocks*)m_mChildren[i])->rowOffsets->numberOfEl;
03237 mustSynchronize = true;
03238 haveBlocks = true;
03239 }
03240 else
03241 {
03242
03243 jproc = 0;
03244 jcand = 0;
03245 nsync = 0;
03246 for (;;)
03247 {
03248 if (m_miRowPartition[jproc] == ((MatrixBlocks*)m_mChildren[i])->rowOffsets->el[jcand])
03249 {
03250 if (haveTemp)
03251 temp[nsync] = m_miRowPartition[jproc];
03252 jproc++;
03253 jcand++;
03254 nsync++;
03255 }
03256 else
03257 {
03258 if (!haveTemp)
03259 {
03260 haveTemp = true;
03261 tempSize = min (((MatrixBlocks*)m_mChildren[i])->rowOffsets->numberOfEl,
03262 m_iRowPartitionSize);
03263 temp = new int[tempSize];
03264 for (int l=0; l < nsync; l++)
03265 temp[l] = m_miRowPartition[l];
03266 }
03267 if (m_miRowPartition[jproc] <
03268 ((MatrixBlocks*)m_mChildren[i])->rowOffsets->el[jcand])
03269 jproc++;
03270 else
03271 jcand++;
03272 }
03273 if (jproc >= m_iRowPartitionSize ||
03274 jcand >= ((MatrixBlocks*)m_mChildren[i])->rowOffsets->numberOfEl)
03275 break;
03276 }
03277 }
03278
03279 if (haveTemp && temp[nsync-1] < numberOfRows)
03280 {
03281 temp[nsync] = numberOfRows;
03282 nsync++;
03283 }
03284 }
03285
03286 if (haveTemp)
03287 {
03288 if (m_miRowPartition != NULL) delete m_miRowPartition;
03289 m_miRowPartition = new int[nsync];
03290 for (int l=0; l<nsync; l++)
03291 m_miRowPartition[l] = temp[l];
03292 delete [] temp;
03293 m_iRowPartitionSize = nsync;
03294 if (nsync == 2) break;
03295 }
03296 }
03297
03298 if (haveBlocks == false)
03299 {
03300 m_miRowPartition = new int[2];
03301 m_iRowPartitionSize = 2;
03302 m_miRowPartition[0] = 0;
03303 m_miRowPartition[1] = numberOfRows;
03304 }
03305
03306
03307 haveBlocks = false;
03308 haveTemp = false;
03309 mustSynchronize = false;
03310
03311 if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix)
03312 {
03313 tempSize = ((BaseMatrix*)m_mChildren[0])->baseMatrix->getColumnPartitionSize();
03314 if (tempSize > 2)
03315 {
03316 m_miColumnPartition = ((BaseMatrix*)m_mChildren[0])->baseMatrix->getColumnPartition();
03317 m_iColumnPartitionSize = tempSize;
03318 mustSynchronize = true;
03319 haveBlocks = true;
03320 }
03321 iconst = 1;
03322 }
03323 else
03324 iconst = 0;
03325
03326
03327 for (int i=iconst; i < inumberOfChildren; i++)
03328 {
03329 if (m_mChildren[i]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks)
03330 {
03331 if (((MatrixBlocks*)m_mChildren[i])->colOffsets->el[0] != 0)
03332 return false;
03333
03334 if (haveBlocks == false)
03335 {
03336 m_miColumnPartition = ((MatrixBlocks*)m_mChildren[i])->colOffsets->el;
03337 m_iColumnPartitionSize = ((MatrixBlocks*)m_mChildren[i])->colOffsets->numberOfEl;
03338 mustSynchronize = true;
03339 haveBlocks = true;
03340 }
03341 else
03342 {
03343
03344 jproc = 0;
03345 jcand = 0;
03346 nsync = 0;
03347 for (;;)
03348 {
03349 if (m_miColumnPartition[jproc] == ((MatrixBlocks*)m_mChildren[i])->colOffsets->el[jcand])
03350 {
03351 if (haveTemp)
03352 temp[nsync] = m_miColumnPartition[jproc];
03353 jproc++;
03354 jcand++;
03355 nsync++;
03356 }
03357 else
03358 {
03359 if (!haveTemp)
03360 {
03361 haveTemp = true;
03362 tempSize = min (((MatrixBlocks*)m_mChildren[i])->colOffsets->numberOfEl,
03363 m_iColumnPartitionSize);
03364 temp = new int[tempSize];
03365 for (int l=0; l < nsync; l++)
03366 temp[l] = m_miColumnPartition[l];
03367 }
03368 if (m_miColumnPartition[jproc] <
03369 ((MatrixBlocks*)m_mChildren[i])->colOffsets->el[jcand])
03370 jproc++;
03371 else
03372 jcand++;
03373 }
03374 if (jproc >= m_iColumnPartitionSize ||
03375 jcand >= ((MatrixBlocks*)m_mChildren[i])->colOffsets->numberOfEl)
03376 break;
03377 }
03378 }
03379
03380 if (haveTemp && temp[nsync-1] < numberOfColumns)
03381 {
03382 temp[nsync] = numberOfColumns;
03383 nsync++;
03384 }
03385 }
03386
03387 if (haveTemp)
03388 {
03389 if (m_miColumnPartition != NULL) delete m_miColumnPartition;
03390 m_miColumnPartition = new int[nsync];
03391 for (int l=0; l<nsync; l++)
03392 m_miColumnPartition[l] = temp[l];
03393 delete [] temp;
03394 m_iColumnPartitionSize = nsync;
03395 if (nsync == 2) break;
03396 }
03397 }
03398
03399 if (haveBlocks == false)
03400 {
03401 m_miColumnPartition = new int[2];
03402 m_iColumnPartitionSize = 2;
03403 m_miColumnPartition[0] = 0;
03404 m_miColumnPartition[1] = numberOfRows;
03405 }
03406
03407 return true;
03408 }
03409 #endif
03410
03411 bool OSMatrix::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
03412 {
03413 bool accumulator = true;
03414 for (int i=0; i < inumberOfChildren; i++)
03415 if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix)
03416 accumulator &= m_mChildren[i]->alignsOnBlockBoundary(firstRow, firstColumn, nRows, nCols);
03417 else if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks)
03418 accumulator &= m_mChildren[i]->alignsOnBlockBoundary(firstRow, firstColumn, nRows, nCols);
03419 else if (m_mChildren[i]->nType == ENUM_MATRIX_CONSTRUCTOR_TYPE_transformation)
03420 return false;
03421 else return false;
03422 return accumulator;
03423 }
03424
03425 #if 0
03426 bool OSMatrix::isBlockDiagonal()
03427 {
03428 bool isDiagonal;
03429 int haveBaseBlocks = false;
03430 int nBlocks;
03431 int iconst;
03432
03433
03434 if (inumberOfChildren == 0)
03435 return true;
03436
03437
03438 if (m_mChildren[0]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix)
03439 {
03440 int tempSize = ((BaseMatrix*)m_mChildren[0])->baseMatrix->getRowPartitionSize();
03441 if (tempSize > 2)
03442 {
03443 haveBaseBlocks = true;
03444 isDiagonal = ((BaseMatrix*)m_mChildren[0])->baseMatrix->isBlockDiagonal();
03445 if (!isDiagonal) return false;
03446 }
03447 else
03448 isDiagonal = true;
03449 iconst = 1;
03450 }
03451 else
03452 iconst = 0;
03453
03454
03455 int jproc;
03456 int jcand;
03457 int nsync;
03458 int* rowPartition = getRowPartition();
03459 int rowPartitionSize = getRowPartitionSize();
03460 int* colPartition = getColumnPartition();
03461 int colPartitionSize = getColumnPartitionSize();
03462
03463 for (int i=iconst; i < inumberOfChildren; i++)
03464 if (m_mChildren[i]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks)
03465 for (int j=0; j < ((MatrixBlocks*)m_mChildren[i])->numberOfBlocks; j++)
03466 if ( ((MatrixBlock*)((MatrixBlocks*)m_mChildren[i])->m_mChildren[j])->blockRowIdx !=
03467 ((MatrixBlock*)((MatrixBlocks*)m_mChildren[i])->m_mChildren[j])->blockColIdx)
03468 return false;
03469
03470
03471 if (iconst == 1 && !haveBaseBlocks) return false;
03472 for (int i=iconst; i < inumberOfChildren; i++)
03473 if (m_mChildren[i]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_elements)
03474 {
03475 if (((MatrixElements*)m_mChildren[i])->constantElements != NULL)
03476 {
03477 if (((MatrixElements*)m_mChildren[i])->constantElements->rowMajor)
03478 {
03479 for (int j=1; j < colPartitionSize; j++)
03480 for (int k = colPartition[j-1]; k < colPartition[j]; j++)
03481 for (int l = ((MatrixElements*)m_mChildren[i])->constantElements->start->el[k];
03482 l < ((MatrixElements*)m_mChildren[i])->constantElements->start->el[k+1];
03483 l++)
03484 if ( ((MatrixElements*)m_mChildren[i])->constantElements->indexes->el[l]
03485 < rowPartition[j-1] ||
03486 ((MatrixElements*)m_mChildren[i])->constantElements->indexes->el[l]
03487 >= rowPartition[j] )
03488 return false;
03489 }
03490 else
03491 {
03492 for (int j=1; j < rowPartitionSize; j++)
03493 for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
03494 for (int l = ((MatrixElements*)m_mChildren[i])->constantElements->start->el[k];
03495 l < ((MatrixElements*)m_mChildren[i])->constantElements->start->el[k+1];
03496 l++)
03497 if ( ((MatrixElements*)m_mChildren[i])->constantElements->indexes->el[l]
03498 < colPartition[j-1] ||
03499 ((MatrixElements*)m_mChildren[i])->constantElements->indexes->el[l]
03500 >= colPartition[j] )
03501 return false;
03502 }
03503 }
03504
03505
03506 if (((MatrixElements*)m_mChildren[i])->varReferenceElements != NULL)
03507 {
03508 if (((MatrixElements*)m_mChildren[i])->varReferenceElements->rowMajor)
03509 {
03510 for (int j=1; j < colPartitionSize; j++)
03511 for (int k = colPartition[j-1]; k < colPartition[j]; j++)
03512 for (int l = ((MatrixElements*)m_mChildren[i])->varReferenceElements->start->el[k];
03513 l < ((MatrixElements*)m_mChildren[i])->varReferenceElements->start->el[k+1];
03514 l++)
03515 if ( ((MatrixElements*)m_mChildren[i])->varReferenceElements->indexes->el[l]
03516 < rowPartition[j-1] ||
03517 ((MatrixElements*)m_mChildren[i])->varReferenceElements->indexes->el[l]
03518 >= rowPartition[j] )
03519 return false;
03520 }
03521 else
03522 {
03523 for (int j=1; j < rowPartitionSize; j++)
03524 for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
03525 for (int l = ((MatrixElements*)m_mChildren[i])->varReferenceElements->start->el[k];
03526 l < ((MatrixElements*)m_mChildren[i])->varReferenceElements->start->el[k+1];
03527 l++)
03528 if ( ((MatrixElements*)m_mChildren[i])->varReferenceElements->indexes->el[l]
03529 < colPartition[j-1] ||
03530 ((MatrixElements*)m_mChildren[i])->varReferenceElements->indexes->el[l]
03531 >= colPartition[j] )
03532 return false;
03533 }
03534 }
03535
03536
03537 if (((MatrixElements*)m_mChildren[i])->linearElements != NULL)
03538 {
03539 if (((MatrixElements*)m_mChildren[i])->linearElements->rowMajor)
03540 {
03541 for (int j=1; j < colPartitionSize; j++)
03542 for (int k = colPartition[j-1]; k < colPartition[j]; j++)
03543 for (int l = ((MatrixElements*)m_mChildren[i])->linearElements->start->el[k];
03544 l < ((MatrixElements*)m_mChildren[i])->linearElements->start->el[k+1];
03545 l++)
03546 if ( ((MatrixElements*)m_mChildren[i])->linearElements->indexes->el[l]
03547 < rowPartition[j-1] ||
03548 ((MatrixElements*)m_mChildren[i])->linearElements->indexes->el[l]
03549 >= rowPartition[j] )
03550 return false;
03551 }
03552 else
03553 {
03554 for (int j=1; j < rowPartitionSize; j++)
03555 for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
03556 for (int l = ((MatrixElements*)m_mChildren[i])->linearElements->start->el[k];
03557 l < ((MatrixElements*)m_mChildren[i])->linearElements->start->el[k+1];
03558 l++)
03559 if ( ((MatrixElements*)m_mChildren[i])->linearElements->indexes->el[l]
03560 < colPartition[j-1] ||
03561 ((MatrixElements*)m_mChildren[i])->linearElements->indexes->el[l]
03562 >= colPartition[j] )
03563 return false;
03564 }
03565 }
03566
03567
03568 if (((MatrixElements*)m_mChildren[i])->generalElements != NULL)
03569 {
03570 if (((MatrixElements*)m_mChildren[i])->generalElements->rowMajor)
03571 {
03572 for (int j=1; j < colPartitionSize; j++)
03573 for (int k = colPartition[j-1]; k < colPartition[j]; j++)
03574 for (int l = ((MatrixElements*)m_mChildren[i])->generalElements->start->el[k];
03575 l < ((MatrixElements*)m_mChildren[i])->generalElements->start->el[k+1];
03576 l++)
03577 if ( ((MatrixElements*)m_mChildren[i])->generalElements->indexes->el[l]
03578 < rowPartition[j-1] ||
03579 ((MatrixElements*)m_mChildren[i])->generalElements->indexes->el[l]
03580 >= rowPartition[j] )
03581 return false;
03582 }
03583 else
03584 {
03585 for (int j=1; j < rowPartitionSize; j++)
03586 for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
03587 for (int l = ((MatrixElements*)m_mChildren[i])->generalElements->start->el[k];
03588 l < ((MatrixElements*)m_mChildren[i])->generalElements->start->el[k+1];
03589 l++)
03590 if ( ((MatrixElements*)m_mChildren[i])->generalElements->indexes->el[l]
03591 < colPartition[j-1] ||
03592 ((MatrixElements*)m_mChildren[i])->generalElements->indexes->el[l]
03593 >= colPartition[j] )
03594 return false;
03595 }
03596 }
03597
03598
03599 if (((MatrixElements*)m_mChildren[i])->objReferenceElements != NULL)
03600 {
03601 if (((MatrixElements*)m_mChildren[i])->objReferenceElements->rowMajor)
03602 {
03603 for (int j=1; j < colPartitionSize; j++)
03604 for (int k = colPartition[j-1]; k < colPartition[j]; j++)
03605 for (int l = ((MatrixElements*)m_mChildren[i])->objReferenceElements->start->el[k];
03606 l < ((MatrixElements*)m_mChildren[i])->objReferenceElements->start->el[k+1];
03607 l++)
03608 if ( ((MatrixElements*)m_mChildren[i])->objReferenceElements->indexes->el[l]
03609 < rowPartition[j-1] ||
03610 ((MatrixElements*)m_mChildren[i])->objReferenceElements->indexes->el[l]
03611 >= rowPartition[j] )
03612 return false;
03613 }
03614 else
03615 {
03616 for (int j=1; j < rowPartitionSize; j++)
03617 for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
03618 for (int l = ((MatrixElements*)m_mChildren[i])->objReferenceElements->start->el[k];
03619 l < ((MatrixElements*)m_mChildren[i])->objReferenceElements->start->el[k+1];
03620 l++)
03621 if ( ((MatrixElements*)m_mChildren[i])->objReferenceElements->indexes->el[l]
03622 < colPartition[j-1] ||
03623 ((MatrixElements*)m_mChildren[i])->objReferenceElements->indexes->el[l]
03624 >= colPartition[j] )
03625 return false;
03626 }
03627 }
03628
03629
03630 if (((MatrixElements*)m_mChildren[i])->conReferenceElements != NULL)
03631 {
03632 if (((MatrixElements*)m_mChildren[i])->conReferenceElements->rowMajor)
03633 {
03634 for (int j=1; j < colPartitionSize; j++)
03635 for (int k = colPartition[j-1]; k < colPartition[j]; j++)
03636 for (int l = ((MatrixElements*)m_mChildren[i])->conReferenceElements->start->el[k];
03637 l < ((MatrixElements*)m_mChildren[i])->conReferenceElements->start->el[k+1];
03638 l++)
03639 if ( ((MatrixElements*)m_mChildren[i])->conReferenceElements->indexes->el[l]
03640 < rowPartition[j-1] ||
03641 ((MatrixElements*)m_mChildren[i])->conReferenceElements->indexes->el[l]
03642 >= rowPartition[j] )
03643 return false;
03644 }
03645 else
03646 {
03647 for (int j=1; j < rowPartitionSize; j++)
03648 for (int k = rowPartition[j-1]; k < rowPartition[j]; j++)
03649 for (int l = ((MatrixElements*)m_mChildren[i])->conReferenceElements->start->el[k];
03650 l < ((MatrixElements*)m_mChildren[i])->conReferenceElements->start->el[k+1];
03651 l++)
03652 if ( ((MatrixElements*)m_mChildren[i])->conReferenceElements->indexes->el[l]
03653 < colPartition[j-1] ||
03654 ((MatrixElements*)m_mChildren[i])->conReferenceElements->indexes->el[l]
03655 >= colPartition[j] )
03656 return false;
03657 }
03658 }
03659 }
03660 else if (m_mChildren[i]->getNodeType() == ENUM_MATRIX_CONSTRUCTOR_TYPE_transformation)
03661 return false;
03662
03663 return true;
03664 }
03665 #endif
03666
03667
03668 bool OSMatrix::setMatrix(std::string name, int numberOfRows, int numberOfColumns,
03669 ENUM_MATRIX_SYMMETRY symmetry, ENUM_MATRIX_TYPE matrixType,
03670 unsigned int inumberOfChildren, MatrixNode **m_mChildren)
03671 {
03672 this->name = name;
03673 this->numberOfRows = numberOfRows;
03674 this->numberOfColumns = numberOfColumns;
03675 this->symmetry = symmetry;
03676 this->matrixType = matrixType;
03677 this->inumberOfChildren = inumberOfChildren;
03678 this->m_mChildren = m_mChildren;
03679 return true;
03680 }
03681
03682
03683 std::string OSMatrix::getMatrixNodeInXML()
03684 {
03685 ostringstream outStr;
03686 outStr << "<matrix";
03687 outStr << " numberOfRows=\"" << numberOfRows << "\"";
03688 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
03689 if (symmetry != ENUM_MATRIX_SYMMETRY_none)
03690 outStr << " symmetry=\"" << returnMatrixSymmetryString(symmetry) << "\"";
03691 if (name != "")
03692 outStr << " name=\"" << name << "\"";
03693 if (matrixType != ENUM_MATRIX_TYPE_unknown)
03694 outStr << " type=\"" << returnMatrixTypeString(matrixType) << "\"";
03695
03696 if (inumberOfChildren > 0)
03697 {
03698 outStr << ">" << std::endl;
03699 for (int i=0; i < inumberOfChildren; i++)
03700 outStr << m_mChildren[i]->getMatrixNodeInXML();
03701 outStr << "</matrix>" << std::endl;
03702 }
03703 else
03704 outStr << "/>" << std::endl;
03705 return outStr.str();
03706 }
03707
03708 OSMatrix* OSMatrix::cloneMatrixNode()
03709 {
03710 MatrixType *nodePtr;
03711 nodePtr = new OSMatrix();
03712 return (OSMatrix*)nodePtr;
03713 }
03714
03715 bool OSMatrix::IsEqual(OSMatrix *that)
03716 {
03717 #ifndef NDEBUG
03718 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in OSMatrix");
03719 #endif
03720 if (this == NULL)
03721 {
03722 if (that == NULL)
03723 return true;
03724 else
03725 {
03726 #ifndef NDEBUG
03727 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
03728 "First object is NULL, second is not");
03729 #endif
03730 return false;
03731 }
03732 }
03733 else
03734 {
03735 if (that == NULL)
03736 {
03737 #ifndef NDEBUG
03738 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
03739 "Second object is NULL, first is not");
03740 #endif
03741 return false;
03742 }
03743 else
03744 {
03745 if (this->idx != this->idx) return false;
03746 if (this->name != this->name) return false;
03747 if (!this->MatrixNode::IsEqual(that)) return false;
03748
03749 return true;
03750 }
03751 }
03752 }
03753
03754
03755
03757 OSMatrixWithMatrixVarIdx::OSMatrixWithMatrixVarIdx():
03758 OSMatrix(),
03759 matrixVarIdx(-1)
03760 {
03761 #ifndef NDEBUG
03762 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixVarIdx Constructor");
03763 #endif
03764 }
03765
03766 OSMatrixWithMatrixVarIdx::~OSMatrixWithMatrixVarIdx()
03767 {
03768 #ifndef NDEBUG
03769 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixVarIdx Destructor");
03770 #endif
03771 }
03772
03773
03774 std::string OSMatrixWithMatrixVarIdx::getMatrixNodeInXML()
03775 {
03776 ostringstream outStr;
03777 outStr << "<matrixVar";
03778 outStr << " numberOfRows=\"" << numberOfRows << "\"";
03779 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
03780 outStr << " matrixVarIdx=\"" << matrixVarIdx << "\"";
03781 if (symmetry != ENUM_MATRIX_SYMMETRY_none)
03782 outStr << " symmetry=\"" << returnMatrixSymmetryString(symmetry) << "\"";
03783 if (name != "")
03784 outStr << " name=\"" << name << "\"";
03785 if (matrixType != ENUM_MATRIX_TYPE_unknown)
03786 outStr << " type=\"" << returnMatrixTypeString(matrixType) << "\"";
03787
03788 if (inumberOfChildren > 0)
03789 {
03790 outStr << ">" << std::endl;
03791 for (int i=0; i < inumberOfChildren; i++)
03792 outStr << m_mChildren[i]->getMatrixNodeInXML();
03793 outStr << "</matrixVar>" << std::endl;
03794 }
03795 else
03796 outStr << "/>" << std::endl;
03797 return outStr.str();
03798 }
03799
03800 OSMatrixWithMatrixVarIdx* OSMatrixWithMatrixVarIdx::cloneMatrixNode()
03801 {
03802 MatrixType *nodePtr;
03803 nodePtr = new OSMatrixWithMatrixVarIdx();
03804 return (OSMatrixWithMatrixVarIdx*)nodePtr;
03805 }
03806
03808 OSMatrixWithMatrixObjIdx::OSMatrixWithMatrixObjIdx():
03809 OSMatrix(),
03810 matrixObjIdx(-1)
03811 {
03812 #ifndef NDEBUG
03813 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixObjIdx Constructor");
03814 #endif
03815 }
03816
03817 OSMatrixWithMatrixObjIdx::~OSMatrixWithMatrixObjIdx()
03818 {
03819 #ifndef NDEBUG
03820 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixObjIdx Destructor");
03821 #endif
03822 }
03823
03824
03825 std::string OSMatrixWithMatrixObjIdx::getMatrixNodeInXML()
03826 {
03827 ostringstream outStr;
03828 outStr << "<matrixObj";
03829 outStr << " numberOfRows=\"" << numberOfRows << "\"";
03830 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
03831 outStr << " matrixObjIdx=\"" << matrixObjIdx << "\"";
03832 if (symmetry != ENUM_MATRIX_SYMMETRY_none)
03833 outStr << " symmetry=\"" << returnMatrixSymmetryString(symmetry) << "\"";
03834 if (name != "")
03835 outStr << " name=\"" << name << "\"";
03836 if (matrixType != ENUM_MATRIX_TYPE_unknown)
03837 outStr << " type=\"" << returnMatrixTypeString(matrixType) << "\"";
03838
03839 if (inumberOfChildren > 0)
03840 {
03841 outStr << ">" << std::endl;
03842 for (int i=0; i < inumberOfChildren; i++)
03843 outStr << m_mChildren[i]->getMatrixNodeInXML();
03844 outStr << "</matrixObj>" << std::endl;
03845 }
03846 else
03847 outStr << "/>" << std::endl;
03848 return outStr.str();
03849 }
03850
03851 OSMatrixWithMatrixObjIdx* OSMatrixWithMatrixObjIdx::cloneMatrixNode()
03852 {
03853 MatrixType *nodePtr;
03854 nodePtr = new OSMatrixWithMatrixObjIdx();
03855 return (OSMatrixWithMatrixObjIdx*)nodePtr;
03856 }
03857
03859 OSMatrixWithMatrixConIdx::OSMatrixWithMatrixConIdx():
03860 OSMatrix(),
03861 matrixConIdx(-1)
03862 {
03863 #ifndef NDEBUG
03864 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixConIdx Constructor");
03865 #endif
03866 }
03867
03868 OSMatrixWithMatrixConIdx::~OSMatrixWithMatrixConIdx()
03869 {
03870 #ifndef NDEBUG
03871 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the OSMatrixWithMatrixConIdx Destructor");
03872 #endif
03873 }
03874
03875 std::string OSMatrixWithMatrixConIdx::getMatrixNodeInXML()
03876 {
03877 ostringstream outStr;
03878 outStr << "<matrixCon";
03879 outStr << " numberOfRows=\"" << numberOfRows << "\"";
03880 outStr << " numberOfColumns=\"" << numberOfColumns << "\"";
03881 outStr << " matrixConIdx=\"" << matrixConIdx << "\"";
03882 if (symmetry != ENUM_MATRIX_SYMMETRY_none)
03883 outStr << " symmetry=\"" << returnMatrixSymmetryString(symmetry) << "\"";
03884 if (name != "")
03885 outStr << " name=\"" << name << "\"";
03886 if (matrixType != ENUM_MATRIX_TYPE_unknown)
03887 outStr << " type=\"" << returnMatrixTypeString(matrixType) << "\"";
03888
03889 if (inumberOfChildren > 0)
03890 {
03891 outStr << ">" << std::endl;
03892 for (int i=0; i < inumberOfChildren; i++)
03893 outStr << m_mChildren[i]->getMatrixNodeInXML();
03894 outStr << "</matrixCon>" << std::endl;
03895 }
03896 else
03897 outStr << "/>" << std::endl;
03898 return outStr.str();
03899 }
03900
03901 OSMatrixWithMatrixConIdx* OSMatrixWithMatrixConIdx::cloneMatrixNode()
03902 {
03903 MatrixType *nodePtr;
03904 nodePtr = new OSMatrixWithMatrixConIdx();
03905 return (OSMatrixWithMatrixConIdx*)nodePtr;
03906 }
03907
03909 BaseMatrix::BaseMatrix():
03910 baseMatrixIdx(-1),
03911 baseMatrix(NULL),
03912 targetMatrixFirstRow(0),
03913 targetMatrixFirstCol(0),
03914 baseMatrixStartRow(0),
03915 baseMatrixStartCol(0),
03916 baseMatrixEndRow(-1),
03917 baseMatrixEndCol(-1),
03918 baseTranspose(false),
03919 scalarMultiplier(1.0)
03920 {
03921 #ifndef NDEBUG
03922 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the BaseMatrix Constructor");
03923 #endif
03924 nType = ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix;
03925 }
03926
03927 BaseMatrix::~BaseMatrix()
03928 {
03929 #ifndef NDEBUG
03930 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the BaseMatrix Destructor");
03931 #endif
03932 }
03933
03934 ENUM_MATRIX_CONSTRUCTOR_TYPE BaseMatrix::getNodeType()
03935 {
03936 return ENUM_MATRIX_CONSTRUCTOR_TYPE_baseMatrix;
03937 }
03938
03939 std::string BaseMatrix::getNodeName()
03940 {
03941 return "baseMatrix";
03942 }
03943
03944 ENUM_MATRIX_TYPE BaseMatrix::getMatrixType()
03945 {
03946 return ((OSMatrix*)baseMatrix)->getMatrixType();
03947 }
03948
03949 std::string BaseMatrix::getMatrixNodeInXML()
03950 {
03951 ostringstream outStr;
03952 outStr << "<baseMatrix";
03953 outStr << " baseMatrixIdx=\"" << baseMatrixIdx << "\"";
03954 if (baseMatrixStartRow != 0)
03955 outStr << " baseMatrixStartRow=\"" << baseMatrixStartRow << "\"";
03956 if (baseMatrixStartCol != 0)
03957 outStr << " baseMatrixStartCol=\"" << baseMatrixStartCol << "\"";
03958 if (baseMatrixEndRow >= 0)
03959 outStr << " baseMatrixEndRow=\"" << baseMatrixEndRow << "\"";
03960 if (baseMatrixEndCol >= 0)
03961 outStr << " baseMatrixEndCol=\"" << baseMatrixEndCol << "\"";
03962 if (baseTranspose)
03963 outStr << " baseTranspose=\"true\"";
03964 if (scalarMultiplier != 1)
03965 outStr << " scalarMultiplier=\"" << scalarMultiplier << "\"";
03966 if (targetMatrixFirstRow != 0)
03967 outStr << " targetMatrixFirstRow=\"" << targetMatrixFirstRow << "\"";
03968 if (targetMatrixFirstCol != 0)
03969 outStr << " targetMatrixFirstCol=\"" << targetMatrixFirstCol << "\"";
03970 outStr << "/>" << std::endl;
03971 return outStr.str();
03972 }
03973
03974 bool BaseMatrix::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
03975 {
03976 return ((OSMatrix*)baseMatrix)->alignsOnBlockBoundary(firstRow, firstColumn, nRows, nCols);
03977 }
03978
03979 BaseMatrix* BaseMatrix::cloneMatrixNode()
03980 {
03981 MatrixNode *nodePtr;
03982 nodePtr = new BaseMatrix();
03983 return (BaseMatrix*)nodePtr;
03984 }
03985
03986 bool BaseMatrix::IsEqual(BaseMatrix *that)
03987 {
03988 #ifndef NDEBUG
03989 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in BaseMatrix");
03990 #endif
03991 if (this == NULL)
03992 {
03993 if (that == NULL)
03994 return true;
03995 else
03996 {
03997 #ifndef NDEBUG
03998 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
03999 "First object is NULL, second is not");
04000 #endif
04001 return false;
04002 }
04003 }
04004 else
04005 {
04006 if (that == NULL)
04007 {
04008 #ifndef NDEBUG
04009 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04010 "Second object is NULL, first is not");
04011 #endif
04012 return false;
04013 }
04014 else
04015 {
04016 if (this->baseMatrixIdx != that->baseMatrixIdx) return false;
04017 if (this->targetMatrixFirstRow != that->targetMatrixFirstRow) return false;
04018 if (this->targetMatrixFirstCol != that->targetMatrixFirstCol) return false;
04019 if (this->baseMatrixStartRow != that->baseMatrixStartRow) return false;
04020 if (this->baseMatrixStartCol != that->baseMatrixStartCol) return false;
04021 if (this->baseMatrixEndRow != that->baseMatrixEndRow) return false;
04022 if (this->baseMatrixEndCol != that->baseMatrixEndCol) return false;
04023 if (this->baseTranspose != that->baseTranspose) return false;
04024 if (this->scalarMultiplier != that->scalarMultiplier) return false;
04025
04026 return true;
04027 }
04028 }
04029 }
04030
04031
04032
04034 MatrixTransformation::MatrixTransformation():
04035 shape(ENUM_NL_EXPR_SHAPE_general),
04036 transformation(NULL)
04037 {
04038 #ifndef NDEBUG
04039 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixTransformation Constructor");
04040 #endif
04041 nType = ENUM_MATRIX_CONSTRUCTOR_TYPE_transformation;
04042 }
04043
04044 MatrixTransformation::~MatrixTransformation()
04045 {
04046 #ifndef NDEBUG
04047 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixTransformation Destructor");
04048 #endif
04049 if (transformation != NULL)
04050 delete transformation;
04051 transformation = NULL;
04052 }
04053
04054 ENUM_MATRIX_CONSTRUCTOR_TYPE MatrixTransformation::getNodeType()
04055 {
04056 return ENUM_MATRIX_CONSTRUCTOR_TYPE_transformation;
04057 }
04058
04059 std::string MatrixTransformation::getNodeName()
04060 {
04061 return "transformation";
04062 }
04063
04064 ENUM_MATRIX_TYPE MatrixTransformation::getMatrixType()
04065 {
04066 if (matrixType == ENUM_MATRIX_TYPE_unknown)
04067 matrixType = ENUM_MATRIX_TYPE_general;
04068 return matrixType;
04069 }
04070
04071 std::string MatrixTransformation::getMatrixNodeInXML()
04072 {
04073 ostringstream outStr;
04074 outStr << "<transformation";
04075 if (shape != ENUM_NL_EXPR_SHAPE_general)
04076 outStr << " shape=\"" << returnExprShapeString(shape) << "\"";
04077 outStr << ">" << std::endl;
04078
04079 outStr << transformation->getNonlinearExpressionInXML() << std::endl;
04080
04081 outStr << "</transformation>" << std::endl;
04082 return outStr.str();
04083 }
04084
04085 bool MatrixTransformation::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
04086 {
04087 return false;
04088 }
04089
04090 MatrixTransformation* MatrixTransformation::cloneMatrixNode()
04091 {
04092 MatrixTransformation *nodePtr;
04093 nodePtr = new MatrixTransformation();
04094 return (MatrixTransformation*)nodePtr;
04095 }
04096
04097 bool MatrixTransformation::IsEqual(MatrixTransformation *that)
04098 {
04099 #ifndef NDEBUG
04100 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixTransformation");
04101 #endif
04102 if (this == NULL)
04103 {
04104 if (that == NULL)
04105 return true;
04106 else
04107 {
04108 #ifndef NDEBUG
04109 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
04110 "First object is NULL, second is not");
04111 #endif
04112 return false;
04113 }
04114 }
04115 else
04116 {
04117 if (that == NULL)
04118 {
04119 #ifndef NDEBUG
04120 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
04121 "Second object is NULL, first is not");
04122 #endif
04123 return false;
04124 }
04125 else
04126 {
04127 if (!this->transformation->IsEqual(that->transformation))
04128 return false;
04129
04130 return true;
04131 }
04132 }
04133 }
04134
04135
04136
04138 ConstantMatrixElements::ConstantMatrixElements():
04139 value(NULL)
04140 {
04141 #ifndef NDEBUG
04142 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConstantMatrixElements Constructor");
04143 #endif
04144 }
04145
04146 ConstantMatrixElements::~ConstantMatrixElements()
04147 {
04148 #ifndef NDEBUG
04149 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
04150 "Inside the ConstantMatrixElements Destructor");
04151
04152 ostringstream outStr;
04153 outStr.str("");
04154 outStr.clear();
04155 outStr << "deleting ConstantMatrixElements->value at " << &value << std::endl;
04156 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
04157 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
04158 #endif
04159 if (value != NULL)
04160 delete value;
04161 value = NULL;
04162 }
04163
04164 ENUM_MATRIX_CONSTRUCTOR_TYPE ConstantMatrixElements::getNodeType()
04165 {
04166 return ENUM_MATRIX_CONSTRUCTOR_TYPE_constantElements;
04167 }
04168
04169 std::string ConstantMatrixElements::getNodeName()
04170 {
04171 return "constantElements";
04172 }
04173
04174 ENUM_MATRIX_TYPE ConstantMatrixElements::getMatrixType()
04175 {
04176 if (matrixType == ENUM_MATRIX_TYPE_unknown)
04177 matrixType = ENUM_MATRIX_TYPE_constant;
04178 return matrixType;
04179 }
04180
04181 std::string ConstantMatrixElements::getMatrixNodeInXML()
04182 {
04183 ostringstream outStr;
04184 outStr << "<constantElements";
04185 if (rowMajor)
04186 outStr << " rowMajor=\"true\"";
04187 outStr << " numberOfValues=\"" << numberOfValues << "\"";
04188 outStr << ">" << std::endl;
04189
04190 outStr << "<start>" << std::endl;
04191 outStr << writeIntVectorData(start, true, false);
04192 outStr << "</start>" << std::endl;
04193
04194 if (numberOfValues > 0)
04195 {
04196 outStr << "<index>" << std::endl;
04197 outStr << writeIntVectorData(index, true, false);
04198 outStr << "</index>" << std::endl;
04199
04200 outStr << "<value>" << std::endl;
04201
04202 for(int i = 0; i < numberOfValues;)
04203 {
04204 int mult = getMult(&(value->el[i]), numberOfValues - i);
04205 if (mult == 1)
04206 outStr << "<el>" ;
04207 else
04208 outStr << "<el mult=\"" << mult << "\">";
04209 outStr << os_dtoa_format(value->el[i]);
04210 outStr << "</el>" << std::endl;
04211 i += mult;
04212 }
04213 outStr << "</value>" << std::endl;
04214 }
04215
04216 outStr << "</constantElements>" << std::endl;
04217 return outStr.str();
04218 }
04219
04220 bool ConstantMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
04221 {
04222 return false;
04223 }
04224
04225 ConstantMatrixElements* ConstantMatrixElements::cloneMatrixNode()
04226 {
04227 ConstantMatrixElements *nodePtr;
04228 nodePtr = new ConstantMatrixElements();
04229 return (ConstantMatrixElements*)nodePtr;
04230 }
04231
04232 bool ConstantMatrixElements::IsEqual(ConstantMatrixElements *that)
04233 {
04234 #ifndef NDEBUG
04235 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in BaseMatrix");
04236 #endif
04237 if (this == NULL)
04238 {
04239 if (that == NULL)
04240 return true;
04241 else
04242 {
04243 #ifndef NDEBUG
04244 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04245 "First object is NULL, second is not");
04246 #endif
04247 return false;
04248 }
04249 }
04250 else
04251 {
04252 if (that == NULL)
04253 {
04254 #ifndef NDEBUG
04255 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04256 "Second object is NULL, first is not");
04257 #endif
04258 return false;
04259 }
04260 else
04261 {
04262 if (this->rowMajor != that->rowMajor) return false;
04263 if (this->numberOfValues != that->numberOfValues) return false;
04264
04265 if (!this->start->IsEqual(that->start)) return false;
04266 if (!this->index->IsEqual(that->index)) return false;
04267 if (!this->value->IsEqual(that->value)) return false;
04268
04269 return true;
04270 }
04271 }
04272 }
04273
04274 bool ConstantMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
04275 {
04276 return true;
04277 }
04278
04279 bool ConstantMatrixElements::deepCopyFrom(ConstantMatrixElements *that)
04280 {
04281 return true;
04282 }
04283
04284
04286 ConstantMatrixValues::ConstantMatrixValues():
04287 el(NULL)
04288 {
04289 #ifndef NDEBUG
04290 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConstantMatrixValues Constructor");
04291 #endif
04292 }
04293
04294 ConstantMatrixValues::~ConstantMatrixValues()
04295 {
04296 #ifndef NDEBUG
04297 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConstantMatrixValues Destructor");
04298 ostringstream outStr;
04299 outStr.str("");
04300 outStr.clear();
04301 outStr << "deleting ConstantMatrixValues->el at " << &el << std::endl;
04302 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
04303 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
04304 #endif
04305 if (el != NULL)
04306 delete [] el;
04307 el = NULL;
04308 }
04309
04310 bool ConstantMatrixValues::IsEqual(ConstantMatrixValues *that)
04311 {
04312 #ifndef NDEBUG
04313 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ConstantMatrixValues");
04314 #endif
04315 if (this == NULL)
04316 {
04317 if (that == NULL)
04318 return true;
04319 else
04320 {
04321 #ifndef NDEBUG
04322 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04323 "First object is NULL, second is not");
04324 #endif
04325 return false;
04326 }
04327 }
04328 else
04329 {
04330 if (that == NULL)
04331 {
04332 #ifndef NDEBUG
04333 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04334 "Second object is NULL, first is not");
04335 #endif
04336 return false;
04337 }
04338 else
04339 {
04340 if (this->numberOfEl != that->numberOfEl) return false;
04341 for (int i=0; i < numberOfEl; i++)
04342 if (this->el[i] != that->el[i]) return false;
04343
04344 return true;
04345 }
04346 }
04347 }
04348
04349 bool ConstantMatrixValues::setRandom(double density, bool conformant, int iMin, int iMax)
04350 {
04351 return true;
04352 }
04353
04354 bool ConstantMatrixValues::deepCopyFrom(ConstantMatrixValues *that)
04355 {
04356 #ifndef NDEBUG
04357 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of ConstantMatrixValues");
04358 #endif
04359 this->numberOfEl = that->numberOfEl;
04360 this->el = new double[numberOfEl];
04361 for (int i=0; i<numberOfEl; i++)
04362 this->el[i] = that->el[i];
04363
04364 return true;
04365 }
04366
04367
04369 VarReferenceMatrixElements::VarReferenceMatrixElements():
04370 value(NULL)
04371 {
04372 #ifndef NDEBUG
04373 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the VarReferenceMatrixElements Constructor");
04374 #endif
04375 }
04376
04377 VarReferenceMatrixElements::~VarReferenceMatrixElements()
04378 {
04379 #ifndef NDEBUG
04380 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
04381 "Inside the VarReferenceMatrixElements Destructor");
04382
04383 ostringstream outStr;
04384 outStr.str("");
04385 outStr.clear();
04386 outStr << "deleting VarReferenceMatrixElements->value at " << &value << std::endl;
04387 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
04388 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
04389 #endif
04390 if (value != NULL)
04391 delete value;
04392 value = NULL;
04393 }
04394
04395 ENUM_MATRIX_CONSTRUCTOR_TYPE VarReferenceMatrixElements::getNodeType()
04396 {
04397 return ENUM_MATRIX_CONSTRUCTOR_TYPE_varRefElements;
04398 }
04399
04400 std::string VarReferenceMatrixElements::getNodeName()
04401 {
04402 return "varReferenceElements";
04403 }
04404
04405 ENUM_MATRIX_TYPE VarReferenceMatrixElements::getMatrixType()
04406 {
04407 if (matrixType == ENUM_MATRIX_TYPE_unknown)
04408 matrixType = ENUM_MATRIX_TYPE_varReference;
04409 return matrixType;
04410 }
04411
04412 std::string VarReferenceMatrixElements::getMatrixNodeInXML()
04413 {
04414 int mult, incr;
04415 ostringstream outStr;
04416 outStr << "<varReferenceElements";
04417 if (rowMajor)
04418 outStr << " rowMajor=\"true\"";
04419 outStr << " numberOfValues=\"" << numberOfValues << "\"";
04420 outStr << ">" << std::endl;
04421
04422 outStr << "<start>" << std::endl;
04423 outStr << writeIntVectorData(start, true, false);
04424 outStr << "</start>" << std::endl;
04425
04426 if (numberOfValues > 0)
04427 {
04428 outStr << "<index>" << std::endl;
04429 outStr << writeIntVectorData(index, true, false);
04430 outStr << "</index>" << std::endl;
04431
04432 outStr << "<value>" << std::endl;
04433
04434 for(int i = 0; i < numberOfValues;)
04435 {
04436 getMultIncr(&(value->el[i]), &mult, &incr, (value->numberOfEl) - i, 0);
04437 if (mult == 1)
04438 outStr << "<el>";
04439 else if (incr == 0)
04440 outStr << "<el mult=\"" << mult << "\">";
04441 else
04442 outStr << "<el mult=\"" << mult << "\" incr=\"" << incr << "\">";
04443 outStr << value->el[i];
04444 outStr << "</el>" << std::endl;
04445 i += mult;
04446 }
04447 outStr << "</value>" << std::endl;
04448 }
04449
04450 outStr << "</varReferenceElements>" << std::endl;
04451 return outStr.str();
04452 }
04453
04454 bool VarReferenceMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
04455 {
04456 return false;
04457 }
04458
04459 VarReferenceMatrixElements* VarReferenceMatrixElements::cloneMatrixNode()
04460 {
04461 VarReferenceMatrixElements *nodePtr;
04462 nodePtr = new VarReferenceMatrixElements();
04463 return (VarReferenceMatrixElements*)nodePtr;
04464 }
04465
04466 bool VarReferenceMatrixElements::IsEqual(VarReferenceMatrixElements *that)
04467 {
04468 #ifndef NDEBUG
04469 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in VarReferenceMatrixElements");
04470 #endif
04471 if (this == NULL)
04472 {
04473 if (that == NULL)
04474 return true;
04475 else
04476 {
04477 #ifndef NDEBUG
04478 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04479 "First object is NULL, second is not");
04480 #endif
04481 return false;
04482 }
04483 }
04484 else
04485 {
04486 if (that == NULL)
04487 {
04488 #ifndef NDEBUG
04489 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04490 "Second object is NULL, first is not");
04491 #endif
04492 return false;
04493 }
04494 else
04495 {
04496 if (this->rowMajor != that->rowMajor) return false;
04497 if (this->numberOfValues != that->numberOfValues) return false;
04498
04499 if (!this->start->IsEqual(that->start)) return false;
04500 if (!this->index->IsEqual(that->index)) return false;
04501 if (!this->value->IsEqual(that->value)) return false;
04502
04503 return true;
04504 }
04505 }
04506 }
04507
04508 bool VarReferenceMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
04509 {
04510 return true;
04511 }
04512
04513 bool VarReferenceMatrixElements::deepCopyFrom(VarReferenceMatrixElements *that)
04514 {
04515 return true;
04516 }
04517
04518
04520 VarReferenceMatrixValues::VarReferenceMatrixValues():
04521 el(NULL)
04522 {
04523 #ifndef NDEBUG
04524 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the VarReferenceMatrixValues Constructor");
04525 #endif
04526 }
04527
04528 VarReferenceMatrixValues::~VarReferenceMatrixValues()
04529 {
04530 #ifndef NDEBUG
04531 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
04532 "Inside the VarReferenceMatrixValues Destructor");
04533 ostringstream outStr;
04534 outStr.str("");
04535 outStr.clear();
04536 outStr << "deleting VarReferenceMatrixValues->el at " << &el << std::endl;
04537 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
04538 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
04539 #endif
04540 if (el != NULL)
04541 delete [] el;
04542 el = NULL;
04543 }
04544
04545 bool VarReferenceMatrixValues::IsEqual(VarReferenceMatrixValues *that)
04546 {
04547 #ifndef NDEBUG
04548 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in VarReferenceMatrixValues");
04549 #endif
04550 if (this == NULL)
04551 {
04552 if (that == NULL)
04553 return true;
04554 else
04555 {
04556 #ifndef NDEBUG
04557 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04558 "First object is NULL, second is not");
04559 #endif
04560 return false;
04561 }
04562 }
04563 else
04564 {
04565 if (that == NULL)
04566 {
04567 #ifndef NDEBUG
04568 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04569 "Second object is NULL, first is not");
04570 #endif
04571 return false;
04572 }
04573 else
04574 {
04575 if (this->numberOfEl != that->numberOfEl) return false;
04576 for (int i=0; i < numberOfEl; i++)
04577 if (this->el[i] != that->el[i]) return false;
04578
04579 return true;
04580 }
04581 }
04582 }
04583
04584 bool VarReferenceMatrixValues::setRandom(double density, bool conformant, int iMin, int iMax)
04585 {
04586 return true;
04587 }
04588
04589 bool VarReferenceMatrixValues::deepCopyFrom(VarReferenceMatrixValues *that)
04590 {
04591 #ifndef NDEBUG
04592 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of VarReferenceMatrixValues");
04593 #endif
04594 this->numberOfEl = that->numberOfEl;
04595 this->el = new int[numberOfEl];
04596 for (int i=0; i<numberOfEl; i++)
04597 this->el[i] = that->el[i];
04598
04599 return true;
04600 }
04601
04602
04604 LinearMatrixElements::LinearMatrixElements():
04605 value(NULL)
04606 {
04607 #ifndef NDEBUG
04608 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the LinearMatrixElements Constructor");
04609 #endif
04610 }
04611
04612 LinearMatrixElements::~LinearMatrixElements()
04613 {
04614 std::ostringstream outStr;
04615 #ifndef NDEBUG
04616 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
04617 "Inside the LinearMatrixElements Destructor");
04618
04619 outStr.str("");
04620 outStr.clear();
04621 outStr << "deleting LinearMatrixElements->value at " << &value << std::endl;
04622 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
04623 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
04624 #endif
04625 if (value != NULL)
04626 delete value;
04627 value = NULL;
04628 }
04629
04630 ENUM_MATRIX_CONSTRUCTOR_TYPE LinearMatrixElements::getNodeType()
04631 {
04632 return ENUM_MATRIX_CONSTRUCTOR_TYPE_linearElements;
04633 }
04634
04635 std::string LinearMatrixElements::getNodeName()
04636 {
04637 return "linearElements";
04638 }
04639
04640 ENUM_MATRIX_TYPE LinearMatrixElements::getMatrixType()
04641 {
04642 if (matrixType == ENUM_MATRIX_TYPE_unknown)
04643 matrixType = ENUM_MATRIX_TYPE_linear;
04644 return matrixType;
04645 }
04646
04647 std::string LinearMatrixElements::getMatrixNodeInXML()
04648 {
04649 ostringstream outStr;
04650 outStr << "<linearElements";
04651 if (rowMajor)
04652 outStr << " rowMajor=\"true\"";
04653 outStr << " numberOfValues=\"" << numberOfValues << "\"";
04654 outStr << ">" << std::endl;
04655
04656 outStr << "<start>" << std::endl;
04657 outStr << writeIntVectorData(start, true, false);
04658 outStr << "</start>" << std::endl;
04659
04660 if (numberOfValues > 0)
04661 {
04662 outStr << "<index>" << std::endl;
04663 outStr << writeIntVectorData(index, true, false);
04664 outStr << "</index>" << std::endl;
04665
04666 outStr << "<value>" << std::endl;
04667
04668 int i,j;
04669 for (i=0; i < numberOfValues; i++)
04670 {
04671 outStr << "<el";
04672 outStr << " numberOfVarIdx=\"" << value->el[i]->numberOfVarIdx << "\"";
04673 if (value->el[i]->constant != 0.0)
04674 outStr << " constant=\"" << value->el[i]->constant << "\"";
04675 outStr << ">" << std::endl;
04676
04677 for (j=0; j < value->el[i]->numberOfVarIdx; j++)
04678 {
04679 outStr << "<varIdx";
04680 if (value->el[i]->varIdx[j]->coef != 1.0)
04681 outStr << " coef=\"" << value->el[i]->varIdx[j]->coef << "\"";
04682 outStr << ">";
04683 outStr << value->el[i]->varIdx[j]->idx;
04684 outStr << "</varIdx>" << std::endl;
04685 }
04686
04687 outStr << "</el>" << std::endl;
04688 }
04689 outStr << "</value>" << std::endl;
04690 }
04691 outStr << "</linearElements>" << std::endl;
04692 return outStr.str();
04693 }
04694
04695 bool LinearMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
04696 {
04697 return false;
04698 }
04699
04700 LinearMatrixElements* LinearMatrixElements::cloneMatrixNode()
04701 {
04702 LinearMatrixElements *nodePtr;
04703 nodePtr = new LinearMatrixElements();
04704 return (LinearMatrixElements*)nodePtr;
04705 }
04706
04707 bool LinearMatrixElements::IsEqual(LinearMatrixElements *that)
04708 {
04709 #ifndef NDEBUG
04710 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in LinearMatrixElements");
04711 #endif
04712 if (this == NULL)
04713 {
04714 if (that == NULL)
04715 return true;
04716 else
04717 {
04718 #ifndef NDEBUG
04719 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04720 "First object is NULL, second is not");
04721 #endif
04722 return false;
04723 }
04724 }
04725 else
04726 {
04727 if (that == NULL)
04728 {
04729 #ifndef NDEBUG
04730 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04731 "Second object is NULL, first is not");
04732 #endif
04733 return false;
04734 }
04735 else
04736 {
04737 if (this->rowMajor != that->rowMajor) return false;
04738 if (this->numberOfValues != that->numberOfValues) return false;
04739
04740 if (!this->start->IsEqual(that->start)) return false;
04741 if (!this->index->IsEqual(that->index)) return false;
04742 if (!this->value->IsEqual(that->value)) return false;
04743
04744 return true;
04745 }
04746 }
04747 }
04748
04749 bool LinearMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
04750 {
04751 return true;
04752 }
04753
04754 bool LinearMatrixElements::deepCopyFrom(LinearMatrixElements *that)
04755 {
04756 return true;
04757 }
04758
04759
04761 LinearMatrixValues::LinearMatrixValues():
04762 el(NULL)
04763 {
04764 #ifndef NDEBUG
04765 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
04766 "Inside the LinearMatrixValues Constructor");
04767
04768 #endif
04769 }
04770
04771 LinearMatrixValues::~LinearMatrixValues()
04772 {
04773 std::ostringstream outStr;
04774 #ifndef NDEBUG
04775 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
04776 "Inside the LinearMatrixValues Destructor");
04777
04778 outStr.str("");
04779 outStr.clear();
04780 outStr << "deleting LinearMatrixValues->el at " << &el << std::endl;
04781 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
04782 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
04783 #endif
04784
04785 if (el != NULL)
04786 {
04787 for (int i=0; i < numberOfEl; i++)
04788 {
04789 if (el[i] != NULL)
04790 {
04791 #ifndef NDEBUG
04792 outStr.str("");
04793 outStr.clear();
04794 outStr << "deleting LinearMatrixValues->el [" << i << "] at " << &el[i] << std::endl;
04795 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
04796 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
04797 #endif
04798 delete el[i];
04799 el[i] = NULL;
04800 }
04801 }
04802 delete [] el;
04803 el = NULL;
04804 }
04805 }
04806
04807 bool LinearMatrixValues::IsEqual(LinearMatrixValues *that)
04808 {
04809 #ifndef NDEBUG
04810 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in LinearMatrixValues");
04811 #endif
04812 if (this == NULL)
04813 {
04814 if (that == NULL || that->numberOfEl == 0)
04815 return true;
04816 else
04817 {
04818 #ifndef NDEBUG
04819 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04820 "First object is NULL, second is not");
04821 #endif
04822 return false;
04823 }
04824 }
04825 else
04826 {
04827 if (that == NULL || that->numberOfEl == 0)
04828 {
04829 #ifndef NDEBUG
04830 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04831 "Second object is NULL, first is not");
04832 #endif
04833 return false;
04834 }
04835 else
04836 {
04837 if (this->numberOfEl != that->numberOfEl) return false;
04838
04839 for (int i=0; i < numberOfEl; i++)
04840 if (!this->el[i]->IsEqual(that->el[i])) return false;
04841
04842 return true;
04843 }
04844 }
04845 }
04846
04847 bool LinearMatrixValues::setRandom(double density, bool conformant, int iMin, int iMax)
04848 {
04849 return true;
04850 }
04851
04852 bool LinearMatrixValues::deepCopyFrom(LinearMatrixValues *that)
04853 {
04854 #ifndef NDEBUG
04855 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of LinearMatrixValues");
04856 #endif
04857 this->numberOfEl = that->numberOfEl;
04858 this->el = new LinearMatrixElement*[numberOfEl];
04859 for (int i=0; i<numberOfEl; i++)
04860 {
04861 this->el[i] = new LinearMatrixElement();
04862 ((LinearMatrixValues*)this)->el[i]->deepCopyFrom(that->el[i]);
04863 }
04864 return true;
04865 }
04866
04867
04869 LinearMatrixElement::LinearMatrixElement():
04870 numberOfVarIdx(0),
04871 constant(0.0),
04872 varIdx(NULL)
04873 {
04874 #ifndef NDEBUG
04875 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance,
04876 ENUM_OUTPUT_LEVEL_trace, "Inside the LinearMatrixElement Constructor");
04877 #endif
04878 }
04879
04880 LinearMatrixElement::~LinearMatrixElement()
04881 {
04882 std::ostringstream outStr;
04883 #ifndef NDEBUG
04884 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance,
04885 ENUM_OUTPUT_LEVEL_trace, "Inside the LinearMatrixElement Destructor");
04886 outStr.str("");
04887 outStr.clear();
04888 outStr << "NUMBER OF VARIDX = " << numberOfVarIdx << endl;
04889 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
04890 #endif
04891 if (varIdx != NULL)
04892 {
04893 for (int i=0; i < numberOfVarIdx; i++)
04894 {
04895 #ifndef NDEBUG
04896 outStr.str("");
04897 outStr.clear();
04898 outStr << "DESTROYING VARIDX " << i << " at " << &varIdx[i] << std::endl;
04899 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
04900 #endif
04901 if (varIdx[i] != NULL)
04902 delete varIdx[i];
04903 varIdx[i] = NULL;
04904 }
04905 delete [] varIdx;
04906 varIdx = NULL;
04907 }
04908 }
04909
04910 bool LinearMatrixElement::IsEqual(LinearMatrixElement *that)
04911 {
04912 #ifndef NDEBUG
04913 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in LinearMatrixElement");
04914 #endif
04915 if (this == NULL)
04916 {
04917 if (that == NULL || that->numberOfVarIdx == 0)
04918 return true;
04919 else
04920 {
04921 #ifndef NDEBUG
04922 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04923 "First object is NULL, second is not");
04924 #endif
04925 return false;
04926 }
04927 }
04928 else
04929 {
04930 if (that == NULL || that->numberOfVarIdx == 0)
04931 {
04932 #ifndef NDEBUG
04933 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
04934 "Second object is NULL, first is not");
04935 #endif
04936 return false;
04937 }
04938 else
04939 {
04940 if (this->numberOfVarIdx != that->numberOfVarIdx) return false;
04941 if (this->constant != that->constant) return false;
04942
04943 for (int i=0; i < numberOfVarIdx; i++)
04944 if (!this->varIdx[i]->IsEqual(that->varIdx[i])) return false;
04945
04946 return true;
04947 }
04948 }
04949 }
04950
04951 bool LinearMatrixElement::setRandom(double density, bool conformant, int iMin, int iMax)
04952 {
04953 return true;
04954 }
04955
04956 bool LinearMatrixElement::deepCopyFrom(LinearMatrixElement *that)
04957 {
04958 try
04959 {
04960 this->constant = that->constant;
04961 this->numberOfVarIdx = that->numberOfVarIdx;
04962 this->varIdx = new LinearMatrixElementTerm*[numberOfVarIdx];
04963 for (int i=0; i<numberOfVarIdx; i++)
04964 {
04965 this->varIdx[i] = new LinearMatrixElementTerm();
04966 ((LinearMatrixElement*)this)->varIdx[i]->deepCopyFrom(that->varIdx[i]);
04967 }
04968 return true;
04969 }
04970 catch(const ErrorClass& eclass)
04971 {
04972 throw ErrorClass( eclass.errormsg);
04973 }
04974 }
04975
04976
04978 LinearMatrixElementTerm::LinearMatrixElementTerm():
04979 idx(-1),
04980 coef(1.0)
04981 {
04982 #ifndef NDEBUG
04983 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the LinearMatrixElementTerm Constructor");
04984 #endif
04985 }
04986
04987 LinearMatrixElementTerm::~LinearMatrixElementTerm()
04988 {
04989 #ifndef NDEBUG
04990 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the LinearMatrixElementTerm Destructor");
04991 #endif
04992 }
04993
04994 bool LinearMatrixElementTerm::IsEqual(LinearMatrixElementTerm *that)
04995 {
04996 #ifndef NDEBUG
04997 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in LinearMatrixElementTerm");
04998 #endif
04999 if (this == NULL)
05000 {
05001 if (that == NULL)
05002 return true;
05003 else
05004 {
05005 #ifndef NDEBUG
05006 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05007 "First object is NULL, second is not");
05008 #endif
05009 return false;
05010 }
05011 }
05012 else
05013 {
05014 if (that == NULL)
05015 {
05016 #ifndef NDEBUG
05017 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05018 "Second object is NULL, first is not");
05019 #endif
05020 return false;
05021 }
05022 else
05023 {
05024 if (this->idx != that->idx) return false;
05025 if (this->coef != that->coef) return false;
05026
05027 return true;
05028 }
05029 }
05030 }
05031
05032 bool LinearMatrixElementTerm::setRandom(double density, bool conformant, int iMin, int iMax)
05033 {
05034 return true;
05035 }
05036
05037 bool LinearMatrixElementTerm::deepCopyFrom(LinearMatrixElementTerm *that)
05038 {
05039 this->coef = that->coef;
05040 this->idx = that->idx;
05041 return true;
05042 }
05043
05044
05046 GeneralMatrixElements::GeneralMatrixElements():
05047 value(NULL)
05048 {
05049 #ifndef NDEBUG
05050 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralMatrixElements Constructor");
05051 #endif
05052 }
05053
05054 GeneralMatrixElements::~GeneralMatrixElements()
05055 {
05056 #ifndef NDEBUG
05057 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance,
05058 ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralMatrixElements Destructor");
05059
05060 ostringstream outStr;
05061 outStr.str("");
05062 outStr.clear();
05063 outStr << "deleting GeneralMatrixElements->value at " << &value << std::endl;
05064 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
05065 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
05066 #endif
05067 if (value != NULL)
05068 delete value;
05069 value = NULL;
05070 }
05071
05072 ENUM_MATRIX_CONSTRUCTOR_TYPE GeneralMatrixElements::getNodeType()
05073 {
05074 return ENUM_MATRIX_CONSTRUCTOR_TYPE_generalElements;
05075 }
05076
05077 std::string GeneralMatrixElements::getNodeName()
05078 {
05079 return "generalElements";
05080 }
05081
05082 ENUM_MATRIX_TYPE GeneralMatrixElements::getMatrixType()
05083 {
05084 if (matrixType == ENUM_MATRIX_TYPE_unknown)
05085 matrixType = ENUM_MATRIX_TYPE_general;
05086 return matrixType;
05087 }
05088
05089 std::string GeneralMatrixElements::getMatrixNodeInXML()
05090 {
05091 ostringstream outStr;
05092 outStr << "<generalElements";
05093 if (rowMajor)
05094 outStr << " rowMajor=\"true\"";
05095 outStr << " numberOfValues=\"" << numberOfValues << "\"";
05096 outStr << ">" << std::endl;
05097
05098 outStr << "<start>" << std::endl;
05099 outStr << writeIntVectorData(start, true, false);
05100 outStr << "</start>" << std::endl;
05101
05102 if (numberOfValues > 0)
05103 {
05104 outStr << "<index>" << std::endl;
05105 outStr << writeIntVectorData(index, true, false);
05106 outStr << "</index>" << std::endl;
05107
05108 outStr << "<value>" << std::endl;
05109
05110 for (int i=0; i < numberOfValues; i++)
05111 {
05112 outStr << "<el>";
05113 outStr << value->el[i]->m_treeRoot->getNonlinearExpressionInXML();
05114 outStr << "</el>" << std::endl;
05115 }
05116 outStr << "</value>" << std::endl;
05117 }
05118 outStr << "</generalElements>" << std::endl;
05119 return outStr.str();
05120 }
05121
05122 bool GeneralMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
05123 {
05124 return false;
05125 }
05126
05127 GeneralMatrixElements* GeneralMatrixElements::cloneMatrixNode()
05128 {
05129 GeneralMatrixElements *nodePtr;
05130 nodePtr = new GeneralMatrixElements();
05131 return (GeneralMatrixElements*)nodePtr;
05132 }
05133
05134 bool GeneralMatrixElements::IsEqual(GeneralMatrixElements *that)
05135 {
05136 #ifndef NDEBUG
05137 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in GeneralMatrixElements");
05138 #endif
05139 if (this == NULL)
05140 {
05141 if (that == NULL)
05142 return true;
05143 else
05144 {
05145 #ifndef NDEBUG
05146 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05147 "First object is NULL, second is not");
05148 #endif
05149 return false;
05150 }
05151 }
05152 else
05153 {
05154 if (that == NULL)
05155 {
05156 #ifndef NDEBUG
05157 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05158 "Second object is NULL, first is not");
05159 #endif
05160 return false;
05161 }
05162 else
05163 {
05164 if (this->rowMajor != that->rowMajor) return false;
05165 if (this->numberOfValues != that->numberOfValues) return false;
05166
05167 if (!this->start->IsEqual(that->start)) return false;
05168 if (!this->index->IsEqual(that->index)) return false;
05169 if (!this->value->IsEqual(that->value)) return false;
05170
05171 return true;
05172 }
05173 }
05174 }
05175
05176 bool GeneralMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
05177 {
05178 return true;
05179 }
05180
05181 bool GeneralMatrixElements::deepCopyFrom(GeneralMatrixElements *that)
05182 {
05183 return true;
05184 }
05185
05186
05188 GeneralMatrixValues::GeneralMatrixValues():
05189 el(NULL)
05190 {
05191 #ifndef NDEBUG
05192 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralMatrixValues Constructor");
05193 #endif
05194 }
05195
05196 GeneralMatrixValues::~GeneralMatrixValues()
05197 {
05198 std::ostringstream outStr;
05199
05200 #ifndef NDEBUG
05201 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance,
05202 ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralMatrixValues Destructor");
05203 outStr.str("");
05204 outStr.clear();
05205 outStr << "NUMBER OF VALUES = " << numberOfEl << endl;
05206 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
05207 #endif
05208 if (numberOfEl > 0 && el != NULL)
05209 {
05210 for (int i=0; i < numberOfEl; i++)
05211 {
05212 if (el[i] != NULL)
05213 {
05214 #ifndef NDEBUG
05215 outStr.str("");
05216 outStr.clear();
05217 outStr << "deleting ConstantMatrixValues->el [" << i << "] at " << &el[i] << std::endl;
05218 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
05219 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
05220 #endif
05221 delete el[i];
05222 el[i] = NULL;
05223 }
05224 }
05225 }
05226 if (el != NULL)
05227 delete [] el;
05228 el = NULL;
05229 }
05230
05231 bool GeneralMatrixValues::IsEqual(GeneralMatrixValues *that)
05232 {
05233 #ifndef NDEBUG
05234 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
05235 ENUM_OUTPUT_LEVEL_trace, "Start comparing in GeneralMatrixValues");
05236 #endif
05237 if (this == NULL)
05238 {
05239 if (that == NULL || that->numberOfEl == 0)
05240 return true;
05241 else
05242 {
05243 #ifndef NDEBUG
05244 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05245 "First object is NULL, second is not");
05246 #endif
05247 return false;
05248 }
05249 }
05250 else
05251 {
05252 if (that == NULL || that->numberOfEl == 0)
05253 {
05254 #ifndef NDEBUG
05255 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05256 "Second object is NULL, first is not");
05257 #endif
05258 return false;
05259 }
05260 else
05261 {
05262 if (this->numberOfEl != that->numberOfEl) return false;
05263
05264 for (int i=0; i < numberOfEl; i++)
05265 if (!this->el[i]->IsEqual(that->el[i])) return false;
05266
05267 return true;
05268 }
05269 }
05270 }
05271
05272 bool GeneralMatrixValues::deepCopyFrom(GeneralMatrixValues *that)
05273 {
05274 #ifndef NDEBUG
05275 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of GeneralMatrixValues");
05276 #endif
05277 this->numberOfEl = that->numberOfEl;
05278 this->el = new ScalarExpressionTree*[numberOfEl];
05279 for (int i=0; i<numberOfEl; i++)
05280 {
05281 this->el[i] = new ScalarExpressionTree();
05282
05283 this->el[i]->m_treeRoot->copyNodeAndDescendants();
05284 }
05285 return true;
05286 }
05287
05289 ObjReferenceMatrixElements::ObjReferenceMatrixElements():
05290 value(NULL)
05291 {
05292 #ifndef NDEBUG
05293 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ObjReferenceMatrixElements Constructor");
05294 #endif
05295 }
05296
05297 ObjReferenceMatrixElements::~ObjReferenceMatrixElements()
05298 {
05299 #ifndef NDEBUG
05300 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance,
05301 ENUM_OUTPUT_LEVEL_trace, "Inside the ObjReferenceMatrixElements Destructor");
05302
05303 ostringstream outStr;
05304 outStr.str("");
05305 outStr.clear();
05306 outStr << "deleting ObjReferenceMatrixElements->value at " << &value << std::endl;
05307 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
05308 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
05309 #endif
05310 if (value != NULL)
05311 delete value;
05312 value = NULL;
05313 }
05314
05315 ENUM_MATRIX_CONSTRUCTOR_TYPE ObjReferenceMatrixElements::getNodeType()
05316 {
05317 return ENUM_MATRIX_CONSTRUCTOR_TYPE_objRefElements;
05318 }
05319
05320 std::string ObjReferenceMatrixElements::getNodeName()
05321 {
05322 return "objRefElements";
05323 }
05324
05325 ENUM_MATRIX_TYPE ObjReferenceMatrixElements::getMatrixType()
05326 {
05327 if (matrixType == ENUM_MATRIX_TYPE_unknown)
05328 matrixType = ENUM_MATRIX_TYPE_objReference;
05329 return matrixType;
05330 }
05331
05332 std::string ObjReferenceMatrixElements::getMatrixNodeInXML()
05333 {
05334 ostringstream outStr;
05335 outStr << "<objReferenceElements";
05336 if (rowMajor)
05337 outStr << " rowMajor=\"true\"";
05338 outStr << " numberOfValues=\"" << numberOfValues << "\"";
05339 outStr << ">" << std::endl;
05340
05341 outStr << "<start>" << std::endl;
05342 outStr << writeIntVectorData(start, true, false);
05343 outStr << "</start>" << std::endl;
05344
05345 int mult, incr;
05346 if (numberOfValues > 0)
05347 {
05348 outStr << "<index>" << std::endl;
05349 outStr << writeIntVectorData(index, true, false);
05350 outStr << "</index>" << std::endl;
05351
05352 outStr << "<value>" << std::endl;
05353
05354 for(int i = 0; i < numberOfValues;)
05355 {
05356 getMultIncr(&(value->el[i]), &mult, &incr, (value->numberOfEl) - i, 0);
05357 if (mult == 1)
05358 outStr << "<el>";
05359 else if (incr == 0)
05360 outStr << "<el mult=\"" << mult << "\">";
05361 else
05362 outStr << "<el mult=\"" << mult << "\" incr=\"" << incr << "\">";
05363 outStr << value->el[i];
05364 outStr << "</el>" << std::endl;
05365 i += mult;
05366 }
05367 outStr << "</value>" << std::endl;
05368 }
05369
05370 outStr << "</objReferenceElements>" << std::endl;
05371 return outStr.str();
05372 }
05373
05374 bool ObjReferenceMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
05375 {
05376 return false;
05377 }
05378
05379 ObjReferenceMatrixElements* ObjReferenceMatrixElements::cloneMatrixNode()
05380 {
05381 ObjReferenceMatrixElements *nodePtr;
05382 nodePtr = new ObjReferenceMatrixElements();
05383 return (ObjReferenceMatrixElements*)nodePtr;
05384 }
05385
05386 bool ObjReferenceMatrixElements::IsEqual(ObjReferenceMatrixElements *that)
05387 {
05388 #ifndef NDEBUG
05389 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ObjReferenceMatrixElements");
05390 #endif
05391 if (this == NULL)
05392 {
05393 if (that == NULL)
05394 return true;
05395 else
05396 {
05397 #ifndef NDEBUG
05398 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05399 "First object is NULL, second is not");
05400 #endif
05401 return false;
05402 }
05403 }
05404 else
05405 {
05406 if (that == NULL)
05407 {
05408 #ifndef NDEBUG
05409 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05410 "Second object is NULL, first is not");
05411 #endif
05412 return false;
05413 }
05414 else
05415 {
05416 if (this->rowMajor != that->rowMajor) return false;
05417 if (this->numberOfValues != that->numberOfValues) return false;
05418
05419 if (!this->start->IsEqual(that->start)) return false;
05420 if (!this->index->IsEqual(that->index)) return false;
05421 if (!this->value->IsEqual(that->value)) return false;
05422
05423 return true;
05424 }
05425 }
05426 }
05427
05428 bool ObjReferenceMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
05429 {
05430 return true;
05431 }
05432
05433 bool ObjReferenceMatrixElements::deepCopyFrom(ObjReferenceMatrixElements *that)
05434 {
05435 return true;
05436 }
05437
05438
05440 ObjReferenceMatrixValues::ObjReferenceMatrixValues():
05441 el(NULL)
05442 {
05443 #ifndef NDEBUG
05444 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ObjReferenceMatrixValues Constructor");
05445 #endif
05446 }
05447
05448 ObjReferenceMatrixValues::~ObjReferenceMatrixValues()
05449 {
05450 #ifndef NDEBUG
05451 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance,
05452 ENUM_OUTPUT_LEVEL_trace, "Inside the ObjReferenceMatrixValues Destructor");
05453
05454 ostringstream outStr;
05455 outStr.str("");
05456 outStr.clear();
05457 outStr << "deleting ObjReferenceMatrixValues->el at " << &el << std::endl;
05458 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
05459 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
05460 #endif
05461 if (el != NULL)
05462 delete [] el;
05463 el = NULL;
05464 }
05465
05466 bool ObjReferenceMatrixValues::IsEqual(ObjReferenceMatrixValues *that)
05467 {
05468 #ifndef NDEBUG
05469 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ObjReferenceMatrixValues");
05470 #endif
05471 if (this == NULL)
05472 {
05473 if (that == NULL)
05474 return true;
05475 else
05476 {
05477 #ifndef NDEBUG
05478 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05479 "First object is NULL, second is not");
05480 #endif
05481 return false;
05482 }
05483 }
05484 else
05485 {
05486 if (that == NULL)
05487 {
05488 #ifndef NDEBUG
05489 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05490 "Second object is NULL, first is not");
05491 #endif
05492 return false;
05493 }
05494 else
05495 {
05496 if (this->numberOfEl != that->numberOfEl) return false;
05497 for (int i=0; i < numberOfEl; i++)
05498 if (this->el[i] != that->el[i]) return false;
05499
05500 return true;
05501 }
05502 }
05503 }
05504
05505 bool ObjReferenceMatrixValues::setRandom(double density, bool conformant, int iMin, int iMax)
05506 {
05507 return true;
05508 }
05509
05510 bool ObjReferenceMatrixValues::deepCopyFrom(ObjReferenceMatrixValues *that)
05511 {
05512 #ifndef NDEBUG
05513 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of ObjReferenceMatrixValues");
05514 #endif
05515 this->numberOfEl = that->numberOfEl;
05516 this->el = new int[numberOfEl];
05517 for (int i=0; i<numberOfEl; i++)
05518 this->el[i] = that->el[i];
05519 return true;
05520 }
05521
05522
05524 ConReferenceMatrixElements::ConReferenceMatrixElements():
05525 value(NULL)
05526 {
05527 #ifndef NDEBUG
05528 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixElements Constructor");
05529 #endif
05530 }
05531
05532 ConReferenceMatrixElements::~ConReferenceMatrixElements()
05533 {
05534 #ifndef NDEBUG
05535 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance,
05536 ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixElements Destructor");
05537
05538 ostringstream outStr;
05539 outStr.str("");
05540 outStr.clear();
05541 outStr << "deleting ConReferenceMatrixElements->value at " << &value << std::endl;
05542 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
05543 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
05544 #endif
05545 if (value != NULL)
05546 delete value;
05547 value = NULL;
05548 }
05549
05550 ENUM_MATRIX_CONSTRUCTOR_TYPE ConReferenceMatrixElements::getNodeType()
05551 {
05552 return ENUM_MATRIX_CONSTRUCTOR_TYPE_conRefElements;
05553 }
05554
05555 std::string ConReferenceMatrixElements::getNodeName()
05556 {
05557 return "conRefElements";
05558 }
05559
05560 ENUM_MATRIX_TYPE ConReferenceMatrixElements::getMatrixType()
05561 {
05562 if (matrixType == ENUM_MATRIX_TYPE_unknown)
05563 matrixType = ENUM_MATRIX_TYPE_conReference;
05564 return matrixType;
05565 }
05566
05567 std::string ConReferenceMatrixElements::getMatrixNodeInXML()
05568 {
05569 ostringstream outStr;
05570 outStr << "<conReferenceElements";
05571 if (rowMajor)
05572 outStr << " rowMajor=\"true\"";
05573 outStr << " numberOfValues=\"" << numberOfValues << "\"";
05574 outStr << ">" << std::endl;
05575
05576 outStr << "<start>" << std::endl;
05577 outStr << writeIntVectorData(start, true, false);
05578 outStr << "</start>" << std::endl;
05579
05580 if (numberOfValues > 0)
05581 {
05582 outStr << "<index>" << std::endl;
05583 outStr << writeIntVectorData(index, true, false);
05584 outStr << "</index>" << std::endl;
05585
05586 outStr << "<value>" << std::endl;
05587
05588 for(int i = 0; i < numberOfValues; i++)
05589 {
05590 outStr << "<el";
05591 if (value->el[i]->valueType != ENUM_CONREFERENCE_VALUETYPE_value)
05592 {
05593 outStr << " valueType=\"";
05594 outStr << returnConReferenceValueTypeString(value->el[i]->valueType) << "\"";
05595 }
05596 outStr << ">";
05597 outStr << os_dtoa_format(value->el[i]->conReference);
05598 outStr << "</el>" << std::endl;
05599 }
05600 outStr << "</value>" << std::endl;
05601 }
05602
05603 outStr << "</conReferenceElements>" << std::endl;
05604 return outStr.str();
05605 }
05606
05607 bool ConReferenceMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
05608 {
05609 return false;
05610 }
05611
05612 ConReferenceMatrixElements* ConReferenceMatrixElements::cloneMatrixNode()
05613 {
05614 ConReferenceMatrixElements *nodePtr;
05615 nodePtr = new ConReferenceMatrixElements();
05616 return (ConReferenceMatrixElements*)nodePtr;
05617 }
05618
05619 bool ConReferenceMatrixElements::IsEqual(ConReferenceMatrixElements *that)
05620 {
05621 #ifndef NDEBUG
05622 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ConReferenceMatrixElements");
05623 #endif
05624 if (this == NULL)
05625 {
05626 if (that == NULL)
05627 return true;
05628 else
05629 {
05630 #ifndef NDEBUG
05631 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05632 "First object is NULL, second is not");
05633 #endif
05634 return false;
05635 }
05636 }
05637 else
05638 {
05639 if (that == NULL)
05640 {
05641 #ifndef NDEBUG
05642 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05643 "Second object is NULL, first is not");
05644 #endif
05645 return false;
05646 }
05647 else
05648 {
05649 if (this->rowMajor != that->rowMajor) return false;
05650 if (this->numberOfValues != that->numberOfValues) return false;
05651
05652 if (!this->start->IsEqual(that->start)) return false;
05653 if (!this->index->IsEqual(that->index)) return false;
05654 if (!this->value->IsEqual(that->value)) return false;
05655
05656 return true;
05657 }
05658 }
05659 }
05660
05661
05662 bool ConReferenceMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
05663 {
05664 return true;
05665 }
05666
05667 bool ConReferenceMatrixElements::deepCopyFrom(ConReferenceMatrixElements *that)
05668 {
05669 return true;
05670 }
05671
05672
05674 ConReferenceMatrixValues::ConReferenceMatrixValues():
05675 el(NULL)
05676 {
05677 #ifndef NDEBUG
05678 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixValues Constructor");
05679 #endif
05680 }
05681
05682 ConReferenceMatrixValues::~ConReferenceMatrixValues()
05683 {
05684 #ifndef NDEBUG
05685 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixValues Destructor");
05686 #endif
05687 if (numberOfEl > 0 && el != NULL)
05688 {
05689 for (int i=0; i < numberOfEl; i++)
05690 {
05691 if (el[i] != NULL)
05692 {
05693 #ifndef NDEBUG
05694 ostringstream outStr;
05695 outStr.str("");
05696 outStr.clear();
05697 outStr << "deleting ConstantMatrixValues->el [" << i << "] at " << &el[i] << std::endl;
05698 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
05699 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
05700 #endif
05701 delete el[i];
05702 el[i] = NULL;
05703 }
05704 }
05705 }
05706 if (el != NULL)
05707 delete [] el;
05708 el = NULL;
05709 }
05710
05711 bool ConReferenceMatrixValues::IsEqual(ConReferenceMatrixValues *that)
05712 {
05713 #ifndef NDEBUG
05714 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ConReferenceMatrixValues");
05715 #endif
05716 if (this == NULL)
05717 {
05718 if (that == NULL)
05719 return true;
05720 else
05721 {
05722 #ifndef NDEBUG
05723 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05724 "First object is NULL, second is not");
05725 #endif
05726 return false;
05727 }
05728 }
05729 else
05730 {
05731 if (that == NULL)
05732 {
05733 #ifndef NDEBUG
05734 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05735 "Second object is NULL, first is not");
05736 #endif
05737 return false;
05738 }
05739 else
05740 {
05741 if (this->numberOfEl != that->numberOfEl) return false;
05742 for (int i=0; i < numberOfEl; i++)
05743 if (!this->el[i]->IsEqual(that->el[i])) return false;
05744
05745 return true;
05746 }
05747 }
05748 }
05749
05750 bool ConReferenceMatrixValues::setRandom(double density, bool conformant, int iMin, int iMax)
05751 {
05752 return true;
05753 }
05754
05755 bool ConReferenceMatrixValues::deepCopyFrom(ConReferenceMatrixValues *that)
05756 {
05757 #ifndef NDEBUG
05758 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSGeneral, ENUM_OUTPUT_LEVEL_trace, "Make deep copy of ConReferenceMatrixValues");
05759 #endif
05760 this->numberOfEl = that->numberOfEl;
05761 this->el = new ConReferenceMatrixElement*[numberOfEl];
05762 for (int i=0; i<numberOfEl; i++)
05763 ((ConReferenceMatrixValues*)this)->el[i]->deepCopyFrom(that->el[i]);
05764 return true;
05765 }
05766
05767
05769 ConReferenceMatrixElement::ConReferenceMatrixElement():
05770 conReference(-1),
05771 valueType(ENUM_CONREFERENCE_VALUETYPE_value)
05772 {
05773 #ifndef NDEBUG
05774 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixElement Constructor");
05775 #endif
05776 }
05777
05778 ConReferenceMatrixElement::~ConReferenceMatrixElement()
05779 {
05780 #ifndef NDEBUG
05781 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ConReferenceMatrixElement Destructor");
05782 #endif
05783 }
05784
05785 bool ConReferenceMatrixElement::IsEqual(ConReferenceMatrixElement *that)
05786 {
05787 #ifndef NDEBUG
05788 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in ConReferenceMatrixElement");
05789 #endif
05790 if (this == NULL)
05791 {
05792 if (that == NULL)
05793 return true;
05794 else
05795 {
05796 #ifndef NDEBUG
05797 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05798 "First object is NULL, second is not");
05799 #endif
05800 return false;
05801 }
05802 }
05803 else
05804 {
05805 if (that == NULL)
05806 {
05807 #ifndef NDEBUG
05808 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
05809 "Second object is NULL, first is not");
05810 #endif
05811 return false;
05812 }
05813 else
05814 {
05815 if (this->conReference != that->conReference) return false;
05816 if (this->valueType != that->valueType ) return false;
05817
05818 return true;
05819 }
05820 }
05821 }
05822
05823 bool ConReferenceMatrixElement::setRandom(double density, bool conformant, int iMin, int iMax)
05824 {
05825 return true;
05826 }
05827
05828 bool ConReferenceMatrixElement::deepCopyFrom(ConReferenceMatrixElement *that)
05829 {
05830 this->conReference = that->conReference;
05831 this->valueType = that->valueType;
05832 this->value = that->value;
05833 return true;
05834 }
05835
05836
05838 MixedRowReferenceMatrixElements::MixedRowReferenceMatrixElements():
05839 value(NULL)
05840 {
05841 #ifndef NDEBUG
05842 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MixedRowReferenceMatrixElements Constructor");
05843 #endif
05844 }
05845
05846 MixedRowReferenceMatrixElements::~MixedRowReferenceMatrixElements()
05847 {
05848 #ifndef NDEBUG
05849 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MixedRowReferenceMatrixElements Destructor");
05850 #endif
05851 if (value != NULL)
05852 delete value;
05853 value = NULL;
05854 }
05855
05856 ENUM_MATRIX_CONSTRUCTOR_TYPE MixedRowReferenceMatrixElements::getNodeType()
05857 {
05858 return ENUM_MATRIX_CONSTRUCTOR_TYPE_mixedRowRefElements;
05859 }
05860
05861 std::string MixedRowReferenceMatrixElements::getNodeName()
05862 {
05863 return "mixedRowRefElements";
05864 }
05865
05866 ENUM_MATRIX_TYPE MixedRowReferenceMatrixElements::getMatrixType()
05867 {
05868 if (matrixType == ENUM_MATRIX_TYPE_unknown)
05869 matrixType = ENUM_MATRIX_TYPE_mixedRowReference;
05870 return matrixType;
05871 }
05872
05873 std::string MixedRowReferenceMatrixElements::getMatrixNodeInXML()
05874 {
05878 ostringstream outStr;
05879 int tmpNum = 0;
05880 int i, j;
05881 for (i=0; i < start->numberOfEl - 1; i++)
05882 {
05883 for (j=start->el[i]; j<start->el[i+1]; j++)
05884 {
05885 if (value->el[j]->conReference < 0) tmpNum++;
05886 }
05887 }
05888
05889 if (tmpNum > 0)
05890 {
05891 outStr << "<objReferenceElements";
05892 if (rowMajor)
05893 outStr << " rowMajor=\"true\"";
05894 outStr << " numberOfValues=\"" << tmpNum << "\"";
05895 outStr << ">" << std::endl;
05896
05897 if (tmpNum < numberOfValues)
05898 {
05899 outStr << "<start>" << std::endl;
05900 outStr << "<el>0</el>" << std::endl;
05901 tmpNum = 0;
05902 for (i=0; i < start->numberOfEl - 1; i++)
05903 {
05904 for (j=start->el[i]; j<start->el[i+1]; j++)
05905 {
05906 if (value->el[j]->conReference < 0) tmpNum++;
05907 }
05908 outStr << "<el>" << tmpNum << "</el>" << std::endl;
05909 }
05910 outStr << "</start>" << std::endl;
05911
05912 outStr << "<index>" << std::endl;
05913 for (i=0; i < start->numberOfEl - 1; i++)
05914 {
05915 for (j=start->el[i]; j<start->el[i+1]; j++)
05916 {
05917 if (value->el[j]->conReference < 0)
05918 outStr << "<el>" << index->el[j] << "</el>";
05919 }
05920 }
05921 outStr << "</index>" << std::endl;
05922
05923 outStr << "<value>" << std::endl;
05924 for (i=0; i < start->numberOfEl - 1; i++)
05925 {
05926 for (j=start->el[i]; j<start->el[i+1]; j++)
05927 {
05928 if (value->el[j]->conReference < 0)
05929 outStr << "<el>" << value->el[j]->conReference << "</el>";
05930 }
05931 }
05932 outStr << "</value>" << std::endl;
05933 outStr << "</objReferenceElements>" << std::endl;
05934
05935 outStr << "<conReferenceElements";
05936 if (rowMajor)
05937 outStr << " rowMajor=\"true\"";
05938 outStr << " numberOfValues=\"" << numberOfValues - tmpNum << "\"";
05939 outStr << ">" << std::endl;
05940
05941 outStr << "<start>" << std::endl;
05942 outStr << "<el>0</el>" << std::endl;
05943 tmpNum = 0;
05944 for (i=0; i < start->numberOfEl - 1; i++)
05945 {
05946 for (j=start->el[i]; j<start->el[i+1]; j++)
05947 {
05948 if (value->el[j]->conReference >= 0) tmpNum++;
05949 }
05950 outStr << "<el>" << tmpNum << "</el>" << std::endl;
05951 }
05952 outStr << "</start>" << std::endl;
05953
05954 outStr << "<index>" << std::endl;
05955 for (i=0; i < start->numberOfEl - 1; i++)
05956 {
05957 for (j=start->el[i]; j<start->el[i+1]; j++)
05958 {
05959 if (value->el[j]->conReference >= 0)
05960 outStr << "<el>" << index->el[j] << "</el>";
05961 }
05962 }
05963 outStr << "</index>" << std::endl;
05964
05965 outStr << "<value>" << std::endl;
05966 for (i=0; i < start->numberOfEl - 1; i++)
05967 {
05968 for (j=start->el[i]; j<start->el[i+1]; j++)
05969 {
05970 if (value->el[j]->conReference >= 0)
05971 {
05972 outStr << "<el";
05973 if (value->el[i]->valueType != ENUM_CONREFERENCE_VALUETYPE_value)
05974 {
05975 outStr << " valueType=\"";
05976 outStr << returnConReferenceValueTypeString(value->el[i]->valueType) << "\"";
05977 }
05978 outStr << ">" << value->el[j]->conReference << "</el>";
05979 }
05980 }
05981 }
05982 outStr << "</value>" << std::endl;
05983 outStr << "</conReferenceElements>" << std::endl;
05984
05985 }
05986 else
05987 {
05988 outStr << "<start>" << std::endl;
05989 outStr << writeIntVectorData(start, true, false);
05990 outStr << "</start>" << std::endl;
05991
05992 if (numberOfValues > 0)
05993 {
05994 outStr << "<index>" << std::endl;
05995 outStr << writeIntVectorData(index, true, false);
05996 outStr << "</index>" << std::endl;
05997
05998 outStr << "<value>" << std::endl;
05999
06000 for(int i = 0; i < numberOfValues; i++)
06001 {
06002 outStr << "<el";
06003
06004 outStr << ">";
06005 outStr << os_dtoa_format(value->el[i]->conReference);
06006 outStr << "</el>" << std::endl;
06007 }
06008 outStr << "</value>" << std::endl;
06009 }
06010 outStr << "</objReferenceElements>" << std::endl;
06011 }
06012 }
06013 else
06014 {
06015 outStr << "<conReferenceElements";
06016 if (rowMajor)
06017 outStr << " rowMajor=\"true\"";
06018 outStr << " numberOfValues=\"" << numberOfValues << "\"";
06019 outStr << ">" << std::endl;
06020
06021 outStr << "<start>" << std::endl;
06022 outStr << writeIntVectorData(start, true, false);
06023 outStr << "</start>" << std::endl;
06024
06025 if (numberOfValues > 0)
06026 {
06027 outStr << "<index>" << std::endl;
06028 outStr << writeIntVectorData(index, true, false);
06029 outStr << "</index>" << std::endl;
06030
06031 outStr << "<value>" << std::endl;
06032
06033 for(int i = 0; i < numberOfValues; i++)
06034 {
06035 outStr << "<el";
06036 if (value->el[i]->valueType != ENUM_CONREFERENCE_VALUETYPE_value)
06037 {
06038 outStr << " valueType=\"";
06039 outStr << returnConReferenceValueTypeString(value->el[i]->valueType) << "\"";
06040 }
06041
06042 outStr << ">";
06043 outStr << os_dtoa_format(value->el[i]->conReference);
06044 outStr << "</el>" << std::endl;
06045 }
06046 outStr << "</value>" << std::endl;
06047 }
06048 outStr << "</conReferenceElements>" << std::endl;
06049 }
06050
06051 return outStr.str();
06052 }
06053
06054 bool MixedRowReferenceMatrixElements::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
06055 {
06056 return false;
06057 }
06058
06059 MixedRowReferenceMatrixElements* MixedRowReferenceMatrixElements::cloneMatrixNode()
06060 {
06061 MixedRowReferenceMatrixElements *nodePtr;
06062 nodePtr = new MixedRowReferenceMatrixElements();
06063 return (MixedRowReferenceMatrixElements*)nodePtr;
06064 }
06065
06066 bool MixedRowReferenceMatrixElements::IsEqual(MixedRowReferenceMatrixElements *that)
06067 {
06068 #ifndef NDEBUG
06069 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace, "Start comparing in MixedRowReferenceMatrixElements");
06070 #endif
06071 if (this == NULL)
06072 {
06073 if (that == NULL)
06074 return true;
06075 else
06076 {
06077 #ifndef NDEBUG
06078 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
06079 "First object is NULL, second is not");
06080 #endif
06081 return false;
06082 }
06083 }
06084 else
06085 {
06086 if (that == NULL)
06087 {
06088 #ifndef NDEBUG
06089 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix, ENUM_OUTPUT_LEVEL_trace,
06090 "Second object is NULL, first is not");
06091 #endif
06092 return false;
06093 }
06094 else
06095 {
06096 if (this->rowMajor != that->rowMajor) return false;
06097 if (this->numberOfValues != that->numberOfValues) return false;
06098
06099 if (!this->start->IsEqual(that->start)) return false;
06100 if (!this->index->IsEqual(that->index)) return false;
06101 if (!this->value->IsEqual(that->value)) return false;
06102
06103 return true;
06104 }
06105 }
06106 }
06107
06108 bool MixedRowReferenceMatrixElements::setRandom(double density, bool conformant, int iMin, int iMax)
06109 {
06110 return true;
06111 }
06112
06113 bool MixedRowReferenceMatrixElements::deepCopyFrom(MixedRowReferenceMatrixElements *that)
06114 {
06115 return true;
06116 }
06117
06118
06120 MatrixBlocks::MatrixBlocks():
06121 colOffset(NULL),
06122 rowOffset(NULL)
06123 {
06124 #ifndef NDEBUG
06125 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixBlocks Constructor");
06126 #endif
06127 nType = ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks;
06128 }
06129
06130 MatrixBlocks::~MatrixBlocks()
06131 {
06132 std::ostringstream outStr;
06133
06134 #ifndef NDEBUG
06135 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixBlocks Destructor");
06136 outStr.str("");
06137 outStr.clear();
06138 outStr << "NUMBER OF BLOCKS = " << inumberOfChildren << endl;
06139 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06140
06141 outStr.str("");
06142 outStr.clear();
06143 outStr << "deleting MatrixBlocks->colOffset at " << &colOffset << std::endl;
06144 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
06145 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06146
06147 outStr.str("");
06148 outStr.clear();
06149 outStr << "deleting MatrixBlocks->rowOffset at " << &rowOffset << std::endl;
06150 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
06151 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06152 #endif
06153 if (colOffset != NULL)
06154 delete colOffset;
06155 colOffset = NULL;
06156
06157 if (rowOffset != NULL)
06158 delete rowOffset;
06159 rowOffset = NULL;
06160
06161 #if 0
06162 if(inumberOfChildren > 0 && block != NULL)
06163 {
06164 for (int i=0; i < numberOfBlocks; i++)
06165 {
06166 if (block[i] != NULL)
06167 {
06168 #ifndef NDEBUG
06169 outStr.str("");
06170 outStr.clear();
06171 outStr << "deleting MatrixBlocks->block [" << i << "] at " << &block[i] << std::endl;
06172 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
06173 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06174 #endif
06175 delete block[i];
06176 block[i] = NULL;
06177 }
06178 }
06179 }
06180 if (block != NULL)
06181 delete [] block;
06182 block = NULL;
06183 #endif
06184 }
06185
06186 ENUM_MATRIX_CONSTRUCTOR_TYPE MatrixBlocks::getNodeType()
06187 {
06188 return ENUM_MATRIX_CONSTRUCTOR_TYPE_blocks;
06189 }
06190
06191 std::string MatrixBlocks::getNodeName()
06192 {
06193 return "blocks";
06194 }
06195
06196 ENUM_MATRIX_TYPE MatrixBlocks::getMatrixType()
06197 {
06198 if (matrixType == ENUM_MATRIX_TYPE_unknown)
06199 {
06200 matrixType = ENUM_MATRIX_TYPE_empty;
06201 for (int i=0; i<inumberOfChildren; i++)
06202 matrixType = mergeMatrixType(matrixType, m_mChildren[i]->getMatrixType());
06203 }
06204 return matrixType;
06205 }
06206
06207 std::string MatrixBlocks::getMatrixNodeInXML()
06208 {
06209 ostringstream outStr;
06210 outStr << "<blocks numberOfBlocks=\"" << inumberOfChildren << "\">" << std::endl;
06211 outStr << "<colOffset numberOfEl=\"" << colOffset->numberOfEl << "\">" << std::endl;
06212 outStr << writeIntVectorData(colOffset, true, false);
06213 outStr << "</colOffset>" << std::endl;
06214 outStr << "<rowOffset numberOfEl=\"" << rowOffset->numberOfEl << "\">" << std::endl;
06215 outStr << writeIntVectorData(rowOffset, true, false);
06216 outStr << "</rowOffset>" << std::endl;
06217
06218 for (int i=0; i < inumberOfChildren; i++)
06219 outStr << m_mChildren[i]->getMatrixNodeInXML();
06220
06221 outStr << "</blocks>" << std::endl;
06222 return outStr.str();
06223 }
06224
06225 bool MatrixBlocks::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
06226 {
06227 bool accumulator = false;
06228 int nrBlocks = rowOffset->numberOfEl - 1;
06229 int ncBlocks = colOffset->numberOfEl - 1;
06230 for (int i=0; i < nrBlocks; i++)
06231 if ( (rowOffset->el[i] == firstRow) && ((firstRow+nRows) == rowOffset->el[i+1]) )
06232 {
06233 accumulator = true;
06234 break;
06235 }
06236 if (!accumulator) return false;
06237 for (int i=0; i < ncBlocks; i++)
06238 if ( (colOffset->el[i] == firstColumn) && ((firstColumn+nCols) == colOffset->el[i+1]) )
06239 {
06240 accumulator = true;
06241 break;
06242 }
06243 return accumulator;
06244 }
06245
06246 MatrixBlocks* MatrixBlocks::cloneMatrixNode()
06247 {
06248 MatrixNode *nodePtr;
06249 nodePtr = new MatrixBlocks();
06250 return (MatrixBlocks*)nodePtr;
06251 }
06252
06253 bool MatrixBlocks::IsEqual(MatrixBlocks *that)
06254 {
06255 #ifndef NDEBUG
06256 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug, "Start comparing in MatrixBlocks");
06257 #endif
06258 if (this == NULL)
06259 {
06260 if (that == NULL)
06261 return true;
06262 else
06263 {
06264 #ifndef NDEBUG
06265 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
06266 "First object is NULL, second is not");
06267 #endif
06268 return false;
06269 }
06270 }
06271 else
06272 {
06273 if (that == NULL)
06274 {
06275 #ifndef NDEBUG
06276 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_debug,
06277 "Second object is NULL, first is not");
06278 #endif
06279 return false;
06280 }
06281 else
06282 {
06283 if (!this->colOffset->IsEqual(that->colOffset))
06284 return false;
06285 if (!this->rowOffset->IsEqual(that->rowOffset))
06286 return false;
06287 return true;
06288 }
06289 }
06290 }
06291
06292
06293
06295 MatrixBlock::MatrixBlock():
06296 blockRowIdx(-1),
06297 blockColIdx(-1)
06298 {
06299 #ifndef NDEBUG
06300 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixBlock Constructor");
06301 #endif
06302 nType = ENUM_MATRIX_CONSTRUCTOR_TYPE_block;
06303 }
06304
06305 MatrixBlock::~MatrixBlock()
06306 {
06307 #ifndef NDEBUG
06308 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the MatrixBlock Destructor");
06309 #endif
06310 }
06311
06312 ENUM_MATRIX_CONSTRUCTOR_TYPE MatrixBlock::getNodeType()
06313 {
06314 return ENUM_MATRIX_CONSTRUCTOR_TYPE_block;
06315 }
06316
06317 std::string MatrixBlock::getNodeName()
06318 {
06319 return "block";
06320 }
06321
06322 ENUM_MATRIX_TYPE MatrixBlock::getMatrixType()
06323 {
06324 if (matrixType == ENUM_MATRIX_TYPE_unknown)
06325 {
06326 matrixType = ENUM_MATRIX_TYPE_empty;
06327 for (int i=0; i<inumberOfChildren; i++)
06328 {
06329 matrixType = mergeMatrixType(matrixType, m_mChildren[i]->getMatrixType());
06330 }
06331 }
06332 return matrixType;
06333 }
06334
06335 std::string MatrixBlock::getMatrixNodeInXML()
06336 {
06337 ostringstream outStr;
06338 outStr << "<block";
06339 outStr << " blockRowIdx=\"" << blockRowIdx << "\"";
06340 outStr << " blockColIdx=\"" << blockColIdx << "\"";
06341 if (symmetry != ENUM_MATRIX_SYMMETRY_none)
06342 outStr << " symmetry=\"" << returnMatrixSymmetryString(symmetry) << "\"";
06343 if (matrixType != ENUM_MATRIX_TYPE_unknown)
06344 outStr << " type=\"" << returnMatrixTypeString(matrixType) << "\"";
06345
06346 if (inumberOfChildren > 0)
06347 {
06348 outStr << ">" << std::endl;
06349 for (int i=0; i < inumberOfChildren; i++)
06350 outStr << m_mChildren[i]->getMatrixNodeInXML();
06351 outStr << "</block>" << std::endl;
06352 }
06353 else
06354 outStr << "/>" << std::endl;
06355 return outStr.str();
06356 }
06357
06358 bool MatrixBlock::alignsOnBlockBoundary(int firstRow, int firstColumn, int nRows, int nCols)
06359 {
06360 return (firstRow == 0 && firstColumn == 0 && nRows == numberOfRows && nCols == numberOfColumns);
06361 }
06362
06363 bool MatrixBlock::expandElements(bool rowMajor)
06364 {
06365 return NULL;
06366 }
06367
06368 MatrixBlock* MatrixBlock::cloneMatrixNode()
06369 {
06370 MatrixType *nodePtr;
06371 nodePtr = new MatrixBlock();
06372 return (MatrixBlock*)nodePtr;
06373 }
06374
06375 bool MatrixBlock::IsEqual(MatrixBlock *that)
06376 {
06377 return true;
06378 }
06379
06380 bool MatrixBlock::setRandom(double density, bool conformant, int iMin, int iMax)
06381 {
06382 return true;
06383 }
06384
06385 bool MatrixBlock::deepCopyFrom(MatrixBlock *that)
06386 {
06387 return true;
06388 }
06389
06390
06391
06393 GeneralSparseMatrix::GeneralSparseMatrix():
06394 b_deleteStartArray(true),
06395 b_deleteIndexArray(true),
06396 b_deleteValueArray(true),
06397 isRowMajor(false),
06398 startSize(-1),
06399 valueSize(-1),
06400 vType(ENUM_MATRIX_TYPE_unknown),
06401 start(NULL),
06402 index(NULL),
06403 value(NULL)
06404 {
06405 #ifndef NDEBUG
06406 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralSparseMatrix Constructor");
06407 #endif
06408 }
06409
06410 GeneralSparseMatrix::GeneralSparseMatrix(bool isColumnMajor_, int startSize_, int valueSize_,
06411 ENUM_MATRIX_TYPE type_):
06412 b_deleteStartArray(true),
06413 b_deleteIndexArray(true),
06414 b_deleteValueArray(true),
06415 value(NULL)
06416 {
06417 #ifndef NDEBUG
06418 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the alternate GeneralSparseMatrix Constructor");
06419 #endif
06420 isRowMajor = !(isColumnMajor_);
06421 startSize = startSize_;
06422 valueSize = valueSize_;
06423 vType = type_;
06424 start = new int[startSize];
06425 index = new int[valueSize];
06426 }
06427
06428 GeneralSparseMatrix::~GeneralSparseMatrix()
06429 {
06430 #ifndef NDEBUG
06431 ostringstream outStr;
06432
06433 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance,
06434 ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralSparseMatrix Destructor");
06435 #endif
06436 if (b_deleteStartArray)
06437 {
06438 if (start != NULL)
06439 {
06440 #ifndef NDEBUG
06441 outStr.str("");
06442 outStr.clear();
06443 outStr << "deleting GeneralSparseMatrix->start at " << &start << std::endl;
06444 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
06445 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06446 #endif
06447 delete [] start;
06448 start = NULL;
06449 }
06450 }
06451 if (b_deleteIndexArray)
06452 {
06453 if (index != NULL)
06454 {
06455 #ifndef NDEBUG
06456 outStr.str("");
06457 outStr.clear();
06458 outStr << "deleting GeneralSparseMatrix->index at " << &index << std::endl;
06459 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
06460 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06461 #endif
06462 delete [] index;
06463 index = NULL;
06464 }
06465 }
06466 if (b_deleteValueArray)
06467 {
06468 if (value != NULL)
06469 {
06470 #ifndef NDEBUG
06471 outStr.str("");
06472 outStr.clear();
06473 outStr << "deleting GeneralSparseMatrix->value at " << &value << std::endl;
06474 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
06475 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06476 #endif
06477 delete value;
06478 value = NULL;
06479 }
06480 }
06481 }
06482
06483 bool GeneralSparseMatrix::isDiagonal()
06484 {
06485 #ifndef NDEBUG
06486 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
06487 "Inside GeneralSparseMatrix::isDiagonal()");
06488 #endif
06489 if (valueSize == 0)
06490 return true;
06491 if (valueSize >= startSize)
06492 return false;
06493
06494 for (int i=1; i < startSize; i++)
06495 {
06496 if (start[i] - start[i-1] > 1)
06497 return false;
06498 for (int j=start[i-1]; j<start[i]; j++)
06499 if (index[j] != i-1)
06500 return false;
06501 }
06502
06503 return true;
06504 }
06505
06506 bool GeneralSparseMatrix::display(int secondaryDim)
06507 {
06508 return true;
06509 }
06510
06511
06513 ExpandedMatrixBlocks::ExpandedMatrixBlocks():
06514 bDeleteArrays(true),
06515 isRowMajor(false),
06516 blockNumber(0),
06517 blockRows(NULL),
06518 blockColumns(NULL),
06519 blocks(NULL)
06520 {
06521 #ifndef NDEBUG
06522 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralSparseMatrix default constructor");
06523 #endif
06524 }
06525
06526 ExpandedMatrixBlocks::ExpandedMatrixBlocks(bool isRowMajor_, int startSize, int valueSize):
06527 bDeleteArrays(true),
06528 blockNumber(0),
06529 blockRows(NULL),
06530 blockColumns(NULL),
06531 blocks(NULL)
06532 {
06533 #ifndef NDEBUG
06534 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the GeneralSparseMatrix default constructor");
06535 #endif
06536 isRowMajor = isRowMajor_;
06537 }
06538
06539 ExpandedMatrixBlocks::~ExpandedMatrixBlocks()
06540 {
06541 std::ostringstream outStr;
06542 #ifndef NDEBUG
06543 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace, "Inside the ExpandedMatrixBlocks Destructor");
06544 #endif
06545 if (bDeleteArrays)
06546 {
06547 if (blockRows != NULL)
06548 {
06549 #ifndef NDEBUG
06550 outStr.str("");
06551 outStr.clear();
06552 outStr << "deleting ExpandedMatrixBlocks->blockRows at " << &blockRows << std::endl;
06553 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
06554 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06555 #endif
06556 delete [] blockRows;
06557 blockRows = NULL;
06558 }
06559 if (blockColumns != NULL)
06560 {
06561 #ifndef NDEBUG
06562 outStr.str("");
06563 outStr.clear();
06564 outStr << "deleting ExpandedMatrixBlocks->blockColumns at " << &blockColumns << std::endl;
06565 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
06566 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06567 #endif
06568 delete [] blockColumns;
06569 blockColumns = NULL;
06570 }
06571 if (blockNumber > 0 && blocks != NULL)
06572 {
06573 for (int i=0; i < blockNumber; i++)
06574 {
06575 if (blocks[i] != NULL)
06576 {
06577 #ifndef NDEBUG
06578 outStr.str("");
06579 outStr.clear();
06580 outStr << "deleting ExpandedMatrixBlocks->blocks[" << i << "] at "
06581 << &blocks[i] << std::endl;
06582 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSMatrix,
06583 ENUM_OUTPUT_LEVEL_detailed_trace, outStr.str());
06584 #endif
06585 delete blocks[i];
06586 blocks[i] = NULL;
06587 }
06588 }
06589 }
06590 if (blocks != NULL) delete [] blocks;
06591 blocks = NULL;
06592 }
06593 }
06594
06595 GeneralSparseMatrix* ExpandedMatrixBlocks::getBlock(int rowIdx, int colIdx)
06596 {
06597 #ifndef NDEBUG
06598 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
06599 "Inside ExpandedMatrixBlocks::getBlock()");
06600 #endif
06601 for (int i=0; i < blockNumber; i++)
06602 if (blockRows[i] == rowIdx && blockColumns[i] == colIdx)
06603 return blocks[i];
06604
06605 return NULL;
06606 }
06607
06608 bool ExpandedMatrixBlocks::isBlockDiagonal()
06609 {
06610 #ifndef NDEBUG
06611 osoutput->OSPrint(ENUM_OUTPUT_AREA_OSInstance, ENUM_OUTPUT_LEVEL_trace,
06612 "Inside ExpandedMatrixBlocks::isBlockDiagonal()");
06613 #endif
06614 if (blockNumber >= rowOffsetSize || blockNumber >= colOffsetSize || rowOffsetSize != colOffsetSize)
06615 return false;
06616
06617 for (int i=0; i < blockNumber; i++)
06618 if (blockRows[i] != blockColumns[i])
06619 return false;
06620
06621 return true;
06622 }
06623
06624
06625 bool ExpandedMatrixBlocks::display(int secondaryDim)
06626 {
06627 return true;
06628 }
06629
06630
06631
06635 LinearMatrixElement* convertToLinearMatrixElement(double val)
06636 {
06637 try
06638 {
06639 LinearMatrixElement* tmp = new LinearMatrixElement();
06640 tmp->constant = val;
06641 tmp->numberOfVarIdx = 0;
06642 tmp->varIdx = NULL;
06643 return tmp;
06644 }
06645 catch(const ErrorClass& eclass)
06646 {
06647 throw ErrorClass( eclass.errormsg);
06648 }
06649 }
06650
06651 LinearMatrixElement* convertToLinearMatrixElement(int varref)
06652 {
06653 try
06654 {
06655 LinearMatrixElement* tmp = new LinearMatrixElement();
06656 tmp->constant = 0.0;
06657 tmp->numberOfVarIdx = 1;
06658 tmp->varIdx = new LinearMatrixElementTerm*[1];
06659 tmp->varIdx[0] = new LinearMatrixElementTerm();
06660 tmp->varIdx[0]->coef = 1.0;
06661 tmp->varIdx[0]->idx = varref;
06662 return tmp;
06663 }
06664 catch(const ErrorClass& eclass)
06665 {
06666 throw ErrorClass( eclass.errormsg);
06667 }
06668 }
06669
06670 ScalarExpressionTree* convertToGeneralMatrixElement(double val)
06671 {
06672 try
06673 {
06674 std::vector<ExprNode*> nlNodeVec;
06675 ScalarExpressionTree* tmp = new ScalarExpressionTree();
06676
06677 OSnLNodeNumber* tmpNum = new OSnLNodeNumber();
06678 tmpNum->value = val;
06679 nlNodeVec.push_back(tmpNum);
06680
06681 tmp->m_treeRoot =
06682 ((OSnLNode*)nlNodeVec[ 0])->createExpressionTreeFromPostfix(nlNodeVec);
06683 nlNodeVec.clear();
06684 return tmp;
06685 }
06686 catch(const ErrorClass& eclass)
06687 {
06688 throw ErrorClass( eclass.errormsg);
06689 }
06690 }
06691
06692 ScalarExpressionTree* convertToGeneralMatrixElement(int refIdx, bool varRef)
06693 {
06694 try
06695 {
06696 std::vector<ExprNode*> nlNodeVec;
06697 ScalarExpressionTree* tmp = new ScalarExpressionTree();
06698
06699 OSnLNode* tmpRef;
06700
06701 if (varRef)
06702 {
06703 tmpRef = new OSnLNodeVariable();
06704 ((OSnLNodeVariable*)tmpRef)->idx = refIdx;
06705 }
06706 else
06707 throw ErrorClass("OSnLNodeObjective not yet implemented");
06708 nlNodeVec.push_back(tmpRef);
06709
06710 tmp->m_treeRoot =
06711 ((OSnLNode*)nlNodeVec[ 0])->createExpressionTreeFromPostfix(nlNodeVec);
06712 nlNodeVec.clear();
06713 return tmp;
06714 }
06715 catch(const ErrorClass& eclass)
06716 {
06717 throw ErrorClass( eclass.errormsg);
06718 }
06719 }
06720
06721 ScalarExpressionTree* convertToGeneralMatrixElement(LinearMatrixElement* linearExpr)
06722 {
06723 try
06724 {
06725 std::vector<ExprNode*> nlNodeVec;
06726 ScalarExpressionTree* tmp = new ScalarExpressionTree();
06727
06728
06729 OSnLNodeSum* tmpSum = new OSnLNodeSum();
06730 OSnLNodeNumber* tmpNum;
06731 OSnLNodeVariable* tmpVar;
06732 OSnLNodeTimes* tmpTimes;
06733
06734 for (int i=0; i < linearExpr->numberOfVarIdx; i++)
06735 {
06736 tmpVar = new OSnLNodeVariable();
06737 tmpVar->idx = linearExpr->varIdx[i]->idx;
06738 nlNodeVec.push_back(tmpVar);
06739 if (linearExpr->varIdx[i]->coef != 1.0)
06740 {
06741 tmpNum = new OSnLNodeNumber();
06742 tmpNum->value = linearExpr->varIdx[i]->coef;
06743 nlNodeVec.push_back(tmpNum);
06744
06745 tmpTimes = new OSnLNodeTimes();
06746 nlNodeVec.push_back(tmpTimes);
06747 }
06748 }
06749
06750 if (linearExpr->constant != 0.0)
06751 {
06752 tmpNum = new OSnLNodeNumber();
06753 tmpNum->value = linearExpr->constant;
06754 nlNodeVec.push_back(tmpNum);
06755 }
06756
06757 nlNodeVec.push_back(tmpSum);
06758
06759 tmp->m_treeRoot =
06760 ((OSnLNode*)nlNodeVec[ 0])->createExpressionTreeFromPostfix(nlNodeVec);
06761 nlNodeVec.clear();
06762 return tmp;
06763 }
06764 catch(const ErrorClass& eclass)
06765 {
06766 throw ErrorClass( eclass.errormsg);
06767 }
06768 }
06769
06770 ScalarExpressionTree* convertToGeneralMatrixElement(ConReferenceMatrixElement* val)
06771 {
06772 try
06773 {
06774 throw ErrorClass("In convertToGeneralMatrixElement: OSnLNodeConstraint not yet implemented");
06775 return NULL;
06776 }
06777 catch(const ErrorClass& eclass)
06778 {
06779 throw ErrorClass( eclass.errormsg);
06780 }
06781 }
06782
06783 ConReferenceMatrixElement* convertToConReferenceMatrixElement(int objref)
06784 {
06785 try
06786 {
06787 throw ErrorClass("In convertToConReferenceMatrixElement: OSnLNodeConstraint not yet implemented");
06788 return NULL;
06789 }
06790 catch(const ErrorClass& eclass)
06791 {
06792 throw ErrorClass( eclass.errormsg);
06793 }
06794 }
06795
06796 #if 0
06797
06798 OSnLNode *nlNodePoint;
06799 OSnLNodeVariable *nlNodeVariablePoint;
06800 std::vector<ExprNode*> nlNodeVec;
06801
06802
06803 int i;
06804 for(i = 0; i < numQPTerms; i++)
06805 {
06806 instanceData->nonlinearExpressions->nl[ i] = new Nl();
06807 instanceData->nonlinearExpressions->nl[ i]->idx = rowIndexes[ i];
06808 instanceData->nonlinearExpressions->nl[ i]->osExpressionTree = new ScalarExpressionTree();
06809
06810 nlNodeVariablePoint = new OSnLNodeVariable();
06811 nlNodeVariablePoint->idx = varOneIndexes[ i];
06812
06813 nlNodeVariablePoint->coef = coefficients[ i];
06814 nlNodeVec.push_back( nlNodeVariablePoint);
06815
06816 nlNodeVariablePoint = new OSnLNodeVariable();
06817 nlNodeVariablePoint->idx = varTwoIndexes[ i];
06818 nlNodeVec.push_back( nlNodeVariablePoint);
06819
06820 nlNodePoint = new OSnLNodeTimes();
06821 nlNodeVec.push_back( (OSnLNode*)nlNodePoint);
06822
06823
06824 instanceData->nonlinearExpressions->nl[ i]->osExpressionTree->m_treeRoot =
06825 ((OSnLNode*)nlNodeVec[ 0])->createExpressionTreeFromPostfix( nlNodeVec);
06826 nlNodeVec.clear();
06827 }
06828 #endif