LifeV
darcy/testsuite/basic_test/3d/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 = [2 1 0
45  1 1 0
46  0 0 1]
47 */
48 Matrix inversePermeability::eval ( const UInt& /*iElem*/, const Vector3D& /*P*/, const Real& /*time*/ ) const
49 {
50  Matrix invK ( static_cast<UInt> (3), static_cast<UInt> (3) );
51 
52  // First row
53  const Real Entry00 = 1.;
54  const Real Entry01 = -1.;
55  const Real Entry02 = 0.;
56 
57  // Second row
58  const Real Entry11 = 2.;
59  const Real Entry12 = 0.;
60 
61  // Third row
62  const Real Entry22 = 1.;
63 
64  // Fill in of the inversePermeabilityMatrix
65  invK ( static_cast<UInt> (0), static_cast<UInt> (0) ) = Entry00;
66  invK ( static_cast<UInt> (0), static_cast<UInt> (1) ) = Entry01;
67  invK ( static_cast<UInt> (0), static_cast<UInt> (2) ) = Entry02;
68  invK ( static_cast<UInt> (1), static_cast<UInt> (0) ) = Entry01;
69  invK ( static_cast<UInt> (1), static_cast<UInt> (1) ) = Entry11;
70  invK ( static_cast<UInt> (1), static_cast<UInt> (2) ) = Entry12;
71  invK ( static_cast<UInt> (2), static_cast<UInt> (0) ) = Entry02;
72  invK ( static_cast<UInt> (2), static_cast<UInt> (1) ) = Entry12;
73  invK ( static_cast<UInt> (2), static_cast<UInt> (2) ) = Entry22;
74 
75  return invK;
76 }
77 
78 // Reaction term
79 Real reactionTerm::eval ( const UInt& /*iElem*/, const Vector3D& P, const Real& /*time*/ ) const
80 {
81  return (P[0] * P[1] - 0.5 * P[2]);
82 }
83 
84 // Scalar source term
85 Real scalarSource::eval ( const UInt& /*iElem*/, const Vector3D& P, const Real& time ) const
86 {
87  return - 4. * P[1] * P[1] + 4. * P[0] * P[0] - 8. * P[0] * P[1] + 6. +
88  ( P[0] * P[1] - 0.5 * P[2] ) * analyticalSolution ( time, P[0], P[1], P[2], 0 );
89 }
90 
91 // Vector source term
92 Vector vectorSource::eval ( const UInt& /*iElem*/, const Vector3D& P, const Real& /*time*/ ) const
93 {
94  Vector source ( static_cast<UInt> (3) );
95 
96  const Real Entry0 = std::pow ( P[0], 3 );
97  const Real Entry1 = 2. * P[1];
98  const Real Entry2 = 4. * P[2];
99 
100  source ( static_cast<UInt> (0) ) = Entry0;
101  source ( static_cast<UInt> (1) ) = Entry1;
102  source ( static_cast<UInt> (2) ) = Entry2;
103 
104  return source;
105 }
106 
107 // ===================================================
108 //! Boundary data
109 // ===================================================
111 {
112 
113  BCFunctionBase dirichletBDfun, neumannBDfun1, neumannBDfun2;
114  BCFunctionRobin robinBDfun;
115 
116  dirichletBDfun.setFunction ( dirichlet );
117  neumannBDfun1.setFunction ( neumann1 );
118  neumannBDfun2.setFunction ( neumann2 );
119  // dp/dn = first_parameter + second_parameter * p
120  robinBDfun.setFunctions_Robin ( robin, robinMass );
121 
122  bcDarcy->addBC ( "Top", BCFlags::TOP, Natural, Full, neumannBDfun1, 1);
123  bcDarcy->addBC ( "Bottom", BCFlags::BOTTOM, Robin, Scalar, robinBDfun );
124  bcDarcy->addBC ( "Left", BCFlags::LEFT, Essential, Scalar, dirichletBDfun );
125  bcDarcy->addBC ( "Right", BCFlags::RIGHT, Essential, Scalar, dirichletBDfun );
126  bcDarcy->addBC ( "Back", BCFlags::BACK, Essential, Scalar, dirichletBDfun );
127  bcDarcy->addBC ( "Front", BCFlags::FRONT, Natural, Full, neumannBDfun2, 1);
128 
129 }
130 
131 // Boundary condition of Dirichlet
132 Real dirichlet ( const Real& t,
133  const Real& x,
134  const Real& y,
135  const Real& z,
136  const ID& icomp )
137 {
138  return analyticalSolution ( t, x, y, z, icomp );
139 }
140 
141 // Boundary condition of Neumann
142 Real neumann1 ( const Real& t,
143  const Real& x,
144  const Real& y,
145  const Real& z,
146  const ID& /*icomp*/ )
147 {
148  return analyticalFlux ( t, x, y, z, 2 );
149 }
150 
151 Real neumann2 ( const Real& t,
152  const Real& x,
153  const Real& y,
154  const Real& z,
155  const ID& /*icomp*/ )
156 {
157  return -1. * analyticalFlux ( t, x, y, z, 1 );
158 }
159 
160 // Boundary condition of Robin
161 Real robin ( const Real& t,
162  const Real& x,
163  const Real& y,
164  const Real& z,
165  const ID& icomp )
166 {
167  return -1. * analyticalFlux ( t, x, y, z, 2 ) +
168  analyticalSolution ( t, x, y, z, icomp );
169 }
170 
171 Real robinMass ( const Real& /*t*/,
172  const Real& /*x*/,
173  const Real& /*y*/,
174  const Real& /*z*/,
175  const ID& /*icomp*/ )
176 {
177  return 1.;
178 }
179 
180 // ===================================================
181 //! Analytical solution
182 // ===================================================
183 
184 // Analytical solution
185 Real analyticalSolution ( const Real& /*t*/,
186  const Real& x,
187  const Real& y,
188  const Real& z,
189  const ID& /*ic*/ )
190 {
191  return x * x * y * y + 6. * x + 5. * z;
192 }
193 
194 // Gradient of the analytical solution
195 Real analyticalFlux ( const Real& /*t*/,
196  const Real& x,
197  const Real& y,
198  const Real& z,
199  const ID& icomp )
200 {
201  switch ( icomp )
202  {
203  case 0:
204  return -1. * ( 4. * x * y * y + 2. * x * x * y + 12. - 2. * x * x * x - 2. * y );
205 
206  case 1:
207  return -1. * ( 2. * y * x * x + 2. * x * y * y + 6. - 2. * y - x * x * x );
208 
209  case 2:
210  return -1. * ( 5. - 4. * z );
211 
212  default:
213  return 0.;
214  }
215 }
216 
217 } // Namespace DataProblem
Real dirichlet(const Real &t, const Real &x, const Real &y, const Real &z, const ID &ic)
Definition: hyperbolic.cpp:172
Real neumann1(const Real &, const Real &, const Real &, const Real &, const ID &)
Real robinMass(const Real &, const Real &, const Real &, const Real &, const ID &)
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.
BCFunctionRobin - class that holds the function used for prescribing Robin boundary conditions...
Definition: BCFunction.hpp:231
BCFunctionBase - class that holds the function used for prescribing boundary conditions.
Definition: BCFunction.hpp:77
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
Real robin(const Real &, const Real &, const Real &, const Real &, const ID &)
Real neumann2(const Real &, const Real &, const Real &, const Real &, const ID &)
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.