Commit 2760c3db authored by Mark Olesen's avatar Mark Olesen
Browse files

Merge commit 'OpenCFD/master' into olesenm

parents 02ef85fa 94f2aac0
PolynomialTest.C
EXE = $(FOAM_USER_APPBIN)/PolynomialTest
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-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
PolynomialTest
Description
Test application for the templated Polynomial class
\*---------------------------------------------------------------------------*/
#include "IFstream.H"
#include "Polynomial.H"
#include "Random.H"
using namespace Foam;
scalar polyValue(const scalar x)
{
// Hard-coded polynomial 8 coeff (7th order)
return
0.11
+ 0.45*x
- 0.94*sqr(x)
+ 1.58*pow3(x)
- 2.58*pow4(x)
+ 0.08*pow5(x)
+ 3.15*pow6(x)
- 4.78*x*pow6(x);
}
scalar intPolyValue(const scalar x)
{
// Hard-coded integrated form of above polynomial
return
0.11*x
+ 0.45/2.0*sqr(x)
- 0.94/3.0*pow3(x)
+ 1.58/4.0*pow4(x)
- 2.58/5.0*pow5(x)
+ 0.08/6.0*pow6(x)
+ 3.15/7.0*x*pow6(x)
- 4.78/8.0*x*x*pow6(x);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
IFstream is("polyTestInput");
Polynomial<8> poly("testPoly", is);
Polynomial<9> intPoly(poly.integrate(0.0));
Info<< "poly = " << poly << endl;
Info<< "intPoly = " << intPoly << nl << endl;
Info<< "2*poly = " << 2*poly << endl;
Info<< "poly+poly = " << poly + poly << nl << endl;
Info<< "3*poly = " << 3*poly << endl;
Info<< "poly+poly+poly = " << poly + poly + poly << nl << endl;
Info<< "3*poly - 2*poly = " << 3*poly - 2*poly << nl << endl;
Polynomial<8> polyCopy = poly;
Info<< "poly, polyCopy = " << poly << ", " << polyCopy << nl << endl;
polyCopy = 2.5*poly;
Info<< "2.5*polyCopy = " << polyCopy << nl << endl;
Random rnd(123456);
for (int i=0; i<10; i++)
{
scalar x = rnd.scalar01()*100;
scalar px = polyValue(x);
scalar ipx = intPolyValue(x);
scalar pxTest = poly.evaluate(x);
scalar ipxTest = intPoly.evaluate(x);
Info<<"\nx = " << x << endl;
Info<< " px, pxTest = " << px << ", " << pxTest << endl;
Info<< " ipx, ipxTest = " << ipx << ", " << ipxTest << endl;
if (mag(px - pxTest) > SMALL)
{
Info<< " *** WARNING: px != pxTest: " << px - pxTest << endl;
}
if (mag(ipx - ipxTest) > SMALL)
{
Info<< " *** WARNING: ipx != ipxTest: " << ipx - ipxTest << endl;
}
Info<< endl;
}
Info<< nl << "Done." << endl;
return 0;
}
// ************************************************************************* //
testPoly
(
0.11
0.45
-0.94
1.58
-2.58
0.08
3.15
-4.78
)
......@@ -93,9 +93,9 @@ void readAndRotateFields
}
void rotateFields(const Time& runTime, const tensor& T)
void rotateFields(const argList& args, const Time& runTime, const tensor& T)
{
# include "createMesh.H"
# include "createNamedMesh.H"
// Read objects in time directory
IOobjectList objects(mesh, runTime.timeName());
......@@ -167,7 +167,11 @@ int main(int argc, char *argv[])
"vector",
"transform in terms of '( yaw pitch roll )' in degrees"
);
argList::addBoolOption("rotateFields");
argList::addBoolOption
(
"rotateFields",
"read and transform vector and tensor fields too"
);
argList::addOption
(
"scale",
......@@ -176,16 +180,29 @@ int main(int argc, char *argv[])
"uniform [mm] to [m] scaling"
);
# include "addRegionOption.H"
# include "setRootCase.H"
# include "createTime.H"
word regionName = polyMesh::defaultRegion;
fileName meshDir;
if (args.optionReadIfPresent("region", regionName))
{
meshDir = regionName/polyMesh::meshSubDir;
}
else
{
meshDir = polyMesh::meshSubDir;
}
pointIOField points
(
IOobject
(
"points",
runTime.findInstance(polyMesh::meshSubDir, "points"),
polyMesh::meshSubDir,
runTime.findInstance(meshDir, "points"),
meshDir,
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE,
......@@ -224,7 +241,7 @@ int main(int argc, char *argv[])
if (args.optionFound("rotateFields"))
{
rotateFields(runTime, T);
rotateFields(args, runTime, T);
}
}
else if (args.optionFound("rollPitchYaw"))
......@@ -247,7 +264,7 @@ int main(int argc, char *argv[])
if (args.optionFound("rotateFields"))
{
rotateFields(runTime, R.R());
rotateFields(args, runTime, R.R());
}
}
else if (args.optionFound("yawPitchRoll"))
......@@ -276,7 +293,7 @@ int main(int argc, char *argv[])
if (args.optionFound("rotateFields"))
{
rotateFields(runTime, R.R());
rotateFields(args, runTime, R.R());
}
}
......
......@@ -34,13 +34,19 @@ Description
Can also work like decomposePar:
@verbatim
# Create empty processor directories (have to exist for argList)
mkdir processor0
..
mkdir processorN
# Copy undecomposed polyMesh
cp -r constant processor0
# Distribute
mpirun -np ddd redistributeMeshPar -parallel
@endverbatim
\*---------------------------------------------------------------------------*/
#include "Field.H"
#include "fvMesh.H"
#include "decompositionMethod.H"
#include "PstreamReduceOps.H"
......@@ -62,6 +68,7 @@ static const scalar defaultMergeTol = 1E-6;
autoPtr<fvMesh> createMesh
(
const Time& runTime,
const word& regionName,
const fileName& instDir,
const bool haveMesh
)
......@@ -69,43 +76,33 @@ autoPtr<fvMesh> createMesh
Pout<< "Create mesh for time = "
<< runTime.timeName() << nl << endl;
// Create dummy mesh. Only used on procs that don't have mesh.
// Note constructed on all processors since does parallel comms.
fvMesh dummyMesh
IOobject io
(
IOobject
(
fvMesh::defaultRegion,
instDir,
runTime,
IOobject::MUST_READ
),
xferCopy(pointField()),
xferCopy(faceList()),
xferCopy(labelList()),
xferCopy(labelList())
regionName,
instDir,
runTime,
IOobject::MUST_READ
);
if (!haveMesh)
{
Pout<< "Writing dummy mesh to " << runTime.path()/instDir << endl;
// Create dummy mesh. Only used on procs that don't have mesh.
fvMesh dummyMesh
(
io,
xferCopy(pointField()),
xferCopy(faceList()),
xferCopy(labelList()),
xferCopy(labelList()),
false
);
Pout<< "Writing dummy mesh to " << dummyMesh.polyMesh::objectPath()
<< endl;
dummyMesh.write();
}
Pout<< "Reading mesh from " << runTime.path()/instDir << endl;
autoPtr<fvMesh> meshPtr
(
new fvMesh
(
IOobject
(
fvMesh::defaultRegion,
instDir,
runTime,
IOobject::MUST_READ
)
)
);
Pout<< "Reading mesh from " << io.objectPath() << endl;
autoPtr<fvMesh> meshPtr(new fvMesh(io));
fvMesh& mesh = meshPtr();
......@@ -229,8 +226,9 @@ autoPtr<fvMesh> createMesh
if (!haveMesh)
{
// We created a dummy mesh file above. Delete it.
Pout<< "Removing dummy mesh in " << runTime.path()/instDir << endl;
rmDir(runTime.path()/instDir/polyMesh::meshSubDir);
Pout<< "Removing dummy mesh " << io.objectPath()
<< endl;
rmDir(io.objectPath());
}
// Force recreation of globalMeshData.
......@@ -285,7 +283,6 @@ scalar getMergeDistance
void printMeshData(Ostream& os, const polyMesh& mesh)
{
os << "Number of points: " << mesh.points().size() << nl
<< " edges: " << mesh.edges().size() << nl
<< " faces: " << mesh.faces().size() << nl
<< " internal faces: " << mesh.faceNeighbour().size() << nl
<< " cells: " << mesh.cells().size() << nl
......@@ -506,17 +503,34 @@ void compareFields
int main(int argc, char *argv[])
{
# include "addRegionOption.H"
argList::addOption("mergeTol", "relative merge distance");
// Create argList. This will check for non-existing processor dirs.
# include "setRootCase.H"
// Create processor directory if non-existing
if (!Pstream::master() && !isDir(args.path()))
//- Not useful anymore. See above.
//// Create processor directory if non-existing
//if (!Pstream::master() && !isDir(args.path()))
//{
// Pout<< "Creating case directory " << args.path() << endl;
// mkDir(args.path());
//}
# include "createTime.H"
word regionName = polyMesh::defaultRegion;
fileName meshSubDir;
if (args.optionReadIfPresent("region", regionName))
{
Pout<< "Creating case directory " << args.path() << endl;
mkDir(args.path());
meshSubDir = regionName/polyMesh::meshSubDir;
}
else
{
meshSubDir = polyMesh::meshSubDir;
}
Info<< "Using mesh subdirectory " << meshSubDir << nl << endl;
# include "createTime.H"
// Get time instance directory. Since not all processors have meshes
// just use the master one everywhere.
......@@ -524,15 +538,18 @@ int main(int argc, char *argv[])
fileName masterInstDir;
if (Pstream::master())
{
masterInstDir = runTime.findInstance(polyMesh::meshSubDir, "points");
masterInstDir = runTime.findInstance(meshSubDir, "points");
}
Pstream::scatter(masterInstDir);
// Check who has a mesh
const fileName meshDir = runTime.path()/masterInstDir/polyMesh::meshSubDir;
const fileName meshPath = runTime.path()/masterInstDir/meshSubDir;
Info<< "Found points in " << meshPath << nl << endl;
boolList haveMesh(Pstream::nProcs(), false);
haveMesh[Pstream::myProcNo()] = isDir(meshDir);
haveMesh[Pstream::myProcNo()] = isDir(meshPath);
Pstream::gatherList(haveMesh);
Pstream::scatterList(haveMesh);
Info<< "Per processor mesh availability : " << haveMesh << endl;
......@@ -542,6 +559,7 @@ int main(int argc, char *argv[])
autoPtr<fvMesh> meshPtr = createMesh
(
runTime,
regionName,
masterInstDir,
haveMesh[Pstream::myProcNo()]
);
......@@ -799,7 +817,7 @@ int main(int argc, char *argv[])
<< nl
<< "the processor directories with 0 sized meshes in them." << nl
<< "Below is a sample set of commands to do this."
<< " Take care when issueing these" << nl
<< " Take care when issuing these" << nl
<< "commands." << nl << endl;
forAll(nFaces, procI)
......@@ -812,8 +830,8 @@ int main(int argc, char *argv[])
}
else
{
fileName timeDir = procDir/runTime.timeName()/polyMesh::meshSubDir;
fileName constDir = procDir/runTime.constant()/polyMesh::meshSubDir;
fileName timeDir = procDir/runTime.timeName()/meshSubDir;
fileName constDir = procDir/runTime.constant()/meshSubDir;
Info<< " rm -r " << constDir.c_str() << nl
<< " mv " << timeDir.c_str()
......
......@@ -9,4 +9,5 @@ EXE_LIBS = \
-ltecio \
-llagrangian \
-lfiniteVolume \
-lgenericPatchFields \
-lmeshTools
......@@ -909,106 +909,115 @@ int main(int argc, char *argv[])
const polyPatch& pp = patches[patchID];
//INTEGER4 strandID = 1 + i;
Info<< " Writing patch " << patchID << "\t" << pp.name()
<< "\tstrand:" << strandID << nl << endl;
if (pp.size() > 0)
{
Info<< " Writing patch " << patchID << "\t" << pp.name()
<< "\tstrand:" << strandID << nl << endl;
const indirectPrimitivePatch ipp
(
IndirectList<face>(pp, identity(pp.size())),
pp.points()
);
const indirectPrimitivePatch ipp
(
IndirectList<face>(pp, identity(pp.size())),
pp.points()
);
writer.writePolygonalZone
(
pp.name(),
strandID++, //strandID,
ipp,
allVarLocation
);
writer.writePolygonalZone
(
pp.name(),
strandID++, //strandID,
ipp,
allVarLocation
);
// Write coordinates
writer.writeField(ipp.localPoints().component(0)());
writer.writeField(ipp.localPoints().component(1)());
writer.writeField(ipp.localPoints().component(2)());
// Write coordinates
writer.writeField(ipp.localPoints().component(0)());
writer.writeField(ipp.localPoints().component(1)());
writer.writeField(ipp.localPoints().component(2)());
// Write all fields
forAll(vsf, i)
{
writer.writeField
(
writer.getPatchField
// Write all fields
forAll(vsf, i)
{
writer.writeField
(
nearCellValue,
vsf[i],
patchID
)()
);
}
forAll(vvf, i)
{
writer.writeField
(
writer.getPatchField
writer.getPatchField
(
nearCellValue,
vsf[i],
patchID
)()
);
}
forAll(vvf, i)
{
writer.writeField
(
nearCellValue,
vvf[i],
patchID
)()
);
}
forAll(vSpheretf, i)
{
writer.writeField
(
writer.getPatchField
writer.getPatchField
(
nearCellValue,
vvf[i],
patchID
)()
);
}
forAll(vSpheretf, i)
{
writer.writeField
(
nearCellValue,
vSpheretf[i],
patchID
)()
);
}
forAll(vSymmtf, i)
{
writer.writeField
(
writer.getPatchField
writer.getPatchField
(
nearCellValue,
vSpheretf[i],
patchID
)()
);
}
forAll(vSymmtf, i)
{
writer.writeField
(
nearCellValue,
vSymmtf[i],
patchID
)()
);
}
forAll(vtf, i)
{
writer.writeField
(
writer.getPatchField
writer.getPatchField
(
nearCellValue,
vSymmtf[i],
patchID
)()
);
}
forAll(vtf, i)
{