Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ForcingNoise.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: ForcingNoise.cpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: white noise forcing
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
37 #include <MultiRegions/ExpList.h>
38 
39 using namespace std;
40 
41 namespace Nektar
42 {
43 namespace SolverUtils
44 {
45 
46  std::string ForcingNoise::className = GetForcingFactory().
47  RegisterCreatorFunction("Noise",
48  ForcingNoise::create,
49  "White Noise Forcing");
50 
51  ForcingNoise::ForcingNoise(
53  : Forcing(pSession)
54  {
55  }
56 
59  const unsigned int& pNumForcingFields,
60  const TiXmlElement* pForce)
61  {
62  m_NumVariable = pNumForcingFields;
63  int nq = pFields[0]->GetTotPoints();
64 
65  const TiXmlElement* noiseElmt = pForce->FirstChildElement("WHITENOISE");
66  ASSERTL0(noiseElmt, "Requires WHITENOISE tag specifying "
67  "magnitude of white noise force.");
68 
69  string noiseValue = noiseElmt->GetText();
70 
71  m_noise = boost::lexical_cast<NekDouble>(noiseValue);
72 
73  // Load optional parameters
74  const TiXmlElement* freqElmt = pForce->FirstChildElement("UPDATEFREQ");
75  if (freqElmt)
76  {
77  string freqValue = freqElmt->GetText();
78  m_updateFreq = boost::lexical_cast<int>(freqValue);
79  }
80  else
81  {
82  // Default is 0 (never update forcing)
83  m_updateFreq = 0;
84  }
85 
86  const TiXmlElement* stepsElmt = pForce->FirstChildElement("NSTEPS");
87  if (stepsElmt)
88  {
89  string stepsValue = stepsElmt->GetText();
90  m_numSteps = boost::lexical_cast<int>(stepsValue);
91  }
92  else
93  {
94  // Default is 0 (use noise in the entire simulation)
95  m_numSteps = 0;
96  }
97 
99 
100  // Fill forcing: use -i as seed to avoid repeated results
101  for (int i = 0; i < m_NumVariable; ++i)
102  {
103  m_Forcing[i] = Array<OneD, NekDouble> (nq, 0.0);
104  Vmath::FillWhiteNoise(nq,m_noise,&m_Forcing[i][0],1,-i);
105  }
106 
107  m_index = 0;
108  }
109 
112  const Array<OneD, Array<OneD, NekDouble> > &inarray,
113  Array<OneD, Array<OneD, NekDouble> > &outarray,
114  const NekDouble &time)
115  {
116  // Do not apply forcing if exceeded m_numSteps
117  if( m_numSteps && (m_index >= m_numSteps) )
118  {
119  return;
120  }
121 
122  // Update forcing (change seed to avoid getting same result)
124  {
125  for (int i = 0; i < m_NumVariable; ++i)
126  {
127  Vmath::FillWhiteNoise(outarray[i].num_elements(),
128  m_noise,&m_Forcing[i][0],1,
129  -m_index*m_NumVariable-i);
130  }
131  }
132 
133  // Apply forcing
134  for (int i = 0; i < m_NumVariable; i++)
135  {
136  Vmath::Vadd(outarray[i].num_elements(), outarray[i], 1,
137  m_Forcing[i], 1, outarray[i], 1);
138  }
139 
140  ++m_index;
141  }
142 
143 }
144 }
virtual SOLVER_UTILS_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:97
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:161
virtual SOLVER_UTILS_EXPORT void v_Apply(const Array< OneD, MultiRegions::ExpListSharedPtr > &fields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time)
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:44
STL namespace.
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
double NekDouble
int m_NumVariable
Number of variables.
Definition: Forcing.h:99
void FillWhiteNoise(int n, const T eps, T *x, const int incx, int outseed)
Fills a vector with white noise.
Definition: Vmath.cpp:138
Defines a forcing term to be explicitly applied.
Definition: Forcing.h:70
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.cpp:285