Nektar++
NonlinearSWE.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: NonlinearSWE.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: Nonlinear Shallow water equations in conservative variables
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#include <iomanip>
36#include <iostream>
37
40
41namespace Nektar
42{
43std::string NonlinearSWE::className =
45 "NonlinearSWE", NonlinearSWE::create,
46 "Nonlinear shallow water equation in conservative variables.");
47
50 : ShallowWaterSystem(pSession, pGraph)
51{
52}
53
54void NonlinearSWE::v_InitObject(bool DeclareFields)
55{
57
58 // Type of advection class to be used
59 switch (m_projectionType)
60 {
61 // Continuous field
63 {
64 // Do nothing
65 break;
66 }
67 // Discontinuous field
69 {
70 std::string advName;
71 std::string diffName;
72 std::string riemName;
73
74 //---------------------------------------------------------------
75 // Setting up advection and diffusion operators
76 m_session->LoadSolverInfo("AdvectionType", advName, "WeakDG");
78 advName, advName);
79 m_advection->SetFluxVector(&NonlinearSWE::GetFluxVector, this);
80
81 // Setting up Riemann solver for advection operator
82 m_session->LoadSolverInfo("UpwindType", riemName, "Average");
85 riemName, m_session);
86
87 // Setting up parameters for advection operator Riemann solver
88 m_riemannSolver->SetParam("gravity", &NonlinearSWE::GetGravity,
89 this);
90 m_riemannSolver->SetAuxVec("vecLocs", &NonlinearSWE::GetVecLocs,
91 this);
92 m_riemannSolver->SetVector("N", &NonlinearSWE::GetNormals, this);
93 m_riemannSolver->SetScalar("depth", &NonlinearSWE::GetDepth, this);
94
95 // Concluding initialisation of advection operators
96 m_advection->SetRiemannSolver(m_riemannSolver);
97 m_advection->InitObject(m_session, m_fields);
98 break;
99 }
100 default:
101 {
102 ASSERTL0(false, "Unsupported projection type.");
103 break;
104 }
105 }
106
110}
111
113 const Array<OneD, const Array<OneD, NekDouble>> &inarray,
114 Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble time)
115{
116 int ndim = m_spacedim;
117 int nvariables = inarray.size();
118 int nq = GetTotPoints();
119
120 switch (m_projectionType)
121 {
123 {
124 //-------------------------------------------------------
125 // Compute the DG advection including the numerical flux
126 // by using SolverUtils/Advection
127 // Input and output in physical space
129 inarray, outarray, time);
130 //-------------------------------------------------------
131
132 //-------------------------------------------------------
133 // negate the outarray since moving terms to the rhs
134 for (int i = 0; i < nvariables; ++i)
135 {
136 Vmath::Neg(nq, outarray[i], 1);
137 }
138 //-------------------------------------------------------
139
140 //-------------------------------------------------
141 // Add "source terms"
142 // Input and output in physical space
143
144 // Coriolis forcing
145 if (m_coriolis.size() != 0)
146 {
147 AddCoriolis(inarray, outarray);
148 }
149
150 // Variable Depth
151 if (m_constantDepth != true)
152 {
153 AddVariableDepth(inarray, outarray);
154 }
155 //-------------------------------------------------
156 }
157 break;
159 {
160 //-------------------------------------------------------
161 // Compute the fluxvector in physical space
163 nvariables);
164
165 for (int i = 0; i < nvariables; ++i)
166 {
167 fluxvector[i] = Array<OneD, Array<OneD, NekDouble>>(ndim);
168 for (int j = 0; j < ndim; ++j)
169 {
170 fluxvector[i][j] = Array<OneD, NekDouble>(nq);
171 }
172 }
173
174 NonlinearSWE::GetFluxVector(inarray, fluxvector);
175 //-------------------------------------------------------
176
177 //-------------------------------------------------------
178 // Take the derivative of the flux terms
179 // and negate the outarray since moving terms to the rhs
180 Array<OneD, NekDouble> tmp0(nq);
181 Array<OneD, NekDouble> tmp1(nq);
182
183 for (int i = 0; i < nvariables; ++i)
184 {
186 fluxvector[i][0], tmp0);
188 fluxvector[i][1], tmp1);
189 Vmath::Vadd(nq, tmp0, 1, tmp1, 1, outarray[i], 1);
190 Vmath::Neg(nq, outarray[i], 1);
191 }
192
193 //-------------------------------------------------
194 // Add "source terms"
195 // Input and output in physical space
196
197 // Coriolis forcing
198 if (m_coriolis.size() != 0)
199 {
200 AddCoriolis(inarray, outarray);
201 }
202
203 // Variable Depth
204 if (m_constantDepth != true)
205 {
206 AddVariableDepth(inarray, outarray);
207 }
208 //-------------------------------------------------
209 }
210 break;
211 default:
212 ASSERTL0(false, "Unknown projection scheme for the NonlinearSWE");
213 break;
214 }
215}
216
218{
220 SolverUtils::AddSummaryItem(s, "Variables", "h should be in field[0]");
221 SolverUtils::AddSummaryItem(s, "", "hu should be in field[1]");
222 SolverUtils::AddSummaryItem(s, "", "hv should be in field[2]");
223}
224
225// Physfield in conservative Form
227 const Array<OneD, const Array<OneD, NekDouble>> &physfield,
229{
230 int nq = m_fields[0]->GetTotPoints();
231
232 NekDouble g = m_g;
234
235 // Flux vector for the mass equation
236 for (int i = 0; i < m_spacedim; ++i)
237 {
238 velocity[i] = Array<OneD, NekDouble>(nq);
239 Vmath::Vcopy(nq, physfield[i + 1], 1, flux[0][i], 1);
240 }
241
242 GetVelocityVector(physfield, velocity);
243
244 // Put (0.5 g h h) in tmp
246 Vmath::Vmul(nq, physfield[0], 1, physfield[0], 1, tmp, 1);
247 Vmath::Smul(nq, 0.5 * g, tmp, 1, tmp, 1);
248
249 // Flux vector for the momentum equations
250 for (int i = 0; i < m_spacedim; ++i)
251 {
252 for (int j = 0; j < m_spacedim; ++j)
253 {
254 Vmath::Vmul(nq, velocity[j], 1, physfield[i + 1], 1, flux[i + 1][j],
255 1);
256 }
257
258 // Add (0.5 g h h) to appropriate field
259 Vmath::Vadd(nq, flux[i + 1][i], 1, tmp, 1, flux[i + 1][i], 1);
260 }
261}
262
263/**
264 * @brief Compute the velocity field \f$ \mathbf{v} \f$ given the momentum
265 * \f$ h\mathbf{v} \f$.
266 *
267 * @param physfield Momentum field.
268 * @param velocity Velocity field.
269 */
271 const Array<OneD, const Array<OneD, NekDouble>> &physfield,
273{
274 const int npts = physfield[0].size();
275
276 for (int i = 0; i < m_spacedim; ++i)
277 {
278 Vmath::Vdiv(npts, physfield[1 + i], 1, physfield[0], 1, velocity[i], 1);
279 }
280}
281
282// physarray contains the conservative variables
284 const Array<OneD, const Array<OneD, NekDouble>> &physarray,
286{
287 int ncoeffs = GetNcoeffs();
288 int nq = GetTotPoints();
289
291 Array<OneD, NekDouble> mod(ncoeffs);
292
293 switch (m_projectionType)
294 {
296 {
297 for (int i = 0; i < m_spacedim; ++i)
298 {
299 Vmath::Vmul(nq, m_bottomSlope[i], 1, physarray[0], 1, tmp, 1);
300 Vmath::Smul(nq, m_g, tmp, 1, tmp, 1);
301 m_fields[0]->IProductWRTBase(tmp, mod);
302 m_fields[0]->MultiplyByElmtInvMass(mod, mod);
303 m_fields[0]->BwdTrans(mod, tmp);
304 Vmath::Vadd(nq, tmp, 1, outarray[i + 1], 1, outarray[i + 1], 1);
305 }
306 }
307 break;
309 {
310 for (int i = 0; i < m_spacedim; ++i)
311 {
312 Vmath::Vmul(nq, m_bottomSlope[i], 1, physarray[0], 1, tmp, 1);
313 Vmath::Smul(nq, m_g, tmp, 1, tmp, 1);
314 Vmath::Vadd(nq, tmp, 1, outarray[i + 1], 1, outarray[i + 1], 1);
315 }
316 }
317 break;
318 default:
319 ASSERTL0(false, "Unknown projection scheme for the NonlinearSWE");
320 break;
321 }
322}
323
324} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
void DefineProjection(FuncPointerT func, ObjectPointerT obj)
void DefineOdeRhs(FuncPointerT func, ObjectPointerT obj)
void DefineImplicitSolve(FuncPointerT func, ObjectPointerT obj)
static std::string className
Name of class.
Definition: NonlinearSWE.h:60
void GetVelocityVector(const Array< OneD, const Array< OneD, NekDouble > > &physfield, Array< OneD, Array< OneD, NekDouble > > &velocity)
Compute the velocity field given the momentum .
void v_GenerateSummary(SolverUtils::SummaryList &s) override
Print a summary of time stepping parameters.
void AddVariableDepth(const Array< OneD, const Array< OneD, NekDouble > > &physarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
void GetFluxVector(const Array< OneD, const Array< OneD, NekDouble > > &physfield, Array< OneD, Array< OneD, Array< OneD, NekDouble > > > &flux)
static SolverUtils::EquationSystemSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
Creates an instance of this class.
Definition: NonlinearSWE.h:49
NonlinearSWE(const LibUtilities::SessionReaderSharedPtr &pSession, const SpatialDomains::MeshGraphSharedPtr &pGraph)
void v_InitObject(bool DeclareFields=true) override
Init object for UnsteadySystem class.
void v_DoOdeRhs(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time) override
Base class for unsteady solvers.
NekDouble m_g
Acceleration of gravity.
SolverUtils::RiemannSolverSharedPtr m_riemannSolver
Array< OneD, Array< OneD, NekDouble > > m_bottomSlope
const Array< OneD, NekDouble > & GetDepth()
void AddCoriolis(const Array< OneD, const Array< OneD, NekDouble > > &physarray, Array< OneD, Array< OneD, NekDouble > > &outarray)
void DoOdeProjection(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &outarray, const NekDouble time)
SolverUtils::AdvectionSharedPtr m_advection
bool m_constantDepth
Indicates if constant depth case.
void v_GenerateSummary(SolverUtils::SummaryList &s) override
Print a summary of time stepping parameters.
Array< OneD, NekDouble > m_coriolis
Coriolis force.
void DoImplicitSolve(const Array< OneD, const Array< OneD, NekDouble > > &inpnts, Array< OneD, Array< OneD, NekDouble > > &outpnt, const NekDouble time, const NekDouble lambda)
void v_InitObject(bool DeclareFields=true) override
Init object for UnsteadySystem class.
const Array< OneD, const Array< OneD, NekDouble > > & GetNormals()
const Array< OneD, const Array< OneD, NekDouble > > & GetVecLocs()
int m_spacedim
Spatial dimension (>= expansion dim).
Array< OneD, MultiRegions::ExpListSharedPtr > m_fields
Array holding all dependent variables.
LibUtilities::SessionReaderSharedPtr m_session
The session reader.
SOLVER_UTILS_EXPORT int GetNcoeffs()
enum MultiRegions::ProjectionType m_projectionType
Type of projection; e.g continuous or discontinuous.
SOLVER_UTILS_EXPORT int GetTotPoints()
LibUtilities::TimeIntegrationSchemeOperators m_ode
The time integration scheme operators to use.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
MultiRegions::Direction const DirCartesianMap[]
Definition: ExpList.h:87
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Definition: Advection.cpp:43
std::vector< std::pair< std::string, std::string > > SummaryList
Definition: Misc.h:46
EquationSystemFactory & GetEquationSystemFactory()
void AddSummaryItem(SummaryList &l, const std::string &name, const std::string &value)
Adds a summary item to the summary info list.
Definition: Misc.cpp:47
RiemannSolverFactory & GetRiemannSolverFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:174
static Array< OneD, Array< OneD, NekDouble > > NullNekDoubleArrayOfArray
double NekDouble
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.hpp:72
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.hpp:292
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
void Smul(int n, const T alpha, const T *x, const int incx, T *y, const int incy)
Scalar multiply y = alpha*x.
Definition: Vmath.hpp:100
void Vdiv(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x/y.
Definition: Vmath.hpp:126
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825