LifeV
multiscale/testsuite/onedmodel/ud_functions.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /*!
28  * @file
29  * @brief File containing function for imposing boundary conditions of the 1D model.
30  *
31  * @version 1.0
32  * @author Lucia Mirabella <lucia@mathcs.emory.edu>
33  * @author Tiziano Passerini <tiziano@mathcs.emory.edu>
34  * @date 01-04-2007
35  *
36  * @version 2.0
37  * @author Cristiano Malossi <cristiano.malossi@epfl.ch>
38  * @date 20-04-2010
39  *
40  * @maintainer Cristiano Malossi <cristiano.malossi@epfl.ch>
41  */
42 
43 #ifndef ONED_FUNCTIONS_1D_H
44 #define ONED_FUNCTIONS_1D_H
45 
46 #include <lifev/one_d_fsi/function/OneDFSIFunction.hpp>
47 
48 namespace LifeV
49 {
50 
51 //! Const - Base class for One Dimensional BC Functions
52 /*!
53  * @author Lucia Mirabella
54  */
55 class Constant
56 {
57 public:
58 
59  explicit Constant ( const Real& value ) :
60  M_value ( value )
61  {}
62 
63  virtual ~Constant() {}
64 
65  Real operator() ( const Real& /*time*/ )
66  {
67  return M_value;
68  }
69 
70 private:
71 
73 };
74 
75 
76 
77 //! Sin - Sinusoidal wave.
78 /*!
79  * @author Lucia Mirabella
80  */
81 class Sin
82 {
83 public:
84 
85  /*!
86  \brief The constructor
87 
88  \param[in] mean the time average of the sinus \f$ B \f$
89  \param[in] scale the sinus amplitude \f$ A \f$
90  \param[in] period the sinus period \f$ T \f$
91  \param[in] phase the sinus phase \f$ \phi \f$
92  */
93  explicit Sin ( const Real mean = 0, const Real scale = 10, const Real period = .01, const Real phase = 0. ) :
94  M_mean (mean),
95  M_scale (scale),
96  M_period (period),
97  M_phase (phase)
98  {}
99 
100  virtual ~Sin() {}
101 
102  /*!
103  \brief Compute the sinus at the specified time
104 
105  \param[in] time the time
106  \return \f$ B + A sin( \frac{2 \pi t}{T} + \phi ) \f$
107  */
108  Real operator() ( const Real& time )
109  {
110  if (time < M_period)
111  {
112  std::cout << time << " Flux BC = " << M_mean + M_scale* std::sin (M_phase + 2 * M_PI * time / M_period) << std::endl;
113  return - (M_mean + M_scale * std::sin (M_phase + 2 * M_PI * time / M_period) );
114  }
115  else
116  {
117  return 0.;
118  }
119  }
120 
121 private:
122 
127 };
128 
129 
130 //! Cos_min_Sin - A superimposition of a sinusoidal and a cosinusoidal waves, whose amplitude is damped by exponential terms
131 /*!
132  * @author Lucia Mirabella
133  */
135 {
136 public:
137 
138  /*!
139  \brief The constructor
140 
141  \param[in] coeff_exp_t_cos the coefficient multiplying time in the
142  exponential damping the cosinus amplitude \f$ \lambda_c \f$
143  \param[in] mean_cos the time average of the cosinus \f$ B_c \f$
144  \param[in] amplitude_cos the cosinus amplitude \f$ A_c \f$
145  \param[in] frequency_cos the cosinus period \f$ T_c \f$
146  \param[in] phase_cos the cosinus phase \f$ \phi_c \f$
147  \param[in] coeff_exp_t_sin the coefficient multiplying time in the
148  exponential damping the sinus amplitude \f$ \lambda_s \f$
149  \param[in] mean_sin the time average of the sinus \f$ B_s \f$
150  \param[in] amplitude_sin the sinus amplitude \f$ A_s \f$
151  \param[in] frequency_sin the sinus period \f$ T_s \f$
152  \param[in] phase_sin the sinus phase \f$ \phi_s \f$
153  */
154  explicit Cos_min_Sin (const Real coeff_exp_t_cos = 0, const Real mean_cos = 0,
155  const Real amplitude_cos = 10, const Real frequency_cos = 8.*atan (1.),
156  const Real phase_cos = 0.,
157  const Real coeff_exp_t_sin = 0, const Real mean_sin = 0,
158  const Real amplitude_sin = 10, const Real frequency_sin = 8.*atan (1.),
159  const Real phase_sin = 0. ) :
160  M_coeff_exp_t_cos (coeff_exp_t_cos),
161  M_mean_cos (mean_cos),
162  M_amplitude_cos (amplitude_cos),
163  M_frequency_cos (frequency_cos),
164  M_phase_cos (phase_cos),
165  M_coeff_exp_t_sin (coeff_exp_t_sin),
166  M_mean_sin (mean_sin),
167  M_amplitude_sin (amplitude_sin),
168  M_frequency_sin (frequency_sin),
169  M_phase_sin (phase_sin)
170  {}
171 
172  virtual ~Cos_min_Sin() {}
173 
174  /*!
175  \brief Compute the wave at the specified time
176 
177  \param[in] time the time
178  \return \f$ B_c + A_c cos( \frac{2 \pi t}{T_c} + \phi_c ) -
179  ( B_s + A_s sin( \frac{2 \pi t}{T_s} + \phi_s ) ) \f$
180  */
181  Real operator() ( const Real& time )
182  {
183  Real result = M_mean_cos
184  + M_amplitude_cos * std::cos (M_phase_cos + time * M_frequency_cos)
185  - ( M_mean_sin + M_amplitude_sin * std::sin (M_phase_sin + time * M_frequency_sin) );
186 
187  return result;
188  }
189 
190  /*! \name Getters
191  */
192  //@{
193 
195  {
196  return M_coeff_exp_t_cos;
197  }
199  {
200  return M_mean_cos;
201  }
203  {
204  return M_amplitude_cos;
205  }
207  {
208  return M_frequency_cos;
209  }
211  {
212  return M_phase_cos;
213  }
215  {
216  return M_coeff_exp_t_sin;
217  }
219  {
220  return M_mean_sin;
221  }
223  {
224  return M_amplitude_sin;
225  }
227  {
228  return M_frequency_sin;
229  }
231  {
232  return M_phase_sin;
233  }
234 
235  //@}
236 
237 private:
238 
249 };
250 
251 
252 //! Analytical_Solution - A particular case of Cos_min_Sin
253 /*!
254  * @author Lucia Mirabella
255  *
256  * This analytical solution is in the form
257  *
258  * U = ( Re(U) + i Im(U) ) * exp( Im(k) x ) *
259  * exp[ i ( \omega t - Re(k) x ) ] .
260  *
261  * Its real part is
262  * Re(U) = [ Re(U) * exp( Im(k) x ) ] * cos( \omega t - Re(k) x ) +
263  * - [ Im(U) * exp( Im(k) x ) ] * sin( \omega t - Re(k) x ) +
264  */
266 {
267 public:
268 
269  /*!
270  \brief The constructor
271 
272  \param[in] sol_amplitude_Re the real part of the wave amplitude
273  \param[in] sol_amplitude_Im the imaginary part of the wave amplitude
274  \param[in] kappa_Re the real part of the wave number \f$ k \f$
275  \param[in] kappa_Im the imaginary part of the wave number \f$ k \f$
276  \param[in] omega the wave time frequency \f$ \omega \f$ (supposed to be real)
277  */
278  explicit Analytical_Solution ( Real const& sol_amplitude_Re, Real const& sol_amplitude_Im,
279  Real const& kappa_Re, Real const& kappa_Im,
280  Real const& omega ) :
281  Cos_min_Sin (0., 0., sol_amplitude_Re, omega, 0.,
282  0., 0., sol_amplitude_Im, omega, 0.),
283  M_sol_amplitude_Re (sol_amplitude_Re),
284  M_sol_amplitude_Im (sol_amplitude_Im),
285  M_kappa_Re (kappa_Re),
286  M_kappa_Im (kappa_Im)
287  {}
288 
289  virtual ~Analytical_Solution() {}
290 
291  /*!
292  \brief Compute the wave at the specified time
293 
294  \param[in] time the time
295  \return \f$ B_c + A_c cos( \frac{2 \pi t}{T_c} + \phi_c ) -
296  ( B_s + A_s sin( \frac{2 \pi t}{T_s} + \phi_s ) ) \f$
297  */
298  Real operator() ( const Real& time )
299  {
300  return Cos_min_Sin::operator() (time);
301  }
302 
303  /*!
304  \brief Compute the wave at the specified time
305 
306  \param[in] time the time
307  \return \f$ B_c + A_c cos( \frac{2 \pi t}{T_c} + \phi_c ) -
308  ( B_s + A_s sin( \frac{2 \pi t}{T_s} + \phi_s ) ) \f$
309  */
310  void update_x ( const Real& _x )
311  {
312  this->amplitude_cos() = M_sol_amplitude_Re * std::exp ( M_kappa_Im * _x );
313  this->phase_cos() = - M_kappa_Re * _x;
314  this->amplitude_sin() = M_sol_amplitude_Im * std::exp ( M_kappa_Im * _x );
315  this->phase_sin() = - M_kappa_Re * _x;
316  }
317 
318 private:
319 
324 };
325 
326 
327 //! PhysiologicalFlux - Base class for One Dimensional BC Functions
328 /*!
329  * @author Lucia Mirabella
330  */
332 {
333 public:
334 
335  explicit PhysiologicalFlux() :
336  M_rampT(),
337  M_time_step(),
338  M_scale()
339  {}
340 
341  virtual ~PhysiologicalFlux() {}
342 
343  Real operator() ( const Real& time );
344 
345 private:
346 
350 };
351 
352 Real
354 {
355  double time = t;
356  int numData = 100;
357  double flux[101] = { 0.55457447187998,
358  0.55312181720914,
359  0.55299302643153,
360  0.55302818124406,
361  0.55317321131557,
362  0.55353364652152,
363  0.55374878962962,
364  0.55406829977313,
365  0.55585881887584,
366  0.55879983633299,
367  0.56387572718194,
368  0.57079488161935,
369  0.58817359652018,
370  0.61511673048210,
371  0.65025652077432,
372  0.79143597227331,
373  1.06959564837144,
374  1.33301653745648,
375  1.55916094914244,
376  1.69807981838757,
377  1.73941326221337,
378  1.69691789994768,
379  1.61546505715344,
380  1.51298277554169,
381  1.35636910481872,
382  1.18958468647846,
383  1.02381943290960,
384  0.89472539111700,
385  0.79994401665900,
386  0.74338513206540,
387  0.72984443940672,
388  0.74311502021666,
389  0.77155202899612,
390  0.80920592343822,
391  0.84528951107944,
392  0.87014986946118,
393  0.89016029509068,
394  0.89999452080415,
395  0.89511807514404,
396  0.87823357219620,
397  0.85663326250089,
398  0.82858260857792,
399  0.79671836139948,
400  0.75291106131325,
401  0.70711033067577,
402  0.65740190152584,
403  0.61066125251620,
404  0.56488426267136,
405  0.51713402331108,
406  0.46453623816504,
407  0.41513731950517,
408  0.47836113912116,
409  0.56452765299777,
410  0.62096051336166,
411  0.66202024502726,
412  0.69173157064612,
413  0.71835003021294,
414  0.74183126309604,
415  0.75295645424862,
416  0.75292455314576,
417  0.74514787317446,
418  0.72467414023271,
419  0.70473486985061,
420  0.68057326827129,
421  0.66194232245132,
422  0.64681425465222,
423  0.63714376881254,
424  0.62991615896879,
425  0.62662699778909,
426  0.62724985397200,
427  0.62674770176751,
428  0.62666043242736,
429  0.62617509524360,
430  0.62556258658310,
431  0.62581913341632,
432  0.62604032520998,
433  0.62582937168093,
434  0.62404471163034,
435  0.61923663804136,
436  0.61378537728592,
437  0.60976137345625,
438  0.60596975158344,
439  0.60144172708524,
440  0.59702451106965,
441  0.59319136754468,
442  0.58982107329344,
443  0.58718879911670,
444  0.58474181066352,
445  0.58208280034445,
446  0.57913818429409,
447  0.57588144074776,
448  0.57289019558638,
449  0.57076133371909,
450  0.56912637026578,
451  0.56776096894206,
452  0.56622327633393,
453  0.56376396210446,
454  0.56132345661888,
455  0.55914786876437,
456  0.55714215894326,
457  0.55457447187998
458  };
459 
460  double timescale = M_scale / numData;
461 
462  for (;;)
463  {
464  if (time < M_scale)
465  {
466  break;
467  }
468  time = time - M_scale;
469  }
470 
471  int ipos = time / timescale;
472  double t2 = timescale * (ipos + 1);
473 
474  double a = (flux[ipos + 1] - flux[ipos]) / timescale;
475  double b = flux[ipos + 1] - a * t2;
476 
477  std::cout << "BC: Flux = " << time* a + b
478  << " period = " << M_scale << " pos = " << ipos << std::endl;
479  return time * a + b;
480 }
481 
482 //! PressureRamp
483 /*!
484  * @author Lucia Mirabella
485  */
487 {
488 public:
489  explicit PressureRamp ( const Real& startT = .001,
490  const Real& duration = 0.7,
491  const Real& endvalue = 106400 );
492 
493  virtual ~PressureRamp() {}
494 
495  Real operator() ( const Real& time );
496 
497 private:
498 
502 };
503 
504 PressureRamp::PressureRamp ( const Real& startT,
505  const Real& duration,
506  const Real& endvalue ) :
507  M_startT ( startT ),
508  M_duration ( duration ),
509  M_endvalue ( endvalue )
510 {}
511 
512 Real
513 PressureRamp::operator() ( const Real& time )
514 {
515  Real t = time;
516 
517  Int numData = 80;
518  Real pressure[81] = { 110170,
519  109540,
520  108930,
521  108320,
522  107710,
523  107120,
524  106530,
525  111130,
526  115440,
527  118690,
528  121460,
529  123940,
530  126350,
531  128890,
532  131510,
533  133980,
534  136200,
535  138330,
536  140350,
537  142290,
538  144360,
539  146130,
540  147530,
541  148780,
542  149740,
543  150320,
544  150470,
545  150250,
546  149750,
547  148990,
548  148220,
549  147210,
550  145940,
551  144960,
552  143750,
553  141980,
554  139900,
555  137260,
556  133970,
557  131670,
558  131320,
559  133150,
560  132710,
561  131570,
562  130280,
563  129750,
564  129330,
565  128910,
566  128360,
567  127680,
568  127000,
569  126410,
570  125920,
571  125480,
572  125040,
573  124560,
574  124050,
575  123530,
576  123000,
577  122440,
578  121840,
579  121220,
580  120580,
581  119950,
582  119330,
583  118710,
584  118100,
585  117470,
586  116840,
587  116200,
588  115560,
589  114920,
590  114280,
591  113650,
592  113020,
593  112400,
594  111790,
595  111200,
596  110620,
597  110060,
598  110170
599  };
600 
601  Real P = 0;
602  if (t < 0)
603  {
604  P = t / M_startT * pressure[0];
605  }
606  else
607  {
608  Real timescale = M_duration / numData;
609 
610  for (;;)
611  {
612  if (t < M_duration)
613  {
614  break;
615  }
616  t -= M_duration;
617  }
618 
619  Int ipos = t / timescale;
620  Real t2 = timescale * (ipos + 1);
621 
622  Real a = ( pressure[ipos + 1] - pressure[ipos] ) / timescale;
623  Real b = pressure[ipos + 1] - a * t2;
624 
625  P = t * a + b;
626 
627  std::cout << "BC: Pressure = " << P
628  << " period = " << M_duration << " pos = " << ipos << std::endl;
629  }
630 
631 #ifdef HAVE_LIFEV_DEBUG
632  debugStream ( 6030 ) << "[PressureRamp::evaluate] imposed pressure = " << P << "\n";
633 #endif
634 
635  return P;
636 }
637 
638 }
639 
640 #endif
Cos_min_Sin(const Real coeff_exp_t_cos=0, const Real mean_cos=0, const Real amplitude_cos=10, const Real frequency_cos=8.*atan(1.), const Real phase_cos=0., const Real coeff_exp_t_sin=0, const Real mean_sin=0, const Real amplitude_sin=10, const Real frequency_sin=8.*atan(1.), const Real phase_sin=0.)
The constructor.
Sin(const Real mean=0, const Real scale=10, const Real period=.01, const Real phase=0.)
The constructor.
Real operator()(const Real &time)
Compute the wave at the specified time.
PressureRamp(const Real &startT=.001, const Real &duration=0.7, const Real &endvalue=106400)
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
#define M_PI
Definition: winmath.h:20
void updateInverseJacobian(const UInt &iQuadPt)
Real operator()(const Real &time)
Compute the wave at the specified time.
Analytical_Solution - A particular case of Cos_min_Sin.
Real operator()(const Real &time)
Compute the sinus at the specified time.
Analytical_Solution(Real const &sol_amplitude_Re, Real const &sol_amplitude_Im, Real const &kappa_Re, Real const &kappa_Im, Real const &omega)
The constructor.
PhysiologicalFlux - Base class for One Dimensional BC Functions.
double Real
Generic real data.
Definition: LifeV.hpp:175
Const - Base class for One Dimensional BC Functions.
Cos_min_Sin - A superimposition of a sinusoidal and a cosinusoidal waves, whose amplitude is damped b...
void update_x(const Real &_x)
Compute the wave at the specified time.