23 : modelType_(modelType),
28 daColoring_(
mesh, daOption, daModel, daIndex),
29 daField_(
mesh, daOption, daModel, daIndex)
65 Info <<
"Generating Connectivity for Boundaries:" << endl;
74 wordList writeJacobians;
76 if (writeJacobians.found(
"stateBoundaryCon"))
130 const PetscInt* cols;
131 const PetscScalar*
vals;
133 MatAssemblyBegin(connections, MAT_FINAL_ASSEMBLY);
134 MatAssemblyEnd(connections, MAT_FINAL_ASSEMBLY);
136 MatGetRow(connections, 0, &nCols, &cols, &
vals);
137 MatSetValues(conMat, 1, &idxI, nCols, cols,
vals, INSERT_VALUES);
140 MatRestoreRow(connections, 0, &nCols, &cols, &
vals);
141 MatDestroy(&connections);
166 MatSetUp(*connectedStates);
168 MatZeroEntries(*connectedStates);
175 const Vec preallocOnProc,
176 const Vec preallocOffProc)
const
190 PetscScalar normOn, normOff;
191 VecNorm(preallocOnProc, NORM_2, &normOn);
192 VecNorm(preallocOffProc, NORM_2, &normOff);
193 PetscScalar normSum = normOn + normOff;
194 if (normSum < 1.0e-10)
196 FatalErrorIn(
"preallocateJacobianMatrix")
197 <<
"preallocOnProc and preallocOffProc are not allocated!"
198 << abort(FatalError);
201 PetscScalar *onVec, *offVec;
204 VecGetArray(preallocOnProc, &onVec);
205 VecGetArray(preallocOffProc, &offVec);
208 onSize[i] = round(onVec[i]);
213 offSize[i] = round(offVec[i]) + 5;
216 VecRestoreArray(preallocOnProc, &onVec);
217 VecRestoreArray(preallocOffProc, &offVec);
222 MatMPIAIJSetPreallocation(dRMat, NULL, onSize, NULL, offSize);
223 MatSeqAIJSetPreallocation(dRMat, NULL, onSize);
230 const label transposed)
const
264 MatCreate(PETSC_COMM_WORLD, &
jacCon_);
282 Info <<
"Connectivity matrix initialized." << endl;
297 HashTable<List<List<word>>> stateResConInfo;
298 options.readEntry<HashTable<List<List<word>>>>(
"stateResConInfo", stateResConInfo);
300 label isPrealloc = 0;
307 const label connectedLevelLocal,
308 const wordList connectedStatesLocal,
309 const List<List<word>> connectedStatesInterProc,
408 if (connectedLevelLocal > 3 or connectedLevelLocal < 0)
410 FatalErrorIn(
"connectedLevelLocal not valid") << abort(FatalError);
412 if (addFace != 0 && addFace != 1)
414 FatalErrorIn(
"addFace not valid") << abort(FatalError);
416 if (cellI >=
mesh_.nCells())
418 FatalErrorIn(
"cellI not valid") << abort(FatalError);
425 labelList val1 = {1};
426 labelList vals2 = {1, 1};
427 labelList vals3 = {1, 1, 1};
429 label interProcLevel = connectedStatesInterProc.size();
431 if (connectedLevelLocal == 0)
434 forAll(connectedStatesLocal, idxI)
436 word stateName = connectedStatesLocal[idxI];
442 for (label i = 0; i < compMax; i++)
453 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
458 else if (connectedLevelLocal == 1)
461 forAll(connectedStatesLocal, idxI)
463 word stateName = connectedStatesLocal[idxI];
472 label localCell =
mesh_.cellCells()[cellI][cellJ];
475 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
481 if (interProcLevel == 0)
485 else if (interProcLevel == 1)
492 connectedStatesInterProc,
495 else if (interProcLevel == 2)
502 connectedStatesInterProc,
505 else if (interProcLevel == 3)
512 connectedStatesInterProc,
517 FatalErrorIn(
"interProcLevel not valid") << abort(FatalError);
520 else if (connectedLevelLocal == 2)
524 label localCell =
mesh_.cellCells()[cellI][cellJ];
527 forAll(connectedStatesLocal, idxI)
529 word stateName = connectedStatesLocal[idxI];
538 label localCellK =
mesh_.cellCells()[localCell][cellK];
541 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
548 if (interProcLevel == 0)
552 else if (interProcLevel == 1)
559 connectedStatesInterProc,
562 else if (interProcLevel == 2)
569 connectedStatesInterProc,
572 else if (interProcLevel == 3)
579 connectedStatesInterProc,
584 FatalErrorIn(
"interProcLevel not valid") << abort(FatalError);
588 else if (connectedLevelLocal == 3)
593 label localCell =
mesh_.cellCells()[cellI][cellJ];
596 label localCell2 =
mesh_.cellCells()[localCell][cellK];
599 forAll(connectedStatesLocal, idxI)
601 word stateName = connectedStatesLocal[idxI];
610 label localCellL =
mesh_.cellCells()[localCell2][cellL];
613 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
620 if (interProcLevel == 0)
624 else if (interProcLevel == 1)
631 connectedStatesInterProc,
634 else if (interProcLevel == 2)
641 connectedStatesInterProc,
644 else if (interProcLevel == 3)
651 connectedStatesInterProc,
656 FatalErrorIn(
"interProcLevel not valid") << abort(FatalError);
663 FatalErrorIn(
"connectedLevelLocal not valid") << abort(FatalError);
671 const label idx)
const
682 MatSetValues(conMat, 1, &idxI, 1, &idx, &v, INSERT_VALUES);
712 const polyBoundaryMesh& patches =
mesh_.boundaryMesh();
717 forAll(neiBFaceGlobalCompact, idx)
719 neiBFaceGlobalCompact[idx] = -1;
726 const polyPatch& pp = patches[patchI];
729 label faceIStart = pp.start();
748 syncTools::swapBoundaryFaceList(
mesh_, neiBFaceGlobalCompact);
771 const polyPatch& pp =
mesh_.boundaryMesh()[patchI];
777 label faceStart = pp.start();
778 label patchSize = pp.size();
779 label faceEnd = faceStart + patchSize;
780 if (localFaceI >= faceStart && localFaceI < faceEnd)
783 label countDelta = localFaceI - pp.start();
784 PetscInt bRow = counter + countDelta;
790 counter += patchSize;
796 FatalErrorIn(
"getLocalBndFaceIndex") << abort(FatalError);
832 MatCreate(PETSC_COMM_WORLD, stateBoundaryCon);
839 MatSetFromOptions(*stateBoundaryCon);
840 MatMPIAIJSetPreallocation(*stateBoundaryCon, 1000, NULL, 1000, NULL);
841 MatSeqAIJSetPreallocation(*stateBoundaryCon, 1000, NULL);
842 MatSetOption(*stateBoundaryCon, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
843 MatSetUp(*stateBoundaryCon);
844 MatZeroEntries(*stateBoundaryCon);
846 Mat stateBoundaryConTmp;
847 MatCreate(PETSC_COMM_WORLD, &stateBoundaryConTmp);
854 MatSetFromOptions(stateBoundaryConTmp);
855 MatMPIAIJSetPreallocation(stateBoundaryConTmp, 1000, NULL, 1000, NULL);
856 MatSeqAIJSetPreallocation(stateBoundaryConTmp, 1000, NULL);
857 MatSetOption(stateBoundaryConTmp, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
858 MatSetUp(stateBoundaryConTmp);
859 MatZeroEntries(stateBoundaryConTmp);
873 const polyBoundaryMesh& patches =
mesh_.boundaryMesh();
877 const polyPatch& pp = patches[patchI];
878 const UList<label>& pFaceCells = pp.faceCells();
880 label faceIStart = pp.start();
893 label idxN = pFaceCells[faceI];
900 label localCell =
mesh_.cellCells()[idxN][cellI];
927 MatAssemblyBegin(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
928 MatAssemblyEnd(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
929 MatAssemblyBegin(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
930 MatAssemblyEnd(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
935 const polyPatch& pp = patches[patchI];
936 const UList<label>& pFaceCells = pp.faceCells();
938 label faceIStart = pp.start();
951 label idxN = pFaceCells[faceI];
978 MatAssemblyBegin(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
979 MatAssemblyEnd(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
980 MatAssemblyBegin(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
981 MatAssemblyEnd(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
986 const polyPatch& pp = patches[patchI];
987 const UList<label>& pFaceCells = pp.faceCells();
989 label faceIStart = pp.start();
1002 label idxN = pFaceCells[faceI];
1006 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
1014 stateBoundaryConTmp,
1024 MatAssemblyBegin(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
1025 MatAssemblyEnd(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
1026 MatAssemblyBegin(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1027 MatAssemblyEnd(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1032 const polyPatch& pp = patches[patchI];
1033 const UList<label>& pFaceCells = pp.faceCells();
1035 label faceIStart = pp.start();
1048 label idxN = pFaceCells[faceI];
1062 stateBoundaryConTmp,
1073 MatAssemblyBegin(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
1074 MatAssemblyEnd(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
1083 const polyPatch& pp = patches[patchI];
1084 const UList<label>& pFaceCells = pp.faceCells();
1086 label faceIStart = pp.start();
1099 label idxN = pFaceCells[faceI];
1106 label localCell =
mesh_.cellCells()[idxN][cellI];
1107 labelList val1 = {3};
1109 List<List<word>> connectedStates(0);
1111 stateBoundaryConTmp,
1122 MatAssemblyBegin(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1123 MatAssemblyEnd(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1128 const polyPatch& pp = patches[patchI];
1129 const UList<label>& pFaceCells = pp.faceCells();
1131 label faceIStart = pp.start();
1144 label idxN = pFaceCells[faceI];
1146 labelList vals2 = {2, 3};
1148 List<List<word>> connectedStates(0);
1150 stateBoundaryConTmp,
1160 MatAssemblyBegin(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1161 MatAssemblyEnd(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1166 const polyPatch& pp = patches[patchI];
1167 const UList<label>& pFaceCells = pp.faceCells();
1169 label faceIStart = pp.start();
1182 label idxN = pFaceCells[faceI];
1184 labelList vals1 = {2};
1186 List<List<word>> connectedStates(0);
1188 stateBoundaryConTmp,
1198 MatAssemblyBegin(stateBoundaryConTmp, MAT_FINAL_ASSEMBLY);
1199 MatAssemblyEnd(stateBoundaryConTmp, MAT_FINAL_ASSEMBLY);
1208 Mat* stateBoundaryCon,
1209 Mat* stateBoundaryConTmp)
1232 const PetscInt* cols;
1233 const PetscScalar*
vals;
1236 const PetscInt* cols1;
1237 const PetscScalar* vals1;
1240 MatDestroy(stateBoundaryCon);
1241 MatCreate(PETSC_COMM_WORLD, stateBoundaryCon);
1248 MatSetFromOptions(*stateBoundaryCon);
1249 MatMPIAIJSetPreallocation(*stateBoundaryCon, 1000, NULL, 1000, NULL);
1250 MatSeqAIJSetPreallocation(*stateBoundaryCon, 1000, NULL);
1251 MatSetOption(*stateBoundaryCon, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
1252 MatSetUp(*stateBoundaryCon);
1253 MatZeroEntries(*stateBoundaryCon);
1256 PetscInt Istart, Iend;
1257 MatGetOwnershipRange(*stateBoundaryConTmp, &Istart, &Iend);
1258 for (PetscInt i = Istart; i < Iend; i++)
1260 MatGetRow(*stateBoundaryConTmp, i, &nCols, &cols, &
vals);
1261 for (PetscInt j = 0; j < nCols; j++)
1263 MatSetValue(*stateBoundaryCon, i, cols[j],
vals[j], INSERT_VALUES);
1265 MatRestoreRow(*stateBoundaryConTmp, i, &nCols, &cols, &
vals);
1267 MatAssemblyBegin(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
1268 MatAssemblyEnd(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
1270 MatDestroy(stateBoundaryConTmp);
1273 MatConvert(*stateBoundaryCon, MATSAME, MAT_INITIAL_MATRIX, stateBoundaryConTmp);
1287 const polyBoundaryMesh& patches =
mesh_.boundaryMesh();
1291 const polyPatch& pp = patches[patchI];
1292 const UList<label>& pFaceCells = pp.faceCells();
1293 label faceIStart = pp.start();
1301 label idxN = pFaceCells[faceI];
1305 label localCell =
mesh_.cellCells()[idxN][cellI];
1306 labelList val1 = {3};
1308 List<List<word>> connectedStates(0);
1310 *stateBoundaryConTmp,
1320 MatAssemblyBegin(*stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1321 MatAssemblyEnd(*stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1326 const polyPatch& pp = patches[patchI];
1327 const UList<label>& pFaceCells = pp.faceCells();
1328 label faceIStart = pp.start();
1336 label idxN = pFaceCells[faceI];
1338 labelList vals2 = {2, 3};
1340 List<List<word>> connectedStates(0);
1342 *stateBoundaryConTmp,
1351 MatAssemblyBegin(*stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1352 MatAssemblyEnd(*stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1357 const polyPatch& pp = patches[patchI];
1358 const UList<label>& pFaceCells = pp.faceCells();
1359 label faceIStart = pp.start();
1367 label idxN = pFaceCells[faceI];
1369 labelList vals1 = {2};
1371 List<List<word>> connectedStates(0);
1373 *stateBoundaryConTmp,
1382 MatAssemblyBegin(*stateBoundaryConTmp, MAT_FINAL_ASSEMBLY);
1383 MatAssemblyEnd(*stateBoundaryConTmp, MAT_FINAL_ASSEMBLY);
1390 MatCreate(PETSC_COMM_WORLD, &tmpMat);
1397 MatSetFromOptions(tmpMat);
1398 MatMPIAIJSetPreallocation(tmpMat, 1000, NULL, 1000, NULL);
1399 MatSeqAIJSetPreallocation(tmpMat, 1000, NULL);
1400 MatSetOption(tmpMat, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
1402 MatZeroEntries(tmpMat);
1403 for (PetscInt i = Istart; i < Iend; i++)
1405 MatGetRow(*stateBoundaryCon, i, &nCols, &cols, &
vals);
1406 MatGetRow(*stateBoundaryConTmp, i, &nCols1, &cols1, &vals1);
1407 for (PetscInt j = 0; j < nCols1; j++)
1412 PetscScalar newVal = vals1[j];
1413 PetscInt newCol = cols1[j];
1414 for (PetscInt
k = 0;
k < nCols;
k++)
1416 if (
int(cols[
k]) ==
int(cols1[j]))
1423 MatSetValue(tmpMat, i, newCol, newVal, INSERT_VALUES);
1425 MatRestoreRow(*stateBoundaryCon, i, &nCols, &cols, &
vals);
1426 MatRestoreRow(*stateBoundaryConTmp, i, &nCols1, &cols1, &vals1);
1428 MatAssemblyBegin(tmpMat, MAT_FINAL_ASSEMBLY);
1429 MatAssemblyEnd(tmpMat, MAT_FINAL_ASSEMBLY);
1432 MatDestroy(stateBoundaryCon);
1433 MatConvert(tmpMat, MATSAME, MAT_INITIAL_MATRIX, stateBoundaryCon);
1434 MatAssemblyBegin(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
1435 MatAssemblyEnd(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
1437 MatDestroy(stateBoundaryConTmp);
1438 MatDestroy(&tmpMat);
1455 PetscInt nCols, colI;
1456 const PetscInt* cols;
1457 const PetscScalar*
vals;
1458 PetscInt Istart, Iend;
1464 labelList adjStateID4GlobalAdjIdx;
1469 MatCreate(PETSC_COMM_WORLD, stateBoundaryConID);
1471 *stateBoundaryConID,
1476 MatSetFromOptions(*stateBoundaryConID);
1477 MatMPIAIJSetPreallocation(*stateBoundaryConID, 1000, NULL, 1000, NULL);
1478 MatSeqAIJSetPreallocation(*stateBoundaryConID, 1000, NULL);
1479 MatSetOption(*stateBoundaryConID, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
1480 MatSetUp(*stateBoundaryConID);
1481 MatZeroEntries(*stateBoundaryConID);
1486 for (PetscInt i = Istart; i < Iend; i++)
1489 for (PetscInt j = 0; j < nCols; j++)
1494 valIn = adjStateID4GlobalAdjIdx[colI];
1495 MatSetValue(*stateBoundaryConID, i, colI, valIn, INSERT_VALUES);
1501 adjStateID4GlobalAdjIdx.clear();
1503 MatAssemblyBegin(*stateBoundaryConID, MAT_FINAL_ASSEMBLY);
1504 MatAssemblyEnd(*stateBoundaryConID, MAT_FINAL_ASSEMBLY);
1513 const word stateName,
1514 const PetscScalar val)
1547 PetscInt idxJ, idxI;
1558 for (label i = 0; i < compMax; i++)
1562 MatSetValues(conMat, 1, &idxI, 1, &idxJ, &val, INSERT_VALUES);
1572 const word stateName,
1573 const PetscScalar val)
1611 PetscInt idxJ, idxI;
1618 localCellJ =
mesh_.cellCells()[cellI][cellJ];
1626 for (label i = 0; i < compMax; i++)
1630 MatSetValues(conMat, 1, &idxI, 1, &idxJ, &val, INSERT_VALUES);
1641 const word stateName,
1642 const PetscScalar val)
1676 PetscInt idxJ, idxI;
1681 const labelList& faces =
mesh_.cells()[cellI];
1687 MatSetValues(conMat, 1, &idxI, 1, &idxJ, &val, INSERT_VALUES);
1698 const List<List<word>> connectedStates,
1699 const label addFaces)
1767 if (v.size() != connectedStates.size() && connectedStates.size() != 0)
1769 FatalErrorIn(
"") <<
"size of v and connectedStates are not identical!"
1770 << abort(FatalError);
1773 PetscInt idxJ, idxI, bRow, bRowGlobal;
1775 const PetscInt* cols;
1776 const PetscScalar*
vals;
1779 const PetscInt* colsID;
1780 const PetscScalar* valsID;
1783 labelListList connectedStateIDs(connectedStates.size());
1784 forAll(connectedStates, idxI)
1786 forAll(connectedStates[idxI], idxJ)
1788 word stateName = connectedStates[idxI][idxJ];
1790 connectedStateIDs[idxI].append(stateID);
1797 const labelList& faces =
mesh_.cells()[cellI];
1800 label level = v.size();
1802 for (label lv = level; lv >= 1; lv--)
1807 label currFace = faces[faceI];
1824 if (connectedStates.size() != 0)
1832 for (label i = 0; i < nCols; i++)
1835 label val = round(
vals[i]);
1838 label stateID = -9999;
1840 if (connectedStates.size() != 0)
1842 stateID = round(valsID[i]);
1845 if (connectedStates.size() == 0)
1849 else if (connectedStateIDs[lv - 1].found(stateID))
1858 if (val == lv && addState)
1861 PetscScalar valIn = v[lv - 1];
1862 MatSetValues(conMat, 1, &idxI, 1, &idxJ, &valIn, INSERT_VALUES);
1864 if (val == 10 && addFaces)
1867 PetscScalar valIn = v[lv - 1];
1868 MatSetValues(conMat, 1, &idxI, 1, &idxJ, &valIn, INSERT_VALUES);
1874 if (connectedStates.size() != 0)
1901 Info <<
"Checking if Coloring file exists.." << endl;
1902 label nProcs = Pstream::nProcs();
1903 word fileName =
modelType_ +
"Coloring" + postFix +
"_" + Foam::name(nProcs);
1904 word checkFile = fileName +
".bin";
1905 std::ifstream fIn(checkFile);
1908 Info << checkFile <<
" exists." << endl;
1941 Info <<
"Calculating " <<
modelType_ <<
" Coloring.." << endl;
1942 label nProcs = Pstream::nProcs();
1943 word fileName =
modelType_ +
"Coloring" + postFix +
"_" + Foam::name(nProcs);
1955 PetscScalar* jacConColorsArray;
1959 for (label i = Istart; i < Iend; i++)
1961 label relIdx = i - Istart;
1962 jacConColorsArray[relIdx] = i * 1.0;
1974 Info <<
"Writing Colors to " << fileName << endl;
2002 label nProcs = Pstream::nProcs();
2003 word fileName =
modelType_ +
"Coloring" + postFix +
"_" + Foam::name(nProcs);
2004 Info <<
"Reading Coloring " << fileName << endl;
2032 HashTable<List<List<word>>> stateResConInfo;
2033 options.readEntry<HashTable<List<List<word>>>>(
"stateResConInfo", stateResConInfo);
2035 label isPrealloc = 1;
2040 const HashTable<List<List<word>>>& stateResConInfo,
2041 const label isPrealloc)
2153 Mat connectedStatesP;
2156 const PetscInt* cols;
2157 const PetscScalar*
vals;
2160 const PetscInt* colsID;
2161 const PetscScalar* valsID;
2176 Info <<
"Computing preallocating vectors for Jacobian connectivity mat" << endl;
2180 Info <<
"Setup Jacobian connectivity mat" << endl;
2192 word resName = stateName +
"Res";
2203 label maxConLevel = stateResConInfo[resName].size() - 1;
2214 for (label comp = 0; comp < compMax; comp++)
2221 forAll(stateResConInfo[resName], idxJ)
2225 wordList connectedStatesLocal(0);
2226 forAll(stateResConInfo[resName][idxJ], idxK)
2228 word conName = stateResConInfo[resName][idxJ][idxK];
2233 connectedStatesLocal.append(conName);
2238 List<List<word>> connectedStatesInterProc;
2242 connectedStatesInterProc.setSize(0);
2244 else if (idxJ != maxConLevel)
2246 connectedStatesInterProc.setSize(maxConLevel - idxJ + 1);
2247 for (label
k = 0;
k < maxConLevel - idxJ + 1;
k++)
2249 label conSize = stateResConInfo[resName][
k + idxJ].size();
2250 for (label l = 0; l < conSize; l++)
2252 word conName = stateResConInfo[resName][
k + idxJ][l];
2257 connectedStatesInterProc[
k].append(conName);
2264 connectedStatesInterProc.setSize(1);
2265 label conSize = stateResConInfo[resName][maxConLevel].size();
2266 for (label l = 0; l < conSize; l++)
2268 word conName = stateResConInfo[resName][maxConLevel][l];
2273 connectedStatesInterProc[0].append(conName);
2282 word conName =
stateInfo_[
"surfaceScalarStates"][idxK];
2283 if (stateResConInfo[resName][idxJ].found(conName))
2292 && this->addPhi4PIV(stateName, cellI, comp))
2302 connectedStatesLocal,
2303 connectedStatesInterProc,
2338 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
2339 word resName = stateName +
"Res";
2342 label maxConLevel = stateResConInfo[resName].size() - 1;
2351 label idxO = -1, idxN = -1;
2354 idxO =
mesh_.owner()[faceI];
2355 idxN =
mesh_.neighbour()[faceI];
2363 const UList<label>& pFaceCells =
mesh_.boundaryMesh()[patchIdx].faceCells();
2364 idxN = pFaceCells[faceIdx];
2368 forAll(stateResConInfo[resName], idxJ)
2372 wordList connectedStatesLocal(0);
2373 forAll(stateResConInfo[resName][idxJ], idxK)
2375 word conName = stateResConInfo[resName][idxJ][idxK];
2380 connectedStatesLocal.append(conName);
2385 List<List<word>> connectedStatesInterProc;
2389 connectedStatesInterProc.setSize(0);
2391 else if (idxJ != maxConLevel)
2393 connectedStatesInterProc.setSize(maxConLevel - idxJ + 1);
2394 for (label
k = 0;
k < maxConLevel - idxJ + 1;
k++)
2396 label conSize = stateResConInfo[resName][
k + idxJ].size();
2397 for (label l = 0; l < conSize; l++)
2399 word conName = stateResConInfo[resName][
k + idxJ][l];
2404 connectedStatesInterProc[
k].append(conName);
2411 connectedStatesInterProc.setSize(1);
2412 label conSize = stateResConInfo[resName][maxConLevel].size();
2413 for (label l = 0; l < conSize; l++)
2415 word conName = stateResConInfo[resName][maxConLevel][l];
2420 connectedStatesInterProc[0].append(conName);
2429 word conName =
stateInfo_[
"surfaceScalarStates"][idxK];
2442 levelCheck = idxJ - 1;
2445 if (stateResConInfo[resName][levelCheck].found(conName))
2454 && this->addPhi4PIV(stateName, faceI))
2464 connectedStatesLocal,
2465 connectedStatesInterProc,
2475 connectedStatesLocal,
2476 connectedStatesInterProc,
2491 label maxLevel = stateResConInfo[resName].size();
2493 if (
mesh_.boundaryMesh()[patchIdx].coupled())
2500 for (label i = 0; i < nCols; i++)
2502 PetscInt idxJ = cols[i];
2503 label val = round(
vals[i]);
2506 label stateID = round(valsID[i]);
2512 if (val != 10 && val < maxLevel + 1)
2514 if (stateResConInfo[resName][val - 1].found(conName))
2519 if (addState == 1 && val < maxLevel + 1 && val > 0)
2564 wordList writeJacobians;
2566 if (writeJacobians.found(
"dRdWTPrealloc"))
2576 MatAssemblyBegin(
jacCon_, MAT_FINAL_ASSEMBLY);
2577 MatAssemblyEnd(
jacCon_, MAT_FINAL_ASSEMBLY);
2580 wordList writeJacobians;
2582 if (writeJacobians.found(
"dRdWCon"))
2593 Info <<
"Preallocating state Jacobian connectivity mat: finished!" << endl;
2597 Info <<
"Setup state Jacobian connectivity mat: finished!" << endl;
2604 Vec preallocOffProc,
2605 Vec preallocOnProcT,
2606 Vec preallocOffProcT,
2634 PetscScalar v = 1.0;
2636 const PetscInt* cols;
2637 const PetscScalar*
vals;
2639 MatAssemblyBegin(connections, MAT_FINAL_ASSEMBLY);
2640 MatAssemblyEnd(connections, MAT_FINAL_ASSEMBLY);
2649 MatGetRow(connections, 0, &nCols, &cols, &
vals);
2653 label totalCount = 0;
2654 label localCount = 0;
2656 for (label j = 0; j < nCols; j++)
2659 scalar val =
vals[j];
2664 label idx = cols[j];
2666 if (colMin <= idx && idx < colMax)
2669 VecSetValue(preallocOnProcT, idx, v, ADD_VALUES);
2675 VecSetValue(preallocOffProcT, idx, v, ADD_VALUES);
2680 label offProcCount = totalCount - localCount;
2681 VecSetValue(preallocOnProc, row, localCount, INSERT_VALUES);
2682 VecSetValue(preallocOffProc, row, offProcCount, INSERT_VALUES);
2685 MatRestoreRow(connections, 0, &nCols, &cols, &
vals);
2686 MatDestroy(&connections);
2693 Vec coloredColumn)
const
2775 VecZeroEntries(colorIdx);
2783 const PetscScalar* jacConColorsArray;
2784 PetscScalar* colorIdxArray;
2786 VecGetArray(colorIdx, &colorIdxArray);
2789 for (label j = Istart; j < Iend; j++)
2791 label idx = j - Istart;
2796 colorIdxArray[idx] = j + 1;
2800 VecRestoreArray(colorIdx, &colorIdxArray);
2806 VecSet(coloredColumn, -1);
2808 MatMultAdd(
jacCon_, colorIdx, coloredColumn, coloredColumn);
2811 VecDestroy(&colorIdx);
2816 PetscScalar val = colorI * 1.0;
2817 VecSet(coloredColumn, val);
2819 VecAssemblyBegin(coloredColumn);
2820 VecAssemblyEnd(coloredColumn);
2837 Info <<
"pressureInletVelocity detected, applying special treatment for connectivity." << endl;
2847 Info <<
"Calculating pressureInletVelocity state vec..." << endl;
2851 mesh_.time().timeName(),
2853 IOobject::READ_IF_PRESENT,
2857 dimensionedVector(
"U", dimensionSet(0, 1, -1, 0, 0, 0, 0), vector::zero),
2858 zeroGradientFvPatchField<vector>::typeName);
2860 forAll(
U.boundaryField(), patchI)
2862 if (
U.boundaryFieldRef()[patchI].type() ==
"pressureInletVelocity")
2864 const UList<label>& pFaceCells =
mesh_.boundaryMesh()[patchI].faceCells();
2865 forAll(
U.boundaryFieldRef()[patchI], faceI)
2868 label faceCellI = pFaceCells[faceI];
2874 label faceCellJ =
mesh_.cellCells()[faceCellI][cellJ];
2879 label faceCellK =
mesh_.cellCells()[faceCellI][cellJ];
2890 wordList writeJacobians;
2892 if (writeJacobians.found(
"isPIVVec"))
2919 label cellFaceI =
mesh_.cells()[cellI][faceI];
2921 VecSetValue(isPIV, rowI, 1.0, INSERT_VALUES);
2933 for (label comp = 0; comp < compMax; comp++)
2936 VecSetValue(isPIV, rowI, 1.0, INSERT_VALUES);
2943 const word stateName,
2949 PetscScalar* isPIVArray;