FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "randomise.H"
00027 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00028 
00029 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033     namespace calcTypes
00034     {
00035         defineTypeNameAndDebug(randomise, 0);
00036         addToRunTimeSelectionTable(calcType, randomise, dictionary);
00037     }
00038 }
00039 
00040 
00041 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00042 
00043 Foam::calcTypes::randomise::randomise()
00044 :
00045     calcType()
00046 {}
00047 
00048 
00049 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00050 
00051 Foam::calcTypes::randomise::~randomise()
00052 {}
00053 
00054 
00055 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00056 
00057 void Foam::calcTypes::randomise::init()
00058 {
00059     argList::validArgs.append("randomise");
00060     argList::validArgs.append("perturbation");
00061     argList::validArgs.append("fieldName");
00062 }
00063 
00064 
00065 void Foam::calcTypes::randomise::preCalc
00066 (
00067     const argList& args,
00068     const Time& runTime,
00069     const fvMesh& mesh
00070 )
00071 {}
00072 
00073 
00074 void Foam::calcTypes::randomise::calc
00075 (
00076     const argList& args,
00077     const Time& runTime,
00078     const fvMesh& mesh
00079 )
00080 {
00081     const stringList& params = args.additionalArgs();
00082     const scalar pertMag = readScalar(IStringStream(params[1])());
00083     const word& fieldName = params[2];
00084 
00085     Random rand(1234567);
00086 
00087     IOobject fieldHeader
00088     (
00089         fieldName,
00090         runTime.timeName(),
00091         mesh,
00092         IOobject::MUST_READ
00093     );
00094 
00095     // Check field exists
00096     if (fieldHeader.headerOk())
00097     {
00098         bool processed = false;
00099 
00100         writeRandomField<vector>
00101         (
00102             fieldHeader,
00103             pertMag,
00104             rand,
00105             mesh,
00106             processed
00107         );
00108         writeRandomField<sphericalTensor>
00109         (
00110             fieldHeader,
00111             pertMag,
00112             rand,
00113             mesh,
00114             processed
00115         );
00116         writeRandomField<symmTensor>
00117         (
00118             fieldHeader,
00119             pertMag,
00120             rand,
00121             mesh,
00122             processed
00123         );
00124         writeRandomField<tensor>
00125         (
00126             fieldHeader,
00127             pertMag,
00128             rand,
00129             mesh,
00130             processed
00131         );
00132 
00133         if (!processed)
00134         {
00135             FatalError
00136                 << "Unable to process " << fieldName << nl
00137                 << "No call to randomise for fields of type "
00138                 << fieldHeader.headerClassName() << nl << nl
00139                 << exit(FatalError);
00140         }
00141     }
00142     else
00143     {
00144         Info<< "    No " << fieldName << endl;
00145     }
00146 }
00147 
00148 
00149 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines