LifeV
RBF_test3dVectorial/rbf3d.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
30 
31 @author Davide Forti <davide.forti@epfl.ch>
32 @date 05-28-2015
33 */
34 
35 // Tell the compiler to ignore specific kind of warnings:
36 #pragma GCC diagnostic ignored "-Wunused-variable"
37 #pragma GCC diagnostic ignored "-Wunused-parameter"
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 #include <lifev/core/LifeV.hpp>
48 #include <lifev/core/filter/GetPot.hpp>
49 #include <lifev/core/mesh/MeshPartitioner.hpp>
50 #include <lifev/core/mesh/MeshData.hpp>
51 #include <lifev/core/filter/ExporterHDF5.hpp>
52 #include <lifev/core/interpolation/RBFInterpolation.hpp>
53 #include <lifev/core/interpolation/RBFlocallyRescaledVectorial.hpp>
54 #include <lifev/core/interpolation/RBFrescaledVectorial.hpp>
55 #include <Teuchos_ParameterList.hpp>
56 #include <Teuchos_XMLParameterListHelpers.hpp>
57 #include <Teuchos_RCP.hpp>
58 
59 //Tell the compiler to restore the warning previously silented
60 #pragma GCC diagnostic warning "-Wunused-variable"
61 #pragma GCC diagnostic warning "-Wunused-parameter"
62 
63 using namespace LifeV;
64 
65 double fx (double x, double y, double z)
66 {
67  return sin (x) + y + z;
68 }
69 
70 double fy (double x, double y, double z)
71 {
72  return sin (y) + x + z;
73 }
74 
75 double fz (double x, double y, double z)
76 {
77  return sin (z) + x + y ;
78 }
79 
80 Real exact_sol (const Real& /*t*/, const Real& x, const Real& y, const Real& z, const ID& i)
81 {
82  switch (i)
83  {
84  case 0:
85  return sin (x) + y + z;
86  break;
87  case 1:
88  return sin (y) + x + z;
89  break;
90  case 2:
91  return sin (z) + x + y ;
92  break;
93  default:
94  ERROR_MSG ("This entry is not allowed: ud_functions.hpp");
95  return 0.;
96  break;
97  }
98 }
99 
100 Real exact_sol_easy (const Real& /*t*/, const Real& /*x*/, const Real& /*y*/, const Real& /*z*/, const ID& i)
101 {
102  switch (i)
103  {
104  case 0:
105  return 20.;
106  break;
107  case 1:
108  return 30.;
109  break;
110  case 2:
111  return -15.;
112  break;
113  default:
114  ERROR_MSG ("This entry is not allowed: ud_functions.hpp");
115  return 0.;
116  break;
117  }
118 }
119 
120 int main (int argc, char** argv )
121 {
122  typedef VectorEpetra vector_Type;
123  typedef std::shared_ptr<vector_Type > vectorPtr_Type;
124  typedef RegionMesh<LinearTetra > mesh_Type;
125  typedef std::shared_ptr< mesh_Type > meshPtr_Type;
126  typedef RBFInterpolation<mesh_Type> interpolation_Type;
127  typedef std::shared_ptr<interpolation_Type> interpolationPtr_Type;
128  typedef FESpace< RegionMesh<LinearTetra>, MapEpetra > FESpace_Type;
129 
130  std::shared_ptr<Epetra_Comm> Comm;
131 #ifdef HAVE_MPI
132  MPI_Init (&argc, &argv);
133  Comm.reset (new Epetra_MpiComm (MPI_COMM_WORLD) );
134 #else
135  Comm.reset ( new Epetra_SerialComm() );
136 #endif
137 
138  // DATAFILE
139  GetPot command_line (argc, argv);
140  GetPot dataFile ( command_line.follow ("data_rbf3d", 2, "-f", "--file" ) );
141 
142  // BELOS XML file
143  Teuchos::RCP< Teuchos::ParameterList > belosList = Teuchos::rcp ( new Teuchos::ParameterList );
144  belosList = Teuchos::getParametersFromXmlFile ( "SolverParamList_rbf3d.xml" );
145 
146  // LOADING MESHES
147  MeshData Solid_mesh_data;
148  meshPtr_Type Solid_mesh_ptr ( new mesh_Type ( Comm ) );
149  Solid_mesh_data.setup (dataFile, "solid/space_discretization");
150  readMesh (*Solid_mesh_ptr, Solid_mesh_data);
151 
152  MeshData Fluid_mesh_data;
153  meshPtr_Type Fluid_mesh_ptr ( new mesh_Type ( Comm ) );
154  Fluid_mesh_data.setup (dataFile, "fluid/space_discretization");
155  readMesh (*Fluid_mesh_ptr, Fluid_mesh_data);
156 
157  // PARTITIONING MESHES
158  MeshPartitioner<mesh_Type> Solid_mesh_part;
159  std::shared_ptr<mesh_Type> Solid_localMesh;
160  Solid_mesh_part.doPartition (Solid_mesh_ptr, Comm);
161  Solid_localMesh = Solid_mesh_part.meshPartition();
162 
163  MeshPartitioner<mesh_Type> Fluid_mesh_part;
164  std::shared_ptr<mesh_Type> Fluid_localMesh;
165  Fluid_mesh_part.doPartition (Fluid_mesh_ptr, Comm);
166  Fluid_localMesh = Fluid_mesh_part.meshPartition();
167 
168  // CREATING A FE-SPACE FOR THE GRID ON WHICH WE ASSUME TO KNOW THE INTERFACE FIELD. DEFINING AN INTERFACE VECTOR TO BE INTERPOLATED.
169  std::shared_ptr<FESpace<mesh_Type, MapEpetra> > Solid_fieldFESpace (new FESpace<mesh_Type, MapEpetra> (Solid_localMesh, "P1", 3, Comm) );
170  vectorPtr_Type Solid_vector (new vector_Type (Solid_fieldFESpace->map(), Unique) );
171  vectorPtr_Type Solid_vector_one (new vector_Type (Solid_fieldFESpace->map(), Unique) );
172  Solid_fieldFESpace->interpolate ( static_cast<FESpace_Type::function_Type> ( exact_sol_easy ), *Solid_vector_one, 0.0 );
173 
174  // GET THE EXACT SOLUTION THAT WILL BE INTERPOLATED
175  Solid_fieldFESpace->interpolate ( static_cast<FESpace_Type::function_Type> ( exact_sol ), *Solid_vector, 0.0 );
176 
177  // CREATING A FE-SPACE FOR THE GRID ON WHICH WE WANT TO INTERPOLATE THE DATA. INITIALIZING THE SOLUTION VECTOR.
178  std::shared_ptr<FESpace<mesh_Type, MapEpetra> > Fluid_fieldFESpace (new FESpace<mesh_Type, MapEpetra> (Fluid_localMesh, "P1", 3, Comm) );
179  vectorPtr_Type Fluid_solution (new vector_Type (Fluid_fieldFESpace->map(), Unique) );
180 
181  // NUMBER OF FLAGS CONSIDERED: THE DOFS WHOSE FLAG IS 1 AND 20 ARE TAKEN INTO ACCOUNT
182  // NOTE: from mesh to mesh the vector of flag has to contain one element with value -1
183  int nFlags = 2;
184  std::vector<int> flags (nFlags);
185  flags[0] = 1;
186  flags[1] = 20;
187 
188  // INITIALIZE THE INTERPOLANT
189  interpolationPtr_Type RBFinterpolant;
190 
191  // READING FROM DATAFILE WHICH INTERPOLANT HAS TO BE USED
192  RBFinterpolant.reset ( interpolation_Type::InterpolationFactory::instance().createObject (dataFile("interpolation/interpolation_Type","none")));
193 
194  // SET UP FOR THE INTERPOLANT: GLOBAL AND LOCAL MESHES PLUS THE VECTOR OF FLAGS
195  RBFinterpolant->setup(Solid_mesh_ptr, Solid_localMesh, Fluid_mesh_ptr, Fluid_localMesh, flags);
196 
197  // PASSING THE VECTOR WITH THE DATA, THE ONE THAT WILL STORE THE SOLUTION, THE DATAFILE AND THE BELOS LIST
198  RBFinterpolant->setupRBFData (Solid_vector_one, Fluid_solution, dataFile, belosList);
199 
200  // CREATING THE RBF OPERATORS
201  RBFinterpolant->buildOperators();
202 
203  // TESTING THE RESTRICTION AND EXPANDING METHODS
204  vectorPtr_Type solidVectorOnGamma;
205  vectorPtr_Type solidVectorOnOmega;
206 
207  RBFinterpolant->restrictOmegaToGamma_Known(Solid_vector, solidVectorOnGamma);
208  RBFinterpolant->expandGammaToOmega_Known(solidVectorOnGamma, solidVectorOnOmega);
209 
210  // EXPORTING THE DEFINED FIELD
211  ExporterHDF5<mesh_Type> Solid_exporter (dataFile, Solid_localMesh, "InputField", Comm->MyPID() );
212  Solid_exporter.setMeshProcId (Solid_localMesh, Comm->MyPID() );
213  Solid_exporter.exportPID (Solid_localMesh, Comm, true );
214  Solid_exporter.addVariable (ExporterData<mesh_Type>::VectorField, "f(x,y,z)", Solid_fieldFESpace, Solid_vector, UInt (0) );
215  Solid_exporter.addVariable (ExporterData<mesh_Type>::VectorField, "restrict-expand", Solid_fieldFESpace, solidVectorOnOmega, UInt (0) );
216  Solid_exporter.postProcess (0);
217  Solid_exporter.closeFile();
218 
219  // PERFORMING INTERPOLATION WITH A VECTOR OF ONE
220  RBFinterpolant->interpolate();
221 
222  // GET THE SOLUTION
223  RBFinterpolant->solution (Fluid_solution);
224 
225  // GET THE SOLUTION ON GAMMA
226  vectorPtr_Type Fluid_solutionOnGamma;
227  RBFinterpolant->getSolutionOnGamma (Fluid_solutionOnGamma);
228 
229  // TESTING THE METHOD updateRhs
230  RBFinterpolant->updateRhs (Solid_vector);
231 
232  // PERFORMING INTERPOLATION WITH A VECTOR OF ONE
233  RBFinterpolant->interpolate();
234 
235  // GET THE SOLUTION
236  RBFinterpolant->solution (Fluid_solution);
237 
238  // COMPUTING THE ERROR
239  vectorPtr_Type Fluid_exact_solution (new vector_Type (Fluid_fieldFESpace->map(), Unique) );
240  vectorPtr_Type myError (new vector_Type (Fluid_fieldFESpace->map(), Unique) );
241  vectorPtr_Type rbfError (new vector_Type (Fluid_fieldFESpace->map(), Unique) );
242 
243  // NOTE: HERE WE DO NOT USE THE INTERPOLATE METHOD OF THE FESPACE CLASS SINCE WE WANT THAT THE EXACT SOLUTION
244  // IS DEFINED JUST AT THE INTERFACE BETWEEN THE MESHES
245  for ( UInt j = 0; j < 3; ++j)
246  for ( UInt i = 0; i < Fluid_exact_solution->epetraVector().MyLength(); ++i )
247  if ( Fluid_exact_solution->blockMap().GID (i) < Fluid_mesh_ptr->pointList.size())
248  if ( Fluid_mesh_ptr->point ( Fluid_exact_solution->blockMap().GID (i) ).markerID() == flags[0] ||
249  Fluid_mesh_ptr->point ( Fluid_exact_solution->blockMap().GID (i) ).markerID() == flags[1] )
250  if ( Fluid_exact_solution->blockMap().LID ( static_cast<EpetraInt_Type> ( Fluid_exact_solution->blockMap().GID (i) + Fluid_exact_solution->size()/3*j ) ) != -1)
251  {
252  switch (j)
253  {
254  case(0):
255  (*Fluid_exact_solution) [Fluid_exact_solution->blockMap().GID (i) + Fluid_exact_solution->size()/3*j ] = fx ( Fluid_mesh_ptr->point (Fluid_exact_solution->blockMap().GID (i) ).x(), Fluid_mesh_ptr->point (Fluid_exact_solution->blockMap().GID (i) ).y(), Fluid_mesh_ptr->point (Fluid_exact_solution->blockMap().GID (i) ).z() );
256  break;
257  case(1):
258  (*Fluid_exact_solution) [Fluid_exact_solution->blockMap().GID (i) + Fluid_exact_solution->size()/3*j ] = fy ( Fluid_mesh_ptr->point (Fluid_exact_solution->blockMap().GID (i) ).x(), Fluid_mesh_ptr->point (Fluid_exact_solution->blockMap().GID (i) ).y(), Fluid_mesh_ptr->point (Fluid_exact_solution->blockMap().GID (i) ).z() );
259  break;
260  case(2):
261  (*Fluid_exact_solution) [Fluid_exact_solution->blockMap().GID (i) + Fluid_exact_solution->size()/3*j ] = fz ( Fluid_mesh_ptr->point (Fluid_exact_solution->blockMap().GID (i) ).x(), Fluid_mesh_ptr->point (Fluid_exact_solution->blockMap().GID (i) ).y(), Fluid_mesh_ptr->point (Fluid_exact_solution->blockMap().GID (i) ).z() );
262  break;
263  }
264 
265  (*myError) [myError->blockMap().GID (i) + Fluid_exact_solution->size()/3*j ] = (*Fluid_exact_solution) [Fluid_exact_solution->blockMap().GID (i) + Fluid_exact_solution->size()/3*j ] - (*Fluid_solution) [Fluid_solution->blockMap().GID (i) + Fluid_exact_solution->size()/3*j ];
266  }
267 
268  // COMPUTING SOME ERRORS
269  Real err_inf = myError->normInf();
270 
271  // EXPORTING THE SOLUTION
272  ExporterHDF5<mesh_Type> Fluid_exporter (dataFile, Fluid_localMesh, "Results", Comm->MyPID() );
273  Fluid_exporter.setMeshProcId (Fluid_localMesh, Comm->MyPID() );
274  Fluid_exporter.exportPID (Fluid_localMesh, Comm, true );
275  Fluid_exporter.addVariable (ExporterData<mesh_Type>::VectorField, "Solution", Fluid_fieldFESpace, Fluid_solution, UInt (0) );
276  Fluid_exporter.postProcess (0);
277  Fluid_exporter.closeFile();
278 
279 #ifdef HAVE_MPI
280  MPI_Finalize();
281 #endif
282 
283  if ( std::abs(err_inf) < 1.0e-1 )
284  {
285  return ( EXIT_SUCCESS );
286  }
287  else
288  {
289  return ( EXIT_FAILURE );
290  }
291 
292 }
Real exact_sol_easy(const Real &, const Real &, const Real &, const Real &, const ID &i)
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
double fy(double x, double y, double z)
#define ERROR_MSG(A)
Definition: LifeAssert.hpp:69
uint32_type ID
IDs.
Definition: LifeV.hpp:194
Real exact_sol(const Real &, const Real &x, const Real &y, const Real &z, const ID &i)
double fz(double x, double y, double z)
double Real
Generic real data.
Definition: LifeV.hpp:175
GetPot(const STRING_VECTOR &FileNameList)
Definition: GetPot.hpp:645
const std::string follow(const char *Default, unsigned No, const char *Option,...)
Definition: GetPot.hpp:1510
double fx(double x, double y, double z)
int main(int argc, char **argv)