Nektar++
UpwindPulseSolver.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: UpwindPulseSolver.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: Upwind pulse Riemann solver.
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
36 
37 namespace Nektar
38 {
41  "UpwindPulse", UpwindPulseSolver::create, "UpwindPulseSolver");
42 
45  : RiemannSolver(pSession)
46 {
47 }
48 
49 /**
50  * Calculates the third term of the weak form (1): numerical flux
51  * at boundary \f$ \left[ \mathbf{\psi}^{\delta} \cdot \{
52  * \mathbf{F}^u - \mathbf{F}(\mathbf{U}^{\delta}) \}
53  * \right]_{x_e^l}^{x_eû} \f$
54  */
56  const int nDim, const Array<OneD, const Array<OneD, NekDouble>> &Fwd,
57  const Array<OneD, const Array<OneD, NekDouble>> &Bwd,
59 {
60  int i;
61  int nTracePts = Fwd[0].num_elements();
62 
63  ASSERTL1(CheckScalars("A0"), "A0 not defined.");
64  const Array<OneD, NekDouble> &A0 = m_scalars["A0"]();
65 
66  ASSERTL1(CheckScalars("beta"), "beta not defined.");
67  const Array<OneD, NekDouble> &beta = m_scalars["beta"]();
68 
69  ASSERTL1(CheckScalars("N"), "N not defined.");
70  const Array<OneD, NekDouble> &N = m_scalars["N"]();
71 
72  for (i = 0; i < nTracePts; ++i)
73  {
74  RiemannSolverUpwind(Fwd[0][i], Fwd[1][i], Bwd[0][i], Bwd[1][i],
75  flux[0][i], flux[1][i], A0[i], beta[i], N[i]);
76  }
77 }
78 
79 /**
80  * Riemann solver for upwinding at an interface between two
81  * elements. Uses the characteristic variables for calculating
82  * the upwinded state \f$(A_u,u_u)\f$ from the left
83  * \f$(A_L,u_L)\f$ and right state \f$(A_R,u_R)\f$. Returns the
84  * upwinded flux $\mathbf{F}^u$ needed for the weak formulation
85  * (1). Details can be found in "Pulse wave propagation in the
86  * human vascular system", section 3.3
87  *
88  */
90  NekDouble AR, NekDouble uR,
91  NekDouble &Aflux, NekDouble &uflux,
92  NekDouble A_0, NekDouble beta,
93  NekDouble n)
94 {
96  Array<OneD, NekDouble> upwindedphysfield(2);
97  NekDouble cL = 0.0;
98  NekDouble cR = 0.0;
99  NekDouble p = 0.0;
100  NekDouble p_t = 0.0;
101 
102  ASSERTL1(CheckParams("rho"), "rho not defined.");
103  NekDouble rho = m_params["rho"]();
104 
105  ASSERTL1(CheckParams("pext"), "pext not defined.");
106  NekDouble pext = m_params["pext"]();
107 
108  // Compute the wave speeds. The use of the normal here allows
109  // for the definition of the characteristics to be inverted
110  // (and hence the left and right state) if n is in the -ve
111  // x-direction. This means we end up with the positive
112  // defintion of the flux which has to therefore be multiplied
113  // by the normal at the end of the methods This is a bit of a
114  // mind twister but is efficient from a coding perspective.
115  cL = sqrt(beta * sqrt(AL) / (2 * rho)) * n;
116  cR = sqrt(beta * sqrt(AR) / (2 * rho)) * n;
117 
118  ASSERTL1(fabs(cL + cR) > fabs(uL + uR), "Conditions are not sub-sonic");
119 
120  // If upwinding from left and right for subsonic domain
121  // then know characteristics immediately
122  W[0] = uL + 4 * cL;
123  W[1] = uR - 4 * cR;
124 
125  // Calculate conservative variables from characteristics
126  NekDouble w0mw1 = 0.25 * (W[0] - W[1]);
127  NekDouble fac = rho / (2 * beta);
128  w0mw1 *= w0mw1; // squared
129  w0mw1 *= w0mw1; // fourth power
130  fac *= fac; // squared
131  upwindedphysfield[0] = w0mw1 * fac;
132  upwindedphysfield[1] = 0.5 * (W[0] + W[1]);
133 
134  // Compute the fluxes multipled by the normal.
135  Aflux = upwindedphysfield[0] * upwindedphysfield[1] * n;
136  p = pext + beta * (sqrt(upwindedphysfield[0]) - sqrt(A_0));
137  p_t = 0.5 * (upwindedphysfield[1] * upwindedphysfield[1]) + p / rho;
138  uflux = p_t * n;
139 }
140 }
SOLVER_UTILS_EXPORT bool CheckScalars(std::string name)
Determine whether a scalar has been defined in m_scalars.
virtual void v_Solve(const int nDim, const Array< OneD, const Array< OneD, NekDouble >> &Fwd, const Array< OneD, const Array< OneD, NekDouble >> &Bwd, Array< OneD, Array< OneD, NekDouble >> &flux)
UpwindPulseSolver(const LibUtilities::SessionReaderSharedPtr &pSession)
std::map< std::string, RSScalarFuncType > m_scalars
Map of scalar function types.
void RiemannSolverUpwind(NekDouble AL, NekDouble uL, NekDouble AR, NekDouble uR, NekDouble &Aflux, NekDouble &uflux, NekDouble A_0, NekDouble beta, NekDouble n)
RiemannSolverFactory & GetRiemannSolverFactory()
double NekDouble
static std::string solverName
static RiemannSolverSharedPtr create(const LibUtilities::SessionReaderSharedPtr &pSession)
The RiemannSolver class provides an abstract interface under which solvers for various Riemann proble...
Definition: RiemannSolver.h:59
std::map< std::string, RSParamFuncType > m_params
Map of parameter function types.
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:199
SOLVER_UTILS_EXPORT bool CheckParams(std::string name)
Determine whether a parameter has been defined in m_params.
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Definition: ErrorUtil.hpp:250
std::shared_ptr< SessionReader > SessionReaderSharedPtr