LifeV
lifev/core/testsuite/fem/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 Test for the CurrentFE update
30 
31  @author Samuel Quinodoz <samuel.quinodoz@epfl.ch>
32  @date 16-04-2010
33 
34  Just a fast test to see if the update procedure is
35  working correctly in the CurrentFE class.
36  */
37 
38 
39 #include <Epetra_ConfigDefs.h>
40 #ifdef EPETRA_MPI
41 #include <mpi.h>
42 #include <Epetra_MpiComm.h>
43 #else
44 #include <Epetra_SerialComm.h>
45 #endif
46 
47 
48 #include <lifev/core/LifeV.hpp>
49 
50 #include <lifev/core/fem/CurrentFE.hpp>
51 
52 using namespace LifeV;
53 
54 int
55 main ( int argc, char** argv )
56 {
57  //MPI communicator initialization
58  std::shared_ptr<Epetra_Comm> comm;
59 
60 #ifdef HAVE_MPI
61  std::cout << "MPI Initialization" << std::endl;
62  MPI_Init ( &argc, &argv );
63 #endif
64 
65  //MPI Preprocessing
66 #ifdef EPETRA_MPI
67 
68  int nprocs;
69  int rank;
70 
71  MPI_Comm_size ( MPI_COMM_WORLD, &nprocs );
72  MPI_Comm_rank ( MPI_COMM_WORLD, &rank );
73 
74  if ( rank == 0 )
75  {
76  std::cout << "MPI processes: " << nprocs << std::endl;
77  std::cout << "MPI Epetra Initialization ... " << std::endl;
78  }
79  comm.reset ( new Epetra_MpiComm ( MPI_COMM_WORLD ) );
80 
81  comm->Barrier();
82 
83 #else
84 
85  std::cout << "MPI SERIAL Epetra Initialization ... " << std::endl;
86  comm.reset ( new Epetra_SerialComm() );
87 
88 #endif
89 
90 
91  // Test the current FE...
92 
93  Real test_tolerance (1e-10);
94 
95  // We define a fictious tetra
96  std::vector<Real> P0 (3);
97  P0[0] = 1;
98  P0[1] = 0;
99  P0[2] = 0;
100  std::vector<Real> P1 (3);
101  P1[0] = 1.1;
102  P1[1] = 0;
103  P1[2] = 0;
104  std::vector<Real> P2 (3);
105  P2[0] = 1;
106  P2[1] = 0.2;
107  P2[2] = 0;
108  std::vector<Real> P3 (3);
109  P3[0] = 1;
110  P3[1] = 0;
111  P3[2] = 0.15;
112 
113  std::vector< std::vector< Real > > Tetra1 (4);
114  Tetra1[0] = P0;
115  Tetra1[1] = P1;
116  Tetra1[2] = P2;
117  Tetra1[3] = P3;
118 
119  // 1. Part: flags & update
120 
121  std::cout << " Checking updates ... " << std::endl;
122 
123  CurrentFE test_CFE (feTetraP2, geoLinearTetra, quadRuleTetra4pt);
124 
125  test_CFE.update (Tetra1, UPDATE_QUAD_NODES);
126  test_CFE.quadNode (0, 0);
127 
128  test_CFE.update (Tetra1, UPDATE_DPHI);
129  test_CFE.dphi (2, 0, 3);
130 
131  test_CFE.update (Tetra1, UPDATE_D2PHI);
132  test_CFE.d2phi (1, 0, 1, 2);
133 
134  test_CFE.update (Tetra1, UPDATE_WDET);
135  test_CFE.wDetJacobian (0);
136 
137  // 2. Part: check values
138 
139  // Check the partition of unity
140 
141  std::cout << " Checking partition of unity ... " << std::endl;
142 
143  test_CFE.update (Tetra1, UPDATE_DPHI);
144  Real sum_phi;
145  Real sum_dphi;
146  for (UInt i (0); i < test_CFE.nbQuadPt(); ++i)
147  {
148  sum_phi = 0.0;
149  sum_dphi = 0.0;
150 
151  for (UInt n (0); n < test_CFE.nbFEDof(); ++n)
152  {
153  sum_phi += test_CFE.phi (n, i);
154  sum_dphi += test_CFE.dphi (n, 0, i);
155  }
156 
157  if (std::fabs (sum_phi - 1) > test_tolerance)
158  {
159  std::cerr << " Sum of the basis functions : " << sum_phi << std::endl;
160  return EXIT_FAILURE;
161  };
162  if (std::fabs (sum_dphi) > test_tolerance)
163  {
164  std::cerr << " Sum of the derivatives of the basis functions : " << sum_dphi << std::endl;
165  return EXIT_FAILURE;
166  };
167  }
168 
169  // Check the measures
170 
171  std::cout << " Checking measure ... " << std::endl;
172 
173  test_CFE.update (Tetra1, UPDATE_WDET );
174 
175  Real meas (test_CFE.measure() );
176  if (std::fabs (meas - 0.0005) > test_tolerance)
177  {
178  std::cerr << " Measure : " << meas << std::endl;
179  return EXIT_FAILURE;
180  }
181 
182 
183  // 3. Part: change of quadrature
184 
185  std::cout << " Checking setQuadRule ... " << std::endl;
186  test_CFE.setQuadRule (quadRuleTetra5pt);
187 
188  test_CFE.update (Tetra1, UPDATE_QUAD_NODES);
189  test_CFE.quadNode (3, 0);
190 
191  test_CFE.update (Tetra1, UPDATE_DPHI);
192  test_CFE.dphi (2, 0, 4);
193 
194  test_CFE.update (Tetra1, UPDATE_D2PHI);
195  test_CFE.d2phi (1, 0, 1, 4);
196 
197  test_CFE.update (Tetra1, UPDATE_WDET);
198  test_CFE.wDetJacobian (4);
199 
200 
201  // ----- End of test calls -----
202 
203 #ifdef HAVE_MPI
204  std::cout << "MPI Finalization" << std::endl;
205  MPI_Finalize();
206 #endif
207 
208  // If everything runs correctly we return EXIT_SUCCESS flag
209  return EXIT_SUCCESS;
210 }
void updateInverseJacobian(const UInt &iQuadPt)
int main(int argc, char **argv)
Definition: dummy.cpp:5
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