LifeV
OseenSolverImplementation.cpp
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 the implementation of the file OseenSolver.hpp
30 
31  @author Davide Forti <davide.forti@epfl.ch>
32 
33  @date 28-01-2014
34 
35  */
36 
37 #include <lifev/core/LifeV.hpp>
38 
39 namespace LifeV
40 {
41 
43 {
44 public:
46 
47  inline return_Type operator() (Real a, Real b, Real c)
48  {
49  VectorSmall<3> o;
50  o[0] = a;
51  o[1] = b;
52  o[2] = c;
53  return o;
54  }
55 
59 };
60 
61 // ===================================================
62 // Constructors & Destructor
63 // ===================================================
64 
65 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
66 OseenSolver<MeshType, SolverType, MapType , SpaceDim, FieldDim>::
67 OseenSolver ( boost::shared_ptr<data_Type> dataType,
68  FESpace<mesh_Type, MapEpetra>& velocityFESpace,
69  FESpace<mesh_Type, MapEpetra>& pressureFESpace,
70  boost::shared_ptr<Epetra_Comm>& communicator,
71  const Int lagrangeMultiplier ) :
72  M_oseenData ( dataType ),
73  M_velocityFESpace ( velocityFESpace ),
74  M_pressureFESpace ( pressureFESpace ),
75  M_Displayer ( communicator ),
76  M_fluxMap ( lagrangeMultiplier, communicator),
77  M_localMap ( M_velocityFESpace.map() + M_pressureFESpace.map() + lagrangeMultiplier),
78  M_velocityMatrixMass ( ),
79  M_pressureMatrixMass ( ),
80  M_matrixStokes ( ),
81  M_matrixNoBC ( ),
82  M_matrixStabilization ( ),
83  M_rightHandSideNoBC ( ),
84  M_solution ( new vector_Type ( M_localMap ) ),
85  M_residual ( new vector_Type (M_localMap ) ),
86  M_linearSolver ( new linearSolver_Type (communicator) ),
87  M_steady ( ),
88  M_postProcessing ( new PostProcessingBoundary<mesh_Type> ( M_velocityFESpace.mesh(),
89  &M_velocityFESpace.feBd(),
90  &M_velocityFESpace.dof(),
91  &M_pressureFESpace.feBd(),
92  &M_pressureFESpace.dof(),
93  M_localMap ) ),
94  M_stabilization ( false ),
95  M_reuseStabilization ( false ),
96  M_resetStabilization ( false ),
97  M_iterReuseStabilization ( -1 ),
98  // M_ipStabilization ( M_velocityFESpace.mesh(),
99  // M_velocityFESpace.dof(),
100  // M_velocityFESpace.refFE(),
101  // M_velocityFESpace.feBd(),
102  // M_velocityFESpace.qr(),
103  // 0., 0., 0.,
104  // M_oseenData->viscosity() ),
105  M_betaFunction ( 0 ),
106  M_divBetaUv ( false ),
107  M_stiffStrain ( false ),
108  M_diagonalize ( false ),
109  M_count ( 0 ),
110  M_recomputeMatrix ( false ),
111  M_elementMatrixStiff ( M_velocityFESpace.fe().nbFEDof(), velocityFESpace.fieldDim(), velocityFESpace.fieldDim() ),
112  M_elementMatrixMass ( M_velocityFESpace.fe().nbFEDof(), velocityFESpace.fieldDim(), velocityFESpace.fieldDim() ),
113  M_elementMatrixPreconditioner ( M_pressureFESpace.fe().nbFEDof(), 1, 1 ),
114  M_elementMatrixDivergence ( M_pressureFESpace.fe().nbFEDof(), 1, 0,
115  M_velocityFESpace.fe().nbFEDof(), 0, velocityFESpace.fieldDim() ),
116  M_elementMatrixGradient ( M_velocityFESpace.fe().nbFEDof(), velocityFESpace.fieldDim(), 0,
117  M_pressureFESpace.fe().nbFEDof(), 0, 1 ),
118  M_elementRightHandSide ( M_velocityFESpace.fe().nbFEDof(), velocityFESpace.fieldDim() ),
119  M_wLoc ( M_velocityFESpace.fe().nbFEDof(), velocityFESpace.fieldDim() ),
120  M_uLoc ( M_velocityFESpace.fe().nbFEDof(), velocityFESpace.fieldDim() ),
121  M_un ( new vector_Type (M_localMap) ),
122  M_velocityPreviousTimestep (new vector_Type (M_velocityFESpace.map()) ),
123  M_pressurePreviousTimestep (new vector_Type (M_pressureFESpace.map()) ),
124  M_pressureExtrapolated ( new vector_Type (M_pressureFESpace.map() ) ),
125  M_fespaceUETA ( new ETFESpace_velocity(M_velocityFESpace.mesh(), &(M_velocityFESpace.refFE()), communicator)),
126  M_fespacePETA ( new ETFESpace_pressure(M_pressureFESpace.mesh(), &(M_pressureFESpace.refFE()), communicator)),
127  M_supgStabilization (new StabilizationSUPG<mesh_Type, MapEpetra, SpaceDim>(velocityFESpace, pressureFESpace)),
128  M_supgVmsStabilization (new StabilizationSUPGVMS<mesh_Type, MapEpetra, SpaceDim>(velocityFESpace, pressureFESpace)),
129  M_VMSLESStabilization (new StabilizationVMSLES<mesh_Type, MapEpetra, SpaceDim>(velocityFESpace, pressureFESpace))
130 {
131  *M_solution *= 0;
132  // if(M_stabilization = ( &M_velocityFESpace.refFE() == &M_pressureFESpace.refFE() ))
133  {
134  M_ipStabilization.setFeSpaceVelocity (M_velocityFESpace);
135  M_ipStabilization.setViscosity (M_oseenData->viscosity() );
136  }
137 }
138 
139 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
146  UInt offset ) :
147  M_oseenData ( dataType ),
154  M_matrixStokes ( ),
155  M_matrixNoBC ( ),
158  M_solution ( ),
159  M_residual ( ),
160  M_linearSolver ( ),
166  M_localMap ) ),
167  M_stabilization ( false ),
168  M_reuseStabilization ( false ),
169  M_resetStabilization ( false ),
171  M_betaFunction ( 0 ),
172  M_divBetaUv ( false ),
173  M_stiffStrain ( false ),
174  M_diagonalize ( false ),
175  M_count ( 0 ),
176  M_recomputeMatrix ( false ),
183  M_pressureFESpace.fe().nbFEDof(), 0, 1 ),
187  M_un ( /*new vector_Type(M_localMap)*/ ),
196 {
197  ASSERT(0!=0,"ENTERING IN THE MONOLITHIC CONSTRUCTOR");
198  // if(M_stabilization = ( &M_velocityFESpace.refFE() == &M_pressureFESpace.refFE() ))
199  {
202  }
203 }
204 
205 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
212  M_oseenData ( dataType ),
219  M_matrixStokes ( ),
220  M_matrixNoBC ( ),
223  M_solution ( new vector_Type ( M_localMap ) ),
224  M_residual ( ),
231  M_localMap ) ),
232  M_stabilization ( false ),
233  M_reuseStabilization ( false ),
234  M_resetStabilization ( false ),
236  M_betaFunction ( 0 ),
237  M_divBetaUv ( false ),
238  M_stiffStrain ( false ),
239  M_diagonalize ( false ),
240  M_count ( 0 ),
241  M_recomputeMatrix ( false ),
248  M_pressureFESpace.fe().nbFEDof(), 0, 1 ),
252  M_un ( new vector_Type (M_localMap) ),
261 {
262  *M_solution *= 0;
263  // if(M_stabilization = ( &M_velocityFESpace.refFE() == &M_pressureFESpace.refFE() ))
264  {
267  }
268 }
269 
270 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
272 ~OseenSolver()
273 {
274 
275 }
276 
277 
278 // ===================================================
279 // Methods
280 // ===================================================
281 
282 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
283 void
285 {
286  if (M_linearSolver.get() )
287  {
288  M_linearSolver->setupPreconditioner ( dataFile, "fluid/prec" );
289  M_linearSolver->setDataFromGetPot ( dataFile, "fluid/solver" );
290  }
291 
292  M_stabilization = dataFile ( "fluid/stabilization/use", /*(&M_velocityFESpace.refFE() == &M_pressureFESpace.refFE() ) ,*/ false);
293 
294  // If using P1-P1 the use of the stabilization is necessary
295  //if(&M_velocityFESpace.refFE() == &M_pressureFESpace.refFE())
296  // M_stabilization = true;
297 
298  M_steady = dataFile ( "fluid/miscellaneous/steady", 0 );
299 
300  Real bdfOrder = dataFile ( "fluid/time_discretization/BDF_order", 1.0 );
301 
302  if (M_stabilization)
303  {
304  if(M_oseenData->stabilizationType() == "IP")
305  {
306  M_gammaBeta = dataFile ( "fluid/ipstab/gammaBeta", 0. );
307  M_gammaDiv = dataFile ( "fluid/ipstab/gammaDiv", 0. );
308  M_gammaPress = dataFile ( "fluid/ipstab/gammaPress", 0. );
309  M_reuseStabilization = dataFile ( "fluid/ipstab/reuse", false );
310 
314 
315  if (M_linearSolver.get() )
316  M_iterReuseStabilization = dataFile ( "fluid/ipstab/max_iter_reuse", static_cast<Int> ( M_linearSolver->maxNumIterations() * 8. / 10. ) );
317  }
318  else if (M_oseenData->stabilizationType() == "SUPG")
319  {
320  int vel_order = dataFile ( "fluid/space_discretization/vel_order", 1 );
329 
330  }
331  else if (M_oseenData->stabilizationType() == "SUPGVMS")
332  {
333  int vel_order = dataFile ( "fluid/space_discretization/vel_order", 1 );
342 
343  }
344  else if (M_oseenData->stabilizationType() == "VMSLES")
345  {
348  int vel_order = dataFile ( "fluid/space_discretization/vel_order", 1 );
357  }
358  }
359  // Energetic stabilization term
360  M_divBetaUv = dataFile ( "fluid/space_discretization/div_beta_u_v", false);
361  // Enable grad( u )^T in stress tensor
362  M_stiffStrain = dataFile ( "fluid/space_discretization/stiff_strain", false);
363  M_diagonalize = dataFile ( "fluid/space_discretization/diagonalize", 1. );
364 
365  // M_linearSolver.setAztecooPreconditioner( dataFile, "fluid/solver" );
366 
367 }
368 
369 
370 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
371 void
374 {
378  M_oseenData->dataTime()->time() );
379 
383  M_oseenData->dataTime()->time() );
384 
386 }
387 
388 
389 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
390 void
393 {
394 
399 
400 }
401 
402 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
403 void
406 {
407 
409  if ( M_solution.get() )
410  {
412  }
413 
414 }
415 
416 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
417 void
419  const GetPot& dataFile, BCHandler& bcDrag,
423 {
426 
427  {
428  using namespace ExpressionAssembly;
429 
430  integrate(
436  ) >> laplacian;
437  }
438 
440  rhs_drag *= 0;
441 
443  rhs_lift *= 0;
444 
447 
450 
452 
454 
457 
461 
462  // drag
465 
466  linearSolver_drag->setupPreconditioner ( dataFile, "preprocessing/prec" );
467  linearSolver_drag->setDataFromGetPot ( dataFile, "preprocessing/solver" );
468 
470 
473 
475 
476  // lift
479 
480  linearSolver_lift->setupPreconditioner ( dataFile, "preprocessing/prec" );
481  linearSolver_lift->setDataFromGetPot ( dataFile, "preprocessing/solver" );
482 
484 
487 
489 }
490 
491 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
492 void
494 {
495  // New ETA PART
496  /*
497  * TESTING THE ASSEMBLY USING ETA
498  *
499  */
500 
501  M_Displayer.leaderPrint ( " F- Computing constant matrices ... " );
503  chrono.start();
504 
507 
508  *M_velocityMatrixMass *= 0;
509  *M_matrixStokes *= 0;
510 
511  {
512  using namespace ExpressionAssembly;
513 
514  if ( !M_steady )
515  {
516  integrate(
522  ) >> M_velocityMatrixMass->block(0,0);
523 
525 
529  }
530 
531  if ( M_stiffStrain )
532  {
533  integrate(
539  ) >> M_matrixStokes->block(0,0);
540  }
541  else
542  {
543  integrate(
549  ) >> M_matrixStokes->block(0,0);
550  }
551 
552 
553  integrate(
558  value(-1.0) * phi_j * div(phi_i)
559  ) >> M_matrixStokes->block(0,1);
560 
561  integrate(
566  phi_i * div(phi_j)
567  ) >> M_matrixStokes->block(1,0);
568  }
569 
571 
572  chrono.stop();
573  M_Displayer.leaderPrintMax ( "done in " , chrono.diff() );
574 
575 }
576 
577 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
578 void
581  const vector_Type& u_star,
582  const vector_Type& rightHandSide )
583 {
584  if ( M_matrixNoBC.get() )
585  {
587  }
588  else
589  {
591  }
592 
594  if ( alphaOverTimestep != 0. )
595  {
597  }
598 
599 }
600 
601 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
602 void
605  const vector_Type& u_star,
606  const vector_Type& rightHandSide,
608  const vector_Type& un )
609 {
610  M_Displayer.leaderPrint ( " F- Setting the right hand side ..." );
612  chrono.start();
613 
615 
616  chrono.stop();
617  M_Displayer.leaderPrintMax ( " done in ", chrono.diff() );
618 
620 
621  if ( M_recomputeMatrix )
622  buildSystem();
623 
624  //! managing the convective term : semi-implicit approximation of the convective term
625 
626  Real normInf;
627  u_star.normInf ( &normInf );
628 
629  MatrixSmall<3, 3> Eye;
630  Eye *= 0.0;
631  Eye[0][0] = 1;
632  Eye[1][1] = 1;
633  Eye[2][2] = 1;
634 
635  // u_star: extrapolation of the velocity
636  // NOTE: for ALE formulation it has to be already: extrapolation of fluid velocity - extrapolation of fluid mesh velocity
638 
640  *M_convectiveMatrix *= 0;
641 
642  // only if the extrapolation of the velocity differs from zero we update the convective term
643  if ( normInf != 0. )
644  {
646  *M_convectiveMatrix *= 0;
647 
649  {
650  using namespace ExpressionAssembly;
651  integrate(
652  elements(M_fespaceUETA->mesh()), // Mesh
653  M_velocityFESpace.qr(), // QR
656  dot(grad(phi_j) * M_oseenData->density() * value(M_fespaceUETA, u_starRepeated), phi_i) // semi-implicit convective term
657  + 0.5 * M_oseenData->density() * dot ( value ( Eye ) , grad(M_fespaceUETA, u_starRepeated) ) * dot( phi_j , phi_i ) // consistency term
658  // - M_oseenData->density() * dot ( value ( Eye ) , grad(M_fespaceUETA, wRepeated) ) * dot( phi_j , phi_i ) // conservative formulation
659  )
660  >> M_convectiveMatrix->block(0,0);
661  }
662  else
663  {
664  using namespace ExpressionAssembly;
665  integrate(
666  elements(M_fespaceUETA->mesh()), // Mesh
667  M_velocityFESpace.qr(), // Quadrature rule
670  value(M_oseenData->density()) * dot(phi_i, value(M_fespaceUETA, u_starRepeated)*grad(phi_j)) // semi-implicit treatment of the convective term
671  // value( -1.0*M_oseenData->density() )* dot( grad(phi_i), outerProduct( value(M_fespaceUETA, u_starRepeated), phi_j ) )
672  )
673  >> M_convectiveMatrix->block(0,0);
674  }
675 
676  // Stabilising term: -rho div(u^n) u v
677  if ( M_divBetaUv )
678  {
679  ASSERT(0!=0,"If really needed, please code it using ET");
680  // OLD-STYLE assembly:
681  // mass_divw ( -0.5 * M_oseenData->density(),
682  // M_uLoc,
683  // M_elementMatrixStiff,
684  // M_velocityFESpace.fe(), 0, 0, numVelocityComponent );
685  }
686  }
687 
688  if(M_stabilization)
690 
691  if ( alphaOverTimestep != 0. )
692  {
694  }
695 
698 
705 
706 }
707 
708 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
709 void
711 {
712  Real normInf;
713  u_star.normInf ( &normInf );
714 
716 
717  if ( normInf != 0. )
718  {
719  if( M_oseenData->stabilizationType() == "IP" /*&& ( M_resetStabilization || !M_reuseStabilization || ( M_matrixStabilization.get() == 0 ) )*/ )
720  {
722  M_Displayer.leaderPrint ( " F- Updating the IP stabilization terms ... " );
723  chrono.start();
724 
728  M_resetStabilization = false;
729  chrono.stop();
730  M_Displayer.leaderPrintMax ( "done in " , chrono.diff() );
731  }
732  else if(M_oseenData->stabilizationType() == "SUPG")
733  {
734 
735  M_Displayer.leaderPrint ( " F- Updating the SUPG stabilization terms ... " );
736  chrono.start();
737 
738  // TIpically here alpha is already divided by the timestep, but I want to use the actual alfa, so I multiply
746 
748  *M_rhsStabilization *= 0;
750 
751  chrono.stop();
752  M_Displayer.leaderPrintMax ( "done in " , chrono.diff() );
753 
754  }
755  else if(M_oseenData->stabilizationType() == "SUPGVMS")
756  {
757 
758  M_Displayer.leaderPrint ( " F- Updating the SUPG-VMS stabilization terms ... " );
759  chrono.start();
760 
761  // TIpically here alpha is already divided by the timestep, but I want to use the actual alfa, so I multiply
769 
771  *M_rhsStabilization *= 0;
773 
774  chrono.stop();
775  M_Displayer.leaderPrintMax ( "done in " , chrono.diff() );
776 
777  }
778  else if(M_oseenData->stabilizationType() == "VMSLES")
779  {
780 
781  M_Displayer.leaderPrint ( " F- Updating the VMSLES stabilization terms ... " );
782  chrono.start();
783 
784  // TIpically here alpha is already divided by the timestep, but I want to use the actual alfa, so I multiply
789  u_star,
790  alpha,
792  *M_velocityRhs);
793 
797 
799  *M_rhsStabilization *= 0;
801  u_star,
802  *M_velocityRhs,
803  alpha,
805 
806  chrono.stop();
807  M_Displayer.leaderPrintMax ( "done in " , chrono.diff() );
808 
809  }
810  }
811  else
812  {
813  if (M_oseenData->stabilizationType() == "IP")
814  {
815  M_Displayer.leaderPrint ( " F- Updating the IP stabilization terms ... " );
816  chrono.start();
817 
819  {
823  M_resetStabilization = false;
824  chrono.stop();
825  M_Displayer.leaderPrintMax ( "done in " , chrono.diff() );
826  }
827  else
828  {
829  M_Displayer.leaderPrint ( "reusing\n" );
830  }
831  }
832  else if(M_oseenData->stabilizationType() == "SUPG")
833  {
834 
835  M_Displayer.leaderPrint ( " F- Updating the SUPG stabilization terms ... " );
836  chrono.start();
837 
838  // TIpically here alpha is already divided by the timestep, but I want to use the actual alfa, so I multiply
843 
847 
848  // comment because if steady simulation this is not needed
850  *M_rhsStabilization *= 0;
852 
853  chrono.stop();
854  M_Displayer.leaderPrintMax ( "done in " , chrono.diff() );
855 
856  }
857  else if(M_oseenData->stabilizationType() == "SUPGVMS")
858  {
859 
860  M_Displayer.leaderPrint ( " F- Updating the SUPG-VMS stabilization terms ... " );
861  chrono.start();
862 
863  // TIpically here alpha is already divided by the timestep, but I want to use the actual alfa, so I multiply
868 
872 
873  // comment because if steady simulation this is not needed
875  *M_rhsStabilization *= 0;
877 
878  chrono.stop();
879  M_Displayer.leaderPrintMax ( "done in " , chrono.diff() );
880 
881  }
882  else if(M_oseenData->stabilizationType() == "VMSLES")
883  {
884 
885  M_Displayer.leaderPrint ( " F- Updating the VMSLES stabilization terms ... " );
886  chrono.start();
887 
888  // TIpically here alpha is already divided by the timestep, but I want to use the actual alfa, so I multiply
893  u_star,
894  alpha,
896  *M_velocityRhs);
897 
901 
902  // comment because if steady simulation this is not needed
904  *M_rhsStabilization *= 0;
906  u_star,
907  *M_velocityRhs,
908  alpha,
910 
911  chrono.stop();
912  M_Displayer.leaderPrintMax ( "done in " , chrono.diff() );
913 
914  }
915  }
916 }
917 
918 
919 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
920 void
922 {
923  if ( M_stabilization )
924  {
927  }
928 
929 }
930 
931 template <typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
933 {
935 
937  UInt nc = nDimensions;
938 
939  // loop on volumes: assembling source term
940  for ( UInt i = 1; i <= M_velocityFESpace->mesh()->numVolumes(); ++i )
941  {
942 
944 
945  M_elvec.zero();
946 
947  for ( UInt ic = 0; ic < nc; ++ic )
948  {
949  compute_vec ( source, M_elvec, M_velocityFESpace->fe(), M_oseenData->dataTime()->time(), ic ); // compute local vector
950  assembleVector ( *rhs, M_elvec, M_velocityFESpace->fe(), M_velocityFESpace->dof(), ic, ic * M_velocityFESpace->getDim() ); // assemble local vector into global one
951  }
952  }
953  M_rightHandSideNoBC *= 0;
955 }
956 
957 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
958 void
960 {
961 
963 
964  // matrix and vector assembling communication
965  M_Displayer.leaderPrint ( " F- Updating the boundary conditions ... " );
966 
967  // HERE I SHOULD APPLY THE STABILIZATION ON THE RHS
968 
969  chrono.start();
970 
972 
974 
976 
978 
980 
981  if(M_stabilization)
982  {
983  if(M_oseenData->stabilizationType() == "SUPG" || M_oseenData->stabilizationType() == "SUPGVMS" || M_oseenData->stabilizationType() == "VMSLES" )
984  {
986  }
987  }
988 
989  chrono.stop();
990 
991  M_Displayer.leaderPrintMax ( "done in ", chrono.diff() );
992 
993  // boundary conditions update
994  M_Displayer.leaderPrint (" F- Applying boundary conditions ... ");
995 
996  chrono.start();
997 
999 
1001 
1002  chrono.stop();
1003 
1004  M_Displayer.leaderPrintMax ( "done in " , chrono.diff() );
1005 
1006  // solving the system
1008 
1010 
1012 
1013  // if the preconditioner has been rese the stab terms are to be updated
1014  if ( numIter < 0 || numIter > M_iterReuseStabilization )
1015  {
1017  }
1018 
1019  if (M_stabilization && M_oseenData->stabilizationType() == "VMSLES" )
1020  {
1023 
1026  }
1027 
1028  // Computation of the residual for the coefficients
1029 
1031  *matrixNoBC *= 0;
1035 
1038 
1039  *M_residual *= 0;
1040 
1042  *M_residual -= (*matrixNoBC) * (*M_solution);
1043 
1044  //M_residual.spy("residual");
1045 } // iterate()
1046 
1047 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1048 void
1050 {
1054 
1057 
1058  Real errorH1SquaredLocal( 0.0 );
1059  Real errorH1Squared( 0.0 );
1060 
1062 
1063  {
1064  using namespace ExpressionAssembly;
1065  integrate (
1066  elements (M_fespaceUETA->mesh() ), // Mesh
1067  M_velocityFESpace.qr(), // QR
1068  dot ( ( eval ( gradUExactFct, value(M_oseenData->dataTime()->time()), X) + (-1) * grad( M_fespaceUETA , uComputed ) ) ,
1069  ( eval ( gradUExactFct, value(M_oseenData->dataTime()->time()), X) + (-1) * grad( M_fespaceUETA , uComputed ) ) )
1070  )
1072 
1073  }
1074 
1075  M_fespaceUETA->mesh()->comm()->Barrier();
1078 }
1079 
1080 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1081 void
1083 {
1085 
1086  if ( false /*S_verbose*/ )
1087  {
1088  for ( UInt iDof = 0; iDof < M_velocityFESpace.fieldDim() * dimVelocity(); ++iDof )
1089  {
1090  velocityVector[ iDof ] = solution[ iDof ];
1091  }
1092 
1093  for ( UInt iDof = 0; iDof < dimPressure(); ++iDof )
1094  {
1096  }
1097  }
1098 
1099 }
1100 
1101 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1102 void
1104 {
1106 
1107  if ( false /*S_verbose*/ )
1108  {
1109  for ( UInt iDof = 0; iDof < M_velocityFESpace.fieldDim() * dimVelocity(); ++iDof )
1110  {
1111  residualVector[ iDof ] = residual[ iDof ];
1112  }
1113 
1114  }
1115 }
1116 
1117 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1118 void
1120 {
1123 }
1124 
1125 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1126 void
1128 {
1130 }
1131 
1132 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1133 void
1135 {
1137 }
1138 
1139 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1140 void
1142 {
1144 }
1145 
1146 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1147 Real
1149 {
1150  return flux ( flag, *M_solution );
1151 }
1152 
1153 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1154 Real
1156  const vector_Type& solution )
1157 {
1161 
1162  return M_postProcessing->flux ( velocity, flag );
1163 }
1164 
1165 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1166 Real
1168 {
1169  return kineticNormalStress ( flag, *M_solution );
1170 }
1171 
1172 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1173 Real
1175  const vector_Type& solution )
1176 {
1180 
1182 }
1183 
1184 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1185 Real
1187 {
1188  return M_postProcessing->measure ( flag );
1189 }
1190 
1191 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1192 Vector
1194 {
1195  return M_postProcessing->normal ( flag );
1196 }
1197 
1198 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1199 Vector
1201 {
1203 }
1204 
1205 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1206 Real
1208 {
1209  return pressure ( flag, *M_solution );
1210 }
1211 
1212 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1213 Real
1215  const vector_Type& solution)
1216 {
1220  this->M_velocityFESpace.dim() *this->M_velocityFESpace.fieldDim() );
1221 
1222  // third argument is 1, to use the pressure finite element space (see PostProcessingBoundary docs)
1223  return M_postProcessing->average ( pressure, flag, 1 ) [0];
1224 }
1225 
1226 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1227 Real
1229 {
1230  return meanNormalStress ( flag, bcHandler, *M_solution );
1231 }
1232 
1233 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1234 Real
1236 {
1237  if ( bcHandler.findBCWithFlag ( flag ).type() == Flux )
1238  {
1239  return -lagrangeMultiplier ( flag, bcHandler, solution );
1240  }
1241  else
1242  {
1243 #ifdef HAVE_LIFEV_DEBUG
1244  M_Displayer.leaderPrint ( " !!! WARNING - OseenSolver::meanNormalStress( flag, bcHandler, solution) is returning an approximation \n" );
1245 #endif
1246  return -pressure ( flag, solution ); // TODO: This is an approximation of the mean normal stress as the pressure.
1247  // A proper method should be coded in the PostprocessingBoundary class
1248  // to compute the exact mean normal stress.
1249  }
1250 }
1251 
1252 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1253 Real
1255 {
1257 }
1258 
1259 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1260 Real
1262 {
1264 }
1265 
1266 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1267 Real
1269 {
1271 }
1272 
1273 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1274 Real
1277  const vector_Type& solution )
1278 {
1279  // Create a list of Flux bcName_Type ??
1282 
1283  // Create a Repeated vector for looking to the lambda
1285 
1286  // Find the index associated to the correct Lagrange multiplier
1287  for ( UInt lmIndex = 0; lmIndex < static_cast <UInt> ( fluxBCVector.size() ); ++lmIndex )
1288  if ( fluxbcName_Type.compare ( fluxBCVector[ lmIndex ] ) == 0 )
1291 
1292  // If lmIndex has not been found a warning message is printed
1293  M_Displayer.leaderPrint ( "!!! Warning - Lagrange multiplier for Flux BC not found!\n" );
1294  return 0;
1295 }
1296 
1297 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1298 Real
1300 {
1301  Real energy = 0.0;
1302 
1304  tmp *= 0;
1305  tmp = (*M_matrixMass) * (*M_solution);
1306  energy = M_solution->dot(tmp);
1307  energy *= 0.5;
1308 
1309  return energy;
1310 }
1311 
1312 
1313 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1314 VectorSmall<2>
1317 {
1319  onesOnBodyDrag *= 0;
1320 
1322  onesOnBodyLift *= 0;
1323 
1326 
1327  Real drag (0.0);
1328  Real lift (0.0);
1329 
1332 
1333  M_Displayer.leaderPrint ( " F- Value of the drag: ", drag );
1334  M_Displayer.leaderPrint ( " F- Value of the lift: ", lift );
1335 
1336  VectorSmall<2> Forces;
1337  Forces[0] = drag;
1338  Forces[1] = lift;
1339 
1340  return Forces;
1341 }
1342 
1343 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1344 VectorSmall<2>
1346  const vector_Type& lift_vector )
1347 {
1348  Real drag (0.0);
1349  Real lift (0.0);
1350 
1353 
1354  M_Displayer.leaderPrint ( " F- Value of the drag: ", drag );
1355  M_Displayer.leaderPrint ( " F- Value of the lift: ", lift );
1356 
1357  VectorSmall<2> Forces;
1358  Forces[0] = drag;
1359  Forces[1] = lift;
1360 
1361  return Forces;
1362 }
1363 
1364 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1365 VectorSmall<2>
1369 {
1370  // 1) flag che dice in quale componente calcolare la resistenza (0 in x, 1 in y, 2 in z)
1371  // 2) creare vettore pieno di zeri lungo quanto il vettore soluzione -> vettore soluzione u organizzato come ( ux | uy | uz | p)
1372  // 3) mettere degli 1 nei nodi corrispondenti al bordo nel blocco del vettore, ovvero:
1373  // se la resistenza é in direzione x: vettore da creare ( 1suBody | 0 | 0 | 0 )
1374  // 4) prodotto scalare del vettore del residuo con questo vettore definito al punto 3)
1375 
1376 
1378  onesOnBodyDrag *= 0;
1379 
1381  onesOnBodyLift *= 0;
1382 
1385 
1386  Real drag (0.0);
1387  Real lift (0.0);
1388 
1391 
1392  M_Displayer.leaderPrint ( " F- Value of the drag: ", drag );
1393  M_Displayer.leaderPrint ( " F- Value of the lift: ", lift );
1394 
1395  VectorSmall<2> Forces;
1396  Forces[0] = drag;
1397  Forces[1] = lift;
1398 
1399  return Forces;
1400 }
1401 
1402 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1403 VectorSmall<2>
1407  const Real& velocityInfty,
1408  const Real& Area)
1409 {
1410  // 1) flag che dice in quale componente calcolare la resistenza (0 in x, 1 in y, 2 in z)
1411  // 2) creare vettore pieno di zeri lungo quanto il vettore soluzione -> vettore soluzione u organizzato come ( ux | uy | uz | p)
1412  // 3) mettere degli 1 nei nodi corrispondenti al bordo nel blocco del vettore, ovvero:
1413  // se la resistenza é in direzione x: vettore da creare ( 1suBody | 0 | 0 | 0 )
1414  // 4) prodotto scalare del vettore del residuo con questo vettore definito al punto 3)
1415 
1416 
1418  onesOnBodyDrag *= 0;
1419 
1421  onesOnBodyLift *= 0;
1422 
1425 
1426  Real drag (0.0);
1427  Real lift (0.0);
1428 
1431 
1432  M_Displayer.leaderPrint ( " F- Value of the drag: ", drag );
1433  M_Displayer.leaderPrint ( " F- Value of the lift: ", lift );
1434 
1435  M_Displayer.leaderPrint ( "\n\n" );
1436 
1439 
1440  M_Displayer.leaderPrint ( " F- Value of the drag coefficient: ", drag );
1441  M_Displayer.leaderPrint ( " F- Value of the lift coefficient: ", lift );
1442 
1444  Coefficients[0] = drag;
1445  Coefficients[1] = lift;
1446 
1447  return Coefficients;
1448 }
1449 
1450 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1451 Real
1453 {
1454 
1456  chrono.start();
1457 
1460 
1461 
1462  if ( M_pressureMatrixMass.get() == 0 )
1463  {
1465  }
1466 
1468  {
1469  chrono.start();
1470  // just to provide the id number in the assem_mat_mixed
1472 
1474  // mass
1475  chrono.start();
1477  chrono.stop();
1478 
1479  chrono.start();
1490  chrono.stop();
1491  }
1492 
1494 
1496  ones = 1.0;
1497 
1498  Real mean;
1499  mean = ones * ( M_pressureMatrixMass * x );
1500  x += ( -mean );
1501 
1502  ASSERT ( std::fabs ( ones * ( M_pressureMatrixMass * x ) ) < 1e-9 , "after removeMean the mean pressure should be zero!");
1503 
1504  return mean;
1505 
1506 } // removeMean()
1507 
1508 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1509 void
1513 {
1514  // M_rightHandSideFull = M_rightHandSideNoBC;
1515 
1516  // BC manage for the velocity
1518  {
1521  M_velocityFESpace.dof() );
1522  }
1523 
1524  // ignoring non-local entries, Otherwise they are summed up lately
1525  //vector_Type rightHandSideFull( rightHandSide, Repeated, Zero );
1526  // ignoring non-local entries, Otherwise they are summed up lately
1528 
1532  bcHandler,
1534  1.,
1535  M_oseenData->dataTime()->time() );
1536 
1538 
1540  {
1542  M_diagonalize,
1543  rightHandSide,
1544  0. );
1545  }
1546 
1547 } // applyBoundaryCondition
1548 
1549 // ===================================================
1550 // Set Methods
1551 // ===================================================
1552 
1553 
1554 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1555 void
1557 {
1563  M_localMap ) );
1564 }
1565 
1566 template<typename MeshType, typename SolverType, typename MapType , UInt SpaceDim, UInt FieldDim>
1567 void
1569 {
1572 }
1573 
1574 } //end namespace LifeV
void updateInverseJacobian(const UInt &iQuadPt)
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
double Real
Generic real data.
Definition: LifeV.hpp:175
buildVector(const buildVector &)
return_Type operator()(Real a, Real b, Real c)
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191