LifeV
RegionMesh1DStructured.hpp
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 Contains methods to generate 1D meshes.
30 
31  @author Antonio Cervone <ant.cervone@gmail.com>
32  @author Alessio Fumagalli <alessio.fumagalli@mail.polimi.it>
33  @contributor Mauro Perego <mperego@fsu.edu>
34  @maintainer -
35 
36  @date 15-10-2012
37  */
38 
39 #ifndef REGIONMESH1DSTRUCTURED_HPP
40 #define REGIONMESH1DSTRUCTURED_HPP 1
41 
42 #include <lifev/core/LifeV.hpp>
43 #include <lifev/core/mesh/RegionMesh.hpp>
44 
45 namespace LifeV
46 {
47 
48 // Labels for the structured 1D mesh
50 {
51 //! Label for the internal entities
53 
54 //! Label for the left boundary corner
55 const markerID_Type LEFT = 1;
56 
57 //! Label for the right boundary corner
58 const markerID_Type RIGHT = 2;
59 } // namespace Structured1DLabel
60 
61 //! Build uniform mesh along the x axis.
62 /*!
63  @tparam mesh Reference to the mesh.
64  @param regionFlag flag for the mesh.
65  @param numberOfElements Number of elements inside the mesh.
66  @param verbose Output verbosity.
67  @param lenght Length of the mesh.
68  @param origin Origin of the mesh.
69 
70  Build 1D uniform mesh along the x axis, extending from origin to origin + length,
71  with numberOfElements elements.
72 */
73 template <typename MeshType>
74 void regularMesh1D ( MeshType& mesh,
75  markerID_Type regionFlag,
76  const UInt& numberOfElements,
77  bool verbose = false,
78  const Real& length = 1.,
79  const Real& origin = 0. )
80 {
81  typedef MeshType mesh_Type;
82 
83  if ( verbose && mesh.comm()->MyPID() == 0 )
84  {
85  std::cout << "Building 1d mesh" << std::endl;
86  }
87 
88  mesh.setMaxNumPoints (numberOfElements + 1, true);
89  mesh.setNumBPoints (2);
90  mesh.setMarkerID (regionFlag);
91 
92  Real deltax = (length - origin) / numberOfElements;
93 
94  typename mesh_Type::point_Type* pp = 0;
95 
96  for (UInt it = 0; it < numberOfElements + 1; it++)
97  {
98  bool isBoundary = (it == numberOfElements) || ( it == 0);
99 
100  // insert a new Point1D in point list
101  pp = &mesh.addPoint ( isBoundary, false );
102  pp->x() = origin + it * deltax;
103  pp->y() = 0.;
104  pp->z() = 0.;
105  pp->setId (it);
106 
107  if ( it == 0 )
108  {
109  pp->firstAdjacentElementIdentity() = 0;
110  pp->firstAdjacentElementPosition() = 0;
111 
112  pp->secondAdjacentElementIdentity() = NotAnId;
113  pp->secondAdjacentElementPosition() = NotAnId;
114 
115  pp->setMarkerID ( Structured1DLabel::LEFT );
116  }
117  else if ( it == numberOfElements )
118  {
119  pp->firstAdjacentElementIdentity() = it - 1;
120  pp->firstAdjacentElementPosition() = 1;
121 
122  pp->secondAdjacentElementIdentity() = NotAnId;
123  pp->secondAdjacentElementPosition() = NotAnId;
124 
125  pp->setMarkerID ( Structured1DLabel::RIGHT );
126  }
127  else
128  {
129  pp->firstAdjacentElementIdentity() = it;
130  pp->firstAdjacentElementPosition() = 0;
131 
132  pp->secondAdjacentElementIdentity() = it - 1;
133  pp->secondAdjacentElementPosition() = 1;
134 
135  pp->setMarkerID ( Structured1DLabel::INTERNAL );
136  }
137 
138 
139  }
140 
141  mesh.setNumGlobalVertices ( mesh.pointList.size() );
142  mesh.setNumVertices (mesh.pointList.size() );
143  mesh.setMaxNumPoints ( mesh.pointList.size(), true );
144  mesh.setMaxNumGlobalPoints ( mesh.pointList.size() );
145  mesh.numBVertices() = 2;
146  mesh.setNumBPoints ( mesh.numBVertices() );
147 
148  mesh.setLinkSwitch ( "FACETS_HAVE_ADIACENCY" );
149  mesh.setLinkSwitch ( "HAS_ALL_FACETS" );
150 
151  mesh.setMaxNumEdges (numberOfElements, true);
152 
153  typename mesh_Type::edge_Type* pe = 0;
154 
155  for (UInt it = 0; it < numberOfElements; it++)
156  {
157  pe = &mesh.addEdge ( false );
158  pe->setPoint (0, mesh.point (it) );
159  pe->setPoint (1, mesh.point (it + 1) );
160  pe->setId (it);
161  pe->setMarkerID ( Structured1DLabel::INTERNAL );
162  }
163  mesh.setNumEdges (mesh.edgeList.size() );
164  mesh.setMaxNumGlobalEdges (mesh.edgeList.size() );
165 
166  mesh.updateElementFacets ( true, false, mesh.pointList.size() );
167 } // regularMesh1D
168 
169 } // Namespace LifeV
170 
171 #endif /* REGIONMESH1DSTRUCTURED_HPP */
const markerID_Type INTERNAL
Label for the internal entities.
const markerID_Type RIGHT
Label for the right boundary corner.
ID markerID_Type
markerID_Type is the type used to store the geometric entity marker IDs
Definition: Marker.hpp:81
void updateInverseJacobian(const UInt &iQuadPt)
double Real
Generic real data.
Definition: LifeV.hpp:175
const ID NotAnId
Definition: LifeV.hpp:264
const markerID_Type LEFT
Label for the left boundary corner.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
void regularMesh1D(MeshType &mesh, markerID_Type regionFlag, const UInt &numberOfElements, bool verbose=false, const Real &length=1., const Real &origin=0.)
Build uniform mesh along the x axis.