LifeV
lifev/eta/tutorials/13_ETA_LaplacianVector/main.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  @brief Tutorial for laplacian of trial functions.
30 
31  @author Davide Forti <davide.forti@epfl.ch>
32  @date 2013-05
33 
34  Test to check (and to show) how the laplacian pf the test
35  and trial functions is computed
36 
37  */
38 
39 // ---------------------------------------------------------------
40 // We reuse the same files as in the previous tutorial. We add the
41 // chrono to measure the timings.
42 // ---------------------------------------------------------------
43 
44 
45 #include <Epetra_ConfigDefs.h>
46 #ifdef EPETRA_MPI
47 #include <mpi.h>
48 #include <Epetra_MpiComm.h>
49 #else
50 #include <Epetra_SerialComm.h>
51 #endif
52 
53 
54 #include <lifev/core/LifeV.hpp>
55 
56 #include <lifev/core/mesh/MeshPartitioner.hpp>
57 #include <lifev/core/mesh/RegionMesh3DStructured.hpp>
58 #include <lifev/core/mesh/RegionMesh.hpp>
59 #include <lifev/core/mesh/MeshData.hpp>
60 
61 #include <lifev/core/array/MatrixEpetra.hpp>
62 #include <lifev/core/array/VectorEpetra.hpp>
63 
64 #include <lifev/eta/fem/ETFESpace.hpp>
65 #include <lifev/eta/expression/Integrate.hpp>
66 
67 #include <lifev/core/fem/FESpace.hpp>
68 
69 #include <lifev/core/util/LifeChrono.hpp>
70 
71 using namespace LifeV;
72 
74 typedef MatrixEpetra<Real> matrix_Type;
75 typedef VectorEpetra vector_Type;
76 
77 Real uOnes ( const Real& /* t */, const Real& x , const Real& y , const Real& z , const ID& i )
78 {
79  return 1.0;
80 }
81 
82 Real uFunction ( const Real& /* t */, const Real& x , const Real& y , const Real& z , const ID& i )
83 {
84  if ( i == 0 )
85  return x*x*0.5;
86  else if ( i == 1)
87  return y*y*0.5;
88  else
89  return z*z*0.5;
90 }
91 
92 int main ( int argc, char** argv )
93 {
94 
95 #ifdef HAVE_MPI
96  MPI_Init (&argc, &argv);
97  std::shared_ptr<Epetra_Comm> Comm (new Epetra_MpiComm (MPI_COMM_WORLD) );
98 #else
99  std::shared_ptr<Epetra_Comm> Comm (new Epetra_SerialComm);
100 #endif
101 
102  const bool verbose (Comm->MyPID() == 0);
103 
104  const UInt Nelements (10);
105 
106  std::shared_ptr< mesh_Type > fullMeshPtr (new mesh_Type);
107 
108  Real length = 3.0;
109 
110  regularMesh3D ( *fullMeshPtr, 1, Nelements, Nelements, Nelements, false,
111  length, length, length,
112  0.0, 0.0, 0.0);
113 
114  MeshPartitioner< mesh_Type > meshPart (fullMeshPtr, Comm);
115  std::shared_ptr< mesh_Type > meshPtr (meshPart.meshPartition() );
116 
117  fullMeshPtr.reset();
118 
119  std::string uOrder ("P2");
120 
121  ///////////////////////////////////
122  // Testing the scalar field case //
123  ///////////////////////////////////
124 
125  std::shared_ptr<FESpace< mesh_Type, MapEpetra > > uSpace
126  ( new FESpace< mesh_Type, MapEpetra > (meshPtr, uOrder, 1, Comm) );
127 
128  std::shared_ptr<ETFESpace< mesh_Type, MapEpetra, 3, 1 > > ETuSpace
129  ( new ETFESpace< mesh_Type, MapEpetra, 3, 1 > (meshPtr, & (uSpace->refFE() ), & (uSpace->fe().geoMap() ), Comm) );
130 
131  vector_Type myFEvector (uSpace->map(), Unique);
132  uSpace->interpolate (static_cast<FESpace< mesh_Type, MapEpetra >::function_Type> (uFunction), myFEvector, 0.0);
133  vector_Type myFEvectorRepeated (myFEvector, Repeated);
134 
135  vector_Type vectorOnes (uSpace->map(), Unique);
136  uSpace->interpolate (static_cast<FESpace< mesh_Type, MapEpetra >::function_Type> (uOnes), vectorOnes, 0.0);
137 
138  vector_Type integral (uSpace->map() );
139 
140  {
141  using namespace ExpressionAssembly;
142 
143  integrate ( elements (ETuSpace->mesh() ),
144  uSpace->qr(),
145  ETuSpace,
146  laplacian(ETuSpace, myFEvectorRepeated) * phi_i
147  )
148  >> integral;
149  }
150 
151  integral.globalAssemble();
152 
153  Real result = 0.0;
154 
155  result = integral.dot(vectorOnes);
156 
157  if ( Comm->MyPID() == 0 )
158  {
159  std::cout << "\n\nSCALAR CASE " << std::endl;
160  std::cout << "\nThe volume is = " << length*length*length << std::endl;
161  std::cout << "\nThe result is = " << result << std::endl;
162  std::cout << "\nThe error is = " << result-(length*length*length) << std::endl;
163  }
164 
165  Real error_scalar = result-length*length*length;
166 
167  ///////////////////////////////////
168  // Testing the vector field case //
169  ///////////////////////////////////
170 
171  std::shared_ptr<FESpace< mesh_Type, MapEpetra > > uSpaceVec
172  ( new FESpace< mesh_Type, MapEpetra > (meshPtr, uOrder, 3, Comm) );
173 
174  std::shared_ptr<ETFESpace< mesh_Type, MapEpetra, 3, 3 > > ETuSpaceVec
175  ( new ETFESpace< mesh_Type, MapEpetra, 3, 3 > (meshPtr, & (uSpaceVec->refFE() ), & (uSpaceVec->fe().geoMap() ), Comm) );
176 
177  vector_Type myFEvectorVec (uSpaceVec->map(), Unique);
178  uSpaceVec->interpolate (static_cast<FESpace< mesh_Type, MapEpetra >::function_Type> (uFunction), myFEvectorVec, 0.0);
179  vector_Type myFEvectorRepeatedVec (myFEvectorVec, Repeated);
180 
181  vector_Type vectorOnesVec (uSpaceVec->map(), Unique);
182  uSpaceVec->interpolate (static_cast<FESpace< mesh_Type, MapEpetra >::function_Type> (uOnes), vectorOnesVec, 0.0);
183 
184  vector_Type integralVec (uSpaceVec->map() );
185 
186  {
187  using namespace ExpressionAssembly;
188 
189  integrate ( elements (ETuSpaceVec->mesh() ),
190  uSpaceVec->qr(),
191  ETuSpaceVec,
192  dot ( laplacian(ETuSpaceVec, myFEvectorVec), phi_i )
193  )
194  >> integralVec;
195  }
196 
197  integralVec.globalAssemble();
198 
199  result = 0.0;
200 
201  result = integralVec.dot(vectorOnesVec);
202 
203  if ( Comm->MyPID() == 0 )
204  {
205  std::cout << "\n\nVECTORIAL CASE " << std::endl;
206  std::cout << "\nThe volume is = " << 3*length*length*length << std::endl;
207  std::cout << "\nThe result is = " << result << std::endl;
208  std::cout << "\nThe error is = " << result-(3*(length*length*length)) << "\n\n";
209  }
210 
211  Real error_vectorial = result-3*length*length*length;
212 
213 #ifdef HAVE_MPI
214  MPI_Finalize();
215 #endif
216 
217  if ( std::fabs(error_scalar) < 1e-9 && std::fabs(error_vectorial) < 1e-9 )
218  {
219  return ( EXIT_SUCCESS );
220  }
221 
222  return ( EXIT_FAILURE );
223 }
int main(int argc, char **argv)
MatrixEpetra< Real > matrix_Type
uint32_type ID
IDs.
Definition: LifeV.hpp:194
double Real
Generic real data.
Definition: LifeV.hpp:175
Real uOnes(const Real &, const Real &x, const Real &y, const Real &z, const ID &i)
RegionMesh< LinearTetra > mesh_Type
Real uFunction(const Real &, const Real &x, const Real &y, const Real &z, const ID &i)