00001 #include <string.h>
00002 #include "gnode.h"
00003 #include "gtopology.h"
00004
00005
00006
00007 gnode::gnode (void)
00008 {
00009
00010 ndofn=0;
00011
00012 cn=NULL;
00013
00014 x=0.0; y=0.0; z=0.0;
00015
00016
00017
00018 ai=-1;
00019
00020
00021 tgf=NULL;
00022
00023
00024 mnodes = NULL;
00025
00026 natcoord = NULL;
00027
00028 masentity = noel;
00029 }
00030
00031
00032
00033 gnode::~gnode (void)
00034 {
00035
00036 delete [] cn;
00037
00038 delete [] tgf;
00039
00040 delete [] mnodes;
00041
00042 delete [] natcoord;
00043 }
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 void gnode::read (XFILE *in)
00055 {
00056 long i;
00057
00058 xfscanf (in,"%lf %lf %lf",&x,&y,&z);
00059
00060
00061 xfscanf (in,"%ld",&ndofn);
00062 if (ndofn>0){
00063
00064
00065 cn = new long [ndofn];
00066 for (i=0;i<ndofn;i++){
00067 cn[i]=1;
00068 }
00069 }
00070 if (ndofn<0){
00071
00072
00073 mnodes = new long [0-ndofn];
00074
00075 for (i=0;i<0-ndofn;i++){
00076 xfscanf (in,"%ld",mnodes+i);
00077 mnodes[i]--;
00078 }
00079 natcoord = new double [3];
00080
00081 xfscanf (in,"%le %le %le",natcoord+0,natcoord+1,natcoord+2);
00082
00083 xfscanf (in,"%ld",&masentity);
00084 }
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 void gnode::print (FILE *out)
00097 {
00098 long i;
00099
00100 fprintf (out," %lf %lf %lf ",x,y,z);
00101
00102
00103 fprintf (out," %ld ",ndofn);
00104 if (ndofn<0){
00105 for (i=0;i<0-ndofn;i++){
00106 fprintf (out," %ld ",mnodes[i]+1);
00107 }
00108
00109 fprintf (out," %le %le %le ",natcoord[0],natcoord[1],natcoord[2]);
00110
00111 fprintf (out," %d ",masentity);
00112 }
00113 }
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127 void gnode::constr (long dofcontr,XFILE *in)
00128 {
00129 long i;
00130
00131 if (ndofn < 0)
00132 print_err("Hanging node cannot be constrained", __FILE__, __LINE__, __func__);
00133
00134
00135 if (dofcontr==0){
00136 for (i=0;i<ndofn;i++){
00137 xfscanf (in,"%ld",cn+i);
00138 }
00139 }
00140
00141
00142 if (dofcontr==1){
00143 tgf = new long [ndofn];
00144 for (i=0;i<ndofn;i++){
00145 xfscanf (in,"%ld",tgf+i);
00146 tgf[i]--;
00147 }
00148 }
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 void gnode::print_constr (long dofcontr,FILE *out)
00161 {
00162 long i;
00163
00164 if (ndofn < 0)
00165 print_err("Hanging node cannot be constrained", __FILE__, __LINE__, __func__);
00166
00167
00168 if (dofcontr==0){
00169 for (i=0;i<ndofn;i++){
00170 if(cn[i] > 0)
00171 fprintf (out," 1 ");
00172 else
00173 fprintf (out," %ld ",cn[i]);
00174 }
00175 }
00176
00177
00178 if (dofcontr==1){
00179 for (i=0;i<ndofn;i++){
00180 fprintf (out,"%ld",tgf[i]+1);
00181 }
00182 }
00183 }
00184
00185
00186
00187
00188
00189
00190
00191
00192 long gnode::give_ndofn ()
00193 {
00194 return ndofn;
00195 }
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 long gnode::give_dof (long m)
00207 {
00208 if (m>=ndofn || m<0){
00209 print_err("wrong number of component is required,\n %ld-th dof is out of interval <%ld;%ld>",
00210 __FILE__,__LINE__,__func__, m+1, 1, ndofn);
00211 }
00212 return cn[m];
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 void gnode::save_dof (long m,long num)
00226 {
00227 if (m>=ndofn || m<0){
00228 print_err("wrong number of component is required,\n %ld-th dof is out of interval <%ld;%ld>",
00229 __FILE__,__LINE__,__func__, m+1, 1, ndofn);
00230 }
00231 cn[m]=num;
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 void gnode::clear_dof ()
00243 {
00244 if (ndofn > 0)
00245 memset(cn, 0, sizeof(*cn)*ndofn);
00246 }
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258 double gnode::distance2 (long dim,const double *c)
00259 {
00260 if (dim == 1) return ((x-c[0])*(x-c[0]));
00261 else if (dim == 2) return ((x-c[0])*(x-c[0]) + (y-c[1])*(y-c[1]));
00262 else if (dim == 3) return ((x-c[0])*(x-c[0]) + (y-c[1])*(y-c[1]) + (z-c[2])*(z-c[2]));
00263 else { print_err("Wrong dimension",__FILE__,__LINE__,__func__); return (-1); }
00264 return 0;
00265 }
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 void gnode::update_dofs (gfunct *gf,double time, long lnso)
00280 {
00281 long i,j,k;
00282
00283 for (i=0;i<ndofn;i++){
00284
00285 j=tgf[i];
00286 if (j < 0)
00287 {
00288 cn[i] = lnso;
00289 }
00290 else
00291 {
00292
00293 k=gf[j].getval_long (time);
00294 cn[i]=k;
00295 }
00296 }
00297 }
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 long gnode::search_changed_dofs (gfunct *gf,double time,double prev_time, long lnso, long plnso)
00314 {
00315 long i,j,k,l,nch;
00316
00317
00318 nch=0;
00319
00320 if (time>prev_time){
00321 for (i=0;i<ndofn;i++){
00322
00323 j=tgf[i];
00324
00325 if (j < 0)
00326 {
00327 if (plnso != lnso)
00328 nch++;
00329 }
00330 else
00331 {
00332
00333 k=gf[j].getval_long (time);
00334
00335 l=gf[j].getval_long (prev_time);
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345 if (k == l)
00346 continue;
00347
00348
00349 nch++;
00350 }
00351 }
00352 }
00353 else{
00354
00355
00356 for (i=0;i<ndofn;i++){
00357
00358 j=tgf[i];
00359 if (j < 0)
00360 {
00361 if (plnso != lnso)
00362 nch++;
00363 }
00364 else
00365 {
00366
00367 k=gf[j].getval_long (time);
00368
00369 cn[i]=k;
00370 nch++;
00371 }
00372 }
00373 }
00374
00375 return nch;
00376 }