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 namespace Nektar
40 {
41 namespace SolverUtils
42 {
43 
45  RegisterCreatorFunction("Noise",
47  "White Noise Forcing");
48 
51  : Forcing(pSession)
52  {
53  }
54 
57  const unsigned int& pNumForcingFields,
58  const TiXmlElement* pForce)
59  {
60  m_NumVariable = pNumForcingFields;
61  int nq = pFields[0]->GetTotPoints();
62 
63  const TiXmlElement* noiseElmt = pForce->FirstChildElement("WHITENOISE");
64  ASSERTL0(noiseElmt, "Requires WHITENOISE tag specifying "
65  "magnitude of white noise force.");
66 
67  string noiseValue = noiseElmt->GetText();
68 
69  m_noise = boost::lexical_cast<NekDouble>(noiseValue);
70 
71  // Load optional parameters
72  const TiXmlElement* freqElmt = pForce->FirstChildElement("UPDATEFREQ");
73  if (freqElmt)
74  {
75  string freqValue = freqElmt->GetText();
76  m_updateFreq = boost::lexical_cast<int>(freqValue);
77  }
78  else
79  {
80  // Default is 0 (never update forcing)
81  m_updateFreq = 0;
82  }
83 
84  const TiXmlElement* stepsElmt = pForce->FirstChildElement("NSTEPS");
85  if (stepsElmt)
86  {
87  string stepsValue = stepsElmt->GetText();
88  m_numSteps = boost::lexical_cast<int>(stepsValue);
89  }
90  else
91  {
92  // Default is 0 (use noise in the entire simulation)
93  m_numSteps = 0;
94  }
95 
97 
98  // Fill forcing: use -i as seed to avoid repeated results
99  for (int i = 0; i < m_NumVariable; ++i)
100  {
101  m_Forcing[i] = Array<OneD, NekDouble> (nq, 0.0);
102  Vmath::FillWhiteNoise(nq,m_noise,&m_Forcing[i][0],1,-i);
103  }
104 
105  m_index = 0;
106  }
107 
110  const Array<OneD, Array<OneD, NekDouble> > &inarray,
111  Array<OneD, Array<OneD, NekDouble> > &outarray,
112  const NekDouble &time)
113  {
114  // Do not apply forcing if exceeded m_numSteps
115  if( m_numSteps && (m_index >= m_numSteps) )
116  {
117  return;
118  }
119 
120  // Update forcing (change seed to avoid getting same result)
122  {
123  for (int i = 0; i < m_NumVariable; ++i)
124  {
125  Vmath::FillWhiteNoise(outarray[i].num_elements(),
126  m_noise,&m_Forcing[i][0],1,
127  -m_index*m_NumVariable-i);
128  }
129  }
130 
131  // Apply forcing
132  for (int i = 0; i < m_NumVariable; i++)
133  {
134  Vmath::Vadd(outarray[i].num_elements(), outarray[i], 1,
135  m_Forcing[i], 1, outarray[i], 1);
136  }
137 
138  ++m_index;
139  }
140 
141 }
142 }
virtual SOLVER_UTILS_EXPORT void v_InitObject(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
ForcingNoise(const LibUtilities::SessionReaderSharedPtr &pSession)
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:42
boost::shared_ptr< SessionReader > SessionReaderSharedPtr
Definition: MeshPartition.h:51
static SOLVER_UTILS_EXPORT ForcingSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
Creates an instance of this class.
Definition: ForcingNoise.h:58
double NekDouble
static std::string className
Name of the class.
Definition: ForcingNoise.h:71
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