00001
00010 #ifndef _GRIDS_BASSO_H_
00011 #define _GRIDS_BASSO_H_
00012
00013
00014 #include <iostream>
00015 #include <set>
00016 #include <list>
00017
00018
00019
00020
00021 #include "basso.h"
00022 #include "geometry.h"
00023 #include "Node.h"
00024 #include "Element.h"
00025
00026
00027 namespace basso {
00028
00033 template< class ElEmEnTlIsT >
00034 void add_nodeids( const ElEmEnTlIsT &conn, set<int> &nid_set )
00035 {
00036 typename ElEmEnTlIsT::const_iterator eItr;
00037 for ( eItr=conn.begin(); eItr!=conn.end(); ++eItr )
00038 for ( int j=0; j<eItr->NumNodes(); ++j )
00039 nid_set.insert( (*eItr)[j] );
00040 }
00041
00043 template< class CONNMAT >
00044 void print_grid_connectivity( const CONNMAT &conn, std::ostream &out=StdOutput )
00045 {
00046 out << "\ngrid connectivity (" << vect_size(conn) << " elements)\n";
00047 for ( int i=0; i<vect_size(conn); ++i )
00048 out << i << " : " << conn[i] << "\n";
00049 }
00050
00052 template< class COORDMAT >
00053 void print_grid_coordinates( const COORDMAT &coord, std::ostream &out=StdOutput )
00054 {
00055 out << "\ngrid node coordinates (" << vect_size(coord) << " nodes)\n";
00056 for ( int i=0; i<vect_size(coord); ++i )
00057 out << i << " : " << coord[i] << "\n";
00058 }
00059
00077 class GridRectTria3 {
00078
00079 public:
00080
00081
00082
00083
00084 GridRectTria3( const Point &p1, const Point &p2, Numeric h );
00085
00086 virtual ~GridRectTria3() { }
00087
00088
00089
00090
00091
00093 int NumNodes() const { return nx*ny; }
00094
00096 void NodeCoordinates( Array<Node> &coord ) const;
00097
00099 void NodeCoordinates( nMatrix &coord ) const;
00100
00102 int NumElements() const { return 2*(nx-1)*(ny-1); }
00103
00105 void ElementConnectivity( list< Element > &conn ) const;
00106
00108 void RightEdge( list< Element > &conn ) const;
00109
00113 void RightEdge( set<int> &nid_set ) const
00114 {
00115 list< Element > conn;
00116 RightEdge(conn);
00117 add_nodeids( conn, nid_set );
00118 }
00119
00121 void TopEdge( list< Element > &conn ) const;
00122
00126 void TopEdge( set<int> &nid_set ) const
00127 {
00128 list< Element > conn;
00129 TopEdge(conn);
00130 add_nodeids( conn, nid_set );
00131 }
00132
00134 void LeftEdge( list< Element > &conn ) const;
00135
00139 void LeftEdge( set<int> &nid_set ) const
00140 {
00141 list< Element > conn;
00142 LeftEdge(conn);
00143 add_nodeids( conn, nid_set );
00144 }
00145
00147 void BottomEdge( list< Element > &conn ) const;
00148
00152 void BottomEdge( set<int> &nid_set ) const
00153 {
00154 list< Element > conn;
00155 BottomEdge(conn);
00156 add_nodeids( conn, nid_set );
00157 }
00158
00159 private:
00160 Numeric length, width, x0, y0;
00161 int nx, ny;
00162
00163 };
00164
00165 GridRectTria3::GridRectTria3( const Point &p1, const Point &p2, Numeric h )
00166 {
00167 x0=p1.x(); y0=p1.y();
00168 length=p2.x()-p1.x(); width=p2.y()-p1.y();
00169 nx=static_cast<int>(ceil(length/h))+1;
00170 ny=static_cast<int>(ceil(width/h))+1;
00171 }
00172
00173 void GridRectTria3::NodeCoordinates( Array<Node> &coord ) const
00174 {
00175 if ( coord.size() != NumNodes() )
00176 resize( coord, NumNodes() );
00177
00178 Numeric hx=length/static_cast<Numeric>(nx-1);
00179 Numeric hy=width/static_cast<Numeric>(ny-1);
00180 Numeric x, y=y0;
00181 int n=0;
00182 for ( int j=0; j<ny; ++j, y+=hy ) {
00183 x=x0;
00184 for ( int i=0; i<nx; ++i, x+=hx, ++n )
00185 coord[n] = Node(n,x,y);
00186 }
00187 }
00188
00189 void GridRectTria3::NodeCoordinates( nMatrix &coord ) const
00190 {
00191 if ( mat_nrows(coord) != NumNodes() || mat_ncols(coord) >= 2 )
00192 resize( coord, NumNodes(), 2 );
00193
00194 Numeric hx=length/static_cast<Numeric>(nx-1);
00195 Numeric hy=width/static_cast<Numeric>(ny-1);
00196 Numeric x, y=y0;
00197 int n=0;
00198 for ( int j=0; j<ny; ++j, y+=hy ) {
00199 x=x0;
00200 for ( int i=0; i<nx; ++i, x+=hx, ++n )
00201 coord(n,0) = x; coord(n,1) = y;
00202 }
00203 }
00204
00205 void GridRectTria3::ElementConnectivity( list< Element > &conn ) const
00206 {
00207 iArray econn(3);
00208 int e=0, ei=0;
00209 for ( int j=0; j<ny-1; ++j, ++ei ) {
00210 for ( int i=0; i<nx-1; ++i, ++ei ) {
00211 econn[0]=ei; econn[1]=ei+1; econn[2]=ei+nx;
00212 conn.push_back( Element(e,0,kTRIA3,econn) );
00213 ++e;
00214 econn[0]=ei+nx+1; econn[1]=ei+nx; econn[2]=ei+1;
00215 conn.push_back( Element(e,0,kTRIA3,econn) );
00216 ++e;
00217 }
00218 }
00219 }
00220
00221 void GridRectTria3::RightEdge( list< Element > &conn ) const
00222 {
00223 int ei=nx-1;
00224 iArray econn(2);
00225 for ( int e=0; e<ny-1; ++e, ei+=nx ) {
00226 econn[0]=ei; econn[1]=ei+nx;
00227 conn.push_back( Element(e,1,kLINE2,econn) );
00228 }
00229 }
00230
00231 void GridRectTria3::TopEdge( list< Element > &conn ) const
00232 {
00233 int ei=nx*(ny-1);
00234 iArray econn(2);
00235 for ( int e=0; e<nx-1; ++e, ++ei ) {
00236 econn[0]=ei+1; econn[1]=ei;
00237 conn.push_back( Element(e,2,kLINE2,econn) );
00238 }
00239 }
00240
00241 void GridRectTria3::LeftEdge( list< Element > &conn ) const
00242 {
00243 int ei=0;
00244 iArray econn(2);
00245 for ( int e=0; e<ny-1; ++e, ei+=nx ) {
00246 econn[0]=ei+nx; econn[1]=ei;
00247 conn.push_back( Element(e,3,kLINE2,econn) );
00248 }
00249 }
00250
00251 void GridRectTria3::BottomEdge( list< Element > &conn ) const
00252 {
00253 int ei=0;
00254 iArray econn(2);
00255 for ( int e=0; e<nx-1; ++e, ++ei ) {
00256 econn[0]=ei; econn[1]=ei+1;
00257 conn.push_back( Element(e,4,kLINE2,econn) );
00258 }
00259 }
00260
00261
00262
00263 }
00264
00265 #endif
00266
00267