LifeV
DarcySolverNonLinear.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 the LifeV library
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
21  License along with this library; if not, see <http://www.gnu.org/licenses/>
22 
23  This file is part of the LifeV library
24 
25  Author(s): A. Fumagalli <alessio.fumagalli@mail.polimi.it>
26  Date: 2010-05-09
27 
28  Copyright (C) 2001-2006 EPFL, Politecnico di Milano, INRIA
29  Copyright (C) 2006-2010 Politecnico di Milano
30 
31 *******************************************************************************
32 
33 */
34 //@HEADER
35 
36 /*!
37  @file
38  @brief This file contains a non-linear permeability term Darcy equation solver class
39 
40  @date 05/2010
41  @author A. Fumagalli <alessio.fumagalli@mail.polimi.it>
42 
43  @contributor M. Kern <michel.kern@inria.fr>
44  @maintainer M. Kern <michel.kern@inria.fr>
45 */
46 
47 #ifndef _DARCYSOLVERNONLINEAR_H_
48 #define _DARCYSOLVERNONLINEAR_H_ 1
49 
50 #include <lifev/darcy/solver/DarcySolverLinear.hpp>
51 
52 // LifeV namespace.
53 namespace LifeV
54 {
55 //! @class DarcySolverNonLinear This class implements a non-linear Darcy solver
56 /*!
57  @author A. Fumagalli <alessio.fumagalli@mail.polimi.it>
58 
59  This class implements a non-linear Darcy solver with fixed point scheme to handle the non-linearity.
60  <br>
61  <br>
62  The classical non-linear Darcy formulation is a couple of differential equations of first order with
63  the unknowns \f$ p \in C^1 (\Omega ) \f$, being the pressure or the primal unknown,
64  and \f$ \sigma \in (C^1( \Omega ) )^n \f$, being the Darcy velocity or the flux or the dual unknown,
65  such that
66  \f[
67  \left\{
68  \begin{array}{l l l}
69  \Lambda^{-1}(p) \sigma + \nabla p = f_v & \mathrm{in} & \Omega\,, \vspace{0.2cm} \\
70  \nabla \cdot \sigma + \pi p - f = 0 & \mathrm{in} & \Omega\,, \vspace{0.2cm} \\
71  p = g_D & \mathrm{on} & \Gamma_D\,,\vspace{0.2cm} \\
72  \sigma \cdot n + h p = g_R & \mathrm{on} & \Gamma_R\,.
73  \end{array}
74  \right.
75  \f]
76  The data in the system are:
77  <ul>
78  <li> \f$ \Lambda \f$ the permeability tensor that depends on \f$ p \f$; </li>
79  <li> \f$ f \f$ the scalar source term; </li>
80  <li> \f$ f_v \f$ the vector source term; </li>
81  <li> \f$ \pi \f$ the reaction coefficient; </li>
82  <li> \f$ \Gamma_D \f$ the subset of the boundary of \f$ \Omega \f$ with Dirichlet boundary conditions; </li>
83  <li> \f$ g_D \f$ Dirichlet boundary condition data; </li>
84  <li> \f$ \Gamma_R \f$ that is the part of the boundary of \f$ \Omega \f$ with Robin, or Neumann, boundary conditions; </li>
85  <li> \f$ h \f$ and \f$ g_R \f$ Robin boundary condition data; </li>
86  </ul>
87  We suppose that \f$ \partial \Omega = \Gamma_D \cup \Gamma_R \f$ and \f$ \Gamma_D \cap \Gamma_R = \emptyset \f$.
88  <br>
89  Using the hybridization procedure, and introducing a new variable, we may split the problem from
90  the entire domain to problems in each elements of the triangulation \f$ \mathcal{T}_h \f$, then we may write
91  the weak formulation for the dual problem.
92  The new variable is the hybrid unknown \f$ \lambda \f$, e.g. "the trace" of pressure of the primal unknown,
93  it is the Lagrange multipliers forcing the continuity of the flux across each faces or edges in the triangulation.
94  We introduce the following functional spaces, the first is the space of the primal variable, the third for
95  the dual variable, the fourth for the hybrid variable.
96  \f[
97  \begin{array}{l}
98  V = L^2 (\Omega ) \,,\vspace{0.2cm} \\
99  H(div, K) = \displaystyle \left\{ \tau \in ( L^2(K))^n : \nabla \cdot \tau \in L^2(K)\right\}\,, \vspace{0.2cm}\\
100  Z = \displaystyle \left\{ \tau \in L^2(\Omega) : \tau\vert_K \in H(div, K) \, \forall K \in \mathcal{T}_h \right\}\,, \vspace{0.2cm}\\
101  \Lambda = \displaystyle \left\{ \lambda \in \prod_{K \in \mathcal{T}_h} H^{1/2} (\partial K): \lambda_K = \lambda_{K'} \,\, \mathrm{on} \,\, e_{K-K'} \, \forall K \in \mathcal{T}_h,\, \lambda = g_D \,\, \mathrm{on} \,\, \Gamma_D \right\}\,.
102  \end{array}
103  \f]
104  Introducing the following operator, bilinear forms and the functionals
105  \f[
106  \begin{array}{l l}
107  a(\sigma, \tau, p) = \sum_{K \in \mathcal{T}_h}\int_K \Lambda^{-1}(p) \sigma \cdot \tau \,, &
108  b(p, \tau) = -\sum_{K \in \mathcal{T}_h} \int_K p \nabla \cdot \tau\,, \vspace{0.2cm}\\
109  c(\lambda, \tau) = \sum_{K \in \mathcal{T}_h} \int_{\partial K} \lambda \tau \cdot n\,,&
110  d(p, q) = \displaystyle \sum_{K \in \mathcal{T}_h} \int_{\partial K} \pi p q \,,\vspace{0.2cm}\\
111  h(\lambda, \mu) = \sum_{K \in \mathcal{T}_h} \int_{\partial K \cap \Gamma_R} h \mu \lambda \,,&
112  F(q) = \sum_{K \in \mathcal{T}_h} \int_K f q\,,\vspace{0.2cm}\\
113  F_v(\tau) = \displaystyle \sum_{K \in \mathcal{T}_h} \int_K f_v \tau \,, \vspace{0.2cm}\,,&
114  G(\mu) =\sum_{K \in \mathcal{T}_h} \int_{\partial K \cap \Gamma_R} g \mu\,,
115  \end{array}
116  \f]
117  we obtain the Darcy problem in the weak form: find \f$ (\sigma, \, p, \, \lambda) \in Z \times V \times \Lambda \f$ such that
118  \f[
119  \left\{
120  \begin{array}{l l}
121  a(\sigma, \tau, p) + b(p, \tau) + c(\lambda, \tau) = F_v(\tau)\,, & \forall \tau \in Z \,,\vspace{0.2cm}\\
122  b(q, \sigma) + d (p, q)= - F(q)\,, & \forall q \in V \,,\vspace{0.2cm}\\
123  c(\mu, \sigma) + h(\lambda, \mu) = G(\mu) \,, & \forall \mu \in \Lambda\,.
124  \end{array}
125  \right.
126  \f]
127  At discrete level we introduce the polynomial space, of degree \f$ r \f$, that approximate the finite dimensional
128  spaces introduced above \f$ V_h \subset V \f$, \f$ Z_h \subset Z \f$ and \f$\Lambda_h \subset \Lambda \f$
129  \f[
130  \begin{array}{l}
131  V_h = \left\{ v_h \in V: v_h|_K \in P_r (K)\, \forall K \in \mathcal{T}_h \right\}\,, \vspace{0.2cm}\\
132  Z_h = \left\{ \tau_h \in Z: \tau_h|_K \in RT_r(K) \, \forall K \in \mathcal{T}_h \right\} \,, \vspace{0.2cm} \\
133  \Lambda_h = \left\{ \lambda_h \in \Lambda: \lambda_h|_{\partial K} \in R_r( \partial K ) \, \forall K \in \mathcal{T}_h\right\}\,,
134  \end{array}
135  \f]
136  where \f$ P_r(K) \f$ is the space of polynomial of degree \f$ r \f$ in the element \f$ K \f$, \f$ RT_r(K) \f$ is the space of
137  polynomial of Raviart-Thomas of degrees \f$ r \f$ in the element \f$ K \f$ and \f$ R_r(\partial K) \f$ is the space of polynomial of
138  degree \f$ r \f$ definite on each of the boundary of the element \f$ K \f$ and discontinuous from one edge to the other.
139  <BR>
140  The finite dimensional problem is: find \f$ (\sigma_h,\,, p_h, \, \lambda_h) \in Z_h \times V_h \times \Lambda_h \f$ such that
141  \f[
142  \left\{
143  \begin{array}{l l}
144  a(\sigma_h, \tau_h, p_h) + b(p_h, \tau_h) + c(\lambda_h, \tau_h) = F_v(\tau)\,, & \forall \tau_h \in Z_h \,,\vspace{0.2cm}\\
145  b(q_h, \sigma_h) - d(p_h, q_h) = - F(q_h)\,, & \forall q_h \in V_h \,,\vspace{0.2cm}\\
146  c(\mu_h, \sigma_h) + h(\lambda_h, \mu_h) = G(\mu_h) \,, & \forall \mu_h \in \Lambda_h\,.
147  \end{array}
148  \right.
149  \f]
150  To solve the non-linearity we use a fixed point scheme based on the relative difference between two consecutive iterations
151  of the primal variable. We start from the, user defined, function \f$ p^0 \f$ and solve the linearized problem for \f$ n \geq 1 \f$:
152  find \f$ (\sigma_h^n,\, p_h^n, \, \lambda_h^n) \in Z_h \times V_h \times \Lambda_h \f$ such that
153  \f[
154  \left\{
155  \begin{array}{l l}
156  a(\sigma_h^n, \tau_h; p_h^{n-1}) + b(p_h^n, \tau_h) + c(\lambda_h^n, \tau_h) = F_v(\tau) \,, & \forall \tau_h \in Z_h \,,\vspace{0.2cm}\\
157  b(q_h, \sigma_h^n) - d(p_h, q_h)= - F(q_h)\,, & \forall q_h \in V_h \,,\vspace{0.2cm}\\
158  c(\mu_h, \sigma_h^n) + h(\lambda_h^n, \mu_h) = G(\mu_h) \,, & \forall \mu_h \in \Lambda_h\,.
159  \end{array}
160  \right.
161  \f]
162  At each iteration, to solve the problem, we use the static condensation procedure, i.e. the unknowns in the discrete
163  weak system are not independent and \f$ p_K^n \f$, \f$\sigma_K^n \f$ may be written in function of
164  \f$ \lambda_K^n \f$ alone. We introduce the following local matrices
165  \f[
166  \begin{array}{l l l}
167  \left[ A \left( p_K^{n-1}\right) \right]_{ij} = \displaystyle \int_K \Lambda^{-1}\left( p^{n-1} \right) \psi_j \cdot \psi_i \,, &
168  \left[ B \right]_{ij} = - \displaystyle \int_K \phi_j \nabla \cdot \psi_i \,, &
169  \left[ C \right]_{ij} = \displaystyle \int_{\partial K} \xi_i \psi_j \cdot n \,, \vspace{0.2cm} \\
170  \left[ D \right]_{ij} = \displaystyle \int_K \pi \phi_j \phi_i\,, &
171  \left[ H \right]_{ij} = \displaystyle \int_{\partial K \cap \Gamma_R} h \xi_i \xi_j\,, &
172  \left[ F \right]_{j} = \displaystyle \int_K f \phi_j\,,\vspace{0.2cm} \\
173  \left[ F_v \right]_{j} = \displaystyle \int_K f_v \psi_j\,,&
174  \left[ G \right]_{j} = \displaystyle \int_{\partial K \cap \Gamma_R } g \xi_j\,,
175  \end{array}
176  \f]
177  where we avoid to write the dependence on the triangle \f$ K \f$ in all the matrices and vectors.
178  <br>
179  The local matrix formulation of the finite dimensional problem, at each iteration, is
180  \f[
181  \left\{
182  \begin{array}{l}
183  A \left( p_K^{n-1} \right) \sigma_K^n + B p_K^n + C \lambda_K^n = F_v\,, \vspace{0.2cm} \\
184  B^T \sigma_K^n - D p_K^n= -F \,, \vspace{0.2cm}\\
185  C^T \sigma_K^n + H \lambda_K^n = G\,.
186  \end{array}
187  \right.
188  \f]
189  Or alternatively
190  \f[
191  \begin{array}{l l l}
192  \left[
193  \begin{array}{c c c}
194  A \left( p_K^{n-1} \right) & B & C \vspace{0.2cm} \\
195  B^T & -D & 0 \vspace{0.2cm} \\
196  C^T & 0 & H
197  \end{array}
198  \right] \, \cdot &
199  \left[
200  \begin{array}{c}
201  \sigma_K^n \vspace{0.2cm}\\
202  p_K^n \vspace{0.2cm}\\
203  \lambda_K^n
204  \end{array}
205  \right] \, &
206  =
207  \left[
208  \begin{array}{c}
209  F_v \vspace{0.2cm}\\
210  -F \vspace{0.2cm}\\
211  G
212  \end{array}
213  \right]\,.
214  \end{array}
215  \f]
216  Introducing the local hybrid matrix and local hybrid right hand side
217  \f[
218  \begin{array}{l}
219  L_K = -C^T A^{-1}\left( p_k^{n-1}\right) C + C^T A^{-1} \left( p_K^{n-1} \right) B
220  \left[ B^T A^{-1}\left( p_K^{n-1}\right) B + D \right]^{-1} B^T A^{-1}\left( p_K^{n-1} \right) C + H \,, \vspace{0.2cm} \\
221  r_K = G + C^T A^{-1}\left( p_K^{n-1} \right) B \left[ B^T A^{-1}\left( p_K^{n-1} \right) B + D \right]^{-1} F
222  + C^T A^{-1}\left( p_K^{n-1} \right) B \left[ B^T A^{-1}\left( p_K^{n-1} \right) B +
223  D \right]^{-1} B^T A^{-1}\left( p_K^{n-1} \right) F_v - C^T A^{-1}\left( p_K^{n-1} \right) F_v\,,
224  \end{array}
225  \f]
226  Imposing that at each edge or face the hybrid unknown is single value we obtain a linear system for the hybrid unknown
227  \f[
228  L^n \lambda^n = r \,.
229  \f]
230  We recover the primal and dual variable as a post-process from the hybrid variable at element level, so we have
231  \f[
232  \begin{array}{l}
233  p_K^n = \left[ B^T A^{-1}\left( p_K^{n-1} \right) B + D\right]^{-1} \left[ F + B^T A^{-1}\left( p_K^{n-1}\right) F_v
234  - B^T A^{-1}\left( p_K^{n-1}\right) C \lambda_K^n \right]\,, \vspace{0.2cm} \\
235  \sigma_K^n = -A^{-1}\left(p_K^{n-1} \right) \left( B p_K^n - F_v + C \lambda_K^n \right) \,.
236  \end{array}
237  \f]
238  @note In the code we do not use the matrix \f$ H \f$ and the vector \f$ G \f$, because all the boundary
239  conditions are imposed via BCHandler class.
240  @note Example of usage can be found in darcy_nonlinear and darcy_linear.
241  Coupled with an hyperbolic solver in impes.
242  @todo Insert any scientific publications that use this solver.
243  @todo Attention! We have the hypothesis that we use P0 elements for the primal unknown. Change this in a future!
244  @todo Add criteria to ensure convergence of the fixed point method.
245 */
246 template < typename MeshType >
248  virtual public DarcySolverLinear < MeshType >
249 {
250 
251 public:
252 
253  //! @name Public Types
254  //@{
255 
256  //! Typedef for mesh template.
257  typedef MeshType mesh_Type;
258 
259  //! Self typedef.
261 
262  //! Darcy solver class.
264 
265  //! Typedef for the data type.
267 
268  //! Shared pointer for the data type.
270 
271  //! Shared pointer to a scalar value function.
273 
274  //! Shared pointer to a matrix value function.
276 
277  //! Scalar field.
279 
280  //! Shared pointer to a scalar field.
282 
283  //@}
284 
285  //! @name Constructors & destructor
286  //@{
287 
288  //! Constructor for the class.
290 
291  //! Virtual destructor.
292  virtual ~DarcySolverNonLinear () {};
293 
294  //@}
295 
296  //! @name Methods
297  //@{
298 
299  //! Set up the linear solver and the preconditioner for the linear system.
300  virtual void setup ();
301 
302  //! Solve the problem performing the fixed point scheme.
303  virtual void solve ()
304  {
305  fixedPoint ();
306  }
307 
308  //@}
309 
310  //! @name Set methos
311  //@{
312 
313  //! Initial guess for fixed point iteration
314  /*!
315  Set the function for the first iteration for the fixed point method.
316  @param primalZeroIteration The function for the first iteration.
317  */
318  void setPrimalZeroIteration ( const scalarFctPtr_Type& primalZeroIteration );
319 
320  //! Set the inverse of diffusion tensor,
321  /*!
322  The non linearity of the solver is in the diffusion or permeability tensor.
323  To handle this type of non linearity we use an iterative scheme and we
324  write the tensor depending on the solution at previuos step.
325  The non linear tensor now has as an additional scalar field, the last one,
326  the solution of the problem at previuos step.
327  This scalar field is automatically updated each iteration of the non
328  linear solver.
329  <br>
330  The user should take into account that the value of the primal variable is
331  the last field set, by the user, plus one. So the inverse of permeability
332  can access to the primal variable, for example, with
333  \code
334  // Inverse of permeability matrix
335  typedef RegionMesh < LinearTriangle > regionMesh_Type;
336  class inversePermeability : public FEFunction < regionMesh_Type, MapEpetra, Matrix >
337 
338  {
339  public:
340  virtual Matrix eval ( const UInt& iElem, const Vector3D& P, const Real& time = 0. ) const;
341  };
342  \endcode
343  Its implementation is
344  \code
345  Matrix inversePermeability::eval ( const UInt& iElem, const Vector3D& P, const Real& time ) const
346  {
347  Matrix invK ( 2, 2 );
348 
349  Real unkown_n = scalarField(0).eval( iElem, P, time );
350 
351  // Fill in of the inversePermeabilityMatrix
352  invK ( 0, 0 ) = 1;
353  invK ( 0, 1 ) = 0;
354  invK ( 1, 0 ) = 0;
355  invK ( 1, 1 ) = 1. / ( unkown_n * unkown_n + 1. );
356 
357  return invK;
358  }
359  \endcode
360  obtaining a tensor with the non linearity in the position \f$ (1,1) \f$
361  the function \f$ \left[K^{-1}\right]_{1,1} = u^2 + 1 \f$.
362  <br>
363  In the previous
364  example we have supposed that the permeability has not others scalar fields.
365  If the user has set \f$ m \f$ scalar fields prior to calling setInversePermeability, then the code
366  should be
367  \code
368  const Real unkown_n = scalarField(m).eval( iElem, P, time );
369  \endcode
370  to access the primal at previous step.
371  @note For an example of the usage see darcy_nonlinear and
372  twophase_impes
373  @param invPerm Inverse of the permeability tensor for the problem.
374  */
375  virtual void setInversePermeability ( const matrixFctPtr_Type& invPerm )
376  {
377 
378  // Call the standard set inverse permeability
379  darcySolverLinear_Type::setInversePermeability ( invPerm );
380 
381  // Create the primal variable for the first iteration.
382  M_primalFieldPreviousIteration.reset ( new scalarField_Type ( this->M_primalField->getFESpacePtr() ) );
383 
384  // Set the dependence of the previous solution in the permeability
385  this->M_inversePermeabilityFct->addScalarField ( M_primalFieldPreviousIteration );
386  }
387 
388  /*!
389  Set fixed point tolerance
390  @param tol requested tolerance
391  */
392  void setFixedPointTolerance ( const Real& tol )
393  {
394  M_fixedPointTolerance = tol;
395  }
396 
397  /*!
398  Set maximum number of fixed point iterations permitted
399  @param maxit requested maximum
400  */
401  void setFixedPointMaxIteration ( const UInt& maxit )
402  {
403  M_fixedPointMaxIteration = maxit;
404  }
405 
406  //@}
407 
408  //! @name Get methods
409  //@{
410 
411  /*!
412  Returns the number of iteration of the fixed point scheme.
413  @return Final number of iterations of the fixed point method as a constant UInt.
414  */
416  {
418  }
419 
420  //! Returns the residual between two iterations of the fixed point scheme.
421  /*!
422  @return Final residual of the fixed point method as a constant Real.
423  */
425  {
426  return M_fixedPointResidual;
427  }
428 
429  //! Returns fixed point tolerance
430  /*!
431  @return M_fixedPointTolerance
432  */
433  const Real& fixedPointTolerance () const
434  {
435  return M_fixedPointTolerance;
436  }
437 
438  //! Returns fixed point tolerance
439  /*!
440  @return M_fixedPointTolerance
441  */
443  {
444  return M_fixedPointTolerance;
445  }
446 
447  //! Returns maximum number of fixed point iterations allowed
448  /*!
449  @return max possible number of fixed point iterations
450  */
451  const UInt& fixedPointMaxIteration () const
452  {
454  }
455 
456  //! Returns maximum number of fixed point iterations allowed
457  /*!
458  @return max possible number of fixed point iterations
459  */
461  {
463  }
464 
465  //! Returns the pointer of the primal solution field at previous step.
466  /*!
467  @return Constant scalarFieldPtr_Type reference of the primal solution field at previous step.
468  */
470  {
472  }
473 
474  //! Returns the pointer of the primal solution field at previous step.
475  /*!
476  @return Constant scalarFieldPtr_Type reference of the primal solution field at previous step.
477  */
479  {
481  }
482 
483  //@}
484 
485 protected:
486 
487  // Methods
488  //! @name Protected Methods
489  //@{
490 
491  //! Update all problem variables
492  /*!
493  Update all the variables of the problem before the construction of
494  the global hybrid matrix, e.g. reset the global hybrid matrix.
495  It is principally used for a time dependent derived class.
496  */
497  virtual void resetVariables ();
498 
499  //! Perform the fixed point loop to solve the non-linear problem.
500  void fixedPoint ();
501 
502  //! Set up the data for the non-linear solver.
503  void setupNonLinear ();
504 
505  //@}
506 
507  //! @name Protected Members
508  //@{
509 
510  //! Primal solution at previous iteration step.
512 
513  //@}
514 
515 private:
516 
517  //! @name Private Constructors
518  //@{
519 
520  //! Inhibited copy constructor.
522 
523  //@}
524 
525  //! @name Private Operators
526  //@{
527 
528  //! Inhibited assign operator.
530 
531  //@}
532 
533  // Non-linear stuff.
534  //! @name Non-linear stuff
535  //@{
536 
537  //! The maximum number of iterations for the fixed point method.
539 
540  //! The current iterations for the fixed point method.
542 
543  //! Tollerance for the stopping criteria for the fixed point method.
545 
546  //! The residual between two iteration of the fixed point scheme.
548 
549  //! Primal solution at zero time step.
551 
552  //@}
553 
554 }; // class DarcySolverNonLinear
555 
556 //
557 // IMPLEMENTATION
558 //
559 
560 // ===================================================
561 // Constructors & Destructor
562 // ===================================================
563 
564 // Complete constructor.
565 template < typename MeshType >
566 DarcySolverNonLinear < MeshType >::
568  // Standard Darcy solver constructor.
570  // Non-linear stuff.
571  M_fixedPointMaxIteration ( static_cast<UInt> (10) ),
572  M_fixedPointNumIteration ( static_cast<UInt> (0) ),
573  M_fixedPointTolerance ( static_cast<Real> (1.e-8) ),
574  M_fixedPointResidual ( M_fixedPointTolerance + static_cast<Real> (1.) )
575 {
576 } // Constructor
577 
578 // ===================================================
579 // Public methods
580 // ===================================================
581 
582 // Set up the linear solver and the preconditioner.
583 template < typename MeshType >
584 void
585 DarcySolverNonLinear < MeshType >::
587 {
588 
589  // Call the DarcySolverLinear setup method for setting up the linear solver.
590  darcySolverLinear_Type::setup();
591 
592  // Call the setup for the non-linear data.
594 
595 } // setup
596 
597 // Set up the non-linear data.
598 template < typename MeshType >
599 void
600 DarcySolverNonLinear < MeshType >::
602 {
603 
604  const typename darcySolverLinear_Type::data_Type::data_Type& dataFile = * ( this->M_data->dataFilePtr() );
605 
606  // Path for the non linear stuff in the data file.
607  const std::string dataPath = this->M_data->section() + "/non-linear";
608 
609  // Set the maximum number of iteration for the fixed point iteration scheme.
610  const UInt maxIter = dataFile ( ( dataPath + "/fixed_point_iteration" ).data(), 10 );
611  setFixedPointMaxIteration ( maxIter );
612 
613  // Set the tollerance for the fixed point iteration scheme.
614  const Real tol = dataFile ( ( dataPath + "/fixed_point_toll" ).data(), 1.e-8 );
616 
617 } // setupNonLinear
618 
619 // Fixed point scheme.
620 template < typename MeshType >
621 void
622 DarcySolverNonLinear < MeshType >::
624 {
625 
626  // Current iteration.
627  M_fixedPointNumIteration = static_cast<UInt> (0);
628 
629  // Error between two iterations, it is the relative error between two step of the primal vector
630  M_fixedPointResidual = fixedPointTolerance() + 1.;
631 
632  /* A loop for the fixed point scheme, with exit condition based on stagnate of the
633  primal variable and the maximum iteration. */
636  {
637  // Increment the iteration number.
639 
640  // Solve the problem.
641  darcySolverLinear_Type::solve ();
642 
643  // Compute the error.
644  M_fixedPointResidual = ( this->M_primalField->getVector() -
645  M_primalFieldPreviousIteration->getVector() ).norm2()
646  / this->M_primalField->getVector().norm2();
647 
648  // The leader process prints the iteration data.
649  this->M_displayer->leaderPrint ( "Fixed point scheme\n" );
650 
651  // Print the actual iterations
652  this->M_displayer->leaderPrint ( "Number of iterations ", M_fixedPointNumIteration );
653 
654  // Print the maximum number of iterations
655  this->M_displayer->leaderPrint ( " of ", M_fixedPointMaxIteration, "\n" );
656 
657  // Print the error reached
658  this->M_displayer->leaderPrint ( "Error ", M_fixedPointResidual );
659 
660  // Print the tollerance
661  this->M_displayer->leaderPrint ( " over ", M_fixedPointTolerance, "\n" );
662 
663  }
664 
665  // Check if the fixed point method reach the tolerance.
667  {
668  std::cerr << "Attention the fixed point scheme did not reach convergence."
669  << std::endl << "Max of iterations " << M_fixedPointMaxIteration
670  << std::endl << "Number of iterations " << M_fixedPointNumIteration
671  << std::endl;
672  exit (1);
673  }
674 
675 } // fixedPoint
676 
677 // Set the first value for the fixed point method.
678 template < typename MeshType >
679 void
680 DarcySolverNonLinear < MeshType >::
681 setPrimalZeroIteration ( const scalarFctPtr_Type& primalZeroIterationFct )
682 {
683  // Set the function for the first iteration.
684  M_primalFieldZeroIterationFct = primalZeroIterationFct;
685 
686  // Interpolate the primal variable for the first iteration.
687  M_primalFieldZeroIterationFct->interpolate ( * (this->M_primalField),
688  this->M_data->dataTimePtr()->initialTime() );
689 
690 } // SetZeroIterationPrimal
691 
692 // ===================================================
693 // Protected Methods
694 // ===================================================
695 
696 // Update all the variables of the problem.
697 template < typename MeshType >
698 void
699 DarcySolverNonLinear < MeshType >::
701 {
702 
703  // Update the primal vector at the previous iteration step.
704  M_primalFieldPreviousIteration->setVector ( this->M_primalField->getVector() );
705 
706  // Call the method of the DarcySolverLinear to update all the variables defined in it.
707  darcySolverLinear_Type::resetVariables();
708 
709 } // resetVariables
710 
711 } // namespace LifeV
712 
713 #endif //_DARCYSOLVERNONLINEAR_H_
MeshType mesh_Type
Typedef for mesh template.
darcySolverLinear_Type::dataPtr_Type dataPtr_Type
Shared pointer for the data type.
const UInt & fixedPointMaxIteration() const
Returns maximum number of fixed point iterations allowed.
void setFixedPointTolerance(const Real &tol)
const Real & fixedPointTolerance() const
Returns fixed point tolerance.
Real fixedPointResidual()
Returns the residual between two iterations of the fixed point scheme.
darcySolverLinear_Type::matrixFctPtr_Type matrixFctPtr_Type
Shared pointer to a matrix value function.
Real & fixedPointTolerance()
Returns fixed point tolerance.
darcySolverLinear_Type::scalarFieldPtr_Type scalarFieldPtr_Type
Shared pointer to a scalar field.
void setFixedPointMaxIteration(const UInt &maxit)
Real M_fixedPointResidual
The residual between two iteration of the fixed point scheme.
DarcySolverNonLinear()
Constructor for the class.
scalarFieldPtr_Type & primalPreviousIterationPtr()
Returns the pointer of the primal solution field at previous step.
virtual void setInversePermeability(const matrixFctPtr_Type &invPerm)
Set the inverse of diffusion tensor,.
void setupNonLinear()
Set up the data for the non-linear solver.
DarcySolverNonLinear(const darcySolverNonLinear_Type &)
Inhibited copy constructor.
DarcySolverLinear< mesh_Type > darcySolverLinear_Type
Darcy solver class.
UInt & fixedPointMaxIteration()
Returns maximum number of fixed point iterations allowed.
scalarFieldPtr_Type M_primalFieldPreviousIteration
Primal solution at previous iteration step.
scalarFctPtr_Type M_primalFieldZeroIterationFct
Primal solution at zero time step.
DarcySolverNonLinear< mesh_Type > darcySolverNonLinear_Type
Self typedef.
void fixedPoint()
Perform the fixed point loop to solve the non-linear problem.
UInt M_fixedPointNumIteration
The current iterations for the fixed point method.
virtual ~DarcySolverNonLinear()
Virtual destructor.
virtual void solve()
Solve the problem performing the fixed point scheme.
double Real
Generic real data.
Definition: LifeV.hpp:175
virtual void setup()
Set up the linear solver and the preconditioner for the linear system.
implements a mixed-hybrid FE Darcy solver.
darcySolverLinear_Type::data_Type data_Type
Typedef for the data type.
darcySolverLinear_Type::scalarField_Type scalarField_Type
Scalar field.
virtual void resetVariables()
Update all problem variables.
Real M_fixedPointTolerance
Tollerance for the stopping criteria for the fixed point method.
const scalarFieldPtr_Type & primalPreviousIterationPtr() const
Returns the pointer of the primal solution field at previous step.
void setPrimalZeroIteration(const scalarFctPtr_Type &primalZeroIteration)
Initial guess for fixed point iteration.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
darcySolverNonLinear_Type & operator=(const darcySolverNonLinear_Type &)
Inhibited assign operator.
UInt M_fixedPointMaxIteration
The maximum number of iterations for the fixed point method.
implements a non-linear Darcy solver
darcySolverLinear_Type::scalarFctPtr_Type scalarFctPtr_Type
Shared pointer to a scalar value function.