Nektar++
ForcingIncNSSyntheticEddy.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: ForcingIncNSSyntheticEddy.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// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Derived base class - Synthetic turbulence forcing for the
32// Incompressible solver.
33//
34///////////////////////////////////////////////////////////////////////////////
35
37
38namespace Nektar::SolverUtils
39{
40
43 "IncNSSyntheticTurbulence", ForcingIncNSSyntheticEddy::create,
44 "Inc NS Synthetic Eddy Turbulence Forcing (Generation)");
45
48 const std::weak_ptr<EquationSystem> &pEquation)
49 : Forcing(pSession, pEquation), ForcingSyntheticEddy(pSession, pEquation)
50{
51}
52
53/**
54 * @brief Apply forcing term if an eddy left the box of eddies and
55 * update the eddies positions.
56 *
57 * @param pFields Pointer to fields.
58 * @param inarray Given fields. The fields are in in physical space.
59 * @param outarray Calculated solution after forcing term being applied
60 * in physical space.
61 * @param time time.
62 */
65 [[maybe_unused]] const Array<OneD, Array<OneD, NekDouble>> &inarray,
67 [[maybe_unused]] const NekDouble &time)
68{
69 // Number of Variables
70 int nVars = pFields.size();
71 // Total number of coefficients
72 unsigned int nqTot = pFields[0]->GetTotPoints();
73
74 // Only calculates the forcing in the first time step and when an eddy
75 // leaves the synthetic eddy region (box).
76 if (m_calcForcing)
77 {
78 CalculateForcing(pFields);
79 m_calcForcing = false;
80 }
81
82 // Incompressible version
83 // Only velocities u,v,w: nVars - 1
84 for (size_t i = 0; i < (nVars - 1); ++i)
85 {
86 Vmath::Vadd(nqTot, m_Forcing[i], 1, outarray[i], 1, outarray[i], 1);
87 }
88
89 // Update eddies position inside the box.
91}
92
93/**
94 * @brief Calculate forcing term.
95 *
96 * @param pFfields Pointer to fields.
97 */
100{
101 // Total number of quadrature points
102 int nqTot = pFields[0]->GetTotPoints();
103
104 // Compute Stochastic Signal
105 Array<OneD, Array<OneD, NekDouble>> stochasticSignal;
106 stochasticSignal = ComputeStochasticSignal(pFields);
107
108 // Compute velocity flsuctuation
110 velFluc = ComputeVelocityFluctuation(pFields, stochasticSignal);
111
112 // Compute characteristic convective turbulent time
114 convTurbTime = ComputeCharConvTurbTime(pFields);
115
116 // Compute smoothing factor
118 smoothFac = ComputeSmoothingFactor(pFields, convTurbTime);
119
120 // Check if eddies left the box. Note that the member m_eddiesIDForcing
121 // is populate with the eddies that left the box. If any left it is going
122 // to be empty.
123 if (!m_eddiesIDForcing.empty())
124 {
125 // Forcing must stop applying for eddies that left the box.
127
128 // Update Forcing term which are going to be applied until
129 // the eddy leave the domain.
130 // Select the eddies to apply the forcing. Superposition.
131 for (auto &n : m_eddiesIDForcing)
132 {
133 // velocity term
134 for (size_t j = 0; j < m_spacedim; ++j)
135 {
136 for (size_t i = 0; i < nqTot; ++i)
137 {
138 if (m_mask[i])
139 {
140 m_ForcingEddy[n][j][i] +=
141 ((velFluc[n][j * nqTot + i] * smoothFac[j][i]) /
142 convTurbTime[j][i]);
143 // Update forcing
144 m_Forcing[j][i] += m_ForcingEddy[n][j][i];
145 }
146 }
147 }
148 }
149 // delete eddies
151 m_eddiesIDForcing.end());
152 }
153 else
154 {
155 NEKERROR(ErrorUtil::efatal, "Failed: Eddies ID vector is empty.");
156 }
157}
158
159} // namespace Nektar::SolverUtils
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Defines a forcing term to be explicitly applied.
Definition: Forcing.h:71
Array< OneD, Array< OneD, NekDouble > > m_Forcing
Evaluated forcing function.
Definition: Forcing.h:119
static ForcingSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation, const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const unsigned int &pNumForcingFields, const TiXmlElement *pForce)
Creates an instance of this class.
ForcingIncNSSyntheticEddy(const LibUtilities::SessionReaderSharedPtr &pSession, const std::weak_ptr< EquationSystem > &pEquation)
static std::string className
Name of the class.
void v_Apply(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, const Array< OneD, Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble &time) override
Apply forcing term if an eddy left the box of eddies and update the eddies positions.
void CalculateForcing(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
Calculate Forcing.
SOLVER_UTILS_EXPORT Array< OneD, Array< OneD, NekDouble > > ComputeSmoothingFactor(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, Array< OneD, Array< OneD, NekDouble > > convTurb)
Compute Smoothing Factor.
Array< OneD, Array< OneD, Array< OneD, NekDouble > > > m_ForcingEddy
Forcing for each eddy.
SOLVER_UTILS_EXPORT Array< OneD, Array< OneD, NekDouble > > ComputeStochasticSignal(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
Compute Stochastic Signal.
SOLVER_UTILS_EXPORT Array< OneD, Array< OneD, NekDouble > > ComputeVelocityFluctuation(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields, Array< OneD, Array< OneD, NekDouble > > stochasticSignal)
Compute Velocity Fluctuation.
SOLVER_UTILS_EXPORT void UpdateEddiesPositions()
Update positions of the eddies inside the box.
std::vector< unsigned int > m_eddiesIDForcing
Eddies that add to the domain.
bool m_calcForcing
Check when the forcing should be applied.
SOLVER_UTILS_EXPORT void RemoveEddiesFromForcing(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
Remove eddy from forcing term.
SOLVER_UTILS_EXPORT Array< OneD, Array< OneD, NekDouble > > ComputeCharConvTurbTime(const Array< OneD, MultiRegions::ExpListSharedPtr > &pFields)
Compute Characteristic Convective Turbulent Time.
Array< OneD, int > m_mask
Box of eddies mask.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
ForcingFactory & GetForcingFactory()
Declaration of the forcing factory singleton.
Definition: Forcing.cpp:42
double NekDouble
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.hpp:180