FreeFOAM The Cross-Platform CFD Toolkit
randomise.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2008-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "randomise.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  namespace calcTypes
34  {
35  defineTypeNameAndDebug(randomise, 0);
37  }
38 }
39 
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
44 :
45  calcType()
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
50 
52 {}
53 
54 
55 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
56 
58 {
59  argList::validArgs.append("randomise");
60  argList::validArgs.append("perturbation");
61  argList::validArgs.append("fieldName");
62 }
63 
64 
66 (
67  const argList& args,
68  const Time& runTime,
69  const fvMesh& mesh
70 )
71 {}
72 
73 
75 (
76  const argList& args,
77  const Time& runTime,
78  const fvMesh& mesh
79 )
80 {
81  const stringList& params = args.additionalArgs();
82  const scalar pertMag = readScalar(IStringStream(params[1])());
83  const word& fieldName = params[2];
84 
85  Random rand(1234567);
86 
87  IOobject fieldHeader
88  (
89  fieldName,
90  runTime.timeName(),
91  mesh,
93  );
94 
95  // Check field exists
96  if (fieldHeader.headerOk())
97  {
98  bool processed = false;
99 
100  writeRandomField<vector>
101  (
102  fieldHeader,
103  pertMag,
104  rand,
105  mesh,
106  processed
107  );
108  writeRandomField<sphericalTensor>
109  (
110  fieldHeader,
111  pertMag,
112  rand,
113  mesh,
114  processed
115  );
116  writeRandomField<symmTensor>
117  (
118  fieldHeader,
119  pertMag,
120  rand,
121  mesh,
122  processed
123  );
124  writeRandomField<tensor>
125  (
126  fieldHeader,
127  pertMag,
128  rand,
129  mesh,
130  processed
131  );
132 
133  if (!processed)
134  {
135  FatalError
136  << "Unable to process " << fieldName << nl
137  << "No call to randomise for fields of type "
138  << fieldHeader.headerClassName() << nl << nl
139  << exit(FatalError);
140  }
141  }
142  else
143  {
144  Info<< " No " << fieldName << endl;
145  }
146 }
147 
148 
149 // ************************ vim: set sw=4 sts=4 et: ************************ //