| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Galeri: Finite Element and Matrix Generation Package |
| 4 |
// |
| 5 |
// Copyright 2006 ETHZ/NTESS and the Galeri contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#include "Galeri_ConfigDefs.h" |
| 11 |
#include "Galeri_Exception.h" |
| 12 |
#include "Galeri_FiniteElements.h" |
| 13 |
#ifdef HAVE_MPI |
| 14 |
#include "mpi.h" |
| 15 |
#include "Epetra_MpiComm.h" |
| 16 |
#else |
| 17 |
#include "Epetra_SerialComm.h" |
| 18 |
#endif |
| 19 |
|
| 20 |
using namespace Galeri; |
| 21 |
using namespace Galeri::FiniteElements; |
| 22 |
|
| 23 |
// =========== // |
| 24 |
// main driver // |
| 25 |
// =========== // |
| 26 |
|
| 27 |
int main(int argc, char *argv[]) |
| 28 |
{ |
| 29 |
#ifdef HAVE_MPI |
| 30 |
MPI_Init(&argc,&argv); |
| 31 |
Epetra_MpiComm Comm(MPI_COMM_WORLD); |
| 32 |
#else |
| 33 |
Epetra_SerialComm Comm; |
| 34 |
#endif |
| 35 |
|
| 36 |
try { |
| 37 |
|
| 38 |
// Prepares the computational domain. For simplicity, |
| 39 |
// the computation domain has (nx * NumProcs, ny, nz) elements, |
| 40 |
// and it is partitioned into (NumProcs, 1, 1) subdomains. |
| 41 |
|
| 42 |
int nx = 2 * Comm.NumProc(); |
| 43 |
int ny = 2; |
| 44 |
// int nz = 2; // unused |
| 45 |
int mx = Comm.NumProc(); |
| 46 |
int my = 1; |
| 47 |
// int mz = 1; // unused |
| 48 |
double lx = 1.0 * Comm.NumProc(); |
| 49 |
double ly = 1.0; |
| 50 |
// double lz = 1.0; // unused |
| 51 |
|
| 52 |
// Uncomment one of the following: |
| 53 |
TriangleRectangleGrid Grid(Comm, nx, ny, mx, my, lx, ly); |
| 54 |
//QuadRectangleGrid Grid(Comm, nx, ny, mx, my, lx, ly); |
| 55 |
//TetCubeGrid Grid(Comm, nx, ny, nz, mx, my, mz, lx, ly, lz); |
| 56 |
//HexCubeGrid Grid(Comm, nx, ny, nz, mx, my, mz, lx, ly, lz); |
| 57 |
|
| 58 |
// just work on processor 0, only to reduce the output |
| 59 |
if (!Comm.MyPID()) |
| 60 |
{ |
| 61 |
// Extracts the information from the Grid using AbstractGrid |
| 62 |
// methods. First, some general information. |
| 63 |
|
| 64 |
cout << "Number of dimensions = " << Grid.NumDimensions() << endl; |
| 65 |
cout << "Number of vertices per element = " << Grid.NumVerticesPerElement() << endl; |
| 66 |
cout << "Number of faces per element = " << Grid.NumFacesPerElement() << endl; |
| 67 |
cout << "Number of vertices per face = " << Grid.NumVerticesPerFace() << endl; |
| 68 |
cout << "Element type = " << Grid.ElementType() << endl; |
| 69 |
|
| 70 |
cout << "Number of elements: global = " << Grid.NumGlobalElements(); |
| 71 |
cout << ", on proc 0 = " << Grid.NumMyElements() << endl; |
| 72 |
cout << "Number of vertices: global = " << Grid.NumGlobalVertices(); |
| 73 |
cout << ", on proc 0 = " << Grid.NumMyVertices() << endl; |
| 74 |
cout << "Number of boundary faces: " |
| 75 |
"on proc 0 = " << Grid.NumMyBoundaryFaces() << endl; |
| 76 |
|
| 77 |
// Now loop over all the local elements, and print |
| 78 |
// the local ID of each vertex. |
| 79 |
|
| 80 |
std::vector<double> coord(3); |
| 81 |
std::vector<int> vertices(Grid.NumVerticesPerElement()); |
| 82 |
|
| 83 |
for (int i = 0 ; i < Grid.NumMyElements() ; ++i) |
| 84 |
{ |
| 85 |
cout << "Element " << i << ": "; |
| 86 |
Grid.ElementVertices(i, &vertices[0]); |
| 87 |
for (int j = 0 ; j < Grid.NumVerticesPerElement() ; ++j) |
| 88 |
cout << vertices[j] << " "; |
| 89 |
cout << endl; |
| 90 |
} |
| 91 |
|
| 92 |
// Loop over all local vertices, and print out the coordinates |
| 93 |
|
| 94 |
for (int i = 0 ; i < Grid.NumMyVertices() ; ++i) |
| 95 |
{ |
| 96 |
Grid.VertexCoord(i, &coord[0]); |
| 97 |
cout << "Vertex " << i << ": (" << coord[0]; |
| 98 |
cout << ", " << coord[1] << ", " << coord[2] << ")" << endl; |
| 99 |
} |
| 100 |
|
| 101 |
// Loop over all local boundary faces, and print out the local ID of each |
| 102 |
// vertex belonging to the face |
| 103 |
|
| 104 |
for (int i = 0 ; i < Grid.NumMyBoundaryFaces() ; ++i) |
| 105 |
{ |
| 106 |
cout << "Boundary face " << i << ": "; |
| 107 |
int tag; |
| 108 |
Grid.FaceVertices(i, tag, &vertices[0]); |
| 109 |
for (int j = 0 ; j < Grid.NumVerticesPerFace() ; ++j) |
| 110 |
cout << vertices[j] << " "; |
| 111 |
cout << endl; |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
// The following instructions can be used to visualize with MEDIT |
| 116 |
#if 0 |
| 117 |
MEDITInterface MEDIT(Comm); |
| 118 |
|
| 119 |
// We need to define a vector to plot, in this case constant |
| 120 |
Epetra_Vector Vector(Grid.RowMap()); |
| 121 |
MEDIT.Write(Grid, "grid", Vector); |
| 122 |
#endif |
| 123 |
|
| 124 |
} |
| 125 |
catch (Exception& rhs) |
| 126 |
{ |
| 127 |
if (Comm.MyPID() == 0) |
| 128 |
{ |
| 129 |
cerr << "Caught exception: "; |
| 130 |
rhs.Print(); |
| 131 |
} |
| 132 |
} |
| 133 |
|
| 134 |
#ifdef HAVE_MPI |
| 135 |
MPI_Finalize(); |
| 136 |
#endif |
| 137 |
} |