00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <Block2D.h>
00035
00036
00037
00038 Block2D::Block2D(int numx, int numy,
00039 const ID& nodeID,
00040 const Matrix& coorArray,
00041 int numNode)
00042 :
00043 coor(3),
00044 element(numNode) ,
00045 numNodesElement(numNode),
00046 errorFlag(0)
00047 {
00048 this->nx = numx;
00049 this->ny = numy;
00050
00051 if (numNodesElement == 9) {
00052 if (((numx % 2) != 0) || ((numy % 2) != 0)) {
00053 opserr << "ERROR: Block2D::Block2D - numX & numY for nine noded elements must be even\n";
00054 errorFlag = 1;
00055 }
00056 }
00057
00058 if (numNodesElement != 9 && numNodesElement != 4) {
00059 opserr << "ERROR: Block2D::Block2D - numNode must be either 4 or 9\n";
00060 errorFlag = 1;
00061 }
00062
00063 this->setUpXl( nodeID, coorArray );
00064
00065 }
00066
00067
00068
00069 Block2D::~Block2D( )
00070 {
00071
00072 }
00073
00074
00075
00076 void Block2D::setUpXl( const ID &nodeID, const Matrix &coorArray )
00077 {
00078
00079 int i, j;
00080
00081 for ( i=0; i<4; i++ ){
00082 if ( nodeID(i) == -1 ) {
00083 opserr << "Warning : in Block2D, block node "
00084 << i
00085 << " is not defined. No Generation will take place."
00086 << endln;
00087 break;
00088 }
00089 }
00090
00091
00092 for ( i=0; i<3; i++ ) {
00093 for ( j=0; j<9; j++ )
00094 xl[i][j] = coorArray(j,i);
00095 }
00096
00097
00098 if ( nodeID(4) == -1 ) {
00099 for ( i=0; i<3; i++ )
00100 xl[i][4] = 0.5*( xl[i][0] + xl[i][1] );
00101 }
00102
00103 if ( nodeID(5) == -1 ) {
00104 for ( i=0; i<3; i++ )
00105 xl[i][5] = 0.5*( xl[i][1] + xl[i][2] );
00106 }
00107
00108 if ( nodeID(6) == -1 ) {
00109 for ( i=0; i<3; i++ )
00110 xl[i][6] = 0.5*( xl[i][2] + xl[i][3] );
00111 }
00112
00113 if ( nodeID(7) == -1 ) {
00114 for ( i=0; i<3; i++ )
00115 xl[i][7] = 0.5*( xl[i][3] + xl[i][0] );
00116 }
00117
00118 if ( nodeID(8) == -1 ) {
00119 for ( i=0; i<3; i++ )
00120 xl[i][8] = 0.25*( xl[i][0] + xl[i][1] + xl[i][2] + xl[i][3] ) ;
00121 }
00122
00123
00124 return;
00125 }
00126
00127
00128
00129 const Vector&
00130 Block2D::getNodalCoords( int i, int j )
00131 {
00132
00133 double hx = 2.0 / nx;
00134
00135 double hy = 2.0 / ny;
00136
00137 double x = -1.0 + (i*hx);
00138
00139 double y = -1.0 + (j*hy);
00140
00141 coor(0) = x;
00142 coor(1) = y;
00143 coor(2) = 0.0;
00144
00145 this->transformNodalCoordinates( );
00146
00147 return coor;
00148 }
00149
00150
00151
00152 const ID&
00153 Block2D::getElementNodes( int i, int j )
00154 {
00155
00156 if (errorFlag == 1)
00157 return element;
00158
00159 else if (numNodesElement == 4) {
00160 int nenx = nx + 1;
00161 int neny = ny + 1;
00162
00163 int node1, node2, node3, node4;
00164
00165 node1 = i + j*nenx;
00166 node2 = node1 + 1;
00167
00168 node3 = node2 + nenx;
00169 node4 = node1 + nenx;
00170
00171 element(0) = node1;
00172 element(1) = node2;
00173 element(2) = node3;
00174 element(3) = node4;
00175
00176 } else {
00177
00178 int nenx = nx + 1;
00179 int neny = ny + 1;
00180
00181 int node1, node2, node3, node4, node5, node6, node7, node8, node9;
00182
00183 node1 = i*2 + j*2*nenx;
00184 node5 = node1 + 1;
00185 node2 = node1 + 2;
00186
00187 node4 = node1 + 2*nenx;
00188 node7 = node4 + 1;
00189 node3 = node7 + 1;
00190
00191 node8 = node1 + nenx;
00192 node9 = node8 + 1;
00193 node6 = node9 + 1;
00194
00195 element(0) = node1;
00196 element(1) = node2;
00197 element(2) = node3;
00198 element(3) = node4;
00199 element(4) = node5;
00200 element(5) = node6;
00201 element(6) = node7;
00202 element(7) = node8;
00203 element(8) = node9;
00204
00205 }
00206
00207 return element;
00208 }
00209
00210
00211
00212
00213 void Block2D::transformNodalCoordinates( )
00214 {
00215
00216 static double shape[9];
00217
00218 static double natCoor[2];
00219
00220 natCoor[0] = coor(0);
00221 natCoor[1] = coor(1);
00222
00223 coor.Zero( );
00224
00225 this->shape2d( natCoor[0], natCoor[1], shape );
00226
00227 for ( int j=0; j<9; j++ ) {
00228
00229 for ( int dim=0; dim<3; dim++ )
00230 coor(dim) += shape[j]*xl[dim][j];
00231
00232 }
00233
00234 return;
00235
00236 }
00237
00238
00239
00240 void Block2D::shape2d( double x, double y,
00241 double shape[9] )
00242 {
00243 static double Nx[3];
00244 static double Ny[3];
00245
00246 Nx[0] = 0.5 * x * ( x - 1.0 );
00247 Nx[1] = 1.0 - (x*x);
00248 Nx[2] = 0.5 * x * ( x + 1.0 );
00249
00250 Ny[0] = 0.5 * y * ( y - 1.0 );
00251 Ny[1] = 1.0 - (y*y);
00252 Ny[2] = 0.5 * y * ( y + 1.0 );
00253
00254 shape[0] = Nx[0]*Ny[0];
00255 shape[1] = Nx[2]*Ny[0];
00256 shape[2] = Nx[2]*Ny[2];
00257 shape[3] = Nx[0]*Ny[2];
00258
00259 shape[4] = Nx[1]*Ny[0];
00260 shape[5] = Nx[2]*Ny[1];
00261 shape[6] = Nx[1]*Ny[2];
00262 shape[7] = Nx[0]*Ny[1];
00263
00264 shape[8] = Nx[1]*Ny[1];
00265
00266 return;
00267 }