Utility to add mirrored fields to time series.

This commit is contained in:
Thomas Lichtenegger
2017-12-18 12:25:07 +01:00
parent 63fdfd9026
commit 589f193b11
9 changed files with 395 additions and 0 deletions

View File

@ -0,0 +1,37 @@
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.4 |
| \\ / A nd | Web: http://www.openfoam.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
root "";
case "";
instance "";
local "";
class dictionary;
object mirrorProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//===========================================================================//
// sub-models & settings
refPoint (0 0 0);
refDirection (1 0 0);
fieldName U;
// ************************************************************************* //

View File

@ -0,0 +1,3 @@
rBaseMirrorScalar.C
EXE=$(CFDEM_APP_DIR)/rBaseMirrorScalar

View File

@ -0,0 +1,16 @@
include $(CFDEM_ADD_LIBS_DIR)/additionalLibs
EXE_INC = \
$(PFLAGS) \
-I$(LIB_SRC)/finiteVolume/cfdTools \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/fvOptions/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lmeshTools \
-lsampling \
-lfvOptions

View File

@ -0,0 +1,29 @@
IOdictionary mirrorProperties
(
IOobject
(
"mirrorProperties",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
vector refPoint(mirrorProperties.lookup("refPoint"));
vector refDirection(mirrorProperties.lookup("refDirection"));
word fieldName(mirrorProperties.lookup("fieldName"));
volScalarField origField
(
IOobject
(
fieldName,
runTime.timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
mesh
);

View File

@ -0,0 +1,131 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Application
rBaseMirror
Description
Read time series and extend it by mirrored fields if geometry possesses
the same symmetry
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
timeSelector::addOptions();
#include "setRootCase.H"
#include "createTime.H"
// read in start and end time from controlDict
scalar startTime=runTime.startTime().value();
scalar endTime=runTime.endTime().value();
scalar origTimeRange = endTime - startTime;
Info << "start time = " << runTime.startTime() << endl;
Info << "end time = " << runTime.endTime() << endl;
// check which time directories are present
instantList timeDirs = timeSelector::select0(runTime, args);
runTime.setTime(timeDirs[0], 0);
#include "createMesh.H"
#include "createFields.H"
Info << fieldName << endl;
volScalarField transformedField = origField;
scalar t;
label shiftedTimeI = 0;
// check number of time directories
label shift = 0;
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
t = runTime.value();
if(t<startTime) continue;
if(t>endTime) continue;
shift++;
}
scalar dt = origTimeRange / (shift - 1.0);
runTime.setEndTime(startTime + 2 * origTimeRange + dt);
label cellI_transformed = -1;
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
t = runTime.value();
if(t<startTime) continue;
if(t>endTime) continue;
Info << "time = " << t << ", time index = " << timeI << endl;
#include "createFields.H"
forAll(transformedField, cellI)
{
vector position = mesh.C()[cellI];
vector transformedPosition = 2 * ((refPoint - position) & refDirection) * refDirection / (refDirection & refDirection) + position;
cellI_transformed = mesh.findCell(transformedPosition);
if(cellI_transformed < 0)
{
Info << "Couldn't find transformed cell. Stopping." << endl;
return 0;
}
scalar value = origField[cellI_transformed];
scalar transformedValue = value;
transformedField[cellI] = transformedValue;
}
shiftedTimeI = timeI + shift;
t = runTime.value() + origTimeRange + dt;
runTime.setTime(t, shiftedTimeI);
Info << "creating transformed fields for time = " << t << ", time index = " << shiftedTimeI << endl;
transformedField.write();
}
Info<< "\nEnd" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,3 @@
rBaseMirrorVec.C
EXE=$(CFDEM_APP_DIR)/rBaseMirrorVec

View File

@ -0,0 +1,16 @@
include $(CFDEM_ADD_LIBS_DIR)/additionalLibs
EXE_INC = \
$(PFLAGS) \
-I$(LIB_SRC)/finiteVolume/cfdTools \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/fvOptions/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-lmeshTools \
-lsampling \
-lfvOptions

View File

@ -0,0 +1,29 @@
IOdictionary mirrorProperties
(
IOobject
(
"mirrorProperties",
mesh.time().constant(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
vector refPoint(mirrorProperties.lookup("refPoint"));
vector refDirection(mirrorProperties.lookup("refDirection"));
word fieldName(mirrorProperties.lookup("fieldName"));
volVectorField origField
(
IOobject
(
fieldName,
runTime.timeName(),
mesh,
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
mesh
);

View File

@ -0,0 +1,131 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Application
rBaseMirror
Description
Read time series and extend it by mirrored fields if geometry possesses
the same symmetry
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
timeSelector::addOptions();
#include "setRootCase.H"
#include "createTime.H"
// read in start and end time from controlDict
scalar startTime=runTime.startTime().value();
scalar endTime=runTime.endTime().value();
scalar origTimeRange = endTime - startTime;
Info << "start time = " << runTime.startTime() << endl;
Info << "end time = " << runTime.endTime() << endl;
// check which time directories are present
instantList timeDirs = timeSelector::select0(runTime, args);
runTime.setTime(timeDirs[0], 0);
#include "createMesh.H"
#include "createFields.H"
Info << fieldName << endl;
volVectorField transformedField = origField;
scalar t;
label shiftedTimeI = 0;
// check number of time directories
label shift = 0;
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
t = runTime.value();
if(t<startTime) continue;
if(t>endTime) continue;
shift++;
}
scalar dt = origTimeRange / (shift - 1.0);
runTime.setEndTime(startTime + 2 * origTimeRange + dt);
label cellI_transformed = -1;
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
t = runTime.value();
if(t<startTime) continue;
if(t>endTime) continue;
Info << "time = " << t << ", time index = " << timeI << endl;
#include "createFields.H"
forAll(transformedField, cellI)
{
vector position = mesh.C()[cellI];
vector transformedPosition = 2 * ((refPoint - position) & refDirection) * refDirection / (refDirection & refDirection) + position;
cellI_transformed = mesh.findCell(transformedPosition);
if(cellI_transformed < 0)
{
Info << "Couldn't find transformed cell. Stopping." << endl;
return 0;
}
vector value = origField[cellI_transformed];
vector transformedValue = -2 * (value & refDirection) * refDirection / (refDirection & refDirection) + value;
transformedField[cellI] = transformedValue;
}
shiftedTimeI = timeI + shift;
t = runTime.value() + origTimeRange + dt;
runTime.setTime(t, shiftedTimeI);
Info << "creating transformed fields for time = " << t << ", time index = " << shiftedTimeI << endl;
transformedField.write();
}
Info<< "\nEnd" << endl;
return 0;
}
// ************************************************************************* //