From aad21d457550cf0eaa092faa0803b0141751e025 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 6 May 2008 10:17:48 +0200 Subject: [PATCH 01/41] removed junk files --- bin/#foamPackBin# | 98 ------------------------------------------ bin/doxyClassPatch | 103 --------------------------------------------- 2 files changed, 201 deletions(-) delete mode 100755 bin/#foamPackBin# delete mode 100755 bin/doxyClassPatch diff --git a/bin/#foamPackBin# b/bin/#foamPackBin# deleted file mode 100755 index 63353c9fe2..0000000000 --- a/bin/#foamPackBin# +++ /dev/null @@ -1,98 +0,0 @@ -#!/bin/sh -#------------------------------------------------------------------------------ -# ========= | -# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox -# \\ / O peration | -# \\ / A nd | Copyright (C) 1991-2007 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 -# -# Script -# foamPackBin [outputDir] -# -# Description -# Packs and compresses binary version of OpenFOAM for release -# -#------------------------------------------------------------------------------ - -if [ $# = 0 ] -then - echo "Error: architecture type expected, exiting" - echo - echo "Usage : ${0##*/} [outputDir]" - echo - exit 1 -fi -arch=$1 - -timeStamp=$(date +%Y-%m-%d) -packDir=$WM_PROJECT-$WM_PROJECT_VERSION -packFile=${packDir}.${arch}_${timeStamp}.gtgz - -# add optional output directory -if [ -d "$2" ] -then - packFile="$2/$packFile" -fi - -if [ -f $packFile ] -then - echo "Error: $packFile already exists" - exit 1 -fi - -# check for essential directories -for dir in $packDir $packDir/lib/$arch $packDir/applications/bin/$arch -do - if [ ! -d $dir ] - then - echo "Error: directory $dir does not exist" - exit 1 - fi -done - -# get list of directories -dirList=$( - for dir in \ - $packDir/lib/$arch \ - $packDir/applications/bin/$arch \ - $packDir/wmake/rules \ - $packDir/src/{mico,mpich,lam,openmpi}-*/platforms/$arch \ - $packDir/src/{mico,mpich,lam,openmpi}-*/platforms/$arch \ - ; - do - [ -d $dir ] && echo $dir - done -) - -echo -echo "Packing $arch port of $packDir into $packFile" -echo - -tar czpf $packFile $dirList - -if [ $? = 0 ] -then - echo "Finished packing and compressing file $packFile" -else - echo "Error: failure packing $packFile" - rm -f $packFile 2>/dev/null -fi - -#------------------------------------------------------------------------------ diff --git a/bin/doxyClassPatch b/bin/doxyClassPatch deleted file mode 100755 index f724ca8d43..0000000000 --- a/bin/doxyClassPatch +++ /dev/null @@ -1,103 +0,0 @@ -#!/bin/sh -# ----------------------------------------------------------------------------- -# ========= | -# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox -# \\ / O peration | -# \\ / A nd | Copyright (C) 1991-2007 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 -# -# Script -# doxyClassPatch -# -# Description -# search for header files and fix up 'Class' section for doxygen -# -# change: -# |Class -# | className -# -> -# |Class -# | Foam::className -# -# change: -# |Class -# | -# -> -# |Class -# | Foam::(basename) -# -# leave untouched: -# |Class -# | Foam... -# and -# |Class -# | Namespace::className -# -# -# ----------------------------------------------------------------------------- -backup=.unclassified -remove=no - -for search -do - for file in $( - find -H $search \ - -type f -name "*.H" \ - -exec perl -ne \ - 'if (/^Class\s*$/) { $_ = <>; /(^\s*Foam|::)/ or print "$ARGV\n"; exit 0; }' \ - \{\} \; - ) - do - perl -i$backup -x $0 $file - if [ -f $file$backup ] - then - [ $file -nt $file$backup ] && touch -r $file$backup $file - [ "$remove" = yes ] && /bin/rm $file$backup 2>/dev/null - fi - done -done - -exit 0 -# ---------------------------------------------------------------- end-of-file - -# embedded Perl program -#!/usr/bin/perl -wp -use strict; - -my $namespace = "Foam::"; -( my $class = $ARGV ) =~ s{^.*/|\.[A-Za-z]$}{}g; - -if (/^Class\s*$/) { - print; - $_ = <>; - - # provide a reasonable guess for empty classes - if (/^\s*$/) { - $_ = " $namespace$class\n"; - warn "modified $ARGV\n"; - } - elsif ( not /(^\s*Foam|::)/ ) { - s{^\s+|\s*$}{}g; - $_ = " $namespace$_\n"; - warn "modified $ARGV\n"; - } -} - -# ---------------------------------------------------------------- end-of-file From 2744374ad02d1ab1550037c717e6bded624db840 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 May 2008 13:37:30 +0200 Subject: [PATCH 02/41] removed unused files from ccm example --- .../ccm26ToFoam/ccm26ToFoam/Vector.cpp | 36 ---- .../ccm26ToFoam/ccm26ToFoam/Vector.h | 158 ------------------ 2 files changed, 194 deletions(-) delete mode 100644 applications/utilities/mesh/conversion/ccm26ToFoam/ccm26ToFoam/Vector.cpp delete mode 100644 applications/utilities/mesh/conversion/ccm26ToFoam/ccm26ToFoam/Vector.h diff --git a/applications/utilities/mesh/conversion/ccm26ToFoam/ccm26ToFoam/Vector.cpp b/applications/utilities/mesh/conversion/ccm26ToFoam/ccm26ToFoam/Vector.cpp deleted file mode 100644 index 9ee5d80de9..0000000000 --- a/applications/utilities/mesh/conversion/ccm26ToFoam/ccm26ToFoam/Vector.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "Vector.h" - -using namespace std; - -float Vector::distanceToSegment(const Vector& p1, const Vector& p2) const -{ - // vector from p1 to p2 - Vector p1p2(p1,p2); - - float length = p1p2.mag(); - if (length <= 1.0e-9) - return Vector::distance(*this, p1); - - p1p2.normalize(); - - // vector from p1 to this - Vector p1point(p1, *this); - - // u is distance along segment from point 1 - float u = Vector::dot(p1point, p1p2); - - if (u <= 0.0) // closest to point 1 - return p1point.mag(); - else if (u >= length) // closest to point 2 - return Vector::distance(*this, p2); - else // use pythagorean theorem to compute projected distance - return sqrt(p1point.mag_squared() - u*u); - - return 0.0; -} - -ostream& operator<< (ostream& s, const Vector& v) -{ - s << "(" << v.x() << ", " << v.y() << ", " << v.z() << ")"; - return s; -} diff --git a/applications/utilities/mesh/conversion/ccm26ToFoam/ccm26ToFoam/Vector.h b/applications/utilities/mesh/conversion/ccm26ToFoam/ccm26ToFoam/Vector.h deleted file mode 100644 index ce0d9dd72c..0000000000 --- a/applications/utilities/mesh/conversion/ccm26ToFoam/ccm26ToFoam/Vector.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef _CCMVECTOR_H -#define _CCMVECTOR_H - -#include -#include - -class Vector -{ - public: - Vector() { - _xyz[0] = 0.0; - _xyz[1] = 0.0; - _xyz[2] = 0.0; - } - Vector(float x, float y, float z) { - _xyz[0] = x; - _xyz[1] = y; - _xyz[2] = z; - } - Vector(const Vector& p1, const Vector& p2) { - _xyz[0] = p2._xyz[0] - p1._xyz[0]; - _xyz[1] = p2._xyz[1] - p1._xyz[1]; - _xyz[2] = p2._xyz[2] - p1._xyz[2]; - } - Vector(const float *xyz) { - _xyz[0] = xyz[0]; - _xyz[1] = xyz[1]; - _xyz[2] = xyz[2]; - } - - void set(int i, float val) { - _xyz[i] = val; - } - - void setXYZ(const float *xyz) { - _xyz[0] = xyz[0]; - _xyz[1] = xyz[1]; - _xyz[2] = xyz[2]; - } - - void setXYZ(float x, float y, float z) { - _xyz[0] = x; - _xyz[1] = y; - _xyz[2] = z; - } - - void axpy(float a, const Vector& x, const Vector& y) { - _xyz[0] = a*x._xyz[0] + y._xyz[0]; - _xyz[1] = a*x._xyz[1] + y._xyz[1]; - _xyz[2] = a*x._xyz[2] + y._xyz[2]; - } - - - float x() const {return _xyz[0];} - float y() const {return _xyz[1];} - float z() const {return _xyz[2];} - const float *xyz() const {return _xyz;} - float& operator[](unsigned int i) { return _xyz[i]; } - - float mag() const { - return sqrt(_xyz[0]*_xyz[0] + - _xyz[1]*_xyz[1] + - _xyz[2]*_xyz[2]); - } - - float mag_squared() const { - return _xyz[0]*_xyz[0] + - _xyz[1]*_xyz[1] + - _xyz[2]*_xyz[2]; - } - - int normalize() { - float mag = this->mag(); - if (mag < 1.0e-9) - return 1; - - float scale = 1.0f / mag; - for(int i=0; i<3; i++) - _xyz[i] *= scale; - return 0; - } - - Vector& operator+=(const Vector& v1) { - _xyz[0] += v1._xyz[0]; - _xyz[1] += v1._xyz[1]; - _xyz[2] += v1._xyz[2]; - return *this; - } - - Vector& operator-=(const Vector& v1) { - _xyz[0] -= v1._xyz[0]; - _xyz[1] -= v1._xyz[1]; - _xyz[2] -= v1._xyz[2]; - return *this; - } - - Vector& operator*=(const float scale) { - _xyz[0] *= scale; - _xyz[1] *= scale; - _xyz[2] *= scale; - return *this; - } - - Vector operator-(const Vector &v) const { - return Vector( - this->_xyz[0] - v._xyz[0], - this->_xyz[1] - v._xyz[1], - this->_xyz[2] - v._xyz[2]); - } - - Vector operator+(const Vector &v) const { - return Vector( - this->_xyz[0] + v._xyz[0], - this->_xyz[1] + v._xyz[1], - this->_xyz[2] + v._xyz[2]); - } - - static float distance(const Vector& v1, const Vector& v2) { - return sqrt((v1._xyz[0]-v2._xyz[0])*(v1._xyz[0]-v2._xyz[0])+ - (v1._xyz[1]-v2._xyz[1])*(v1._xyz[1]-v2._xyz[1])+ - (v1._xyz[2]-v2._xyz[2])*(v1._xyz[2]-v2._xyz[2])); - } - - static float distance_squared(const Vector& v1, const Vector& v2) { - return (v1._xyz[0]-v2._xyz[0])*(v1._xyz[0]-v2._xyz[0])+ - (v1._xyz[1]-v2._xyz[1])*(v1._xyz[1]-v2._xyz[1])+ - (v1._xyz[2]-v2._xyz[2])*(v1._xyz[2]-v2._xyz[2]); - } - - static Vector cross(const Vector& v1, const Vector& v2) { - return Vector( - v1._xyz[1] * v2._xyz[2] - v1._xyz[2] * v2._xyz[1], - v1._xyz[2] * v2._xyz[0] - v1._xyz[0] * v2._xyz[2], - v1._xyz[0] * v2._xyz[1] - v1._xyz[1] * v2._xyz[0]); - } - - static Vector subtract_component(const Vector& v, const Vector& dir) { - float dot = Vector::dot(v, dir); - return Vector(v._xyz[0] - dot*dir._xyz[0], - v._xyz[1] - dot*dir._xyz[1], - v._xyz[2] - dot*dir._xyz[2]); - } - - static float dot(const Vector& v1, const Vector& v2) { - return v1._xyz[0]*v2._xyz[0] + - v1._xyz[1]*v2._xyz[1] + - v1._xyz[2]*v2._xyz[2]; - } - - float distanceToSegment(const Vector& p1, const Vector& p2) const; - private: - float _xyz[3]; -}; - -std::ostream& operator<< (std::ostream& s, const Vector& v); - -#endif - From 4b0bfd906d2dc8c63104e3bd77fbba7708482bfa Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 May 2008 13:48:42 +0200 Subject: [PATCH 03/41] cosmetics changes and small cleanups --- applications/Allwmake | 4 +- .../mesh/conversion/ccm26ToFoam/Allwmake | 10 +- bin/foamDiffSourceList | 12 +- bin/foamPack | 9 +- bin/foamPackChanged | 110 ++++++++++++++++++ bin/foamPackSource | 10 +- src/Allwmake | 12 +- 7 files changed, 136 insertions(+), 31 deletions(-) create mode 100755 bin/foamPackChanged diff --git a/applications/Allwmake b/applications/Allwmake index a734704b28..7437e4f9b0 100755 --- a/applications/Allwmake +++ b/applications/Allwmake @@ -1,5 +1,5 @@ #!/bin/sh set -x -(cd solvers ; wmake all) -(cd utilities ; wmake all) +( cd solvers && wmake all ) +( cd utilities && wmake all ) diff --git a/applications/utilities/mesh/conversion/ccm26ToFoam/Allwmake b/applications/utilities/mesh/conversion/ccm26ToFoam/Allwmake index 876f5dd455..d9b55b3b5f 100755 --- a/applications/utilities/mesh/conversion/ccm26ToFoam/Allwmake +++ b/applications/utilities/mesh/conversion/ccm26ToFoam/Allwmake @@ -1,9 +1,9 @@ #!/bin/sh set -x -# Some fun: prostar uses ccmio2.3, Star-ccm+ uses ccmio2.4 +# compile cd-adapco's CCM library +wmake libso libccmio/libadf +wmake libso libccmio/libccmio +wmake libso libccmio/libcgns -(cd libccmio; wmake libso libadf) -(cd libccmio; wmake libso libccmio) -(cd libccmio; wmake libso libcgns) -(cd ccm26ToFoam; wmake) +wmake ccm26ToFoam diff --git a/bin/foamDiffSourceList b/bin/foamDiffSourceList index 435eda9a1c..b713573890 100755 --- a/bin/foamDiffSourceList +++ b/bin/foamDiffSourceList @@ -72,6 +72,7 @@ find -H $newDir \ ! -type d -type f \ ! -name "*~" \ -a ! -name ".*~" \ + -a ! -name ".#*" \ -a ! -name "*.orig" \ -a ! -name "*.dep" \ -a ! -name "*.o" \ @@ -83,10 +84,11 @@ find -H $newDir \ -a ! -name "log[0-9]*" \ | sed \ -e "\@$newDir/lib/@d" \ - -e "\@$newDir/src/mico-[0-9.]*/platforms@d" \ - -e "\@$newDir/src/mpich-[0-9.]*/platforms@d" \ - -e "\@$newDir/src/mpich-[0-9.]*/lib@d" \ - -e "\@$newDir/src/lam-[0-9.]*/platforms@d" \ + -e "\@$newDir/src/other/mico-*/platforms@d" \ + -e "\@$newDir/src/other/mpich-*/platforms@d" \ + -e "\@$newDir/src/other/mpich-*/lib@d" \ + -e "\@$newDir/src/other/lam-*/platforms@d" \ + -e "\@$newDir/src/other/openmpi-*/platforms@d" \ -e '\@applications/bin/@d' \ -e '\@/t/@d' \ -e '\@Make[.A-Za-z]*/[^/]*/@d' \ @@ -118,7 +120,7 @@ find -H $newDir \ done ) -# file fileCount +# file fileCount fileCount=$(cat $tmpFile | wc -l) echo "----------------------------------------------------------------------" echo "pack $fileCount changed/new files" diff --git a/bin/foamPack b/bin/foamPack index 1ac1175d71..5122b252af 100755 --- a/bin/foamPack +++ b/bin/foamPack @@ -86,10 +86,11 @@ find -H $packDir \ -a ! -name "so_locations" \ | sed \ -e "\@$packDir/lib/@d" \ - -e "\@$packDir/src/mico-[0-9.]*/platforms@d" \ - -e "\@$packDir/src/mpich-[0-9.]*/platforms@d" \ - -e "\@$packDir/src/mpich-[0-9.]*/lib@d" \ - -e "\@$packDir/src/lam-[0-9.]*/platforms@d" \ + -e "\@$packDir/src/other/mico-*/platforms@d" \ + -e "\@$packDir/src/other/mpich-*/platforms@d" \ + -e "\@$packDir/src/other/mpich-*/lib@d" \ + -e "\@$packDir/src/other/lam-*/platforms@d" \ + -e "\@$packDir/src/other/openmpi-*/platforms@d" \ -e '\@applications/bin/@d' \ -e '\@/t/@d' \ -e '\@Make[.A-Za-z]*/[^/]*/@d' \ diff --git a/bin/foamPackChanged b/bin/foamPackChanged new file mode 100755 index 0000000000..38fbb38551 --- /dev/null +++ b/bin/foamPackChanged @@ -0,0 +1,110 @@ +#!/bin/sh +#------------------------------------------------------------------------------ +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 1991-2007 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 +# +# Script +# foamPackChanged +# +# Description +# Packs and compresses files that have a corresponding .orig file +# +#------------------------------------------------------------------------------ +tmpFile=${TMPDIR:-/tmp}/foamPackChanged.$$ + +if [ $# -ne 2 ]; then + echo "Usage : ${0##*/} directory tarFile" + echo "" + echo "Packs and compresses files that have a corresponding .orig file" + echo "" + exit 1 +fi + +# canonical form (no double and no trailing dashes) +packDir=$(echo "$1" | sed -e 's@//*@/@g' -e 's@/$@@') +packFile=$2 + +if [ ! -d $packDir ]; then + echo "Error: directory $packDir does not exist" + exit 1 +fi + +# Clean up on termination and on Ctrl-C +trap 'rm -f $tmpFile 2>/dev/null; exit 0' EXIT TERM INT + +fileCount=0 +cat /dev/null > $tmpFile + +find -H $packDir \ + ! -type d \ + -type f \ + -name "*.orig" \ +| sed \ + -e "\@$packDir/lib/@d" \ + -e "\@$packDir/src/other/mico-*/platforms@d" \ + -e "\@$packDir/src/other/mpich-*/platforms@d" \ + -e "\@$packDir/src/other/mpich-*/lib@d" \ + -e "\@$packDir/src/other/lam-*/platforms@d" \ + -e "\@$packDir/src/other/openmpi-*/platforms@d" \ + -e '\@applications/bin/@d' \ + -e '\@/t/@d' \ + -e '\@Make[.A-Za-z]*/[^/]*/@d' \ + -e '\@[Dd]oxygen/html@d' \ + -e '\@[Dd]oxygen/latex@d' \ + -e '\@[Dd]oxygen/man@d' \ + -e "s@$packDir/*@@" \ + | \ + ( + while read file + do + (( fileCount=$fileCount + 1 )) + + file=${file%%.orig} + + if [ -f "$packDir/$file" ] + then + echo $fileCount $file + echo $packDir/$file >> $tmpFile + else + echo "[MISSING]" $file + fi + done + ) + +# file fileCount +fileCount=$(cat $tmpFile | wc -l) +echo "----------------------------------------------------------------------" +echo "pack $fileCount updated (non-.orig) files" + +tar -czpf $packFile --files-from $tmpFile + +if [ $? = 0 ] +then + echo "Finished packing changed files from $packDir into $packFile" +else + echo "Error: failure packing changed files from $packDir into $packFile" + rm -f $packFile 2>/dev/null +fi +echo "----------------------------------------------------------------------" + +# ---------------------------------------------------------------------------- diff --git a/bin/foamPackSource b/bin/foamPackSource index 1a643bdf8b..9e1141972e 100755 --- a/bin/foamPackSource +++ b/bin/foamPackSource @@ -75,11 +75,11 @@ find -H $packDir \ -a ! -name "log[0-9]*" \ | sed \ -e "\@$packDir/lib/@d" \ - -e "\@$packDir/src/other/mico-[0-9.]*/platforms@d" \ - -e "\@$packDir/src/other/mpich-[0-9.]*/platforms@d" \ - -e "\@$packDir/src/other/mpich-[0-9.]*/lib@d" \ - -e "\@$packDir/src/other/lam-[0-9.]*/platforms@d" \ - -e "\@$packDir/src/other/openmpi-[0-9.]*/platforms@d" \ + -e "\@$packDir/src/other/mico-*/platforms@d" \ + -e "\@$packDir/src/other/mpich-*/platforms@d" \ + -e "\@$packDir/src/other/mpich-*/lib@d" \ + -e "\@$packDir/src/other/lam-*/platforms@d" \ + -e "\@$packDir/src/other/openmpi-*/platforms@d" \ -e '\@applications/bin/@d' \ -e '\@/t/@d' \ -e '\@Make[.A-Za-z]*/[^/]*/@d' \ diff --git a/src/Allwmake b/src/Allwmake index f20347166b..bd6e753e9a 100755 --- a/src/Allwmake +++ b/src/Allwmake @@ -1,10 +1,8 @@ #!/bin/sh set -x -( cd $FOAM_SRC/OpenFOAM && wmakeLnInclude . ) - -( cd $FOAM_SRC/other && ./Allwmake ) - +( cd OpenFOAM && wmakeLnInclude . ) +( cd other && ./Allwmake ) ( cd Pstream && ./Allwmake ) wmake libo OSspecific/$WM_OS @@ -15,7 +13,6 @@ wmake libso lagrangian/basic wmake libso triSurface wmake libso edgeMesh wmake libso meshTools - wmake libso finiteVolume ( cd MGridGenGamgAgglomeration && ./Allwmake ) @@ -23,7 +20,6 @@ wmake libso finiteVolume wmake libso sampling wmake libso dynamicMesh - wmake libso dynamicFvMesh wmake libso topoChangerFvMesh wmake libso fvMotionSolver @@ -36,14 +32,10 @@ wmake libso randomProcesses ( cd transportModels && ./Allwmake ) ( cd turbulenceModels && ./Allwmake ) ( cd LESmodels && ./Allwmake ) - ( cd lagrangian && ./Allwmake ) - ( cd postProcessing && ./Allwmake ) wmake libso autoMesh - wmake libso errorEstimation - # ----------------------------------------------------------------- end-of-file From f9f39234d2b2d0492802f47ce48c95d14402c475 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 May 2008 13:52:38 +0200 Subject: [PATCH 04/41] removed spurious execution bit from the file permissions --- src/lagrangian/basic/Make/files | 0 src/lagrangian/basic/Make/options | 0 src/lagrangian/dieselSpray/Make/files | 0 src/lagrangian/dieselSpray/Make/options | 0 src/lagrangian/intermediate/Make/files | 0 src/lagrangian/intermediate/Make/options | 0 src/lagrangian/solidParticle/Make/files | 0 src/lagrangian/solidParticle/Make/options | 0 src/thermophysicalModels/radiation/Make/files | 0 src/thermophysicalModels/radiation/Make/options | 0 10 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/lagrangian/basic/Make/files mode change 100755 => 100644 src/lagrangian/basic/Make/options mode change 100755 => 100644 src/lagrangian/dieselSpray/Make/files mode change 100755 => 100644 src/lagrangian/dieselSpray/Make/options mode change 100755 => 100644 src/lagrangian/intermediate/Make/files mode change 100755 => 100644 src/lagrangian/intermediate/Make/options mode change 100755 => 100644 src/lagrangian/solidParticle/Make/files mode change 100755 => 100644 src/lagrangian/solidParticle/Make/options mode change 100755 => 100644 src/thermophysicalModels/radiation/Make/files mode change 100755 => 100644 src/thermophysicalModels/radiation/Make/options diff --git a/src/lagrangian/basic/Make/files b/src/lagrangian/basic/Make/files old mode 100755 new mode 100644 diff --git a/src/lagrangian/basic/Make/options b/src/lagrangian/basic/Make/options old mode 100755 new mode 100644 diff --git a/src/lagrangian/dieselSpray/Make/files b/src/lagrangian/dieselSpray/Make/files old mode 100755 new mode 100644 diff --git a/src/lagrangian/dieselSpray/Make/options b/src/lagrangian/dieselSpray/Make/options old mode 100755 new mode 100644 diff --git a/src/lagrangian/intermediate/Make/files b/src/lagrangian/intermediate/Make/files old mode 100755 new mode 100644 diff --git a/src/lagrangian/intermediate/Make/options b/src/lagrangian/intermediate/Make/options old mode 100755 new mode 100644 diff --git a/src/lagrangian/solidParticle/Make/files b/src/lagrangian/solidParticle/Make/files old mode 100755 new mode 100644 diff --git a/src/lagrangian/solidParticle/Make/options b/src/lagrangian/solidParticle/Make/options old mode 100755 new mode 100644 diff --git a/src/thermophysicalModels/radiation/Make/files b/src/thermophysicalModels/radiation/Make/files old mode 100755 new mode 100644 diff --git a/src/thermophysicalModels/radiation/Make/options b/src/thermophysicalModels/radiation/Make/options old mode 100755 new mode 100644 From 9d4b64bdbe232c1e3cb792d1cb5758e3c393a055 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 May 2008 13:55:13 +0200 Subject: [PATCH 05/41] updated scripts for paraview 3.3 * install into paraview-3.3 instead of ParaView3.X.x for consistency with LD_LIBRARY_PATH --- bin/paraFoam | 81 ++++++++-------- bin/paraFoam.pvs | 12 +++ bin/tools/README | 2 + bin/tools/buildParaView3.3 | 193 +++++++++++++++++++++++++++++++++++++ etc/apps/paraview3/bashrc | 16 ++- etc/apps/paraview3/cshrc | 9 +- 6 files changed, 264 insertions(+), 49 deletions(-) create mode 100644 bin/paraFoam.pvs create mode 100644 bin/tools/README create mode 100755 bin/tools/buildParaView3.3 diff --git a/bin/paraFoam b/bin/paraFoam index e58290507d..a049d97484 100755 --- a/bin/paraFoam +++ b/bin/paraFoam @@ -33,33 +33,33 @@ Script=${0##*/} usage() { - while [ "$#" -ge 1 ]; do echo "$1"; shift; done - cat</dev/null || usage "directory does not exist: '$caseDir'" - ;; - *) - usage "unknown option/argument: '$*'" - ;; - esac + case "$1" in + -h | -help) + usage + ;; + -case) + shift + caseDir=$1 + [ "$#" -ge 1 ] || usage "'-case' option requires an argument" + cd "$caseDir" 2>/dev/null || usage "directory does not exist: '$caseDir'" + ;; + *) + usage "unknown option/argument: '$*'" + ;; + esac fi # get a sensible caseName @@ -67,41 +67,38 @@ caseName=${PWD##*/} # parent directory for normal or parallel results case "$caseName" in - processor*) parentDir=".." ;; - *) parentDir="." ;; + processor*) parentDir=".." ;; + *) parentDir="." ;; esac # check existence of essential files for check in system/controlDict system/fvSchemes system/fvSolution do - [ -s "$parentDir/$check" ] || usage "file does not exist: '$parentDir/$check'" + [ -s "$parentDir/$check" ] || usage "file does not exist: '$parentDir/$check'" done -OpenFoamExt="foam" -# OpenFoamExt="OpenFOAM" +caseFile="$caseName.foam" +# caseFile="$caseName.OpenFOAM" -if [ "$ParaView_VERSION" = "3" ]; then +case "$ParaView_VERSION" in +2*) + # Clean up on termination and on Ctrl-C + trap "rm -f paraFoam.pvs $caseFile 2>/dev/null; exit 0" EXIT TERM INT + touch $caseFile - # check existence of essential files - for check in system/controlDict system/fvSchemes system/fvSolution - do - [ -s "$parentDir/$check" ] || usage "file does not exist: '$parentDir/$check'" - done + # since we are now in the cwd, %CASE% is '$PWD/$caseFile' + sed -e s@%CASE%@$PWD/$caseFile@g \ + $WM_PROJECT_DIR/bin/paraFoam.pvs > paraFoam.pvs - touch $caseName.$OpenFoamExt - paraview --data=$caseName.$OpenFoamExt - rm $caseName.$OpenFoamExt 2>/dev/null + paraview paraFoam.pvs + ;; -else - - # since we are now in the cwd, FOAM_ROOT/FOAM_CASE is '$PWD' - sed -e s%FOAM_ROOT/FOAM_CASE%$PWD%g \ - -e s%FOAM_CASE%$caseName%g $WM_PROJECT_DIR/bin/paraFoam.pvs > paraFoam.pvs - - touch $caseName.$OpenFoamExt - paraview paraFoam.pvs - rm paraFoam.pvs $caseName.$OpenFoamExt 2>/dev/null - -fi +*) + # Clean up on termination and on Ctrl-C + trap "rm -f $caseFile 2>/dev/null; exit 0" EXIT TERM INT + touch $caseFile + paraview --data=$caseFile + ;; +esac #------------------------------------------------------------------------------ diff --git a/bin/paraFoam.pvs b/bin/paraFoam.pvs new file mode 100644 index 0000000000..8cbca6dc41 --- /dev/null +++ b/bin/paraFoam.pvs @@ -0,0 +1,12 @@ +# ParaView State Version 2.2 + +set kw(vtkTemp2) [$Application GetMainWindow] +set kw(vtkTemp29) [$kw(vtkTemp2) GetMainView] +set kw(vtkTemp980) [$kw(vtkTemp2) GetAnimationManager] +[$kw(vtkTemp2) GetRotateCameraButton] SetState 1 +$kw(vtkTemp2) ChangeInteractorStyle 1 +set kw(vtkTemp840) [$kw(vtkTemp2) InitializeReadCustom "FoamReader" "%CASE%"] +$kw(vtkTemp2) ReadFileInformation $kw(vtkTemp840) "%CASE%" +$kw(vtkTemp2) FinalizeRead $kw(vtkTemp840) "%CASE%" +set kw(vtkTemp868) [$kw(vtkTemp840) GetPVWidget {Filename}] +$kw(vtkTemp868) SetValue "%CASE%" diff --git a/bin/tools/README b/bin/tools/README new file mode 100644 index 0000000000..c99723b20e --- /dev/null +++ b/bin/tools/README @@ -0,0 +1,2 @@ +Misc. tools for building applications, etc that are useful to have +but which don't really need to be in the PATH. diff --git a/bin/tools/buildParaView3.3 b/bin/tools/buildParaView3.3 new file mode 100755 index 0000000000..028320139d --- /dev/null +++ b/bin/tools/buildParaView3.3 @@ -0,0 +1,193 @@ +#!/bin/sh +set -x + +# ParaView 3.x build script +# - normally run from folder above source folder + +# use the version number and the installation location specified +# in etc/apps/paraview3/{bashrc,cshrc} +: ${ParaView_VERSION:=3.3} +: ${ParaView_INST_DIR:=$WM_PROJECT_INST_DIR/paraview-$ParaView_VERSION} + +#!!User: +# set to location of paraview sources and where to build paraview +# PARAVIEW_SRC_DIR=$WM_PROJECT_INST_DIR/src/other/ParaView3 +PARAVIEW_SRC_DIR=/data/cfd2/work/cfdadmin/cvs/ParaView3 +PARAVIEW_BUILD_DIR=$PARAVIEW_SRC_DIR/platforms + +# TODO: extract the version number from the CMakeLists.txt variables: +# PARAVIEW_VERSION_MAJOR, and PARAVIEW_VERSION_MINOR +# ParaView_VERSION="3.3" + +# SET(PARAVIEW_VERSION_MAJOR 3) +# SET(PARAVIEW_VERSION_MINOR 3) + +#!!User: +# select desired features, include Python whenever possible +VERBOSE=OFF +INCLUDE_MPI=OFF +MPI_MAX_PROCS=32 +INCLUDE_PYTHON=ON +INCLUDE_MESA=OFF + +# initialisation +oldpwd=$PWD +unset OBJ_ADD + +# always build shared libraries +CMAKE_VARIABLES="-DBUILD_SHARED_LIBS:BOOL=ON" + +if [ "$VERBOSE" = ON ]; then + CMAKE_VARIABLES="$CMAKE_VARIABLES -DCMAKE_VERBOSE_MAKEFILE=TRUE" +fi + +#**************************************************************************** +# FIX: Attempt to get around seg-fault when building documentation +#CMAKE_VARIABLES="$CMAKE_VARIABLES -BUILD_DOCUMENTATION-ADVANCED:INTERNAL=0" +#**************************************************************************** + +# set python specific options +# NOTE - you'll need both python and python-devel packages installed +# - might need to create a symbolic link to the python library +# - anything after the '.so' gets in the way... +# - might need to run cmake -> make twice to pick up all the links... +if [ "$INCLUDE_PYTHON" = ON ]; then + PYTHON_INCLUDE_DIR=/usr/include/python2.5 + PYTHON_LIBRARY=/usr/lib$WM_COMPILER_LIB_ARCH/libpython2.5.so + + if [ -d "$PYTHON_INCLUDE_DIR" ]; then + OBJ_ADD="$OBJ_ADD-py" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DPARAVIEW_ENABLE_PYTHON=ON" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DPYTHON_INCLUDE_PATH=$PYTHON_INCLUDE_DIR" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DPYTHON_LIBRARY=$PYTHON_LIBRARY" + else + echo "non-existent PYTHON_INCLUDE_DIR: $PYTHON_INCLUDE_DIR" + fi +fi + +# set MPI specific options +if [ "$INCLUDE_MPI" = ON ]; then + case "$WM_MPLIB" in + OPENMPI) + MPI_INCLUDE_PATH=$OPENMPI_ARCH_PATH/include + MPI_LIBRARY=$OPENMPI_ARCH_PATH/lib/libmpi.so + MPI_RUN=$OPENMPI_ARCH_PATH/bin/mpirun + ;; + LAM) + MPI_INCLUDE_PATH=$LAM_ARCH_PATH/include + MPI_LIBRARY=$LAM_ARCH_PATH/lib/libmpi.so + MPI_RUN=$LAM_ARCH_PATH/bin/mpirun + ;; + MPICH) + MPI_INCLUDE_PATH=$MPICH_ARCH_PATH/include + MPI_LIBRARY=$MPICH_ARCH_PATH/lib/libmpich.so + MPI_RUN=$MPICH_ARCH_PATH/bin/mpirun + ;; + *) + unset INCLUDE_MPI + ;; + esac + + if [ "$INCLUDE_MPI" ]; then + OBJ_ADD="$OBJ_ADD-mpi" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DVTK_USE_MPI=ON" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DPARAVIEW_USE_MPI=ON" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DMPI_INCLUDE_PATH=$MPI_INCLUDE_PATH" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DMPI_LIBRARY=$MPI_LIBRARY" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DVTK_MPIRUN_EXE=$MPI_RUN" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DVTK_MPI_MAX_NUMPROCS=$MPI_MAX_PROCS" + else + echo "unknown/unsupported mpi: $WM_MPLIB" + fi +fi + +# set MESA specific options +if [ "$INCLUDE_MESA" = ON ]; then + MESA_INCLUDE_DIR=/usr/include/GL + MESA_LIBRARY=/usr/lib$WM_COMPILER_LIB_ARCH/libOSMesa.so + + if [ -d "$MESA_INCLUDE_DIR" -a -f "$MESA_LIBRARY" ]; then + OBJ_ADD="$OBJ_ADD-mesa" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DVTK_OPENGL_HAS_OSMESA=ON" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DOSMESA_INCLUDE_DIR=$MESA_INCLUDE_DIR" + CMAKE_VARIABLES="$CMAKE_VARIABLES -DOSMESA_LIBRARY=$MESA_LIBRARY" + else + echo "no MESA information found ... skipping" + fi +fi + + +# finalize the build/install environment +PARAVIEW_OBJ_DIR=$PARAVIEW_BUILD_DIR/$WM_OPTIONS$OBJ_ADD +PARAVIEW_APP_DIR=$ParaView_INST_DIR/platforms/$WM_OPTIONS$OBJ_ADD + +# create paraview build folder +mkdir -p $PARAVIEW_OBJ_DIR +cd $PARAVIEW_OBJ_DIR + +# +# make paraview +# + +# provide a backdoor to skip cmake for repeated builds +if [ -z "$build_no_cmake" ] +then + cmake \ + -DCMAKE_INSTALL_PREFIX=$PARAVIEW_APP_DIR \ + $CMAKE_VARIABLES \ + $PARAVIEW_SRC_DIR +fi + + +if [ -r /proc/cpuinfo ]; then + WM_NCOMPPROCS=`egrep "^processor" /proc/cpuinfo | wc -l` + + [ $WM_NCOMPPROCS -le 8 ] || WM_NCOMPPROCS=8 + + make -j $WM_NCOMPPROCS +else + make +fi + + +if [ -e "$PARAVIEW_OBJ_DIR/bin/paraview" ]; then + echo "Info: Installation completed - proceeding to install" + make install + + # copy VTK headers to install directory + echo "Info: Copying VTK headers" + cp -r $PARAVIEW_SRC_DIR/VTK $PARAVIEW_APP_DIR + cp -r $PARAVIEW_OBJ_DIR/VTK/vtkConfigure.h $PARAVIEW_APP_DIR/VTK + cp -r $PARAVIEW_OBJ_DIR/VTK/vtkstd $PARAVIEW_APP_DIR/VTK + + # copy all .so files to the lib folder + # - NOTE: shouldn't be necessary - but some libs not copied over to the + # install folder +## echo "Info: Copying libs" +## cp $PARAVIEW_OBJ_DIR/bin/*.so* $PARAVIEW_APP_DIR/lib/paraview-$ParaView_VERSION + + echo "Info: Copying ParaViewConfig.cmake" + cp $PARAVIEW_OBJ_DIR/ParaViewConfig.cmake $PARAVIEW_APP_DIR + + if [ "$OBJ_ADD" ]; then + echo "Creating symbolic link in $ParaView_INST_DIR/platforms from $WM_OPTIONS$OBJ_ADD to $WM_OPTIONS" + ( cd $ParaView_INST_DIR/platforms && ln -s $WM_OPTIONS$OBJ_ADD $WM_OPTIONS ) + fi + + echo "Installation complete" + echo "Set environment variables:" + echo " - ParaView_DIR to $PARAVIEW_APP_DIR" + echo " - ParaView_INST_DIR to $PARAVIEW_APP_DIR" + echo " - PV_PLUGIN_PATH to $FOAM_LIBBIN" + echo "Add $ParaView_INST_DIR/bin to PATH" + echo "Add $ParaView_INST_DIR/lib to LD_LIBRARY_PATH" + + echo "done." +else + echo "*** Error: Installation failed - see output window" +fi + +# finalisation +cd $oldpwd + +# ----------------------------------------------------------------- end-of-file diff --git a/etc/apps/paraview3/bashrc b/etc/apps/paraview3/bashrc index c02b490abb..3d197f43f3 100644 --- a/etc/apps/paraview3/bashrc +++ b/etc/apps/paraview3/bashrc @@ -41,18 +41,26 @@ export CMAKE_HOME=$WM_PROJECT_INST_DIR/$WM_ARCH/cmake-2.4.6 if [ -r $CMAKE_HOME ]; then export PATH=$CMAKE_HOME/bin:$PATH +else + unset CMAKE_HOME fi -export ParaView_VERSION=3 +# export ParaView_VERSION="3.3-cvs" +export ParaView_VERSION=3.3 -export ParaView_INST_DIR=$WM_PROJECT_INST_DIR/ParaView3.3-cvs +export ParaView_INST_DIR=$WM_PROJECT_INST_DIR/paraview-$ParaView_VERSION export ParaView_DIR=$ParaView_INST_DIR/platforms/$WM_OPTIONS -export PYTHONPATH=$PYTHONPATH:$ParaView_DIR/bin:$ParaView_DIR/Utilities/VTKPythonWrapping +if [ "$PYTHONPATH" ]; then + export PYTHONPATH=$PYTHONPATH:$ParaView_DIR/Utilities/VTKPythonWrapping +else + export PYTHONPATH=$ParaView_DIR/Utilities/VTKPythonWrapping +fi + if [ -r $ParaView_DIR ]; then export PATH=$ParaView_DIR/bin:$PATH - export LD_LIBRARY_PATH=${ParaView_DIR}/bin:${LD_LIBRARY_PATH} + export LD_LIBRARY_PATH=$ParaView_DIR/lib/paraview-$ParaView_VERSION:$LD_LIBRARY_PATH export PV_PLUGIN_PATH=$FOAM_LIBBIN fi diff --git a/etc/apps/paraview3/cshrc b/etc/apps/paraview3/cshrc index c419259279..e3d3c87ea2 100644 --- a/etc/apps/paraview3/cshrc +++ b/etc/apps/paraview3/cshrc @@ -41,11 +41,14 @@ setenv CMAKE_HOME $WM_PROJECT_INST_DIR/$WM_ARCH/cmake-2.4.6 if ( -r $CMAKE_HOME ) then set path=($CMAKE_HOME/bin $path) +else + unset CMAKE_HOME endif -setenv ParaView_VERSION 3 +# setenv ParaView_VERSION 3.3-cvs +setenv ParaView_VERSION 3.3 -setenv ParaView_INST_DIR $WM_PROJECT_INST_DIR/ParaView3.3-cvs +export ParaView_INST_DIR=$WM_PROJECT_INST_DIR/paraview-$ParaView_VERSION setenv ParaView_DIR $ParaView_INST_DIR/platforms/$WM_OPTIONS if ($?PYTHONPATH) then @@ -56,7 +59,7 @@ endif if ( -r $ParaView_INST_DIR ) then set path=($ParaView_DIR/bin $path) - setenv LD_LIBRARY_PATH ${ParaView_DIR}/bin:${LD_LIBRARY_PATH} + setenv LD_LIBRARY_PATH $ParaView_DIR/lib/paraview-$ParaView_VERSION:$LD_LIBRARY_PATH setenv PV_PLUGIN_PATH $FOAM_LIBBIN endif From 146b67bb9f8b6712d6dbd4109f2b72c5a96d9e24 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 May 2008 13:58:24 +0200 Subject: [PATCH 06/41] revived old changes to engineTime to allow dictionary modifications to be noticed and to make the engine geometry optional --- src/engine/engineTime/engineTime.C | 132 ++++++++++++++++------------- src/engine/engineTime/engineTime.H | 57 +++++++++---- 2 files changed, 117 insertions(+), 72 deletions(-) diff --git a/src/engine/engineTime/engineTime.C b/src/engine/engineTime/engineTime.C index 10827455af..313a53c068 100644 --- a/src/engine/engineTime/engineTime.C +++ b/src/engine/engineTime/engineTime.C @@ -27,21 +27,35 @@ License #include "engineTime.H" #include "mathematicalConstants.H" -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -namespace Foam +void Foam::engineTime::timeAdjustment() { + deltaT_ = degToTime(deltaT_); + endTime_ = degToTime(endTime_); + + if + ( + writeControl_ == wcRunTime + || writeControl_ == wcAdjustableRunTime + ) + { + writeInterval_ = degToTime(writeInterval_); + } +} + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // //- Construct from objectRegistry arguments -engineTime::engineTime +Foam::engineTime::engineTime ( const word& name, const fileName& rootPath, const fileName& caseName, const fileName& systemName, - const fileName& constantName + const fileName& constantName, + const fileName& dictName ) : Time @@ -52,7 +66,7 @@ engineTime::engineTime systemName, constantName ), - engineGeometry_ + dict_ ( IOobject ( @@ -64,78 +78,84 @@ engineTime::engineTime false ) ), - conRodLength_(engineGeometry_.lookup("conRodLength")), - bore_(engineGeometry_.lookup("bore")), - stroke_(engineGeometry_.lookup("stroke")), - clearance_(engineGeometry_.lookup("clearance")), - rpm_(engineGeometry_.lookup("rpm")) + rpm_(dict_.lookup("rpm")), + conRodLength_(dimensionedScalar("conRodLength", dimLength, 0)), + bore_(dimensionedScalar("bore", dimLength, 0)), + stroke_(dimensionedScalar("stroke", dimLength, 0)), + clearance_(dimensionedScalar("clearance", dimLength, 0)) { - value() = degToTime(value()); + // the geometric parameters are not strictly required for Time + if (dict_.found("conRodLength")) + { + dict_.lookup("conRodLength") >> conRodLength_; + } + if (dict_.found("bore")) + { + dict_.lookup("bore") >> bore_; + } + if (dict_.found("stroke")) + { + dict_.lookup("stroke") >> stroke_; + } + if (dict_.found("clearance")) + { + dict_.lookup("clearance") >> clearance_; + } + + timeAdjustment(); startTime_ = degToTime(startTime_); - endTime_ = degToTime(endTime_); - - deltaT_ = degToTime(deltaT_); - deltaT0_ = deltaT_; - - if - ( - writeControl_ == wcRunTime - || writeControl_ == wcAdjustableRunTime - ) - { - writeInterval_ = degToTime(writeInterval_); - } + value() = degToTime(value()); + deltaT0_ = deltaT_; } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // Read the controlDict and set all the parameters -bool engineTime::read() +void Foam::engineTime::readDict() { - if (!Time::read()) + Time::readDict(); + timeAdjustment(); +} + + +// Read the controlDict and set all the parameters +bool Foam::engineTime::read() +{ + if (Time::read()) { - return false; + timeAdjustment(); + return true; } else { - deltaT_ = degToTime(deltaT_); - endTime_ = degToTime(endTime_); - - if - ( - writeControl_ == wcRunTime - || writeControl_ == wcAdjustableRunTime - ) - { - writeInterval_ = degToTime(writeInterval_); - } - - return true; + return false; } } -scalar engineTime::degToRad(const scalar deg) const +Foam::scalar Foam::engineTime::degToRad(const scalar deg) const { return mathematicalConstant::pi*deg/180.0; } -scalar engineTime::degToTime(const scalar theta) const +Foam::scalar Foam::engineTime::degToTime(const scalar theta) const { - return theta/(360.0*rpm_.value()/60.0); + // 6 * rpm => deg/s + return theta/(6.0*rpm_.value()); } -scalar engineTime::timeToDeg(const scalar t) const +Foam::scalar Foam::engineTime::timeToDeg(const scalar t) const { - return t*(360.0*rpm_.value()/60.0); + // 6 * rpm => deg/s + return t*(6.0*rpm_.value()); } -scalar engineTime::theta() const +Foam::scalar Foam::engineTime::theta() const { return timeToDeg(value()); } @@ -143,7 +163,7 @@ scalar engineTime::theta() const // Return current crank-angle translated to a single revolution // (value between -180 and 180 with 0 = top dead centre) -scalar engineTime::thetaRevolution() const +Foam::scalar Foam::engineTime::thetaRevolution() const { scalar t = theta(); @@ -161,13 +181,13 @@ scalar engineTime::thetaRevolution() const } -scalar engineTime::deltaTheta() const +Foam::scalar Foam::engineTime::deltaTheta() const { return timeToDeg(deltaT().value()); } -scalar engineTime::pistonPosition(const scalar theta) const +Foam::scalar Foam::engineTime::pistonPosition(const scalar theta) const { return ( @@ -186,7 +206,7 @@ scalar engineTime::pistonPosition(const scalar theta) const } -dimensionedScalar engineTime::pistonPosition() const +Foam::dimensionedScalar Foam::engineTime::pistonPosition() const { return dimensionedScalar ( @@ -197,7 +217,7 @@ dimensionedScalar engineTime::pistonPosition() const } -dimensionedScalar engineTime::pistonDisplacement() const +Foam::dimensionedScalar Foam::engineTime::pistonDisplacement() const { return dimensionedScalar ( @@ -208,24 +228,24 @@ dimensionedScalar engineTime::pistonDisplacement() const } -dimensionedScalar engineTime::pistonSpeed() const +Foam::dimensionedScalar Foam::engineTime::pistonSpeed() const { return dimensionedScalar ( "pistonSpeed", - dimLength/dimTime, + dimVelocity, pistonDisplacement().value()/(deltaT().value() + VSMALL) ); } -scalar engineTime::userTimeToTime(const scalar theta) const +Foam::scalar Foam::engineTime::userTimeToTime(const scalar theta) const { return degToTime(theta); } -scalar engineTime::timeToUserTime(const scalar t) const +Foam::scalar Foam::engineTime::timeToUserTime(const scalar t) const { return timeToDeg(t); } @@ -233,6 +253,4 @@ scalar engineTime::timeToUserTime(const scalar t) const // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace Foam - // ************************************************************************* // diff --git a/src/engine/engineTime/engineTime.H b/src/engine/engineTime/engineTime.H index 3a78aa7ab6..5ecf2c9022 100644 --- a/src/engine/engineTime/engineTime.H +++ b/src/engine/engineTime/engineTime.H @@ -26,7 +26,25 @@ Class Foam::engineTime Description - Foam::engineTime + Manage time in terms of engine RPM and crank-angle. + + When engineTime is in effect, the userTime is reported in degrees + crank-angle instead of in seconds. The RPM to be used is specified in + @c constant/engineGeometry. If only a time conversion is required, + the geometric engine parameters can be dropped or set to zero. + + For example, + @verbatim + rpm rpm [0 0 -1 0 0] 2000; + + conRodLength conRodLength [0 1 0 0 0] 0.0; + bore bore [0 1 0 0 0] 0.0; + stroke stroke [0 1 0 0 0] 0.0; + clearance clearance [0 1 0 0 0] 0.0; + @endverbatim + +Note + The engineTime can currently only be selected at compile-time. SourceFiles engineTime.C @@ -46,7 +64,7 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class engineTime Declaration + Class engineTime Declaration \*---------------------------------------------------------------------------*/ class engineTime @@ -55,13 +73,16 @@ class engineTime { // Private data - IOdictionary engineGeometry_; + IOdictionary dict_; + //- RPM is required + dimensionedScalar rpm_; + + //- Optional engine geometry parameters dimensionedScalar conRodLength_; dimensionedScalar bore_; dimensionedScalar stroke_; dimensionedScalar clearance_; - dimensionedScalar rpm_; // Private Member Functions @@ -72,6 +93,8 @@ class engineTime //- Disallow default bitwise assignment void operator=(const engineTime&); + //- adjust read time values + void timeAdjustment(); public: @@ -84,7 +107,8 @@ public: const fileName& rootPath, const fileName& caseName, const fileName& systemName = "system", - const fileName& constantName = "constant" + const fileName& constantName = "constant", + const fileName& dictName = "engineGeometry" ); // Destructor @@ -116,7 +140,13 @@ public: //- Return the engine geometry dictionary const dictionary& engineDict() const { - return engineGeometry_; + return dict_; + } + + //- Return the engines current operating RPM + const dimensionedScalar& rpm() const + { + return rpm_; } //- Return the engines connecting-rod length @@ -143,12 +173,6 @@ public: return clearance_; } - //- Return the engines current operating RPM - const dimensionedScalar& rpm() const - { - return rpm_; - } - //- Return current crank-angle scalar theta() const; @@ -173,16 +197,19 @@ public: // Member functions overriding the virtual functions in time //- Convert the user-time (CA deg) to real-time (s). - scalar userTimeToTime(const scalar theta) const; + virtual scalar userTimeToTime(const scalar theta) const; //- Convert the real-time (s) into user-time (CA deg) - scalar timeToUserTime(const scalar t) const; + virtual scalar timeToUserTime(const scalar t) const; + + //- Read the control dictionary and set the write controls etc. + virtual void readDict(); // Edit //- Read the controlDict and set all the parameters - bool read(); + virtual bool read(); }; From 365b6311b9c4e2e42594f082589d01d2c1beb6ef Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 May 2008 14:14:15 +0200 Subject: [PATCH 07/41] add timeSeries interpolations (good for boundary conditions) --- .../interpolations/timeSeries/timeSeries.C | 402 ++++++++++++++++++ .../interpolations/timeSeries/timeSeries.H | 162 +++++++ 2 files changed, 564 insertions(+) create mode 100644 src/OpenFOAM/interpolations/timeSeries/timeSeries.C create mode 100644 src/OpenFOAM/interpolations/timeSeries/timeSeries.H diff --git a/src/OpenFOAM/interpolations/timeSeries/timeSeries.C b/src/OpenFOAM/interpolations/timeSeries/timeSeries.C new file mode 100644 index 0000000000..cd52424e32 --- /dev/null +++ b/src/OpenFOAM/interpolations/timeSeries/timeSeries.C @@ -0,0 +1,402 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 + +\*---------------------------------------------------------------------------*/ + +#include "timeSeries.H" +#include "Istream.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::timeSeries::timeSeries(const bounds bound) +: + List >(), + bounding_(bound) +{} + + +template +Foam::timeSeries::timeSeries(const word& bound) +: + List >(), + bounding_(timeSeries::WARN) +{ + bounding(bound); +} + + +template +Foam::timeSeries::timeSeries(Istream& is, const bounds bound) +: + List >(is), + bounding_(bound) +{} + + +template +Foam::timeSeries::timeSeries(Istream& is, const word& bound) +: + List >(is), + bounding_(timeSeries::WARN) +{ + bounding(bound); +} + + +// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::timeSeries::~timeSeries() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::word Foam::timeSeries::bounding() const +{ + word enumName("warn"); + + switch (bounding_) + { + case timeSeries::ERROR: + enumName = "error"; + break; + + case timeSeries::WARN: + enumName = "warn"; + break; + + case timeSeries::CLAMP: + enumName = "clamp"; + break; + + case timeSeries::REPEAT: + enumName = "repeat"; + break; + } + + return enumName; +} + + +template +void Foam::timeSeries::bounding(const word& bound) +{ + if (bound == "error") + { + bounding_ = timeSeries::ERROR; + } + else if (bound == "warn") + { + bounding_ = timeSeries::WARN; + } + else if (bound == "clamp") + { + bounding_ = timeSeries::CLAMP; + } + else if (bound == "repeat") + { + bounding_ = timeSeries::REPEAT; + } + else + { + WarningIn("Foam::timeSeries::boundingEnum(const word&)") + << "bad bounding specifier " << bound << " using 'warn'" << endl; + + bounding_ = timeSeries::WARN; + } +} + + +template +void Foam::timeSeries::check() const +{ + label n = size(); + scalar prevTime = List >::operator[](0).first(); + + for (label i = 1; i < n; ++i) + { + const scalar currTime = List >::operator[](i).first(); + + // avoid duplicate times (divide-by-zero error) + if (currTime <= prevTime) + { + FatalErrorIn + ( + "Foam::timeSeries::checkOrder() const" + ) << "out-of-order time: " + << currTime << " at index " << i << nl + << exit(FatalError); + } + prevTime = currTime; + } +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + + +template +const Foam::Tuple2& +Foam::timeSeries::operator[](const label i) const +{ + label ii = i; + label n = size(); + + if (n <= 1) + { + ii = 0; + } + else if (ii < 0) + { + switch (bounding_) + { + case timeSeries::ERROR: + FatalErrorIn + ( + "Foam::timeSeries::operator[](const label) const" + ) << "index (" << ii << ") underflow" << nl + << exit(FatalError); + break; + + case timeSeries::WARN: + WarningIn + ( + "Foam::timeSeries::operator[](const label) const" + ) << "index (" << ii << ") underflow" << nl + << " Continuing with the first entry" + << endl; + // fall-through to 'CLAMP' + + case timeSeries::CLAMP: + ii = 0; + break; + + case timeSeries::REPEAT: + while (ii < 0) + { + ii += n; + } + break; + } + } + else if (ii >= n) + { + switch (bounding_) + { + case timeSeries::ERROR: + FatalErrorIn + ( + "Foam::timeSeries::operator[](const label) const" + ) << "index (" << ii << ") overflow" << nl + << exit(FatalError); + break; + + case timeSeries::WARN: + WarningIn + ( + "Foam::timeSeries::operator[](const label) const" + ) << "index (" << ii << ") overflow" << nl + << " Continuing with the last entry" + << endl; + // fall-through to 'CLAMP' + + case timeSeries::CLAMP: + ii = n - 1; + break; + + case timeSeries::REPEAT: + while (ii >= n) + { + ii -= n; + } + break; + } + } + + return List >::operator[](ii); +} + + +template +T Foam::timeSeries::operator()(const scalar timeValue) const +{ + label n = size(); + + if (n <= 1) + { + return List >::operator[](0).second(); + } + + scalar minTime = List >::operator[](0).first(); + scalar maxTime = List >::operator[](n-1).first(); + scalar lookupTime = timeValue; + + if (lookupTime < minTime) + { + switch (bounding_) + { + case timeSeries::ERROR: + FatalErrorIn + ( + "Foam::timeSeries::operator[](const scalar) const" + ) << "time (" << lookupTime << ") underflow" << nl + << exit(FatalError); + break; + + case timeSeries::WARN: + WarningIn + ( + "Foam::timeSeries::operator[](const scalar) const" + ) << "time (" << lookupTime << ") underflow" << nl + << " Continuing with the first entry" + << endl; + // fall-through to 'CLAMP' + + case timeSeries::CLAMP: + return List >::operator[](0).second(); + break; + + case timeSeries::REPEAT: + // adjust lookupTime to >= 0 + while (lookupTime < 0) + { + lookupTime += maxTime; + } + break; + } + } + else if (lookupTime >= maxTime) + { + switch (bounding_) + { + case timeSeries::ERROR: + FatalErrorIn + ( + "Foam::timeSeries::operator[](const label) const" + ) << "time (" << lookupTime << ") overflow" << nl + << exit(FatalError); + break; + + case timeSeries::WARN: + WarningIn + ( + "Foam::timeSeries::operator[](const label) const" + ) << "time (" << lookupTime << ") overflow" << nl + << " Continuing with the last entry" + << endl; + // fall-through to 'CLAMP' + + case timeSeries::CLAMP: + return List >::operator[](n-1).second(); + break; + + case timeSeries::REPEAT: + // adjust lookupTime <= maxTime + while (lookupTime > maxTime) + { + lookupTime -= maxTime; + } + break; + } + } + + label lo = 0; + label hi = 0; + + // look for the correct range + for (label i = 0; i < n; ++i) + { + if (lookupTime >= List >::operator[](i).first()) + { + lo = hi = i; + } + else + { + hi = i; + break; + } + } + + if (lo == hi) + { + // we are at the end of the table - or there is only a single entry + return List >::operator[](hi).second(); + } + else if (hi == 0) + { + // this treatment should should only occur under these condition: + // -> the 'REPEAT' treatment + // -> (0 <= time <= minTime) + // -> minTime > 0 + // Use the value at maxTime as the value for time=0 + lo = n - 1; + + return + ( + List >::operator[](lo).second() + + + ( + List >::operator[](hi).second() + - List >::operator[](lo).second() + ) + * (lookupTime / minTime) + ); + } + else + { + // normal interpolation + return + ( + List >::operator[](lo).second() + + + ( + List >::operator[](hi).second() + - List >::operator[](lo).second() + ) + * + ( + lookupTime + - List >::operator[](lo).first() + ) + / + ( + List >::operator[](hi).first() + - List >::operator[](lo).first() + ) + ); + } +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/interpolations/timeSeries/timeSeries.H b/src/OpenFOAM/interpolations/timeSeries/timeSeries.H new file mode 100644 index 0000000000..f581dafe50 --- /dev/null +++ b/src/OpenFOAM/interpolations/timeSeries/timeSeries.H @@ -0,0 +1,162 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2007 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 + +Class + Foam::timeSeries + +Description + A list of times and values. + The time values must be positive and monotonically increasing. + + The treatment of out-of-bounds values depends on the current setting + of bounding. + + If @a REPEAT bounding is in effect, the final time value is treated + as being equivalent to time=0 for the following periods. + +Note + - Accessing an empty list will result in an error. + - Accessing a list with a single element will always return the same value. + +SourceFiles + timeSeries.C + +\*---------------------------------------------------------------------------*/ + +#ifndef timeSeries_H +#define timeSeries_H + +#include "List.H" +#include "Tuple2.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class timeSeries Declaration +\*---------------------------------------------------------------------------*/ + +template +class timeSeries +: + public List > +{ +public: + + // Public data types + + //- Enumeration for handling out-of-bound times + enum bounds + { + ERROR, /*!< Exit with a FatalError */ + WARN, /*!< Issue warning and clamp value (default) */ + CLAMP, /*!< Clamp value to the start/end value */ + REPEAT /*!< Treat as a repeating list */ + }; + +private: + + // Private data + + //- Enumeration for handling out-of-bound times + bounds bounding_; + +public: + + // Constructors + + //- Construct null, optionally with a given bounding + timeSeries(const bounds = timeSeries::WARN); + + //- Construct null with a given bounding + timeSeries(const word&); + + //- Construct from Istream, optionally with a given bounding + timeSeries(Istream&, const bounds = timeSeries::WARN); + + //- Construct from Istream with a given bounding + timeSeries(Istream&, const word&); + + // Destructor + + ~timeSeries(); + + // Member Functions + + // Access + + //- Return the size + label size() const + { + return List >::size(); + } + + //- Return the out-of-bounds treatment as a word + word bounding() const; + + // Check + + //- Check that list is monotonically increasing + // Exit with a FatalError if there is a problem + void check() const; + + // Edit + + //- Set the out-of-bounds treatment from enum, return previous setting + bounds bounding(const bounds& bound) + { + bounds prev = bounding_; + bounding_ = bound; + return prev; + } + + //- Set the out-of-bounds treatment from word + void bounding(const word& bound); + + // Member Operators + + //- Return an element of constant Tuple2 + const Tuple2& operator[](const label) const; + + //- Return an interpolated value + T operator()(const scalar) const; + +}; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "timeSeries.C" +#endif + +#endif +// ************************************************************************* // From 52be85e2f439ff1dec040ff6f3f3fbe5bd06f7e7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 May 2008 14:15:31 +0200 Subject: [PATCH 08/41] added access to STL stable_sort algorithm --- src/OpenFOAM/containers/Lists/List/List.C | 14 +++++++ src/OpenFOAM/containers/Lists/List/List.H | 8 +++- .../Lists/SortableList/SortableList.C | 41 +++++++++++++------ .../Lists/SortableList/SortableList.H | 5 ++- 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 3eecd8c055..6884f8de40 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -435,6 +435,20 @@ void sort(List& a, const Cmp& cmp) } +template +void stableSort(List& a) +{ + std::stable_sort(a.begin(), a.end()); +} + + +template +void stableSort(List& a, const Cmp& cmp) +{ + std::stable_sort(a.begin(), a.end(), cmp); +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // Assignment to UList operator. Takes linear time. diff --git a/src/OpenFOAM/containers/Lists/List/List.H b/src/OpenFOAM/containers/Lists/List/List.H index 50db82f0a3..52e285418e 100644 --- a/src/OpenFOAM/containers/Lists/List/List.H +++ b/src/OpenFOAM/containers/Lists/List/List.H @@ -28,7 +28,7 @@ Class Description A 1D array of objects of type \, where the size of the vector is known and used for subscript bounds checking, etc. - + Storage is allocated on free-store during construction. SourceFiles @@ -195,6 +195,12 @@ void sort(List& a); template void sort(List& a, const Cmp&); +template +void stableSort(List& a); + +template +void stableSort(List& a, const Cmp&); + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C index b20baf4645..78e9553d96 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.C +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.C @@ -28,14 +28,11 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -namespace Foam -{ - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // Construct from List template -SortableList::SortableList(const List& values) +Foam::SortableList::SortableList(const List& values) : List(values), indices_(values.size()) @@ -46,7 +43,7 @@ SortableList::SortableList(const List& values) // Construct given size. Sort later on. template -SortableList::SortableList(const label size) +Foam::SortableList::SortableList(const label size) : List(size), indices_(size) @@ -55,7 +52,7 @@ SortableList::SortableList(const label size) // Construct given size and initial value. Sort later on. template -SortableList::SortableList(const label size, const Type& val) +Foam::SortableList::SortableList(const label size, const Type& val) : List(size, val), indices_(size) @@ -64,7 +61,7 @@ SortableList::SortableList(const label size, const Type& val) // Construct as copy. template -SortableList::SortableList(const SortableList& lst) +Foam::SortableList::SortableList(const SortableList& lst) : List(lst), indices_(lst.indices()) @@ -74,7 +71,7 @@ SortableList::SortableList(const SortableList& lst) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template -void SortableList::setSize(const label newSize) +void Foam::SortableList::setSize(const label newSize) { List::setSize(newSize); indices_.setSize(newSize); @@ -82,7 +79,7 @@ void SortableList::setSize(const label newSize) template -void SortableList::sort() +void Foam::SortableList::sort() { forAll(indices_, i) { @@ -98,7 +95,29 @@ void SortableList::sort() tmpValues[i] = this->operator[](indices_[i]); } - List::operator=(tmpValues); + List::transfer(tmpValues); +} + + + +template +void Foam::SortableList::stableSort() +{ + forAll(indices_, i) + { + indices_[i] = i; + } + + Foam::stableSort(indices_, less(*this)); + + List tmpValues(this->size()); + + forAll(indices_, i) + { + tmpValues[i] = this->operator[](indices_[i]); + } + + List::transfer(tmpValues); } @@ -114,6 +133,4 @@ void Foam::SortableList::operator=(const SortableList& rhs) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -} // End namespace Foam - // ************************************************************************* // diff --git a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H index 6a242180c2..389f98215e 100644 --- a/src/OpenFOAM/containers/Lists/SortableList/SortableList.H +++ b/src/OpenFOAM/containers/Lists/SortableList/SortableList.H @@ -100,7 +100,7 @@ public: // Member Functions - //- Return the list of sorted point indices. Updated every sort. + //- Return the list of sorted indices. Updated every sort. const labelList& indices() const { return indices_; @@ -112,6 +112,9 @@ public: //- Sort the list (if changed after construction time) void sort(); + //- Sort the list (if changed after construction time) + void stableSort(); + // Member Operators From 02df4dbd2c841e7062de79883a6f5eac1b1b7948 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 May 2008 14:17:04 +0200 Subject: [PATCH 09/41] add copy construct with max number of characters --- src/OpenFOAM/primitives/strings/word/word.H | 7 +++++-- src/OpenFOAM/primitives/strings/word/wordI.H | 21 +++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/OpenFOAM/primitives/strings/word/word.H b/src/OpenFOAM/primitives/strings/word/word.H index cd75979c69..42bbc57b6d 100644 --- a/src/OpenFOAM/primitives/strings/word/word.H +++ b/src/OpenFOAM/primitives/strings/word/word.H @@ -84,11 +84,14 @@ public: inline word(); //- Construct as copy - inline word(const word& w); + inline word(const word&); //- Construct as copy of character array inline word(const char*); + //- Construct as copy with a maximum number of characters + inline word(const char*, const size_type); + //- Construct as copy of string inline word(const string&); @@ -96,7 +99,7 @@ public: inline word(const std::string&); //- Construct from Istream - word(Istream& is); + word(Istream&); // Member functions diff --git a/src/OpenFOAM/primitives/strings/word/wordI.H b/src/OpenFOAM/primitives/strings/word/wordI.H index 02acb1ce0c..406525c16e 100644 --- a/src/OpenFOAM/primitives/strings/word/wordI.H +++ b/src/OpenFOAM/primitives/strings/word/wordI.H @@ -39,7 +39,7 @@ inline void Foam::word::stripInvalid() std::cerr << "word::stripInvalid() called for word " << this->c_str() << std::endl; - + if (debug > 1) { std::cerr @@ -65,25 +65,32 @@ inline Foam::word::word() {} -inline Foam::word::word(const string& str) +inline Foam::word::word(const string& s) : - string(str) + string(s) { stripInvalid(); } -inline Foam::word::word(const std::string& stdStr) +inline Foam::word::word(const std::string& s) : - string(stdStr) + string(s) { stripInvalid(); } -inline Foam::word::word(const char* chars) +inline Foam::word::word(const char* s) : - string(chars) + string(s) +{ + stripInvalid(); +} + +inline Foam::word::word(const char* s, const size_type n) +: + string(s, n) { stripInvalid(); } From cfed7e32807592df744b1862a6ff324c43036e53 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 8 May 2008 14:20:03 +0200 Subject: [PATCH 10/41] Added compare methods for edge/triFace. Added edgeDirection methods for face/triFace. Added extra constructors for converting faces to triFaces. The collapse() method now returns the new face size and can be used to check if the collapse face is valid. --- src/OpenFOAM/meshes/meshShapes/edge/edge.H | 8 +- src/OpenFOAM/meshes/meshShapes/edge/edgeI.H | 32 ++++- src/OpenFOAM/meshes/meshShapes/face/face.C | 45 ++++++- src/OpenFOAM/meshes/meshShapes/face/face.H | 8 +- .../meshes/meshShapes/triFace/triFace.H | 28 +++- .../meshes/meshShapes/triFace/triFaceI.H | 122 ++++++++++++++++-- 6 files changed, 217 insertions(+), 26 deletions(-) diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edge.H b/src/OpenFOAM/meshes/meshShapes/edge/edge.H index ccef92bf41..f8fb2696b6 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edge.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edge.H @@ -119,6 +119,12 @@ public: //- Return edge line inline linePointRef line(const pointField&) const; + //- compare edges + // - 0: different + // - +1: identical + // - -1: same edge, but different orientation + static inline int compare(const edge&, const edge&); + // Friend Operators @@ -127,7 +133,7 @@ public: }; -//- Hash specialisation +//- Hash specialisation // Simple commutative hash. template<> inline label Hash::operator()(const edge& e) const diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H index 8aa88ebe78..bd3bd339fd 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edgeI.H @@ -26,6 +26,30 @@ License #include "IOstreams.H" +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + + +// return +// - 0: different +// - +1: identical +// - -1: same edge, but different orientation +inline int Foam::edge::compare(const edge& a, const edge& b) +{ + if (a[0] == b[0] && a[1] == b[1]) + { + return 1; + } + else if (a[0] == b[1] && a[1] == b[0]) + { + return -1; + } + else + { + return 0; + } +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // inline Foam::edge::edge() @@ -146,17 +170,13 @@ inline Foam::linePointRef Foam::edge::line(const pointField& p) const inline bool Foam::operator==(const edge& a, const edge& b) { - return - ( - (a[0] == b[0] && a[1] == b[1]) - || (a[0] == b[1] && a[1] == b[0]) - ); + return edge::compare(a,b) != 0; } inline bool Foam::operator!=(const edge& a, const edge& b) { - return !(a == b); + return edge::compare(a,b) == 0; } diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.C b/src/OpenFOAM/meshes/meshShapes/face/face.C index dda506d789..2d06d0db28 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.C +++ b/src/OpenFOAM/meshes/meshShapes/face/face.C @@ -438,7 +438,7 @@ int Foam::face::compare(const face& a, const face& b) // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::face::collapse() +Foam::label Foam::face::collapse() { if (size() > 1) { @@ -458,6 +458,8 @@ void Foam::face::collapse() setSize(ci); } + + return size(); } @@ -696,6 +698,47 @@ Foam::edgeList Foam::face::edges() const } +int Foam::face::edgeDirection(const edge& e) const +{ + if (size() > 2) + { + edge found(-1,-1); + + // find start/end points - this breaks down for degenerate faces + forAll (*this, i) + { + if (operator[](i) == e.start()) + { + found.start() = i; + } + else if (operator[](i) == e.end()) + { + found.end() = i; + } + } + + label diff = found.end() - found.start(); + if (!diff || found.start() < 0 || found.end() < 0) + { + return 0; + } + + // forward direction + if (diff == 1 || diff == 1 - size()) + { + return 1; + } + // reverse direction + if (diff == -1 || diff == -1 + size()) + { + return -1; + } + } + + return 0; +} + + // Number of triangles directly known from number of vertices Foam::label Foam::face::nTriangles ( diff --git a/src/OpenFOAM/meshes/meshShapes/face/face.H b/src/OpenFOAM/meshes/meshShapes/face/face.H index f56919647a..9325801c41 100644 --- a/src/OpenFOAM/meshes/meshShapes/face/face.H +++ b/src/OpenFOAM/meshes/meshShapes/face/face.H @@ -145,7 +145,8 @@ public: // Member Functions //- Collapse face by removing duplicate point labels - void collapse(); + // return the collapsed size + label collapse(); //- Return the points corresponding to this face inline pointField points(const pointField& meshPoints) const; @@ -251,6 +252,11 @@ public: //- Return n-th face edge inline edge faceEdge(const label n) const; + //- Return the edge direction on the face + // - 0: edge not found on the face + // - +1: forward (counter-clockwise) on the face + // - -1: reverse (clockwise) on the face + int edgeDirection(const edge&) const; // Face splitting utilities diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H index aad4ee455f..9672b93147 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H @@ -81,18 +81,35 @@ public: const label c ); + //- Construct from a face, discarding excess points + inline triFace(const face&); + + //- Construct from a labelList, discarding excess points + explicit inline triFace(const labelList&); + //- Construct from Istream inline triFace(Istream&); // Member Functions + //- Collapse face by removing duplicate point labels + // return the collapsed size, set collapsed point labels to -1 + inline label collapse(); + + //- Return the edge direction on the face + // - +1: forward (counter-clockwise) on the face + // - -1: reverse (clockwise) on the face + // - 0: edge not found on the face + inline int edgeDirection(const edge&) const; + + // Properties //- Return the points corresponding to this face inline pointField points(const pointField& points) const; - //- Return triagle as a face + //- Return triangle as a face inline face triFaceFace() const; //- Return number of edges @@ -128,9 +145,14 @@ public: const intersection::direction dir = intersection::VECTOR ) const; - //- Return the tetrahedron + //- Return the triangle inline triPointRef tri(const pointField&) const; + //- compare triFaces + // - 0: different + // - +1: identical + // - -1: same face, but different orientation + static inline int compare(const triFace&, const triFace&); // Friend Operators @@ -139,7 +161,7 @@ public: }; -//- Hash specialisation +//- Hash specialisation // Simple commutative hash. template<> inline label Hash::operator()(const triFace& t) const diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H index c92e1e47e7..9574a06cbf 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFaceI.H @@ -33,14 +33,45 @@ License namespace Foam { +// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // + + +inline int triFace::compare(const triFace& a, const triFace& b) +{ + if + ( + (a[0] == b[0] && a[1] == b[1] && a[2] == b[2]) + || (a[0] == b[1] && a[1] == b[2] && a[2] == b[0]) + || (a[0] == b[2] && a[1] == b[0] && a[2] == b[1]) + ) + { + // identical + return 1; + } + else if + ( + (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) + || (a[0] == b[1] && a[1] == b[0] && a[2] == b[2]) + || (a[0] == b[0] && a[1] == b[2] && a[2] == b[1]) + ) + { + // same face, but reversed orientation + return -1; + } + else + { + return 0; + } +} + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // -//- Construct null +// Construct null inline triFace::triFace() {} -//- Construct from components +// Construct from components inline triFace::triFace ( const label a, @@ -53,6 +84,18 @@ inline triFace::triFace operator[](2) = c; } +// Construct from a face +inline triFace::triFace(const face& f) +: + FixedList(SubList