diff --git a/applications/test/vector/vectorTest.C b/applications/test/vector/vectorTest.C index f48f65d711975052096ea681bf51d9bb9ab5464b..65e995ae4ab82e70eda22246f6288730a3fe4dfd 100644 --- a/applications/test/vector/vectorTest.C +++ b/applications/test/vector/vectorTest.C @@ -27,7 +27,11 @@ int main() Info<< magSqr(d) << endl; vector d2(0.5, 0.51, -0.5); - Info<< cmptMax(d2) << " " << cmptSum(d2) << " " << cmptMag(d2) << endl; + Info<< cmptMax(d2) << " " + << cmptSum(d2) << " " + << cmptProduct(d2) << " " + << cmptMag(d2) + << endl; Info<< min(d, d2) << endl; return 0; } diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index f48237e9ed4b4ad7b8db2a5194149e014399f0d8..156b7cf54f7e2b0f783f14c60edfe8e7f7547b99 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -27,6 +27,7 @@ setFormat raw; // Surface output format. Choice of // null : suppress output +// ensight : Ensight Gold format, one field per case file // foamFile : separate points, faces and values file // dx : DX scalar or vector format // vtk : VTK ascii format diff --git a/bin/tools/pre-commit-hook b/bin/tools/pre-commit-hook index b0ca86f0202a82db0fa2b32c12ef314ae9bb202a..b06ddd50b6bf83fbc5af17ed00f4dfdcb4a186f1 100755 --- a/bin/tools/pre-commit-hook +++ b/bin/tools/pre-commit-hook @@ -49,9 +49,10 @@ # test the specified files/directories for standards conformance. # #------------------------------------------------------------------------------ +hookName="pre-commit" die() { - echo 'pre-commit hook failure' 1>&2 + echo '$hookName hook failure' 1>&2 echo '-----------------------' 1>&2 echo '' 1>&2 echo "$@" 1>&2 @@ -104,7 +105,7 @@ dieOnBadFiles() { if [ -n "$badFiles" ] then - echo 'pre-commit hook failure' 1>&2 + echo '$hookName hook failure' 1>&2 echo '-----------------------' 1>&2 echo "$@" 1>&2 echo '' 1>&2 @@ -116,22 +117,38 @@ dieOnBadFiles() } +# +# qualify 'git grep' to check cached value or from a specific commit +# +gitScope() +{ + if [ "$#" -gt 0 ] + then + echo "$1:" + else + echo "--cached -- " + fi +} + + # # check for bad strings, characters, etc # checkIllegalCode() { - echo "pre-commit: check bad strings/characters etc ..." 1>&2 + echo "$hookName: check bad strings/characters etc ..." 1>&2 reBad="(N""abla|"$'\t'")" msgBad="N""abla or <TAB>" + scope=$(gitScope $@) + badFiles=$( for f in $fileList do # parse line numbers from grep output: # <lineNr>: contents - lines=$(git grep --cached -E -hn -e "$reBad" -- "$f" | + lines=$(git grep -E -hn -e "$reBad" $scope"$f" | sed -e 's@:.*@@' | tr '\n' ' ' ) @@ -149,7 +166,9 @@ checkIllegalCode() checkCopyright() { year=$(date +%Y) - echo "pre-commit: check copyright ..." 1>&2 + echo "$hookName: check copyright ..." 1>&2 + + scope=$(gitScope $@) badFiles=$( for f in $fileList @@ -160,10 +179,10 @@ checkCopyright() # parse line numbers from grep output: # <lineNr>: contents # - lines=$(git grep --cached -F -hn -e Copyright \ + lines=$(git grep -F -hn -e Copyright \ --and -e OpenCFD \ --and --not -e "$year" \ - -- "$f" | + $scope"$f" | sed -e 's@:.*@@' | tr '\n' ' ' ) @@ -180,7 +199,9 @@ checkCopyright() # checkLineLength() { - echo "pre-commit: check line lengths ..." 1>&2 + echo "$hookName: check line lengths ..." 1>&2 + + scope=$(gitScope $@) badFiles=$( for f in $fileList @@ -190,7 +211,7 @@ checkLineLength() (*.[CH]) # parse line numbers from grep output: # <lineNr>: contents - lines=$(git grep --cached -hn -e '^.\{81,\}' -- "$f" | + lines=$(git grep -hn -e '^.\{81,\}' $scope"$f" | sed -e 's@:.*@@' | tr '\n' ' ' ) @@ -209,7 +230,9 @@ checkLineLength() # checkLineLengthNonComments() { - echo "pre-commit: check line lengths ..." 1>&2 + echo "$hookName: check line lengths ..." 1>&2 + + scope=$(gitScope $@) badFiles=$( for f in $fileList @@ -219,9 +242,9 @@ checkLineLengthNonComments() (*.[CH]) # parse line numbers from grep output: # <lineNr>: contents - lines=$(git grep --cached -hn -e '^.\{81,\}' \ + lines=$(git grep -hn -e '^.\{81,\}' \ --and --not -e "^ *//" \ - -- "$f" | + $scope"$f" | sed -e 's@:.*@@' | tr '\n' ' ' ) @@ -234,12 +257,15 @@ checkLineLengthNonComments() dieOnBadFiles "Limit code to 80 columns before pushing" } + # # limit line length to 80-columns, except #directive lines # checkLineLengthNonDirective() { - echo "pre-commit: check line lengths ..." 1>&2 + echo "$hookName: check line lengths ..." 1>&2 + + scope=$(gitScope $@) badFiles=$( for f in $fileList @@ -249,9 +275,9 @@ checkLineLengthNonDirective() (*.[CH]) # parse line numbers from grep output: # <lineNr>: contents - lines=$(git grep --cached -hn -e '^.\{81,\}' \ + lines=$(git grep -hn -e '^.\{81,\}' \ --and --not -e "^ *#" \ - -- "$f" | + $scope"$f" | sed -e 's@:.*@@' | tr '\n' ' ' ) @@ -265,9 +291,9 @@ checkLineLengthNonDirective() } - -# do all checks -# ~~~~~~~~~~~~~ +#------------------------------------------------------------------------------ +# Main code : do all checks +# # builtin whitespace check to avoid trailing space, including CR-LF endings bad=$(git diff-index --cached --check $against --) || die "$bad" diff --git a/bin/tools/pre-receive-hook b/bin/tools/pre-receive-hook new file mode 100755 index 0000000000000000000000000000000000000000..f289b99be702a3b94179713f069751ed09a2bd27 --- /dev/null +++ b/bin/tools/pre-receive-hook @@ -0,0 +1,303 @@ +#!/bin/bash +#---------------------------------*- sh -*------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2010-2010 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 <http://www.gnu.org/licenses/>. +# +# Script +# pre-receive-hook +# +# Description +# pre-receive hook for git. +# Copy or link this file as ".git/hooks/pre-receive" +# +# Eg, +# ( +# cd $WM_PROJECT_DIR/.git/hooks && +# ln -sf ../../bin/tools/pre-receive-hook pre-receive +# ) +# +# Hook receives: <old-sha1> <new-sha1> <ref-name> +# +# Checks for +# - illegal code, e.g. <TAB> +# - copyright is current, e.g. if present, contains XXX-<current-year> +# - columns greater than 80 for *.[CH] files +# +#------------------------------------------------------------------------------ +hookName="pre-receive" +die() +{ + echo '$hookName hook failure' 1>&2 + echo '-----------------------' 1>&2 + echo '' 1>&2 + echo "$@" 1>&2 + echo '' 1>&2 + exit 1 +} + +#----------------------------------------------------------------------------- + +unset fileList +unset badFiles +# join list of files with this amount of space +Indent=" " + +# +# report bad files and die if there are any +# +dieOnBadFiles() +{ + if [ -n "$badFiles" ] + then + echo '$hookName hook failure' 1>&2 + echo '-----------------------' 1>&2 + echo "$@" 1>&2 + echo '' 1>&2 + echo "File(s):" 1>&2 + echo "$badFiles" 1>&2 + echo '' 1>&2 + exit 1 + fi +} + + +# +# qualify 'git grep' to check cached value or from a specific commit +# +gitScope() +{ + if [ "$#" -gt 0 ] + then + echo "$1:" + else + echo "--cached -- " + fi +} + + +# +# check for bad strings, characters, etc +# +checkIllegalCode() +{ + echo "$hookName: check bad strings/characters etc ..." 1>&2 + + reBad="(N""abla|"$'\t'"|"$'\r\n'")" + msgBad="N""abla, <TAB> or DOS-line-endings" + + scope=$(gitScope $@) + + badFiles=$( + for f in $fileList + do + # parse line numbers from grep output: + # <lineNr>: contents + lines=$(git grep -E -hn -e "$reBad" $scope"$f" | + sed -e 's@:.*@@' | + tr '\n' ' ' + ) + [ -n "$lines" ] && echo "$Indent$f -- lines: $lines" + done + ) + + dieOnBadFiles "Remove/correct bad '$msgBad' references" +} + + +# +# check that OpenCFD copyright is current +# +checkCopyright() +{ + year=$(date +%Y) + echo "$hookName: check copyright ..." 1>&2 + + scope=$(gitScope $@) + + badFiles=$( + for f in $fileList + do + # NB: need to have OpenCFD on a separate line to prevent + # this check being caught by itself! + # + # parse line numbers from grep output: + # <lineNr>: contents + # + lines=$(git grep -F -hn -e Copyright \ + --and -e OpenCFD \ + --and --not -e "$year" \ + $scope"$f" | + sed -e 's@:.*@@' | + tr '\n' ' ' + ) + [ -n "$lines" ] && echo "$Indent$f -- lines: $lines" + done + ) + + dieOnBadFiles "Update copyright year, e.g. XXXX-$year" +} + + +# +# limit line length to 80-columns +# +checkLineLength() +{ + echo "$hookName: check line lengths ..." 1>&2 + + scope=$(gitScope $@) + + badFiles=$( + for f in $fileList + do + # limit to *.[CH] files + case "$f" in + (*.[CH]) + # parse line numbers from grep output: + # <lineNr>: contents + lines=$(git grep -hn -e '^.\{81,\}' $scope"$f" | + sed -e 's@:.*@@' | + tr '\n' ' ' + ) + [ -n "$lines" ] && echo "$Indent$f -- lines: $lines" + ;; + esac + done + ) + + dieOnBadFiles "Limit code to 80 columns before pushing" +} + + +# +# limit line length to 80-columns, except C++ comment lines +# +checkLineLengthNonComments() +{ + echo "$hookName: check line lengths ..." 1>&2 + + scope=$(gitScope $@) + + badFiles=$( + for f in $fileList + do + # limit to *.[CH] files + case "$f" in + (*.[CH]) + # parse line numbers from grep output: + # <lineNr>: contents + lines=$(git grep -hn -e '^.\{81,\}' \ + --and --not -e "^ *//" \ + $scope"$f" | + sed -e 's@:.*@@' | + tr '\n' ' ' + ) + [ -n "$lines" ] && echo "$Indent$f -- lines: $lines" + ;; + esac + done + ) + + dieOnBadFiles "Limit code to 80 columns before pushing" +} + + +# +# limit line length to 80-columns, except #directive lines +# +checkLineLengthNonDirective() +{ + echo "$hookName: check line lengths ..." 1>&2 + + scope=$(gitScope $@) + + badFiles=$( + for f in $fileList + do + # limit to *.[CH] files + case "$f" in + (*.[CH]) + # parse line numbers from grep output: + # <lineNr>: contents + lines=$(git grep -hn -e '^.\{81,\}' \ + --and --not -e "^ *#" \ + $scope"$f" | + sed -e 's@:.*@@' | + tr '\n' ' ' + ) + [ -n "$lines" ] && echo "$Indent$f -- lines: $lines" + ;; + esac + done + ) + + dieOnBadFiles "Limit code to 80 columns before pushing" +} + + +#------------------------------------------------------------------------------ +# Main code : do all checks +# + +while read oldSHA1 newSHA1 refName +do + unset fileList rawFileList + + if [ "$newSHA1" = 0 ] + then + # ref to be deleted + continue + elif [ "$oldSHA1" = 0 ] + then + # ref to be created + rawFileList=$(git diff-tree --root $newSHA1) + else + # normal changes + rawFileList=$(git diff --name-only $oldSHA1..$newSHA1) + fi + + # + # no files changed: can skip all the checks + # + [ -n "$rawFileList" ] || continue + + fileList=$( + for f in $rawFileList + do + git cat-file -e $newSHA1:$f > /dev/null 2>&1 && echo "$f" + done + ) + + # check for illegal code, e.g. <TAB>, etc + checkIllegalCode $newSHA1 + + # ensure OpenCFD copyright contains correct year + checkCopyright $newSHA1 + + # ensure code conforms to 80 columns max + checkLineLengthNonDirective $newSHA1 + +done + + +exit 0 +#------------------------------------------------------------------------------ diff --git a/etc/apps/scotch/bashrc b/etc/apps/scotch/bashrc new file mode 100644 index 0000000000000000000000000000000000000000..5058df0ed1a2187e1492fc24f153e94fbd2b463b --- /dev/null +++ b/etc/apps/scotch/bashrc @@ -0,0 +1,39 @@ +#----------------------------------*-sh-*-------------------------------------- +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | Copyright (C) 2010-2010 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 <http://www.gnu.org/licenses/>. +# +# File +# scotch/bashrc +# +# Description +# Setup file for scotch include/libraries. +# Sourced during wmake process only. +# +# Note +# A csh version is not needed, since the values here are only sourced +# during the wmake process +#------------------------------------------------------------------------------ + +export SCOTCH_VERSION=scotch_5.1.10b +export SCOTCH_ARCH_PATH=$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/$SCOTCH_VERSION + +# ----------------------------------------------------------------------------- diff --git a/etc/cshrc b/etc/cshrc index 807d38f0425a9a6d1d8814f49a57938d6c0bfe4b..25628ab4072c61e51d9c6e731619876986ed9f09 100644 --- a/etc/cshrc +++ b/etc/cshrc @@ -69,14 +69,10 @@ setenv WM_THIRD_PARTY_DIR $WM_PROJECT_INST_DIR/ThirdParty-$WM_PROJECT_VERSION # Source files, possibly with some verbosity -alias _foamSource 'if ($?FOAM_VERBOSE && $?prompt) echo "Sourcing: \!*"; source \!*' +alias _foamSource 'if ($?FOAM_VERBOSE && $?prompt) echo "Sourcing: \!*"; if (\!* != "") source \!*' # Add in preset user or site preferences: -set foamPrefs=`$WM_PROJECT_DIR/bin/foamEtcFile prefs.csh` -if ( $status == 0 ) then - _foamSource $foamPrefs -endif -unset foamPrefs +_foamSource `$WM_PROJECT_DIR/bin/foamEtcFile prefs.csh` # Evaluate command-line parameters while ( $#argv > 0 ) @@ -255,17 +251,8 @@ _foamSource $WM_PROJECT_DIR/etc/aliases.csh # Source user setup files for optional packages # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -set paraview3=`$WM_PROJECT_DIR/bin/foamEtcFile apps/paraview3/cshrc` -if ( $status == 0 ) then - _foamSource $paraview3 -endif -unset paraview3 - -set ensight=`$WM_PROJECT_DIR/bin/foamEtcFile apps/ensight/cshrc` -if ( $status == 0 ) then - _foamSource $ensight -endif -unset ensight +_foamSource `$WM_PROJECT_DIR/bin/foamEtcFile apps/paraview3/cshrc` +_foamSource `$WM_PROJECT_DIR/bin/foamEtcFile apps/ensight/cshrc` # Clean environment paths again. Only remove duplicates diff --git a/src/OpenFOAM/containers/Lists/UList/UList.C b/src/OpenFOAM/containers/Lists/UList/UList.C index 7f3e63d421a01ff9056f43d48e537bc9c8f02bc2..25334db0c5e5fef5a6f0af32e60e5b0ae32e37b9 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.C +++ b/src/OpenFOAM/containers/Lists/UList/UList.C @@ -145,6 +145,13 @@ void Foam::stableSort(UList<T>& a, const Cmp& cmp) } +template<class T> +void Foam::shuffle(UList<T>& a) +{ + std::random_shuffle(a.begin(), a.end()); +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template<class T> diff --git a/src/OpenFOAM/containers/Lists/UList/UList.H b/src/OpenFOAM/containers/Lists/UList/UList.H index d0cb05fc1727747c5fbf850e1657c56964830302..4a4dd598d911251150ce08389f51733dd5a2cd7d 100644 --- a/src/OpenFOAM/containers/Lists/UList/UList.H +++ b/src/OpenFOAM/containers/Lists/UList/UList.H @@ -344,6 +344,9 @@ void stableSort(UList<T>&); template<class T, class Cmp> void stableSort(UList<T>&, const Cmp&); +template<class T> +void shuffle(UList<T>&); + // Reverse the first n elements of the list template<class T> inline void reverse(UList<T>&, const label n); diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.H b/src/OpenFOAM/meshes/boundBox/boundBox.H index dec6ae658df5485ca20a533fbb2ce675abdb3eaa..2f510bc9e75f368e34e03c3a7b55f846a5799e2b 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.H +++ b/src/OpenFOAM/meshes/boundBox/boundBox.H @@ -152,6 +152,12 @@ public: return ::Foam::mag(max_ - min_); } + //- The volume of the bound box + scalar volume() const + { + return cmptProduct(span()); + } + //- Smallest length/height/width dimension scalar minDim() const { diff --git a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H index 1eff60d99be9a9753357ae041916e262b11a5726..d655990e21d63f893762fc481e6dc6398109f49d 100644 --- a/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H +++ b/src/OpenFOAM/primitives/VectorSpace/VectorSpaceI.H @@ -406,6 +406,17 @@ inline Cmpt cmptAv return cmptSum(vs)/nCmpt; } +template<class Form, class Cmpt, int nCmpt> +inline Cmpt cmptProduct +( + const VectorSpace<Form, Cmpt, nCmpt>& vs +) +{ + Cmpt product = vs.v_[0]; + VectorSpaceOps<nCmpt,1>::SeqOp(product, vs, multiplyEqOp<Cmpt>()); + return product; +} + template<class Form, class Cmpt, int nCmpt> inline Form cmptMag diff --git a/src/OpenFOAM/primitives/random/Random/random.3 b/src/OpenFOAM/primitives/random/Random/random.3 deleted file mode 100644 index 8a0af2ca4f41ac30c56726ad5d12c89ad5079a8c..0000000000000000000000000000000000000000 --- a/src/OpenFOAM/primitives/random/Random/random.3 +++ /dev/null @@ -1,168 +0,0 @@ -.\" $NetBSD: random.3,v 1.4 1995/12/28 08:52:42 thorpej Exp $ -.\" -.\" Copyright (c) 1983, 1991 The Regents of the University of California. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" from: @(#)random.3 6.5 (Berkeley) 4/19/91 -.\" -.Dd April 19, 1991 -.Dt RANDOM 3 -.Os BSD 4.2 -.Sh NAME -.Nm random , -.Nm srandom , -.Nm initstate , -.Nm setstate -.Nd better random number generator; routines for changing generators -.Sh SYNOPSIS -.Fd #include <stdlib.h> -.Ft long -.Fn random void -.Ft void -.Fn srandom "unsigned seed" -.Ft char * -.Fn initstate "unsigned seed" "char *state" "int n" -.Ft char * -.Fn setstate "char *state" -.Sh DESCRIPTION -The -.Fn random -function -uses a non-linear additive feedback random number generator employing a -default table of size 31 long integers to return successive pseudo-random -numbers in the range from 0 to -.if t 2\u\s731\s10\d\(mi1. -.if n (2**31)\(mi1. -The period of this random number generator is very large, approximately -.if t 16\(mu(2\u\s731\s10\d\(mi1). -.if n 16*((2**31)\(mi1). -.Pp -The -.Fn random Ns / Fn srandom -have (almost) the same calling sequence and initialization properties as -.Xr rand 3 Ns / Xr srand 3 . -The difference is that -.Xr rand -produces a much less random sequence \(em in fact, the low dozen bits -generated by rand go through a cyclic pattern. All the bits generated by -.Fn random -are usable. For example, -.Sq Li random()&01 -will produce a random binary -value. -.Pp -Unlike -.Xr srand , -.Fn srandom -does not return the old seed; the reason for this is that the amount of -state information used is much more than a single word. (Two other -routines are provided to deal with restarting/changing random -number generators). Like -.Xr rand 3 , -however, -.Fn random -will by default produce a sequence of numbers that can be duplicated -by calling -.Fn srandom -with -.Ql 1 -as the seed. -.Pp -The -.Fn initstate -routine allows a state array, passed in as an argument, to be initialized -for future use. The size of the state array (in bytes) is used by -.Fn initstate -to decide how sophisticated a random number generator it should use \(em the -more state, the better the random numbers will be. -(Current "optimal" values for the amount of state information are -8, 32, 64, 128, and 256 bytes; other amounts will be rounded down to -the nearest known amount. Using less than 8 bytes will cause an error.) -The seed for the initialization (which specifies a starting point for -the random number sequence, and provides for restarting at the same -point) is also an argument. -The -.Fn initstate -function -returns a pointer to the previous state information array. -.Pp -Once a state has been initialized, the -.Fn setstate -routine provides for rapid switching between states. -The -.Fn setstate -function -returns a pointer to the previous state array; its -argument state array is used for further random number generation -until the next call to -.Fn initstate -or -.Fn setstate . -.Pp -Once a state array has been initialized, it may be restarted at a -different point either by calling -.Fn initstate -(with the desired seed, the state array, and its size) or by calling -both -.Fn setstate -(with the state array) and -.Fn srandom -(with the desired seed). -The advantage of calling both -.Fn setstate -and -.Fn srandom -is that the size of the state array does not have to be remembered after -it is initialized. -.Pp -With 256 bytes of state information, the period of the random number -generator is greater than -.if t 2\u\s769\s10\d, -.if n 2**69 -which should be sufficient for most purposes. -.Sh AUTHOR -Earl T. Cohen -.Sh DIAGNOSTICS -If -.Fn initstate -is called with less than 8 bytes of state information, or if -.Fn setstate -detects that the state information has been garbled, error -messages are printed on the standard error output. -.Sh SEE ALSO -.Xr rand 3 -.Sh HISTORY -These -functions appeared in -.Bx 4.2 . -.Sh BUGS -About 2/3 the speed of -.Xr rand 3 . diff --git a/src/OpenFOAM/primitives/random/Random/random.c b/src/OpenFOAM/primitives/random/Random/random.c deleted file mode 100644 index a2d6ac021a249e2fafdd6791ada6c4ade32edc64..0000000000000000000000000000000000000000 --- a/src/OpenFOAM/primitives/random/Random/random.c +++ /dev/null @@ -1,369 +0,0 @@ -/* $NetBSD: random.c,v 1.4 1995/12/28 08:52:43 thorpej Exp $ */ - -/* - * Copyright (c) 1983 Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char *sccsid = "from: @(#)random.c 5.9 (Berkeley) 2/23/91"; -#else -static char *rcsid = "$NetBSD: random.c,v 1.4 1995/12/28 08:52:43 thorpej Exp $"; -#endif -#endif /* LIBC_SCCS and not lint */ - -#include <stdio.h> -#include <stdlib.h> - -/* - * random.c: - * - * An improved random number generation package. In addition to the standard - * rand()/srand() like interface, this package also has a special state info - * interface. The initstate() routine is called with a seed, an array of - * bytes, and a count of how many bytes are being passed in; this array is - * then initialized to contain information for random number generation with - * that much state information. Good sizes for the amount of state - * information are 32, 64, 128, and 256 bytes. The state can be switched by - * calling the setstate() routine with the same array as was initiallized - * with initstate(). By default, the package runs with 128 bytes of state - * information and generates far better random numbers than a linear - * congruential generator. If the amount of state information is less than - * 32 bytes, a simple linear congruential R.N.G. is used. - * - * Internally, the state information is treated as an array of longs; the - * zeroeth element of the array is the type of R.N.G. being used (small - * integer); the remainder of the array is the state information for the - * R.N.G. Thus, 32 bytes of state information will give 7 longs worth of - * state information, which will allow a degree seven polynomial. (Note: - * the zeroeth word of state information also has some other information - * stored in it -- see setstate() for details). - * - * The random number generation technique is a linear feedback shift register - * approach, employing trinomials (since there are fewer terms to sum up that - * way). In this approach, the least significant bit of all the numbers in - * the state table will act as a linear feedback shift register, and will - * have period 2^deg - 1 (where deg is the degree of the polynomial being - * used, assuming that the polynomial is irreducible and primitive). The - * higher order bits will have longer periods, since their values are also - * influenced by pseudo-random carries out of the lower bits. The total - * period of the generator is approximately deg*(2**deg - 1); thus doubling - * the amount of state information has a vast influence on the period of the - * generator. Note: the deg*(2**deg - 1) is an approximation only good for - * large deg, when the period of the shift register is the dominant factor. - * With deg equal to seven, the period is actually much longer than the - * 7*(2**7 - 1) predicted by this formula. - */ - -/* - * For each of the currently supported random number generators, we have a - * break value on the amount of state information (you need at least this - * many bytes of state info to support this random number generator), a degree - * for the polynomial (actually a trinomial) that the R.N.G. is based on, and - * the separation between the two lower order coefficients of the trinomial. - */ -#define TYPE_0 0 /* linear congruential */ -#define BREAK_0 8 -#define DEG_0 0 -#define SEP_0 0 - -#define TYPE_1 1 /* x**7 + x**3 + 1 */ -#define BREAK_1 32 -#define DEG_1 7 -#define SEP_1 3 - -#define TYPE_2 2 /* x**15 + x + 1 */ -#define BREAK_2 64 -#define DEG_2 15 -#define SEP_2 1 - -#define TYPE_3 3 /* x**31 + x**3 + 1 */ -#define BREAK_3 128 -#define DEG_3 31 -#define SEP_3 3 - -#define TYPE_4 4 /* x**63 + x + 1 */ -#define BREAK_4 256 -#define DEG_4 63 -#define SEP_4 1 - -/* - * Array versions of the above information to make code run faster -- - * relies on fact that TYPE_i == i. - */ -#define MAX_TYPES 5 /* max number of types above */ - -static int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }; -static int seps [MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }; - -/* - * Initially, everything is set up as if from: - * - * initstate(1, &randtbl, 128); - * - * Note that this initialization takes advantage of the fact that srandom() - * advances the front and rear pointers 10*rand_deg times, and hence the - * rear pointer which starts at 0 will also end up at zero; thus the zeroeth - * element of the state information, which contains info about the current - * position of the rear pointer is just - * - * MAX_TYPES * (rptr - state) + TYPE_3 == TYPE_3. - */ - -static long randtbl[DEG_3 + 1] = { - TYPE_3, - 0x9a319039, 0x32d9c024, 0x9b663182, 0x5da1f342, 0xde3b81e0, 0xdf0a6fb5, - 0xf103bc02, 0x48f340fb, 0x7449e56b, 0xbeb1dbb0, 0xab5c5918, 0x946554fd, - 0x8c2e680f, 0xeb3d799f, 0xb11ee0b7, 0x2d436b86, 0xda672e2a, 0x1588ca88, - 0xe369735d, 0x904f35f7, 0xd7158fd6, 0x6fa6f051, 0x616e6b96, 0xac94efdc, - 0x36413f93, 0xc622c298, 0xf5a42ab8, 0x8a88d77b, 0xf5ad9d0e, 0x8999220b, - 0x27fb47b9, -}; - -/* - * fptr and rptr are two pointers into the state info, a front and a rear - * pointer. These two pointers are always rand_sep places aparts, as they - * cycle cyclically through the state information. (Yes, this does mean we - * could get away with just one pointer, but the code for random() is more - * efficient this way). The pointers are left positioned as they would be - * from the call - * - * initstate(1, randtbl, 128); - * - * (The position of the rear pointer, rptr, is really 0 (as explained above - * in the initialization of randtbl) because the state table pointer is set - * to point to randtbl[1] (as explained below). - */ -static long *fptr = &randtbl[SEP_3 + 1]; -static long *rptr = &randtbl[1]; - -/* - * The following things are the pointer to the state information table, the - * type of the current generator, the degree of the current polynomial being - * used, and the separation between the two pointers. Note that for efficiency - * of random(), we remember the first location of the state information, not - * the zeroeth. Hence it is valid to access state[-1], which is used to - * store the type of the R.N.G. Also, we remember the last location, since - * this is more efficient than indexing every time to find the address of - * the last element to see if the front and rear pointers have wrapped. - */ -static long *state = &randtbl[1]; -static int rand_type = TYPE_3; -static int rand_deg = DEG_3; -static int rand_sep = SEP_3; -static long *end_ptr = &randtbl[DEG_3 + 1]; - -/* - * srandom: - * - * Initialize the random number generator based on the given seed. If the - * type is the trivial no-state-information type, just remember the seed. - * Otherwise, initializes state[] based on the given "seed" via a linear - * congruential generator. Then, the pointers are set to known locations - * that are exactly rand_sep places apart. Lastly, it cycles the state - * information a given number of times to get rid of any initial dependencies - * introduced by the L.C.R.N.G. Note that the initialization of randtbl[] - * for default usage relies on values produced by this routine. - */ -void -srandom(x) - u_int x; -{ - register int i, j; - - if (rand_type == TYPE_0) - state[0] = x; - else { - j = 1; - state[0] = x; - for (i = 1; i < rand_deg; i++) - state[i] = 1103515245 * state[i - 1] + 12345; - fptr = &state[rand_sep]; - rptr = &state[0]; - for (i = 0; i < 10 * rand_deg; i++) - (void)random(); - } -} - -/* - * initstate: - * - * Initialize the state information in the given array of n bytes for future - * random number generation. Based on the number of bytes we are given, and - * the break values for the different R.N.G.'s, we choose the best (largest) - * one we can and set things up for it. srandom() is then called to - * initialize the state information. - * - * Note that on return from srandom(), we set state[-1] to be the type - * multiplexed with the current value of the rear pointer; this is so - * successive calls to initstate() won't lose this information and will be - * able to restart with setstate(). - * - * Note: the first thing we do is save the current state, if any, just like - * setstate() so that it doesn't matter when initstate is called. - * - * Returns a pointer to the old state. - */ -char * -initstate(seed, arg_state, n) - u_int seed; /* seed for R.N.G. */ - char *arg_state; /* pointer to state array */ - int n; /* # bytes of state info */ -{ - register char *ostate = (char *)(&state[-1]); - - if (rand_type == TYPE_0) - state[-1] = rand_type; - else - state[-1] = MAX_TYPES * (rptr - state) + rand_type; - if (n < BREAK_0) { - (void)fprintf(stderr, - "random: not enough state (%d bytes); ignored.\n", n); - return 0; - } - if (n < BREAK_1) { - rand_type = TYPE_0; - rand_deg = DEG_0; - rand_sep = SEP_0; - } else if (n < BREAK_2) { - rand_type = TYPE_1; - rand_deg = DEG_1; - rand_sep = SEP_1; - } else if (n < BREAK_3) { - rand_type = TYPE_2; - rand_deg = DEG_2; - rand_sep = SEP_2; - } else if (n < BREAK_4) { - rand_type = TYPE_3; - rand_deg = DEG_3; - rand_sep = SEP_3; - } else { - rand_type = TYPE_4; - rand_deg = DEG_4; - rand_sep = SEP_4; - } - state = &(((long *)arg_state)[1]); /* first location */ - end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */ - srandom(seed); - if (rand_type == TYPE_0) - state[-1] = rand_type; - else - state[-1] = MAX_TYPES*(rptr - state) + rand_type; - return(ostate); -} - -/* - * setstate: - * - * Restore the state from the given state array. - * - * Note: it is important that we also remember the locations of the pointers - * in the current state information, and restore the locations of the pointers - * from the old state information. This is done by multiplexing the pointer - * location into the zeroeth word of the state information. - * - * Note that due to the order in which things are done, it is OK to call - * setstate() with the same state as the current state. - * - * Returns a pointer to the old state information. - */ -char * -setstate(arg_state) - char *arg_state; -{ - register long *new_state = (long *)arg_state; - register int type = new_state[0] % MAX_TYPES; - register int rear = new_state[0] / MAX_TYPES; - char *ostate = (char *)(&state[-1]); - - if (rand_type == TYPE_0) - state[-1] = rand_type; - else - state[-1] = MAX_TYPES * (rptr - state) + rand_type; - switch(type) { - case TYPE_0: - case TYPE_1: - case TYPE_2: - case TYPE_3: - case TYPE_4: - rand_type = type; - rand_deg = degrees[type]; - rand_sep = seps[type]; - break; - default: - (void)fprintf(stderr, - "random: state info corrupted; not changed.\n"); - } - state = &new_state[1]; - if (rand_type != TYPE_0) { - rptr = &state[rear]; - fptr = &state[(rear + rand_sep) % rand_deg]; - } - end_ptr = &state[rand_deg]; /* set end_ptr too */ - return(ostate); -} - -/* - * random: - * - * If we are using the trivial TYPE_0 R.N.G., just do the old linear - * congruential bit. Otherwise, we do our fancy trinomial stuff, which is - * the same in all the other cases due to all the global variables that have - * been set up. The basic operation is to add the number at the rear pointer - * into the one at the front pointer. Then both pointers are advanced to - * the next location cyclically in the table. The value returned is the sum - * generated, reduced to 31 bits by throwing away the "least random" low bit. - * - * Note: the code takes advantage of the fact that both the front and - * rear pointers can't wrap on the same call by not testing the rear - * pointer if the front one has wrapped. - * - * Returns a 31-bit random number. - */ -long -random() -{ - long i; - - if (rand_type == TYPE_0) - i = state[0] = (state[0] * 1103515245 + 12345) & 0x7fffffff; - else { - *fptr += *rptr; - i = (*fptr >> 1) & 0x7fffffff; /* chucking least random bit */ - if (++fptr >= end_ptr) { - fptr = state; - ++rptr; - } else if (++rptr >= end_ptr) - rptr = state; - } - return(i); -} diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index 13d7e33f9c76e349d60c0c1c0f5f515dc17501a6..52b173cc6c5706c42ac4e7bc80fc2efc7a1eaca6 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -56,8 +56,7 @@ Foam::fileName::Type Foam::fileName::type() const bool Foam::fileName::isAbsolute() const { - fileName fName(*this); - return fName.size() && fName.operator[](0) == '/'; + return !empty() && operator[](0) == '/'; } diff --git a/src/parallel/decompose/Allwmake b/src/parallel/decompose/Allwmake index 3ca612fb5b57fe9ae8524939cca36b9d30f85968..22515e65d2f57824c54f2b7941816b0a60a740ac 100755 --- a/src/parallel/decompose/Allwmake +++ b/src/parallel/decompose/Allwmake @@ -1,5 +1,17 @@ #!/bin/sh cd ${0%/*} || exit 1 # run from this directory + +# get SCOTCH_VERSION, SCOTCH_ARCH_PATH +settings=`$WM_PROJECT_DIR/bin/foamEtcFile apps/scotch/bashrc` +if [ -f "$settings" ] +then + . $settings + echo "using SCOTCH_ARCH_PATH=$SCOTCH_ARCH_PATH" +else + echo + echo "Error: no apps/scotch/bashrc settings" + echo +fi set -x wmakeLnInclude decompositionMethods @@ -9,7 +21,10 @@ wmake libso metisDecomp if [ -d "$FOAM_MPI_LIBBIN" ] then - ( WM_OPTIONS=${WM_OPTIONS}$WM_MPLIB; wmake libso ptscotchDecomp ) +( + WM_OPTIONS=${WM_OPTIONS}$WM_MPLIB + wmake libso ptscotchDecomp +) fi wmake libso decompositionMethods diff --git a/src/parallel/decompose/ptscotchDecomp/Make/options b/src/parallel/decompose/ptscotchDecomp/Make/options index 3841a348190dc6ea623a04d35d1eb7cbdce7d990..17e6ea5ced3c94e62916539cec9bf1906b7c9be5 100644 --- a/src/parallel/decompose/ptscotchDecomp/Make/options +++ b/src/parallel/decompose/ptscotchDecomp/Make/options @@ -3,7 +3,7 @@ sinclude $(RULES)/mplib$(WM_MPLIB) EXE_INC = \ $(PFLAGS) $(PINC) \ - -I$(WM_THIRD_PARTY_DIR)/scotch_5.1.10b/include \ + -I$(SCOTCH_ARCH_PATH)/include \ -I/usr/include/scotch \ -I../decompositionMethods/lnInclude diff --git a/src/parallel/decompose/scotchDecomp/Make/options b/src/parallel/decompose/scotchDecomp/Make/options index 287aad462b5cd51050bec419798a58700968f95b..c832cc0b7cdd119853edb938ff9bbf49d52d69d5 100644 --- a/src/parallel/decompose/scotchDecomp/Make/options +++ b/src/parallel/decompose/scotchDecomp/Make/options @@ -1,5 +1,5 @@ EXE_INC = \ - -I$(WM_THIRD_PARTY_DIR)/scotch_5.1.10b/include \ + -I$(SCOTCH_ARCH_PATH)/include \ -I/usr/include/scotch \ -I../decompositionMethods/lnInclude diff --git a/src/postProcessing/functionObjects/field/Make/files b/src/postProcessing/functionObjects/field/Make/files index 003ef04ef8fc0418cbe535214f1baf4db121461d..e869e24b1c07c5a90c53e90f6862d5a51796272d 100644 --- a/src/postProcessing/functionObjects/field/Make/files +++ b/src/postProcessing/functionObjects/field/Make/files @@ -20,4 +20,7 @@ streamLine/streamLineParticle.C streamLine/streamLineParticleCloud.C streamLine/streamLineFunctionObject.C +surfaceInterpolateFields/surfaceInterpolateFields.C +surfaceInterpolateFields/surfaceInterpolateFieldsFunctionObject.C + LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects diff --git a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C index 1f6cc537e11d26110b3759868c6ee130a5e96938..e3755efbb8bc319dd712b21fff771411c30cf24f 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/cellSource/cellSource.C @@ -198,11 +198,10 @@ void Foam::fieldValues::cellSource::write() if (active_) { + scalar totalVolume = gSum(filterField(mesh().V())); if (Pstream::master()) { - outputFilePtr_() - << obr_.time().value() << tab - << sum(filterField(mesh().V())); + outputFilePtr_() << obr_.time().value() << tab << totalVolume; } forAll(fields_, i) diff --git a/src/postProcessing/functionObjects/field/fieldValues/controlDict b/src/postProcessing/functionObjects/field/fieldValues/controlDict index 7605d4afc11a477335bc5d2ed5dad1d6bf8b4669..c7619975f7b36ca09be852a02478553575e5cd16 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/controlDict +++ b/src/postProcessing/functionObjects/field/fieldValues/controlDict @@ -61,11 +61,25 @@ functions // Output field values as well valueOutput true; - // Patch or faceZone to sample + // Type of source: patch/faceZone/sampledSurface source patch; + + // if patch or faceZone: name of patch or faceZone sourceName movingWall; -// source faceZone; -// sourceName f0; + + //// if sampledSurface: dictionary with a sampledSurface + //// Note: the sampledSurfaces will have cell-values, i.e. + //// non-interpolated. Also will not sample surface fields. + //sampledSurfaceDict + //{ + // type cuttingPlane; + // planeType pointAndNormal; + // pointAndNormalDict + // { + // basePoint (0 0.099 0); + // normalVector (0 1 0); + // } + //} // Operation: areaAverage/sum/weightedAverage ... operation areaAverage; @@ -73,7 +87,7 @@ functions fields ( p - phi + phi // surface fields not supported for sampledSurface U ); } diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C index f30d80f7160197fb5abe96d3460f6a8e86915e8b..472f725dc4275c011a627f813db216f5b9f6de4a 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.C @@ -28,21 +28,20 @@ License #include "cyclicPolyPatch.H" #include "emptyPolyPatch.H" #include "coupledPolyPatch.H" -#include "surfaceFields.H" -#include "volFields.H" +#include "sampledSurface.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // defineTypeNameAndDebug(Foam::fieldValues::faceSource, 0); template<> -const char* Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 2>:: +const char* Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 3>:: names[] = { - "faceZone", "patch" + "faceZone", "patch", "sampledSurface" }; -const Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 2> +const Foam::NamedEnum<Foam::fieldValues::faceSource::sourceType, 3> Foam::fieldValues::faceSource::sourceTypeNames_; @@ -188,6 +187,19 @@ void Foam::fieldValues::faceSource::setPatchFaces() } +void Foam::fieldValues::faceSource::sampledSurfaceFaces(const dictionary& dict) +{ + surfacePtr_ = sampledSurface::New + ( + name_, + mesh(), + dict.subDict("sampledSurfaceDict") + ); + surfacePtr_().update(); + nFaces_ = returnReduce(surfacePtr_().faces().size(), sumOp<label>()); +} + + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void Foam::fieldValues::faceSource::initialise(const dictionary& dict) @@ -204,20 +216,37 @@ void Foam::fieldValues::faceSource::initialise(const dictionary& dict) setPatchFaces(); break; } + case stSampledSurface: + { + sampledSurfaceFaces(dict); + break; + } default: { FatalErrorIn("faceSource::initialise()") << type() << " " << name_ << ": " << sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl << " Unknown source type. Valid source types are:" - << sourceTypeNames_ << nl << exit(FatalError); + << sourceTypeNames_.sortedToc() << nl << exit(FatalError); } } + scalar totalArea; + + if (surfacePtr_.valid()) + { + surfacePtr_().update(); + totalArea = gSum(surfacePtr_().magSf()); + } + else + { + totalArea = gSum(filterField(mesh().magSf(), false)); + } + Info<< type() << " " << name_ << ":" << nl << " total faces = " << nFaces_ << nl - << " total area = " << gSum(filterField(mesh().magSf(), false)) + << " total area = " << totalArea << nl; if (operation_ == opWeightedAverage) @@ -280,11 +309,11 @@ Foam::fieldValues::faceSource::faceSource fieldValue(name, obr, dict, loadFromFiles), source_(sourceTypeNames_.read(dict.lookup("source"))), operation_(operationTypeNames_.read(dict.lookup("operation"))), + weightFieldName_("undefinedWeightedFieldName"), nFaces_(0), faceId_(), facePatchId_(), - faceSign_(), - weightFieldName_("undefinedWeightedFieldName") + faceSign_() { read(dict); } @@ -315,11 +344,22 @@ void Foam::fieldValues::faceSource::write() if (active_) { + scalar totalArea; + + if (surfacePtr_.valid()) + { + surfacePtr_().update(); + totalArea = gSum(surfacePtr_().magSf()); + } + else + { + totalArea = gSum(filterField(mesh().magSf(), false)); + } + + if (Pstream::master()) { - outputFilePtr_() - << obr_.time().value() << tab - << sum(filterField(mesh().magSf(), false)); + outputFilePtr_() << obr_.time().value() << tab << totalArea; } forAll(fields_, i) diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H index 3789aaadb45cd55842fccdb41ce254648d2323ff..bae5a21ca633b60c0363d387adb4b8d00d34f6d3 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSource.H @@ -36,8 +36,9 @@ Description outputControl outputTime; log true; // log to screen? valueOutput true; // Write values at run-time output times? - source faceZone; // Type of face source: faceZone, patch - sourceName f0; + source faceZone; // Type of face source: + // faceZone,patch,sampledSurface + sourceName f0; // faceZone name, see below operation sum; fields ( @@ -47,7 +48,13 @@ Description ); } - where operation is one of: + source: + - faceZone : requires a 'sourceName' entry to specify the faceZone + - patch : "" patch + - sampledSurface : requires a 'sampledSurfaceDict' subdictionary. See e.g. + sampleDict. + + operation is one of: - none - sum - areaAverage @@ -62,6 +69,11 @@ Description faces. - all fields get oriented according to the faceZone (so you might e.g. see negative pressure) + - using sampledSurfaces: + - they do not do surface fields + - they use cell values - they do not do any interpolation. + - take care when using isoSurfaces - these might have duplicate + triangles so integration might be wrong SourceFiles faceSource.C @@ -80,6 +92,9 @@ SourceFiles namespace Foam { + +class sampledSurface; + namespace fieldValues { @@ -100,11 +115,12 @@ public: enum sourceType { stFaceZone, - stPatch + stPatch, + stSampledSurface }; //- Source type names - static const NamedEnum<sourceType, 2> sourceTypeNames_; + static const NamedEnum<sourceType, 3> sourceTypeNames_; //- Operation type enumeration @@ -133,6 +149,9 @@ private: //- Set faces to evaluate based on a patch void setPatchFaces(); + //- Set faces according to sampledSurface + void sampledSurfaceFaces(const dictionary&); + protected: @@ -144,20 +163,30 @@ protected: //- Operation to apply to values operationType operation_; + //- Weight field name - only used for opWeightedAverage mode + word weightFieldName_; + //- Global number of faces label nFaces_; - //- Local list of face IDs - labelList faceId_; - //- Local list of patch ID per face - labelList facePatchId_; + // If operating on mesh faces (faceZone,patch) - //- List of +1/-1 representing face flip map (1 use as is, -1 negate) - labelList faceSign_; + //- Local list of face IDs + labelList faceId_; + + //- Local list of patch ID per face + labelList facePatchId_; + + //- List of +1/-1 representing face flip map + // (1 use as is, -1 negate) + labelList faceSign_; + + // If operating on sampledSurface + + //- underlying sampledSurface + autoPtr<sampledSurface> surfacePtr_; - //- Weight field name - only used for opWeightedAverage mode - word weightFieldName_; // Protected Member Functions @@ -171,7 +200,7 @@ protected: //- Return field values by looking up field name template<class Type> - tmp<Field<Type> > setFieldValues(const word& fieldName) const; + tmp<Field<Type> > getFieldValues(const word& fieldName) const; //- Apply the 'operation' to the values template<class Type> diff --git a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C index 3f6c9bd3c9bb7b05e71723dc7aeea929a694a249..9999860a62313f130feadf16df04c45422539831 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/faceSource/faceSourceTemplates.C @@ -26,7 +26,7 @@ License #include "faceSource.H" #include "surfaceFields.H" #include "volFields.H" -#include "ListListOps.H" +#include "sampledSurface.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // @@ -36,7 +36,7 @@ bool Foam::fieldValues::faceSource::validField(const word& fieldName) const typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf; typedef GeometricField<Type, fvPatchField, volMesh> vf; - if (obr_.foundObject<sf>(fieldName)) + if (source_ != stSampledSurface && obr_.foundObject<sf>(fieldName)) { return true; } @@ -50,7 +50,7 @@ bool Foam::fieldValues::faceSource::validField(const word& fieldName) const template<class Type> -Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::setFieldValues +Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues ( const word& fieldName ) const @@ -58,13 +58,20 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::setFieldValues typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf; typedef GeometricField<Type, fvPatchField, volMesh> vf; - if (obr_.foundObject<sf>(fieldName)) + if (source_ != stSampledSurface && obr_.foundObject<sf>(fieldName)) { return filterField(obr_.lookupObject<sf>(fieldName), true); } else if (obr_.foundObject<vf>(fieldName)) { - return filterField(obr_.lookupObject<vf>(fieldName), true); + if (surfacePtr_.valid()) + { + return surfacePtr_().sample(obr_.lookupObject<vf>(fieldName)); + } + else + { + return filterField(obr_.lookupObject<vf>(fieldName), true); + } } return tmp<Field<Type> >(new Field<Type>(0)); @@ -131,15 +138,26 @@ bool Foam::fieldValues::faceSource::writeValues(const word& fieldName) if (ok) { - // Get (correctly oriented) field - Field<Type> values = combineFields(setFieldValues<Type>(fieldName)); + Field<Type> values = getFieldValues<Type>(fieldName); + scalarField weightField = getFieldValues<scalar>(weightFieldName_); + scalarField magSf; + + if (surfacePtr_.valid()) + { + // Get unoriented magSf + magSf = surfacePtr_().magSf(); + } + else + { + // Get unoriented magSf + magSf = combineFields(filterField(mesh().magSf(), false)); + } - // Get unoriented magSf - scalarField magSf = combineFields(filterField(mesh().magSf(), false)); + // Combine onto master + values = combineFields(values); + magSf = combineFields(magSf); + weightField = combineFields(weightField); - // Get (correctly oriented) weighting field - scalarField weightField = - combineFields(setFieldValues<scalar>(weightFieldName_)); if (Pstream::master()) { diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C index 1c5af36ad7bd4311bbb3199f58de54fb443deebf..0f4ead7444be55dd87707cc92757d606bd12cf25 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.C @@ -130,7 +130,7 @@ Foam::fieldValue::fieldValue obr_(obr), active_(true), log_(false), - sourceName_(dict.lookup("sourceName")), + sourceName_(dict.lookupOrDefault<word>("sourceName", "sampledSurface")), fields_(dict.lookup("fields")), valueOutput_(dict.lookup("valueOutput")), outputFilePtr_(NULL) diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H index ab32927dc9271ada2829afe4f82b3ccf33e20972..179b96ae94c7f1f2d054dd62009c559708f543c1 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValue.H @@ -164,12 +164,14 @@ public: //- Execute the at the final time-loop, currently does nothing virtual void end(); - //- Comnbine fields from all processor domains into single field + //- Combine fields from all processor domains into single field template<class Type> - tmp<Field<Type> > combineFields - ( - const tmp<Field<Type> >& field - ) const; + tmp<Field<Type> > combineFields(const Field<Type>& field) const; + + //- Combine fields from all processor domains into single field + template<class Type> + tmp<Field<Type> > combineFields(const tmp<Field<Type> >&) const; + }; diff --git a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueTemplates.C b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueTemplates.C index 0aff19c8affeae9aab482ceb97d73c7dfbbd082d..3df599081d315f7eea038b67b99bfd483a6f5414 100644 --- a/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueTemplates.C +++ b/src/postProcessing/functionObjects/field/fieldValues/fieldValue/fieldValueTemplates.C @@ -32,12 +32,12 @@ License template<class Type> Foam::tmp<Foam::Field<Type> > Foam::fieldValue::combineFields ( - const tmp<Field<Type> >& field + const Field<Type>& field ) const { List<Field<Type> > allValues(Pstream::nProcs()); - allValues[Pstream::myProcNo()] = field(); + allValues[Pstream::myProcNo()] = field; Pstream::gatherList(allValues); @@ -57,9 +57,19 @@ Foam::tmp<Foam::Field<Type> > Foam::fieldValue::combineFields } else { - return field(); + return field; } } +template<class Type> +Foam::tmp<Foam::Field<Type> > Foam::fieldValue::combineFields +( + const tmp<Field<Type> >& field +) const +{ + return combineFields(field()); +} + + // ************************************************************************* // diff --git a/src/sampling/Make/files b/src/sampling/Make/files index c385e9aa9395caa95121588ef8189ce65df06566..6fee75b8f7d0b32c7219f83982f66629916c4b35 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -46,6 +46,7 @@ surfWriters = sampledSurface/writers $(surfWriters)/surfaceWriters.C $(surfWriters)/dx/dxSurfaceWriterRunTime.C +$(surfWriters)/ensight/ensightSurfaceWriterRunTime.C $(surfWriters)/foamFile/foamFileSurfaceWriterRunTime.C $(surfWriters)/null/nullSurfaceWriterRunTime.C $(surfWriters)/proxy/proxySurfaceWriterRunTime.C diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C index 4dd5deffa5bdbaa1d7417fde58e56c3e62eb730f..128f7d2606bfec3c9c486148f2ee4888d7e1d4a8 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C @@ -103,7 +103,8 @@ void Foam::sampledSurfaces::sampleAndWrite mergeList_[surfI].points, mergeList_[surfI].faces, fieldName, - allValues + allValues, + s.interpolate() ); } } @@ -121,7 +122,8 @@ void Foam::sampledSurfaces::sampleAndWrite s.points(), s.faces(), fieldName, - values + values, + s.interpolate() ); } } diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C index 4950e37664d1f15cb9f47110d710fa968ac83b8d..f4e7ebe2164f7ffd25be633a89fc2ba1950314b0 100644 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.C @@ -250,6 +250,7 @@ void Foam::dxSurfaceWriter<Type>::write const faceList& faces, const word& fieldName, const Field<Type>& values, + const bool isNodeValues, const bool verbose ) const { @@ -272,7 +273,7 @@ void Foam::dxSurfaceWriter<Type>::write writeData(os, values); - if (values.size() == points.size()) + if (isNodeValues) { os << nl << "attribute \"dep\" string \"positions\"" << nl << nl; diff --git a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H index 897133a005f2170ee03fa75c00c6632a40b61f1e..fc996ee3d9064ee59208b769fff2d86b470d0ea4 100644 --- a/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/dx/dxSurfaceWriter.H @@ -88,6 +88,7 @@ public: const faceList& faces, const word& fieldName, const Field<Type>& values, + const bool isNodeValues, const bool verbose = false ) const; }; diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C new file mode 100644 index 0000000000000000000000000000000000000000..81eb8510fab382598919d37ea9ce2cb0f8ebebf4 --- /dev/null +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C @@ -0,0 +1,372 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "ensightSurfaceWriter.H" + +#include "OFstream.H" +#include "OSspecific.H" +#include "IOmanip.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +template<class Type> +void Foam::ensightSurfaceWriter<Type>::binShapes +( + const pointField& points, + const faceList& faces, + DynamicList<label>& tris, + DynamicList<label>& quads, + DynamicList<label>& polys +) +{ + tris.setCapacity(faces.size()); + quads.setCapacity(faces.size()); + polys.setCapacity(faces.size()); + + forAll(faces, i) + { + const face& f = faces[i]; + if (f.size() == 3) + { + tris.append(i); + } + else if (f.size() == 4) + { + quads.append(i); + } + else + { + polys.append(i); + } + } +} + + +template<class Type> +void Foam::ensightSurfaceWriter<Type>::writeGeometry +( + const fileName& surfaceName, + Ostream& os, + const pointField& points, + const faceList& faces, + const DynamicList<label>& tris, + const DynamicList<label>& quads, + const DynamicList<label>& polys +) +{ + os << "EnSight Geometry File" << nl + << (string("written by OpenFOAM-") + Foam::FOAMversion).c_str() << nl + << "node id assign" << nl + << "element id assign" << nl + << "part" << nl + << setw(10) << 1 << nl + << surfaceName.c_str() << nl; + + os << "coordinates" << nl + << setw(10) << points.size() << nl; + for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++) + { + scalarField v = points.component(cmpt); + forAll(v, i) + { + os << v[i] << nl; + } + } + + + if (tris.size()) + { + os << "tria3" << nl + << setw(10) << tris.size() << nl; + forAll(tris, i) + { + const face& f = faces[tris[i]]; + forAll(f, fp) + { + os << setw(10) << f[fp]+1; + } + os << nl; + } + } + if (quads.size()) + { + os << "quad4" << nl + << setw(10) << quads.size() << nl; + forAll(quads, i) + { + const face& f = faces[quads[i]]; + forAll(f, fp) + { + os << setw(10) << f[fp]+1; + } + os << nl; + } + } + if (polys.size()) + { + os << "nsided" << nl + << setw(10) << polys.size() << nl; + forAll(polys, i) + { + const face& f = faces[polys[i]]; + forAll(f, fp) + { + os << setw(10) << f[fp]+1; + } + os << nl; + } + } +} + + +namespace Foam +{ + + // Write scalarField in ensight format + template<> + void Foam::ensightSurfaceWriter<Foam::scalar>::writeData + ( + Ostream& os, + const Field<Foam::scalar>& values + ) + { + forAll(values, i) + { + os << values[i] << nl; + } + } + + + // Write booField in ensight format + template<> + void Foam::ensightSurfaceWriter<bool>::writeData + ( + Ostream& os, + const Field<bool>& values + ) + { + forAll(values, i) + { + os << values[i] << nl; + } + } +} + + +// Write generic field in ensight format +template<class Type> +void Foam::ensightSurfaceWriter<Type>::writeData +( + Ostream& os, + const Field<Type>& values +) +{ + for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++) + { + scalarField v = values.component(cmpt); + forAll(v, i) + { + os << v[i] << nl; + } + } +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +// Construct from components +template<class Type> +Foam::ensightSurfaceWriter<Type>::ensightSurfaceWriter() +: + surfaceWriter<Type>() +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template<class Type> +Foam::ensightSurfaceWriter<Type>::~ensightSurfaceWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template<class Type> +void Foam::ensightSurfaceWriter<Type>::write +( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose +) const +{ + if (!isDir(outputDir)) + { + mkDir(outputDir); + } + + //const scalar timeValue = Foam::name(this->mesh().time().timeValue()); + const scalar timeValue = 0.0; + + + OFstream caseStr(outputDir/surfaceName + ".case"); + OFstream geomStr(outputDir/surfaceName + ".***.mesh"); + + if (verbose) + { + Info<< "Writing case file to " << caseStr.name() << endl; + } + + caseStr + << "FORMAT" << nl + << "type: ensight gold" << nl + << nl + << "GEOMETRY" << nl + << "model: 1 " << geomStr.name().name() << nl + << nl + << "TIME" << nl + << "time set: 1" << nl + << "number of steps: 1" << nl + << "filename start number: 0" << nl + << "filename increment: 1" << nl + << "time values:" << nl + << timeValue << nl + << nl; + + DynamicList<label> tris; + DynamicList<label> quads; + DynamicList<label> polys; + binShapes(points, faces, tris, quads, polys); + + writeGeometry(surfaceName, geomStr, points, faces, tris, quads, polys); +} + + +template<class Type> +void Foam::ensightSurfaceWriter<Type>::write +( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field<Type>& values, + const bool isNodeValues, + const bool verbose +) const +{ + if (!isDir(outputDir/fieldName)) + { + mkDir(outputDir/fieldName); + } + + //const scalar timeValue = Foam::name(this->mesh().time().timeValue()); + const scalar timeValue = 0.0; + + + OFstream caseStr(outputDir/fieldName/surfaceName + ".case"); + OFstream geomStr(outputDir/fieldName/surfaceName + ".000.mesh"); + OFstream fieldStr(outputDir/fieldName/surfaceName + ".000." + fieldName); + + if (verbose) + { + Info<< "Writing case file to " << caseStr.name() << endl; + } + + caseStr + << "FORMAT" << nl + << "type: ensight gold" << nl + << nl + << "GEOMETRY" << nl + << "model: 1 " << geomStr.name().name() << nl + << nl + << "VARIABLE" << nl; + if (isNodeValues) + { + caseStr + << pTraits<Type>::typeName << " per node:" << setw(10) << 1 + << " " << fieldName + << " " << surfaceName.c_str() << ".***." << fieldName << nl; + } + else + { + caseStr + << pTraits<Type>::typeName << " per element:" << setw(10) << 1 + << " " << fieldName + << " " << surfaceName.c_str() << ".***." << fieldName << nl; + } + + caseStr + << nl + << "TIME" << nl + << "time set: 1" << nl + << "number of steps: 1" << nl + << "filename start number: 0" << nl + << "filename increment: 1" << nl + << "time values:" << nl + << timeValue << nl + << nl; + + DynamicList<label> tris; + DynamicList<label> quads; + DynamicList<label> polys; + binShapes(points, faces, tris, quads, polys); + + writeGeometry(surfaceName, geomStr, points, faces, tris, quads, polys); + + // Write field + fieldStr + << pTraits<Type>::typeName << nl + << "part" << nl + << setw(10) << 1 << nl; + + if (isNodeValues) + { + fieldStr << "coordinates" << nl; + writeData(fieldStr, values); + } + else + { + if (tris.size()) + { + fieldStr << "tria3" << nl; + writeData(fieldStr, Field<Type>(values, tris)); + } + if (quads.size()) + { + fieldStr << "quad4" << nl; + writeData(fieldStr, Field<Type>(values, quads)); + } + if (polys.size()) + { + fieldStr << "nsided" << nl; + writeData(fieldStr, Field<Type>(values, polys)); + } + } +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H new file mode 100644 index 0000000000000000000000000000000000000000..adb974f133afe63a5b6b4e564c43b66858be278b --- /dev/null +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H @@ -0,0 +1,138 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 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 <http://www.gnu.org/licenses/>. + +Class + Foam::ensightSurfaceWriter + +Description + +SourceFiles + ensightSurfaceWriter.C + +\*---------------------------------------------------------------------------*/ + +#ifndef ensightSurfaceWriter_H +#define ensightSurfaceWriter_H + +#include "surfaceWriter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class ensightSurfaceWriter Declaration +\*---------------------------------------------------------------------------*/ + +template<class Type> +class ensightSurfaceWriter +: + public surfaceWriter<Type> +{ + // Private Member Functions + + static void binShapes + ( + const pointField& points, + const faceList& faces, + DynamicList<label>& tris, + DynamicList<label>& quads, + DynamicList<label>& polys + ); + + static void writeGeometry + ( + const fileName&, + Ostream&, + const pointField&, + const faceList&, + const DynamicList<label>&, + const DynamicList<label>&, + const DynamicList<label>& + ); + + static void writeData(Ostream&, const Field<Type>& values); + + +public: + + //- Runtime type information + TypeName("ensight"); + + + // Constructors + + //- Construct null + ensightSurfaceWriter(); + + + //- Destructor + virtual ~ensightSurfaceWriter(); + + + // Member Functions + + // Write + + //- Write geometry to file. + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const bool verbose = false + ) const; + + + //- Writes single surface to file. + virtual void write + ( + const fileName& outputDir, + const fileName& surfaceName, + const pointField& points, + const faceList& faces, + const word& fieldName, + const Field<Type>& values, + const bool isNodeValues, + const bool verbose = false + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "ensightSurfaceWriter.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriterRunTime.C b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriterRunTime.C new file mode 100644 index 0000000000000000000000000000000000000000..8355a6d991b5bbcf791a5214271fb9d706eca17f --- /dev/null +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriterRunTime.C @@ -0,0 +1,44 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2010-2010 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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "ensightSurfaceWriter.H" +#include "surfaceWriters.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +makeSurfaceWriterType(ensightSurfaceWriter, bool); +makeSurfaceWriters(ensightSurfaceWriter); + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C index 887abdd7e42f94a26491192f16ad03625c539e0a..ea121695bb5f0b18eed8c558d3721529b265875d 100644 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.C @@ -96,6 +96,7 @@ void Foam::foamFileSurfaceWriter<Type>::write const faceList& faces, const word& fieldName, const Field<Type>& values, + const bool isNodeValues, const bool verbose ) const { diff --git a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H index 8e1fb570623b8f62ac1f136e681767760680bef7..b77c91388bbea6c74e39fc8f28135e3e482d6fbe 100644 --- a/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/foamFile/foamFileSurfaceWriter.H @@ -95,6 +95,7 @@ public: const faceList& faces, const word& fieldName, const Field<Type>& values, + const bool isNodeValues, const bool verbose = false ) const; }; diff --git a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.C b/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.C index 6ae7a20933772f8b6731caba19f826ce14188615..bfda994af5d07463406217aa1fe1fd856c13d8df 100644 --- a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.C @@ -54,6 +54,7 @@ void Foam::nullSurfaceWriter<Type>::write const faceList& faces, const word& fieldName, const Field<Type>& values, + const bool isNodeValues, const bool verbose ) const {} diff --git a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.H b/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.H index 6b8b3f1fdeb69014bedbbc825d6e552300dc2214..8ea0f6a847089eafa29fcff7cd6803ef002f8c15 100644 --- a/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/null/nullSurfaceWriter.H @@ -80,6 +80,7 @@ public: const faceList& faces, const word& fieldName, const Field<Type>& values, + const bool isNodeValues, const bool verbose = false ) const; }; diff --git a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H index 3fdc991d54ffba268a0236c38dfaddd3f15ef7a8..426816b32cdde508cacf1f13ed699d4ade5cd32f 100644 --- a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H @@ -102,6 +102,7 @@ public: const faceList& faces, const word& fieldName, const Field<Type>& values, + const bool isNodeValues, const bool verbose = false ) const {} diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C index 1dc8ad80a55d17f1e7bc34d6113b0ff68ee41398..a3a7832e4f1261548f04b2b6107cd5f783dd00ce 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C @@ -68,6 +68,7 @@ void Foam::rawSurfaceWriter<Type>::writeData const pointField& points, const faceList& faces, const scalarField& values, + const bool isNodeValues, Ostream& os ) { @@ -75,7 +76,7 @@ void Foam::rawSurfaceWriter<Type>::writeData os << "# x y z " << fieldName << endl; // Write data - if (values.size() == points.size()) + if (isNodeValues) { forAll(values, elemI) { @@ -104,6 +105,7 @@ void Foam::rawSurfaceWriter<Type>::writeData const pointField& points, const faceList& faces, const vectorField& values, + const bool isNodeValues, Ostream& os ) { @@ -115,7 +117,7 @@ void Foam::rawSurfaceWriter<Type>::writeData << endl; // Write data - if (values.size() == points.size()) + if (isNodeValues) { forAll(values, elemI) { @@ -147,6 +149,7 @@ void Foam::rawSurfaceWriter<Type>::writeData const pointField& points, const faceList& faces, const sphericalTensorField& values, + const bool isNodeValues, Ostream& os ) { @@ -155,7 +158,7 @@ void Foam::rawSurfaceWriter<Type>::writeData os << fieldName << "_ii" << endl; // Write data - if (values.size() == points.size()) + if (isNodeValues) { forAll(values, elemI) { @@ -186,6 +189,7 @@ void Foam::rawSurfaceWriter<Type>::writeData const pointField& points, const faceList& faces, const symmTensorField& values, + const bool isNodeValues, Ostream& os ) { @@ -198,7 +202,7 @@ void Foam::rawSurfaceWriter<Type>::writeData os << endl; // Write data - if (values.size() == points.size()) + if (isNodeValues) { forAll(values, elemI) { @@ -233,6 +237,7 @@ void Foam::rawSurfaceWriter<Type>::writeData const pointField& points, const faceList& faces, const tensorField& values, + const bool isNodeValues, Ostream& os ) { @@ -245,7 +250,7 @@ void Foam::rawSurfaceWriter<Type>::writeData os << endl; // Write data - if (values.size() == points.size()) + if (isNodeValues) { forAll(values, elemI) { @@ -343,6 +348,7 @@ namespace Foam const faceList& faces, const word& fieldName, const Field<bool>& values, + const bool isNodeValues, const bool verbose ) const {} @@ -358,6 +364,7 @@ void Foam::rawSurfaceWriter<Type>::write const faceList& faces, const word& fieldName, const Field<Type>& values, + const bool isNodeValues, const bool verbose ) const { @@ -379,7 +386,7 @@ void Foam::rawSurfaceWriter<Type>::write // header os << "# " << fieldName; - if (values.size() == points.size()) + if (isNodeValues) { os << " POINT_DATA "; } @@ -390,7 +397,7 @@ void Foam::rawSurfaceWriter<Type>::write os << values.size() << nl; - writeData(fieldName, points, faces, values, os); + writeData(fieldName, points, faces, values, isNodeValues, os); } diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H index 0fc4478f42d9388b0c85fbaa3dbf763373fb6ea6..a7dee21262acc3512b4ddba350462c8c0a6783e1 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H @@ -73,6 +73,7 @@ class rawSurfaceWriter const pointField& points, const faceList& faces, const scalarField& values, + const bool isNodeValues, Ostream& os ); @@ -82,6 +83,7 @@ class rawSurfaceWriter const pointField& points, const faceList& faces, const vectorField& values, + const bool isNodeValues, Ostream& os ); @@ -91,6 +93,7 @@ class rawSurfaceWriter const pointField& points, const faceList& faces, const sphericalTensorField& values, + const bool isNodeValues, Ostream& os ); @@ -100,6 +103,7 @@ class rawSurfaceWriter const pointField& points, const faceList& faces, const symmTensorField& values, + const bool isNodeValues, Ostream& os ); @@ -109,6 +113,7 @@ class rawSurfaceWriter const pointField& points, const faceList& faces, const tensorField& values, + const bool isNodeValues, Ostream& os ); @@ -152,6 +157,7 @@ public: const faceList& faces, const word& fieldName, const Field<Type>& values, + const bool isNodeValues, const bool verbose = false ) const; }; diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.H b/src/sampling/sampledSurface/writers/surfaceWriter.H index 6fcf0f01330c20eadc841d7de1aff761ff59dd6a..c3f138ad0d97e49916e02b3a4fdb09fe2a7dafe7 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.H +++ b/src/sampling/sampledSurface/writers/surfaceWriter.H @@ -119,7 +119,7 @@ public: //- Writes single surface to file. Either one value per vertex or - // one value per face (detected by values.size()==faces.size()) + // one value per face (isNodeValues = false) virtual void write ( const fileName& outputDir, // <root>/<case>/surface/TIME @@ -128,6 +128,7 @@ public: const faceList& faces, const word& fieldName, // name of field const Field<Type>& values, + const bool isNodeValues, const bool verbose = false ) const = 0; }; diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C index 61da515b40c5d0d3d391aa42dcce086abcccab97..c1aa725c13eecbdb676359ac2ac2750a4e9d3f96 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C @@ -267,6 +267,7 @@ void Foam::vtkSurfaceWriter<Type>::write const faceList& faces, const word& fieldName, const Field<Type>& values, + const bool isNodeValues, const bool verbose ) const { @@ -288,7 +289,7 @@ void Foam::vtkSurfaceWriter<Type>::write writeGeometry(os, points, faces); // start writing data - if (values.size() == points.size()) + if (isNodeValues) { os << "POINT_DATA "; } diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H index 7524cb963c73a674f07110953a563760343c59bb..1d7b005d5dc419570cd15fe4d56e215e664975be 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H @@ -97,6 +97,7 @@ public: const faceList& faces, const word& fieldName, const Field<Type>& values, + const bool isNodeValues, const bool verbose = false ) const; }; diff --git a/src/surfaceFilmModels/submodels/thermo/phaseChangeModel/standardPhaseChange/standardPhaseChange.C b/src/surfaceFilmModels/submodels/thermo/phaseChangeModel/standardPhaseChange/standardPhaseChange.C index 8380d06ef7be8edd73c661d1c850ecf426c0fab1..3dea2ae9104069c75904815bb4e3ff5ee5812aeb 100644 --- a/src/surfaceFilmModels/submodels/thermo/phaseChangeModel/standardPhaseChange/standardPhaseChange.C +++ b/src/surfaceFilmModels/submodels/thermo/phaseChangeModel/standardPhaseChange/standardPhaseChange.C @@ -77,6 +77,7 @@ Foam::surfaceFilmModels::standardPhaseChange::standardPhaseChange Tb_(readScalar(coeffs_.lookup("Tb"))), deltaMin_(readScalar(coeffs_.lookup("deltaMin"))), L_(readScalar(coeffs_.lookup("L"))), + TbFactor_(coeffs_.lookupOrDefault<scalar>("TbFactor", 1.1)), totalMass_(0.0), vapourRate_(0.0) {} @@ -133,7 +134,7 @@ void Foam::surfaceFilmModels::standardPhaseChange::correct const scalar pc = pInf[cellI]; // local temperature - impose lower limit of 200 K for stability - const scalar Tloc = min(liq.Tc(), max(200.0, T[cellI])); + const scalar Tloc = min(TbFactor_*Tb_, max(200.0, T[cellI])); // saturation pressure [Pa] const scalar pSat = liq.pv(pc, Tloc); @@ -149,7 +150,9 @@ void Foam::surfaceFilmModels::standardPhaseChange::correct const scalar qDotFilm = hFilm[cellI]*(T[cellI] - Tw[cellI]); const scalar Cp = liq.Cp(pc, Tloc); - const scalar qCorr = availableMass[cellI]*Cp*(T[cellI] - Tb_); + const scalar Tcorr = max(0.0, T[cellI] - Tb_); + const scalar qCorr = availableMass[cellI]*Cp*(Tcorr); + dMass[cellI] = dt*magSf[cellI]/hVap*(qDotInf + qDotFilm) + qCorr/hVap; @@ -185,7 +188,7 @@ void Foam::surfaceFilmModels::standardPhaseChange::correct const scalar Sh = this->Sh(Re, Sc); // mass transfer coefficient [m/s] - const scalar hm = Sh*Dab/L_; + const scalar hm = Sh*Dab/(L_ + ROOTVSMALL); // add mass contribution to source dMass[cellI] = diff --git a/src/surfaceFilmModels/submodels/thermo/phaseChangeModel/standardPhaseChange/standardPhaseChange.H b/src/surfaceFilmModels/submodels/thermo/phaseChangeModel/standardPhaseChange/standardPhaseChange.H index bb9e69e4c62511ca1d317bf714b181125c156c81..17138974c4921dd30f7dc083828313da6f5160be 100644 --- a/src/surfaceFilmModels/submodels/thermo/phaseChangeModel/standardPhaseChange/standardPhaseChange.H +++ b/src/surfaceFilmModels/submodels/thermo/phaseChangeModel/standardPhaseChange/standardPhaseChange.H @@ -76,6 +76,10 @@ protected: //- Length scale / [m] const scalar L_; + //- Boiling temperature factor / [] + // Used to set max limit on temperature to Tb*TbFactor + const scalar TbFactor_; + //- Total mass evolved / [kg] scalar totalMass_; diff --git a/src/surfaceFilmModels/surfaceFilmModel/thermoSingleLayer/thermoSingleLayer.C b/src/surfaceFilmModels/surfaceFilmModel/thermoSingleLayer/thermoSingleLayer.C index e15c50c22dfda3254d44438ebbf6e2f464ae2432..2d849f580479a2b1619dcae175a3180121856f29 100644 --- a/src/surfaceFilmModels/surfaceFilmModel/thermoSingleLayer/thermoSingleLayer.C +++ b/src/surfaceFilmModels/surfaceFilmModel/thermoSingleLayer/thermoSingleLayer.C @@ -209,12 +209,14 @@ void Foam::surfaceFilmModels::thermoSingleLayer::solveEnergy() massForPrimary_/magSf_/time_.deltaT() ); +// dimensionedScalar hs0("SMALL", hs_.dimensions(), SMALL); + solve ( fvm::ddt(deltaRho_, hs_) + fvm::div(phi_, hs_) == -// fvm::Sp(hsSp_/hs_, hs_) +// fvm::Sp(hsSp_/(hs_ + hs0), hs_) hsSp_ + q(hs_) - fvm::Sp(mLossCoeff, hs_)