From 4bc4c1900bb8496c100328b5022cf6d22682e80f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 5 Apr 2011 20:05:57 +0200 Subject: [PATCH 01/16] ENH: new utility surfaceMeshInfo - useful at the moment for reporting face areas from a surface mesh --- .../surface/surfaceMeshInfo/Make/files | 3 + .../surface/surfaceMeshInfo/Make/options | 5 + .../surface/surfaceMeshInfo/surfaceMeshInfo.C | 230 ++++++++++++++++++ 3 files changed, 238 insertions(+) create mode 100644 applications/utilities/surface/surfaceMeshInfo/Make/files create mode 100644 applications/utilities/surface/surfaceMeshInfo/Make/options create mode 100644 applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C diff --git a/applications/utilities/surface/surfaceMeshInfo/Make/files b/applications/utilities/surface/surfaceMeshInfo/Make/files new file mode 100644 index 0000000000..a008b33fd2 --- /dev/null +++ b/applications/utilities/surface/surfaceMeshInfo/Make/files @@ -0,0 +1,3 @@ +surfaceMeshInfo.C + +EXE = $(FOAM_APPBIN)/surfaceMeshInfo diff --git a/applications/utilities/surface/surfaceMeshInfo/Make/options b/applications/utilities/surface/surfaceMeshInfo/Make/options new file mode 100644 index 0000000000..42b30c8652 --- /dev/null +++ b/applications/utilities/surface/surfaceMeshInfo/Make/options @@ -0,0 +1,5 @@ +EXE_INC = \ + -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/surfMesh/lnInclude + +EXE_LIBS = -lmeshTools -lsurfMesh diff --git a/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C b/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C new file mode 100644 index 0000000000..39d672a341 --- /dev/null +++ b/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C @@ -0,0 +1,230 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2011 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 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 . + +Application + surfaceMeshInfo + +Description + Miscellaneous information about surface meshes + +Usage + - surfaceMeshInfo surfaceFile [OPTION] + + \param -areas \n + Report area for each face. + + \param -scale \ \n + Specify a scaling factor when reading files. + + \param -xml \n + Write output in XML format. + +Note + The filename extensions are used to determine the file format type. + + The XML-like output can be useful for extraction with other tools, + but either output format can be easily extracted with a simple sed + command: + \verbatim + surfaceMeshInfo surfaceFile -areas | \ + sed -ne '/areas/,/:/{ /:/!p }' + + surfaceMeshInfo surfaceFile -areas -xml | \ + sed -ne '/::canRead(importName, true)) + { + return 1; + } + + const bool writeXML = args.optionFound("xml"); + const bool writeAreas = args.optionFound("areas"); + + + // use UnsortedMeshedSurface, not MeshedSurface to maintain ordering + UnsortedMeshedSurface surf(importName); + + scalar scaling = 0; + if (args.optionReadIfPresent("scale", scaling) && scaling > 0) + { + Info<< " -scale " << scaling << endl; + surf.scalePoints(scaling); + } + + scalar areaTotal = 0; + + if (writeXML) + { + Info<<"" << nl + <<"" << nl + << "" << surf.nPoints() << "" << nl + << "" << surf.size() << "" << nl; + + if (writeAreas) + { + Info<<"" << nl; + } + } + else + { + Info<< "nPoints : " << surf.nPoints() << nl + << "nFaces : " << surf.size() << nl; + + if (writeAreas) + { + Info<< "areas : " << nl; + } + } + + forAll(surf, faceI) + { + scalar fArea = mag(faceArea(surf[faceI], surf.points())); + areaTotal += fArea; + + if (writeAreas) + { + Info<< fArea << nl; + } + } + + if (writeXML) + { + if (writeAreas) + { + Info<<"" << nl; + } + + Info<< "" << areaTotal << "" << nl + << "" << nl; + } + else + { + Info<< "area : " << areaTotal << nl; + } + + return 0; +} + +// ************************************************************************* // From cfc1f315d8382ecc7916f43314f1bc8587f8e118 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 7 Apr 2011 09:19:39 +0200 Subject: [PATCH 02/16] ENH: add area() method for face and triFace - optionally returns centre point as well --- src/OpenFOAM/meshes/meshShapes/face/face.C | 132 +++++++++++++++--- src/OpenFOAM/meshes/meshShapes/face/face.H | 27 ++-- .../meshes/meshShapes/triFace/triFace.H | 9 +- .../meshes/meshShapes/triFace/triFaceI.H | 26 +++- 4 files changed, 161 insertions(+), 33 deletions(-) diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.C b/src/OpenFOAM/meshes/meshShapes/face/face.C index 7dbd202335..f0b50dcdda 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.C +++ b/src/OpenFOAM/meshes/meshShapes/face/face.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -491,51 +491,52 @@ void Foam::face::flip() } -Foam::point Foam::face::centre(const pointField& meshPoints) const +Foam::point Foam::face::centre(const pointField& points) const { // Calculate the centre by breaking the face into triangles and // area-weighted averaging their centres + const label nPoints = size(); + // If the face is a triangle, do a direct calculation - if (size() == 3) + if (nPoints) { return (1.0/3.0) *( - meshPoints[operator[](0)] - + meshPoints[operator[](1)] - + meshPoints[operator[](2)] + points[operator[](0)] + + points[operator[](1)] + + points[operator[](2)] ); } - label nPoints = size(); point centrePoint = point::zero; - for (register label pI=0; pI VSMALL) { - return sumAc/(3*sumA); + return sumAc/(3.0*sumA); } else { @@ -554,8 +555,99 @@ Foam::point Foam::face::centre(const pointField& meshPoints) const } +Foam::vector Foam::face::area +( + const pointField& points, + point& centrePt +) const +{ + const label nPoints = this->size(); + const labelList& f = *this; + + // If the face is a triangle, do a direct calculation for efficiency + // and to avoid round-off error-related problems + if (nPoints == 3) + { + // return centre point information? + if (¢rePt) + { + centrePt = + ( + (1.0/3.0) + * (points[f[0]] + points[f[1]] + points[f[2]]) + ); + } + + return + ( + 0.5 + * + ( + (points[f[1]] - points[f[0]]) + ^ (points[f[2]] - points[f[0]]) + ) + ); + } + + point fCentre = points[f[0]]; + for (label pI = 1; pI < nPoints; ++pI) + { + fCentre += points[f[pI]]; + } + + fCentre /= nPoints; + + vector sumN2 = vector::zero; + scalar sumA = 0.0; + vector sumAc = vector::zero; // for area-weighted centre + + for (label pI = 0; pI < nPoints; ++pI) + { + const point& nextPoint = points[f[(pI + 1) % nPoints]]; + + // Calculate 3*triangle centre + const vector ttc + ( + points[f[pI]] + + nextPoint + + fCentre + ); + + // Calculate 2*triangle normal + const vector n2 + ( + (nextPoint - points[f[pI]]) ^ (fCentre - points[f[pI]]) + ); + + // 2*triangle area + const scalar ta(Foam::mag(n2)); + + sumN2 += n2; + sumA += ta; + sumAc += ta*ttc; + } + + // return centre point information? + if (¢rePt) + { + if (sumA > VSMALL) + { + centrePt = sumAc/(3.0*sumA); + } + else + { + centrePt = fCentre; + } + } + + return 0.5*sumN2; +} + + Foam::vector Foam::face::normal(const pointField& p) const { + const label nPoints = size(); + // Calculate the normal by summing the face triangle normals. // Changed to deal with small concavity by using a central decomposition // @@ -563,7 +655,7 @@ Foam::vector Foam::face::normal(const pointField& p) const // If the face is a triangle, do a direct calculation to avoid round-off // error-related problems // - if (size() == 3) + if (nPoints == 3) { return triPointRef ( @@ -573,12 +665,10 @@ Foam::vector Foam::face::normal(const pointField& p) const ).normal(); } - label nPoints = size(); - register label pI; point centrePoint = vector::zero; - for (pI = 0; pI < nPoints; pI++) + for (pI = 0; pI < nPoints; ++pI) { centrePoint += p[operator[](pI)]; } @@ -588,7 +678,7 @@ Foam::vector Foam::face::normal(const pointField& p) const point nextPoint = centrePoint; - for (pI = 0; pI < nPoints; pI++) + for (pI = 0; pI < nPoints; ++pI) { if (pI < nPoints - 1) { diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index 34a66b8524..9fa82bf5fc 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -178,11 +178,18 @@ public: void flip(); //- Return the points corresponding to this face - inline pointField points(const pointField& meshPoints) const; + inline pointField points(const pointField&) const; //- Centre point of face point centre(const pointField&) const; + //- Area of face, optionally return centre point as well + vector area + ( + const pointField&, + point& centrePt = *reinterpret_cast(0) + ) const; + //- Calculate average value at centroid of face template Type average(const pointField&, const Field&) const; @@ -228,8 +235,8 @@ public: //- Return potential intersection with face with a ray starting // at p, direction n (does not need to be normalized) - // Does face-center decomposition and returns triangle intersection - // point closest to p. Face-center is calculated from point average. + // Does face-centre decomposition and returns triangle intersection + // point closest to p. Face-centre is calculated from point average. // For a hit, the distance is signed. Positive number // represents the point in front of triangle // In case of miss the point is the nearest point on the face @@ -242,20 +249,20 @@ public: ( const point& p, const vector& n, - const pointField& meshPoints, + const pointField&, const intersection::algorithm alg = intersection::FULL_RAY, const intersection::direction dir = intersection::VECTOR ) const; //- Fast intersection with a ray. - // Does face-center decomposition and returns triangle intersection + // Does face-centre decomposition and returns triangle intersection // point closest to p. See triangle::intersection for details. pointHit intersection ( const point& p, const vector& q, const point& ctr, - const pointField& meshPoints, + const pointField&, const intersection::algorithm alg, const scalar tol = 0.0 ) const; @@ -264,7 +271,7 @@ public: pointHit nearestPoint ( const point& p, - const pointField& meshPoints + const pointField& ) const; //- Return nearest point to face and classify it: @@ -276,7 +283,7 @@ public: pointHit nearestPointClassify ( const point& p, - const pointField& meshPoints, + const pointField&, label& nearType, label& nearLabel ) const; @@ -286,13 +293,13 @@ public: ( const point& p, const vector& n, - const pointField& meshPoints + const pointField& ) const; //- Return area in contact, given the displacement in vertices scalar areaInContact ( - const pointField& points, + const pointField&, const scalarField& v ) const; diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H index 03e992575f..6528d7350e 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H @@ -103,7 +103,7 @@ public: inline void flip(); //- Return the points corresponding to this face - inline pointField points(const pointField& meshPoints) const; + inline pointField points(const pointField&) const; //- Return triangle as a face inline face triFaceFace() const; @@ -114,6 +114,13 @@ public: //- Return centre (centroid) inline point centre(const pointField&) const; + //- Area, optionally return centre point as well + inline point area + ( + const pointField&, + point& centrePt = *reinterpret_cast(0) + ) const; + //- Calculate average value at centroid of face template Type average(const pointField&, const Field&) const; diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H index e12f175675..58274f36c7 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -171,6 +171,30 @@ inline Foam::point Foam::triFace::centre(const pointField& points) const } +inline Foam::point Foam::triFace::area +( + const pointField& points, + point& centrePt +) const +{ + // return centre point information? + if (¢rePt) + { + centrePt = this->centre(points); + } + + return + ( + 0.5 + * + ( + (points[operator[](1)] - points[operator[](0)]) + ^ (points[operator[](2)] - points[operator[](0)]) + ) + ); +} + + inline Foam::scalar Foam::triFace::mag(const pointField& points) const { return ::Foam::mag(normal(points)); From 9153534a9dcb59d0e0f46e3f298e7a41eebccedb Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 7 Apr 2011 09:29:05 +0200 Subject: [PATCH 03/16] ENH: use face::area() method for surfaceMeshInfo --- .../surface/surfaceMeshInfo/surfaceMeshInfo.C | 55 +------------------ 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C b/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C index 39d672a341..d3b3145c1d 100644 --- a/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C +++ b/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C @@ -64,59 +64,6 @@ Note using namespace Foam; -// -// duplicates code from primitiveMeshFaceCentresAndAreas.C -// should be refactored -// -Foam::vector faceArea(const face& fs, const pointField& p) -{ - const labelList& f = fs; - label nPoints = f.size(); - - point fCentre; - vector fArea; - - // If the face is a triangle, do a direct calculation for efficiency - // and to avoid round-off error-related problems - if (nPoints == 3) - { - fCentre = (1.0/3.0)*(p[f[0]] + p[f[1]] + p[f[2]]); - fArea = 0.5*((p[f[1]] - p[f[0]])^(p[f[2]] - p[f[0]])); - } - else - { - fCentre = p[f[0]]; - for (label pi = 1; pi < nPoints; ++pi) - { - fCentre += p[f[pi]]; - } - - fCentre /= nPoints; - - vector sumN = vector::zero; - scalar sumA = 0.0; - vector sumAc = vector::zero; - - for (label pi = 0; pi < nPoints; ++pi) - { - const point& nextPoint = p[f[(pi + 1) % nPoints]]; - - const vector c = p[f[pi]] + nextPoint + fCentre; - const vector n = (nextPoint - p[f[pi]])^(fCentre - p[f[pi]]); - const scalar a = mag(n); - - sumN += n; - sumA += a; - sumAc += a*c; - } - - fArea = 0.5*sumN; - } - - return fArea; -} - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: @@ -200,7 +147,7 @@ int main(int argc, char *argv[]) forAll(surf, faceI) { - scalar fArea = mag(faceArea(surf[faceI], surf.points())); + const scalar fArea(Foam::mag(surf[faceI].area(surf.points()))); areaTotal += fArea; if (writeAreas) From 1d4fdf1b9f73595ea43a9bd96e34f2ba2ea80855 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 12 Apr 2011 12:44:28 +0200 Subject: [PATCH 04/16] STYLE: return type on triFace::area --- src/OpenFOAM/meshes/meshShapes/triFace/triFace.H | 2 +- src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H index 6528d7350e..21ac6065b6 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H @@ -115,7 +115,7 @@ public: inline point centre(const pointField&) const; //- Area, optionally return centre point as well - inline point area + inline vector area ( const pointField&, point& centrePt = *reinterpret_cast(0) diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H index 58274f36c7..501a6fe1cd 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H @@ -171,7 +171,7 @@ inline Foam::point Foam::triFace::centre(const pointField& points) const } -inline Foam::point Foam::triFace::area +inline Foam::vector Foam::triFace::area ( const pointField& points, point& centrePt @@ -183,15 +183,7 @@ inline Foam::point Foam::triFace::area centrePt = this->centre(points); } - return - ( - 0.5 - * - ( - (points[operator[](1)] - points[operator[](0)]) - ^ (points[operator[](2)] - points[operator[](0)]) - ) - ); + return this->normal(points); } From 03bae68436912a404c88c11f0a2ac224749a073e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 12 Apr 2011 12:53:51 +0200 Subject: [PATCH 05/16] STYLE: drop face::area() and triFace::area() - less useful than expected --- .../surface/surfaceMeshInfo/surfaceMeshInfo.C | 2 +- src/OpenFOAM/meshes/meshShapes/face/face.C | 89 ------------------- src/OpenFOAM/meshes/meshShapes/face/face.H | 9 +- .../meshes/meshShapes/triFace/triFace.H | 11 +-- .../meshes/meshShapes/triFace/triFaceI.H | 17 +--- 5 files changed, 5 insertions(+), 123 deletions(-) diff --git a/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C b/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C index d3b3145c1d..0e08e333fd 100644 --- a/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C +++ b/applications/utilities/surface/surfaceMeshInfo/surfaceMeshInfo.C @@ -147,7 +147,7 @@ int main(int argc, char *argv[]) forAll(surf, faceI) { - const scalar fArea(Foam::mag(surf[faceI].area(surf.points()))); + const scalar fArea(surf[faceI].mag(surf.points())); areaTotal += fArea; if (writeAreas) diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.C b/src/OpenFOAM/meshes/meshShapes/face/face.C index f0b50dcdda..4060404af7 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.C +++ b/src/OpenFOAM/meshes/meshShapes/face/face.C @@ -555,95 +555,6 @@ Foam::point Foam::face::centre(const pointField& points) const } -Foam::vector Foam::face::area -( - const pointField& points, - point& centrePt -) const -{ - const label nPoints = this->size(); - const labelList& f = *this; - - // If the face is a triangle, do a direct calculation for efficiency - // and to avoid round-off error-related problems - if (nPoints == 3) - { - // return centre point information? - if (¢rePt) - { - centrePt = - ( - (1.0/3.0) - * (points[f[0]] + points[f[1]] + points[f[2]]) - ); - } - - return - ( - 0.5 - * - ( - (points[f[1]] - points[f[0]]) - ^ (points[f[2]] - points[f[0]]) - ) - ); - } - - point fCentre = points[f[0]]; - for (label pI = 1; pI < nPoints; ++pI) - { - fCentre += points[f[pI]]; - } - - fCentre /= nPoints; - - vector sumN2 = vector::zero; - scalar sumA = 0.0; - vector sumAc = vector::zero; // for area-weighted centre - - for (label pI = 0; pI < nPoints; ++pI) - { - const point& nextPoint = points[f[(pI + 1) % nPoints]]; - - // Calculate 3*triangle centre - const vector ttc - ( - points[f[pI]] - + nextPoint - + fCentre - ); - - // Calculate 2*triangle normal - const vector n2 - ( - (nextPoint - points[f[pI]]) ^ (fCentre - points[f[pI]]) - ); - - // 2*triangle area - const scalar ta(Foam::mag(n2)); - - sumN2 += n2; - sumA += ta; - sumAc += ta*ttc; - } - - // return centre point information? - if (¢rePt) - { - if (sumA > VSMALL) - { - centrePt = sumAc/(3.0*sumA); - } - else - { - centrePt = fCentre; - } - } - - return 0.5*sumN2; -} - - Foam::vector Foam::face::normal(const pointField& p) const { const label nPoints = size(); diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index 9fa82bf5fc..723d9bbfb7 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -183,18 +183,11 @@ public: //- Centre point of face point centre(const pointField&) const; - //- Area of face, optionally return centre point as well - vector area - ( - const pointField&, - point& centrePt = *reinterpret_cast(0) - ) const; - //- Calculate average value at centroid of face template Type average(const pointField&, const Field&) const; - //- Scalar magnitude + //- Magnitude of face area inline scalar mag(const pointField&) const; //- Vector normal; magnitude is equal to area of face diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H index 21ac6065b6..933cb52239 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H @@ -114,21 +114,14 @@ public: //- Return centre (centroid) inline point centre(const pointField&) const; - //- Area, optionally return centre point as well - inline vector area - ( - const pointField&, - point& centrePt = *reinterpret_cast(0) - ) const; - //- Calculate average value at centroid of face template Type average(const pointField&, const Field&) const; - //- Return scalar magnitude + //- Magnitude of face area inline scalar mag(const pointField&) const; - //- Return vector normal + //- Vector normal; magnitude is equal to area of face inline vector normal(const pointField&) const; //- Number of triangles after splitting diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H index 501a6fe1cd..af62aa1aa3 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H @@ -171,27 +171,12 @@ inline Foam::point Foam::triFace::centre(const pointField& points) const } -inline Foam::vector Foam::triFace::area -( - const pointField& points, - point& centrePt -) const -{ - // return centre point information? - if (¢rePt) - { - centrePt = this->centre(points); - } - - return this->normal(points); -} - - inline Foam::scalar Foam::triFace::mag(const pointField& points) const { return ::Foam::mag(normal(points)); } + // could also delegate to triPointRef(...).normal() inline Foam::vector Foam::triFace::normal(const pointField& points) const { From e1137fe8e29863ddad360ffed3fd4f323124a6a2 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 15 Apr 2011 13:32:59 +0200 Subject: [PATCH 06/16] ENH: add convenience handling of "roots" when the slave roots are identical - a single root entry is interpreted as being the same for all slaves --- doc/changes/inotify.txt | 18 +++++++++--- src/OpenFOAM/global/argList/argList.C | 41 ++++++++++++++++++--------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/doc/changes/inotify.txt b/doc/changes/inotify.txt index 0f91d7c03b..74e2fc7bb4 100644 --- a/doc/changes/inotify.txt +++ b/doc/changes/inotify.txt @@ -55,15 +55,25 @@ timestamps as before or the (linux-specific) 'inotify' system framework - the slave processor directories have no system directory and the constant directory only contains the mesh. - start the job in distributed mode by specifying the slave roots - (so one less than the number of processors) with - the -roots command line option: + (so one fewer than the number of processors) with + the -roots command-line option: - mpirun -np 2 icoFoam -roots '("/tmp")' -parallel + mpirun -np 4 icoFoam -roots '("/tmp" "/tmp" "/tmp")' -parallel - the alternative to the -roots option is to have a cavity/system/decomposeParDict on the master with distributed yes; - roots ("/tmp"); + roots ("/tmp" "/tmp" "/tmp"); + + - as a convenience for cases when the slave roots are identical, + a single root entry is interpreted as being the same for all slaves. + With the -roots command-line option, this can take one of two forms: + + mpirun -np 4 icoFoam -roots '("/tmp")' -parallel + + or simply + + mpirun -np 4 icoFoam -roots '"/tmp"' -parallel Details: diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index f055011bce..cce4739eae 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -549,9 +549,13 @@ Foam::argList::argList if (options_.found("roots")) { source = "'-roots' option"; - IStringStream str(options_["roots"]); - str >> roots; - dictNProcs = roots.size()+1; + IStringStream is(options_["roots"]); + roots = readList(is); + + if (roots.size() != 1) + { + dictNProcs = roots.size()+1; + } } else { @@ -579,6 +583,21 @@ Foam::argList::argList } } + // convenience: + // when a single root is specified, use it for all processes + if (roots.size() == 1) + { + const fileName rootName(roots[0]); + roots.setSize(Pstream::nProcs()-1, rootName); + + // adjust dictNProcs for command-line '-roots' option + if (dictNProcs < 0) + { + dictNProcs = roots.size()+1; + } + } + + // Check number of processors. // nProcs => number of actual procs // dictNProcs => number of procs specified in decompositionDict @@ -602,11 +621,6 @@ Foam::argList::argList // distributed data if (roots.size()) { - forAll(roots, i) - { - roots[i].expand(); - } - if (roots.size() != Pstream::nProcs()-1) { FatalError @@ -617,6 +631,11 @@ Foam::argList::argList << exit(FatalError); } + forAll(roots, i) + { + roots[i].expand(); + } + // Distribute the master's argument list (with new root) bool hadCaseOpt = options_.found("case"); for @@ -626,11 +645,7 @@ Foam::argList::argList slave++ ) { - options_.set - ( - "case", - fileName(roots[slave-1])/globalCase_ - ); + options_.set("case", roots[slave-1]/globalCase_); OPstream toSlave(Pstream::scheduled, slave); toSlave << args_ << options_; From c20efb0923910709ecc0fe805113abfba3b9e6f6 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 15 Apr 2011 13:34:25 +0200 Subject: [PATCH 07/16] ENH: add 'report' to trace #includeEntry/#includeIfPresentEntry - used in "expandDictionary -list" to find which files are included by any particular dictionary --- .../expandDictionary/expandDictionary.C | 47 +++++++++++++++++-- .../includeEntry/includeEntry.C | 19 ++++++-- .../includeEntry/includeEntry.H | 6 +++ .../includeIfPresentEntry.C | 16 +++++-- 4 files changed, 77 insertions(+), 11 deletions(-) diff --git a/applications/utilities/miscellaneous/expandDictionary/expandDictionary.C b/applications/utilities/miscellaneous/expandDictionary/expandDictionary.C index b28d976832..c8beecc361 100644 --- a/applications/utilities/miscellaneous/expandDictionary/expandDictionary.C +++ b/applications/utilities/miscellaneous/expandDictionary/expandDictionary.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2008-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -28,12 +28,33 @@ Description Read the dictionary provided as an argument, expand the macros etc. and write the resulting dictionary to standard output. +Usage + - expandDictionary inputDict [OPTION] + + \param -list \n + Report the #include/#includeIfPresent to stdout only. + +Note + The \c -list option can be useful when determining which files + are actually included by a directory. It can also be used to + determine which files may need to be copied when transferring + simulation to another environment. The following code snippet + could be a useful basis for such cases: + + \verbatim + for i in . 0 constant system + do + find $i -maxdepth 1 -type f -exec expandDictionary -list '{}' \; + done | sed -ne '/^"\//!{ s/^"//; s/"$//; p }' | sort | uniq + \endverbatim + \*---------------------------------------------------------------------------*/ #include "argList.H" #include "IFstream.H" #include "IOobject.H" #include "dictionary.H" +#include "includeEntry.H" using namespace Foam; @@ -48,6 +69,12 @@ int main(int argc, char *argv[]) "the resulting dictionary to standard output." ); + argList::addBoolOption + ( + "list", + "Report the #include/#includeIfPresent to stdout only" + ); + argList::noBanner(); argList::noParallel(); argList::validArgs.append("inputDict"); @@ -55,12 +82,22 @@ int main(int argc, char *argv[]) const string dictName = args[1]; - IOobject::writeBanner(Info) - <<"//\n// " << dictName << "\n//\n"; + const bool listOpt = args.optionFound("list"); - dictionary(IFstream(dictName)(), true).write(Info, false); + if (listOpt) + { + Foam::functionEntries::includeEntry::report = true; + } - IOobject::writeDivider(Info); + dictionary dict(IFstream(dictName)(), true); + + if (!listOpt) + { + IOobject::writeBanner(Info) + <<"//\n// " << dictName << "\n//\n"; + dict.write(Info, false); + IOobject::writeDivider(Info); + } return 0; } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C index ee20e33191..c45ef4f291 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -39,6 +39,9 @@ const Foam::word Foam::functionEntries::includeEntry::typeName // might include includeEntry int Foam::functionEntries::includeEntry::debug(0); +bool Foam::functionEntries::includeEntry::report(false); + + namespace Foam { namespace functionEntries @@ -89,10 +92,15 @@ bool Foam::functionEntries::includeEntry::execute Istream& is ) { - IFstream ifs(includeFileName(is)); + const fileName fName(includeFileName(is)); + IFstream ifs(fName); if (ifs) { + if (Foam::functionEntries::includeEntry::report) + { + Info<< fName << endl; + } parentDict.read(ifs); return true; } @@ -119,10 +127,15 @@ bool Foam::functionEntries::includeEntry::execute Istream& is ) { - IFstream ifs(includeFileName(is)); + const fileName fName(includeFileName(is)); + IFstream ifs(fName); if (ifs) { + if (Foam::functionEntries::includeEntry::report) + { + Info<< fName << endl; + } entry.read(parentDict, ifs); return true; } diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H index 5145b742ae..be99bf588a 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeEntry/includeEntry.H @@ -82,6 +82,12 @@ protected: public: + // Static data members + + //- Report which file is included to stdout + static bool report; + + //- Runtime type information ClassName("include"); diff --git a/src/OpenFOAM/db/dictionary/functionEntries/includeIfPresentEntry/includeIfPresentEntry.C b/src/OpenFOAM/db/dictionary/functionEntries/includeIfPresentEntry/includeIfPresentEntry.C index 86f1618163..8e1bc9b7f1 100644 --- a/src/OpenFOAM/db/dictionary/functionEntries/includeIfPresentEntry/includeIfPresentEntry.C +++ b/src/OpenFOAM/db/dictionary/functionEntries/includeIfPresentEntry/includeIfPresentEntry.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -69,10 +69,15 @@ bool Foam::functionEntries::includeIfPresentEntry::execute Istream& is ) { - IFstream ifs(includeFileName(is)); + const fileName fName(includeFileName(is)); + IFstream ifs(fName); if (ifs) { + if (Foam::functionEntries::includeEntry::report) + { + Info<< fName << endl; + } parentDict.read(ifs); } @@ -87,10 +92,15 @@ bool Foam::functionEntries::includeIfPresentEntry::execute Istream& is ) { - IFstream ifs(includeFileName(is)); + const fileName fName(includeFileName(is)); + IFstream ifs(fName); if (ifs) { + if (Foam::functionEntries::includeEntry::report) + { + Info<< fName << endl; + } entry.read(parentDict, ifs); } From 099ca4711928e08702196380bb5a8328b8e4b19f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 18 Apr 2011 10:51:46 +0200 Subject: [PATCH 08/16] BUG: bad word chars (single quotes) for source '-roots' option --- src/OpenFOAM/global/argList/argList.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index cce4739eae..a020f3e5bd 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -548,7 +548,7 @@ Foam::argList::argList if (options_.found("roots")) { - source = "'-roots' option"; + source = "-roots"; IStringStream is(options_["roots"]); roots = readList(is); From a66a9bbc8e9f9fd2641208ab142db7d708be8dac Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 18 Apr 2011 10:57:21 +0200 Subject: [PATCH 09/16] BUG: FOAM_INST_DIR not preserved across versions in foamExec, foamJob --- bin/foamExec | 23 ++++++++++++----- bin/foamJob | 72 +++++++++++++++++++++++++--------------------------- 2 files changed, 52 insertions(+), 43 deletions(-) diff --git a/bin/foamExec b/bin/foamExec index 26ad311349..711e3f7a8e 100755 --- a/bin/foamExec +++ b/bin/foamExec @@ -33,7 +33,7 @@ # # Can also be used for parallel runs e.g. # mpirun -np \ -# foamExec -v ... -parallel +# foamExec -version ... -parallel # # SeeAlso # foamEtcFile @@ -46,9 +46,11 @@ usage() { Usage: ${0##*/} [OPTION] ... options: + -prefix specify an alternative installation prefix + pass through to foamEtcFile and set as FOAM_INST_DIR -version specify an alternative OpenFOAM version pass through to foamEtcFile - -help this usage + -help print the usage * run a particular OpenFOAM version of @@ -63,7 +65,7 @@ USAGE # foamEtcFile must be found in the same directory as this script #------------------------------------------------------------------------------- -unset etcOpts version +unset etcOpts prefix version # parse options while [ "$#" -gt 0 ] do @@ -71,14 +73,20 @@ do -h | -help) usage ;; - -v | -version) + -m | -mode) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" - version="$2" etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile shift ;; - -m | -mode | -p | -prefix) + -p | -prefix) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" + prefix="$2" + etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile + shift + ;; + -v | -version) + [ "$#" -ge 2 ] || usage "'$1' option requires an argument" + version="$2" etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile shift ;; @@ -111,6 +119,9 @@ sourceRc() exit 1 } + # extra safety when sourcing the bashrc + [ -n "$prefix" ] && export FOAM_INST_DIR="$prefix" + . $foamDotFile } diff --git a/bin/foamJob b/bin/foamJob index 06d56b9f06..70e2c39f28 100755 --- a/bin/foamJob +++ b/bin/foamJob @@ -26,6 +26,8 @@ # foamJob # # Description +# Run an OpenFOAM job in background. +# Redirects the output to 'log' in the case directory. # #------------------------------------------------------------------------------ usage() { @@ -36,9 +38,9 @@ usage() { Usage: ${0##*/} [OPTION] ... options: -case specify alternative case directory, default is the cwd - -p parallel run of processors - -s also sends output to screen - -v specify OpenFOAM version + -parallel parallel run of processors + -screen also sends output to screen + -version specify an alternative OpenFOAM version -help print the usage * run an OpenFOAM job in background. @@ -95,23 +97,22 @@ do usage ;; -case) - [ "$#" -ge 2 ] || usage "'-case' option requires an argument" - caseDir=$2 + [ "$#" -ge 2 ] || usage "'$1' option requires an argument" + cd "$2" 2>/dev/null || usage "directory does not exist: '$2'" shift 2 - cd "$caseDir" 2>/dev/null || usage "directory does not exist: '$caseDir'" ;; - -p) + -p | -parallel) parallelOpt=true shift ;; - -s) + -s | -screen) screenOpt=true shift ;; - -v) - shift - version=$1 - shift + -v | -version) + [ "$#" -ge 2 ] || usage "'$1' option requires an argument" + version="$2" + shift 2 ;; --) shift @@ -126,29 +127,32 @@ do esac done -if [ "$#" -lt 1 ] -then - usage "No application specified" -fi +[ "$#" -ge 1 ] || usage "No application specified" -# use foamExec for a specified version and for remote (parallel) runs + +# use foamExec for a specified version +# also need foamExec for remote (parallel) runs if [ -n "$version" -o "$parallelOpt" = true ] then - APPLICATION=`findExec foamExec` - if [ $? -ne 0 ] + # when possible, determine if application even exists + if [ -z "$version" ] then - usage "'foamExec' not found" + findExec $1 >/dev/null || usage "Application '$1' not found" fi - if [ -n "$version" ] + + # use foamExec for dispatching + APPLICATION=`findExec foamExec` || usage "'foamExec' not found" + + [ -n "$version" ] && APPLICATION="$APPLICATION -version $version" + + # attempt to preserve the installation directory 'FOAM_INST_DIR' + if [ -d "$FOAM_INST_DIR" ] then - APPLICATION="$APPLICATION -v $version" + APPLICATION="$APPLICATION -prefix $FOAM_INST_DIR" fi + else - APPLICATION=`findExec $1` - if [ $? -ne 0 ] - then - usage "Application '$1' executable not found" - fi + APPLICATION=`findExec $1` || usage "Application '$1' not found" echo "Application : $1" shift fi @@ -182,11 +186,7 @@ then # # locate mpirun # - mpirun=`findExec mpirun` - if [ $? -ne 0 ] - then - usage "'mpirun' not found" - fi + mpirun=`findExec mpirun` || usage "'mpirun' not found" mpiopts="-np $NPROCS" # @@ -217,10 +217,10 @@ then # if [ "$screenOpt" = true ] then - echo "Executing: mpirun $mpiopts $APPLICATION $@ -parallel | tee log" - $mpirun $mpiopts $APPLICATION $@ -parallel | tee log + echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel | tee log" + $mpirun $mpiopts $APPLICATION $@ -parallel | tee log else - echo "Executing: mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1" + echo "Executing: $mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1" $mpirun $mpiopts $APPLICATION $@ -parallel > log 2>&1 & fi @@ -237,8 +237,6 @@ else echo "Executing: $APPLICATION $@ > log 2>&1 &" $APPLICATION $@ > log 2>&1 & fi -else - fi #------------------------------------------------------------------------------ From 0fc6700a14a08c80bf6cbaa0b8def56aae14d4f9 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 27 Apr 2011 14:31:37 +0200 Subject: [PATCH 10/16] ENH: allow for user adjustment of compiler/openmpi versions --- .gitignore | 2 ++ etc/config/compiler.csh-EXAMPLE | 51 +++++++++++++++++++++++++++++++++ etc/config/compiler.sh-EXAMPLE | 49 +++++++++++++++++++++++++++++++ etc/config/openmpi.csh-EXAMPLE | 36 +++++++++++++++++++++++ etc/config/openmpi.sh-EXAMPLE | 36 +++++++++++++++++++++++ etc/settings.csh | 7 ++++- etc/settings.sh | 7 ++++- 7 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 etc/config/compiler.csh-EXAMPLE create mode 100644 etc/config/compiler.sh-EXAMPLE create mode 100644 etc/config/openmpi.csh-EXAMPLE create mode 100644 etc/config/openmpi.sh-EXAMPLE diff --git a/.gitignore b/.gitignore index 1b8ce3cde3..e2c6f9b41f 100644 --- a/.gitignore +++ b/.gitignore @@ -60,6 +60,8 @@ doc/[Dd]oxygen/man # untracked configuration files /etc/prefs.csh /etc/prefs.sh +/etc/config/*.csh +/etc/config/*.sh # source packages - anywhere *.tar.bz2 diff --git a/etc/config/compiler.csh-EXAMPLE b/etc/config/compiler.csh-EXAMPLE new file mode 100644 index 0000000000..6d54edbd47 --- /dev/null +++ b/etc/config/compiler.csh-EXAMPLE @@ -0,0 +1,51 @@ +#----------------------------------*-sh-*-------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2011-2011 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 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 . +# +# File +# config/compiler.csh +# +# Description +# Fine tuning of ThirdParty compiler settings for OpenFOAM +# Sourced from OpenFOAM-/etc/settings.csh +# +#------------------------------------------------------------------------------ + +# Modified compiler settings +switch ("$WM_COMPILER") +case Gcc46: +case Gcc46++0x: + set gcc_version=gcc-4.6.0 + set gmp_version=gmp-5.0.1 + set mpfr_version=mpfr-2.4.2 + set mpc_version=mpc-0.8.1 + breaksw +case Gcc45: +case Gcc45++0x: + set gcc_version=gcc-4.5.2 + set gmp_version=gmp-5.0.1 + set mpfr_version=mpfr-2.4.2 + set mpc_version=mpc-0.8.1 + breaksw +endsw + +# ----------------------------------------------------------------- end-of-file diff --git a/etc/config/compiler.sh-EXAMPLE b/etc/config/compiler.sh-EXAMPLE new file mode 100644 index 0000000000..bc6aada36e --- /dev/null +++ b/etc/config/compiler.sh-EXAMPLE @@ -0,0 +1,49 @@ +#----------------------------------*-sh-*-------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2011-2011 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 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 . +# +# File +# config/compiler.sh +# +# Description +# Fine tuning of ThirdParty compiler settings for OpenFOAM +# Sourced from OpenFOAM-/etc/settings.sh +# +#------------------------------------------------------------------------------ + +# Modified compiler settings +case "$WM_COMPILER" in +Gcc46 | Gcc46++0x) + gcc_version=gcc-4.6.0 + gmp_version=gmp-5.0.1 + mpfr_version=mpfr-2.4.2 + mpc_version=mpc-0.8.1 + ;; +Gcc45 | Gcc45++0x) + gcc_version=gcc-4.5.2 + gmp_version=gmp-5.0.1 + mpfr_version=mpfr-2.4.2 + mpc_version=mpc-0.8.1 + ;; +esac + +# ----------------------------------------------------------------- end-of-file diff --git a/etc/config/openmpi.csh-EXAMPLE b/etc/config/openmpi.csh-EXAMPLE new file mode 100644 index 0000000000..94be702e9d --- /dev/null +++ b/etc/config/openmpi.csh-EXAMPLE @@ -0,0 +1,36 @@ +#----------------------------------*-sh-*-------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2011-2011 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 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 . +# +# File +# config/openmpi.csh +# +# Description +# Fine tuning of openmpi settings for OpenFOAM +# Sourced from OpenFOAM-/etc/settings.csh +# +#------------------------------------------------------------------------------ + +# Modified openmpi settings +setenv FOAM_MPI openmpi-1.4.3 + +# ----------------------------------------------------------------- end-of-file diff --git a/etc/config/openmpi.sh-EXAMPLE b/etc/config/openmpi.sh-EXAMPLE new file mode 100644 index 0000000000..b7c5035b04 --- /dev/null +++ b/etc/config/openmpi.sh-EXAMPLE @@ -0,0 +1,36 @@ +#----------------------------------*-sh-*-------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2011-2011 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 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 . +# +# File +# config/openmpi.sh +# +# Description +# Fine tuning of openmpi settings for OpenFOAM +# Sourced from OpenFOAM-/etc/settings.sh +# +#------------------------------------------------------------------------------ + +# Modified openmpi settings +export FOAM_MPI=openmpi-1.4.3 + +# ----------------------------------------------------------------- end-of-file diff --git a/etc/settings.csh b/etc/settings.csh index 0e15cef31e..b63999dccb 100644 --- a/etc/settings.csh +++ b/etc/settings.csh @@ -248,6 +248,9 @@ case ThirdParty: breaksw endsw + # optional configuration tweaks: + _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile config/compiler.csh` + if ( $?gcc_version ) then set gccDir=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH/$gcc_version set gmpDir=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH/$gmp_version @@ -367,8 +370,10 @@ unsetenv MPI_ARCH_PATH MPI_HOME FOAM_MPI_LIBBIN switch ("$WM_MPLIB") case OPENMPI: - #setenv FOAM_MPI openmpi-1.4.3 setenv FOAM_MPI openmpi-1.5.3 + # optional configuration tweaks: + _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile config/openmpi.csh` + setenv MPI_ARCH_PATH $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$FOAM_MPI # Tell OpenMPI where to find its install directory diff --git a/etc/settings.sh b/etc/settings.sh index f3ccaebb18..ec9b33041e 100644 --- a/etc/settings.sh +++ b/etc/settings.sh @@ -265,6 +265,9 @@ OpenFOAM | ThirdParty) ;; esac + # optional configuration tweaks: + _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile config/compiler.sh` + if [ -n "$gcc_version" ] then gccDir=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER_ARCH/$gcc_version @@ -387,8 +390,10 @@ unset MPI_ARCH_PATH MPI_HOME FOAM_MPI_LIBBIN case "$WM_MPLIB" in OPENMPI) - #export FOAM_MPI=openmpi-1.4.3 export FOAM_MPI=openmpi-1.5.3 + # optional configuration tweaks: + _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile config/openmpi.sh` + export MPI_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$FOAM_MPI # Tell OpenMPI where to find its install directory From debb4b42fdc04f24f2175c95a6d13d3c4525a749 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 27 Apr 2011 16:55:32 +0200 Subject: [PATCH 11/16] ENH: add foamEtcFile -silent option to suppress stderr - need to trap possibly weird input within etc/bashrc, etc/cshrc and can't easily redirect stderr in csh. --- bin/foamEtcFile | 10 +++++++--- etc/bashrc | 2 +- etc/cshrc | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bin/foamEtcFile b/bin/foamEtcFile index a6859b6ae5..cabc5831fd 100755 --- a/bin/foamEtcFile +++ b/bin/foamEtcFile @@ -40,7 +40,7 @@ # #------------------------------------------------------------------------------- usage() { - [ "$quietOpt" = true ] && exit 1 + [ "${quietOpt:-$silentOpt}" = true ] && exit 1 exec 1>&2 while [ "$#" -ge 1 ]; do echo "$1"; shift; done @@ -53,6 +53,7 @@ options: -mode any combination of u(user), g(group), o(other) -prefix specify an alternative installation prefix -quiet suppress all normal output + -silent suppress all stderr output -version specify an alternative OpenFOAM version in the form Maj.Min.Rev (eg, 1.7.0) -help print the usage @@ -128,7 +129,7 @@ esac # default mode is 'ugo' mode=ugo -unset listOpt quietOpt +unset listOpt quietOpt silentOpt # parse options while [ "$#" -gt 0 ] @@ -162,6 +163,9 @@ do -q | -quiet) quietOpt=true ;; + -s | -silent) + silentOpt=true + ;; -v | -version) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" version="$2" @@ -241,7 +245,7 @@ then # list directories, or potential file locations [ "$nArgs" -le 1 ] || usage - # a silly combination, but -quiet has precedence + # a silly combination, but -quiet does have precedence [ "$quietOpt" = true ] && exit 0 for dir diff --git a/etc/bashrc b/etc/bashrc index 2de27d0513..edbf3064f0 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -160,7 +160,7 @@ _foamEval() then _foamSource "$1" else - _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile "$1"` + _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile -silent "$1"` fi ;; esac diff --git a/etc/cshrc b/etc/cshrc index a23a607fff..9b824f0c99 100644 --- a/etc/cshrc +++ b/etc/cshrc @@ -157,7 +157,7 @@ while ( $#argv > 0 ) if ( -f "$1" ) then _foamSource "$1" else - _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile "$1"` + _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile -silent "$1"` endif breaksw endsw From b55c3fb66b0624fc87619991008302d6b180c37d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 28 Apr 2011 08:32:00 +0200 Subject: [PATCH 12/16] ENH: avoid stray options affecting _foamEval, pass FOAM_SETTINGS to foamExec --- bin/foamExec | 2 +- etc/bashrc | 4 ++++ etc/cshrc | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/foamExec b/bin/foamExec index 711e3f7a8e..66892c525b 100755 --- a/bin/foamExec +++ b/bin/foamExec @@ -122,7 +122,7 @@ sourceRc() # extra safety when sourcing the bashrc [ -n "$prefix" ] && export FOAM_INST_DIR="$prefix" - . $foamDotFile + . $foamDotFile $FOAM_SETTINGS } diff --git a/etc/bashrc b/etc/bashrc index edbf3064f0..d2539c5b50 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -144,6 +144,10 @@ _foamEval() while [ $# -gt 0 ] do case "$1" in + -*) + # stray option (not meant for us here) -> get out + break + ;; *=) # name= -> unset name [ "$FOAM_VERBOSE" -a "$PS1" ] && echo "unset ${1%=}" diff --git a/etc/cshrc b/etc/cshrc index 9b824f0c99..c2c1b12a9b 100644 --- a/etc/cshrc +++ b/etc/cshrc @@ -142,6 +142,10 @@ _foamSource `$WM_PROJECT_DIR/bin/foamEtcFile prefs.csh` setenv FOAM_SETTINGS "${*}" while ( $#argv > 0 ) switch ($argv[1]) + case -*: + # stray option (not meant for us here) -> get out + break + breaksw case *=: # name= -> unsetenv name if ($?FOAM_VERBOSE && $?prompt) echo "unsetenv $argv[1]:s/=//" From 83c840769272c49844c01b6e4f283707aa60b6d8 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 28 Apr 2011 09:17:32 +0200 Subject: [PATCH 13/16] BUG: apps/paraview/bashrc trashed argument list --- etc/apps/paraview3/bashrc | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/etc/apps/paraview3/bashrc b/etc/apps/paraview3/bashrc index e0e6122946..1dd5386829 100644 --- a/etc/apps/paraview3/bashrc +++ b/etc/apps/paraview3/bashrc @@ -56,16 +56,22 @@ export ParaView_MAJOR=detect # Evaluate command-line parameters for ParaView -while [ $# -gt 0 ] -do - case "$1" in - ParaView*=*) - # name=value -> export name=value - eval "export $1" - ;; - esac - shift -done +_foamParaviewEval() +{ + while [ $# -gt 0 ] + do + case "$1" in + ParaView*=*) + # name=value -> export name=value + eval "export $1" + ;; + esac + shift + done +} + +# Evaluate command-line parameters +_foamParaviewEval $@ # set MAJOR version to correspond to VERSION @@ -108,6 +114,7 @@ else fi +unset _foamParaviewEval unset cleaned cmake paraviewInstDir paraviewPython # ----------------------------------------------------------------------------- From 80a391a4f3eb21b27d9aba2a839bbf7867f5aa8e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 28 Apr 2011 12:49:07 +0200 Subject: [PATCH 14/16] COMP: incorrect comment type in options files (scotchDecomp) --- src/parallel/decompose/scotchDecomp/Make/options | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/parallel/decompose/scotchDecomp/Make/options b/src/parallel/decompose/scotchDecomp/Make/options index a198db40af..b2f7015e24 100644 --- a/src/parallel/decompose/scotchDecomp/Make/options +++ b/src/parallel/decompose/scotchDecomp/Make/options @@ -1,6 +1,7 @@ -# Note including of mplib compilation rules. This -# is purely to avoid scotch.h including mpicxx.h -# which causes problems. +/* + * Note including of mplib compilation rules. + * This is purely to avoid scotch.h including mpicxx.h, which causes problems. + */ sinclude $(GENERAL_RULES)/mplib$(WM_MPLIB) sinclude $(RULES)/mplib$(WM_MPLIB) From 22fae65263f005769037af7bba40e0c63bd400c7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 28 Apr 2011 15:33:38 +0200 Subject: [PATCH 15/16] BUG: FOAM_INST_DIR (or prefix) not passed correctly from foamExec --- bin/foamEtcFile | 10 +++++----- bin/foamExec | 51 +++++++++++++++++++++++++++++++------------------ 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/bin/foamEtcFile b/bin/foamEtcFile index cabc5831fd..8a1f5d97e6 100755 --- a/bin/foamEtcFile +++ b/bin/foamEtcFile @@ -38,6 +38,10 @@ # && _foamSource $foamPrefs # \endcode # +# Note +# This script must exist in /OpenFOAM-/bin/ +# or /openfoam/bin/ (for the debian version) +# #------------------------------------------------------------------------------- usage() { [ "${quietOpt:-$silentOpt}" = true ] && exit 1 @@ -73,13 +77,9 @@ USAGE exit 1 } -# -# This script must exist in /OpenFOAM-/bin/ -# or /openfoam/bin/ (for the debian version) -# #------------------------------------------------------------------------------- -# the bindir: +# the bin dir: binDir="${0%/*}" # the project dir: diff --git a/bin/foamExec b/bin/foamExec index 66892c525b..fba65934cc 100755 --- a/bin/foamExec +++ b/bin/foamExec @@ -31,12 +31,21 @@ # Runs the version of executable # with the rest of the arguments. # -# Can also be used for parallel runs e.g. -# mpirun -np \ -# foamExec -version ... -parallel +# Can also be used for parallel runs. For example, +# \code +# mpirun -np \ +# foamExec -version ... -parallel +# \endcode +# +# Note +# This script must exist in /OpenFOAM-/bin/ +# or /openfoam/bin/ (for the debian version) +# +# foamEtcFile must be found in the same directory as this script # # SeeAlso # foamEtcFile +# #------------------------------------------------------------------------------ usage() { exec 1>&2 @@ -58,14 +67,22 @@ USAGE exit 1 } -# -# This script must exist in /OpenFOAM-/bin/ -# or /openfoam/bin/ (for the debian version) -# -# foamEtcFile must be found in the same directory as this script #------------------------------------------------------------------------------- -unset etcOpts prefix version +# the bin dir: +binDir="${0%/*}" + +# the project dir: +projectDir="${binDir%/bin}" + +# the prefix dir (same as foamInstall): +prefixDir="${projectDir%/*}" + +# # the name used for the project directory +# projectDirName="${projectDir##*/}" + + +unset etcOpts version # parse options while [ "$#" -gt 0 ] do @@ -80,14 +97,14 @@ do ;; -p | -prefix) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" - prefix="$2" etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile + prefixDir="$2" shift ;; -v | -version) [ "$#" -ge 2 ] || usage "'$1' option requires an argument" - version="$2" etcOpts="$etcOpts $1 $2" # pass-thru to foamEtcFile + version="$2" shift ;; --) @@ -104,23 +121,19 @@ do shift done - # # Find and source OpenFOAM settings (bashrc) # placed in function to preserve command-line arguments # sourceRc() { - # default is the current version - : ${version:=${WM_PROJECT_VERSION:-unknown}} - - foamDotFile="$(${0%/*}/foamEtcFile $etcOpts bashrc)" || { - echo "Error : bashrc file could not be found for OpenFOAM-$version" 1>&2 + foamDotFile="$($binDir/foamEtcFile $etcOpts bashrc)" || { + echo "Error : bashrc file could not be found for OpenFOAM-${version:-${WM_PROJECT_VERSION:-???}}" 1>&2 exit 1 } - # extra safety when sourcing the bashrc - [ -n "$prefix" ] && export FOAM_INST_DIR="$prefix" + # set to consistent value before sourcing the bashrc + export FOAM_INST_DIR="$prefixDir" . $foamDotFile $FOAM_SETTINGS } From b646589996f8636f4bacb984195d263e9dca43ef Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 28 Apr 2011 16:26:00 +0200 Subject: [PATCH 16/16] COMP: add sentinels to catch mpi or scotch version changes when compiling --- src/Pstream/Allwmake | 29 +++++++++++++++++++--- src/parallel/decompose/Allwmake | 43 +++++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/Pstream/Allwmake b/src/Pstream/Allwmake index 613263d7bc..50ccb5fe1d 100755 --- a/src/Pstream/Allwmake +++ b/src/Pstream/Allwmake @@ -1,8 +1,31 @@ #!/bin/sh cd ${0%/*} || exit 1 # run from this directory makeType=${1:-libso} -set -x + +# +# define how to create an mpi-versioned library of $makeType +# compile into qualified directory +# use sentinel file to handle version changes +# +wmakeMpiLib() +{ + set +x + for libName + do + ( + WM_OPTIONS="$WM_OPTIONS$WM_MPLIB" + whichmpi="$libName/Make/$WM_OPTIONS/using:$FOAM_MPI" + [ -e "$whichmpi" ] || wclean $libName + echo "wmake $makeType $libName" + wmake $makeType $libName + touch "$whichmpi" + ) + done + set -x +} + +set -x wmake $makeType dummy case "$WM_MPLIB" in @@ -11,9 +34,7 @@ case "$WM_MPLIB" in echo echo "Note: ignore spurious warnings about missing mpicxx.h headers" echo - set -x - # force compilation into qualified directory - WM_OPTIONS=${WM_OPTIONS}$WM_MPLIB wmake $makeType mpi + wmakeMpiLib mpi ;; #GAMMA) diff --git a/src/parallel/decompose/Allwmake b/src/parallel/decompose/Allwmake index 38898b1ea3..cded295a7e 100755 --- a/src/parallel/decompose/Allwmake +++ b/src/parallel/decompose/Allwmake @@ -3,8 +3,7 @@ cd ${0%/*} || exit 1 # run from this directory makeType=${1:-libso} # get SCOTCH_VERSION, SCOTCH_ARCH_PATH -settings=`$WM_PROJECT_DIR/bin/foamEtcFile apps/scotch/bashrc` -if [ -f "$settings" ] +if settings=`$WM_PROJECT_DIR/bin/foamEtcFile apps/scotch/bashrc` then . $settings echo "using SCOTCH_ARCH_PATH=$SCOTCH_ARCH_PATH" @@ -13,21 +12,45 @@ else echo "Error: no apps/scotch/bashrc settings" echo fi + + +# +# define how to create an mpi-versioned library of $makeType +# compile into qualified directory +# use sentinel file to handle version changes +# +wmakeMpiLib() +{ + set +x + for libName + do + ( + WM_OPTIONS="$WM_OPTIONS$WM_MPLIB" + whichmpi="$libName/Make/$WM_OPTIONS/using:$FOAM_MPI" + whichscotch="$libName/Make/$WM_OPTIONS/using:$SCOTCH_VERSION" + [ -e "$whichmpi" -a -e "$whichscotch" ] || wclean $libName + echo "wmake $makeType $libName" + wmake $makeType $libName + touch "$whichmpi" "$whichscotch" + ) + done + set -x +} + set -x wmakeLnInclude decompositionMethods -wmake $makeType scotchDecomp - -if [ -d "$FOAM_LIBBIN/$FOAM_MPI" ] +if [ -n "$SCOTCH_ARCH_PATH" ] then -( - WM_OPTIONS=${WM_OPTIONS}$WM_MPLIB - wmake $makeType ptscotchDecomp -) + wmake $makeType scotchDecomp + [ -d "$FOAM_LIBBIN/$FOAM_MPI" ] && wmakeMpiLib ptscotchDecomp +else + echo + echo "Skipping scotchDecomp (ptscotchDecomp)" + echo fi wmake $makeType decompositionMethods - # ----------------------------------------------------------------- end-of-file