OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

randomise.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 2008-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "randomise.H"
00028 #include "addToRunTimeSelectionTable.H"
00029 
00030 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034     namespace calcTypes
00035     {
00036         defineTypeNameAndDebug(randomise, 0);
00037         addToRunTimeSelectionTable(calcType, randomise, dictionary);
00038     }
00039 }
00040 
00041 
00042 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00043 
00044 Foam::calcTypes::randomise::randomise()
00045 :
00046     calcType()
00047 {}
00048 
00049 
00050 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00051 
00052 Foam::calcTypes::randomise::~randomise()
00053 {}
00054 
00055 
00056 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00057 
00058 void Foam::calcTypes::randomise::init()
00059 {
00060     argList::validArgs.append("randomise");
00061     argList::validArgs.append("perturbation");
00062     argList::validArgs.append("fieldName");
00063 }
00064 
00065 
00066 void Foam::calcTypes::randomise::preCalc
00067 (
00068     const argList& args,
00069     const Time& runTime,
00070     const fvMesh& mesh
00071 )
00072 {}
00073 
00074 
00075 void Foam::calcTypes::randomise::calc
00076 (
00077     const argList& args,
00078     const Time& runTime,
00079     const fvMesh& mesh
00080 )
00081 {
00082     const stringList& params = args.additionalArgs();
00083     const scalar pertMag = readScalar(IStringStream(params[1])());
00084     const word& fieldName = params[2];
00085 
00086     Random rand(1234567);
00087 
00088     IOobject fieldHeader
00089     (
00090         fieldName,
00091         runTime.timeName(),
00092         mesh,
00093         IOobject::MUST_READ
00094     );
00095 
00096     // Check field exists
00097     if (fieldHeader.headerOk())
00098     {
00099         bool processed = false;
00100 
00101         writeRandomField<vector>
00102         (
00103             fieldHeader,
00104             pertMag,
00105             rand,
00106             mesh,
00107             processed
00108         );
00109         writeRandomField<sphericalTensor>
00110         (
00111             fieldHeader,
00112             pertMag,
00113             rand,
00114             mesh,
00115             processed
00116         );
00117         writeRandomField<symmTensor>
00118         (
00119             fieldHeader,
00120             pertMag,
00121             rand,
00122             mesh,
00123             processed
00124         );
00125         writeRandomField<tensor>
00126         (
00127             fieldHeader,
00128             pertMag,
00129             rand,
00130             mesh,
00131             processed
00132         );
00133 
00134         if (!processed)
00135         {
00136             FatalError
00137                 << "Unable to process " << fieldName << nl
00138                 << "No call to randomise for fields of type "
00139                 << fieldHeader.headerClassName() << nl << nl
00140                 << exit(FatalError);
00141         }
00142     }
00143     else
00144     {
00145         Info<< "    No " << fieldName << endl;
00146     }
00147 }
00148 
00149 
00150 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd