LifeV
lifev/core/testsuite/interpolation/RBF_nonconformingPolynomialOrders/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
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/Interpolation.hpp>
53 #include <Teuchos_ParameterList.hpp>
54 #include <Teuchos_XMLParameterListHelpers.hpp>
55 #include <Teuchos_RCP.hpp>
56 
57 //Tell the compiler to restore the warning previously silented
58 #pragma GCC diagnostic warning "-Wunused-variable"
59 #pragma GCC diagnostic warning "-Wunused-parameter"
60 
61 using namespace LifeV;
62 
63 double fx (double x, double y, double z)
64 {
65  return sin (x) + y + z;
66 }
67 
68 double fy (double x, double y, double z)
69 {
70  return sin (y) + x + z;
71 }
72 
73 double fz (double x, double y, double z)
74 {
75  return sin (z) + x + y ;
76 }
77 
78 Real exact_sol (const Real& /*t*/, const Real& x, const Real& y, const Real& z, const ID& i)
79 {
80  switch (i)
81  {
82  case 0:
83  return sin (x) + y + z;
84  break;
85  case 1:
86  return sin (y) + x + z;
87  break;
88  case 2:
89  return sin (z) + x + y ;
90  break;
91  default:
92  ERROR_MSG ("This entry is not allowed: ud_functions.hpp");
93  return 0.;
94  break;
95  }
96 }
97 
98 Real exact_sol_easy (const Real& /*t*/, const Real& /*x*/, const Real& /*y*/, const Real& /*z*/, const ID& i)
99 {
100  switch (i)
101  {
102  case 0:
103  return 20.;
104  break;
105  case 1:
106  return 30.;
107  break;
108  case 2:
109  return -15.;
110  break;
111  default:
112  ERROR_MSG ("This entry is not allowed: ud_functions.hpp");
113  return 0.;
114  break;
115  }
116 }
117 
118 int main (int argc, char** argv )
119 {
120  // Testing interpolation between the interface between two grids that are nonconforming
121  // and discretized by nonconforming FE spaces
122 
123  typedef VectorEpetra vector_Type;
124  typedef std::shared_ptr<vector_Type > vectorPtr_Type;
125  typedef RegionMesh<LinearTetra > mesh_Type;
126  typedef std::shared_ptr< mesh_Type > meshPtr_Type;
127  typedef FESpace< RegionMesh<LinearTetra>, MapEpetra > FESpace_Type;
128 
129  std::shared_ptr<Epetra_Comm> Comm;
130 #ifdef HAVE_MPI
131  MPI_Init (&argc, &argv);
132  Comm.reset (new Epetra_MpiComm (MPI_COMM_WORLD) );
133 #else
134  Comm.reset ( new Epetra_SerialComm() );
135 #endif
136 
137  // DATAFILE
138  GetPot command_line (argc, argv);
139  GetPot dataFile ( command_line.follow ("data", 2, "-f", "--file" ) );
140 
141  // BELOS XML file
142  Teuchos::RCP< Teuchos::ParameterList > belosList = Teuchos::rcp ( new Teuchos::ParameterList );
143  belosList = Teuchos::getParametersFromXmlFile ( "SolverParamList_rbf3d.xml" );
144 
145  // LOADING MESHES
146  MeshData Solid_mesh_data;
147  meshPtr_Type Solid_mesh_ptr ( new mesh_Type ( Comm ) );
148  Solid_mesh_data.setup (dataFile, "solid/space_discretization");
149  readMesh (*Solid_mesh_ptr, Solid_mesh_data);
150 
151  MeshData Fluid_mesh_data;
152  meshPtr_Type Fluid_mesh_ptr ( new mesh_Type ( Comm ) );
153  Fluid_mesh_data.setup (dataFile, "fluid/space_discretization");
154  readMesh (*Fluid_mesh_ptr, Fluid_mesh_data);
155 
156  // PARTITIONING MESHES
157  MeshPartitioner<mesh_Type> Solid_mesh_part;
158  std::shared_ptr<mesh_Type> Solid_localMesh;
159  Solid_mesh_part.doPartition (Solid_mesh_ptr, Comm);
160  Solid_localMesh = Solid_mesh_part.meshPartition();
161 
162  MeshPartitioner<mesh_Type> Fluid_mesh_part;
163  std::shared_ptr<mesh_Type> Fluid_localMesh;
164  Fluid_mesh_part.doPartition (Fluid_mesh_ptr, Comm);
165  Fluid_localMesh = Fluid_mesh_part.meshPartition();
166 
167  // FE spaces
168  std::string orderFluid = dataFile("fluid/space_discretization/order","default");
169  std::string orderStructure = dataFile("solid/space_discretization/order","default");
170 
171  std::shared_ptr<FESpace<mesh_Type, MapEpetra> > Solid_fieldFESpace_whole (new FESpace<mesh_Type, MapEpetra> (Solid_mesh_ptr, orderStructure, 3, Comm) );
172  std::shared_ptr<FESpace<mesh_Type, MapEpetra> > Fluid_fieldFESpace_whole (new FESpace<mesh_Type, MapEpetra> (Fluid_mesh_ptr, orderFluid, 3, Comm) );
173 
174  std::shared_ptr<FESpace<mesh_Type, MapEpetra> > Solid_fieldFESpace (new FESpace<mesh_Type, MapEpetra> (Solid_localMesh, orderStructure, 3, Comm) );
175  std::shared_ptr<FESpace<mesh_Type, MapEpetra> > Fluid_fieldFESpace (new FESpace<mesh_Type, MapEpetra> (Fluid_localMesh, orderFluid, 3, Comm) );
176 
177  Interpolation intergrid;
178  intergrid.setup(dataFile, belosList);
179  intergrid.setFlag( dataFile("flag/interface", 1 ) );
180  intergrid.setMeshSize(MeshUtility::MeshStatistics::computeSize(*Fluid_mesh_ptr).maxH);
181 
182  // Set vectors for interpolation
183  vectorPtr_Type Solid_vector (new vector_Type (Solid_fieldFESpace->map(), Unique) );
184  vectorPtr_Type Fluid_solution (new vector_Type (Fluid_fieldFESpace->map(), Unique) );
185  intergrid.setVectors(Solid_vector, Fluid_solution);
186 
187  // Build table of DOFs
188  intergrid.buildTableDofs_known ( Solid_fieldFESpace_whole );
189  intergrid.buildTableDofs_unknown ( Fluid_fieldFESpace_whole );
190 
191  // Build table of DOFs
192  intergrid.identifyNodes_known ( );
193  intergrid.identifyNodes_unknown ( );
194 
195  // build maps
196  intergrid.buildKnownInterfaceMap();
197  intergrid.buildUnknownInterfaceMap();
198 
199  intergrid.buildOperators();
200 
201  vectorPtr_Type Solid_vector_one (new vector_Type (Solid_fieldFESpace->map(), Unique) );
202  Solid_fieldFESpace->interpolate ( static_cast<FESpace_Type::function_Type> ( exact_sol_easy ), *Solid_vector_one, 0.0 );
203 
204  // GET THE EXACT SOLUTION THAT WILL BE INTERPOLATED
205  Solid_fieldFESpace->interpolate ( static_cast<FESpace_Type::function_Type> ( exact_sol ), *Solid_vector, 0.0 );
206 
207  // TESTING THE RESTRICTION AND EXPANDING METHODS
208  vectorPtr_Type solidVectorOnGamma;
209  vectorPtr_Type solidVectorOnOmega;
210 
211  intergrid.restrictOmegaToGamma_Known(Solid_vector, solidVectorOnGamma);
212  intergrid.expandGammaToOmega_Known(solidVectorOnGamma, solidVectorOnOmega);
213 
214  // EXPORTING THE DEFINED FIELD
215  ExporterHDF5<mesh_Type> Solid_exporter (dataFile, Solid_localMesh, "InputField", Comm->MyPID() );
216  Solid_exporter.setMeshProcId (Solid_localMesh, Comm->MyPID() );
217  Solid_exporter.exportPID (Solid_localMesh, Comm, true );
218  Solid_exporter.addVariable (ExporterData<mesh_Type>::VectorField, "f(x,y,z)", Solid_fieldFESpace, Solid_vector, UInt (0) );
219  Solid_exporter.addVariable (ExporterData<mesh_Type>::VectorField, "restrict-expand", Solid_fieldFESpace, solidVectorOnOmega, UInt (0) );
220  Solid_exporter.postProcess (0);
221  Solid_exporter.closeFile();
222 
223  // EXPORTING THE SOLUTION
224  ExporterHDF5<mesh_Type> Fluid_exporter (dataFile, Fluid_localMesh, "Results", Comm->MyPID() );
225  Fluid_exporter.setMeshProcId (Fluid_localMesh, Comm->MyPID() );
226  Fluid_exporter.exportPID (Fluid_localMesh, Comm, true );
227  Fluid_exporter.addVariable (ExporterData<mesh_Type>::VectorField, "Solution", Fluid_fieldFESpace, Fluid_solution, UInt (0) );
228 
229  // TESTING THE METHOD updateRhs
230  intergrid.updateRhs (Solid_vector);
231 
232  // PERFORMING INTERPOLATION WITH A VECTOR OF ONE
233  intergrid.interpolate();
234 
235  // GET THE SOLUTION
236  intergrid.solution (Fluid_solution);
237 
238  // EXPORT FIRST SOLUTION
239  Fluid_exporter.postProcess (0);
240 
241  // TESTING THE METHOD updateRhs
242  intergrid.updateRhs (Solid_vector_one);
243 
244  // PERFORMING INTERPOLATION WITH A VECTOR OF ONE
245  intergrid.interpolate();
246 
247  // GET THE SOLUTION
248  intergrid.solution (Fluid_solution);
249 
250  // EXPORT FIRST SOLUTION
251  Fluid_exporter.postProcess (1);
252 
253  // GET THE SOLUTION ON GAMMA
254  vectorPtr_Type Fluid_solutionOnGamma;
255  intergrid.getSolutionOnGamma (Fluid_solutionOnGamma);
256 
257  Fluid_exporter.closeFile();
258 
259  Real check = Fluid_solution->norm2();
260 
261 #ifdef HAVE_MPI
262  MPI_Finalize();
263 #endif
264 
265  if ( (check - 1542.4) < 0.1 )
266  {
267  return ( EXIT_SUCCESS );
268  }
269  else
270  {
271  return ( EXIT_FAILURE );
272  }
273 
274 }
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)