63 Py_ssize_t dictSize = PyDict_Size(pyDict);
65 PyObject* keys = PyDict_Keys(pyDict);
68 for (label i = 0; i < dictSize; i++)
71 PyObject* keyI = PyList_GetItem(keys, i);
73 const char* keyUTF8 = PyUnicode_AsUTF8(keyI);
85 PyObject* value = PyDict_GetItem(pyDict, keyI);
86 const char* valueTypeTmp = Py_TYPE(value)->tp_name;
88 if (word(valueTypeTmp) ==
"list")
94 PyObject* value0 = PyList_GetItem(value, 0);
95 const char* valueTypeTmp0 = Py_TYPE(value0)->tp_name;
96 if (word(valueTypeTmp0) ==
"type")
100 value1 = PyList_GetItem(value, 1);
116 const char* valueType = Py_TYPE(value1)->tp_name;
117 bool overwrite =
true;
118 if (word(valueType) ==
"str")
120 const char* valSet = PyUnicode_AsUTF8(value1);
121 ofDict.add(keyUTF8, word(valSet), overwrite);
123 else if (word(valueType) ==
"int")
125 long valSet = PyLong_AsLong(value1);
126 ofDict.add(keyUTF8, label(valSet), overwrite);
128 else if (word(valueType) ==
"bool")
130 label valSet = PyObject_IsTrue(value1);
131 ofDict.add(keyUTF8, valSet, overwrite);
133 else if (word(valueType) ==
"float")
135 scalar valSet = PyFloat_AS_DOUBLE(value1);
136 ofDict.add(keyUTF8, valSet, overwrite);
138 else if (word(valueType) ==
"list")
141 Py_ssize_t listSize = PyList_Size(value1);
146 scalarList valSetScalar;
147 valSetScalar.setSize(label(listSize));
148 labelList valSetLabel;
149 valSetLabel.setSize(label(listSize));
150 List<word> valSetWord;
151 valSetWord.setSize(label(listSize));
155 PyObject* tmp = PyList_GetItem(value1, 0);
156 const char* tmpType = Py_TYPE(tmp)->tp_name;
157 word tmpTypeWord = word(tmpType);
159 for (label j = 0; j < listSize; j++)
161 PyObject* valueListJ = PyList_GetItem(value1, j);
162 if (tmpTypeWord ==
"str")
164 const char* valSet = PyUnicode_AsUTF8(valueListJ);
165 valSetWord[j] = word(valSet);
167 else if (tmpTypeWord ==
"int")
169 long valSet = PyLong_AsLong(valueListJ);
170 valSetLabel[j] = label(valSet);
172 else if (tmpTypeWord ==
"float")
174 scalar valSet = PyFloat_AS_DOUBLE(valueListJ);
175 valSetScalar[j] = valSet;
177 else if (tmpTypeWord ==
"bool")
179 label valSet = PyObject_IsTrue(valueListJ);
180 valSetLabel[j] = valSet;
184 FatalErrorIn(
"pyDict2OFDict") <<
"Type: <" << tmpTypeWord <<
"> for " << keyUTF8
185 <<
" list is not supported! Options are:"
186 <<
" str, int, bool, and float!"
187 << abort(FatalError);
192 if (tmpTypeWord ==
"str")
194 ofDict.add(keyUTF8, valSetWord, overwrite);
196 else if (tmpTypeWord ==
"int")
198 ofDict.add(keyUTF8, valSetLabel, overwrite);
200 else if (tmpTypeWord ==
"float")
202 ofDict.add(keyUTF8, valSetScalar, overwrite);
204 else if (tmpTypeWord ==
"bool")
206 ofDict.add(keyUTF8, valSetLabel, overwrite);
209 else if (word(valueType) ==
"dict")
214 ofDict.add(keyUTF8, subDict, overwrite);
218 FatalErrorIn(
"pyDict2OFDict") <<
"Type: " << valueType <<
" for " << keyUTF8
219 <<
" is not supported! Options are: str, int, float, bool, list, and dict!"
220 << abort(FatalError);
247 std::ostringstream fileNameStream(
"");
248 fileNameStream << prefix <<
".bin";
249 word fileName = fileNameStream.str();
252 PetscViewerBinaryOpen(PETSC_COMM_WORLD, fileName.c_str(), FILE_MODE_READ, &viewer);
253 VecLoad(vecIn, viewer);
254 PetscViewerDestroy(&viewer);
279 std::ostringstream fileNameStream(
"");
280 fileNameStream << prefix <<
".bin";
281 word fileName = fileNameStream.str();
284 PetscViewerBinaryOpen(PETSC_COMM_WORLD, fileName.c_str(), FILE_MODE_WRITE, &viewer);
285 VecView(vecIn, viewer);
286 PetscViewerDestroy(&viewer);
309 std::ostringstream fileNameStream(
"");
310 fileNameStream << prefix <<
".dat";
311 word fileName = fileNameStream.str();
314 PetscViewerASCIIOpen(PETSC_COMM_WORLD, fileName.c_str(), &viewer);
315 PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_MATLAB);
316 VecView(vecIn, viewer);
317 PetscViewerDestroy(&viewer);
343 std::ostringstream fileNameStream(
"");
344 fileNameStream << prefix <<
".bin";
345 word fileName = fileNameStream.str();
348 PetscViewerBinaryOpen(PETSC_COMM_WORLD, fileName.c_str(), FILE_MODE_READ, &viewer);
349 MatLoad(matIn, viewer);
350 PetscViewerDestroy(&viewer);
375 std::ostringstream fileNameStream(
"");
376 fileNameStream << prefix <<
".bin";
377 word fileName = fileNameStream.str();
380 PetscViewerBinaryOpen(PETSC_COMM_WORLD, fileName.c_str(), FILE_MODE_WRITE, &viewer);
381 MatView(matIn, viewer);
382 PetscViewerDestroy(&viewer);
407 std::ostringstream fileNameStream(
"");
408 fileNameStream << prefix <<
".dat";
409 word fileName = fileNameStream.str();
412 PetscViewerASCIIOpen(PETSC_COMM_WORLD, fileName.c_str(), &viewer);
413 MatView(matIn, viewer);
414 PetscViewerDestroy(&viewer);
422 const label printToScreen)
449 const scalar vGreat = 1e200;
450 label useUpperBound = 0, useLowerBound = 0;
452 dictionary varBoundsDict =
allOptions.subDict(
"primalVarBounds");
454 word lowerBoundName = var.name() +
"Min";
455 word upperBoundName = var.name() +
"Max";
457 scalar varMin = varBoundsDict.lookupOrDefault<scalar>(lowerBoundName, -vGreat);
458 scalar varMax = varBoundsDict.lookupOrDefault<scalar>(upperBoundName, vGreat);
462 if (var[cellI] <= varMin)
467 if (var[cellI] >= varMax)
474 forAll(var.boundaryField(), patchI)
476 forAll(var.boundaryField()[patchI], faceI)
478 if (var.boundaryFieldRef()[patchI][faceI] <= varMin)
480 var.boundaryFieldRef()[patchI][faceI] = varMin;
483 if (var.boundaryFieldRef()[patchI][faceI] >= varMax)
485 var.boundaryFieldRef()[patchI][faceI] = varMax;
495 Info <<
"Bounding " << var.name() <<
"<" << varMax << endl;
499 Info <<
"Bounding " << var.name() <<
">" << varMin << endl;
509 const label printToScreen)
536 const scalar vGreat = 1e200;
537 label useUpperBound = 0, useLowerBound = 0;
539 dictionary varBoundsDict =
allOptions.subDict(
"primalVarBounds");
541 word lowerBoundName = var.name() +
"Min";
542 word upperBoundName = var.name() +
"Max";
544 scalar varMin = varBoundsDict.lookupOrDefault<scalar>(lowerBoundName, -vGreat);
545 scalar varMax = varBoundsDict.lookupOrDefault<scalar>(upperBoundName, vGreat);
549 for (label i = 0; i < 3; i++)
551 if (var[cellI][i] <= varMin)
553 var[cellI][i] = varMin;
556 if (var[cellI][i] >= varMax)
558 var[cellI][i] = varMax;
564 forAll(var.boundaryField(), patchI)
566 forAll(var.boundaryField()[patchI], faceI)
568 for (label i = 0; i < 3; i++)
570 if (var.boundaryFieldRef()[patchI][faceI][i] <= varMin)
572 var.boundaryFieldRef()[patchI][faceI][i] = varMin;
575 if (var.boundaryFieldRef()[patchI][faceI][i] >= varMax)
577 var.boundaryFieldRef()[patchI][faceI][i] = varMax;
588 Info <<
"Bounding " << var.name() <<
"<" << varMax << endl;
592 Info <<
"Bounding " << var.name() <<
">" << varMin << endl;
647 globalIndex result(localIndexSize);
668 if (fabs(val - refVal) < tol)