00001 #include "loadel.h"
00002 #include "global.h"
00003 #include "globmat.h"
00004 #include "matrix.h"
00005 #include "intools.h"
00006 #include "elemhead.h"
00007 #include "elemswitch.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016 loadel::loadel()
00017 {
00018
00019 eid = 0L;
00020
00021 ndofe = 0L;
00022
00023 tel = elloadtype(0);
00024
00025 ned = 0;
00026
00027 nned = 0;
00028
00029 nsurf = 0;
00030
00031 nnsurf = 0;
00032
00033 napfun = 0L;
00034
00035 nnve = 0;
00036
00037 nnvs = 0;
00038
00039 nnvv = 0L;
00040
00041 nlc = 0L;
00042
00043 nslc = 0L;
00044
00045
00046 nodvale = NULL;
00047
00048 nodvals = NULL;
00049
00050 nodvalv = NULL;
00051
00052 le = NULL;
00053
00054 ls = NULL;
00055 }
00056
00057
00058
00059
00060
00061
00062
00063
00064 loadel::~loadel()
00065 {
00066 delete [] nodvale;
00067 delete [] nodvals;
00068 delete [] nodvalv;
00069 delete [] le;
00070 delete [] ls;
00071 }
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 long loadel::read (XFILE *in)
00087 {
00088
00089 xfscanf(in,"%ld",&eid);
00090 if (eid<1)
00091 print_err("nonpositive number of loaded element", __FILE__, __LINE__, __func__);
00092 if (eid>Mt->ne)
00093 print_err("number of loaded element (%ld) > total number of elements (%ld)", __FILE__, __LINE__, __func__, eid, Mt->ne);
00094 eid--;
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 xfscanf (in, "%m", &elloadtype_kwdset, (int*)&tel);
00105
00106 switch (tel){
00107 case edge:
00108 readedgeload (in);
00109 edgeload ();
00110 break;
00111 case surface:
00112 readsurfaceload (in);
00113 surfaceload ();
00114 break;
00115 case volume:
00116 readvolumeload (in);
00117 volumeload ();
00118 break;
00119 case edge_surface:
00120 readedgeload (in);
00121 edgeload ();
00122 readsurfaceload (in);
00123 surfaceload ();
00124 break;
00125 case edge_volume:
00126 readedgeload (in);
00127 edgeload ();
00128 readvolumeload (in);
00129 volumeload ();
00130 break;
00131 case surface_volume:
00132 readsurfaceload (in);
00133 surfaceload ();
00134 readvolumeload (in);
00135 volumeload ();
00136 break;
00137 case edge_surface_volume:
00138 readedgeload (in);
00139 edgeload ();
00140 readsurfaceload (in);
00141 surfaceload ();
00142 readvolumeload (in);
00143 volumeload ();
00144 break;
00145 default:
00146 print_err("unknown type of element load is required", __FILE__, __LINE__, __func__);
00147 }
00148 return(0);
00149 }
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 void loadel::readvolumeload (XFILE *in)
00164 {
00165 long i;
00166
00167 ndofe=Mt->give_ndofe (eid);
00168 nodvalv = new double [ndofe];
00169 nnvv = ndofe;
00170
00171 for (i=0;i<ndofe;i++){
00172 xfscanf (in,"%lf",nodvalv+i);
00173 }
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 void loadel::readedgeload (XFILE *in)
00189 {
00190 long i,j,k,l;
00191
00192
00193 ned=Mt->give_ned (eid);
00194
00195 nned=Mt->give_nned (eid);
00196
00197 napfun=Mt->give_napfun (eid);
00198 nnve = ned*nned*napfun;
00199 nodvale = new double [nnve];
00200 for (i=0;i<nnve;i++){
00201 nodvale[i]=0.0;
00202 }
00203
00204 le = new long [ned];
00205
00206 l=0;
00207 for (i=0;i<ned;i++){
00208 xfscanf (in,"%ld",le+i);
00209 if (le[i]>0){
00210 for (j=0;j<nned;j++){
00211 for (k=0;k<napfun;k++){
00212 xfscanf (in,"%lf",nodvale+l);
00213 l++;
00214 }
00215 }
00216 }
00217 else{ l+=nned*napfun; }
00218 }
00219 }
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233 void loadel::readsurfaceload (XFILE *in)
00234 {
00235 long i,j,k,l;
00236
00237 nsurf=Mt->give_nsurf (eid);
00238 nnsurf=Mt->give_nnsurf (eid);
00239 napfun=Mt->give_napfun (eid);
00240 nnvs = nsurf*nnsurf*napfun;
00241 nodvals = new double [nnvs];
00242 for (i=0;i<nnvs;i++){
00243 nodvals[i]=0.0;
00244 }
00245 ls = new long [nsurf];
00246
00247 l=0;
00248 for (i=0;i<nsurf;i++){
00249 xfscanf (in,"%ld",ls+i);
00250
00251
00252
00253 if (ls[i]==1 || ls[i]==2){
00254 for (j=0;j<nnsurf;j++){
00255 for (k=0;k<napfun;k++){
00256 xfscanf (in,"%lf",nodvals+l);
00257 l++;
00258 }
00259 }
00260 }
00261 else{ l+=nnsurf*napfun; }
00262 }
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 void loadel::volumeload ()
00277 {
00278 long ndofe;
00279 matrix lm;
00280
00281
00282 ndofe = Mt->give_ndofe (eid);
00283 allocm (ndofe,ndofe,lm);
00284 allocv (ndofe,nf);
00285
00286
00287 loadmat (eid,lm);
00288
00289 mxv (lm.a,nodvalv,nf.a,ndofe,ndofe);
00290
00291
00292
00293 destrm (lm);
00294 }
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 void loadel::edgeload ()
00307 {
00308 ndofe=Mt->give_ndofe (eid);
00309 allocv (ndofe,nf);
00310
00311 switch (Mt->give_elem_type (eid)){
00312 case bar2d:{
00313 break;
00314 }
00315 case beam2d:{
00316 Beam2d->nodeforces (eid,le,nodvale,nf);
00317 break;
00318 }
00319 case beam3d:{
00320 Beam3d->nodeforces (eid,le,nodvale,nf);
00321 break;
00322 }
00323 case planeelementlt:{
00324 Pelt->nodeforces (eid,le,nodvale,nf);
00325 break;
00326 }
00327 case planeelementqt:{
00328 Peqt->nodeforces (eid,le,nodvale,nf);
00329 break;
00330 }
00331 case planeelementsubqt:{
00332 Pesqt->nodeforces (eid,le,nodvale,nf);
00333 break;
00334 }
00335 case planeelementlq:{
00336 Pelq->nodeforces (eid,le,nodvale,nf);
00337 break;
00338 }
00339 case planeelementqq:{
00340 Peqq->res_nodeforces (eid,le,nodvale,nf);
00341 break;
00342 }
00343
00344 case axisymmlt:{
00345 Asymlt->edgeload (eid,le,nodvale,nf);
00346 break;
00347 }
00348 case axisymmlq:{
00349 Asymlq->edgeload (eid,le,nodvale,nf);
00350 break;
00351 }
00352 default:{
00353 print_err("unknown element type is required", __FILE__, __LINE__, __func__);
00354 }
00355 }
00356
00357 }
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369 void loadel::surfaceload ()
00370 {
00371 ndofe=Mt->give_ndofe (eid);
00372 allocv (ndofe,nf);
00373
00374 switch (Mt->give_elem_type (eid)){
00375 case dktel:{
00376 Dkt->areaforces(eid, nodvals, nf);
00377 break;
00378 }
00379 case lineartet:{
00380 Ltet->node_forces_surf (0,eid,ls,nodvals,nf);
00381 break;
00382 }
00383 case quadrtet:{
00384 Qtet->node_forces_surf (0,eid,ls,nodvals,nf);
00385 break;
00386 }
00387 case linearhex:{
00388 Lhex->node_forces_surf (0,eid,ls,nodvals,nf);
00389 break;
00390 }
00391 case quadrhex:{
00392 Qhex->node_forces_surf (0,eid,ls,nodvals,nf);
00393 break;
00394 }
00395 default:{
00396 print_err("unknown element type is required", __FILE__, __LINE__, __func__);
00397 }
00398 }
00399 }
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418 long loadel::read_prep(XFILE *in, long lc, long *slc=NULL)
00419 {
00420 long i, j, ncomp;
00421
00422 xfscanf (in, "%k%ld", "lc_id", &nlc);
00423 if ((nlc < 1) || (nlc > lc))
00424 return 1;
00425 if (slc)
00426 {
00427 xfscanf (in, "%k%ld", "slc_id", &nslc);
00428 if ((nslc < 1) || (nslc > slc[nlc-1]))
00429 return 1;
00430 }
00431
00432 xfscanf (in, "%k%m", "load_type", &elloadtype_kwdset, &tel);
00433 switch (tel)
00434 {
00435 case edge:
00436 xfscanf (in, "%k%ld", "nedge", &ned);
00437 xfscanf (in, "%k%ld", "ncomp", &ncomp);
00438 nnve = ncomp*ned;
00439 le = new long[ned];
00440 memset(le, 0, sizeof(*le)*ned);
00441 nodvale = new double [nnve];
00442 memset(nodvale, 0, sizeof(*nodvale)*nnve);
00443 for(i=0; i<ned; i++)
00444 {
00445 xfscanf (in,"%k%ld","coord_sys", le+i);
00446 if ((le[i] > -1) && (le[i] < 2))
00447 {
00448 if (le[i])
00449 {
00450 xfscanf(in, "%k", "load_comp");
00451 for(j=0; j<ncomp; j++)
00452 xfscanf(in, "%le", nodvale+i*ncomp+j);
00453 }
00454 }
00455 else
00456 return 3;
00457 }
00458 break;
00459 case surface:
00460 xfscanf (in, "%k%ld", "nsurf", &nsurf);
00461 xfscanf (in, "%k%ld", "ncomp", &ncomp);
00462 nnvs = ncomp*nsurf;
00463 ls = new long[nsurf];
00464 memset(ls, 0, sizeof(*ls)*nsurf);
00465 nodvals = new double [nnvs];
00466 memset(nodvals, 0, sizeof(*nodvals)*nnvs);
00467 for(i=0; i<nsurf; i++)
00468 {
00469 xfscanf (in,"%k%ld","coord_sys", ls+i);
00470 if ((ls[i] > -1) && (ls[i] < 3))
00471 {
00472 if (ls[i])
00473 {
00474 xfscanf(in, "%k", "load_comp");
00475 for(j=0; j<ncomp; j++)
00476 xfscanf(in, "%le", nodvals+i*ncomp+j);
00477 }
00478 }
00479 else
00480 return 3;
00481 }
00482 break;
00483 case volume:
00484 xfscanf (in, "%k%ld", "ncomp", &ncomp);
00485 nnvv = ncomp;
00486 nodvalv = new double [nnvv];
00487 memset(nodvalv, 0, sizeof(*nodvalv)*nnvv);
00488 xfscanf(in, "%k", "load_comp");
00489 for(i=0; i<nnvv; i++)
00490 xfscanf(in, "%le", nodvalv+i);
00491 break;
00492 default:
00493 return 2;
00494 }
00495 return(0);
00496 }
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512 long loadel::print(FILE *out, int ident=0)
00513 {
00514 long i, j, k, nnv1;
00515
00516
00517 fprintf (out, " %d", tel);
00518 if (nodvale)
00519 {
00520 nnv1 = nnve/ned;
00521 k = 0;
00522 fprintf(out, " ");
00523 for(i=0; i<ned; i++)
00524 {
00525 fprintf(out, "%ld", le[i]);
00526 if (le[i])
00527 {
00528 for (j=0; j<nnv1; j++)
00529 {
00530 fprintf(out, " % le", nodvale[k]);
00531 k++;
00532 }
00533 }
00534 else
00535 k += nnv1;
00536 if (i == ned-1)
00537 fprintf(out, "\n");
00538 else
00539 fprintf(out, "\n%*c", ident+3,' ');
00540 }
00541 }
00542 if (nodvals)
00543 {
00544 nnv1 = nnvs/nsurf;
00545 k = 0;
00546 fprintf(out, " ");
00547 for(i=0; i<nsurf; i++)
00548 {
00549 if (nodvale && (i == 0))
00550 fprintf(out, "%*c", ident+2, ' ');
00551
00552 fprintf(out, "%ld", ls[i]);
00553 if (ls[i])
00554 {
00555 for (j=0; j<nnv1; j++)
00556 {
00557 fprintf(out, " % le", nodvals[k]);
00558 k++;
00559 }
00560 }
00561 else
00562 k += nnv1;
00563 if (i == nsurf-1)
00564 fprintf(out, "\n");
00565 else
00566 fprintf(out, "\n%*c", ident+3, ' ');
00567 }
00568 }
00569 if (nodvalv)
00570 {
00571 if (nodvale || nodvals)
00572 fprintf(out, "%*c", ident+2, ' ');
00573 for (i=0; i<nnvv; i++)
00574 fprintf(out, " % le", nodvalv[i]);
00575 fprintf(out, "\n");
00576 }
00577 return(0);
00578 }
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593 long loadel::merge(loadel &lel)
00594 {
00595 long i;
00596 if (lel.nodvale)
00597 {
00598 if (nodvale == NULL)
00599 {
00600 ned = lel.ned;
00601 nnve = lel.nnve;
00602 le = new long[ned];
00603 memset(le, 0, sizeof(*le)*ned);
00604 nodvale = new double [nnve];
00605 memset(nodvale, 0, sizeof(*nodvale)*nnve);
00606 for (i=0; i<ned; i++)
00607 le[i] = lel.le[i];
00608 for (i=0; i<nnve; i++)
00609 nodvale[i] = lel.nodvale[i];
00610 }
00611 else
00612 {
00613
00614 if ((ned != lel.ned) || (nnve != lel.nnve))
00615 return 1;
00616
00617 for (i=0; i<ned; i++)
00618 {
00619 if (lel.le[i])
00620 {
00621 if ((le[i]) && (le[i] != lel.le[i]))
00622 return 2;
00623 else
00624 le[i] = lel.le[i];
00625 }
00626 }
00627 for (i=0; i<nnve; i++)
00628 nodvale[i] += lel.nodvale[i];
00629 }
00630 }
00631
00632 if (lel.nodvals)
00633 {
00634 if (nodvals == NULL)
00635 {
00636 nsurf = lel.nsurf;
00637 nnvs = lel.nnvs;
00638 ls = new long[nsurf];
00639 memset(ls, 0, sizeof(*ls)*nsurf);
00640 nodvals = new double [nnvs];
00641 memset(nodvals, 0, sizeof(*nodvals)*nnvs);
00642 for (i=0; i<nsurf; i++)
00643 ls[i] = lel.ls[i];
00644 for (i=0; i<nnvs; i++)
00645 nodvals[i] = lel.nodvals[i];
00646 }
00647 else
00648 {
00649
00650 if ((nsurf != lel.nsurf) || (nnvs != lel.nnvs))
00651 return 1;
00652
00653 for (i=0; i<nsurf; i++)
00654 {
00655 if (lel.ls[i])
00656 {
00657 if ((ls[i]) && (ls[i] != lel.ls[i]))
00658 return 2;
00659 else
00660 ls[i] = lel.ls[i];
00661 }
00662 }
00663 for (i=0; i<nnvs; i++)
00664 nodvals[i] += lel.nodvals[i];
00665 }
00666 }
00667
00668 if (lel.nodvalv)
00669 {
00670 if (nodvalv == NULL)
00671 {
00672 nnvv = lel.nnvv;
00673 nodvalv = new double [nnvv];
00674 memset(nodvalv, 0, sizeof(*nodvalv)*nnvv);
00675 for (i=0; i<nnvv; i++)
00676 nodvalv[i] = lel.nodvalv[i];
00677 }
00678 else
00679 {
00680
00681 if (nnvv != lel.nnvv)
00682 return 1;
00683 for (i=0; i<nnvv; i++)
00684 nodvalv[i] += lel.nodvalv[i];
00685 }
00686 }
00687 set_load_type();
00688 return 0;
00689 }
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699 void loadel::set_load_type()
00700 {
00701 tel = elloadtype(0);
00702 if (nodvale)
00703 {
00704 if (nodvals)
00705 {
00706 if (nodvalv)
00707 tel = edge_surface_volume;
00708 else
00709 tel = edge_surface;
00710 }
00711 else
00712 {
00713 if (nodvalv)
00714 tel = edge_volume;
00715 else
00716 tel = edge;
00717 }
00718 }
00719 else
00720 {
00721 if (nodvals)
00722 {
00723 if (nodvalv)
00724 tel = surface_volume;
00725 else
00726 tel = surface;
00727 }
00728 else
00729 {
00730 if (nodvalv)
00731 tel = volume;
00732 }
00733 }
00734 }