Nektar++
RCROutflow.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: RCROutflow.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:
33//
34///////////////////////////////////////////////////////////////////////////////
35
38
39using namespace std;
40
41namespace Nektar
42{
43
44std::string RCROutflow::className =
46 "RCR-terminal", RCROutflow::create, "RCR outflow boundary condition");
47
51 : PulseWaveBoundary(pVessel, pSession, pressureArea)
52{
53 m_session->LoadParameter("TimeStep", m_timestep);
54}
55
57{
58}
59
61 const Array<OneD, const Array<OneD, NekDouble>> &inarray,
64 Array<OneD, Array<OneD, NekDouble>> &alpha, const NekDouble time, int omega,
65 int offset, int n)
66{
67 boost::ignore_unused(time);
68
69 NekDouble A_r = 0.0;
70 NekDouble u_r = 0.0;
71 NekDouble A_u = 0.0;
72 NekDouble u_u = 0.0;
73 NekDouble A_l = 0.0;
74 NekDouble u_l = 0.0;
75 NekDouble c_0 = 0.0;
76 NekDouble R1 = 0.0;
77 NekDouble R2 = 0.0;
78 NekDouble POut = m_pout;
79 NekDouble rho = m_rho;
80
82
83 // Pointers to the domains
84 vessel[0] = m_vessels[2 * omega];
85 vessel[1] = m_vessels[2 * omega + 1];
86
87 /* Find the terminal RCR boundary condition and calculates
88 the updated velocity and area as well as the updated
89 boundary conditions */
90
91 /* Load terminal resistance, capacitance, outflow pressure,
92 and number of points from the input file */
93 NekDouble RT = ((vessel[0]->GetBndCondExpansions())[n])->GetCoeffs()[0];
94 NekDouble C = ((vessel[1]->GetBndCondExpansions())[n])->GetCoeffs()[0];
95 int nq = vessel[0]->GetTotPoints();
96
97 // Get the values of all variables needed for the Riemann problem
98 A_l = inarray[0][offset + nq - 1];
99 u_l = inarray[1][offset + nq - 1];
100
101 // Goes through the first resistance; calculates c_0
102 m_pressureArea->GetC(c_0, beta[omega][nq - 1], A_0[omega][nq - 1],
103 A_0[omega][nq - 1], alpha[omega][nq - 1]);
104
105 /* Calculate R1 and R2, R1 being calculated so as
106 to eliminate reflections in the vessel */
107 R1 = rho * c_0 / A_0[omega][nq - 1];
108
109 if (R1 > 0.9 * RT)
110 {
111 // In case the resistance is lower than the characteristic impedance.
112 R1 = 0.9 * RT;
113 }
114
115 R2 = RT - R1;
116
117 // Call the R RiemannSolver
118 R_RiemannSolver(R1, A_l, u_l, A_0[omega][nq - 1], beta[omega][nq - 1],
119 alpha[omega][nq - 1], m_pc, A_u, u_u);
120
121 /* Fix the boundary conditions in the virtual region to ensure
122 upwind state matches the boundary condition at the next time step */
123 A_r = A_l;
124 u_r = 2 * u_u - u_l;
125
126 /* Goes through the CR system, which
127 just updates the pressure pc */
128 m_pc += (m_timestep / C) * (A_u * u_u - (m_pc - POut) / R2);
129
130 // Store the updated values
131 (vessel[0]->UpdateBndCondExpansion(n))->UpdatePhys()[0] = A_r;
132 (vessel[1]->UpdateBndCondExpansion(n))->UpdatePhys()[0] = u_r;
133}
134
136 NekDouble A_0, NekDouble beta, NekDouble alpha,
137 NekDouble POut, NekDouble &A_u, NekDouble &u_u)
138{
139 NekDouble W1 = 0.0;
140 NekDouble c = 0.0;
141 NekDouble cL = 0.0;
142 NekDouble I = 0.0;
143 NekDouble A_calc = 0.0;
144 NekDouble FA = 0.0;
145 NekDouble dFdA = 0.0;
146 NekDouble delta_A_calc = 0.0;
147 NekDouble P = 0.0;
148 NekDouble rho = m_rho;
149
150 int proceed = 1;
151 int iter = 0;
152 int MAX_ITER = 100;
153
154 // Tolerances for the algorithm
155 NekDouble Tol = 1.0E-10;
156
157 // Calculate the wave speed
158 m_pressureArea->GetC(cL, beta, A_l, A_0, alpha);
159
160 // Riemann invariant \f$W_1(Al,ul)\f$
161 m_pressureArea->GetW1(W1, u_l, beta, A_l, A_0, alpha);
162
163 // Newton Iteration (Area only)
164 A_calc = A_l;
165 while ((proceed) && (iter < MAX_ITER))
166 {
167 iter += 1;
168
169 m_pressureArea->GetPressure(P, beta, A_calc, A_0, 0, 0, alpha);
170 m_pressureArea->GetC(c, beta, A_calc, A_0, alpha);
171 m_pressureArea->GetCharIntegral(I, beta, A_calc, A_0, alpha);
172
173 FA = R * A_calc * (W1 - I) - P + POut;
174 dFdA = R * (W1 - I - c) - c * c * rho / A_calc;
175 delta_A_calc = FA / dFdA;
176 A_calc -= delta_A_calc;
177
178 if (sqrt(delta_A_calc * delta_A_calc) < Tol)
179 {
180 proceed = 0;
181 }
182 }
183
184 m_pressureArea->GetPressure(P, beta, A_calc, A_0, 0, 0, alpha);
185
186 // Obtain u_u and A_u
187 u_u = (P - POut) / (R * A_calc);
188 A_u = A_calc;
189}
190
191} // namespace Nektar
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
Array< OneD, MultiRegions::ExpListSharedPtr > m_vessels
PulseWavePressureAreaSharedPtr m_pressureArea
LibUtilities::SessionReaderSharedPtr m_session
virtual ~RCROutflow()
Definition: RCROutflow.cpp:56
void R_RiemannSolver(NekDouble R, NekDouble A_l, NekDouble u_l, NekDouble A_0, NekDouble beta, NekDouble alpha, NekDouble POut, NekDouble &A_u, NekDouble &u_u)
Definition: RCROutflow.cpp:135
NekDouble m_pc
Definition: RCROutflow.h:87
static std::string className
Definition: RCROutflow.h:66
virtual void v_DoBoundary(const Array< OneD, const Array< OneD, NekDouble > > &inarray, Array< OneD, Array< OneD, NekDouble > > &A_0, Array< OneD, Array< OneD, NekDouble > > &beta, Array< OneD, Array< OneD, NekDouble > > &alpha, const NekDouble time, int omega, int offset, int n) override
Definition: RCROutflow.cpp:60
RCROutflow(Array< OneD, MultiRegions::ExpListSharedPtr > pVessel, const LibUtilities::SessionReaderSharedPtr pSession, PulseWavePressureAreaSharedPtr pressureArea)
Definition: RCROutflow.cpp:48
NekDouble m_timestep
Definition: RCROutflow.h:86
static PulseWaveBoundarySharedPtr create(Array< OneD, MultiRegions::ExpListSharedPtr > &pVessel, const LibUtilities::SessionReaderSharedPtr &pSession, PulseWavePressureAreaSharedPtr &pressureArea)
Definition: RCROutflow.h:56
std::shared_ptr< SessionReader > SessionReaderSharedPtr
@ beta
Gauss Radau pinned at x=-1,.
Definition: PointsType.h:61
@ P
Monomial polynomials .
Definition: BasisType.h:64
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
std::shared_ptr< PulseWavePressureArea > PulseWavePressureAreaSharedPtr
BoundaryFactory & GetBoundaryFactory()
double NekDouble
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:294