LifeV
SobolevNorms.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 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 procedures for computing norm and errors.
30 
31  @author
32 
33  @contributor Samuel Quinodoz <samuel.quinodoz@epfl.ch>
34  @contributor Mauro Perego <perego.mauro@gmail.com>
35  @mantainer Samuel Quinodoz <samuel.quinodoz@epfl.ch>
36 
37  */
38 
39 #ifndef _SOBOLEVNORMS_H_INCLUDED
40 #define _SOBOLEVNORMS_H_INCLUDED
41 
42 #include <lifev/core/LifeV.hpp>
43 #include <lifev/core/fem/DOF.hpp>
44 #include <lifev/core/fem/CurrentFE.hpp>
45 
46 namespace LifeV
47 {
48 //! @name Public typedefs
49 //@{
50 typedef boost::numeric::ublas::vector<Real> Vector;
52 //@}
53 
54 //! version for vectorial problem
55 template <typename VectorType>
56 Real
57 elementaryL2NormSquare ( const VectorType& u, const CurrentFE& fe, const DOF& dof,
58  const UInt nbComp )
59 {
60  Int dofID;
61  UInt eleID (fe.currentLocalId() );
62  Real sum (0.0);
63  Real uQuadPt;
64 
65  for ( UInt iComp (0); iComp < nbComp; ++iComp )
66  {
67  for ( UInt iQuadPt (0); iQuadPt < fe.nbQuadPt(); ++iQuadPt )
68  {
69  uQuadPt = 0.;
70  for ( UInt iDof (0); iDof < fe.nbFEDof(); ++iDof )
71  {
72  dofID = dof.localToGlobalMap ( eleID, iDof ) + iComp * dof.numTotalDof();
73  uQuadPt += u ( dofID ) * fe.phi ( iDof, iQuadPt );
74  }
75  sum += uQuadPt * uQuadPt * fe.weightDet ( iQuadPt );
76  }
77  }
78  return sum;
79 }
80 
81 //! returns the square of the L2 norm of fct on the current element
82 inline Real
84  const CurrentFE& fe )
85 {
86  Real sum (0.0);
87  Real f;
88  Real x;
89  Real y;
90  Real z;
91  for ( UInt iQuadPt = 0; iQuadPt < fe.nbQuadPt(); ++iQuadPt )
92  {
93  x = fe.quadNode (iQuadPt, 0);
94  y = fe.quadNode (iQuadPt, 1);
95  z = fe.quadNode (iQuadPt, 2);
96  f = fct ( x, y, z );
97  sum += f * f * fe.weightDet ( iQuadPt );
98  }
99  return sum;
100 }
101 
102 
103 //! for time dependent+vectorial.
104 inline Real
106  const CurrentFE& fe, const Real t, const UInt nbComp )
107 {
108  Real sum (0.0);
109  Real f;
110  Real x;
111  Real y;
112  Real z;
113  for ( UInt iQuadPt = 0; iQuadPt < fe.nbQuadPt(); ++iQuadPt )
114  {
115  x = fe.quadNode (iQuadPt, 0);
116  y = fe.quadNode (iQuadPt, 1);
117  z = fe.quadNode (iQuadPt, 2);
118  for ( UInt iComp (0); iComp < nbComp; ++iComp )
119  {
120  f = fct ( t, x, y, z, iComp );
121  sum += f * f * fe.weightDet ( iQuadPt );
122  }
123  }
124  return sum;
125 }
126 
127 //! returns the square of the H1 norm of u on the current element
128 template <typename VectorType>
129 Real
130 elementaryH1NormSquare ( const VectorType& u, const CurrentFE& fe, const DOF& dof, const UInt nbComp = 1 )
131 {
133  Real sum (0.0);
134  Real sum2 (0.0);
136  Real uQuadPt (0.0);
137 
138  for (UInt iComp (0); iComp < nbComp; ++iComp )
139  {
140  for ( UInt iQuadPt (0); iQuadPt < fe.nbQuadPt(); ++iQuadPt )
141  {
142 
143  uQuadPt = 0.0;
144  for (UInt iCoor (0); iCoor < fe.nbLocalCoor(); ++iCoor)
145  {
146  graduQuadPt[iCoor] = 0.0;
147  }
148 
149  for ( UInt iDof (0); iDof < fe.nbFEDof(); ++iDof )
150  {
152  uQuadPt += u ( dofID ) * fe.phi ( iDof, iQuadPt );
153  for (UInt iCoor (0); iCoor < fe.nbLocalCoor(); ++iCoor)
154  {
155  graduQuadPt[iCoor] += u ( dofID ) * fe.dphi ( iDof, iCoor, iQuadPt );
156  }
157  }
158 
159  sum2 = uQuadPt * uQuadPt;
160  for (UInt icoor = 0; icoor < fe.nbLocalCoor(); icoor++)
161  {
163  }
164  sum += sum2 * fe.weightDet ( iQuadPt );
165  }
166  }
167  return sum;
168 }
169 
170 //! returns the square of the H1 norm of fct on the current element
171 template<typename FunctionType>
172 Real
174 {
175  Real sum (0.0);
176  Real sum2 (0.0);
177  Real x;
178  Real y;
179  Real z;
180 
181  for ( UInt iQuadPt (0); iQuadPt < fe.nbQuadPt(); ++iQuadPt )
182  {
183  x = fe.quadNode (iQuadPt, 0);
184  y = fe.quadNode (iQuadPt, 1);
185  z = fe.quadNode (iQuadPt, 2);
186 
187  sum2 = std::pow (fct ( x, y, z ), 2);
188  for (UInt iCoor (0); iCoor < fe.nbLocalCoor(); ++iCoor)
189  {
190  sum2 += std::pow (fct.grad (iCoor, x, y, z), 2);
191  }
192  sum += sum2 * fe.weightDet ( iQuadPt );
193  }
194  return sum;
195 }
196 
197 //! returns the square of the H1 norm of fct on the current element (time-dependent case)
198 template <typename FunctionType>
200 {
201  Real sum (0.0);
202  Real sum2 (0.0);
203  Real x;
204  Real y;
205  Real z;
206  for ( UInt iQuadPt (0); iQuadPt < fe.nbQuadPt(); ++iQuadPt )
207  {
208  x = fe.quadNode (iQuadPt, 0);
209  y = fe.quadNode (iQuadPt, 1);
210  z = fe.quadNode (iQuadPt, 2);
211 
212  for ( UInt iComp = 0; iComp < nbComp; ++iComp )
213  {
214  sum2 = std::pow (fct (t, x, y, z, iComp ), 2);
215 
216  for (UInt iCoor = 0; iCoor < fe.nbLocalCoor(); ++iCoor)
217  {
218  sum2 += std::pow (fct.grad (iCoor, t, x, y, z, iComp), 2);
219  }
220  sum += sum2 * fe.weightDet ( iQuadPt );
221  }
222  }
223  return sum;
224 }
225 
226 //! returns the square of the L2 norm of (u-fct) on the current element
227 template <typename VectorType>
229  std::function<Real ( Real, Real, Real ) > fct,
230  const CurrentFE& fe,
231  const DOF& dof )
232 {
234  Real sum (0.0);
235  Real x;
236  Real y;
237  Real z;
238  Real uQuadPt (0.0);
239  Real diffQuadPt (0.0);
240 
241  for (UInt iQuadPt (0); iQuadPt < fe.nbQuadPt(); ++iQuadPt )
242  {
243  uQuadPt = 0.0;
244  x = fe.quadNode (iQuadPt, 0);
245  y = fe.quadNode (iQuadPt, 1);
246  z = fe.quadNode (iQuadPt, 2);
247  for (UInt iDof (0); iDof < fe.nbFEDof(); ++iDof )
248  {
250  uQuadPt += u ( dofID ) * fe.phi ( iDof, iQuadPt );
251  }
252  diffQuadPt = uQuadPt - fct ( x, y, z );
254  }
255  return sum;
256 }
257 
258 //! returns the square of the L2 norm of (u-fct) on the current element
259 //! for time dependent+vectorial
260 template <typename VectorType>
262  std::function<Real ( Real, Real, Real, Real, UInt ) > fct,
263  const CurrentFE& fe,
264  const DOF& dof, const Real t, const UInt nbComp )
265 {
266  // returns the square of the L2 norm of (u-fct) on the current element
267 
268  UInt eleID ( fe.currentLocalId() );
269  Real sum (0.0);
270  Real x;
271  Real y;
272  Real z;
273  Real uQuadPt;
275 
276  for ( UInt iQuadPt (0); iQuadPt < fe.nbQuadPt(); ++iQuadPt )
277  {
278  x = fe.quadNode (iQuadPt, 0);
279  y = fe.quadNode (iQuadPt, 1);
280  z = fe.quadNode (iQuadPt, 2);
281  for (UInt iComp = 0; iComp < nbComp; ++iComp )
282  {
283  uQuadPt = 0.0;
284  for (UInt iDof (0); iDof < fe.nbFEDof(); ++iDof )
285  {
287  uQuadPt += u ( dofID ) * fe.phi ( iDof, iQuadPt );
288  }
289  diffQuadPt = uQuadPt - fct ( t, x, y, z, iComp );
291  }
292  }
293  return sum;
294 }
295 
296 //! returns the square of the H1 norm of (u-fct) on the current element
297 template <typename VectorType, typename UsrFct>
299  const DOF& dof )
300 {
302  Real sum (0.0);
303  Real x;
304  Real y;
305  Real z;
306  Real uQuadPt (0.0);
307  Real diffQuadPt (0.0);
308 
309  for (UInt iQuadPt (0); iQuadPt < fe.nbQuadPt(); ++iQuadPt )
310  {
311  uQuadPt = 0.0;
313 
314  x = fe.quadNode (iQuadPt, 0);
315  y = fe.quadNode (iQuadPt, 1);
316  z = fe.quadNode (iQuadPt, 2);
317 
318 
319  for (UInt iDof (0); iDof < fe.nbFEDof(); ++iDof )
320  {
322  uQuadPt += u ( dofID ) * fe.phi ( iDof, iQuadPt );
323  for (UInt iCoor (0); iCoor < fe.nbLocalCoor(); ++iCoor)
324  {
325  graduQuadPt (iCoor) += u ( dofID ) * fe.dphi ( iDof, iCoor, iQuadPt );
326  }
327  }
328 
329  diffQuadPt = uQuadPt - fct ( x, y, z );
330 
332  for (UInt iCoor (0); iCoor < fe.nbLocalCoor(); ++iCoor)
333  {
334  diffGradQuadPt (iCoor) -= fct.grad (iCoor, x, y, z);
335  }
337  for (UInt iCoor (0); iCoor < fe.nbLocalCoor(); ++iCoor)
338  {
340  }
341  sum += sum2 * fe.weightDet ( iQuadPt );
342  }
343  return sum;
344 }
345 
346 //! returns the square of the H1 norm of (u-fct) on the current element (time-dependent case)
347 template <typename VectorType, typename UsrFct>
349  const DOF& dof, const Real t, const UInt nbComp )
350 {
352  Real sum (0.0);
353  Real sum2 (0.0);
354  Real x;
355  Real y;
356  Real z;
357  Real uQuadPt (0.0);
358  Real diffQuadPt (0.0);
359 
360  for (UInt iQuadPt (0); iQuadPt < fe.nbQuadPt(); ++iQuadPt )
361  {
362  x = fe.quadNode (iQuadPt, 0);
363  y = fe.quadNode (iQuadPt, 1);
364  z = fe.quadNode (iQuadPt, 2);
365 
366  for (UInt iComp (0); iComp < nbComp; ++iComp )
367  {
368  uQuadPt = 0.0;
370 
371  for (UInt iDof (0); iDof < fe.nbFEDof(); ++iDof )
372  {
374  uQuadPt += u ( dofID ) * fe.phi ( iDof, iQuadPt );
375  for (UInt iCoor (0); iCoor < fe.nbLocalCoor(); ++iCoor)
376  {
377  graduQuadPt (iCoor) += u ( dofID ) * fe.dphi ( iDof, iCoor, iQuadPt );
378  }
379  }
380 
381  diffQuadPt = uQuadPt - fct (t, x, y, z, iComp);
382 
384  for (UInt iCoor (0); iCoor < fe.nbLocalCoor(); ++iCoor)
385  {
386  diffGradQuadPt (iCoor) -= fct.grad (iCoor, t, x, y, z, iComp);
387  }
388 
390  for (UInt iCoor (0); iCoor < fe.nbLocalCoor(); ++iCoor)
391  {
393  }
394  sum += sum2 * fe.weightDet ( iQuadPt );
395  }
396  }
397  return sum;
398 }
399 
400 //! returns the integral of (u-fct) of u on the current element
401 //! for time dependent+vectorial
402 template <typename VectorType>
404  std::function<Real ( Real, Real, Real, Real, UInt ) > fct,
405  const CurrentFE& fe,
406  const DOF& dof, const Real t, const UInt nbComp = 1)
407 {
409  Real sum (0.0);
410  Real x;
411  Real y;
412  Real z;
413  Real uQuadPt;
414  Real diffQuadPt (0.0);
415 
416  for ( UInt iQuadPt (0); iQuadPt < fe.nbQuadPt(); ++iQuadPt )
417  {
418  x = fe.quadNode (iQuadPt, 0);
419  y = fe.quadNode (iQuadPt, 1);
420  z = fe.quadNode (iQuadPt, 2);
421  uQuadPt = 0.0;
422  for (ID component = 0; component < nbComp; component++)
423  {
424  for ( UInt iDof (0); iDof < fe.nbFEDof(); ++iDof )
425  {
427  uQuadPt += u ( dofID ) * fe.phi ( iDof, iQuadPt );
428  }
429  diffQuadPt = uQuadPt - fct ( t, x, y, z, component );
430  }
431  sum += diffQuadPt * fe.weightDet ( iQuadPt );
432  }
433  return sum;
434 }
435 
436 //! returns the integral of u on the current element
437 template <typename VectorType>
439  const CurrentFE& fe,
440  const DOF& dof, const UInt nbComp = 1)
441 {
443  Real sum (0.0);
444  Real uQuadPt (0.0);
445 
446  for ( UInt iQuadPt (0); iQuadPt < fe.nbQuadPt(); ++iQuadPt )
447  {
448  uQuadPt = 0.0;
449  for (ID component = 0; component < nbComp; component++)
450  {
451  for ( UInt iDof (0); iDof < fe.nbFEDof(); ++iDof )
452  {
454  uQuadPt += u ( dofID ) * fe.phi ( iDof, iQuadPt );
455  }
456  }
457  sum += uQuadPt * fe.weightDet ( iQuadPt );
458  }
459  return sum;
460 }
461 
462 //! returns the integral of fct on the current element
463 inline Real
465  Real, UInt ) > fct,
466  const CurrentFE& fe, const Real t, const UInt nbComp = 1)
467 {
468  Real sum (0.0);
469  Real x;
470  Real y;
471  Real z;
472 
473  for (UInt iQuadPt (0); iQuadPt < fe.nbQuadPt(); ++iQuadPt )
474  {
475  x = fe.quadNode (iQuadPt, 0);
476  y = fe.quadNode (iQuadPt, 1);
477  z = fe.quadNode (iQuadPt, 2);
478 
479  for (ID component = 0; component < nbComp; component++)
480  {
481  sum += fct ( t, x, y, z, component ) * fe.weightDet ( iQuadPt );
482  }
483  }
484  return sum;
485 }
486 
487 
488 } // namespace LifeV
489 #endif
boost::numeric::ublas::zero_vector< Real > ZeroVector
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
void updateInverseJacobian(const UInt &iQuadPt)
const ID & localToGlobalMap(const ID ElId, const ID localNode) const
Return the specified entries of the localToGlobal table.
Definition: DOF.hpp:195
const UInt & numTotalDof() const
The total number of Dof.
Definition: DOF.hpp:177
Real elementaryFctL2NormSquare(std::function< Real(Real, Real, Real) > fct, const CurrentFE &fe)
returns the square of the L2 norm of fct on the current element
double Real
Generic real data.
Definition: LifeV.hpp:175
CurrentFE - A primordial class for the assembly of the local matrices/vectors retaining the values on...
Definition: CurrentFE.hpp:243
UInt nbFEDof() const
Getter for the number of nodes.
Definition: CurrentFE.hpp:377
Real phi(UInt node, UInt quadNode) const
Getter for basis function values (scalar FE case)
Definition: CurrentFE.hpp:472
UInt currentLocalId() const
Getter for the local ID of the current cell.
Definition: CurrentFE.hpp:359
Real weightDet(UInt quadNode) const
Old accessor, use wDetJacobian instead.
Definition: CurrentFE.hpp:527
UInt nbQuadPt() const
Getter for the number of quadrature nodes.
Definition: CurrentFE.hpp:365
Real elementaryL2NormSquare(const VectorType &u, const CurrentFE &fe, const DOF &dof, const UInt nbComp)
version for vectorial problem
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191