LifeV
test_neighborsRadius.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  \file test_ghosthandler.cpp
28  \author D. Forti <davide.forti@epfl.ch>
29  \date 2012-28-12
30  */
31 
32 
33 // ===================================================
34 //! Includes
35 // ===================================================
36 
37 #include <lifev/core/LifeV.hpp>
38 #include <lifev/core/array/GhostHandler.hpp>
39 #include <lifev/core/array/VectorEpetra.hpp>
40 #include <lifev/core/mesh/MeshData.hpp>
41 #include <lifev/core/mesh/MeshPartitioner.hpp>
42 #include <lifev/core/filter/GetPot.hpp>
43 
44 #include <lifev/core/filter/Exporter.hpp>
45 #ifdef HAVE_HDF5
46 #include <lifev/core/filter/ExporterHDF5.hpp>
47 #endif
48 
49 using namespace LifeV;
50 
51 int main ( int argc, char* argv[] )
52 {
53 
54  typedef LinearTetra geoElement_Type;
55  typedef RegionMesh < geoElement_Type > mesh_Type;
56  typedef std::shared_ptr < mesh_Type > meshPtr_Type;
57  typedef VectorEpetra vector_Type;
58  typedef std::shared_ptr<vector_Type> vectorPtr_Type;
59 
60  std::shared_ptr<Epetra_Comm> Comm;
61 #ifdef HAVE_MPI
62  MPI_Init (&argc, &argv);
63  Comm.reset (new Epetra_MpiComm (MPI_COMM_WORLD) );
64 #else
65  comm.reset ( new Epetra_SerialComm() );
66 #endif
67 
68  // Loading data
69  GetPot command_line (argc, argv);
70  GetPot dataFile ( command_line.follow ("data_neighborsRadius", 2, "-f", "--file" ) );
71 
72  // Loading mesh
73  MeshData meshData;
74  meshData.setup (dataFile, "space_discretization");
75 
76  meshPtr_Type fullMeshPtr ( new mesh_Type ( Comm ) );
77  readMesh (*fullMeshPtr, meshData);
78 
79  // Mesh partitioning
80  MeshPartitioner<mesh_Type> meshPart;
81  meshPtr_Type localMeshPtr;
82 
83  // Partitioning the mesh with a number of overlapping regions equal to leveloverlap
84  int levelOverlap = 5;
85  meshPart.setPartitionOverlap (levelOverlap);
86  meshPart.doPartition (fullMeshPtr, Comm);
87  localMeshPtr = meshPart.meshPartition();
88 
89  // Creating and setting up a GhostHandler object
90  std::shared_ptr<FESpace<mesh_Type, MapEpetra> > FESpaceP1 (new FESpace<mesh_Type, MapEpetra> (localMeshPtr, "P1", 1, Comm) );
91  GhostHandler<mesh_Type> ghostObj ( fullMeshPtr, localMeshPtr, FESpaceP1->mapPtr(), Comm );
92 
93  // Creating node-node map over the interface
94  std::vector<int> interfaceMarkers (2);
95  interfaceMarkers[0] = 20;
96  interfaceMarkers[1] = 1;
97  ghostObj.createPointPointNeighborsList ( interfaceMarkers );
98 
99  UInt ID_trial = 314;
100  neighbors_Type Neighbors;
101  double radius = 4 * (double) MeshUtility::MeshStatistics::computeSize (*fullMeshPtr).maxH;
102 
103  Neighbors = ghostObj.neighborsWithinRadius ( fullMeshPtr->point (ID_trial).id(), radius );
104  Neighbors.insert (fullMeshPtr->point (ID_trial).id() );
105 
106  // Exporting the solution
107  vectorPtr_Type TrialOutput (new vector_Type (FESpaceP1->map(), Unique) );
108 
109  for (neighbors_Type::iterator ii = Neighbors.begin(); ii != Neighbors.end(); ++ii)
110  if (TrialOutput->blockMap().LID (static_cast<int> (*ii) ) != -1)
111  {
112  if (*ii == ID_trial)
113  {
114  (*TrialOutput) [*ii] = -1;
115  }
116  else
117  {
118  (*TrialOutput) [*ii] = 1;
119  }
120  }
121 
122  ExporterHDF5<mesh_Type> exporter (dataFile, localMeshPtr, "Output_test_neighborsRadius", Comm->MyPID() );
123  exporter.setMeshProcId (localMeshPtr, Comm->MyPID() );
124  exporter.exportPID (localMeshPtr, Comm, true );
125  exporter.addVariable (ExporterData<mesh_Type>::ScalarField, "Neighbors, red color", FESpaceP1, TrialOutput, UInt (0) );
126  exporter.postProcess (0);
127  exporter.closeFile();
128 
129 
130 #ifdef HAVE_MPI
131  MPI_Finalize();
132 #endif
133 
134  return 0;
135 
136 }
VectorEpetra - The Epetra Vector format Wrapper.
GetPot(const int argc_, char **argv_, const char *FieldSeparator=0x0)
Definition: GetPot.hpp:507
std::shared_ptr< std::vector< Int > > M_isOnProc
MeshData - class for handling spatial discretization.
Definition: MeshData.hpp:72
std::unordered_set< ID > neighbors_Type
A Geometric Shape.
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)
void importFromHDF5(std::string const &fileName="ghostmap")
Import neighbor lists to an hdf5 file.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191