00001 #include "graphmat.h"
00002 #include "global.h"
00003 #include "intpoints.h"
00004 #include "tablefunct.h"
00005 #include "matrix.h"
00006 #include "parser.h"
00007
00008
00009
00010
00011
00012
00013
00014
00015 graphmat::graphmat(void)
00016 {
00017 gt = glinear;
00018 numf = 0L;
00019 k = 0.0;
00020 deq = NULL;
00021 eq = NULL;
00022 deq = NULL;
00023 tab = NULL;
00024 }
00025
00026
00027
00028
00029
00030
00031
00032
00033 graphmat::~graphmat(void)
00034 {
00035 for (long i = 0; i < numf; i++)
00036 {
00037 delete deq[i];
00038 delete eq[i];
00039 }
00040 delete [] deq;
00041 delete [] eq;
00042
00043 delete tab;
00044 }
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 long graphmat::read (XFILE *in)
00065 {
00066 long i;
00067 Parser par;
00068 char func[256];
00069
00070 xfscanf(in, "%m", &graphtype_kwdset, (int *)>);
00071 if ((gt < glinear) || (gt > gfunc_ser))
00072 {
00073 print_err("unknown type of graph", __FILE__, __LINE__, __func__);
00074 return(1);
00075 }
00076
00077 switch (gt)
00078 {
00079 case glinear:
00080 {
00081 xfscanf (in,"%lf", &k);
00082 break;
00083 }
00084 case gtable:
00085 {
00086 tab = new tablefunct;
00087 tab->read(in);
00088 break;
00089 }
00090 case gfunc:
00091 {
00092 eq = new Equation* [1];
00093 xfscanf(in, "%255s", func);
00094 eq[0] = par.TextToTree(func);
00095 if (eq[0] == NULL)
00096 {
00097 print_err("parsing expression in function", __FILE__, __LINE__, __func__);
00098 return(2);
00099 }
00100 deq = new Equation* [1];
00101 deq[0] = new Equation;
00102 eq[0]->Differentiate(deq[0], 1, &par);
00103 break;
00104 }
00105 case gfunc_ser:
00106 {
00107 xfscanf(in, "%ld", &numf);
00108 eq = new Equation* [numf];
00109 deq = new Equation* [numf];
00110 limval = new double [numf];
00111 for (i = 0; i < numf; i++)
00112 {
00113 xfscanf(in, "%le", limval+i);
00114 xfscanf(in, "%255s", func);
00115 eq[i] = par.TextToTree(func);
00116 if (eq[i] == NULL)
00117 {
00118 print_err("parsing expression in function", __FILE__, __LINE__, __func__);
00119 return(3);
00120 }
00121 deq[i] = new Equation;
00122 eq[i]->Differentiate(deq[i], 1, &par);
00123 }
00124 break;
00125 }
00126 default:
00127 {
00128 print_err("unknown type of graph is required", __FILE__, __LINE__, __func__);
00129 return (4);
00130 }
00131 }
00132 return(0);
00133 }
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 void graphmat::matstiff (matrix &d, long ipp)
00148 {
00149 long i, id;
00150 double val;
00151
00152 switch (gt)
00153 {
00154 case glinear:
00155 for (i = 0; i < d.m; i++)
00156 d[i][i] = k;
00157 break;
00158 case gtable:
00159 for (i = 0; i < d.m; i++)
00160 {
00161 if (i >= Mm->ip[ipp].ncompstr)
00162 {
00163 d[i][i] = 0.0;
00164 break;
00165 }
00166 d[i][i] = tab->getval2(Mm->ip[ipp].strain[i],k);
00167
00168
00169 }
00170 break;
00171 case gfunc:
00172 for (i = 0; i < d.m; i++)
00173 {
00174 if (i >= Mm->ip[ipp].ncompstr)
00175 {
00176 d[i][i] = 0.0;
00177 break;
00178 }
00179 if (deq[0]->Variables.at(0))
00180 deq[0]->Variables.at(0)->Value = Mm->ip[ipp].strain[i];
00181 d[i][i] = deq[0]->Evaluate();
00182 }
00183 break;
00184 case gfunc_ser:
00185 {
00186 for (i = 0; i < d.m; i++)
00187 {
00188 for (id = 0; id < numf; id++)
00189 {
00190 val = Mm->ip[ipp].strain[i];
00191 if (limval[id] >= val)
00192 {
00193 if (i >= Mm->ip[ipp].ncompstr)
00194 {
00195 d[i][i] = 0.0;
00196 break;
00197 }
00198 if (deq[id]->Variables.at(0))
00199 deq[id]->Variables.at(0)->Value = Mm->ip[ipp].strain[i];
00200 d[i][i] = deq[id]->Evaluate();
00201 break;
00202 }
00203 if (id == numf-1)
00204 {
00205 if (deq[id]->Variables.at(0))
00206 deq[id]->Variables.at(0)->Value = Mm->ip[ipp].strain[i];
00207 d[i][i] = deq[id]->Evaluate();
00208 }
00209 }
00210 }
00211 break;
00212 }
00213 default:
00214 print_err("unknown graph type is required", __FILE__, __LINE__, __func__);
00215 }
00216 return;
00217 }
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232 void graphmat::nlstresses (long ipp)
00233
00234 {
00235 long i, id, nc=Mm->ip[ipp].ncompstr;
00236 double val;
00237
00238 switch (gt)
00239 {
00240 case glinear:
00241 for (i = 0; i < nc; i++)
00242
00243 Mm->ip[ipp].stress[i] = k * Mm->ip[ipp].strain[i];
00244 break;
00245 case gtable:
00246 for (i = 0; i < nc; i++)
00247 {
00248 k = tab->getval2(Mm->ip[ipp].strain[i],val);
00249
00250 Mm->ip[ipp].stress[i] = k * Mm->ip[ipp].strain[i];
00251 }
00252 break;
00253 case gfunc:
00254 for (i = 0; i < nc; i++)
00255 {
00256 if (eq[0]->Variables.at(0))
00257 eq[0]->Variables.at(0)->Value = Mm->ip[ipp].strain[i];
00258 Mm->ip[ipp].stress[i] = eq[0]->Evaluate();
00259 }
00260 break;
00261 case gfunc_ser:
00262 {
00263 for (i = 0; i < nc; i++)
00264 {
00265 for (id = 0; id < numf; id++)
00266 {
00267 if (limval[id] >= Mm->ip[ipp].strain[i])
00268 {
00269 if (eq[id]->Variables.at(0))
00270 eq[id]->Variables.at(0)->Value = Mm->ip[ipp].strain[i];
00271 Mm->ip[ipp].stress[i] = eq[id]->Evaluate();
00272 break;
00273 }
00274 if (id == numf-1)
00275 {
00276 if (eq[id]->Variables.at(0))
00277 eq[id]->Variables.at(0)->Value = Mm->ip[ipp].strain[i];
00278 Mm->ip[ipp].stress[i] = eq[id]->Evaluate();
00279 }
00280 }
00281 }
00282 break;
00283 }
00284 default:
00285 print_err("unknown graph type is required", __FILE__, __LINE__, __func__);
00286 }
00287 }