LifeV
test_neighborsCircle.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 using namespace std;
51 
52 int main ( int argc, char* argv[] )
53 {
54  std::shared_ptr<Epetra_Comm> Comm;
55 #ifdef HAVE_MPI
56  MPI_Init (&argc, &argv);
57  Comm.reset (new Epetra_MpiComm (MPI_COMM_WORLD) );
58 #else
59  comm.reset ( new Epetra_SerialComm() );
60 #endif
61 
62  GetPot command_line (argc, argv);
63  GetPot dataFile ( command_line.follow ("data_neighborsCircle", 2, "-f", "--file" ) );
64 
65  typedef LinearTriangle geoElement_Type;
66  typedef RegionMesh < geoElement_Type > mesh_Type;
67  typedef std::shared_ptr < mesh_Type > meshPtr_Type;
68  typedef VectorEpetra vector_Type;
69  typedef std::shared_ptr<vector_Type> vectorPtr_Type;
70 
71  MeshData meshData;
72  meshData.setup (dataFile, "space_discretization");
73 
74  meshPtr_Type fullMeshPtr ( new mesh_Type ( Comm ) );
75  readMesh (*fullMeshPtr, meshData);
76 
77  MeshPartitioner<mesh_Type> meshPart;
78  meshPtr_Type localMeshPtr;
79 
80  // Partitioning the mesh with a number of overlapping regions equal to leveloverlap
81  int levelOverlap = 0;
82  meshPart.setPartitionOverlap (levelOverlap);
83  meshPart.doPartition (fullMeshPtr, Comm);
84  localMeshPtr = meshPart.meshPartition();
85 
86  // Creating and setting up a GhostHandler object
87  std::shared_ptr<FESpace<mesh_Type, MapEpetra> > FESpaceP1 (new FESpace<mesh_Type, MapEpetra> (localMeshPtr, "P1", 1, Comm) );
88  GhostHandler<mesh_Type> ghostObj ( fullMeshPtr, localMeshPtr, FESpaceP1->mapPtr(), Comm );
89  ghostObj.setUpNeighbors();
90 
91  // Remark: by calling the setup method, such a class identifies the closest neighbors of grid each node, as it is shown below:
92  //
93  // n6
94  // o ------ o ------ o ------ o ------ o
95  // | | | | | LEGEND: o node
96  // | | | | | --- connectivity between nodes
97  // | | n13 | n2 | n7 |
98  // o ------ o ------ o ------ o ------ o
99  // | | | | |
100  // | | | | |
101  // | n12 | n5 | n1 | n3 | n8
102  // o ------ o ------ o ------ o ------ o
103  // | | | | |
104  // | | | | |
105  // | | n11 | n4 | n9 |
106  // o ------ o ------ o ------ o ------ o
107  // | | | | |
108  // | | | | |
109  // | | | n10 | |
110  // o ------ o ------ o ------ o ------ o
111  //
112  // As an example, concerning node n1, the setUp() will identify as neighbors nodes n2, n3, n4 and n5.
113  // The aim of this test is to extend the possibility of finding all the neighbors which are within
114  // a user-defined number of circles. Regarding the example above, if one chooses as number of circles equal to 1,
115  // we identify as additional neighbors the nodes n6, n7, n8, n9, n10, n11, n12 and n13.
116 
117  UInt ID_trial = 40;
118  neighbors_Type Neighbors;
119  UInt nc = 2;
120 
121  Neighbors = ghostObj.circleNeighbors ( fullMeshPtr->point (ID_trial).id(), nc );
122  Neighbors.insert (fullMeshPtr->point (ID_trial).id() );
123 
124  // createCircleNodeNodeNeighborsMap takes both the number of circles (nc) where to find the neighbors, and the
125  // globalID of the grid node localMeshPtr->point(i).id()() for which we are looking for its neighbors.
126  // As output the method returns a set Neighbors[i] containing the globalID of each neighbor.
127 
128  // EXPORTING THE RESULT FOR ONE NODE (with globalID: ID_trial), IN ORDER TO VISUALIZE THE RESULT WITH PARAVIEW
129  vectorPtr_Type TrialOutput (new vector_Type (FESpaceP1->map(), Unique) );
130 
131  for (neighbors_Type::iterator ii = Neighbors.begin(); ii != Neighbors.end(); ++ii)
132  if (TrialOutput->blockMap().LID (static_cast<int> (*ii) ) != -1)
133  {
134  if (*ii == ID_trial)
135  {
136  (*TrialOutput) [*ii] = -1;
137  }
138  else
139  {
140  (*TrialOutput) [*ii] = 1;
141  }
142  }
143 
144  ExporterHDF5<mesh_Type> exporter (dataFile, localMeshPtr, "Output_test_neighborsCircle", Comm->MyPID() );
145  exporter.setMeshProcId (localMeshPtr, Comm->MyPID() );
146  exporter.exportPID (localMeshPtr, Comm, true );
147  exporter.addVariable (ExporterData<mesh_Type>::ScalarField, "Neighbors, red color", FESpaceP1, TrialOutput, UInt (0) );
148  exporter.postProcess (0);
149  exporter.closeFile();
150 
151 #ifdef HAVE_MPI
152  MPI_Finalize();
153 #endif
154 
155  return 0;
156 
157 }
VectorEpetra - The Epetra Vector format Wrapper.
A Geometric Shape.
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
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