28 : modelType_(modelType),
54 if (
daOption.getAllOptions().lookupOrDefault<label>(
"debug", 0))
56 Info <<
"Selecting " << modelType <<
" for DAJacCon" << endl;
59 dictionaryConstructorTable::iterator cstrIter =
60 dictionaryConstructorTablePtr_->find(modelType);
63 if (cstrIter == dictionaryConstructorTablePtr_->end())
74 <<
"Unknown DAJacCon type "
75 << modelType << nl << nl
76 <<
"Valid DAJacCon types:" << endl
77 << dictionaryConstructorTablePtr_->sortedToc()
82 return autoPtr<DAJacCon>(
108 Info <<
"Generating Connectivity for Boundaries:" << endl;
117 wordList writeJacobians;
119 if (writeJacobians.found(
"stateBoundaryCon"))
145 const PetscInt* cols;
146 const PetscScalar*
vals;
148 MatAssemblyBegin(connections, MAT_FINAL_ASSEMBLY);
149 MatAssemblyEnd(connections, MAT_FINAL_ASSEMBLY);
151 MatGetRow(connections, 0, &nCols, &cols, &
vals);
152 MatSetValues(conMat, 1, &idxI, nCols, cols,
vals, INSERT_VALUES);
155 MatRestoreRow(connections, 0, &nCols, &cols, &
vals);
156 MatDestroy(&connections);
181 MatSetUp(*connectedStates);
183 MatZeroEntries(*connectedStates);
191 const label connectedLevelLocal,
192 const wordList connectedStatesLocal,
193 const List<List<word>> connectedStatesInterProc,
292 if (connectedLevelLocal > 3 or connectedLevelLocal < 0)
294 FatalErrorIn(
"connectedLevelLocal not valid") << abort(FatalError);
296 if (addFace != 0 && addFace != 1)
298 FatalErrorIn(
"addFace not valid") << abort(FatalError);
300 if (cellI >=
mesh_.nCells())
302 FatalErrorIn(
"cellI not valid") << abort(FatalError);
309 labelList val1 = {1};
310 labelList vals2 = {1, 1};
311 labelList vals3 = {1, 1, 1};
313 label interProcLevel = connectedStatesInterProc.size();
315 if (connectedLevelLocal == 0)
318 forAll(connectedStatesLocal, idxI)
320 word stateName = connectedStatesLocal[idxI];
326 for (label i = 0; i < compMax; i++)
337 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
342 else if (connectedLevelLocal == 1)
345 forAll(connectedStatesLocal, idxI)
347 word stateName = connectedStatesLocal[idxI];
356 label localCell =
mesh_.cellCells()[cellI][cellJ];
359 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
365 if (interProcLevel == 0)
369 else if (interProcLevel == 1)
376 connectedStatesInterProc,
379 else if (interProcLevel == 2)
386 connectedStatesInterProc,
389 else if (interProcLevel == 3)
396 connectedStatesInterProc,
401 FatalErrorIn(
"interProcLevel not valid") << abort(FatalError);
404 else if (connectedLevelLocal == 2)
408 label localCell =
mesh_.cellCells()[cellI][cellJ];
411 forAll(connectedStatesLocal, idxI)
413 word stateName = connectedStatesLocal[idxI];
422 label localCellK =
mesh_.cellCells()[localCell][cellK];
425 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
432 if (interProcLevel == 0)
436 else if (interProcLevel == 1)
443 connectedStatesInterProc,
446 else if (interProcLevel == 2)
453 connectedStatesInterProc,
456 else if (interProcLevel == 3)
463 connectedStatesInterProc,
468 FatalErrorIn(
"interProcLevel not valid") << abort(FatalError);
472 else if (connectedLevelLocal == 3)
477 label localCell =
mesh_.cellCells()[cellI][cellJ];
480 label localCell2 =
mesh_.cellCells()[localCell][cellK];
483 forAll(connectedStatesLocal, idxI)
485 word stateName = connectedStatesLocal[idxI];
494 label localCellL =
mesh_.cellCells()[localCell2][cellL];
497 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
504 if (interProcLevel == 0)
508 else if (interProcLevel == 1)
515 connectedStatesInterProc,
518 else if (interProcLevel == 2)
525 connectedStatesInterProc,
528 else if (interProcLevel == 3)
535 connectedStatesInterProc,
540 FatalErrorIn(
"interProcLevel not valid") << abort(FatalError);
547 FatalErrorIn(
"connectedLevelLocal not valid") << abort(FatalError);
555 const label idx)
const
566 MatSetValues(conMat, 1, &idxI, 1, &idx, &v, INSERT_VALUES);
596 const polyBoundaryMesh& patches =
mesh_.boundaryMesh();
601 forAll(neiBFaceGlobalCompact, idx)
603 neiBFaceGlobalCompact[idx] = -1;
610 const polyPatch& pp = patches[patchI];
613 label faceIStart = pp.start();
632 syncTools::swapBoundaryFaceList(
mesh_, neiBFaceGlobalCompact);
655 const polyPatch& pp =
mesh_.boundaryMesh()[patchI];
661 label faceStart = pp.start();
662 label patchSize = pp.size();
663 label faceEnd = faceStart + patchSize;
664 if (localFaceI >= faceStart && localFaceI < faceEnd)
667 label countDelta = localFaceI - pp.start();
668 PetscInt bRow = counter + countDelta;
674 counter += patchSize;
680 FatalErrorIn(
"getLocalBndFaceIndex") << abort(FatalError);
716 MatCreate(PETSC_COMM_WORLD, stateBoundaryCon);
723 MatSetFromOptions(*stateBoundaryCon);
724 MatMPIAIJSetPreallocation(*stateBoundaryCon, 1000, NULL, 1000, NULL);
725 MatSeqAIJSetPreallocation(*stateBoundaryCon, 1000, NULL);
726 MatSetOption(*stateBoundaryCon, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
727 MatSetUp(*stateBoundaryCon);
728 MatZeroEntries(*stateBoundaryCon);
730 Mat stateBoundaryConTmp;
731 MatCreate(PETSC_COMM_WORLD, &stateBoundaryConTmp);
738 MatSetFromOptions(stateBoundaryConTmp);
739 MatMPIAIJSetPreallocation(stateBoundaryConTmp, 1000, NULL, 1000, NULL);
740 MatSeqAIJSetPreallocation(stateBoundaryConTmp, 1000, NULL);
741 MatSetOption(stateBoundaryConTmp, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
742 MatSetUp(stateBoundaryConTmp);
743 MatZeroEntries(stateBoundaryConTmp);
757 const polyBoundaryMesh& patches =
mesh_.boundaryMesh();
761 const polyPatch& pp = patches[patchI];
762 const UList<label>& pFaceCells = pp.faceCells();
764 label faceIStart = pp.start();
777 label idxN = pFaceCells[faceI];
784 label localCell =
mesh_.cellCells()[idxN][cellI];
811 MatAssemblyBegin(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
812 MatAssemblyEnd(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
813 MatAssemblyBegin(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
814 MatAssemblyEnd(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
819 const polyPatch& pp = patches[patchI];
820 const UList<label>& pFaceCells = pp.faceCells();
822 label faceIStart = pp.start();
835 label idxN = pFaceCells[faceI];
862 MatAssemblyBegin(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
863 MatAssemblyEnd(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
864 MatAssemblyBegin(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
865 MatAssemblyEnd(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
870 const polyPatch& pp = patches[patchI];
871 const UList<label>& pFaceCells = pp.faceCells();
873 label faceIStart = pp.start();
886 label idxN = pFaceCells[faceI];
890 word stateName =
stateInfo_[
"surfaceScalarStates"][idxI];
908 MatAssemblyBegin(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
909 MatAssemblyEnd(*stateBoundaryCon, MAT_FLUSH_ASSEMBLY);
910 MatAssemblyBegin(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
911 MatAssemblyEnd(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
916 const polyPatch& pp = patches[patchI];
917 const UList<label>& pFaceCells = pp.faceCells();
919 label faceIStart = pp.start();
932 label idxN = pFaceCells[faceI];
957 MatAssemblyBegin(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
958 MatAssemblyEnd(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
967 const polyPatch& pp = patches[patchI];
968 const UList<label>& pFaceCells = pp.faceCells();
970 label faceIStart = pp.start();
983 label idxN = pFaceCells[faceI];
990 label localCell =
mesh_.cellCells()[idxN][cellI];
991 labelList val1 = {3};
993 List<List<word>> connectedStates(0);
1006 MatAssemblyBegin(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1007 MatAssemblyEnd(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1012 const polyPatch& pp = patches[patchI];
1013 const UList<label>& pFaceCells = pp.faceCells();
1015 label faceIStart = pp.start();
1028 label idxN = pFaceCells[faceI];
1030 labelList vals2 = {2, 3};
1032 List<List<word>> connectedStates(0);
1034 stateBoundaryConTmp,
1044 MatAssemblyBegin(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1045 MatAssemblyEnd(stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1050 const polyPatch& pp = patches[patchI];
1051 const UList<label>& pFaceCells = pp.faceCells();
1053 label faceIStart = pp.start();
1066 label idxN = pFaceCells[faceI];
1068 labelList vals1 = {2};
1070 List<List<word>> connectedStates(0);
1072 stateBoundaryConTmp,
1082 MatAssemblyBegin(stateBoundaryConTmp, MAT_FINAL_ASSEMBLY);
1083 MatAssemblyEnd(stateBoundaryConTmp, MAT_FINAL_ASSEMBLY);
1092 Mat* stateBoundaryCon,
1093 Mat* stateBoundaryConTmp)
1116 const PetscInt* cols;
1117 const PetscScalar*
vals;
1120 const PetscInt* cols1;
1121 const PetscScalar* vals1;
1124 MatDestroy(stateBoundaryCon);
1125 MatCreate(PETSC_COMM_WORLD, stateBoundaryCon);
1132 MatSetFromOptions(*stateBoundaryCon);
1133 MatMPIAIJSetPreallocation(*stateBoundaryCon, 1000, NULL, 1000, NULL);
1134 MatSeqAIJSetPreallocation(*stateBoundaryCon, 1000, NULL);
1135 MatSetOption(*stateBoundaryCon, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
1136 MatSetUp(*stateBoundaryCon);
1137 MatZeroEntries(*stateBoundaryCon);
1140 PetscInt Istart, Iend;
1141 MatGetOwnershipRange(*stateBoundaryConTmp, &Istart, &Iend);
1142 for (PetscInt i = Istart; i < Iend; i++)
1144 MatGetRow(*stateBoundaryConTmp, i, &nCols, &cols, &
vals);
1145 for (PetscInt j = 0; j < nCols; j++)
1147 MatSetValue(*stateBoundaryCon, i, cols[j],
vals[j], INSERT_VALUES);
1149 MatRestoreRow(*stateBoundaryConTmp, i, &nCols, &cols, &
vals);
1151 MatAssemblyBegin(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
1152 MatAssemblyEnd(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
1154 MatDestroy(stateBoundaryConTmp);
1157 MatConvert(*stateBoundaryCon, MATSAME, MAT_INITIAL_MATRIX, stateBoundaryConTmp);
1171 const polyBoundaryMesh& patches =
mesh_.boundaryMesh();
1175 const polyPatch& pp = patches[patchI];
1176 const UList<label>& pFaceCells = pp.faceCells();
1177 label faceIStart = pp.start();
1185 label idxN = pFaceCells[faceI];
1189 label localCell =
mesh_.cellCells()[idxN][cellI];
1190 labelList val1 = {3};
1192 List<List<word>> connectedStates(0);
1194 *stateBoundaryConTmp,
1204 MatAssemblyBegin(*stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1205 MatAssemblyEnd(*stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1210 const polyPatch& pp = patches[patchI];
1211 const UList<label>& pFaceCells = pp.faceCells();
1212 label faceIStart = pp.start();
1220 label idxN = pFaceCells[faceI];
1222 labelList vals2 = {2, 3};
1224 List<List<word>> connectedStates(0);
1226 *stateBoundaryConTmp,
1235 MatAssemblyBegin(*stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1236 MatAssemblyEnd(*stateBoundaryConTmp, MAT_FLUSH_ASSEMBLY);
1241 const polyPatch& pp = patches[patchI];
1242 const UList<label>& pFaceCells = pp.faceCells();
1243 label faceIStart = pp.start();
1251 label idxN = pFaceCells[faceI];
1253 labelList vals1 = {2};
1255 List<List<word>> connectedStates(0);
1257 *stateBoundaryConTmp,
1266 MatAssemblyBegin(*stateBoundaryConTmp, MAT_FINAL_ASSEMBLY);
1267 MatAssemblyEnd(*stateBoundaryConTmp, MAT_FINAL_ASSEMBLY);
1274 MatCreate(PETSC_COMM_WORLD, &tmpMat);
1281 MatSetFromOptions(tmpMat);
1282 MatMPIAIJSetPreallocation(tmpMat, 1000, NULL, 1000, NULL);
1283 MatSeqAIJSetPreallocation(tmpMat, 1000, NULL);
1284 MatSetOption(tmpMat, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
1286 MatZeroEntries(tmpMat);
1287 for (PetscInt i = Istart; i < Iend; i++)
1289 MatGetRow(*stateBoundaryCon, i, &nCols, &cols, &
vals);
1290 MatGetRow(*stateBoundaryConTmp, i, &nCols1, &cols1, &vals1);
1291 for (PetscInt j = 0; j < nCols1; j++)
1296 PetscScalar newVal = vals1[j];
1297 PetscInt newCol = cols1[j];
1298 for (PetscInt
k = 0;
k < nCols;
k++)
1300 if (
int(cols[
k]) ==
int(cols1[j]))
1307 MatSetValue(tmpMat, i, newCol, newVal, INSERT_VALUES);
1309 MatRestoreRow(*stateBoundaryCon, i, &nCols, &cols, &
vals);
1310 MatRestoreRow(*stateBoundaryConTmp, i, &nCols1, &cols1, &vals1);
1312 MatAssemblyBegin(tmpMat, MAT_FINAL_ASSEMBLY);
1313 MatAssemblyEnd(tmpMat, MAT_FINAL_ASSEMBLY);
1316 MatDestroy(stateBoundaryCon);
1317 MatConvert(tmpMat, MATSAME, MAT_INITIAL_MATRIX, stateBoundaryCon);
1318 MatAssemblyBegin(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
1319 MatAssemblyEnd(*stateBoundaryCon, MAT_FINAL_ASSEMBLY);
1321 MatDestroy(stateBoundaryConTmp);
1322 MatDestroy(&tmpMat);
1339 PetscInt nCols, colI;
1340 const PetscInt* cols;
1341 const PetscScalar*
vals;
1342 PetscInt Istart, Iend;
1348 labelList adjStateID4GlobalAdjIdx;
1353 MatCreate(PETSC_COMM_WORLD, stateBoundaryConID);
1355 *stateBoundaryConID,
1360 MatSetFromOptions(*stateBoundaryConID);
1361 MatMPIAIJSetPreallocation(*stateBoundaryConID, 1000, NULL, 1000, NULL);
1362 MatSeqAIJSetPreallocation(*stateBoundaryConID, 1000, NULL);
1363 MatSetOption(*stateBoundaryConID, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE);
1364 MatSetUp(*stateBoundaryConID);
1365 MatZeroEntries(*stateBoundaryConID);
1370 for (PetscInt i = Istart; i < Iend; i++)
1373 for (PetscInt j = 0; j < nCols; j++)
1378 valIn = adjStateID4GlobalAdjIdx[colI];
1379 MatSetValue(*stateBoundaryConID, i, colI, valIn, INSERT_VALUES);
1385 adjStateID4GlobalAdjIdx.clear();
1387 MatAssemblyBegin(*stateBoundaryConID, MAT_FINAL_ASSEMBLY);
1388 MatAssemblyEnd(*stateBoundaryConID, MAT_FINAL_ASSEMBLY);
1397 const word stateName,
1398 const PetscScalar val)
1431 PetscInt idxJ, idxI;
1442 for (label i = 0; i < compMax; i++)
1446 MatSetValues(conMat, 1, &idxI, 1, &idxJ, &val, INSERT_VALUES);
1456 const word stateName,
1457 const PetscScalar val)
1495 PetscInt idxJ, idxI;
1502 localCellJ =
mesh_.cellCells()[cellI][cellJ];
1510 for (label i = 0; i < compMax; i++)
1514 MatSetValues(conMat, 1, &idxI, 1, &idxJ, &val, INSERT_VALUES);
1525 const word stateName,
1526 const PetscScalar val)
1560 PetscInt idxJ, idxI;
1565 const labelList& faces =
mesh_.cells()[cellI];
1571 MatSetValues(conMat, 1, &idxI, 1, &idxJ, &val, INSERT_VALUES);
1582 const List<List<word>> connectedStates,
1583 const label addFaces)
1651 if (v.size() != connectedStates.size() && connectedStates.size() != 0)
1653 FatalErrorIn(
"") <<
"size of v and connectedStates are not identical!"
1654 << abort(FatalError);
1657 PetscInt idxJ, idxI, bRow, bRowGlobal;
1659 const PetscInt* cols;
1660 const PetscScalar*
vals;
1663 const PetscInt* colsID;
1664 const PetscScalar* valsID;
1667 labelListList connectedStateIDs(connectedStates.size());
1668 forAll(connectedStates, idxI)
1670 forAll(connectedStates[idxI], idxJ)
1672 word stateName = connectedStates[idxI][idxJ];
1674 connectedStateIDs[idxI].append(stateID);
1681 const labelList& faces =
mesh_.cells()[cellI];
1684 label level = v.size();
1686 for (label lv = level; lv >= 1; lv--)
1691 label currFace = faces[faceI];
1708 if (connectedStates.size() != 0)
1716 for (label i = 0; i < nCols; i++)
1719 label val = round(
vals[i]);
1722 label stateID = -9999;
1724 if (connectedStates.size() != 0)
1726 stateID = round(valsID[i]);
1729 if (connectedStates.size() == 0)
1733 else if (DAUtility::isInList<label>(stateID, connectedStateIDs[lv - 1]))
1742 if (val == lv && addState)
1745 PetscScalar valIn = v[lv - 1];
1746 MatSetValues(conMat, 1, &idxI, 1, &idxJ, &valIn, INSERT_VALUES);
1748 if (val == 10 && addFaces)
1751 PetscScalar valIn = v[lv - 1];
1752 MatSetValues(conMat, 1, &idxI, 1, &idxJ, &valIn, INSERT_VALUES);
1758 if (connectedStates.size() != 0)
1785 Info <<
"Checking if Coloring file exists.." << endl;
1786 label nProcs = Pstream::nProcs();
1787 word fileName =
modelType_ +
"Coloring" + postFix +
"_" + Foam::name(nProcs);
1788 word checkFile = fileName +
".bin";
1789 std::ifstream fIn(checkFile);
1792 Info << checkFile <<
" exists." << endl;
1825 Info <<
"Calculating " <<
modelType_ <<
" Coloring.." << endl;
1826 label nProcs = Pstream::nProcs();
1827 word fileName =
modelType_ +
"Coloring" + postFix +
"_" + Foam::name(nProcs);
1839 PetscScalar* jacConColorsArray;
1843 for (label i = Istart; i < Iend; i++)
1845 label relIdx = i - Istart;
1846 jacConColorsArray[relIdx] = i * 1.0;
1858 Info <<
"Writing Colors to " << fileName << endl;
1886 label nProcs = Pstream::nProcs();
1887 word fileName =
modelType_ +
"Coloring" + postFix +
"_" + Foam::name(nProcs);
1888 Info <<
"Reading Coloring " << fileName << endl;
1910 FatalErrorIn(
"") <<
"setupJacConPreallocation not implemented " << endl
1912 << abort(FatalError);
1917 const label transposed)
const
1927 FatalErrorIn(
"") <<
"preallocatedRdW not implemented " << endl
1929 << abort(FatalError);
1933 scalarList objFuncFaceValues,
1934 scalarList objFuncCellValues,
1935 Vec objFuncVec)
const
1945 FatalErrorIn(
"") <<
"setObjFuncVec not implemented " << endl
1947 << abort(FatalError);
1952 Vec coloredColumn)
const
2034 VecZeroEntries(colorIdx);
2042 const PetscScalar* jacConColorsArray;
2043 PetscScalar* colorIdxArray;
2045 VecGetArray(colorIdx, &colorIdxArray);
2048 for (label j = Istart; j < Iend; j++)
2050 label idx = j - Istart;
2055 colorIdxArray[idx] = j + 1;
2059 VecRestoreArray(colorIdx, &colorIdxArray);
2065 VecSet(coloredColumn, -1);
2067 MatMultAdd(
jacCon_, colorIdx, coloredColumn, coloredColumn);
2070 VecDestroy(&colorIdx);
2075 PetscScalar val = colorI * 1.0;
2076 VecSet(coloredColumn, val);
2078 VecAssemblyBegin(coloredColumn);
2079 VecAssemblyEnd(coloredColumn);
2096 Info <<
"pressureInletVelocity detected, applying special treatment for connectivity." << endl;
2106 Info <<
"Calculating pressureInletVelocity state vec..." << endl;
2110 mesh_.time().timeName(),
2112 IOobject::READ_IF_PRESENT,
2116 dimensionedVector(
"U", dimensionSet(0, 1, -1, 0, 0, 0, 0), vector::zero),
2117 zeroGradientFvPatchField<vector>::typeName);
2119 forAll(
U.boundaryField(), patchI)
2121 if (
U.boundaryFieldRef()[patchI].type() ==
"pressureInletVelocity")
2123 const UList<label>& pFaceCells =
mesh_.boundaryMesh()[patchI].faceCells();
2124 forAll(
U.boundaryFieldRef()[patchI], faceI)
2127 label faceCellI = pFaceCells[faceI];
2133 label faceCellJ =
mesh_.cellCells()[faceCellI][cellJ];
2138 label faceCellK =
mesh_.cellCells()[faceCellI][cellJ];
2149 wordList writeJacobians;
2151 if (writeJacobians.found(
"isPIVVec"))
2178 label cellFaceI =
mesh_.cells()[cellI][faceI];
2180 VecSetValue(isPIV, rowI, 1.0, INSERT_VALUES);
2192 for (label comp = 0; comp < compMax; comp++)
2195 VecSetValue(isPIV, rowI, 1.0, INSERT_VALUES);
2202 const word stateName,
2208 PetscScalar* isPIVArray;