94 HashTable<List<List<word>>> stateResConInfo;
95 options.readEntry<HashTable<List<List<word>>>>(
"stateResConInfo", stateResConInfo);
112 HashTable<List<List<word>>> stateResConInfo;
113 options.readEntry<HashTable<List<List<word>>>>(
"stateResConInfo", stateResConInfo);
115 label isPrealloc = 0;
129 MatCreate(PETSC_COMM_WORLD, &
jacCon_);
147 Info <<
"Connectivity matrix initialized." << endl;
152 const HashTable<List<List<word>>>& stateResConInfo,
153 const label isPrealloc)
265 Mat connectedStatesP;
268 const PetscInt* cols;
269 const PetscScalar*
vals;
272 const PetscInt* colsID;
273 const PetscScalar* valsID;
288 Info <<
"Computing preallocating vectors for Jacobian connectivity mat" << endl;
292 Info <<
"Setup Jacobian connectivity mat" << endl;
304 word resName = stateName +
"Res";
315 label maxConLevel = stateResConInfo[resName].size() - 1;
326 for (label comp = 0; comp < compMax; comp++)
333 forAll(stateResConInfo[resName], idxJ)
337 wordList connectedStatesLocal(0);
338 forAll(stateResConInfo[resName][idxJ], idxK)
340 word conName = stateResConInfo[resName][idxJ][idxK];
345 connectedStatesLocal.append(conName);
350 List<List<word>> connectedStatesInterProc;
354 connectedStatesInterProc.setSize(0);
356 else if (idxJ != maxConLevel)
358 connectedStatesInterProc.setSize(maxConLevel - idxJ + 1);
359 for (label
k = 0;
k < maxConLevel - idxJ + 1;
k++)
361 label conSize = stateResConInfo[resName][
k + idxJ].size();
362 for (label l = 0; l < conSize; l++)
364 word conName = stateResConInfo[resName][
k + idxJ][l];
369 connectedStatesInterProc[
k].append(conName);
376 connectedStatesInterProc.setSize(1);
377 label conSize = stateResConInfo[resName][maxConLevel].size();
378 for (label l = 0; l < conSize; l++)
380 word conName = stateResConInfo[resName][maxConLevel][l];
385 connectedStatesInterProc[0].append(conName);
394 word conName =
stateInfo_[
"surfaceScalarStates"][idxK];
395 if (DAUtility::isInList<word>(conName, stateResConInfo[resName][idxJ]))
404 && this->addPhi4PIV(stateName, cellI, comp))
414 connectedStatesLocal,
415 connectedStatesInterProc,
450 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
451 word resName = stateName +
"Res";
454 label maxConLevel = stateResConInfo[resName].size() - 1;
463 label idxO = -1, idxN = -1;
466 idxO =
mesh_.owner()[faceI];
467 idxN =
mesh_.neighbour()[faceI];
475 const UList<label>& pFaceCells =
mesh_.boundaryMesh()[patchIdx].faceCells();
476 idxN = pFaceCells[faceIdx];
480 forAll(stateResConInfo[resName], idxJ)
484 wordList connectedStatesLocal(0);
485 forAll(stateResConInfo[resName][idxJ], idxK)
487 word conName = stateResConInfo[resName][idxJ][idxK];
492 connectedStatesLocal.append(conName);
497 List<List<word>> connectedStatesInterProc;
501 connectedStatesInterProc.setSize(0);
503 else if (idxJ != maxConLevel)
505 connectedStatesInterProc.setSize(maxConLevel - idxJ + 1);
506 for (label
k = 0;
k < maxConLevel - idxJ + 1;
k++)
508 label conSize = stateResConInfo[resName][
k + idxJ].size();
509 for (label l = 0; l < conSize; l++)
511 word conName = stateResConInfo[resName][
k + idxJ][l];
516 connectedStatesInterProc[
k].append(conName);
523 connectedStatesInterProc.setSize(1);
524 label conSize = stateResConInfo[resName][maxConLevel].size();
525 for (label l = 0; l < conSize; l++)
527 word conName = stateResConInfo[resName][maxConLevel][l];
532 connectedStatesInterProc[0].append(conName);
541 word conName =
stateInfo_[
"surfaceScalarStates"][idxK];
554 levelCheck = idxJ - 1;
557 if (DAUtility::isInList<word>(conName, stateResConInfo[resName][levelCheck]))
566 && this->addPhi4PIV(stateName, faceI))
576 connectedStatesLocal,
577 connectedStatesInterProc,
587 connectedStatesLocal,
588 connectedStatesInterProc,
603 label maxLevel = stateResConInfo[resName].size();
605 if (
mesh_.boundaryMesh()[patchIdx].coupled())
612 for (label i = 0; i < nCols; i++)
614 PetscInt idxJ = cols[i];
615 label val = round(
vals[i]);
618 label stateID = round(valsID[i]);
624 if (val != 10 && val < maxLevel + 1)
626 if (DAUtility::isInList<word>(conName, stateResConInfo[resName][val - 1]))
631 if (addState == 1 && val < maxLevel + 1 && val > 0)
676 wordList writeJacobians;
678 if (writeJacobians.found(
"dRdWTPrealloc"))
688 MatAssemblyBegin(
jacCon_, MAT_FINAL_ASSEMBLY);
689 MatAssemblyEnd(
jacCon_, MAT_FINAL_ASSEMBLY);
692 wordList writeJacobians;
694 if (writeJacobians.found(
"dRdWCon"))
705 Info <<
"Preallocating state Jacobian connectivity mat: finished!" << endl;
709 Info <<
"Setup state Jacobian connectivity mat: finished!" << endl;
718 Vec preallocOffProcT,
748 const PetscInt* cols;
749 const PetscScalar*
vals;
751 MatAssemblyBegin(connections, MAT_FINAL_ASSEMBLY);
752 MatAssemblyEnd(connections, MAT_FINAL_ASSEMBLY);
761 MatGetRow(connections, 0, &nCols, &cols, &
vals);
765 label totalCount = 0;
766 label localCount = 0;
768 for (label j = 0; j < nCols; j++)
771 scalar val =
vals[j];
778 if (colMin <= idx && idx < colMax)
781 VecSetValue(preallocOnProcT, idx, v, ADD_VALUES);
787 VecSetValue(preallocOffProcT, idx, v, ADD_VALUES);
792 label offProcCount = totalCount - localCount;
793 VecSetValue(preallocOnProc, row, localCount, INSERT_VALUES);
794 VecSetValue(preallocOffProc, row, offProcCount, INSERT_VALUES);
797 MatRestoreRow(connections, 0, &nCols, &cols, &
vals);
798 MatDestroy(&connections);
805 const Vec preallocOnProc,
806 const Vec preallocOffProc)
const
820 PetscScalar normOn, normOff;
821 VecNorm(preallocOnProc, NORM_2, &normOn);
822 VecNorm(preallocOffProc, NORM_2, &normOff);
823 PetscScalar normSum = normOn + normOff;
824 if (normSum < 1.0e-10)
826 FatalErrorIn(
"preallocateJacobianMatrix")
827 <<
"preallocOnProc and preallocOffProc are not allocated!"
828 << abort(FatalError);
831 PetscScalar *onVec, *offVec;
834 VecGetArray(preallocOnProc, &onVec);
835 VecGetArray(preallocOffProc, &offVec);
838 onSize[i] = round(onVec[i]);
843 offSize[i] = round(offVec[i]) + 5;
846 VecRestoreArray(preallocOnProc, &onVec);
847 VecRestoreArray(preallocOffProc, &offVec);
852 MatMPIAIJSetPreallocation(dRMat, NULL, onSize, NULL, offSize);
853 MatSeqAIJSetPreallocation(dRMat, NULL, onSize);
860 const label transposed)
const