00001 #include <string.h>
00002 #include "global.h"
00003 #include "intpoints.h"
00004 #include "microM4.h"
00005 #include "microSIM.h"
00006 #include "microfiber.h"
00007
00008 #ifndef FNAMELEN
00009 #define FNAMELEN 1001
00010 #endif
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 intpoints::intpoints ()
00021 {
00022 tm = NULL; idm = NULL;
00023 nm = 0; hmt = 0;
00024 ncompstr=0; ncompother=0; ssst = (strastrestate) 0;
00025 strain = NULL; stress = NULL; other = NULL; eqother = NULL; nonloc = NULL;
00026 }
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 intpoints::~intpoints (void)
00037 {
00038 delete [] tm; delete [] idm;
00039 delete [] strain; delete [] stress;
00040 delete [] other; delete [] eqother;
00041 delete [] nonloc;
00042 }
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 void intpoints::read (XFILE *in)
00059 {
00060 long i, idx, idxt;
00061
00062 xfscanf (in, "%ld", &nm);
00063 tm = new mattype[nm];
00064 idm = new long[nm];
00065 memset (tm, 0, sizeof(*tm)*nm);
00066 memset (idm, 0, sizeof(*idm)*nm);
00067 idx = 0;
00068 idxt = nm-1;
00069 for (i = 0; i < nm; i++)
00070 {
00071 xfscanf(in, "%k%m%k%ld", "mattype", &mattype_kwdset, (int*)(tm+idx), "num_inst", idm+idx);
00072 idm[idx]--;
00073 if (tm[idx] == therisodilat){
00074 tm[idxt] = tm[idx];
00075 idm[idxt] = idm[idx];
00076 hmt ^= 1;
00077 idxt--;
00078 idx--;
00079 }
00080 idx++;
00081 }
00082 }
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 long intpoints::gemid(void)
00094 {
00095 long ret = nm - 1;
00096 if (hmt & 1)
00097 ret--;
00098 if (hmt & 4)
00099 ret--;
00100
00101 return ret;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111 long intpoints::grmid(void)
00112 {
00113 long ret = -1;
00114
00115 if (hmt & 4){
00116 ret=nm-1;
00117 if (hmt & 1)
00118 ret--;
00119 }
00120
00121 return ret;
00122 }
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166 void intpoints::alloc (long nlc,long ipp,long ncompnl)
00167 {
00168 long ncompo = 0,ncompeqo = 0;
00169
00170
00171
00172
00173 ncompeqo = Mm->givencompeqother(ipp, 0);
00174 ncompeqother = ncompeqo;
00175
00176
00177 ncompo = Mm->givencompother(ipp, 0);
00178 ncompother = ncompo;
00179
00180 strain = new double [nlc*ncompstr];
00181 stress = new double [nlc*ncompstr];
00182 memset(strain, 0, sizeof(*strain)*nlc*ncompstr);
00183 memset(stress, 0, sizeof(*stress)*nlc*ncompstr);
00184
00185
00186 if (ncompeqo > 0)
00187 {
00188 eqother = new double[ncompeqo];
00189 memset(eqother, 0, sizeof(*eqother)*ncompeqo);
00190 }
00191 if (ncompo > 0)
00192 {
00193 other = new double[ncompo];
00194 memset(other, 0, sizeof(*other)*ncompo);
00195 }
00196 if (ncompnl > 0)
00197 {
00198 nonloc = new double[ncompnl];
00199 memset(nonloc, 0, sizeof(*nonloc)*ncompnl);
00200 }
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 void intpoints::alloc_strains (long nlc)
00215 {
00216 strain = new double [nlc*ncompstr];
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 void intpoints::alloc_stresses (long nlc)
00231 {
00232 stress = new double [nlc*ncompstr];
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 void intpoints::alloc_other (long ipp)
00245 {
00246
00247
00248 ncompeqother = Mm->givencompeqother(ipp, 0);
00249
00250
00251 ncompother = Mm->givencompother(ipp, 0);
00252
00253 if (ncompeqother > 0){
00254 eqother = new double[ncompeqother];
00255 memset(eqother, 0, sizeof(*eqother)*ncompeqother);
00256 }
00257 if (ncompother > 0){
00258 other = new double[ncompother];
00259 memset(other, 0, sizeof(*other)*ncompother);
00260 }
00261
00262 }
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277 void intpoints::copy(intpoints &ip, long nlc, long ncompnl)
00278 {
00279
00280 nm = ip.nm;
00281
00282
00283 hmt = ip.hmt;
00284
00285
00286 ncompstr = ip.ncompstr;
00287
00288
00289 ncompeqother = ip.ncompeqother;
00290
00291
00292 ncompother = ip.ncompother;
00293
00294
00295 ssst = ip.ssst;
00296
00297
00298 if (tm)
00299 delete [] tm;
00300 tm = new mattype[nm];
00301 memcpy (tm, ip.tm, sizeof(*tm)*nm);
00302
00303
00304 if (idm)
00305 delete [] idm;
00306 idm = new long[nm];
00307 memcpy (tm, ip.tm, sizeof(*idm)*nm);
00308
00309
00310 if (stress)
00311 delete [] stress;
00312 stress = new double[nlc*ncompstr];
00313 memcpy (stress, ip.stress, sizeof(*stress)*ncompstr);
00314
00315
00316 if (strain)
00317 delete [] strain;
00318 strain = new double[nlc*ncompstr];
00319 memcpy (strain, ip.strain, sizeof(*strain)*ncompstr);
00320
00321
00322 if (other)
00323 delete [] other;
00324 if (ip.other)
00325 {
00326 other = new double[ncompother];
00327 memcpy (other, ip.other, sizeof(*other)*ncompother);
00328 }
00329 else
00330 other = NULL;
00331
00332
00333 if (eqother)
00334 delete [] eqother;
00335 if (ip.eqother)
00336 {
00337 eqother = new double[ncompeqother];
00338 memcpy (eqother, ip.eqother, sizeof(*eqother)*ncompeqother);
00339 }
00340 else
00341 eqother = NULL;
00342
00343
00344 if (nonloc)
00345 delete [] nonloc;
00346 if (ip.nonloc)
00347 {
00348 nonloc = new double[ncompnl];
00349 memcpy (nonloc, ip.nonloc, sizeof(*nonloc)*ncompnl);
00350 }
00351 else
00352 nonloc = NULL;
00353 }
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366 void intpoints::clean (long nlc)
00367 {
00368 long i;
00369 for (i=0;i<nlc*ncompstr;i++){
00370 strain[i]=0.0;
00371 stress[i]=0.0;
00372 }
00373 for (i=0;i<ncompeqother;i++){
00374 eqother[i]=0.0;
00375 }
00376 for (i=0;i<ncompother;i++){
00377 other[i]=0.0;
00378 }
00379 }
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392 void intpoints::clean_strains (long nlc)
00393 {
00394 long i;
00395 for (i=0;i<nlc*ncompstr;i++){
00396 strain[i]=0.0;
00397 }
00398 }
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411 void intpoints::clean_stresses (long nlc)
00412 {
00413 long i;
00414 for (i=0;i<nlc*ncompstr;i++){
00415 stress[i]=0.0;
00416 }
00417 }
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428 void intpoints::clean_other ()
00429 {
00430 long i;
00431 for (i=0;i<ncompeqother;i++){
00432 eqother[i]=0.0;
00433 }
00434 for (i=0;i<ncompother;i++){
00435 other[i]=0.0;
00436 }
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453 void intpoints::save_data_txt (FILE *aux,long nlc, sel &selother)
00454 {
00455 long i;
00456 int prec = (int)Mp->hdbcont.prec;
00457
00458 for (i=0;i<nlc*ncompstr;i++)
00459 fprintf (aux,"%.*le\n",prec,strain[i]);
00460
00461 for (i=0;i<nlc*ncompstr;i++)
00462 fprintf (aux,"%.*le\n",prec,stress[i]);
00463
00464 for (i=0;i<ncompeqother;i++)
00465 {
00466 if (selother.presence_id(i))
00467 fprintf (aux,"%.*le\n",prec,eqother[i]);
00468 }
00469 }
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486 void intpoints::restore_data_txt (FILE *aux,long nlc, long ncompo, sel &selother, long *selid)
00487 {
00488 long i, ik, is;
00489 double tmp;
00490
00491 for (i=0;i<nlc*ncompstr;i++)
00492 fscanf (aux,"%le",strain+i);
00493
00494 for (i=0;i<nlc*ncompstr;i++)
00495 fscanf (aux,"%le",stress+i);
00496
00497 for (i=0;i<ncompo;i++)
00498 {
00499 fscanf (aux,"%le",&tmp);
00500 if (selother.presence_id(i,ik))
00501 {
00502 is = selid[ik]+i-selother.id1[ik];
00503 if (is >= ncompeqother)
00504 print_err("invalid index for eqother restoring is required", __FILE__, __LINE__, __func__);
00505 else
00506 eqother[is] = tmp;
00507 }
00508 }
00509 }
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524 void intpoints::save_data_bin (FILE *aux,long nlc, sel &selother)
00525 {
00526 long i;
00527
00528 fwrite (strain, sizeof(*strain),nlc*ncompstr, aux);
00529 fwrite (stress, sizeof(*stress),nlc*ncompstr, aux);
00530 for (i=0;i<ncompeqother;i++)
00531 {
00532 if (selother.presence_id(i))
00533 fwrite (eqother+i, sizeof(*eqother), 1, aux);
00534 }
00535 }
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552 void intpoints::restore_data_bin (FILE *aux,long nlc, long ncompo, sel &selother, long *selid)
00553 {
00554 long i, ik, is;
00555 double tmp;
00556
00557 fread (strain, sizeof(*strain), nlc*ncompstr, aux);
00558 fread (stress, sizeof(*stress), nlc*ncompstr, aux);
00559 for (i=0;i<ncompo;i++)
00560 {
00561 fread (&tmp, sizeof(tmp), 1, aux);
00562 if (selother.presence_id(i,ik))
00563 {
00564 is = selid[ik]+i-selother.id1[ik];
00565 if (is >= ncompeqother)
00566 print_err("invalid index for eqother restoring is required", __FILE__, __LINE__, __func__);
00567 else
00568 eqother[is] = tmp;
00569 }
00570 }
00571 }
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582 long intpoints::give_ncompstr ()
00583 {
00584 if (ssst==planestress || ssst==planestrain)
00585 return 3;
00586 else
00587 return ncompstr;
00588 }