LifeV
RBF_test3dScalar/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 02-21-2013
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/RBFlocallyRescaledScalar.hpp>
54 #include <lifev/core/interpolation/RBFrescaledScalar.hpp>
55 #include <Teuchos_ParameterList.hpp>
56 #include <Teuchos_XMLParameterListHelpers.hpp>
57 #include <Teuchos_RCP.hpp>
58 
59 #define PI 3.14159265
60 
61 //Tell the compiler to restore the warning previously silented
62 #pragma GCC diagnostic warning "-Wunused-variable"
63 #pragma GCC diagnostic warning "-Wunused-parameter"
64 
65 using namespace LifeV;
66 
67 double f (double x, double y, double z)
68 {
69  double r = std::sqrt (x * x + y * y);
70  return sin (z) + sin (r);
71 }
72 
73 int main (int argc, char** argv )
74 {
75  typedef VectorEpetra vector_Type;
76  typedef std::shared_ptr<vector_Type > vectorPtr_Type;
77  typedef RegionMesh<LinearTetra > mesh_Type;
78  typedef std::shared_ptr< mesh_Type > meshPtr_Type;
79  typedef RBFInterpolation<mesh_Type> interpolation_Type;
80  typedef std::shared_ptr<interpolation_Type> interpolationPtr_Type;
81 
82  std::shared_ptr<Epetra_Comm> Comm;
83 #ifdef HAVE_MPI
84  MPI_Init (&argc, &argv);
85  Comm.reset (new Epetra_MpiComm (MPI_COMM_WORLD) );
86 #else
87  Comm.reset ( new Epetra_SerialComm() );
88 #endif
89 
90  // DATAFILE
91  GetPot command_line (argc, argv);
92  GetPot dataFile ( command_line.follow ("data_rbf3d", 2, "-f", "--file" ) );
93 
94  Teuchos::RCP< Teuchos::ParameterList > belosList = Teuchos::rcp ( new Teuchos::ParameterList );
95  belosList = Teuchos::getParametersFromXmlFile ( "SolverParamList_rbf3d.xml" );
96 
97  // LOADING MESHES
98  MeshData Solid_mesh_data;
99  meshPtr_Type Solid_mesh_ptr ( new mesh_Type ( Comm ) );
100  Solid_mesh_data.setup (dataFile, "solid/space_discretization");
101  readMesh (*Solid_mesh_ptr, Solid_mesh_data);
102 
103  MeshData Fluid_mesh_data;
104  meshPtr_Type Fluid_mesh_ptr ( new mesh_Type ( Comm ) );
105  Fluid_mesh_data.setup (dataFile, "fluid/space_discretization");
106  readMesh (*Fluid_mesh_ptr, Fluid_mesh_data);
107 
108  // PARTITIONING MESHES
109  MeshPartitioner<mesh_Type> Solid_mesh_part;
110  std::shared_ptr<mesh_Type> Solid_localMesh;
111  Solid_mesh_part.setPartitionOverlap (0);
112  Solid_mesh_part.doPartition (Solid_mesh_ptr, Comm);
113  Solid_localMesh = Solid_mesh_part.meshPartition();
114 
115  MeshPartitioner<mesh_Type> Fluid_mesh_part;
116  std::shared_ptr<mesh_Type> Fluid_localMesh;
117  Fluid_mesh_part.setPartitionOverlap (0);
118  Fluid_mesh_part.doPartition (Fluid_mesh_ptr, Comm);
119  Fluid_localMesh = Fluid_mesh_part.meshPartition();
120 
121  // CREATING A FE-SPACE FOR THE GRID ON WHICH WE ASSUME TO KNOW THE INTERFACE FIELD. DEFINING AN INTERFACE VECTOR TO BE INTERPOLATED.
122  std::shared_ptr<FESpace<mesh_Type, MapEpetra> > Fluid_fieldFESpace (new FESpace<mesh_Type, MapEpetra> (Fluid_localMesh, "P1", 1, Comm) );
123  vectorPtr_Type Fluid_vector (new vector_Type (Fluid_fieldFESpace->map(), Unique) );
124  vectorPtr_Type Fluid_vector_one (new vector_Type (Fluid_fieldFESpace->map(), Unique) );
125 
126 
127  for ( UInt i = 0; i < Fluid_vector->epetraVector().MyLength(); ++i )
128  if (Fluid_vector->blockMap().LID (Fluid_vector->blockMap().GID (i) ) != -1)
129  (*Fluid_vector) [Fluid_vector->blockMap().GID (i)] = f ( Fluid_mesh_ptr->point (Fluid_vector->blockMap().GID (i) ).x(),
130  Fluid_mesh_ptr->point (Fluid_vector->blockMap().GID (i) ).y(),
131  Fluid_mesh_ptr->point (Fluid_vector->blockMap().GID (i) ).z() );
132 
133  // EXPORTING THE DEFINED FIELD
134  ExporterHDF5<mesh_Type> Fluid_exporter (dataFile, Fluid_localMesh, "Input field", Comm->MyPID() );
135  Fluid_exporter.setMeshProcId (Fluid_localMesh, Comm->MyPID() );
136  Fluid_exporter.exportPID (Fluid_localMesh, Comm, true );
137  Fluid_exporter.addVariable (ExporterData<mesh_Type>::ScalarField, "f(x,y,z)", Fluid_fieldFESpace, Fluid_vector, UInt (0) );
138  Fluid_exporter.postProcess (0);
139  Fluid_exporter.closeFile();
140 
141  std::shared_ptr<FESpace<mesh_Type, MapEpetra> > Solid_fieldFESpace (new FESpace<mesh_Type, MapEpetra> (Solid_localMesh, "P1", 1, Comm) );
142  vectorPtr_Type Solid_solution (new vector_Type (Solid_fieldFESpace->map(), Unique) );
143  vectorPtr_Type Solid_solution_rbf (new vector_Type (Solid_fieldFESpace->map(), Unique) );
144 
145  int nFlags = 1;
146  std::vector<int> flags (nFlags);
147  flags[0] = -1; // meaning interpolate between meshes
148 
149  interpolationPtr_Type RBFinterpolant;
150  RBFinterpolant.reset ( interpolation_Type::InterpolationFactory::instance().createObject (dataFile("interpolation/interpolation_Type","none")));
151 
152  RBFinterpolant->setup(Fluid_mesh_ptr, Fluid_localMesh, Solid_mesh_ptr, Solid_localMesh, flags);
153 
154  RBFinterpolant->setupRBFData (Fluid_vector, Solid_solution, dataFile, belosList);
155 
156  if(dataFile("interpolation/interpolation_Type","none")!="RBFlocallyRescaledScalar")
157  RBFinterpolant->setRadius((double) MeshUtility::MeshStatistics::computeSize (*Fluid_mesh_ptr).maxH);
158 
159  RBFinterpolant->buildOperators();
160 
161  RBFinterpolant->interpolate();
162 
163  RBFinterpolant->solution (Solid_solution);
164 
165  // COMPUTING THE ERROR
166  vectorPtr_Type Solid_exact_solution (new vector_Type (Solid_fieldFESpace->map(), Unique) );
167  vectorPtr_Type myError (new vector_Type (Solid_fieldFESpace->map(), Unique) );
168 
169  for ( UInt i = 0; i < Solid_exact_solution->epetraVector().MyLength(); ++i )
170  if (Solid_mesh_ptr->point (Solid_exact_solution->blockMap().GID (i) ).markerID() == 1 || Solid_mesh_ptr->point (Solid_exact_solution->blockMap().GID (i) ).markerID() == 20 )
171  if (Solid_exact_solution->blockMap().LID (Solid_exact_solution->blockMap().GID (i) ) != -1)
172  {
173  (*Solid_exact_solution) [Solid_exact_solution->blockMap().GID (i)] = f ( Solid_mesh_ptr->point (Solid_exact_solution->blockMap().GID (i) ).x(),
174  Solid_mesh_ptr->point (Solid_exact_solution->blockMap().GID (i) ).y(),
175  Solid_mesh_ptr->point (Solid_exact_solution->blockMap().GID (i) ).z() );
176 
177  (*myError) [myError->blockMap().GID (i)] = (*Solid_exact_solution) [Solid_exact_solution->blockMap().GID (i)] - (*Solid_solution) [Solid_solution->blockMap().GID (i)];
178  }
179 
180  // EXPORTING THE SOLUTION
181  ExporterHDF5<mesh_Type> Solid_exporter (dataFile, Solid_localMesh, "Results", Comm->MyPID() );
182  Solid_exporter.setMeshProcId (Solid_localMesh, Comm->MyPID() );
183  Solid_exporter.exportPID (Solid_localMesh, Comm, true );
184  Solid_exporter.addVariable (ExporterData<mesh_Type>::ScalarField, "Solution", Solid_fieldFESpace, Solid_solution, UInt (0) );
185  Solid_exporter.postProcess (0);
186  Solid_exporter.closeFile();
187 
188  Real err_inf = myError->normInf();
189 
190 #ifdef HAVE_MPI
191  MPI_Finalize();
192 #endif
193 
194  if ( std::abs(err_inf) < 1.0e-1 )
195  {
196  return ( EXIT_SUCCESS );
197  }
198  else
199  {
200  return ( EXIT_FAILURE );
201  }
202 }
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
double f(double x, double y, double z)
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
int main(int argc, char **argv)