LifeV
lifev/eta/examples/example_biPhasic/main.cpp
Go to the documentation of this file.
1 /* -*- mode: c++ -*-
2 
3  This file is part of the LifeV Applications.
4 
5  Author(s): Samuel Quinodoz <samuel.quinodoz@epfl.ch>
6  Date: 2011-01-27
7 
8  Copyright (C) 2005 EPFL
9 
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful, but
16  WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23  USA
24 */
25 /**
26  \file main.cpp
27  \author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
28  \date 2011-01-127
29 
30 
31  Optimizations: keep the matrices, *= 0.0 only
32 
33  */
34 
35 
36 // Tell the compiler to ignore specific kind of warnings:
37 #pragma GCC diagnostic ignored "-Wunused-variable"
38 #pragma GCC diagnostic ignored "-Wunused-parameter"
39 
40 #include <Epetra_ConfigDefs.h>
41 #ifdef EPETRA_MPI
42 #include <mpi.h>
43 #include <Epetra_MpiComm.h>
44 #else
45 #include <Epetra_SerialComm.h>
46 #endif
47 
48 //Tell the compiler to restore the warning previously silented
49 #pragma GCC diagnostic warning "-Wunused-variable"
50 #pragma GCC diagnostic warning "-Wunused-parameter"
51 
52 #include <lifev/core/LifeV.hpp>
53 
54 
55 #include <lifev/core/algorithm/PreconditionerIfpack.hpp>
56 #include <lifev/core/algorithm/PreconditionerML.hpp>
57 #include <lifev/core/algorithm/SolverAztecOO.hpp>
58 
59 #include <lifev/core/array/MatrixEpetraStructured.hpp>
60 #include <lifev/core/array/VectorBlockMonolithicEpetra.hpp>
61 
62 #include <lifev/core/util/LifeChrono.hpp>
63 
64 #include <lifev/eta/expression/Integrate.hpp>
65 
66 #include <lifev/core/fem/BCHandler.hpp>
67 #include <lifev/core/fem/BCManage.hpp>
68 #include <lifev/core/fem/FESpace.hpp>
69 #include <lifev/eta/fem/ETFESpace.hpp>
70 
71 #include <lifev/core/fem/GradientRecovery.hpp>
72 
73 #include <lifev/core/filter/ExporterEnsight.hpp>
74 #include <lifev/core/filter/ExporterHDF5.hpp>
75 
76 #include <lifev/core/mesh/MeshPartitioner.hpp>
77 #include <lifev/core/mesh/RegionMesh3DStructured.hpp>
78 //#include <lifev/core/mesh/RegionMesh3D.hpp>
79 #include <lifev/core/mesh/RegionMesh.hpp>
80 #include <lifev/core/mesh/MeshUtility.hpp>
81 #include <lifev/core/mesh/MeshData.hpp>
82 
83 #include <lifev/level_set/fem/LevelSetQRAdapter.hpp>
84 
85 #include <iostream>
86 
87 //#define BDF2_TIME 1
88 
89 //#define FULL_CORRECTION 1
90 #define NORMAL_CORRECTION 1
91 
92 using namespace LifeV;
93 
94 // Physics
95 Real viscosityPlus (1e-3);
96 Real viscosityMinus (2e-5);
97 Real densityPlus (1000.0);
98 Real densityMinus (1.0);
99 
100 Real liquidHeight (0.1);
101 Real cylinderRadius (0.144);
102 Real cylinderHeight (0.4);
103 Real alphaBL (3.0);
104 
105 Real thetaInit (0.0);
106 Real omegaInit (0.0);
107 Real tRise (6.0);
108 Real omegaMax (2 * M_PI);
109 Real shakeRadius (0.1);
110 
111 Real slipLength (0.05);
112 Real noSlipCoef (1e6);
113 Real viscosityRatio (50.0);
114 Real slipFriction (0.0);
115 
116 // NS
117 Real NSSupg (1.0e-3); // 1e-3
118 Real NSPspg (1.0e-3); // 1e-3
119 Real NSdivdiv (5.0e2); // 5e2
120 
121 bool NormalizeCorrection (true);
122 
123 // LS advection
124 Real LSSupg (5e-2);
125 
126 // HJ
127 UInt HJeach (1);
128 Real HJdt (2e-2);
129 Real HJtime (0.0);
131 Real HJsupg (5e-1);
132 Real HJpenal (1e5);
133 
134 // Volume correction
135 Real volumeRelaxation (0.5);
136 Real epsilonArea (0.05);
137 
138 // Export
139 UInt exportEach (1);
140 
141 
142 
143 /* Level set initial position */
144 Real initLSFct ( const Real& /*t*/, const Real& /*x*/ , const Real& /*y*/, const Real& z , const ID& /*i*/)
145 {
146  Real distToSurface ( liquidHeight - z );
147 
148  return distToSurface;
149 };
150 
151 /* Velocity initial */
152 Real initVelocity ( const Real& /*t*/, const Real& /*x*/ , const Real& /*y*/, const Real& /*z*/ , const ID& i)
153 {
154  if (i == 2)
155  {
156  return 0.00;
157  }
158  return 0.0;
159 };
160 
161 
162 /* Velocity initial */
163 Real zeroFct ( const Real& /*t*/, const Real& /*x*/ , const Real& /*y*/, const Real& /*z*/ , const ID& /*i*/)
164 {
165  return 0.0;
166 };
167 
168 /* Velocity initial */
169 Real oneFct ( const Real& /*t*/, const Real& /*x*/ , const Real& /*y*/, const Real& /*z*/ , const ID& /*i*/)
170 {
171  return 1.0;
172 };
173 
174 
175 /* Velocity initial */
176 Real volumeForce ( const Real& t, const Real& /*x*/, const Real& /*y*/, const Real& /*z*/, const ID& i)
177 {
178  Real alpha;
179  Real omega;
180  Real theta;
181 
182  if (t < tRise)
183  {
184  theta = thetaInit + omegaInit * t + (omegaMax - omegaInit) * (t - tRise * std::cos (-M_PI / 2.0 + M_PI * t / tRise) / M_PI) / 2.0;
185  omega = omegaInit + (omegaMax - omegaInit) * (std::sin (-M_PI / 2.0 + M_PI * t / tRise) + 1.0) / 2.0;
186  alpha = (omegaMax - omegaInit) * M_PI * std::cos (-M_PI / 2.0 + M_PI * t / tRise) / (2 * tRise);
187  }
188  else
189  {
190  alpha = 0.0;
191  omega = omegaMax;
192  theta = thetaInit + (omegaMax - omegaInit) * (tRise / 2.0) + omegaMax * (t - tRise);
193  }
194 
195  if (i == 0)
196  {
197  return shakeRadius * omega * omega * cos (theta) - shakeRadius * alpha * sin (theta);
198  }
199  if (i == 1)
200  {
201  return -shakeRadius * omega * omega * sin (theta) - shakeRadius * alpha * cos (theta);
202  }
203  if (i == 2)
204  {
205  return -9.806;
206  }
207 
208  return 0.0;
209 };
210 
212 {
213  Real alpha;
214  Real omega;
215  Real theta;
216 
217  if (t < tRise)
218  {
219  theta = thetaInit + omegaInit * t + (omegaMax - omegaInit) * (t - tRise * std::cos (-M_PI / 2.0 + M_PI * t / tRise) / M_PI) / 2.0;
220  omega = omegaInit + (omegaMax - omegaInit) * (std::sin (-M_PI / 2.0 + M_PI * t / tRise) + 1.0) / 2.0;
221  alpha = (omegaMax - omegaInit) * M_PI * std::cos (-M_PI / 2.0 + M_PI * t / tRise) / (2 * tRise);
222  }
223  else
224  {
225  alpha = 0.0;
226  omega = omegaMax;
227  theta = thetaInit + (omegaMax - omegaInit) * (tRise / 2.0) + omegaMax * (t - tRise);
228  }
229 
230  std::cout << " ### Motion ### " << std::endl;
231  std::cout << " theta : " << theta << " (rad) " << std::endl;
232  std::cout << " omega : " << 60.0 * omega / (2.0 * M_PI) << " (rpm) " << std::endl;
233  std::cout << " alpha : " << alpha << " (rad/s2) " << std::endl;
234 }
235 
236 Real volumeForce0 ( const Real& t, const Real& x , const Real& y, const Real& z , const ID& /*i*/)
237 {
238  return volumeForce (t, x, y, z, 0);
239 };
240 Real volumeForce1 ( const Real& t, const Real& x , const Real& y, const Real& z , const ID& /*i*/)
241 {
242  return volumeForce (t, x, y, z, 1);
243 };
244 Real volumeForce2 ( const Real& t, const Real& x , const Real& y, const Real& z , const ID& /*i*/)
245 {
246  return volumeForce (t, x, y, z, 2);
247 };
248 
249 Real normalDirection ( const Real& /*t*/, const Real& x , const Real& y, const Real& /*z*/ , const ID& i)
250 {
251  Real nnorm (x * x + y * y);
252  if (i == 0)
253  {
254  return x / nnorm;
255  }
256  else if (i == 1)
257  {
258  return y / nnorm;
259  }
260 
261  return 0.0;
262 };
263 
265 {
266  //Real frac(std::abs(ls)/(slipLength));
267 
268  if ( ls < -slipLength)
269  {
270  return noSlipCoef / viscosityRatio;
271  }
272  if ( ls < 0 )
273  {
274  return slipFriction / viscosityRatio;
275  }
276  if ( ls < slipLength )
277  {
278  return slipFriction;
279  }
280  return noSlipCoef;
281 };
282 
283 
284 void meshMap ( Real& x, Real& y, Real& z )
285 {
286 
287  if (alphaBL == 0.0)
288  {
289  x = x * cylinderRadius / 0.144;
290  y = y * cylinderRadius / 0.144;
291 
292  }
293  else
294  {
295  // Map to the unit disk
296  x /= 0.144;
297  y /= 0.144;
298 
299  // New radius there
300  Real r (std::sqrt (x * x + y * y) );
301 
302  Real factor = (1 - std::exp (-alphaBL * r) ) / (1 - std::exp (-alphaBL) );
303  x *= factor / r;
304  y *= factor / r;
305 
306  // Map to the right radius
307  x *= cylinderRadius;
308  y *= cylinderRadius;
309  }
310 
311  z = z * cylinderHeight / 0.4;
312 };
313 
314 
315 /* Heaviside function class */
317 {
318 public:
319  typedef Real return_Type;
320 
321  return_Type operator() (const Real& value)
322  {
323  if (value >= 0)
324  {
325  return 1.0;
326  }
327  return 0.0;
328  }
329 
333 };
334 
335 /* Viscosity */
337 {
338 public:
339  typedef Real return_Type;
340 
341  return_Type operator() (const Real& value)
342  {
343  if (value >= 0)
344  {
345  return viscosityPlus;
346  }
347  return viscosityMinus;
348  }
349 
353 };
354 
355 #define VISCOSITY eval(viscosity, value(ETlsFESpace,LSSolutionOld))
356 
357 /* Density */
359 {
360 public:
361  typedef Real return_Type;
362 
363  return_Type operator() (const Real& value)
364  {
365  if (value >= 0)
366  {
367  return densityPlus;
368  }
369  return densityMinus;
370  }
371 
373  DensityFct (const DensityFct&) {}
375 };
376 
377 #define DENSITY eval(density, value(ETlsFESpace,LSSolutionOld))
378 
379 /* NormalizeFct */
381 {
382 public:
384 
385  return_Type operator() (const VectorSmall<3>& value)
386  {
387  Real norm (sqrt ( value[0]*value[0] + value[1]*value[1] + value[2]*value[2]) );
388 
389  if (norm > 0)
390  {
391  return value * (1.0 / norm);
392  }
393  return value;
394  }
395 
399 };
400 
401 
402 /* NormalizeFct */
403 class NormFct
404 {
405 public:
406  typedef Real return_Type;
407 
408  return_Type operator() (const VectorSmall<3> value)
409  {
410  Real norm (sqrt ( value[0]*value[0] + value[1]*value[1] + value[2]*value[2]) );
411 
412  return norm;
413  }
414 
415  NormFct() {}
416  NormFct (const NormFct&) {}
417  ~NormFct() {}
418 };
419 
420 
421 /* SignFct */
422 class SignFct
423 {
424 public:
425  typedef Real return_Type;
426 
427  return_Type operator() (const Real& value)
428  {
429  if (value > 0)
430  {
431  return 1.0;
432  }
433  else if (value < 0)
434  {
435  return -1.0;
436  }
437  return 0.0;
438  }
439 
440  SignFct() {}
441  SignFct (const SignFct&) {}
442  ~SignFct() {}
443 };
444 
445 /* SmoothSignFct */
447 {
448 public:
449  typedef Real return_Type;
450 
451  return_Type operator() (const Real& value)
452  {
453  Real frac (value / epsilonArea);
454 
455  if (frac < -1)
456  {
457  return 0.0;
458  }
459  else if (frac > 1)
460  {
461  return 0.0;
462  }
463  else
464  {
465  return 0.5 * (1 + std::cos (M_PI * frac) ) / epsilonArea;
466  }
467  }
468 
472 };
473 
474 
475 
476 
477 /* Register the preconditioner */
478 namespace
479 {
480 static bool regIF = (PRECFactory::instance().registerProduct ( "Ifpack", &createIfpack ) );
481 static bool regML = (PRECFactory::instance().registerProduct ( "ML", &createML ) );
482 }
483 
484 
485 /* Some typedef */
491 
492 
493 #define BOTTOM_LINE 1
494 #define TOP_LINE 2
495 #define BOTTOM 3
496 #define WALL 4
497 #define TOP 5
498 
499 int main ( int argc, char** argv )
500 {
501 
502 
503 #ifdef HAVE_MPI
504  MPI_Init (&argc, &argv);
505  std::shared_ptr<Epetra_Comm> Comm (new Epetra_MpiComm (MPI_COMM_WORLD) );
506 #else
507  std::shared_ptr<Epetra_Comm> Comm (new Epetra_SerialComm);
508 #endif
509 
510  // a flag to see who's the leader for output purposes
511  bool verbose = (Comm->MyPID() == 0);
512 
513  // Open and read the data file
514  GetPot command_line (argc, argv);
515  std::string data_file_name = command_line.follow ("data", 2, "-f", "--file");
516  //GetPot dataFile( data_file_name );
517  GetPot dataFile ( "data" );
518 
519  // Reading the data
520 
521  viscosityPlus = dataFile ("physics/viscosityPlus", 1e-3);
522  viscosityMinus = dataFile ("physics/viscosityMinus", 2e-5);
523  densityPlus = dataFile ("physics/densityPlus", 1000.0);
524  densityMinus = dataFile ("physics/densityMinus", 1.0);
525 
526  NSSupg = dataFile ("oseen/stab/supg", 1e-3);
527  NSPspg = dataFile ("oseen/stab/pspg", 1e-3);
528  NSdivdiv = dataFile ("oseen/stab/divdiv", 5e2);
529 
530  NormalizeCorrection = dataFile ("oseen/pressure/normalize_correction", true);
531 
532  LSSupg = dataFile ("level_set/advection/supg", 5e-2);
533 
534  HJdt = dataFile ("level_set/hj/dt", 2e-2);
535  HJfinalTime = dataFile ("level_set/hj/final", HJdt);
536  HJsupg = dataFile ("level_set/hj/supg", 5e-1);
537  HJeach = dataFile ("level_set/hj/each", 1);
538  HJpenal = dataFile ("level_set/hj/penalisation", 1e5);
539 
540  liquidHeight = dataFile ("physics/liquid_height", 0.1);
541  cylinderRadius = dataFile ("physics/cylinder_radius", 0.144);
542  cylinderHeight = dataFile ("physics/cylinder_height", 0.4);
543 
544  thetaInit = dataFile ("physics/theta_init", 0.0);
545  omegaInit = 2 * M_PI * dataFile ("physics/omega_init", 0.0) / 60.0;
546  tRise = dataFile ("physics/time_rise", 6.0);
547  omegaMax = 2 * M_PI * dataFile ("physics/omega_final", 60.0) / 60.0;
548 
549  shakeRadius = dataFile ("physics/shake_radius", 0.1);
550 
551  slipLength = dataFile ("oseen/bc/slip_length", 0.05);
552  noSlipCoef = dataFile ("oseen/bc/no_slip_coef", 1e6);
553  viscosityRatio = dataFile ("oseen/bc/ratio", 50.0);
554  slipFriction = dataFile ("oseen/bc/slip_friction", 0.0);
555 
556  exportEach = dataFile ("exporter/each", 1);
557 
558  alphaBL = dataFile ("mesh/alphaBL", 0.0);
559 
560  if (verbose)
561  {
562  std::cout << "alpha : " << alphaBL << std::endl;
563  }
564 
565 
566  Real exactVolume (M_PI * cylinderRadius * cylinderRadius * liquidHeight);
567  if (verbose)
568  {
569  std::cout << "Exact : " << exactVolume << std::endl;
570  }
571 
572  if (verbose)
573  {
574  std::cout << " Reading and partitioning the mesh " << std::endl;
575  }
576 
577 
578  // Load the mesh
579  MeshData dataMesh;
580  dataMesh.setup (dataFile, "mesh");
581 
582  std::shared_ptr < mesh_Type > fullMeshPtr (new mesh_Type);
583  std::shared_ptr < mesh_Type > localMeshPtr (new mesh_Type);
584 
585  if (verbose)
586  {
587  std::cout << "Hello " << exactVolume << std::endl;
588  }
589  readMesh (*fullMeshPtr, dataMesh);
590 
591  // Scale the mesh
592  //std::vector<Real> ScaleFactor(3,cylinderRadius/0.144);
593  //ScaleFactor[2]=cylinderHeight/0.4;
594  //std::vector<Real> DoNothing(3,0.0);
595  //fullMeshPtr->transformMesh(ScaleFactor,DoNothing,DoNothing);
596 
597  if (verbose)
598  {
599  std::cout << " BL factor : " << alphaBL << std::endl;
600  }
601  //std::shared_ptr< MeshTransformer > meshTransformerObject ( new MeshTransfomer(fullMeshPtr) );
602  //fullMeshPtr->transformMesh(meshMap);
603  fullMeshPtr->meshTransformer().transformMesh (meshMap);
604 
605  // Partition the mesh
606  MeshPartitioner< mesh_Type > meshPart (fullMeshPtr, Comm);
607  localMeshPtr = meshPart.meshPartition();
608 
609  // Free the global mesh
610  fullMeshPtr.reset();
611 
612 
613  if (verbose)
614  {
615  std::cout << " Building FESpaces " << std::endl;
616  }
617 
618 
619  //std::string uOrder("P1Bubble");
620  std::string uOrder ("P1");
621  std::string pOrder ("P1");
622  std::string lsOrder ("P1");
623 
624  std::shared_ptr<FESpace< mesh_Type, MapEpetra > > uFESpace ( new FESpace< mesh_Type, MapEpetra > (localMeshPtr, uOrder, 3, Comm) );
625  std::shared_ptr<FESpace< mesh_Type, MapEpetra > > pFESpace ( new FESpace< mesh_Type, MapEpetra > (localMeshPtr, pOrder, 1, Comm) );
626  std::shared_ptr<FESpace< mesh_Type, MapEpetra > > lsFESpace ( new FESpace< mesh_Type, MapEpetra > (localMeshPtr, lsOrder, 1, Comm) );
627 
628  if (verbose)
629  {
630  std::cout << std::endl << " ### Dof Summary ###: " << std::endl;
631  }
632  if (verbose)
633  {
634  std::cout << " Velocity : " << uFESpace->map().map (Unique)->NumGlobalElements() << std::endl;
635  }
636  if (verbose)
637  {
638  std::cout << " Pressure : " << pFESpace->map().map (Unique)->NumGlobalElements() << std::endl;
639  }
640  if (verbose)
641  {
642  std::cout << " Level set : " << lsFESpace->map().map (Unique)->NumGlobalElements() << std::endl << std::endl;
643  }
644 
645 
646  if (verbose)
647  {
648  std::cout << " Building EA FESpaces " << std::endl;
649  }
650 
651 
652  std::shared_ptr<ETFESpace< mesh_Type, MapEpetra, 3, 3 > > ETuFESpace ( new ETFESpace< mesh_Type, MapEpetra, 3, 3 > (meshPart, & (uFESpace->refFE() ), Comm) );
653  std::shared_ptr<ETFESpace< mesh_Type, MapEpetra, 3, 1 > > ETpFESpace ( new ETFESpace< mesh_Type, MapEpetra, 3, 1 > (meshPart, & (pFESpace->refFE() ), Comm) );
654  std::shared_ptr<ETFESpace< mesh_Type, MapEpetra, 3, 1 > > ETlsFESpace ( new ETFESpace< mesh_Type, MapEpetra, 3, 1 > (meshPart, & (lsFESpace->refFE() ), Comm) );
655 
656 
657  if (verbose)
658  {
659  std::cout << " Initial conditions " << std::endl;
660  }
661 
662  vector_type LSSolution (ETlsFESpace->map(), Unique);
663 
664  lsFESpace->interpolate (static_cast<FESpace< mesh_Type, MapEpetra >::function_Type> (initLSFct), LSSolution, 0.0);
665 
666  vector_type LSSolutionOld (LSSolution, Repeated);
667  vector_type HJSolutionOld (LSSolution, Repeated);
668  vector_type HJProjSolution (LSSolution, Repeated);
669 
670  vector_type velocitySolution (ETuFESpace->map(), Unique);
671 
672  uFESpace->interpolate (static_cast<FESpace< mesh_Type, MapEpetra >::function_Type> (initVelocity), velocitySolution, 0.0);
673 
674  vector_type velocitySolutionOld (velocitySolution, Repeated);
675 #ifdef BDF2_TIME
676  vector_type velocitySolutionOldOld (velocitySolution, Repeated);
677 #endif
678 
679  vector_block_type NSSolution (ETuFESpace->map() | ETpFESpace->map(), Unique);
680  NSSolution *= 0.0;
681  //NSSolution += velocitySolution; THIS DOES NOT WORK!
682 
683  vector_block_type NSSolutionOld (NSSolution , Repeated);
684  NSSolutionOld *= 0.0; // JUST TO BE SURE
685 
686 
687  if (verbose)
688  {
689  std::cout << " Building the solvers " << std::endl;
690  }
691 
692 
693  SolverAztecOO LSAdvectionSolver;
694  LSAdvectionSolver.setCommunicator (Comm);
695  LSAdvectionSolver.setDataFromGetPot (dataFile, "solver");
696  LSAdvectionSolver.setupPreconditioner (dataFile, "prec");
697 
698  SolverAztecOO NSSolver;
699  NSSolver.setCommunicator (Comm);
700  NSSolver.setDataFromGetPot (dataFile, "solver");
701  NSSolver.setupPreconditioner (dataFile, "prec");
702 
703  SolverAztecOO HJSolver;
704  HJSolver.setCommunicator (Comm);
705  HJSolver.setDataFromGetPot (dataFile, "solver");
706  HJSolver.setupPreconditioner (dataFile, "prec");
707 
708  if (verbose)
709  {
710  std::cout << " Building the exporter " << std::endl;
711  }
712 
713 
714  ExporterHDF5<mesh_Type> exporter ( dataFile, meshPart.meshPartition(), "solution", Comm->MyPID() );
715  exporter.setMultimesh (false);
716 
717  std::shared_ptr<vector_type> LSExported ( new vector_type (LSSolutionOld, Repeated) );
718  std::shared_ptr<vector_type> NSExported ( new vector_type (NSSolutionOld, Repeated) );
719 
720  const UInt PressureOffset ( 3 * uFESpace->dof().numTotalDof() );
721 
722  exporter.addVariable ( ExporterData<mesh_Type>::ScalarField, "level-set", lsFESpace, LSExported, UInt (0) );
723  exporter.addVariable ( ExporterData<mesh_Type>::VectorField, "velocity", uFESpace, NSExported, UInt (0) );
724  exporter.addVariable ( ExporterData<mesh_Type>::ScalarField, "pressure", pFESpace, NSExported, PressureOffset);
725 
726  if (verbose)
727  {
728  std::cout << " Loading time stuff " << std::endl;
729  }
730 
731 
732  Real currentTime ( dataFile ("time/initial", 0.0) );
733  Real finalTime ( dataFile ("time/final", 1.0) );
734  Real dt ( dataFile ("time/dt", 0.1) );
735  UInt niter (0);
736 
737 
738  if (verbose)
739  {
740  std::cout << " Exporting the initial condition " << std::endl;
741  }
742 
743 
744  exporter.postProcess (currentTime);
745 
746 
747  if (verbose)
748  {
749  std::cout << std::endl;
750  }
751  if (verbose)
752  {
753  std::cout << " ### Simulation times ### " << std::endl;
754  }
755  if (verbose)
756  {
757  std::cout << " From " << currentTime << " to " << finalTime << std::endl;
758  }
759  if (verbose)
760  {
761  std::cout << " Time step: " << dt << std::endl;
762  }
763  if (verbose)
764  {
765  std::cout << std::endl;
766  }
767 
768 
769 
770 
771  while (currentTime < finalTime)
772  {
773  LifeChrono ChronoIteration;
774  ChronoIteration.start();
775 
776  currentTime += dt;
777  niter += 1;
778 
779  if (verbose)
780  {
781  std::cout << std::endl;
782  }
783  if (verbose)
784  {
785  std::cout << "----------------------------" << std::endl;
786  }
787  if (verbose)
788  {
789  std::cout << " Time : " << currentTime << std::endl;
790  }
791  if (verbose)
792  {
793  std::cout << " Iter : " << niter << std::endl;
794  }
795  if (verbose)
796  {
797  std::cout << "----------------------------" << std::endl;
798  }
799  if (verbose)
800  {
801  std::cout << std::endl;
802  }
803 
804  if (verbose)
805  {
806  std::cout << "[Navier-Stokes] Assembling the matrix ... " << std::flush;
807  }
808 
809  LifeChrono ChronoItem;
810  ChronoItem.start();
811 
812 #define SUPG_TEST value(NSSupg)*h_K * (grad(phi_i)*eval(normalize,value(ETuFESpace,velocitySolutionOld)))
813 
814 #define PSPG_TEST value(NSPspg)*h_K * grad(phi_i)
815 
816 #define DIVDIV_TEST value(NSdivdiv)*h_K*div(phi_i)
817 
818 #ifdef BDF2_TIME
819  vector_type velocityExtrapolated (velocitySolutionOld * 2 - velocitySolutionOldOld, Repeated);
820  Real alpha (1.5);
821  vector_type velocityBdfRHS (velocitySolutionOld * 2 - velocitySolutionOldOld * 0.5, Repeated);
822 #else
823  vector_type velocityExtrapolated (velocitySolutionOld, Repeated);
824  Real alpha (1.0);
825  vector_type velocityBdfRHS (velocitySolutionOld, Repeated);
826 #endif
827 
828 
829  std::shared_ptr<matrix_block_type> NSMatrix (new matrix_block_type ( ETuFESpace->map() | ETpFESpace->map() ) );
830  *NSMatrix *= 0.0;
831 
832  {
833  std::shared_ptr<DensityFct> density (new DensityFct);
834  std::shared_ptr<ViscosityFct> viscosity (new ViscosityFct);
835  std::shared_ptr<NormalizeFct> normalize (new NormalizeFct);
836 
837  using namespace ExpressionAssembly;
838 
839  integrate (
840  elements (ETuFESpace->mesh() ), // Mesh
841 
842  adapt (ETlsFESpace, LSSolutionOld, uFESpace->qr() ), // QR
843 
844  ETuFESpace,
845  ETuFESpace,
846 
847  // NS
848  DENSITY
849  * ( value (alpha / dt) * dot (phi_i, phi_j)
850  + dot (grad (phi_j) *value (ETuFESpace, velocityExtrapolated), phi_i)
851  )
852 
853  + VISCOSITY * dot (grad (phi_i), grad (phi_j) )
854 
855  // Div div
856  + DIVDIV_TEST
857  *div (phi_j)
858 
859  // SUPG
860  + dot (
861  grad (phi_j) *value (ETuFESpace, velocityExtrapolated) *DENSITY
862  + value (1.0 / dt) *DENSITY * phi_j
863  , SUPG_TEST)
864 
865  )
866  >> NSMatrix->block (0, 0);
867 
868 
869  integrate (
870  elements (ETuFESpace->mesh() ), // Mesh
871 
872  //uFESpace->qr(), // QR
873  adapt (ETlsFESpace, LSSolutionOld, uFESpace->qr() ), // QR
874 
875  ETuFESpace,
876  ETpFESpace,
877 
878  value (-1.0) *phi_j * div (phi_i)
879 
880  // SUPG
881  + dot ( grad (phi_j) , SUPG_TEST)
882 
883 
884  )
885  >> NSMatrix->block (0, 1);
886 
887 
888  integrate (
889  elements (ETuFESpace->mesh() ), // Mesh
890 
891  //uFESpace->qr(), // QR
892  adapt (ETlsFESpace, LSSolutionOld, uFESpace->qr() ), // QR
893 
894  ETpFESpace,
895  ETuFESpace,
896 
897  phi_i * div (phi_j)
898 
899  // PSPG
900  + dot (
901  grad (phi_j) *value (ETuFESpace, velocityExtrapolated) *DENSITY
902  + value (1.0 / dt) *DENSITY * phi_j
903  , PSPG_TEST)
904 
905 
906  )
907  >> NSMatrix->block (1, 0);
908 
909 
910  integrate (
911  elements (ETuFESpace->mesh() ), // Mesh
912 
913  //uFESpace->qr(), // QR
914  adapt (ETlsFESpace, LSSolutionOld, uFESpace->qr() ), // QR
915 
916  ETpFESpace,
917  ETpFESpace,
918 
919  // PSPG
920  dot (
921  grad (phi_j)
922  , PSPG_TEST)
923 
924  )
925  >> NSMatrix->block (1, 1);
926 
927 
928  }
929 
930  ChronoItem.stop();
931  if (verbose)
932  {
933  std::cout << ChronoItem.diff() << " s" << std::endl;
934  }
935 
936  if (verbose)
937  {
938  std::cout << "[Navier-Stokes] Boundary integral ... " << std::flush;
939  }
940 
941  ChronoItem.start();
942 
943  //QuadratureBoundary myBDQR(buildTetraBDQR(uFESpace->bdQr()));
944  QuadratureBoundary myBDQR (buildTetraBDQR (quadRuleTria4pt) );
945 
946  {
947  using namespace ::LifeV::ExpressionAssembly;
948 
949  std::shared_ptr<DensityFct> density (new DensityFct);
950  std::shared_ptr<ViscosityFct> viscosity (new ViscosityFct);
951  std::shared_ptr<HeavisideFct> heaviside (new HeavisideFct);
952  std::shared_ptr<NormalizeFct> normalize (new NormalizeFct);
953 
954 #ifdef NORMAL_CORRECTION
955  integrate ( boundary (ETuFESpace->mesh(), WALL),
956  adapt (ETlsFESpace, LSSolutionOld, myBDQR),
957  //myBDQR,
958 
959  ETuFESpace,
960  ETuFESpace,
961 
962  value (-1.0) *VISCOSITY * dot ( (grad (phi_j) *Nface), Nface)
963  * dot ( phi_i, Nface )
964  ) >> NSMatrix->block (0, 0);
965 
966  integrate ( boundary (ETuFESpace->mesh(), WALL),
967  myBDQR,
968 
969  ETuFESpace,
970  ETpFESpace,
971 
972  value (1.0) *phi_j * dot ( phi_i, Nface )
973  ) >> NSMatrix->block (0, 1);
974 #endif
975 
976 #ifdef FULL_CORRECTION
977  integrate ( boundary (ETuFESpace->mesh(), WALL),
978  adapt (ETlsFESpace, LSSolutionOld, myBDQR),
979  //myBDQR,
980 
981  ETuFESpace,
982  ETuFESpace,
983 
984  value (-1.0) *VISCOSITY * dot ( (grad (phi_j) *Nface), phi_i)
985 
986  ) >> NSMatrix->block (0, 0);
987 
988  integrate ( boundary (ETuFESpace->mesh(), WALL),
989  myBDQR,
990 
991  ETuFESpace,
992  ETpFESpace,
993 
994  value (1.0) *phi_j * dot ( phi_i, Nface )
995  ) >> NSMatrix->block (0, 1);
996 #endif
997 
998  }
999 
1000 
1001  ChronoItem.stop();
1002  if (verbose)
1003  {
1004  std::cout << ChronoItem.diff() << " s" << std::endl;
1005  }
1006 
1007 
1008  if (verbose)
1009  {
1010  std::cout << "[Navier-Stokes] Closing the matrix ... " << std::flush;
1011  }
1012 
1013  ChronoItem.start();
1014 
1015  NSMatrix->globalAssemble();
1016 
1017  ChronoItem.stop();
1018  if (verbose)
1019  {
1020  std::cout << ChronoItem.diff() << " s" << std::endl;
1021  }
1022 
1023 
1024  if (verbose)
1025  {
1026  std::cout << "[Navier-Stokes] Lifting the pressure ... " << std::flush;
1027  }
1028 
1029  ChronoItem.start();
1030 
1031  vector_type PressurePlus (ETpFESpace->map(), Repeated);
1032  vector_type PressureMinus (ETpFESpace->map(), Repeated);
1033 
1034  {
1035  vector_type N0 (GradientRecovery::ZZGradient (ETlsFESpace, LSSolutionOld, 0), Repeated);
1036  vector_type N1 (GradientRecovery::ZZGradient (ETlsFESpace, LSSolutionOld, 1), Repeated);
1037  vector_type N2 (GradientRecovery::ZZGradient (ETlsFESpace, LSSolutionOld, 2), Repeated);
1038 
1039  vector_type f0 (ETlsFESpace->map(), Unique);
1040 
1041  lsFESpace->interpolate (static_cast<FESpace< mesh_Type, MapEpetra >::function_Type> (volumeForce0), f0, currentTime);
1042  vector_type f1 (ETlsFESpace->map(), Unique);
1043  lsFESpace->interpolate (static_cast<FESpace< mesh_Type, MapEpetra >::function_Type> (volumeForce1), f1, currentTime);
1044  vector_type f2 (ETlsFESpace->map(), Unique);
1045  lsFESpace->interpolate (static_cast<FESpace< mesh_Type, MapEpetra >::function_Type> (volumeForce2), f2, currentTime);
1046 
1047  vector_type gn ( (densityPlus - densityMinus) * ( N0 * f0 + N1 * f1 + N2 * f2 ), Repeated);
1048  vector_type nNorm ( ( N0 * N0 + N1 * N1 + N2 * N2 ), Repeated);
1049 
1050  PressurePlus *= 0.0;
1051  PressureMinus *= 0.0;
1052 
1053  const UInt nbElements (ETpFESpace->mesh()->numElements() );
1054  const UInt nbLocalPDof (ETpFESpace->refFE().nbDof() );
1055 
1056 
1057  for (UInt iElement (0); iElement < nbElements; ++iElement)
1058  {
1059  for (UInt iDof (0); iDof < nbLocalPDof; ++iDof)
1060  {
1061  UInt globalID ( ETlsFESpace->dof().localToGlobalMap (iElement, iDof) );
1062 
1063  Real lsValue ( LSSolutionOld[globalID] );
1064 
1065  if (lsValue >= 0.0)
1066  {
1067  if (NormalizeCorrection)
1068  {
1069  PressureMinus[globalID] = -lsValue * gn[globalID] / sqrt (nNorm[globalID]) ;
1070  }
1071  else
1072  {
1073  PressureMinus[globalID] = -lsValue * gn[globalID];
1074  }
1075  }
1076  else
1077  {
1078  if (NormalizeCorrection)
1079  {
1080  PressurePlus[globalID] = lsValue * gn[globalID] / sqrt (nNorm[globalID]) ;
1081  }
1082  else
1083  {
1084  PressurePlus[globalID] = lsValue * gn[globalID];
1085  }
1086  }
1087  }
1088  }
1089  }
1090 
1091  ChronoItem.stop();
1092 
1093  if (verbose)
1094  {
1095  std::cout << ChronoItem.diff() << " s" << std::endl;
1096  }
1097 
1098  if (verbose)
1099  {
1100  std::cout << "[Navier-Stokes] Assembling the rhs ... " << std::flush;
1101  }
1102 
1103  ChronoItem.start();
1104 
1105  vector_type forceRhs (ETuFESpace->map(), Unique);
1106 
1107  uFESpace->interpolate (static_cast<FESpace< mesh_Type, MapEpetra >::function_Type> (volumeForce), forceRhs, currentTime);
1108 
1109  vector_block_type NSRhs ( ETuFESpace->map() | ETpFESpace->map() , Repeated );
1110  NSRhs *= 0.0;
1111 
1112  {
1113  using namespace ExpressionAssembly;
1114 
1115  std::shared_ptr<DensityFct> density (new DensityFct);
1116  std::shared_ptr<ViscosityFct> viscosity (new ViscosityFct);
1117  std::shared_ptr<HeavisideFct> heaviside (new HeavisideFct);
1118  std::shared_ptr<NormalizeFct> normalize (new NormalizeFct);
1119 
1120  integrate (
1121  elements (ETuFESpace->mesh() ), // Mesh
1122 
1123  adapt (ETlsFESpace, LSSolutionOld, uFESpace->qr() ), // QR
1124 
1125  ETuFESpace,
1126 
1127  DENSITY
1128  * dot ( value (1 / dt) *value (ETuFESpace, velocityBdfRHS) + value (ETuFESpace, forceRhs)
1129  , phi_i)
1130 
1131  // Pressure correction
1132  + value (1.0)
1133  * ( eval (heaviside, value (ETlsFESpace, LSSolutionOld) ) *value (ETpFESpace, PressurePlus)
1134  + (value (1.0) - eval (heaviside, value (ETlsFESpace, LSSolutionOld) ) ) *value (ETpFESpace, PressureMinus) )
1135  *div (phi_i)
1136 
1137  // SUPG
1138  + dot (
1139  DENSITY * value (1 / dt) *value (ETuFESpace, velocityBdfRHS)
1140  + DENSITY * value (ETuFESpace, forceRhs)
1141  - ( eval (heaviside, value (ETlsFESpace, LSSolutionOld) ) *grad (ETpFESpace, PressurePlus)
1142  + (value (1.0) - eval (heaviside, value (ETlsFESpace, LSSolutionOld) ) ) *grad (ETpFESpace, PressureMinus) )
1143  , SUPG_TEST)
1144 
1145 
1146  )
1147  >> NSRhs.block (0);
1148 
1149  integrate (
1150  elements (ETuFESpace->mesh() ), // Mesh
1151 
1152  adapt (ETlsFESpace, LSSolutionOld, pFESpace->qr() ), // QR
1153 
1154  ETpFESpace,
1155 
1156 
1157  // PSPG
1158  dot (
1159  DENSITY * value (1 / dt) *value (ETuFESpace, velocityBdfRHS)
1160  + DENSITY * value (ETuFESpace, forceRhs)
1161  - ( eval (heaviside, value (ETlsFESpace, LSSolutionOld) ) *grad (ETpFESpace, PressurePlus)
1162  + (value (1.0) - eval (heaviside, value (ETlsFESpace, LSSolutionOld) ) ) *grad (ETpFESpace, PressureMinus) )
1163  , PSPG_TEST)
1164 
1165 
1166  )
1167  >> NSRhs.block (1);
1168 
1169 #if defined(FULL_CORRECTION) || defined(NORMAL_CORRECTION)
1170 
1171  // BOUNDARY INTEGRAL FOR THE PRESSURE CORRECTION
1172  integrate ( boundary (ETuFESpace->mesh(), WALL),
1173  //myBDQR,
1174  adapt (ETlsFESpace, LSSolutionOld, myBDQR),
1175  ETuFESpace,
1176 
1177  value (-1.0) * ( eval (heaviside, value (ETlsFESpace, LSSolutionOld) ) *value (ETpFESpace, PressurePlus)
1178  + (value (1.0) - eval (heaviside, value (ETlsFESpace, LSSolutionOld) ) ) *value (ETpFESpace, PressureMinus) )
1179  * dot (phi_i, Nface)
1180 
1181  )
1182  >> NSRhs.block (0);
1183 #endif
1184 
1185  }
1186 
1187  ChronoItem.stop();
1188  if (verbose)
1189  {
1190  std::cout << ChronoItem.diff() << " s" << std::endl;
1191  }
1192 
1193 
1194  if (verbose)
1195  {
1196  std::cout << "[Navier-Stokes] Closing the rhs ... " << std::flush;
1197  }
1198 
1199  ChronoItem.start();
1200 
1201  vector_block_type NSRhsUnique ( NSRhs, Unique );
1202 
1203  ChronoItem.stop();
1204  if (verbose)
1205  {
1206  std::cout << ChronoItem.diff() << " s" << std::endl;
1207  }
1208 
1209 
1210  if (verbose)
1211  {
1212  std::cout << "[Navier-Stokes] Applying boundary conditions ... " << std::flush;
1213  }
1214 
1215  ChronoItem.start();
1216 
1217  BCHandler NSBCHandler;
1218  BCFunctionBase ZeroBCFct (zeroFct);
1219  BCFunctionBase OneBCFct (oneFct);
1220 
1221  std::vector<UInt> compXY (2);
1222  compXY[0] = 0;
1223  compXY[1] = 1;
1224 
1225  // Make the Robin coefficient
1226  vector_type LSReplicated (ETlsFESpace->map() + ETlsFESpace->map() + ETlsFESpace->map() );
1227  LSReplicated *= 0.0;
1228  LSReplicated.add (LSSolution, 0);
1229  LSReplicated.add (LSSolution, ETlsFESpace->dof().numTotalDof() );
1230  LSReplicated.add (LSSolution, 2 * ETlsFESpace->dof().numTotalDof() );
1231 
1232  // Assume same space!
1233  LSReplicated.apply (slipFct);
1234 
1235  vector_type RobinVec (0.0 * velocitySolution, Repeated);
1236  vector_type RobinCoeff (LSReplicated, Repeated);
1237 
1238  BCVector uRobin (RobinVec, ETuFESpace->dof().numTotalDof(), 0);
1239  uRobin.setRobinCoeffVector (RobinCoeff);
1240  uRobin.setBetaCoeff (0.0);
1241 
1242  BCFunctionDirectional directionFct (zeroFct, normalDirection);
1243 
1244  NSBCHandler.addBC ("BottomL", BOTTOM_LINE, Essential, Full, ZeroBCFct , 3);
1245  NSBCHandler.addBC ("TopL", TOP_LINE, Essential, Full, ZeroBCFct , 3);
1246  NSBCHandler.addBC ("Bottom", BOTTOM, Essential, Full, ZeroBCFct , 3);
1247 
1248  NSBCHandler.addBC ("Wall", WALL, Essential, Normal, ZeroBCFct);
1249  //NSBCHandler.addBC("Wall", WALL, Essential, Component, ZeroBCFct ,compXY);
1250  //NSBCHandler.addBC("Wall", WALL, Essential, Directional, directionFct);
1251 
1252  NSBCHandler.addBC ("Wall", WALL, Robin, Full, uRobin , 3);
1253  //NSBCHandler.addBC("Wall", WALL, Natural, Full, OneBCFct ,3);
1254 
1255  NSBCHandler.addBC ("Top", TOP, Essential, Full, ZeroBCFct , 3);
1256 
1257  NSBCHandler.bcUpdate ( *meshPart.meshPartition(), uFESpace->feBd(), uFESpace->dof() );
1258 
1259  bcManage (*NSMatrix, NSRhsUnique,
1260  *uFESpace->mesh(), uFESpace->dof(),
1261  NSBCHandler, uFESpace->feBd(), 1.0, currentTime);
1262 
1263  //NSMatrix->diagonalize(3*ETuFESpace->dof().numTotalDof(),1.0,NSRhsUnique,0.0);
1264 
1265  ChronoItem.stop();
1266  if (verbose)
1267  {
1268  std::cout << ChronoItem.diff() << " s" << std::endl;
1269  }
1270 
1271  if (verbose)
1272  {
1273  std::cout << "[Navier-Stokes] Solving the system " << std::endl;
1274  }
1275 
1276 
1277  NSSolver.setMatrix (*NSMatrix);
1278 
1279 
1280  std::shared_ptr<matrix_type> NSMatrixNoBlock (new matrix_type ( NSMatrix->map() ) );
1281  *NSMatrixNoBlock += *NSMatrix;
1282 
1283  NSSolver.solveSystem (NSRhsUnique, NSSolution, NSMatrixNoBlock);
1284 
1285 
1286  if (verbose)
1287  {
1288  std::cout << "[Navier-Stokes] Time advancing ... " << std::flush;
1289  }
1290 
1291  ChronoItem.start();
1292 
1293  NSSolutionOld = NSSolution;
1294 #ifdef BDF2_TIME
1295  velocitySolutionOldOld = velocitySolutionOld;
1296 #endif
1297  velocitySolutionOld.subset (NSSolutionOld);
1298 
1299  ChronoItem.stop();
1300  if (verbose)
1301  {
1302  std::cout << ChronoItem.diff() << " s" << std::endl;
1303  }
1304 
1305 
1306  if (verbose)
1307  {
1308  std::cout << std::endl;
1309  }
1310 
1311 
1312  if (verbose)
1313  {
1314  std::cout << "[LS advection] Assembling the matrix ... " << std::flush;
1315  }
1316 
1317  ChronoItem.start();
1318 
1319  std::shared_ptr<matrix_type> LSAdvectionMatrix (new matrix_type ( ETlsFESpace->map() ) );
1320  *LSAdvectionMatrix *= 0.0;
1321 
1322  {
1323  using namespace ExpressionAssembly;
1324 
1325  std::shared_ptr<SignFct> sign (new SignFct);
1326  std::shared_ptr<NormalizeFct> normalize (new NormalizeFct);
1327 
1328  integrate (
1329  elements (ETlsFESpace->mesh() ), // Mesh
1330 
1331  //adapt(ETlsFESpace,LSSolutionOld, lsFESpace->qr()), // QR
1332  lsFESpace->qr(),
1333 
1334  ETlsFESpace,
1335  ETlsFESpace,
1336 
1337  // Time derivative
1338  value (1 / dt) *phi_i * phi_j
1339 
1340  // Advection
1341  + dot ( value (ETuFESpace, velocitySolutionOld) , grad (phi_j) ) *phi_i
1342 
1343  // SUPG stabilization
1344  + ( value (LSSupg) *h_K )
1345  * ( value (1 / dt) *phi_j + dot ( value (ETuFESpace, velocitySolutionOld) , grad (phi_j) ) )
1346  //* dot( value(ETuFESpace,velocitySolutionOld) , grad(phi_i) )
1347  * dot ( eval (normalize, value (ETuFESpace, velocitySolutionOld) ) , grad (phi_i) )
1348 
1349  )
1350  >> LSAdvectionMatrix;
1351 
1352  }
1353 
1354  ChronoItem.stop();
1355  if (verbose)
1356  {
1357  std::cout << ChronoItem.diff() << " s" << std::endl;
1358  }
1359 
1360 
1361  if (verbose)
1362  {
1363  std::cout << "[LS advection] Closing the matrix ... " << std::flush;
1364  }
1365 
1366  ChronoItem.start();
1367 
1368  LSAdvectionMatrix->globalAssemble();
1369 
1370  ChronoItem.stop();
1371  if (verbose)
1372  {
1373  std::cout << ChronoItem.diff() << " s" << std::endl;
1374  }
1375 
1376 
1377  if (verbose)
1378  {
1379  std::cout << "[LS advection] Assembling the rhs ... " << std::flush;
1380  }
1381 
1382  ChronoItem.start();
1383 
1384  vector_type LSAdvectionRhs ( ETlsFESpace->map(), Repeated ); // Repeated right?
1385  LSAdvectionRhs *= 0.0;
1386 
1387  {
1388  using namespace ExpressionAssembly;
1389 
1390  std::shared_ptr<SignFct> sign (new SignFct);
1391  std::shared_ptr<NormalizeFct> normalize (new NormalizeFct);
1392 
1393  integrate (
1394  elements (ETlsFESpace->mesh() ), // Mesh
1395 
1396  //adapt(ETlsFESpace,LSSolutionOld, lsFESpace->qr()), // QR
1397  lsFESpace->qr(), // QR
1398 
1399  ETlsFESpace,
1400 
1401  // Time derivative
1402  value (1 / dt) *value (ETlsFESpace, LSSolutionOld) *phi_i
1403 
1404  // SUPG stabilization
1405  + ( value (LSSupg) *h_K )
1406  * (value (1 / dt) *value (ETlsFESpace, LSSolutionOld) )
1407  //* dot( value(ETuFESpace,velocitySolutionOld) , grad(phi_i) )
1408  * dot ( eval (normalize, value (ETuFESpace, velocitySolutionOld) ) , grad (phi_i) )
1409  )
1410  >> LSAdvectionRhs;
1411  }
1412 
1413  ChronoItem.stop();
1414  if (verbose)
1415  {
1416  std::cout << ChronoItem.diff() << " s" << std::endl;
1417  }
1418 
1419 
1420  if (verbose)
1421  {
1422  std::cout << "[LS advection] Closing the rhs ... " << std::flush;
1423  }
1424 
1425  ChronoItem.start();
1426 
1427  vector_type LSAdvectionRhsUnique ( LSAdvectionRhs, Unique );
1428 
1429  ChronoItem.stop();
1430  if (verbose)
1431  {
1432  std::cout << ChronoItem.diff() << " s" << std::endl;
1433  }
1434 
1435 
1436  if (verbose)
1437  {
1438  std::cout << "[LS advection] Solving the system " << std::endl;
1439  }
1440 
1441 
1442  LSAdvectionSolver.setMatrix (*LSAdvectionMatrix);
1443  LSAdvectionSolver.solveSystem (LSAdvectionRhsUnique, LSSolution, LSAdvectionMatrix);
1444 
1445 
1446  if (verbose)
1447  {
1448  std::cout << "[Hamilton-J.] Initializing ... " << std::flush;
1449  }
1450 
1451  ChronoItem.start();
1452 
1453  // To keep the original sign
1454  LSSolutionOld = LSSolution;
1455  HJSolutionOld = LSSolution;
1456 
1457  HJSolver.resetPreconditioner();
1458 
1459  ChronoItem.stop();
1460  if (verbose)
1461  {
1462  std::cout << ChronoItem.diff() << " s" << std::endl;
1463  }
1464 
1465  HJtime = 0.0;
1466 
1467  if (niter % HJeach == 0)
1468  {
1469 
1470  while ( HJtime < HJfinalTime)
1471  {
1472  HJtime += HJdt;
1473 
1474  if (verbose)
1475  {
1476  std::cout << std::endl;
1477  }
1478  if (verbose)
1479  {
1480  std::cout << "[Hamilton-J.] Time : " << HJtime << std::endl;
1481  }
1482  if (verbose)
1483  {
1484  std::cout << "[Hamilton-J.] Building the matrix ... " << std::flush;
1485  }
1486 
1487 
1488  ChronoItem.start();
1489 
1490  std::shared_ptr<matrix_type> HJMatrix (new matrix_type ( ETlsFESpace->map() ) );
1491  *HJMatrix *= 0.0;
1492 
1493 #define BETA ( eval(sign, value(ETlsFESpace,LSSolutionOld) ) * eval(normalization, grad(ETlsFESpace,HJSolutionOld) ) )
1494 
1495  {
1496  using namespace ExpressionAssembly;
1497 
1498  std::shared_ptr<SignFct> sign (new SignFct);
1499  std::shared_ptr<NormalizeFct> normalization (new NormalizeFct);
1500 
1501  integrate (
1502  elements (ETlsFESpace->mesh() ), // Mesh
1503 
1504  adapt (ETlsFESpace, LSSolutionOld, lsFESpace->qr() ), // QR
1505 
1506  ETlsFESpace,
1507  ETlsFESpace,
1508 
1509  // Time derivative
1510  (
1511  value (1 / HJdt) *phi_i * phi_j
1512  + dot ( BETA , grad (phi_j) ) *phi_i
1513 
1514  // SUPG stabilization
1515  + ( value (HJsupg) *h_K )
1516  * ( value (1 / HJdt) *phi_j + dot ( BETA , grad (phi_j) ) )
1517  * dot ( BETA , grad (phi_i) )
1518  )
1519  * (value (1.0) - ifCrossed (ETlsFESpace, LSSolutionOld) )
1520 
1521  +
1522  value (HJpenal) * ( phi_i * phi_j )
1523  *ifCrossed (ETlsFESpace, LSSolutionOld)
1524 
1525  )
1526  >> HJMatrix;
1527 
1528  }
1529 
1530  ChronoItem.stop();
1531  if (verbose)
1532  {
1533  std::cout << ChronoItem.diff() << " s" << std::endl;
1534  }
1535 
1536 
1537  if (verbose)
1538  {
1539  std::cout << "[Hamilton-J.] Closing the matrix ... " << std::flush;
1540  }
1541 
1542  ChronoItem.start();
1543 
1544  HJMatrix->globalAssemble();
1545 
1546  ChronoItem.stop();
1547  if (verbose)
1548  {
1549  std::cout << ChronoItem.diff() << " s" << std::endl;
1550  }
1551 
1552 
1553  if (verbose)
1554  {
1555  std::cout << "[Hamilton-J.] Assembling the rhs " << std::flush;
1556  }
1557 
1558  ChronoItem.start();
1559 
1560  vector_type HJRhs ( ETlsFESpace->map(), Repeated );
1561  HJRhs *= 0.0;
1562 
1563  {
1564  using namespace ExpressionAssembly;
1565 
1566  std::shared_ptr<SignFct> sign (new SignFct);
1567  std::shared_ptr<NormalizeFct> normalization (new NormalizeFct);
1568  std::shared_ptr<NormFct> norm (new NormFct);
1569 
1570  integrate (
1571  elements (ETlsFESpace->mesh() ), // Mesh
1572 
1573  adapt (ETlsFESpace, LSSolutionOld, lsFESpace->qr() ), // QR
1574 
1575  ETlsFESpace,
1576 
1577  (
1578  value (1 / HJdt) *value (ETlsFESpace, HJSolutionOld) *phi_i
1579  + eval (sign, value (ETlsFESpace, LSSolutionOld) ) *phi_i
1580 
1581  + ( value (HJsupg) *h_K )
1582  * ( value (1 / HJdt) *value (ETlsFESpace, HJSolutionOld) + eval (sign, value (ETlsFESpace, LSSolutionOld) ) )
1583  * dot ( BETA, grad (phi_i) )
1584  ) * (value (1.0) - ifCrossed (ETlsFESpace, LSSolutionOld) )
1585 
1586  + value (HJpenal) * ( phi_i * value (ETlsFESpace, LSSolutionOld) / eval (norm, grad (ETlsFESpace, LSSolutionOld) ) ) * ifCrossed (ETlsFESpace, LSSolutionOld)
1587  )
1588 
1589  >> HJRhs;
1590  }
1591 
1592  ChronoItem.stop();
1593  if (verbose)
1594  {
1595  std::cout << ChronoItem.diff() << " s" << std::endl;
1596  }
1597 
1598 
1599  if (verbose)
1600  {
1601  std::cout << "[Hamilton-J.] Closing the rhs ... " << std::flush;
1602  }
1603 
1604  ChronoItem.start();
1605 
1606  vector_type HJRhsUnique ( HJRhs, Unique );
1607 
1608  ChronoItem.stop();
1609  if (verbose)
1610  {
1611  std::cout << ChronoItem.diff() << " s" << std::endl;
1612  }
1613 
1614 
1615  if (verbose)
1616  {
1617  std::cout << "[Hamilton-J.] Solving the system ... " << std::flush;
1618  }
1619 
1620  ChronoItem.start();
1621 
1622  HJSolver.setMatrix (*HJMatrix);
1623  HJSolver.solveSystem (HJRhsUnique, LSSolution, HJMatrix);
1624 
1625  ChronoItem.stop();
1626  if (verbose)
1627  {
1628  std::cout << ChronoItem.diff() << " s" << std::endl;
1629  }
1630 
1631 
1632  if (verbose)
1633  {
1634  std::cout << "[Hamilton-J.] Update the solution ... " << std::flush;
1635  }
1636 
1637  ChronoItem.start();
1638 
1639  HJSolutionOld = LSSolution;
1640 
1641  ChronoItem.stop();
1642  if (verbose)
1643  {
1644  std::cout << ChronoItem.diff() << " s" << std::endl;
1645  }
1646 
1647  if (verbose)
1648  {
1649  std::cout << std::endl;
1650  }
1651  } // end of the pseudo-time loop
1652  } // end if
1653 
1654  if (verbose)
1655  {
1656  std::cout << "[LS correction] Correction of the volume ... " << std::flush;
1657  }
1658 
1659  ChronoItem.start();
1660 
1661  Real localVolume = 0.0;
1662  Real globalVolume = 0.0;
1663 
1664  Real localArea = 0.0;
1665  Real globalArea = 0.0;
1666 
1667  {
1668  using namespace ExpressionAssembly;
1669 
1670  std::shared_ptr<HeavisideFct> heaviside (new HeavisideFct);
1671  std::shared_ptr<SmoothDeltaFct> delta (new SmoothDeltaFct);
1672 
1673  integrate (
1674  elements (ETlsFESpace->mesh() ), // Mesh
1675  adapt (ETlsFESpace, LSSolution, lsFESpace->qr() ), // QR
1676  eval (heaviside, value (ETlsFESpace, LSSolution) ) // Expression
1677  )
1678  >> localVolume;
1679 
1680  integrate (
1681  elements (ETlsFESpace->mesh() ), // Mesh
1682  adapt (ETlsFESpace, LSSolution, lsFESpace->qr() ), // QR
1683  eval (delta, value (ETlsFESpace, LSSolution) ) // Expression
1684  )
1685  >> localArea;
1686 
1687  }
1688 
1689  Comm->Barrier();
1690  Comm->SumAll (&localVolume, &globalVolume, 1);
1691 
1692  Comm->Barrier();
1693  Comm->SumAll (&localArea, &globalArea, 1);
1694 
1695 
1696  LSSolution += volumeRelaxation * (exactVolume - globalVolume) / globalArea;
1697 
1698 
1699  ChronoItem.stop();
1700  if (verbose)
1701  {
1702  std::cout << ChronoItem.diff() << " s" << std::endl;
1703  }
1704  if (verbose)
1705  {
1706  std::cout << "[LS correction] Rel. vol. diff: " << (exactVolume - globalVolume) / exactVolume << std::endl;
1707  }
1708  if (verbose)
1709  {
1710  std::cout << "[LS correction] Approx. area: " << globalArea << std::endl;
1711  }
1712 
1713 
1714  if (verbose)
1715  {
1716  std::cout << "[LS advection] Time advancing ... " << std::flush;
1717  }
1718 
1719  ChronoItem.start();
1720 
1721  LSSolutionOld = LSSolution;
1722 
1723  ChronoItem.stop();
1724  if (verbose)
1725  {
1726  std::cout << ChronoItem.diff() << " s" << std::endl;
1727  }
1728 
1729 
1730  if (verbose)
1731  {
1732  std::cout << " Exporting " << std::endl;
1733  }
1734 
1735 
1736  *LSExported = LSSolutionOld;
1737  *NSExported = NSSolutionOld;
1738 
1739  if (niter % exportEach == 0)
1740  {
1741  exporter.postProcess (currentTime);
1742  }
1743 
1744  ChronoIteration.stop();
1745  if (verbose)
1746  {
1747  std::cout << std::endl << " Total iteration time : " << ChronoIteration.diff() << " s" << std::endl;
1748  }
1749 
1750  if (verbose)
1751  {
1752  displayMotionParameters (currentTime);
1753  }
1754 
1755  } // end time loop
1756 
1757 
1758  exporter.closeFile();
1759 
1760 #ifdef HAVE_MPI
1761  MPI_Finalize();
1762 #endif
1763 
1764 
1765  return ( EXIT_SUCCESS );
1766 }
void meshMap(Real &x, Real &y, Real &z)
VectorEpetra - The Epetra Vector format Wrapper.
VectorBlockMonolithicEpetra - class of block vector.
Real HJfinalTime(HJdt)
Real initLSFct(const Real &, const Real &, const Real &, const Real &z, const ID &)
bool NormalizeCorrection(true)
Real alphaBL(3.0)
Real thetaInit(0.0)
Real HJdt(2e-2)
return_Type operator()(const Real &value)
Real slipFriction(0.0)
Real tRise(6.0)
UInt HJeach(1)
Real volumeForce(const Real &t, const Real &, const Real &, const Real &, const ID &i)
Real NSSupg(1.0e-3)
void importFromHDF5(std::string const &fileName, std::string const &matrixName="matrix")
Read a matrix from a HDF5 (.h5) file.
#define DIVDIV_TEST
Real HJtime(0.0)
Real normalDirection(const Real &, const Real &x, const Real &y, const Real &, const ID &i)
#define BETA
Real volumeRelaxation(0.5)
return_Type operator()(const VectorSmall< 3 > &value)
Real cylinderHeight(0.4)
Real cylinderRadius(0.144)
Real volumeForce0(const Real &t, const Real &x, const Real &y, const Real &z, const ID &)
Real epsilonArea(0.05)
#define SUPG_TEST
#define M_PI
Definition: winmath.h:20
Real HJsupg(5e-1)
Real slipLength(0.05)
Real zeroFct(const Real &, const Real &, const Real &, const Real &, const ID &)
VectorSmall< 3 > operator*(Real const &factor) const
Operator * (multiplication by scalar on the right)
MatrixEpetra< Real > matrix_type
Real NSPspg(1.0e-3)
Real omegaMax(2 *M_PI)
uint32_type ID
IDs.
Definition: LifeV.hpp:194
Real viscosityMinus(2e-5)
RegionMesh< LinearTetra > mesh_Type
Real liquidHeight(0.1)
Real volumeForce1(const Real &t, const Real &x, const Real &y, const Real &z, const ID &)
Real oneFct(const Real &, const Real &, const Real &, const Real &, const ID &)
Real shakeRadius(0.1)
#define PSPG_TEST
double Real
Generic real data.
Definition: LifeV.hpp:175
Real densityMinus(1.0)
return_Type operator()(const Real &value)
Real viscosityRatio(50.0)
Real HJpenal(1e5)
Real omegaInit(0.0)
return_Type operator()(const Real &value)
int main(int argc, char **argv)
return_Type operator()(const Real &value)
MatrixEpetraStructured - class of block matrix.
void displayMotionParameters(const Real &t)
return_Type operator()(const VectorSmall< 3 > value)
Real noSlipCoef(1e6)
Real initVelocity(const Real &, const Real &, const Real &, const Real &, const ID &i)
VectorBlockMonolithicEpetra vector_block_type
Real NSdivdiv(5.0e2)
Real viscosityPlus(1e-3)
return_Type operator()(const Real &value)
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
Real densityPlus(1000.0)
UInt exportEach(1)
Real LSSupg(5e-2)
MatrixEpetraStructured< Real > matrix_block_type
Real volumeForce2(const Real &t, const Real &x, const Real &y, const Real &z, const ID &)