00001 #include "stochdrivert.h"
00002 #include "matrix.h"
00003 #include "vector.h"
00004 #include "globalt.h"
00005 #include "isotrmat.h"
00006 #include "crsection1d.h"
00007 #include "crsection2d.h"
00008 #include "crsection3d.h"
00009
00010
00011
00012 stochdrivert::stochdrivert (void)
00013 {
00014 nsmt=0; nscs=0;
00015 nsampl=0; nstochvar=0; nprunknowns=0;
00016 mt=NULL; idm=NULL; atm=NULL;
00017 cst=NULL; idcs=NULL; atcs=NULL;
00018
00019 nna=NULL; pnv=NULL;
00020 }
00021
00022
00023
00024 stochdrivert::~stochdrivert (void)
00025 {
00026 delete [] mt; delete [] idm; delete [] atm;
00027 delete [] cst; delete [] idcs; delete [] atcs;
00028 delete [] nna; delete [] pnv;
00029 }
00030
00031
00032
00033
00034
00035
00036 void stochdrivert::read (XFILE *in)
00037 {
00038 long i;
00039 XFILE *datin;
00040
00041 xfscanf(in, " %a", auxfile);
00042 datin = xfopen (auxfile,"r");
00043
00044
00045 xfscanf (in,"%ld",&nsmt);
00046 if (Mesprt==1) fprintf (stdout,"\n number of stochastic materials %ld",nsmt);
00047 if (nsmt>0){
00048 mt = new mattypet [nsmt];
00049 idm = new long [nsmt];
00050 atm = new atsel [nsmt];
00051 for (i=0;i<nsmt;i++){
00052 xfscanf (in,"%d %ld",(int*)mt+i,idm+i);
00053 idm[i]--;
00054 atm[i].read(in);
00055 }
00056 }
00057
00058
00059 xfscanf (in,"%ld",&nscs);
00060 if (Mesprt==1) fprintf (stdout,"\n number of stochastic cross sections %ld",nscs);
00061 if (nscs>0){
00062 cst = new crsectypet [nscs];
00063 idcs = new long [nscs];
00064 atcs = new atsel [nscs];
00065 for (i=0;i<nscs;i++){
00066 xfscanf (in,"%d %ld",(int*)cst+i,idcs+i);
00067 idcs[i]--;
00068 atcs[i].read(in);
00069 }
00070 }
00071
00072
00073 xfscanf (in,"%ld",&npnv);
00074 if (Mesprt==1) fprintf (stdout,"\n number of printed nodal values %ld",npnv);
00075 if (npnv>0){
00076 nna = new long [npnv];
00077 pnv = new atsel [npnv];
00078 for (i=0;i<npnv;i++){
00079 xfscanf (in,"%ld",nna+i);
00080 nna[i]--;
00081 pnv[i].read (in);
00082 }
00083 }
00084
00085 readtable (datin);
00086
00087 compute_nprunknowns ();
00088
00089 xfclose (datin);
00090 }
00091
00092
00093
00094 void stochdrivert::compute_nprunknowns ()
00095 {
00096 long i;
00097
00098 nprunknowns=0;
00099 for (i=0;i<npnv;i++){
00100 nprunknowns+=pnv[i].num;
00101 }
00102
00103 allocm (nsampl,nprunknowns,stochtabout);
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 void stochdrivert::readtable (XFILE *in)
00116 {
00117 xfscanf (in,"%ld %ld",&nsampl,&nstochvar);
00118 allocm (nsampl,nstochvar,stochtabin);
00119 readm(in, stochtabin);
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 void stochdrivert::writetable ()
00132 {
00133 FILE *out;
00134 out = fopen (auxfile,"w");
00135
00136 fprintf (out,"%ld\n",nprunknowns);
00137 printm(stochtabout,out,10,20);
00138
00139 fclose (out);
00140 }
00141
00142
00143
00144
00145
00146
00147
00148
00149 void stochdrivert::changevalues (long sampleid)
00150 {
00151 long i,j,k,l,m;
00152 vector val;
00153
00154 j=0;
00155 for (i=0;i<nsmt;i++){
00156 k=atm[i].num; m=0;
00157 allocv (k,val);
00158 for (l=j;l<j+k;l++){
00159 val[m]=stochtabin[sampleid][l];
00160 m++;
00161 }
00162 j+=k;
00163 changematerials (i,val);
00164 destrv (val);
00165 }
00166
00167 for (i=0;i<nscs;i++){
00168 k=atcs[i].num; m=0;
00169 allocv (k,val);
00170 for (l=j;l<j+k;l++){
00171 val[m]=stochtabin[sampleid][l];
00172 m++;
00173 }
00174 j+=k;
00175 changecrsections (i,val);
00176 destrv (val);
00177 }
00178 }
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 void stochdrivert::importvalues (double *dat)
00196 {
00197 vector val;
00198
00199 allocv (atm[0].num, val);
00200 copyv(dat, val);
00201 changematerials (0,val);
00202 destrv (val);
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225 }
00226
00227
00228
00229 void stochdrivert::changematerials (long id,vector &val)
00230 {
00231 switch (mt[id]){
00232 case isotransmat:{
00233 Tm->itrm[idm[id]].changeparam (atm[id],val);
00234 break;
00235 }
00236 case damisotransmat:{
00237 Tm->damitrm[idm[id]].changeparam (atm[id],val);
00238 break;
00239 }
00240 default:{
00241 print_err("unknown material type is required",__FILE__,__LINE__,__func__);
00242 }
00243 }
00244 }
00245
00246
00247
00248 void stochdrivert::changecrsections (long id,vector &val)
00249 {
00250 switch (cst[id]){
00251 case nocrosssectiont:{
00252 break;
00253 }
00254 case crsec1dt:{
00255 Tc->cs1d[idcs[id]].changeparam (atcs[id],val);
00256 break;
00257 }
00258 case crsec2dt:{
00259 Tc->cs2d[idcs[id]].changeparam (atcs[id],val);
00260 break;
00261 }
00262 case crsec3dt:{
00263 Tc->cs3d[idcs[id]].changeparam (atcs[id],val);
00264 break;
00265 }
00266 default:{
00267 print_err("unknown material type is required",__FILE__,__LINE__,__func__);
00268 }
00269 }
00270 }
00271
00272
00273
00274 void stochdrivert::extractor (long sampleid)
00275 {
00276 long i,j,k,ci,nid;
00277
00278 ci=0;
00279 for (i=0;i<npnv;i++){
00280 nid=nna[i];
00281 for (j=0;j<pnv[i].num;j++){
00282 k=Tt->give_dof (nid,pnv[i].atrib[j])-1;
00283 if (k<0){
00284 print_err("wrong number of DOF in function extractor",__FILE__,__LINE__,__func__);
00285 }
00286 stochtabout[sampleid][ci]=Lsrst->lhs[k];
00287 ci++;
00288 }
00289 }
00290 }
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306 void stochdrivert::exportvalues (double *val)
00307 {
00308 long i,j,k,ci,nid;
00309
00310 ci=0;
00311 for (i=0;i<npnv;i++){
00312 nid=nna[i];
00313 for (j=0;j<pnv[i].num;j++){
00314 k=Tt->give_dof (nid,pnv[i].atrib[j])-1;
00315 if (k<0){
00316 print_err("Wrong number of DOF", __FILE__, __LINE__, __func__);
00317 }
00318 val[ci]=Lsrst->lhs[k];
00319 ci++;
00320 }
00321 }
00322 }