LifeV
darcy/testsuite/basic_test/2d/user_fun.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  @author A. Fumagalli <alessio.fumagalli@mail.polimi.it>
30  @date 2010-07-29
31 */
32 #include <iomanip>
33 #include "user_fun.hpp"
34 
35 namespace dataProblem
36 {
37 
38 // ===================================================
39 //! Problem data
40 // ===================================================
41 
42 // Inverse of permeability matrix
43 /* In this case the permeability matrix is
44 K = [1 0
45  0 1+p^2 ]
46 */
47 Matrix inversePermeability::eval ( const UInt& iElem, const Vector3D& P, const Real& time ) const
48 {
49  Matrix invK ( static_cast<UInt> (2), static_cast<UInt> (2) );
50 
51  const Real unkown_n = scalarField (0).eval ( iElem, P, time );
52 
53  // First row
54  const Real Entry00 = 1.;
55  const Real Entry01 = 0.;
56 
57  // Second row
58  const Real Entry11 = 1. / ( unkown_n * unkown_n + 1. );
59 
60  // Fill in of the inversePermeabilityMatrix
61  invK ( static_cast<UInt> (0), static_cast<UInt> (0) ) = Entry00;
62  invK ( static_cast<UInt> (0), static_cast<UInt> (1) ) = Entry01;
63  invK ( static_cast<UInt> (1), static_cast<UInt> (0) ) = Entry01;
64  invK ( static_cast<UInt> (1), static_cast<UInt> (1) ) = Entry11;
65 
66  return invK;
67 }
68 
69 // Reaction term
70 Real reactionTerm::eval ( const UInt& /*iElem*/, const Vector3D& P, const Real& /*time*/ ) const
71 {
72  return 1;
73 }
74 
75 // Scalar source term
76 Real scalarSource::eval ( const UInt& /*iElem*/, const Vector3D& P, const Real& time ) const
77 {
78  const Real x (P[0]), y (P[1]), t (time);
79  return t * x * x - 2. * t * t - t -
80  ( 6. * y + 2. * t * t * y ) * ( 1. + t * t * t * t * x * x * x * x +
81  y * y * y * y * y * y +
82  2. * t * t * x * x * y * y * y ) -
83  ( 3. * y * y + t * t * y * y ) * ( 6. * y * y * y * y * y +
84  6. * t * t * x * x * y * y ) +
85  t * t * x * x + y * y * y;
86 }
87 
88 // Vector source term
89 Vector vectorSource::eval ( const UInt& /*iElem*/, const Vector3D& P, const Real& time ) const
90 {
91  const Real x (P[0]), y (P[1]), t (time);
92  Vector source ( static_cast<UInt> (2) );
93 
94  const Real Entry0 = t * ( - x + y );
95  const Real Entry1 = t * t * ( - y * y );
96 
97  source ( static_cast<UInt> (0) ) = Entry0;
98  source ( static_cast<UInt> (1) ) = Entry1;
99 
100  return source;
101 }
102 
103 // Initial time primal variable for transient and non-linear transient solvers
104 Real initialCondition::eval ( const UInt& /*iElem*/, const Vector3D& P, const Real& /*time*/ ) const
105 {
106  const Real y (P[1]);
107  return y * y * y;
108 }
109 
110 // Mass function for time dependent problem
111 Real massFunction::eval ( const UInt& /*iElem*/, const Vector3D& /*P*/, const Real& /*time*/ ) const
112 {
113  return 0.5;
114 }
115 
116 // ===================================================
117 //! Boundary data
118 // ===================================================
120 {
121 
122  BCFunctionBase dirichletBDfun;
123  dirichletBDfun.setFunction ( dirichlet );
124 
125  bcDarcy->addBC ( "Top", BCFlags::TOP, Essential, Scalar, dirichletBDfun );
126  bcDarcy->addBC ( "Bottom", BCFlags::BOTTOM, Essential, Scalar, dirichletBDfun );
127  bcDarcy->addBC ( "Left", BCFlags::LEFT, Essential, Scalar, dirichletBDfun );
128  bcDarcy->addBC ( "Right", BCFlags::RIGHT, Essential, Scalar, dirichletBDfun );
129 
130 }
131 
132 // Boundary condition of Dirichlet
133 Real dirichlet ( const Real& t,
134  const Real& x,
135  const Real& y,
136  const Real& z,
137  const ID& icomp )
138 {
139  return analyticalSolution ( t, x, y, z, icomp );
140 }
141 
142 // ===================================================
143 //! Analytical solution
144 // ===================================================
145 
146 // Analytical solution
147 Real analyticalSolution ( const Real& t,
148  const Real& x,
149  const Real& y,
150  const Real& z,
151  const ID& /*ic*/ )
152 {
153  return t * t * x * x + y * y * y;
154 }
155 
156 // Gradient of the analytical solution
158  const Real& x,
159  const Real& y,
160  const Real& z,
161  const ID& icomp )
162 {
163  switch ( icomp )
164  {
165  case 0:
166  return -1. * ( 2. * t * t * x + t * ( x - y ) );
167  case 1:
168  return -1. * ( ( 3. * y * y + t * t * y * y ) *
169  ( 1. + t * t * t * t * x * x * x * x +
170  y * y * y * y * y * y +
171  2. * t * t * x * x * y * y * y ) );
172  default:
173  return 0.;
174  }
175 }
176 
177 } // Namespace DataProblem
Real dirichlet(const Real &t, const Real &x, const Real &y, const Real &z, const ID &ic)
Definition: hyperbolic.cpp:172
darcySolverLinear_Type::bcHandlerPtr_Type bcHandlerPtr_Type
Real const & operator[](UInt const &i) const
Operator [].
virtual Matrix eval(const UInt &iElem, const Vector3D &P, const Real &time=0.) const
Abstract virtual eval function.
virtual Real eval(const UInt &iElem, const Vector3D &P, const Real &time=0.) const
Abstract virtual eval function.
BCFunctionBase - class that holds the function used for prescribing boundary conditions.
Definition: BCFunction.hpp:77
virtual Real eval(const UInt &iElem, const Vector3D &P, const Real &time=0.) const
Abstract virtual eval function.
uint32_type ID
IDs.
Definition: LifeV.hpp:194
Real analyticalFlux(const Real &, const Real &, const Real &, const Real &, const ID &)
virtual Vector eval(const UInt &iElem, const Vector3D &P, const Real &time=0.) const
Abstract virtual eval function.
Real analyticalSolution(const Real &t, const Real &x, const Real &y, const Real &, const ID &)
Analytical solution.
Definition: hyperbolic.cpp:65
double Real
Generic real data.
Definition: LifeV.hpp:175
virtual Real eval(const UInt &iElem, const Vector3D &P, const Real &time=0.) const
Abstract virtual eval function.
VectorSmall< 3 > Vector3D
void setBoundaryConditions(bcHandlerPtr_Type &bcDarcy)
Boundary data.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
virtual Real eval(const UInt &iElem, const Vector3D &P, const Real &time=0.) const
Abstract virtual eval function.