createNonConformalCouples: Support patchType overrides

Field settings can now be specified within
createNonConformalCouplesDict. This allows for patchType overrides; for
example to create a jump condition over the coupling.

An alternate syntax has been added to facilitate this. If patch fields
do not need overriding then the old syntax can be used where patches
that are to be coupled are specified as a pair of names; e.g.:

    fields      yes;

    nonConformalCouples
    {
        fan
        {
            patches         (fan0 fan1);
            transform       none;
        }
    }

If patch fields do need overriding, then instead of the "patches" entry,
separate "owner" and "neighbour" sub-dictionaries should be used. These
can both contain a "patchFields" section detailing the boundary
conditions that apply to the newly created patches:

    fields      yes;

    nonConformalCouples
    {
        fan
        {
            owner
            {
                patch       fan0;

                patchFields
                {
                    p
                    {
                        type        fanPressureJump;
                        patchType   nonConformalCyclic;
                        jump        uniform 0;
                        value       uniform 0;
                        jumpTable   polynomial 1((100 0));
                    }
                }
            }

            neighbour
            {
                patch       fan1;

                patchFields
                {
                    $../../owner/patchFields;
                }
            }

            transform       none;
        }
    }

In this example, only the pressure boundary condition is overridden on
the newly created non-conformal cyclic. All other fields will have the
basic constraint type (i.e., nonConformalCyclic) applied.
This commit is contained in:
Will Bainbridge
2022-07-29 15:02:49 +01:00
parent b1d6e64d02
commit ceac941f4c
10 changed files with 410 additions and 178 deletions

View File

@ -75,17 +75,140 @@ using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void createNonConformalCouples int main(int argc, char *argv[])
(
fvMesh& mesh,
const List<Pair<word>>& patchNames,
const wordList& cyclicNames,
const List<cyclicTransform>& transforms
)
{ {
#include "addOverwriteOption.H"
#include "addRegionOption.H"
#include "addDictOption.H"
const bool haveArgs = argList::hasArgs(argc, argv);
if (haveArgs)
{
argList::validArgs.append("patch1");
argList::validArgs.append("patch2");
argList::addBoolOption
(
"fields",
"add non-conformal boundary conditions to the fields"
);
}
#include "setRootCase.H"
#include "createTime.H"
runTime.functionObjects().off();
// Flag to determine whether or not patches are added to fields
bool fields;
// Patch names between which to create couples, field dictionaries, the
// associated cyclic name prefix and transformation (if any)
List<Pair<word>> patchNames;
List<Pair<dictionary>> patchFieldDicts;
wordList cyclicNames;
List<cyclicTransform> transforms;
// If there are patch name arguments, then we assume fields are not being
// changed, the cyclic name is just the cyclic typename, and that there is
// no transformation. If there are no arguments then get all this
// information from the system dictionary.
if (haveArgs)
{
fields = args.optionFound("fields");
patchNames.append(Pair<word>(args[1], args[2]));
patchFieldDicts.append(Pair<dictionary>());
cyclicNames.append(nonConformalCyclicPolyPatch::typeName);
transforms.append(cyclicTransform(true));
}
else
{
static const word dictName("createNonConformalCouplesDict");
IOdictionary dict(systemDict(dictName, args, runTime));
fields = dict.lookupOrDefault<bool>("fields", false);
const dictionary& couplesDict =
dict.optionalSubDict("nonConformalCouples");
forAllConstIter(dictionary, couplesDict, iter)
{
if (!iter().isDict()) continue;
const dictionary& subDict = iter().dict();
const bool havePatches = subDict.found("patches");
const bool haveOwnerNeighbour =
subDict.found("owner") || subDict.found("neighbour");
if (havePatches == haveOwnerNeighbour)
{
FatalIOErrorInFunction(subDict)
<< "Patches should be specified with either a single "
<< "\"patches\" entry with a pair of patch names, or with "
<< "two sub-dictionaries named \"owner\" and "
<< "\"neighbour\"." << exit(FatalIOError);
}
if (havePatches)
{
patchNames.append(subDict.lookup<Pair<word>>("patches"));
patchFieldDicts.append(Pair<dictionary>());
}
if (haveOwnerNeighbour)
{
const dictionary& ownerDict = subDict.subDict("owner");
const dictionary& neighbourDict = subDict.subDict("neighbour");
patchNames.append
(
Pair<word>
(
ownerDict["patch"],
neighbourDict["patch"]
)
);
patchFieldDicts.append
(
Pair<dictionary>
(
ownerDict.subOrEmptyDict("patchFields"),
neighbourDict.subOrEmptyDict("patchFields")
)
);
}
cyclicNames.append(subDict.dictName());
transforms.append(cyclicTransform(subDict, true));
}
}
Foam::word meshRegionName = polyMesh::defaultRegion;
args.optionReadIfPresent("region", meshRegionName);
#include "createNamedMesh.H"
const polyBoundaryMesh& patches = mesh.boundaryMesh(); const polyBoundaryMesh& patches = mesh.boundaryMesh();
const bool overwrite = args.optionFound("overwrite");
const word oldInstance = mesh.pointsInstance();
// Read the fields
IOobjectList objects(mesh, runTime.timeName());
if (fields) Info<< "Reading geometric fields" << nl << endl;
#include "readVolFields.H"
#include "readSurfaceFields.H"
#include "readPointFields.H"
if (fields) Info<< endl;
// Make sure the mesh is not connected before couples are added
mesh.conform();
// Start building lists of patches and patch-fields to add
List<polyPatch*> newPatches; List<polyPatch*> newPatches;
List<dictionary> newPatchFieldDicts;
// Find the first processor patch and face // Find the first processor patch and face
label firstProcPatchi = patches.size(), firstProcFacei = mesh.nFaces(); label firstProcPatchi = patches.size(), firstProcFacei = mesh.nFaces();
@ -116,6 +239,10 @@ void createNonConformalCouples
( (
pp.clone(patches, patchi, pp.size(), pp.start()).ptr() pp.clone(patches, patchi, pp.size(), pp.start()).ptr()
); );
newPatchFieldDicts.append
(
dictionary()
);
} }
// Convenience function to generate patch names for the owner or neighbour // Convenience function to generate patch names for the owner or neighbour
@ -157,6 +284,10 @@ void createNonConformalCouples
transforms[i] transforms[i]
) )
); );
newPatchFieldDicts.append
(
patchFieldDicts[i][0]
);
newPatches.append newPatches.append
( (
new nonConformalCyclicPolyPatch new nonConformalCyclicPolyPatch
@ -172,6 +303,10 @@ void createNonConformalCouples
inv(transforms[i]) inv(transforms[i])
) )
); );
newPatchFieldDicts.append
(
patchFieldDicts[i][1]
);
} }
// Add the error patches. Note there is only one for each source patch, // Add the error patches. Note there is only one for each source patch,
@ -198,6 +333,10 @@ void createNonConformalCouples
iter.key() iter.key()
) )
); );
newPatchFieldDicts.append
(
dictionary()
);
} }
}; };
appendErrorPatches(true); appendErrorPatches(true);
@ -212,6 +351,10 @@ void createNonConformalCouples
( (
pp.clone(patches, newPatches.size(), pp.size(), pp.start()).ptr() pp.clone(patches, newPatches.size(), pp.size(), pp.start()).ptr()
); );
newPatchFieldDicts.append
(
dictionary()
);
} }
// Add the processor cyclic patches // Add the processor cyclic patches
@ -278,6 +421,10 @@ void createNonConformalCouples
patchNames[i][!owner] patchNames[i][!owner]
) )
); );
newPatchFieldDicts.append
(
patchFieldDicts[i][!owner]
);
} }
} }
} }
@ -291,7 +438,8 @@ void createNonConformalCouples
} }
// Re-patch the mesh. Note that new patches are all constraints, so the // Re-patch the mesh. Note that new patches are all constraints, so the
// dictionary and patch type do not get used. // dictionary and patch type do not get used. Overrides will be handled
// later, once all patches have been added and the mesh has been stitched.
forAll(newPatches, newPatchi) forAll(newPatches, newPatchi)
{ {
fvMeshTools::addPatch fvMeshTools::addPatch
@ -303,104 +451,24 @@ void createNonConformalCouples
false false
); );
} }
}
int main(int argc, char *argv[])
{
#include "addOverwriteOption.H"
#include "addRegionOption.H"
#include "addDictOption.H"
const bool haveArgs = argList::hasArgs(argc, argv);
if (haveArgs)
{
argList::validArgs.append("patch1");
argList::validArgs.append("patch2");
argList::addBoolOption
(
"fields",
"add non-conformal boundary conditions to the fields"
);
}
#include "setRootCase.H"
#include "createTime.H"
runTime.functionObjects().off();
// Flag to determine whether or not patches are added to fields
bool fields;
// Patch names between which to create couples, the associated cyclic name
// prefix and transformation (if any)
List<Pair<word>> patchNames;
wordList cyclicNames;
List<cyclicTransform> transforms;
// If there are patch name arguments, then we assume fields are not being
// changed, the cyclic name is just the cyclic typename, and that there is
// no transformation. If there are no arguments then get all this
// information from the system dictionary.
if (haveArgs)
{
fields = args.optionFound("fields");
patchNames.append(Pair<word>(args[1], args[2]));
cyclicNames.append(nonConformalCyclicPolyPatch::typeName);
transforms.append(cyclicTransform(true));
}
else
{
static const word dictName("createNonConformalCouplesDict");
IOdictionary dict(systemDict(dictName, args, runTime));
fields = dict.lookupOrDefault<bool>("fields", false);
const dictionary& couplesDict =
dict.optionalSubDict("nonConformalCouples");
forAllConstIter(dictionary, couplesDict, iter)
{
if (!iter().isDict()) continue;
patchNames.append(iter().dict().lookup<Pair<word>>("patches"));
cyclicNames.append(iter().dict().dictName());
transforms.append(cyclicTransform(iter().dict(), true));
}
}
Foam::word meshRegionName = polyMesh::defaultRegion;
args.optionReadIfPresent("region", meshRegionName);
const bool overwrite = args.optionFound("overwrite");
#include "createNamedMesh.H"
// Read the fields
IOobjectList objects(mesh, runTime.timeName());
if (fields) Info<< "Reading geometric fields" << nl << endl;
#include "readVolFields.H"
#include "readSurfaceFields.H"
#include "readPointFields.H"
if (fields) Info<< endl;
const word oldInstance = mesh.pointsInstance();
// Make sure the mesh is not connected before couples are added
fvMeshStitchers::stationary stitcher(mesh);
stitcher.disconnect(false, false);
createNonConformalCouples
(
mesh,
patchNames,
cyclicNames,
transforms
);
// Connect the mesh so that the new stitching topology gets written out // Connect the mesh so that the new stitching topology gets written out
stitcher.connect(false, false, false); fvMeshStitchers::stationary(mesh).connect(false, false, false);
// Set the fields on the new patches. All new patches are constraints, so
// this should only be creating overrides; e.g., jump cyclics.
forAll(newPatches, newPatchi)
{
if (!newPatchFieldDicts[newPatchi].empty())
{
fvMeshTools::setPatchFields
(
mesh,
newPatchi,
newPatchFieldDicts[newPatchi]
);
}
}
mesh.setInstance(runTime.timeName()); mesh.setInstance(runTime.timeName());

View File

@ -158,7 +158,6 @@ template<class Type>
void Foam::fixedJumpFvPatchField<Type>::write(Ostream& os) const void Foam::fixedJumpFvPatchField<Type>::write(Ostream& os) const
{ {
fvPatchField<Type>::write(os); fvPatchField<Type>::write(os);
writeEntry(os, "patchType", this->interfaceFieldType());
if (this->cyclicPatch().owner()) if (this->cyclicPatch().owner())
{ {

View File

@ -1206,12 +1206,15 @@ bool Foam::fvMeshStitcher::disconnect
Info<< indent << typeName << ": Disconnecting" << incrIndent << endl; Info<< indent << typeName << ": Disconnecting" << incrIndent << endl;
} }
// Pre-conform surface fields. This splits the original and cyclic parts of if (changing)
// the interface fields into separate boundary fields, with both sets of {
// values store on the original faces. The original field overwrites the // Pre-conform surface fields. This splits the original and cyclic
// existing boundary values, whilst the cyclic field is stored as a // parts of the interface fields into separate boundary fields, with
// separate field for use later. // both sets of values store on the original faces. The original field
preConformSurfaceFields(); // overwrites the existing boundary values, whilst the cyclic field is
// stored as a separate field for use later.
preConformSurfaceFields();
}
// Undo all non-conformal changes and clear all geometry and topology // Undo all non-conformal changes and clear all geometry and topology
mesh_.conform(); mesh_.conform();
@ -1382,20 +1385,23 @@ bool Foam::fvMeshStitcher::connect
correctMeshPhi(polyFacesBf, Sf, Cf); correctMeshPhi(polyFacesBf, Sf, Cf);
} }
// Post-non-conform surface fields. This reconstructs the original and if (changing)
// cyclic parts of the interface fields from separate original and cyclic {
// parts. The original part was store in the same field, whilst the cyclic // Post-non-conform surface fields. This reconstructs the original and
// part was separately registered. // cyclic parts of the interface fields from separate original and
postNonConformSurfaceFields(); // cyclic parts. The original part was store in the same field, whilst
// the cyclic part was separately registered.
postNonConformSurfaceFields();
// Volume fields are assumed to be intensive. So, the value on a face which // Volume fields are assumed to be intensive. So, the value on a face
// has changed in size can be retained without modification. New faces need // which has changed in size can be retained without modification. New
// values to be set. This is done by evaluating all the nonConformalCoupled // faces need values to be set. This is done by evaluating all the
// patch fields. // nonConformalCoupled patch fields.
evaluateVolFields(); evaluateVolFields();
// Do special post-non-conformation for surface velocities. // Do special post-non-conformation for surface velocities.
postNonConformSurfaceVelocities(); postNonConformSurfaceVelocities();
}
// Prevent hangs caused by processor cyclic patches using mesh geometry // Prevent hangs caused by processor cyclic patches using mesh geometry
mesh_.deltaCoeffs(); mesh_.deltaCoeffs();

View File

@ -205,12 +205,9 @@ Foam::wordList Foam::basicThermo::heBoundaryBaseTypes()
forAll(tbf, patchi) forAll(tbf, patchi)
{ {
if (isA<fixedJumpFvPatchScalarField>(tbf[patchi])) if (tbf[patchi].overridesConstraint())
{ {
const fixedJumpFvPatchScalarField& pf = hbt[patchi] = tbf[patchi].patch().type();
dynamic_cast<const fixedJumpFvPatchScalarField&>(tbf[patchi]);
hbt[patchi] = pf.interfaceFieldType();
} }
else if (isA<fixedJumpAMIFvPatchScalarField>(tbf[patchi])) else if (isA<fixedJumpAMIFvPatchScalarField>(tbf[patchi]))
{ {

View File

@ -11,7 +11,7 @@ runApplication blockMesh
# Create faceZones for baffles and fan # Create faceZones for baffles and fan
runApplication topoSet runApplication topoSet
# Create wall and cyclic baffles and the fields on them # Create baffles and the fields on them
runApplication createBaffles -overwrite runApplication createBaffles -overwrite
runApplication $application runApplication $application

View File

@ -0,0 +1,20 @@
#!/bin/sh
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
# Get application name
application=$(getApplication)
runApplication blockMesh
# Create faceZones for baffles and fan
runApplication topoSet
# Create baffles and the fields on them
runApplication createBaffles -overwrite -dict system/createBafflesDict.NCC
# Create non-conformal couplings
runApplication createNonConformalCouples -overwrite
runApplication $application

View File

@ -19,10 +19,10 @@ fields true;
baffles baffles
{ {
baffleFaces baffle
{ {
type faceZone; type faceZone;
zoneName baffleFaces; zoneName baffle;
owner owner
{ {
@ -80,18 +80,16 @@ baffles
} }
} }
cyclicFaces fan
{ {
type searchableSurface; type faceZone;
surface searchablePlate; zoneName fan;
origin (0.099 -0.006 0.004);
span (0 0.012 0.012);
owner owner
{ {
name cyclic0; name fan0;
type cyclic; type cyclic;
neighbourPatch cyclic1; neighbourPatch fan1;
patchFields patchFields
{ {
@ -108,9 +106,9 @@ baffles
neighbour neighbour
{ {
name cyclic1; name fan1;
type cyclic; type cyclic;
neighbourPatch cyclic0; neighbourPatch fan0;
patchFields patchFields
{ {

View File

@ -0,0 +1,113 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
object createBafflesDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
internalFacesOnly true;
fields true;
baffles
{
baffle
{
type faceZone;
zoneName baffle;
owner
{
name baffle0;
type wall;
patchFields
{
epsilon
{
type epsilonWallFunction;
Cmu 0.09;
kappa 0.41;
E 9.8;
value uniform 0;
}
k
{
type kqRWallFunction;
value uniform 0;
}
nut
{
type nutkWallFunction;
Cmu 0.09;
kappa 0.41;
E 9.8;
value uniform 0;
}
nuTilda
{
type zeroGradient;
}
p
{
type zeroGradient;
}
U
{
type fixedValue;
value uniform (0 0 0);
}
}
}
neighbour
{
name baffle1;
type wall;
patchFields
{
$../../owner/patchFields;
}
}
}
fan
{
type faceZone;
zoneName fan;
owner
{
name fan0;
type wall;
patchFields
{
$../../../baffle/owner/patchFields;
}
}
neighbour
{
name fan1;
type wall;
patchFields
{
$../../owner/patchFields;
}
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,55 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "system";
object createNonConformalCouplesDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
fields yes;
nonConformalCouples
{
fan
{
owner
{
patch fan0;
patchFields
{
p
{
type fanPressureJump;
patchType nonConformalCyclic;
jump uniform 0;
value uniform 0;
jumpTable polynomial 1((100 0));
}
}
}
neighbour
{
patch fan1;
patchFields
{
$../../owner/patchFields;
}
}
transform none;
}
}
// ************************************************************************* //

View File

@ -17,52 +17,28 @@ FoamFile
actions actions
( (
{ {
name cyclicFacesFaceSet; name baffle;
type faceSet;
action new;
source boxToFace;
box (0.099 -0.006 0.004)(0.101 0.006 0.016);
}
{
name cyclicFacesSlaveCells;
type cellSet;
action new;
source boxToCell;
box (-10 -10 -10)(0.1 10 10);
}
{
name cyclicFaces;
type faceZoneSet; type faceZoneSet;
action new; action new;
source setsToFaceZone; source planeToFaceZone;
faceSet cyclicFacesFaceSet; point (0.1 0 0);
cellSet cyclicFacesSlaveCells; normal (1 0 0);
} }
{ {
name baffleFaceSet; name fan;
type faceSet; type faceZoneSet;
action new; action new;
source boxToFace; source searchableSurfaceToFaceZone;
box (0.099 -10 -10)(0.101 10 10); surface searchablePlate;
origin (0.1 -0.006 0.004);
span (0 0.012 0.012);
} }
{ {
name baffleFaceSet; name baffle;
type faceSet; type faceZoneSet;
action delete; action delete;
source boxToFace; source faceZoneToFaceZone;
box (0.099 -0.006 0.004)(0.101 0.006 0.016); zone fan;
}
{
name baffleFaces;
type faceZoneSet;
action new;
source setToFaceZone;
faceSet baffleFaceSet;
} }
); );