LifeV
test_interpolate.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 Interpolate test
30 
31  @author Mauro Perego <mperego@fsu.edu>
32  @contributor
33  @maintainer Mauro Perego <mperego@fsu.edu>
34 
35  @date 07-01-2010
36 
37 The program tests the interpolation methods between different finite elements (mostly between scalar continuous finite elements).
38 Also it test the interpolation of an analytical function into a finite element space.
39  */
40 
41 #include <lifev/core/LifeV.hpp>
42 #include <lifev/core/fem/QuadratureRule.hpp>
43 #include <lifev/core/fem/FESpace.hpp>
44 #include <lifev/core/array/VectorEpetra.hpp>
45 #include <string>
46 #include <fstream>
47 #include <boost/bind.hpp>
48 
49 using namespace LifeV;
50 
51 Real linearFunction (const Real& t, const Real& x, const Real& y, const Real& z, const ID& ic);
52 
53 Real linearBubbleFunction (const Real& t, const Real& x, const Real& y, const Real& z, const ID& ic);
54 
55 Real quadraticFunction (const Real& t, const Real& x, const Real& y, const Real& z, const ID& ic);
56 
57 Real bilinearFunction (const Real& /*t*/, const Real& x, const Real& y, const Real& z, const ID& ic);
58 
59 
60 //! Interpolate the analytical function into the FE spaces specified in originalFeSpaceVecPtr, obtaining the set of FE vectors.
61 //! then, interpolate this set of FE vectors into vectors having FE spaces specified in finalFeSpaceVecPtr (all the possible combination).
62 //! Compute the errors between these FE vectors and the analytical solution, and compare them with the ones provided in the array errorArray.
63 //! return true if all the errors are equal to the errors in errorArray, within a tolerance eps. return false otherwise.
64 template<typename MeshType, typename MapType, typename Fct>
65 bool check_interpolate ( std::vector< std::shared_ptr < FESpace<MeshType, MapType> > >& originalFeSpaceVecPtr,
66  std::vector< std::shared_ptr < FESpace<MeshType, MapType> > >& finalFeSpaceVecPtr,
67  const MapEpetraType& outputMapType, Fct& function,
68  const Real errorArray [], const std::string stringArray [], Real eps, Real time, UInt verbose)
69 {
70  std::vector< std::shared_ptr <VectorEpetra> > interpVecPtr (originalFeSpaceVecPtr.size() );
71  bool check (true);
72 
73  for (UInt i = 0; i < originalFeSpaceVecPtr.size(); i++)
74  {
75  std::shared_ptr <VectorEpetra> tmp (new VectorEpetra (originalFeSpaceVecPtr[i]->map(), outputMapType) );
76  originalFeSpaceVecPtr[i]->interpolate ( static_cast<typename FESpace<MeshType, MapType>::function_Type> ( function ), *tmp, time);
77  interpVecPtr[i] = tmp;
78  }
79 
80  Real err_rel (0);
81  for (UInt i = 0; i < originalFeSpaceVecPtr.size(); i++)
82  for (UInt j = 0; j < finalFeSpaceVecPtr.size(); j++)
83  {
84  VectorEpetra interpolated = finalFeSpaceVecPtr[j]->feToFEInterpolate (*originalFeSpaceVecPtr[i], *interpVecPtr[i], outputMapType);
85  finalFeSpaceVecPtr[j]->l2Error ( function, VectorEpetra (interpolated, Repeated), time, &err_rel );
86  check &= fabs (err_rel - errorArray[finalFeSpaceVecPtr.size() * i + j]) < eps;
87 
88  if (verbose)
89  {
90  UInt index = finalFeSpaceVecPtr.size() * i + j;
91  std::cout.precision (7);
92  std::cout << stringArray[index] << ": " << std::setw (15) << std::setprecision (10) << err_rel << " (expected " << errorArray[index] << ")\t";
93  std::cout << "\n";
94  }
95  }
96  if (verbose)
97  {
98  std::cout << std::endl;
99  }
100  return check;
101 }
Real linearFunction(const Real &t, const Real &x, const Real &y, const Real &z, const ID &ic)
Real linearBubbleFunction(const Real &t, const Real &x, const Real &y, const Real &z, const ID &ic)
Real bilinearFunction(const Real &, const Real &x, const Real &y, const Real &z, const ID &ic)
uint32_type ID
IDs.
Definition: LifeV.hpp:194
double Real
Generic real data.
Definition: LifeV.hpp:175
bool check_interpolate(std::vector< std::shared_ptr< FESpace< MeshType, MapType > > > &originalFeSpaceVecPtr, std::vector< std::shared_ptr< FESpace< MeshType, MapType > > > &finalFeSpaceVecPtr, const MapEpetraType &outputMapType, Fct &function, const Real errorArray [], const std::string stringArray [], Real eps, Real time, UInt verbose)
Interpolate the analytical function into the FE spaces specified in originalFeSpaceVecPtr, obtaining the set of FE vectors.
Real quadraticFunction(const Real &t, const Real &x, const Real &y, const Real &z, const ID &ic)