-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed a bug for the variance and added a util for extracting data. (#521
- Loading branch information
Showing
4 changed files
with
159 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
getFIData.C | ||
|
||
EXE = $(DAFOAM_ROOT_PATH)/OpenFOAM/sharedBins/getFIData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
EXE_INC = \ | ||
-std=c++11 \ | ||
-Wno-old-style-cast \ | ||
-Wno-conversion-null \ | ||
-Wno-deprecated-copy \ | ||
-I$(LIB_SRC)/finiteVolume/lnInclude \ | ||
-I$(LIB_SRC)/meshTools/lnInclude | ||
|
||
EXE_LIBS = \ | ||
-lfiniteVolume \ | ||
-lmeshTools | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
/*---------------------------------------------------------------------------*\ | ||
DAFoam : Discrete Adjoint with OpenFOAM | ||
Version : v3 | ||
Description | ||
Extract the reference data for field inversion | ||
\*---------------------------------------------------------------------------*/ | ||
|
||
#include "fvCFD.H" | ||
#include "argList.H" | ||
#include "Time.H" | ||
#include "fvMesh.H" | ||
#include "OFstream.H" | ||
|
||
using namespace Foam; | ||
|
||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
|
||
Info << "Get ref data for field inversion...." << endl; | ||
|
||
#include "setRootCase.H" | ||
#include "createTime.H" | ||
#include "createMesh.H" | ||
|
||
// Read FIDataDict | ||
IOdictionary FIDataDict( | ||
IOobject( | ||
"FIDataDict", | ||
mesh.time().system(), | ||
mesh, | ||
IOobject::MUST_READ, | ||
IOobject::NO_WRITE)); | ||
|
||
scalar endTime = runTime.endTime().value(); | ||
scalar deltaT = runTime.deltaT().value(); | ||
label nInstances = round(endTime / deltaT); | ||
|
||
forAll(FIDataDict.toc(), idxI) | ||
{ | ||
word varName = FIDataDict.toc()[idxI]; | ||
dictionary dataSubDict = FIDataDict.subDict(varName); | ||
word dataType = dataSubDict.getWord("dataType"); | ||
word fieldType = dataSubDict.getWord("fieldType"); | ||
|
||
if (dataType == "probePoints") | ||
{ | ||
List<List<scalar>> probePointCoords = {{0, 0, 0}}; | ||
dataSubDict.readEntry<List<List<scalar>>>("pointCoords", probePointCoords); | ||
// Info << "Reading probePointCoords from FIDataDict. probePointCoords = " << probePointCoords << endl; | ||
|
||
// hard coded probe point info. | ||
labelList probePointCellIList(probePointCoords.size(), -999); | ||
forAll(probePointCoords, idxI) | ||
{ | ||
point point = {probePointCoords[idxI][0], probePointCoords[idxI][1], probePointCoords[idxI][2]}; | ||
probePointCellIList[idxI] = mesh.findNearestCell(point); | ||
} | ||
|
||
for (label n = 1; n < nInstances + 1; n++) | ||
{ | ||
scalar t = n * deltaT; | ||
runTime.setTime(t, n); | ||
|
||
if (fieldType == "scalar") | ||
{ | ||
volScalarField varRead( | ||
IOobject( | ||
varName, | ||
mesh.time().timeName(), | ||
mesh, | ||
IOobject::MUST_READ, | ||
IOobject::NO_WRITE), | ||
mesh); | ||
|
||
forAll(varRead, cellI) | ||
{ | ||
if (!probePointCellIList.found(cellI)) | ||
{ | ||
varRead[cellI] = 1e17; | ||
} | ||
} | ||
|
||
varRead.rename(varName + "Data"); | ||
varRead.write(); | ||
} | ||
else if (fieldType == "vector") | ||
{ | ||
volVectorField varRead( | ||
IOobject( | ||
varName, | ||
mesh.time().timeName(), | ||
mesh, | ||
IOobject::MUST_READ, | ||
IOobject::NO_WRITE), | ||
mesh); | ||
|
||
forAll(varRead, cellI) | ||
{ | ||
if (!probePointCellIList.found(cellI)) | ||
{ | ||
for (label i = 0; i < 3; i++) | ||
{ | ||
varRead[cellI][i] = 1e17; | ||
} | ||
} | ||
} | ||
|
||
varRead.rename(varName + "Data"); | ||
varRead.write(); | ||
} | ||
else | ||
{ | ||
FatalErrorIn("") | ||
<< "fieldType" << fieldType << " not supported! Options are: scalar or vector" | ||
<< abort(FatalError); | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
FatalErrorIn("") | ||
<< "dataType" << dataType << " not supported! Options are: probePoints" | ||
<< abort(FatalError); | ||
} | ||
} | ||
Info << "Finished!" << endl; | ||
|
||
return 0; | ||
} | ||
|
||
// ************************************************************************* // |