Added support for patch manipulation of pointFields

e.g. during createBaffles

Added a test application and test case for meshTools: test/fvMeshTools

Patch contributed by Mattijs Janssens
This commit is contained in:
Henry Weller
2019-04-12 18:44:32 +01:00
parent 181f110a2f
commit 3cbb932be8
49 changed files with 2296 additions and 779 deletions

11
test/fvMeshTools/Allrun Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
wmake Test-fvMeshTools
( cd cavity && ./Allrun $* )
#------------------------------------------------------------------------------

View File

@ -0,0 +1,3 @@
Test-fvMeshTools.C
EXE = $(FOAM_USER_APPBIN)/Test-fvMeshTools

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,217 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2019 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
Test-fvMeshTools
Description
Testing of adding and removing patches.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "Time.H"
#include "ReadFields.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "pointFields.H"
#include "fvMeshTools.H"
#include "wallPolyPatch.H"
#include "processorFvPatchField.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::addNote("Test patch manipulation");
#include "addRegionOption.H"
#include "setRootCase.H"
#include "createTime.H"
runTime.functionObjects().off();
#include "createNamedMesh.H"
// Read objects in time directory
IOobjectList objects(mesh, runTime.timeName());
Info<< "Reading geometric fields" << nl << endl;
const bool fields = true;
#include "readVolFields.H"
#include "readSurfaceFields.H"
#include "readPointFields.H"
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
// Add/insert a (global) wall patch
{
wallPolyPatch pp
(
"myWall",
0, // dummy
0, // dummy
0, // dummy
pbm,
wallPolyPatch::typeName
);
label newPatchi = fvMeshTools::addPatch
(
mesh,
pp,
dictionary(), // no specialised patch fields
calculatedFvPatchField<scalar>::typeName,
true // parallel sync'ed addition
);
Info<< "Inserted patch " << mesh.boundaryMesh()[newPatchi].name()
<< " type " << mesh.boundaryMesh()[newPatchi].type()
<< " at index " << newPatchi << endl;
runTime++;
mesh.setInstance(runTime.timeName());
Info<< "Writing mesh with added patch to " << runTime.timeName()
<< endl;
mesh.write();
}
// Remove a (zero-sized!) patch everywhere
const label removei = 0;
if (!isA<processorPolyPatch>(pbm[removei]) && pbm[removei].size() == 0)
{
Info<< "Removing patch " << pbm[removei].name() << endl;
labelList oldToNew(pbm.size());
for (label i = 0; i < removei; i++)
{
oldToNew[i] = i;
}
oldToNew[removei] = pbm.size()-1;
for (label i = removei+1; i < oldToNew.size(); i++)
{
oldToNew[i] = i-1;
}
fvMeshTools::reorderPatches(mesh, oldToNew, pbm.size()-1, true);
runTime++;
mesh.setInstance(runTime.timeName());
Info<< "Writing mesh with removed patch to " << runTime.timeName()
<< endl;
mesh.write();
}
// Add a pair of processor patches
if (Pstream::parRun())
{
word newPatchName;
if (Pstream::myProcNo() == 0 || Pstream::myProcNo() == 1)
{
const label nbrProcNo = (1-Pstream::myProcNo());
newPatchName =
processorPolyPatch::newName(Pstream::myProcNo(), nbrProcNo)
+ "_extra";
dictionary dict;
dict.add("myProcNo", Pstream::myProcNo());
dict.add("neighbProcNo", nbrProcNo);
dict.add("startFace", 0);
dict.add("nFaces", 0);
processorPolyPatch pp
(
newPatchName,
dict,
0, // dummy index
pbm,
processorPolyPatch::typeName
);
label newPatchi = fvMeshTools::addPatch
(
mesh,
pp,
dictionary(), // no specialised patch fields
processorFvPatchField<scalar>::typeName,
false // parallel sync'ed addition
);
Pout<< "Inserted patch " << mesh.boundaryMesh()[newPatchi].name()
<< " type " << mesh.boundaryMesh()[newPatchi].type()
<< " at index " << newPatchi << endl;
}
// Note: write on all processors. There is a slight problem in
// reconstructPar: mesh.readUpdate checks that the boundary file is
// different. On proc 0 and 1 it will be different, on proc2.. it
// stays the same. This causes a failure in reconstructPar.
runTime++;
mesh.setInstance(runTime.timeName());
Info<< "Writing mesh with added (local) patch to " << runTime.timeName()
<< endl;
mesh.write();
// Remove the added patch
if (newPatchName.size())
{
label removei = pbm.findPatchID(newPatchName);
if (removei == -1)
{
FatalErrorInFunction << "Problem" << exit(FatalError);
}
Info<< "Removing patch " << pbm[removei].name() << endl;
labelList oldToNew(pbm.size());
for (label i = 0; i < removei; i++)
{
oldToNew[i] = i;
}
oldToNew[removei] = pbm.size()-1;
for (label i = removei+1; i < oldToNew.size(); i++)
{
oldToNew[i] = i-1;
}
fvMeshTools::reorderPatches(mesh, oldToNew, pbm.size()-1, false);
}
runTime++;
mesh.setInstance(runTime.timeName());
Info<< "Writing mesh with removed local patch to " << runTime.timeName()
<< endl;
mesh.write();
}
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,45 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0);
boundaryField
{
zeroSizedPatch
{
type noSlip;
}
movingWall
{
type fixedValue;
value uniform (1 0 0);
}
fixedWalls
{
type noSlip;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,44 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object p;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
zeroSizedPatch
{
type zeroGradient;
}
movingWall
{
type zeroGradient;
}
fixedWalls
{
type zeroGradient;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,46 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class pointVectorField;
location "0";
object pointDisplacement;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 0 0 0 0 0];
internalField uniform (0 0 0);
boundaryField
{
zeroSizedPatch
{
type noSlip;
}
movingWall
{
type noSlip;
}
fixedWalls
{
type noSlip;
}
frontAndBack
{
type empty;
}
}
// ************************************************************************* //

23
test/fvMeshTools/cavity/Allrun Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
runApplication blockMesh
runApplication $(getApplication)
runApplication checkMesh
runApplication foamToVTK
runApplication decomposePar
runParallel -s par $(getApplication)
runParallel -s par checkMesh
runParallel -s par foamToEnsight
runApplication reconstructParMesh -mergeTol 1e-6
# This will fail for any processors that does not have any local patches
# added so exclude that time
runApplication reconstructPar -time '0:0.01'
runApplication -s latestTime reconstructPar -latestTime
#------------------------------------------------------------------------------

View File

@ -0,0 +1,82 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 0.1;
vertices
(
(0 0 0)
(1 0 0)
(1 1 0)
(0 1 0)
(0 0 0.1)
(1 0 0.1)
(1 1 0.1)
(0 1 0.1)
);
blocks
(
hex (0 1 2 3 4 5 6 7) (20 20 1) simpleGrading (1 1 1)
);
edges
(
);
boundary
(
zeroSizedPatch
{
type wall;
faces
(
);
}
movingWall
{
type wall;
faces
(
(3 7 6 2)
);
}
fixedWalls
{
type wall;
faces
(
(0 4 7 3)
(2 6 5 1)
(1 5 4 0)
);
}
frontAndBack
{
type empty;
faces
(
(0 3 2 1)
(4 5 6 7)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //

View File

@ -0,0 +1,49 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application Test-fvMeshTools;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.01;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //

View File

@ -0,0 +1,21 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object decomposeParDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
numberOfSubdomains 3;
method scotch;
// ************************************************************************* //

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
{
version 2.0;
format ascii;
class dictionary;
location "system";
object fvSchemes;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
ddtSchemes
{
#ifeq ${FOAM_APPLICATION} icoFoam
default steadyState;
#else
default Euler;
#endif
}
gradSchemes
{
default Gauss linear;
grad(p) Gauss linear;
}
divSchemes
{
default none;
div(phi,U) Gauss linear;
}
laplacianSchemes
{
default Gauss linear orthogonal;
}
interpolationSchemes
{
default linear;
}
snGradSchemes
{
default orthogonal;
}
// ************************************************************************* //

View File

@ -0,0 +1,52 @@
/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: dev
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
location "system";
object fvSolution;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
solvers
{
p
{
solver PCG;
preconditioner DIC;
tolerance 1e-06;
relTol 0.05;
}
pFinal
{
$p;
relTol 0;
}
U
{
solver smoothSolver;
smoother symGaussSeidel;
tolerance 1e-05;
relTol 0;
}
}
PISO
{
nCorrectors 2;
nNonOrthogonalCorrectors 0;
pRefCell 0;
pRefValue 0;
}
// ************************************************************************* //