Skip to content
Snippets Groups Projects
Commit 5395344e authored by Andrew Heather's avatar Andrew Heather
Browse files

Merge branch 'feature-externalCoupled' into 'develop'

Feature external coupled

- externalCoupled moved from BC to FO
- Multi-region support
- tutorial heatTransfer/chtMultiRegionFoam/externalCoupledMultiRegionHeater/

See merge request !16
parents 6a6896ce 6c251c20
Branches
Tags
No related merge requests found
Showing
with 834 additions and 528 deletions
//
// addRegionOption.H
// ~~~~~~~~~~~~~~~~~
Foam::argList::addOption
(
"regions",
"(name1 .. nameN)",
"specify alternative mesh regions"
);
......@@ -38,6 +38,11 @@ Usage
\param -region \<name\> \n
Specify an alternative mesh region.
\param -regions (\<name1\> \<name2\> .. \<namen\>) \n
Specify alternative mesh regions. The region names will be sorted
alphabetically and a single composite name will be created
\<nameX\>_\<nameY\>.._\<nameZ\>
On execution, the combined patch geometry (points and faces) are output
to the communications directory.
......@@ -59,6 +64,7 @@ SeeAlso
int main(int argc, char *argv[])
{
#include "addRegionOption.H"
#include "addRegionsOption.H"
argList::validArgs.append("patchGroup");
argList::addOption
(
......@@ -68,16 +74,52 @@ int main(int argc, char *argv[])
);
#include "setRootCase.H"
#include "createTime.H"
#include "createNamedMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
wordList regionNames(1, fvMesh::defaultRegion);
if (!args.optionReadIfPresent("region", regionNames[0]))
{
args.optionReadIfPresent("regions", regionNames);
}
const wordRe patchGroup(args[1]);
const wordRe patchGroup(args.argRead<wordRe>(1));
fileName commsDir(runTime.path()/"comms");
args.optionReadIfPresent("commsDir", commsDir);
externalCoupledFunctionObject::writeGeometry(mesh, commsDir, patchGroup);
// Make sure region names are in canonical order
stableSort(regionNames);
PtrList<const fvMesh> meshes(regionNames.size());
forAll(regionNames, i)
{
Info<< "Create mesh " << regionNames[i] << " for time = "
<< runTime.timeName() << nl << endl;
meshes.set
(
i,
new fvMesh
(
Foam::IOobject
(
regionNames[i],
runTime.timeName(),
runTime,
Foam::IOobject::MUST_READ
)
)
);
}
externalCoupledFunctionObject::writeGeometry
(
UPtrList<const fvMesh>(meshes),
commsDir,
patchGroup
);
Info<< "\nEnd\n" << endl;
......
......@@ -48,7 +48,10 @@ Description
which gets read/written on the master processor only. In the
communications directory the structure will be
<regionName>/<patchGroup>/<fieldName>.[in|out]
<regionsName>/<patchGroup>/<fieldName>.[in|out]
(where regionsName is either the name of a single region or a composite
of multiple region names)
At start-up, the boundary creates a lock file, i.e..
......@@ -58,13 +61,13 @@ Description
execution the boundary values are written to files (one per region,
per patch(group), per field), e.g.
<regionName>/<patchGroup>/<fieldName>.out
<regionsName>/<patchGroup>/<fieldName>.out
The lock file is then removed, instructing the external source to take
control of the program execution. When ready, the external program
should create the return values, e.g. to files
<regionName>/<patchGroup>/<fieldName>.in
<regionsName>/<patchGroup>/<fieldName>.in
... and then re-instate the lock file. The functionObject will then
read these values, apply them to the boundary conditions and pass
......@@ -82,7 +85,7 @@ Description
regions
{
region0
"(region1|region0)" // Name of region(s)
{
TPatchGroup // Name of patch(group)
{
......@@ -95,7 +98,7 @@ Description
\endverbatim
This reads/writes (on the master processor) the directory:
comms/region0/TPatchGroup/
comms/region0_region1/TPatchGroup/
with contents:
patchPoints (collected points)
patchFaces (collected faces)
......@@ -120,6 +123,7 @@ SourceFiles
#include "wordReList.H"
#include "scalarField.H"
#include "Switch.H"
#include "UPtrList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -167,18 +171,18 @@ class externalCoupledFunctionObject
//- Log flag
bool log_;
//- Names of regions
DynamicList<word> regionNames_;
//- Names of (composite) regions
DynamicList<word> regionGroupNames_;
// Per (composite) region the names of the regions
DynamicList<wordList> regionGroupRegions_;
// Per region the indices of the group information
// Per (composite) region the indices of the group information
HashTable<labelList> regionToGroups_;
// Per group the names of the patches/patchGroups
DynamicList<wordRe> groupNames_;
// Per group the indices of the patches
DynamicList<labelList> groupPatchIDs_;
// Per group the names of the fields to read
DynamicList<wordList> groupReadFields_;
......@@ -195,7 +199,7 @@ class externalCoupledFunctionObject
static fileName groupDir
(
const fileName& commsDir,
const word& regionName,
const word& regionsName,
const wordRe& groupName
);
......@@ -225,9 +229,8 @@ class externalCoupledFunctionObject
template<class Type>
bool readData
(
const fvMesh& mesh,
const UPtrList<const fvMesh>& meshes,
const wordRe& groupName,
const labelList& patchIDs,
const word& fieldName
);
//- Read data for all regions, all fields
......@@ -237,9 +240,8 @@ class externalCoupledFunctionObject
template<class Type>
bool writeData
(
const fvMesh& mesh,
const UPtrList<const fvMesh>& meshes,
const wordRe& groupName,
const labelList& patchIDs,
const word& fieldName
) const;
......@@ -275,6 +277,7 @@ class externalCoupledFunctionObject
template<class Type>
static tmp<Field<Type> > gatherAndCombine(const Field<Type>& fld);
static void checkOrder(const wordList&);
//- Disallow default bitwise copy construc
externalCoupledFunctionObject(const externalCoupledFunctionObject&);
......@@ -356,10 +359,14 @@ public:
// Other
//- Create single name by appending words (in sorted order),
// separated by '_'
static word compositeName(const wordList&);
//- Write geometry for the group/patch
static void writeGeometry
(
const fvMesh& mesh,
const UPtrList<const fvMesh>& meshes,
const fileName& commsDir,
const wordRe& groupName
);
......
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
location "0";
object alphat;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [1 -1 -1 0 0 0 0];
internalField uniform 0;
boundaryField
{
frontAndBack
{
type compressible::alphatWallFunction;
Prt 0.85;
value uniform 0;
}
topAndBottom
{
type compressible::alphatWallFunction;
Prt 0.85;
value uniform 0;
}
hot
{
type compressible::alphatWallFunction;
Prt 0.85;
value uniform 0;
}
cold
{
type compressible::alphatWallFunction;
Prt 0.85;
value uniform 0;
}
}
// ************************************************************************* //
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
./Allrun.pre
runApplication $(getApplication) &
./externalSolver
# ----------------------------------------------------------------- end-of-file
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
runApplication blockMesh
runApplication createExternalCoupledPatchGeometry T
# ----------------------------------------------------------------- end-of-file
Example of an explicit coupling between OpenFOAM and an external application
using the externalCoupled boundary conditions.
The case is based on the buoyantCavity tutorial case, whereby on each iteration
the 'hot' and 'cold' patch temperatures are incremented by 1K.
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object T;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 1 0 0 0];
internalField uniform 300;
boundaryField
{
".*"
{
type calculated;
value uniform 300;
}
}
// ************************************************************************* //
......@@ -10,41 +10,21 @@ FoamFile
version 2.0;
format ascii;
class volVectorField;
location "0";
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0);
internalField uniform (0.01 0 0);
boundaryField
{
frontAndBack
".*"
{
type fixedValue;
value uniform (0 0 0);
}
topAndBottom
{
type fixedValue;
value uniform (0 0 0);
}
hot
{
type fixedValue;
value uniform (0 0 0);
}
cold
{
type fixedValue;
value uniform (0 0 0);
type calculated;
value uniform (0.01 0 0);
}
}
// ************************************************************************* //
......@@ -10,36 +10,20 @@ FoamFile
version 2.0;
format ascii;
class volScalarField;
location "0";
object epsilon;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -3 0 0 0 0];
internalField uniform 4e-06;
internalField uniform 0.01;
boundaryField
{
frontAndBack
".*"
{
type epsilonWallFunction;
value uniform 4e-06;
}
topAndBottom
{
type epsilonWallFunction;
value uniform 4e-06;
}
hot
{
type epsilonWallFunction;
value uniform 4e-06;
}
cold
{
type epsilonWallFunction;
value uniform 4e-06;
type calculated;
value uniform 0.01;
}
}
......
......@@ -10,36 +10,20 @@ FoamFile
version 2.0;
format ascii;
class volScalarField;
location "0";
object k;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -2 0 0 0 0];
internalField uniform 3.75e-04;
internalField uniform 0.1;
boundaryField
{
frontAndBack
".*"
{
type kqRWallFunction;
value uniform 3.75e-04;
}
topAndBottom
{
type kqRWallFunction;
value uniform 3.75e-04;
}
hot
{
type kqRWallFunction;
value uniform 3.75e-04;
}
cold
{
type kqRWallFunction;
value uniform 3.75e-04;
type calculated;
value uniform 0.1;
}
}
......
......@@ -10,7 +10,6 @@ FoamFile
version 2.0;
format ascii;
class volScalarField;
location "0";
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -21,30 +20,11 @@ internalField uniform 1e5;
boundaryField
{
frontAndBack
".*"
{
type calculated;
value $internalField;
}
topAndBottom
{
type calculated;
value $internalField;
}
hot
{
type calculated;
value $internalField;
}
cold
{
type calculated;
value $internalField;
value uniform 1e5;
}
}
// ************************************************************************* //
......@@ -10,7 +10,6 @@ FoamFile
version 2.0;
format ascii;
class volScalarField;
location "0";
object p_rgh;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -21,30 +20,11 @@ internalField uniform 1e5;
boundaryField
{
frontAndBack
".*"
{
type fixedFluxPressure;
value uniform 1e5;
}
topAndBottom
{
type fixedFluxPressure;
value uniform 1e5;
}
hot
{
type fixedFluxPressure;
value uniform 1e5;
}
cold
{
type fixedFluxPressure;
type calculated;
value uniform 1e5;
}
}
// ************************************************************************* //
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
# Source tutorial clean functions
. $WM_PROJECT_DIR/bin/tools/CleanFunctions
cleanCase
rm -rf comms
killall externalSolver > /dev/null 2>&1
rm -rf VTK
rm -rf constant/cellToRegion constant/polyMesh/sets
rm -rf 0/bottomWater
rm -rf 0/topAir
rm -rf 0/heater
rm -rf 0/leftSolid
rm -rf 0/rightSolid
rm -f 0/cellToRegion
rm -rf constant/bottomWater/polyMesh
rm -rf constant/topAir/polyMesh
rm -rf constant/heater/polyMesh
rm -rf constant/leftSolid/polyMesh
rm -rf constant/rightSolid/polyMesh
# ----------------------------------------------------------------- end-of-file
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
./Allrun.pre
runApplication decomposePar
#-- Run on single processor
#runApplication `getApplication` &
# Simulated external solver
#runApplication ./externalSolver
# Decompose
runApplication decomposePar -allRegions
# Run OpenFOAM
runParallel `getApplication` 4 &
runParallel $(getApplication) 4 &
# Simulated external solver
runApplication ./externalSolver
./externalSolver
# Reconstruct
runApplication reconstructPar -allRegions
# ----------------------------------------------------------------- end-of-file
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
runApplication blockMesh
runApplication topoSet
runApplication splitMeshRegions -cellZones -overwrite
# remove fluid fields from solid regions (important for post-processing)
for i in heater leftSolid rightSolid
do
rm -f 0*/$i/{nut,alphat,epsilon,k,U,p_rgh}
done
for i in bottomWater topAir heater leftSolid rightSolid
do
changeDictionary -region $i > log.changeDictionary.$i 2>&1
done
# Create coupling geometry
runApplication createExternalCoupledPatchGeometry \
-regions '(topAir heater)' coupleGroup
echo
echo "creating files for paraview post-processing"
echo
paraFoam -touchAll
# ----------------------------------------------------------------- end-of-file
Modification of the heatTransfer chtMultiRegionFoam tutorial that demonstrates
the externalCoupled functionObject in combination with the ./externalSolver
script to simulate coupling to an external code.
......@@ -10,7 +10,6 @@ FoamFile
version 2.0;
format ascii;
class uniformDimensionedVectorField;
location "constant";
object g;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -18,5 +17,4 @@ FoamFile
dimensions [0 1 -2 0 0 0 0];
value (0 -9.81 0);
// ************************************************************************* //
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment