Nektar++
PulseWavePropagation.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File PulseWavePropagation.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: Pulse Wave Propagation solve routines based on the weak
33 // formulation (1):
34 //
35 ///////////////////////////////////////////////////////////////////////////////
36 
37 #include <iostream>
38 
41 
42 using namespace std;
43 
44 namespace Nektar
45 {
46 
47 string PulseWavePropagation::className =
49  "PulseWavePropagation", PulseWavePropagation::create,
50  "Pulse Wave Propagation equation.");
51 /**
52  * @class PulseWavePropagation
53  *
54  * Set up the routines based on the weak formulation from
55  * "Computational Modelling of 1D blood flow with variable
56  * mechanical properties" by S. J. Sherwin et al. The weak
57  * formulation (1) reads:
58  * \f$ \sum_{e=1}^{N_{el}} \left[ \left( \frac{\partial \mathbf{U}^{\delta}
59  * }{\partial t} , \mathbf{\psi}^{\delta} \right)_{\Omega_e} - \left(
60  * \frac{\partial \mathbf{F(\mathbf{U})}^{\delta} }
61  * {\partial x}, \mathbf{\psi}^{\delta} \right)_{\Omega_e} + \left[
62  * \mathbf{\psi}^{\delta} \cdot \{ \mathbf{F}^u -
63  * \mathbf{F}(\mathbf{U}^{\delta}) \} \right]_{x_e^l}^{x_eû} \right] = 0 \f$
64  */
65 PulseWavePropagation::PulseWavePropagation(
68  : PulseWaveSystem(pSession, pGraph)
69 {
70 }
71 
72 void PulseWavePropagation::v_InitObject(bool DeclareField)
73 {
74  // Will set up an array of vessels/fields in PulseWaveSystem::v_InitObject
75  // so set DeclareField to false so that the fields are not set up in
76  // EquationSystem unnecessarily. Note the number of fields in Equation
77  // system is related to the number of variables. The number of vessels is
78  // therefore held in PulwWaveSystem.
80 
81  if (m_session->DefinesSolverInfo("PressureArea"))
82  {
84  m_session->GetSolverInfo("PressureArea"), m_vessels, m_session);
85  }
86  else
87  {
89  "Beta", m_vessels, m_session);
90  }
91 
93  {
96  }
97  else
98  {
99  ASSERTL0(false, "Implicit Pulse Wave Propagation not set up.");
100  }
101 
102  // Create advection object
103  string advName;
104  string riemName;
105  switch (m_upwindTypePulse)
106  {
107  case eUpwindPulse:
108  {
109  advName = "WeakDG";
110  riemName = "UpwindPulse";
111  }
112  break;
113  default:
114  {
115  ASSERTL0(false, "populate switch statement for upwind flux");
116  }
117  break;
118  }
119  m_advObject =
121  m_advObject->SetFluxVector(&PulseWavePropagation::GetFluxVector, this);
123  riemName, m_session);
124  m_riemannSolver->SetScalar("A0", &PulseWavePropagation::GetA0, this);
125  m_riemannSolver->SetScalar("beta", &PulseWavePropagation::GetBeta, this);
126  m_riemannSolver->SetScalar("alpha", &PulseWavePropagation::GetAlpha, this);
127  m_riemannSolver->SetScalar("N", &PulseWavePropagation::GetN, this);
128  m_riemannSolver->SetParam("rho", &PulseWavePropagation::GetRho, this);
130  this);
131 
132  m_advObject->SetRiemannSolver(m_riemannSolver);
133  m_advObject->InitObject(m_session, m_fields);
134 }
135 
137 {
138 }
139 
140 /**
141  * Computes the right hand side of (1). The RHS is everything
142  * except the term that contains the time derivative
143  * \f$\frac{\partial \mathbf{U}}{\partial t}\f$. In case of a
144  * Discontinuous Galerkin projection, m_advObject->Advect
145  * will be called
146  *
147  */
149  const Array<OneD, const Array<OneD, NekDouble>> &inarray,
150  Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble time)
151 {
152  int i;
153 
155 
156  // Dummy array for WeakDG advection
158 
159  // Output array for advection
161 
162  int cnt = 0;
163 
164  // Set up Inflow and Outflow boundary conditions.
165  SetPulseWaveBoundaryConditions(inarray, outarray, time);
166 
167  // Set up any interface conditions and write into boundary condition
169 
170  // do advection evaluation in all domains
171  for (int omega = 0; omega < m_nDomains; ++omega)
172  {
173  LibUtilities::Timer timer;
174  m_currentDomain = omega;
175  int nq = m_vessels[omega * m_nVariables]->GetTotPoints();
176 
177  timer.Start();
178  for (i = 0; i < m_nVariables; ++i)
179  {
180  physarray[i] = inarray[i] + cnt;
181  out[i] = outarray[i] + cnt;
182  }
183 
184  for (i = 0; i < m_nVariables; ++i)
185  {
186  m_fields[i] = m_vessels[omega * m_nVariables + i];
187  }
188 
189  m_advObject->Advect(m_nVariables, m_fields, advVel, physarray, out,
190  time);
191  for (i = 0; i < m_nVariables; ++i)
192  {
193  Vmath::Neg(nq, out[i], 1);
194  }
195  timer.Stop();
196  timer.AccumulateRegion("PulseWavePropagation:_DoOdeRHS", 1);
197  cnt += nq;
198  }
199 }
200 
202  const Array<OneD, const Array<OneD, NekDouble>> &inarray,
203  Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble time)
204 {
205  // Just copy over array
206  for (int i = 0; i < m_nVariables; ++i)
207  {
208  Vmath::Vcopy(inarray[i].size(), inarray[i], 1, outarray[i], 1);
209  }
210 }
211 
212 /**
213  * Does the projection between ... space and the ... space. Also checks for
214  *Q-inflow boundary conditions at the inflow of the current arterial segment and
215  *applies the Q-inflow if specified
216  */
218  const Array<OneD, const Array<OneD, NekDouble>> &inarray,
219  Array<OneD, Array<OneD, NekDouble>> &outarray, const NekDouble time)
220 
221 {
222  int omega;
223 
225 
226  int offset = 0;
227 
228  // This will be moved to the RCR boundary condition once factory is setup
229  if (time == 0)
230  {
232 
233  for (omega = 0; omega < m_nDomains; ++omega)
234  {
235  vessel[0] = m_vessels[2 * omega];
236  vessel[1] = m_vessels[2 * omega + 1];
237 
238  for (int j = 0; j < 2; ++j)
239  {
240  std::string BCType;
241 
242  if (j < vessel[0]->GetBndConditions().size())
243  {
244  BCType = vessel[0]->GetBndConditions()[j]->GetUserDefined();
245  }
246 
247  // if no condition given define it to be NoUserDefined
248  if (BCType.empty() || BCType == "Interface")
249  {
250  BCType = "NoUserDefined";
251  }
252 
253  m_Boundary[2 * omega + j] = GetBoundaryFactory().CreateInstance(
255 
256  // turn on time dependent BCs
257  if (BCType == "Q-inflow")
258  {
259  vessel[0]->GetBndConditions()[j]->SetIsTimeDependent(true);
260  }
261  else if (BCType == "A-inflow")
262  {
263  vessel[0]->GetBndConditions()[j]->SetIsTimeDependent(true);
264  }
265  else if (BCType == "U-inflow")
266  {
267  vessel[1]->GetBndConditions()[j]->SetIsTimeDependent(true);
268  }
269  else if (BCType == "RCR-terminal")
270  {
271  vessel[0]->GetBndConditions()[j]->SetIsTimeDependent(true);
272  }
273  }
274  }
275  }
276 
277  SetBoundaryConditions(time);
278 
279  // Loop over all vessels and set boundary conditions
280  LibUtilities::Timer timer;
281  for (omega = 0; omega < m_nDomains; ++omega)
282  {
283  timer.Start();
284  for (int n = 0; n < 2; ++n)
285  {
286  m_Boundary[2 * omega + n]->DoBoundary(
287  inarray, m_A_0, m_beta, m_alpha, time, omega, offset, n);
288  }
289 
290  offset += m_vessels[2 * omega]->GetTotPoints();
291  timer.Stop();
292  timer.AccumulateRegion("PulseWavePropagation:_SetBCs", 1);
293  }
294 }
295 
296 /**
297  * Calculates the second term of the weak form (1): \f$
298  * \left( \frac{\partial \mathbf{F(\mathbf{U})}^{\delta}
299  * }{\partial x}, \mathbf{\psi}^{\delta} \right)_{\Omega_e}
300  * \f$
301  * The variables of the system are $\mathbf{U} = [A,u]^T$
302  * physfield[0] = A physfield[1] = u
303  * flux[0] = F[0] = A*u flux[1] = F[1] = u^2/2 + p/rho
304  */
306  const Array<OneD, Array<OneD, NekDouble>> &physfield,
308 {
309  int nq = m_vessels[m_currentDomain * m_nVariables]->GetTotPoints();
310  NekDouble domain = m_currentDomain;
311  m_pressure[domain] = Array<OneD, NekDouble>(nq);
312  Array<OneD, NekDouble> dAUdx(nq);
313  NekDouble viscoelasticGradient = 0.0;
314 
315  LibUtilities::Timer timer;
316 
317  for (int j = 0; j < nq; ++j)
318  {
319  timer.Start();
320  flux[0][0][j] = physfield[0][j] * physfield[1][j];
321  timer.Stop();
322  timer.AccumulateRegion("PulseWavePropagation:GetFluxVector-flux", 3);
323  }
324 
325  // d/dx of AU, for the viscoelastic tube law and extra fields
326  m_fields[0]->PhysDeriv(flux[0][0], dAUdx);
327 
328  for (int j = 0; j < nq; ++j)
329  {
330  if ((j == 0) || (j == nq - 1))
331  {
332  viscoelasticGradient = dAUdx[j];
333  }
334  else
335  {
336  viscoelasticGradient = (dAUdx[j] + dAUdx[j + 1]) / 2;
337  }
338 
339  m_pressureArea->GetPressure(m_pressure[domain][j], m_beta[domain][j],
340  physfield[0][j], m_A_0[domain][j],
341  viscoelasticGradient, m_gamma[domain][j],
342  m_alpha[domain][j]);
343 
344  flux[1][0][j] = physfield[1][j] * physfield[1][j] / 2 +
345  m_pressure[domain][j] / m_rho;
346  }
347 
348  m_session->MatchSolverInfo("OutputExtraFields", "True", extraFields, true);
349 
350  if (extraFields)
351  {
352  /*
353  Calculates wave speed and characteristic variables.
354 
355  Ideally this should be moved to PulseWaveSystem, but it's easiest to
356  implement here.
357  */
358  int counter = 0;
359 
360  m_PWV[domain] = Array<OneD, NekDouble>(nq);
361  m_W1[domain] = Array<OneD, NekDouble>(nq);
362  m_W2[domain] = Array<OneD, NekDouble>(nq);
363 
364  for (int j = 0; j < nq; ++j)
365  {
366  m_pressureArea->GetC(m_PWV[domain][j], m_beta[domain][j],
367  physfield[0][counter + j], m_A_0[domain][j],
368  m_alpha[domain][j]);
369  m_pressureArea->GetW1(m_W1[domain][j], physfield[1][counter + j],
370  m_beta[domain][j], physfield[0][counter + j],
371  m_A_0[domain][j], m_alpha[domain][j]);
372  m_pressureArea->GetW2(m_W2[domain][j], physfield[1][counter + j],
373  m_beta[domain][j], physfield[0][counter + j],
374  m_A_0[domain][j], m_alpha[domain][j]);
375  }
376 
377  counter += nq;
378  }
379 }
380 
382 {
384 }
385 
387 {
389 }
390 
392 {
394 }
395 
397 {
399 }
400 
402 {
403  return m_rho;
404 }
405 
407 {
408  return m_nDomains;
409 }
410 
411 /**
412  * Print summary routine, calls virtual routine reimplemented in
413  * UnsteadySystem
414  */
416 {
418 }
419 
420 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
tKey RegisterCreatorFunction(tKey idKey, CreatorFunction classCreator, std::string pDesc="")
Register a class with the factory.
Definition: NekFactory.hpp:198
tBaseSharedPtr CreateInstance(tKey idKey, tParam... args)
Create an instance of the class referred to by idKey.
Definition: NekFactory.hpp:144
void DefineProjection(FuncPointerT func, ObjectPointerT obj)
void DefineOdeRhs(FuncPointerT func, ObjectPointerT obj)
void AccumulateRegion(std::string, int iolevel=0)
Accumulate elapsed time for a region.
Definition: Timer.cpp:73
Array< OneD, NekDouble > & GetAlpha()
virtual void v_InitObject(bool DeclareField=false)
SolverUtils::RiemannSolverSharedPtr m_riemannSolver
SolverUtils::AdvectionSharedPtr m_advObject
void GetFluxVector(const Array< OneD, Array< OneD, NekDouble >> &physfield, Array< OneD, Array< OneD, Array< OneD, NekDouble >>> &flux)
DG Pulse Wave Propagation routines:
Array< OneD, PulseWaveBoundarySharedPtr > m_Boundary
void SetPulseWaveBoundaryConditions(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray, const NekDouble time)
Array< OneD, NekDouble > & GetN()
virtual void v_GenerateSummary(SolverUtils::SummaryList &s)
Array< OneD, NekDouble > & GetA0()
void DoOdeProjection(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray, const NekDouble time)
Array< OneD, NekDouble > & GetBeta()
void DoOdeRhs(const Array< OneD, const Array< OneD, NekDouble >> &inarray, Array< OneD, Array< OneD, NekDouble >> &outarray, const NekDouble time)
Base class for unsteady solvers.
Array< OneD, Array< OneD, NekDouble > > m_A_0
Array< OneD, Array< OneD, NekDouble > > m_beta_trace
void EnforceInterfaceConditions(const Array< OneD, const Array< OneD, NekDouble >> &fields)
Array< OneD, Array< OneD, NekDouble > > m_W2
Array< OneD, Array< OneD, NekDouble > > m_trace_fwd_normal
PulseWavePressureAreaSharedPtr m_pressureArea
Array< OneD, Array< OneD, NekDouble > > m_W1
Array< OneD, Array< OneD, NekDouble > > m_alpha_trace
virtual void v_InitObject(bool DeclareField=false)
UpwindTypePulse m_upwindTypePulse
Array< OneD, Array< OneD, NekDouble > > m_A_0_trace
Array< OneD, Array< OneD, NekDouble > > m_pressure
Array< OneD, Array< OneD, NekDouble > > m_gamma
Array< OneD, Array< OneD, NekDouble > > m_alpha
Array< OneD, Array< OneD, NekDouble > > m_PWV
Array< OneD, MultiRegions::ExpListSharedPtr > m_vessels
Array< OneD, Array< OneD, NekDouble > > m_beta
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 void SetBoundaryConditions(NekDouble time)
Evaluates the boundary conditions at the given time.
LibUtilities::TimeIntegrationSchemeOperators m_ode
The time integration scheme operators to use.
bool m_explicitAdvection
Indicates if explicit or implicit treatment of advection is used.
virtual SOLVER_UTILS_EXPORT void v_GenerateSummary(SummaryList &s)
Print a summary of time stepping parameters.
std::shared_ptr< SessionReader > SessionReaderSharedPtr
AdvectionFactory & GetAdvectionFactory()
Gets the factory for initialising advection objects.
Definition: Advection.cpp:47
std::vector< std::pair< std::string, std::string > > SummaryList
Definition: Misc.h:48
EquationSystemFactory & GetEquationSystemFactory()
RiemannSolverFactory & GetRiemannSolverFactory()
std::shared_ptr< MeshGraph > MeshGraphSharedPtr
Definition: MeshGraph.h:172
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:1
PressureAreaFactory & GetPressureAreaFactory()
@ eUpwindPulse
simple upwinding scheme
BoundaryFactory & GetBoundaryFactory()
double NekDouble
void Neg(int n, T *x, const int incx)
Negate x = -x.
Definition: Vmath.cpp:518
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255