Add the OpenFOAM source tree

This commit is contained in:
Henry
2014-12-10 22:40:10 +00:00
parent ee487c860d
commit 446e5777f0
13379 changed files with 3983377 additions and 0 deletions

View File

@ -0,0 +1,7 @@
faceSelection/faceSelection.C
faceSelection/faceZoneSelection.C
faceSelection/searchableSurfaceSelection.C
createBaffles.C
EXE = $(FOAM_APPBIN)/createBaffles

View File

@ -0,0 +1,11 @@
EXE_INC = \
-IfaceSelection \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-ldynamicMesh \
-lmeshTools \
-lfiniteVolume \
-lgenericPatchFields

View File

@ -0,0 +1,910 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
Application
createBaffles
Description
Makes internal faces into boundary faces. Does not duplicate points, unlike
mergeOrSplitBaffles.
Note: if any coupled patch face is selected for baffling the opposite
member has to be selected for baffling as well.
- if the patch already exists will not override it nor its fields
- if the patch does not exist it will be created together with 'calculated'
patchfields unless the field is mentioned in the patchFields section.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "polyTopoChange.H"
#include "polyModifyFace.H"
#include "polyAddFace.H"
#include "ReadFields.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "fvMeshMapper.H"
#include "faceSelection.H"
#include "fvMeshTools.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
label addPatch
(
fvMesh& mesh,
const word& patchName,
const word& groupName,
const dictionary& patchDict
)
{
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
if (pbm.findPatchID(patchName) == -1)
{
autoPtr<polyPatch> ppPtr
(
polyPatch::New
(
patchName,
patchDict,
0,
pbm
)
);
polyPatch& pp = ppPtr();
if (!groupName.empty() && !pp.inGroup(groupName))
{
pp.inGroups().append(groupName);
}
// Add patch, create calculated everywhere
fvMeshTools::addPatch
(
mesh,
pp,
dictionary(), // do not set specialised patchFields
calculatedFvPatchField<scalar>::typeName,
true // parallel sync'ed addition
);
}
else
{
Info<< "Patch '" << patchName
<< "' already exists. Only "
<< "moving patch faces - type will remain the same"
<< endl;
}
return pbm.findPatchID(patchName);
}
void modifyOrAddFace
(
polyTopoChange& meshMod,
const face& f,
const label faceI,
const label own,
const bool flipFaceFlux,
const label newPatchI,
const label zoneID,
const bool zoneFlip,
PackedBoolList& modifiedFace
)
{
if (!modifiedFace[faceI])
{
// First usage of face. Modify.
meshMod.setAction
(
polyModifyFace
(
f, // modified face
faceI, // label of face
own, // owner
-1, // neighbour
flipFaceFlux, // face flip
newPatchI, // patch for face
false, // remove from zone
zoneID, // zone for face
zoneFlip // face flip in zone
)
);
modifiedFace[faceI] = 1;
}
else
{
// Second or more usage of face. Add.
meshMod.setAction
(
polyAddFace
(
f, // modified face
own, // owner
-1, // neighbour
-1, // master point
-1, // master edge
faceI, // master face
flipFaceFlux, // face flip
newPatchI, // patch for face
zoneID, // zone for face
zoneFlip // face flip in zone
)
);
}
}
// Create faces for fZone faces. Usually newMasterPatches, newSlavePatches
// only size one but can be more for duplicate baffle sets
void createFaces
(
const bool internalFacesOnly,
const fvMesh& mesh,
const faceZone& fZone,
const labelList& newMasterPatches,
const labelList& newSlavePatches,
polyTopoChange& meshMod,
PackedBoolList& modifiedFace,
label& nModified
)
{
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
forAll(newMasterPatches, i)
{
// Pass 1. Do selected side of zone
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
{
label zoneFaceI = fZone.whichFace(faceI);
if (zoneFaceI != -1)
{
if (!fZone.flipMap()[zoneFaceI])
{
// Use owner side of face
modifyOrAddFace
(
meshMod,
mesh.faces()[faceI], // modified face
faceI, // label of face
mesh.faceOwner()[faceI],// owner
false, // face flip
newMasterPatches[i], // patch for face
fZone.index(), // zone for face
false, // face flip in zone
modifiedFace // modify or add status
);
}
else
{
// Use neighbour side of face.
// To keep faceZone pointing out of original neighbour
// we don't need to set faceFlip since that cell
// now becomes the owner
modifyOrAddFace
(
meshMod,
mesh.faces()[faceI].reverseFace(), // modified face
faceI, // label of face
mesh.faceNeighbour()[faceI],// owner
true, // face flip
newMasterPatches[i], // patch for face
fZone.index(), // zone for face
false, // face flip in zone
modifiedFace // modify or add status
);
}
nModified++;
}
}
// Pass 2. Do other side of zone
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
{
label zoneFaceI = fZone.whichFace(faceI);
if (zoneFaceI != -1)
{
if (!fZone.flipMap()[zoneFaceI])
{
// Use neighbour side of face
modifyOrAddFace
(
meshMod,
mesh.faces()[faceI].reverseFace(), // modified face
faceI, // label of face
mesh.faceNeighbour()[faceI], // owner
true, // face flip
newSlavePatches[i], // patch for face
fZone.index(), // zone for face
true, // face flip in zone
modifiedFace // modify or add
);
}
else
{
// Use owner side of face
modifyOrAddFace
(
meshMod,
mesh.faces()[faceI], // modified face
faceI, // label of face
mesh.faceOwner()[faceI],// owner
false, // face flip
newSlavePatches[i], // patch for face
fZone.index(), // zone for face
true, // face flip in zone
modifiedFace // modify or add status
);
}
}
}
// Modify any boundary faces
// ~~~~~~~~~~~~~~~~~~~~~~~~~
// Normal boundary:
// - move to new patch. Might already be back-to-back baffle
// you want to add cyclic to. Do warn though.
//
// Processor boundary:
// - do not move to cyclic
// - add normal patches though.
// For warning once per patch.
labelHashSet patchWarned;
forAll(pbm, patchI)
{
const polyPatch& pp = pbm[patchI];
label newPatchI = newMasterPatches[i];
if (pp.coupled() && pbm[newPatchI].coupled())
{
// Do not allow coupled faces to be moved to different
// coupled patches.
}
else if (pp.coupled() || !internalFacesOnly)
{
forAll(pp, i)
{
label faceI = pp.start()+i;
label zoneFaceI = fZone.whichFace(faceI);
if (zoneFaceI != -1)
{
if (patchWarned.insert(patchI))
{
WarningIn("createFaces(..)")
<< "Found boundary face (in patch "
<< pp.name()
<< ") in faceZone " << fZone.name()
<< " to convert to baffle patch "
<< pbm[newPatchI].name()
<< endl
<< " Run with -internalFacesOnly option"
<< " if you don't wish to convert"
<< " boundary faces." << endl;
}
modifyOrAddFace
(
meshMod,
mesh.faces()[faceI], // modified face
faceI, // label of face
mesh.faceOwner()[faceI], // owner
false, // face flip
newPatchI, // patch for face
fZone.index(), // zone for face
fZone.flipMap()[zoneFaceI], // face flip in zone
modifiedFace // modify or add
);
nModified++;
}
}
}
}
}
}
int main(int argc, char *argv[])
{
argList::addNote
(
"Makes internal faces into boundary faces.\n"
"Does not duplicate points."
);
#include "addDictOption.H"
#include "addOverwriteOption.H"
#include "addDictOption.H"
#include "addRegionOption.H"
#include "setRootCase.H"
#include "createTime.H"
runTime.functionObjects().off();
#include "createNamedMesh.H"
const bool overwrite = args.optionFound("overwrite");
const word oldInstance = mesh.pointsInstance();
const word dictName("createBafflesDict");
#include "setSystemMeshDictionaryIO.H"
Switch internalFacesOnly(false);
Switch noFields(false);
PtrList<faceSelection> selectors;
{
Info<< "Reading baffle criteria from " << dictName << nl << endl;
IOdictionary dict(dictIO);
dict.lookup("internalFacesOnly") >> internalFacesOnly;
noFields = dict.lookupOrDefault("noFields", false);
const dictionary& selectionsDict = dict.subDict("baffles");
label n = 0;
forAllConstIter(dictionary, selectionsDict, iter)
{
if (iter().isDict())
{
n++;
}
}
selectors.setSize(n);
n = 0;
forAllConstIter(dictionary, selectionsDict, iter)
{
if (iter().isDict())
{
selectors.set
(
n++,
faceSelection::New(iter().keyword(), mesh, iter().dict())
);
}
}
}
if (internalFacesOnly)
{
Info<< "Not converting faces on non-coupled patches." << nl << endl;
}
// Read objects in time directory
IOobjectList objects(mesh, runTime.timeName());
// Read vol fields.
Info<< "Reading geometric fields" << nl << endl;
PtrList<volScalarField> vsFlds;
if (!noFields) ReadFields(mesh, objects, vsFlds);
PtrList<volVectorField> vvFlds;
if (!noFields) ReadFields(mesh, objects, vvFlds);
PtrList<volSphericalTensorField> vstFlds;
if (!noFields) ReadFields(mesh, objects, vstFlds);
PtrList<volSymmTensorField> vsymtFlds;
if (!noFields) ReadFields(mesh, objects, vsymtFlds);
PtrList<volTensorField> vtFlds;
if (!noFields) ReadFields(mesh, objects, vtFlds);
// Read surface fields.
PtrList<surfaceScalarField> ssFlds;
if (!noFields) ReadFields(mesh, objects, ssFlds);
PtrList<surfaceVectorField> svFlds;
if (!noFields) ReadFields(mesh, objects, svFlds);
PtrList<surfaceSphericalTensorField> sstFlds;
if (!noFields) ReadFields(mesh, objects, sstFlds);
PtrList<surfaceSymmTensorField> ssymtFlds;
if (!noFields) ReadFields(mesh, objects, ssymtFlds);
PtrList<surfaceTensorField> stFlds;
if (!noFields) ReadFields(mesh, objects, stFlds);
// Creating (if necessary) faceZones
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
forAll(selectors, selectorI)
{
const word& name = selectors[selectorI].name();
if (mesh.faceZones().findZoneID(name) == -1)
{
mesh.faceZones().clearAddressing();
label sz = mesh.faceZones().size();
labelList addr(0);
boolList flip(0);
mesh.faceZones().setSize(sz+1);
mesh.faceZones().set
(
sz,
new faceZone(name, addr, flip, sz, mesh.faceZones())
);
}
}
// Select faces
// ~~~~~~~~~~~~
//- Per face zoneID it is in and flip status.
labelList faceToZoneID(mesh.nFaces(), -1);
boolList faceToFlip(mesh.nFaces(), false);
forAll(selectors, selectorI)
{
const word& name = selectors[selectorI].name();
label zoneID = mesh.faceZones().findZoneID(name);
selectors[selectorI].select(zoneID, faceToZoneID, faceToFlip);
}
// Add faces to faceZones
labelList nFaces(mesh.faceZones().size(), 0);
forAll(faceToZoneID, faceI)
{
label zoneID = faceToZoneID[faceI];
if (zoneID != -1)
{
nFaces[zoneID]++;
}
}
forAll(selectors, selectorI)
{
const word& name = selectors[selectorI].name();
label zoneID = mesh.faceZones().findZoneID(name);
label& n = nFaces[zoneID];
labelList addr(n);
boolList flip(n);
n = 0;
forAll(faceToZoneID, faceI)
{
label zone = faceToZoneID[faceI];
if (zone == zoneID)
{
addr[n] = faceI;
flip[n] = faceToFlip[faceI];
n++;
}
}
Info<< "Created zone " << name
<< " at index " << zoneID
<< " with " << n << " faces" << endl;
mesh.faceZones().set
(
zoneID,
new faceZone(name, addr, flip, zoneID, mesh.faceZones())
);
}
// Count patches to add
// ~~~~~~~~~~~~~~~~~~~~
HashSet<word> bafflePatches;
{
forAll(selectors, selectorI)
{
const dictionary& dict = selectors[selectorI].dict();
if (dict.found("patches"))
{
const dictionary& patchSources = dict.subDict("patches");
forAllConstIter(dictionary, patchSources, iter)
{
const word patchName(iter().dict()["name"]);
bafflePatches.insert(patchName);
}
}
else
{
const word masterName = selectors[selectorI].name() + "_master";
bafflePatches.insert(masterName);
const word slaveName = selectors[selectorI].name() + "_slave";
bafflePatches.insert(slaveName);
}
}
}
// Create baffles
// ~~~~~~~~~~~~~~
// Is done in multiple steps
// - create patches with 'calculated' patchFields
// - move faces into these patches
// - change the patchFields to the wanted type
// This order is done so e.g. fixedJump works:
// - you cannot create patchfields at the same time as patches since
// they do an evaluate upon construction
// - you want to create the patchField only after you have faces
// so you don't get the 'create-from-nothing' mapping problem.
// Pass 1: add patches
// ~~~~~~~~~~~~~~~~~~~
//HashSet<word> addedPatches;
{
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
forAll(selectors, selectorI)
{
const dictionary& dict = selectors[selectorI].dict();
const word& groupName = selectors[selectorI].name();
if (dict.found("patches"))
{
const dictionary& patchSources = dict.subDict("patches");
forAllConstIter(dictionary, patchSources, iter)
{
const word patchName(iter().dict()["name"]);
if (pbm.findPatchID(patchName) == -1)
{
dictionary patchDict = iter().dict();
patchDict.set("nFaces", 0);
patchDict.set("startFace", 0);
// Note: do not set coupleGroup if constructed from
// baffles so you have freedom specifying it
// yourself.
//patchDict.set("coupleGroup", groupName);
addPatch(mesh, patchName, groupName, patchDict);
}
else
{
Info<< "Patch '" << patchName
<< "' already exists. Only "
<< "moving patch faces - type will remain the same"
<< endl;
}
}
}
else
{
const dictionary& patchSource = dict.subDict("patchPairs");
const word masterName = groupName + "_master";
const word slaveName = groupName + "_slave";
word groupNameMaster = groupName;
word groupNameSlave = groupName;
dictionary patchDictMaster(patchSource);
patchDictMaster.set("nFaces", 0);
patchDictMaster.set("startFace", 0);
patchDictMaster.set("coupleGroup", groupName);
dictionary patchDictSlave(patchDictMaster);
// Note: This is added for the particular case where we want
// master and slave in different groupNames
// (ie 3D thermal baffles)
Switch sameGroup
(
patchSource.lookupOrDefault("sameGroup", true)
);
if (!sameGroup)
{
groupNameMaster = groupName + "Group_master";
groupNameSlave = groupName + "Group_slave";
patchDictMaster.set("coupleGroup", groupNameMaster);
patchDictSlave.set("coupleGroup", groupNameSlave);
}
addPatch(mesh, masterName, groupNameMaster, patchDictMaster);
addPatch(mesh, slaveName, groupNameSlave, patchDictSlave);
}
}
}
// Make sure patches and zoneFaces are synchronised across couples
mesh.boundaryMesh().checkParallelSync(true);
mesh.faceZones().checkParallelSync(true);
// Mesh change container
polyTopoChange meshMod(mesh);
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
// Do the actual changes. Note:
// - loop in incrementing face order (not necessary if faceZone ordered).
// Preserves any existing ordering on patch faces.
// - two passes, do non-flip faces first and flip faces second. This
// guarantees that when e.g. creating a cyclic all faces from one
// side come first and faces from the other side next.
// Whether first use of face (modify) or consecutive (add)
PackedBoolList modifiedFace(mesh.nFaces());
label nModified = 0;
forAll(selectors, selectorI)
{
const word& name = selectors[selectorI].name();
label zoneID = mesh.faceZones().findZoneID(name);
const faceZone& fZone = mesh.faceZones()[zoneID];
const dictionary& dict = selectors[selectorI].dict();
DynamicList<label> newMasterPatches;
DynamicList<label> newSlavePatches;
if (dict.found("patches"))
{
const dictionary& patchSources = dict.subDict("patches");
bool master = true;
forAllConstIter(dictionary, patchSources, iter)
{
const word patchName(iter().dict()["name"]);
label patchI = pbm.findPatchID(patchName);
if (master)
{
newMasterPatches.append(patchI);
}
else
{
newSlavePatches.append(patchI);
}
master = !master;
}
}
else
{
const word masterName = selectors[selectorI].name() + "_master";
newMasterPatches.append(pbm.findPatchID(masterName));
const word slaveName = selectors[selectorI].name() + "_slave";
newSlavePatches.append(pbm.findPatchID(slaveName));
}
createFaces
(
internalFacesOnly,
mesh,
fZone,
newMasterPatches,
newSlavePatches,
meshMod,
modifiedFace,
nModified
);
}
Info<< "Converted " << returnReduce(nModified, sumOp<label>())
<< " faces into boundary faces in patches "
<< bafflePatches.sortedToc() << nl << endl;
if (!overwrite)
{
runTime++;
}
// Change the mesh. Change points directly (no inflation).
autoPtr<mapPolyMesh> map = meshMod.changeMesh(mesh, false);
// Update fields
mesh.updateMesh(map);
// Correct boundary faces mapped-out-of-nothing.
// This is just a hack to correct the value field.
{
fvMeshMapper mapper(mesh, map);
bool hasWarned = false;
forAllConstIter(HashSet<word>, bafflePatches, iter)
{
label patchI = mesh.boundaryMesh().findPatchID(iter.key());
const fvPatchMapper& pm = mapper.boundaryMap()[patchI];
if (pm.sizeBeforeMapping() == 0)
{
if (!hasWarned)
{
hasWarned = true;
WarningIn(args.executable())
<< "Setting field on boundary faces to zero." << endl
<< "You might have to edit these fields." << endl;
}
fvMeshTools::zeroPatchFields(mesh, patchI);
}
}
}
// Pass 2: change patchFields
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
{
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
forAll(selectors, selectorI)
{
const dictionary& dict = selectors[selectorI].dict();
if (dict.found("patches"))
{
const dictionary& patchSources = dict.subDict("patches");
forAllConstIter(dictionary, patchSources, iter)
{
const word patchName(iter().dict()["name"]);
label patchI = pbm.findPatchID(patchName);
if (iter().dict().found("patchFields"))
{
const dictionary& patchFieldsDict =
iter().dict().subDict
(
"patchFields"
);
fvMeshTools::setPatchFields
(
mesh,
patchI,
patchFieldsDict
);
}
}
}
else
{
const dictionary& patchSource = dict.subDict("patchPairs");
Switch sameGroup
(
patchSource.lookupOrDefault("sameGroup", true)
);
const word& groupName = selectors[selectorI].name();
if (patchSource.found("patchFields"))
{
dictionary patchFieldsDict = patchSource.subDict
(
"patchFields"
);
if (sameGroup)
{
// Add coupleGroup to all entries
forAllIter(dictionary, patchFieldsDict, iter)
{
if (iter().isDict())
{
dictionary& dict = iter().dict();
dict.set("coupleGroup", groupName);
}
}
const labelList& patchIDs =
pbm.groupPatchIDs()[groupName];
forAll(patchIDs, i)
{
fvMeshTools::setPatchFields
(
mesh,
patchIDs[i],
patchFieldsDict
);
}
}
else
{
const word masterPatchName(groupName + "_master");
const word slavePatchName(groupName + "_slave");
label patchIMaster = pbm.findPatchID(masterPatchName);
label patchISlave = pbm.findPatchID(slavePatchName);
fvMeshTools::setPatchFields
(
mesh,
patchIMaster,
patchFieldsDict
);
fvMeshTools::setPatchFields
(
mesh,
patchISlave,
patchFieldsDict
);
}
}
}
}
}
// Move mesh (since morphing might not do this)
if (map().hasMotionPoints())
{
mesh.movePoints(map().preMotionPoints());
}
if (overwrite)
{
mesh.setInstance(oldInstance);
}
Info<< "Writing mesh to " << runTime.timeName() << endl;
mesh.write();
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,144 @@
/*--------------------------------*- 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 dictionary;
object createBafflesDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Sample for creating baffles:
// - usually converting internal faces into two boundary faces
// - or converting boundary faces into a boundary face
// (internalFacesOnly=false)(though should use really createPatch
// to do this)
//
// - selection of faces (and orientation) to 'baffle' through:
// faceZone:
// type faceZone;
// zoneName f0;
// searchableSurface:
// type searchableSurface;
// surface triSurfaceMesh;
// name baffle1D.stl;
//
// - specification of patches for baffle sides in one of two modes:
// - patchPairs : create two patches of same type, same input
// - patches : create patches separately, full control over what
// to create on what side
// (this mode can also create duplicate (overlapping)
// sets of baffles:
// - internalFacesOnly = false
// - have 4 entries in patches:
// - master
// - slave
// - additional master
// - additional slave)
// Whether to convert internal faces only (so leave boundary faces intact).
// This is only relevant if your face selection type can pick up boundary
// faces.
internalFacesOnly true;
// Optionally do not read/convert/write any fields.
//noFields true;
// Baffles to create.
baffles
{
baffle1
{
//- Use surface to select faces and orientation.
type searchableSurface;
surface triSurfaceMesh;
name baffle1D.stl;
//- Optional flip
//flip false;
// Generate patchGroup baffle1 with two patches:
// - baffle1_master
// - baffle1_slave
patchPairs
{
type wall;
//- Optional override of added patchfields. If not specified
// any added patchfields are of type calculated.
patchFields
{
U
{
type fixedValue;
value uniform (0 0 0);
}
}
}
}
cyclicFaces
{
//- Select faces and orientation through a searchableSurface
type searchableSurface;
surface searchablePlate;
origin (0.099 -0.006 0.004);
span (0 0.012 0.012);
// Generate patches explicitly
patches
{
master
{
//- Master side patch
name fan_half0;
type cyclic;
neighbourPatch fan_half1;
patchFields
{
p
{
type fan;
patchType cyclic;
jump uniform 0;
value uniform 0;
jumpTable polynomial 1((100 0));
}
}
}
slave
{
//- Slave side patch
name fan_half1;
type cyclic;
neighbourPatch fan_half0;
patchFields
{
p
{
type fan;
patchType cyclic;
value uniform 0;
}
}
}
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,111 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "faceSelection.H"
#include "fvMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(faceSelection, 0);
defineRunTimeSelectionTable(faceSelection, dictionary);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::faceSelection::faceSelection
(
const word& name,
const fvMesh& mesh,
const dictionary& dict
)
:
name_(name),
mesh_(mesh),
dict_(dict),
flip_(dict.lookupOrDefault("flip", false))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::faceSelection::~faceSelection()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::faceSelection> Foam::faceSelection::New
(
const word& name,
const fvMesh& mesh,
const dictionary& dict
)
{
const word sampleType(dict.lookup("type"));
dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(sampleType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorIn
(
"faceSelection::New"
"(const word&, const fvMesh&, const dictionary&)"
) << "Unknown faceSelection type "
<< sampleType << nl << nl
<< "Valid faceSelection types : " << endl
<< dictionaryConstructorTablePtr_->sortedToc()
<< exit(FatalError);
}
return autoPtr<faceSelection>(cstrIter()(name, mesh, dict));
}
void Foam::faceSelection::select
(
const label zoneID,
labelList& faceToZoneID,
boolList& faceToFlip
) const
{
if (flip_)
{
forAll(faceToZoneID, faceI)
{
if (faceToZoneID[faceI] == zoneID)
{
faceToFlip[faceI] = !faceToFlip[faceI];
}
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,156 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::faceSelection
Description
Face selection method for createBaffles
SourceFiles
faceSelection.C
\*---------------------------------------------------------------------------*/
#ifndef faceSelection_H
#define faceSelection_H
#include "dictionary.H"
#include "typeInfo.H"
#include "runTimeSelectionTables.H"
#include "autoPtr.H"
#include "boolList.H"
#include "labelList.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class fvMesh;
/*---------------------------------------------------------------------------*\
Class faceSelection Declaration
\*---------------------------------------------------------------------------*/
class faceSelection
{
protected:
// Protected data
//- Name
const word name_;
//- Reference to mesh
const fvMesh& mesh_;
//- Input dictionary
const dictionary dict_;
//- Switch direction?
const Switch flip_;
public:
//- Runtime type information
TypeName("faceSelection");
// Declare run-time constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
faceSelection,
dictionary,
(
const word& name,
const fvMesh& mesh,
const dictionary& dict
),
(name, mesh, dict)
);
// Constructors
//- Construct from dictionary
faceSelection
(
const word& name,
const fvMesh& mesh,
const dictionary& dict
);
//- Clone
autoPtr<faceSelection> clone() const
{
notImplemented("autoPtr<faceSelection> clone() const");
return autoPtr<faceSelection>(NULL);
}
// Selectors
//- Return a reference to the selected faceSelection
static autoPtr<faceSelection> New
(
const word& name,
const fvMesh& mesh,
const dictionary& dict
);
//- Destructor
virtual ~faceSelection();
// Member Functions
const word& name() const
{
return name_;
}
const dictionary& dict() const
{
return dict_;
}
virtual void select(const label, labelList&, boolList&) const = 0;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,108 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "faceZoneSelection.H"
#include "addToRunTimeSelectionTable.H"
#include "fvMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace faceSelections
{
defineTypeNameAndDebug(faceZoneSelection, 0);
addToRunTimeSelectionTable(faceSelection, faceZoneSelection, dictionary);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::faceSelections::faceZoneSelection::faceZoneSelection
(
const word& name,
const fvMesh& mesh,
const dictionary& dict
)
:
faceSelection(name, mesh, dict),
zoneName_(dict_.lookup("zoneName"))
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::faceSelections::faceZoneSelection::~faceZoneSelection()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::faceSelections::faceZoneSelection::select
(
const label zoneID,
labelList& faceToZoneID,
boolList& faceToFlip
) const
{
label readID = mesh_.faceZones().findZoneID(zoneName_);
if (readID == -1)
{
FatalErrorIn
(
"faceSelections::faceZoneSelection::select(labelList&) const"
) << "Cannot find faceZone " << zoneName_ << nl << "Valid zones are "
<< mesh_.faceZones().names()
<< exit(FatalError);
}
const faceZone& fZone = mesh_.faceZones()[readID];
forAll(fZone, i)
{
label faceI = fZone[i];
if (faceToZoneID[faceI] == -1)
{
faceToZoneID[faceI] = zoneID;
faceToFlip[faceI] = fZone.flipMap()[i];
}
else if (faceToZoneID[faceI] != zoneID)
{
FatalErrorIn
(
"faceSelections::faceZoneSelection::select(labelList&) const"
) << "Face " << faceI << " already in faceZone "
<< faceToZoneID[faceI]
<< exit(FatalError);
}
}
faceSelection::select(zoneID, faceToZoneID, faceToFlip);
}
// ************************************************************************* //

View File

@ -0,0 +1,114 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2014 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::faceSelections::faceZoneSelection
Description
Select faces from faceZone
SourceFiles
faceZoneSelection.C
\*---------------------------------------------------------------------------*/
#ifndef faceZoneSelection_H
#define faceZoneSelection_H
#include "faceSelection.H"
#include "pointField.H"
#include "boolList.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class regionSplit;
namespace faceSelections
{
/*---------------------------------------------------------------------------*\
Class faceZoneSelection Declaration
\*---------------------------------------------------------------------------*/
class faceZoneSelection
:
public faceSelection
{
// Private data
//- Name of faceZone
const word zoneName_;
// Private Member Functions
public:
//- Runtime type information
TypeName("faceZone");
// Constructors
//- Construct from dictionary
faceZoneSelection
(
const word& name,
const fvMesh& mesh,
const dictionary& dict
);
//- Clone
autoPtr<faceSelection> clone() const
{
notImplemented("autoPtr<faceSelection> clone() const");
return autoPtr<faceSelection>(NULL);
}
//- Destructor
virtual ~faceZoneSelection();
// Member Functions
//- Apply this selector
virtual void select(const label zoneID, labelList&, boolList&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace faceSelections
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,181 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "searchableSurfaceSelection.H"
#include "addToRunTimeSelectionTable.H"
#include "syncTools.H"
#include "searchableSurface.H"
#include "fvMesh.H"
#include "Time.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace faceSelections
{
defineTypeNameAndDebug(searchableSurfaceSelection, 0);
addToRunTimeSelectionTable
(
faceSelection,
searchableSurfaceSelection,
dictionary
);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::faceSelections::searchableSurfaceSelection::searchableSurfaceSelection
(
const word& name,
const fvMesh& mesh,
const dictionary& dict
)
:
faceSelection(name, mesh, dict),
surfacePtr_
(
searchableSurface::New
(
word(dict.lookup("surface")),
IOobject
(
dict.lookupOrDefault("name", mesh.objectRegistry::db().name()),
mesh.time().constant(),
"triSurface",
mesh.objectRegistry::db(),
IOobject::MUST_READ,
IOobject::NO_WRITE
),
dict
)
)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::faceSelections::searchableSurfaceSelection::~searchableSurfaceSelection()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::faceSelections::searchableSurfaceSelection::select
(
const label zoneID,
labelList& faceToZoneID,
boolList& faceToFlip
) const
{
// Get cell-cell centre vectors
pointField start(mesh_.nFaces());
pointField end(mesh_.nFaces());
// Internal faces
for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
{
start[faceI] = mesh_.cellCentres()[mesh_.faceOwner()[faceI]];
end[faceI] = mesh_.cellCentres()[mesh_.faceNeighbour()[faceI]];
}
// Boundary faces
vectorField neighbourCellCentres;
syncTools::swapBoundaryCellPositions
(
mesh_,
mesh_.cellCentres(),
neighbourCellCentres
);
const polyBoundaryMesh& pbm = mesh_.boundaryMesh();
forAll(pbm, patchI)
{
const polyPatch& pp = pbm[patchI];
if (pp.coupled())
{
forAll(pp, i)
{
label faceI = pp.start()+i;
start[faceI] = mesh_.cellCentres()[mesh_.faceOwner()[faceI]];
end[faceI] = neighbourCellCentres[faceI-mesh_.nInternalFaces()];
}
}
else
{
forAll(pp, i)
{
label faceI = pp.start()+i;
start[faceI] = mesh_.cellCentres()[mesh_.faceOwner()[faceI]];
end[faceI] = mesh_.faceCentres()[faceI];
}
}
}
List<pointIndexHit> hits;
surfacePtr_().findLine(start, end, hits);
pointField normals;
surfacePtr_().getNormal(hits, normals);
//- Note: do not select boundary faces.
for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++)
{
if (hits[faceI].hit())
{
faceToZoneID[faceI] = zoneID;
vector d = end[faceI]-start[faceI];
faceToFlip[faceI] = ((normals[faceI] & d) < 0);
}
}
forAll(pbm, patchI)
{
const polyPatch& pp = pbm[patchI];
if (pp.coupled())
{
forAll(pp, i)
{
label faceI = pp.start()+i;
if (hits[faceI].hit())
{
faceToZoneID[faceI] = zoneID;
vector d = end[faceI]-start[faceI];
faceToFlip[faceI] = ((normals[faceI] & d) < 0);
}
}
}
}
faceSelection::select(zoneID, faceToZoneID, faceToFlip);
}
// ************************************************************************* //

View File

@ -0,0 +1,106 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::faceSelections::searchableSurfaceSelection
Description
Selects all (internal or coupled) faces intersecting the searchableSurface.
SourceFiles
searchableSurfaceSelection.C
\*---------------------------------------------------------------------------*/
#ifndef searchableSurfaceSelection_H
#define searchableSurfaceSelection_H
#include "faceSelection.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class searchableSurface;
namespace faceSelections
{
/*---------------------------------------------------------------------------*\
Class searchableSurfaceSelection Declaration
\*---------------------------------------------------------------------------*/
class searchableSurfaceSelection
:
public faceSelection
{
// Private data
autoPtr<searchableSurface> surfacePtr_;
public:
//- Runtime type information
TypeName("searchableSurface");
// Constructors
//- Construct from dictionary
searchableSurfaceSelection
(
const word& name,
const fvMesh& mesh,
const dictionary& dict
);
//- Clone
autoPtr<faceSelection> clone() const
{
notImplemented("autoPtr<faceSelection> clone() const");
return autoPtr<faceSelection>(NULL);
}
//- Destructor
virtual ~searchableSurfaceSelection();
// Member Functions
virtual void select(const label zoneID, labelList&, boolList&) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace faceSelections
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //