00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef MECHSYS_MODELWRAPPER_H
00023 #define MECHSYS_MODELWRAPPER_H
00024
00025
00026 #include "models/equilibmodel.h"
00027 #include "models/coupled/coupledmodel.h"
00028 #include "models/linearelastic.h"
00029 #include "models/camclay.h"
00030 #include "models/subcam.h"
00031 #include "models/subtij.h"
00032 #include "models/subcamx.h"
00033 #include "models/barcelonax.h"
00034 #include "models/subbar.h"
00035
00036 #ifdef MODELWRAPPER_WITH_VTK
00037 #include "vtkwrap/vtkwin.h"
00038 #include "vtkwrap/structgrid.h"
00039 #include "vtkwrap/sgridisosurf.h"
00040 #include "vtkwrap/colors.h"
00041 #include "vtkwrap/plane.h"
00042 #include "vtkwrap/hedgehog.h"
00043 #include "vtkwrap/sphere.h"
00044 #include "tensors/tensors.h"
00045 #include "tensors/functions.h"
00046 #include "numerical/meshgrid.h"
00047 #endif // MODELWRAPPER_WITH_VTK
00048
00049 class ModelWrapper
00050 {
00051 public:
00052
00053 ModelWrapper(String const & Name, Array<REAL> const & Prms, Array<REAL> const & IniData);
00054
00055
00056 ~ModelWrapper();
00057
00058
00059 void Actualize(Tensor2 const & DSig, REAL const & DPp, Tensor2 & DEps, REAL & DnSr)
00060 { (_cmodel==NULL ? _emodel->Actualize(DSig,DEps) : _cmodel->Actualize(DSig,DPp,DEps,DnSr)); }
00061
00062
00063
00064 String Name() const { return (_cmodel==NULL ? _emodel->Name() : _cmodel->Name()); }
00065 Tensor2 const & Sig () const { return (_cmodel==NULL ? _emodel->Sig () : _cmodel->Sig ()); }
00066 Tensor2 const & Eps () const { return (_cmodel==NULL ? _emodel->Eps () : _cmodel->Eps ()); }
00067 REAL Pp () const { return (_cmodel==NULL ? 0.0 : _cmodel->Pp ()); }
00068
00069 void InternalStateValues (Array<REAL> & IntStateVals ) const
00070 { (_cmodel==NULL ? _emodel->InternalStateValues(IntStateVals ) : _cmodel->InternalStateValues(IntStateVals)); }
00071
00072 void InternalStateNames (Array<String> & IntStateNames) const
00073 { (_cmodel==NULL ? _emodel->InternalStateNames (IntStateNames) : _cmodel->InternalStateNames (IntStateNames)); }
00074
00075 #ifdef MODELWRAPPER_WITH_VTK
00076
00077 void AddInipsqActorsTo (VTKWin & win, int nPts, bool ShowHH, REAL Opac, REAL & p_Max);
00078 void AddIniStateActorsTo(VTKWin & win, int nPts, bool ShowHH, REAL Opac, REAL & p_Max);
00079 #endif // MODELWRAPPER_WITH_VTK
00080
00081 private:
00082
00083 CoupledModel * _cmodel;
00084 EquilibModel * _emodel;
00085 Array<REAL> _prms;
00086
00087 };
00088
00089 #define ALLOCMODELFUNC(NAME,PRMS,INIDATA, PTR) (PTR = new ModelWrapper(NAME,PRMS,INIDATA))
00090 #define USE_COUPLEDMODEL
00091 #include "labtestsim/lts.h"
00092 #include "labtestsim/inputdata.h"
00093
00094
00096
00097
00098 inline ModelWrapper::ModelWrapper(String const & Name, Array<REAL> const & Prms, Array<REAL> const & IniData)
00099 : _cmodel (NULL),
00100 _emodel (NULL),
00101 _prms (Prms)
00102 {
00103
00104 bool is_coupled = false;
00105 if (EquilibModelFactory.find(Name)==EquilibModelFactory.end())
00106 {
00107 if (CoupledModelFactory.find(Name)==CoupledModelFactory.end())
00108 throw new Fatal(_("ModelWrapper::ModelWrapper: Could not find %s model neither inside EquilibModelFactory nor CoupledModelFactory"),(Name.GetSTL().c_str()));
00109 is_coupled = true;
00110 }
00111
00112
00113 if (is_coupled) _cmodel = AllocCoupledModel(Name,Prms,IniData);
00114 else
00115 {
00116
00117 Array<REAL> inidata;
00118 inidata.push_back(IniData[0]);
00119 inidata.push_back(IniData[1]);
00120 inidata.push_back(IniData[2]);
00121 inidata.push_back(IniData[3]);
00122 inidata.push_back(IniData[4]);
00123 _emodel = AllocEquilibModel(Name,Prms,inidata);
00124 }
00125 }
00126
00127 inline ModelWrapper::~ModelWrapper()
00128 {
00129 if (_cmodel!=NULL) delete _cmodel;
00130 if (_emodel!=NULL) delete _emodel;
00131 }
00132
00133 #ifdef MODELWRAPPER_WITH_VTK
00134
00135 inline void ModelWrapper::AddInipsqActorsTo(VTKWin & win, int nPts, bool ShowHH, REAL Opac, REAL & p_Max)
00136 {
00137 using Tensors::Stress_p_q_S_sin3th;
00138 using Tensors::Tensor2;
00139 using Tensors::Norm;
00140 using Tensors::Hid2Sig;
00141 using Tensors::I;
00142
00143
00144 Tensor2 sig_ini = this->Sig();
00145 REAL suc_ini = -this->Pp();
00146 Array<REAL> isv; this->InternalStateValues(isv);
00147
00148 if (this->Name()=="BarcelonaX")
00149 {
00150
00151
00152 REAL k = _prms[6];
00153 REAL z0 = isv[0];
00154 REAL z1 = isv[1];
00155 REAL M = dynamic_cast<BarcelonaX*>(_cmodel)->GetM(Util::ToRad(30.0));
00156 BarcelonaX::IntVars z; z=z0,z1;
00157 Tensor2 sig;
00158 Tensor2 dfdsig;
00159 REAL dfdsuc;
00160
00161 std::cout << "BarcelonaX: z0=" << z0 << ", z1=" << z1 << std::endl;
00162
00163
00164 REAL cp = 1.3;
00165 REAL cs = 1.3;
00166 REAL cq = 1.2;
00167 REAL p0m = dynamic_cast<BarcelonaX*>(_cmodel)->Calc_p0(z1,z0);
00168 REAL qm = M*sqrt((z0/2.0+k*z1)*(p0m-z0/2.0));
00169 REAL pm = p0m;
00170 REAL p_min=-cp*k*z1; p_Max=cp*pm;
00171 REAL s_min=0.0; REAL s_max=cs*z1;
00172 REAL q_min=-cq*qm; REAL q_max=cq*qm;
00173 MeshGrid mg(p_min ,p_Max ,nPts,
00174 s_min ,s_max ,nPts,
00175 q_min ,q_max ,nPts);
00176 int size = mg.Length();
00177
00178
00179 REAL sq2 = sqrt(2.0);
00180 REAL sq3 = sqrt(3.0);
00181 REAL F_ZERO_TOL = 1.0e-2;
00182 REAL L = sqrt(z0*z0+z1*z1);
00183
00184
00185 double * F = new double [size];
00186 StructGrid::VectorTuple * T = new StructGrid::VectorTuple [size];
00187 for (int i=0; i<size; ++i)
00188 {
00189
00190 REAL p = mg.X()[i];
00191 REAL suc = mg.Y()[i];
00192 REAL q = mg.Z()[i];
00193 REAL th = 0.0;
00194 REAL s1,s2,s3;
00195 Hid2Sig(p,q,th, s1,s2,s3);
00196 sig=s1,s2,s3,0,0,0;
00197
00198
00199 F[i] = dynamic_cast<BarcelonaX*>(_cmodel)->YieldFunc(sig,z,suc);
00200
00201
00202 dynamic_cast<BarcelonaX*>(_cmodel)->Calc_dFdSig_dFdSuc(sig,z,suc, dfdsig,dfdsuc);
00203 REAL trV = (dfdsig(0)+dfdsig(1)+dfdsig(2));
00204 Tensor2 devV = dfdsig - (trV/3.0)*I;
00205 REAL dfdp = trV;
00206 REAL dfdq = 2.0*sq3*Norm(devV)/(3.0*sq2);
00207 if (q<0.0) dfdq=-dfdq;
00208
00209
00210 REAL Grad[3];
00211 Grad[0] = dfdp;
00212 Grad[1] = 0.0;
00213 Grad[2] = dfdq;
00214
00215
00216 T[i].vx=Grad[0]; T[i].vy=Grad[1]; T[i].vz=Grad[2];
00217 if (fabs(F[i])/L<=F_ZERO_TOL)
00218 {
00219 REAL norm=1.0;
00220 if (true) norm = sqrt(Grad[0]*Grad[0]+Grad[1]*Grad[1]+Grad[2]*Grad[2]);
00221 if (norm/z0>1.0e-5)
00222 { T[i].vx=Grad[0]/norm; T[i].vy=Grad[1]/norm; T[i].vz=Grad[2]/norm; }
00223 else
00224 { T[i].vx=0.0; T[i].vy=0.0; T[i].vz=0.0; }
00225 }
00226 else
00227 { T[i].vx=0.0; T[i].vy=0.0; T[i].vz=0.0; }
00228 }
00229
00230
00231 StructGrid sg (mg.X(),nPts, mg.Y(),nPts, mg.Z(),nPts, F, 0);
00232 StructGrid sg_hh(mg.X(),nPts, mg.Y(),nPts, mg.Z(),nPts, 0, T);
00233
00234
00235
00236 vtkLookupTable * lt = vtkLookupTable::New();
00237 lt->SetNumberOfColors(10);
00238 lt->Build();
00239 for (int i=0; i<10; ++i) lt->SetTableValue(i,CLR["salmon"].C);
00240
00241
00242 SGridIsoSurf iso(sg.GetGrid(), 0.0, lt);
00243 iso.GetActor()->GetProperty()->SetOpacity(Opac);
00244 win.AddActor(iso.GetActor());
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256 if (ShowHH)
00257 {
00258 REAL normals_sf = 0.2*L;
00259 HedgeHog * hh = new HedgeHog (sg_hh.GetGrid(), normals_sf);
00260 hh->GetActor()->GetProperty()->SetColor(CLR["light_blue"].C);
00261 win.AddActor(hh->GetActor());
00262 delete hh;
00263 }
00264
00265
00266 REAL p_ini,q_ini,sin3th_ini;
00267 Tensor2 S_ini;
00268 Stress_p_q_S_sin3th(sig_ini,p_ini,q_ini,S_ini,sin3th_ini);
00269 Sphere sp_ini(p_ini,suc_ini,q_ini, 0.03*p_Max, "yellow");
00270 win.AddActor(sp_ini.GetActor());
00271
00272 std::cout << "BarcelonaX: p_ini=" << p_ini << ", q_ini=" << q_ini << ", suc_ini=" << suc_ini << std::endl;
00273
00274
00275 lt->Delete();
00276 delete [] F;
00277
00278 }
00279
00280 else if (this->Name()=="SubBar")
00281 {
00282
00283 REAL k = _prms[6];
00284 REAL z0 = isv[0];
00285 REAL z1 = isv[1];
00286 REAL z2 = isv[2];
00287 REAL z3 = isv[3];
00288 REAL M = dynamic_cast<SubBar*>(_cmodel)->GetM(Util::ToRad(30.0));
00289 SubBar::IntVars z; z=z0,z1,z2,z3;
00290 Tensor2 sig;
00291 Tensor2 dfdsig;
00292 REAL dfdsuc;
00293
00294 std::cout << "VTKSubBar: z0=" << z0 << ", z1=" << z1 << ", z2=" << z2 << ", z3=" << z3 << std::endl;
00295
00296
00297 SubBar::IntVars z_tmp; z_tmp=z2,z3,0,0;
00298 REAL cp = 1.1;
00299 REAL cs = 1.3;
00300 REAL cq = 1.1;
00301 REAL p0m = dynamic_cast<SubBar*>(_cmodel)->Calc_p0(z_tmp,z3);
00302 REAL qm = M*sqrt((z2/2.0+k*z3)*(p0m-z2/2.0));
00303 REAL pm = p0m;
00304 REAL p_min=-cp*k*z3; p_Max=cp*pm;
00305 REAL s_min=0.0; REAL s_max=cs*z3;
00306 REAL q_min=-cq*qm; REAL q_max=cq*qm;
00307 MeshGrid mg(p_min ,p_Max ,nPts,
00308 s_min ,s_max ,nPts,
00309 q_min ,q_max ,nPts);
00310 int size = mg.Length();
00311
00312
00313 REAL sq2 = sqrt(2.0);
00314 REAL sq3 = sqrt(3.0);
00315 REAL F_ZERO_TOL = 1.0e-2;
00316 REAL L = sqrt(z0*z0+z1*z1);
00317
00318
00319 double * F_sl = new double [size];
00320 double * F_no = new double [size];
00321 StructGrid::VectorTuple * T = new StructGrid::VectorTuple [size];
00322 for (int i=0; i<size; ++i)
00323 {
00324
00325 REAL p = mg.X()[i];
00326 REAL suc = mg.Y()[i];
00327 REAL q = mg.Z()[i];
00328 REAL th = 0.0;
00329 REAL s1,s2,s3;
00330 Hid2Sig(p,q,th, s1,s2,s3);
00331 sig=s1,s2,s3,0,0,0;
00332
00333
00334 F_sl[i] = dynamic_cast<SubBar*>(_cmodel)->YieldFunc (sig,z,suc);
00335 F_no[i] = dynamic_cast<SubBar*>(_cmodel)->YieldFunc_Normal(sig,z,suc);
00336
00337
00338 dynamic_cast<SubBar*>(_cmodel)->Calc_dFdSig_dFdSuc(sig,z,suc, dfdsig,dfdsuc);
00339 REAL trV = (dfdsig(0)+dfdsig(1)+dfdsig(2));
00340 Tensor2 devV = dfdsig - (trV/3.0)*I;
00341 REAL dfdp = trV;
00342 REAL dfdq = 2.0*sq3*Norm(devV)/(3.0*sq2);
00343 if (q<0.0) dfdq = -dfdq;
00344
00345
00346 REAL Grad[3];
00347 Grad[0] = dfdp;
00348 Grad[1] = dfdsuc;
00349 Grad[2] = dfdq;
00350
00351
00352 T[i].vx=Grad[0]; T[i].vy=Grad[1]; T[i].vz=Grad[2];
00353 if (fabs(F_sl[i])/L<=F_ZERO_TOL)
00354 {
00355 REAL norm=1.0;
00356 if (true) norm = sqrt(Grad[0]*Grad[0]+Grad[1]*Grad[1]+Grad[2]*Grad[2]);
00357 if (norm/z0>1.0e-5)
00358 { T[i].vx=Grad[0]/norm; T[i].vy=Grad[1]/norm; T[i].vz=Grad[2]/norm; }
00359 else
00360 { T[i].vx=0.0; T[i].vy=0.0; T[i].vz=0.0; }
00361 }
00362 else
00363 { T[i].vx=0.0; T[i].vy=0.0; T[i].vz=0.0; }
00364 }
00365
00366
00367 StructGrid sg_sl(mg.X(),nPts, mg.Y(),nPts, mg.Z(),nPts, F_sl, T);
00368 StructGrid sg_no(mg.X(),nPts, mg.Y(),nPts, mg.Z(),nPts, F_no, T);
00369
00370
00371 vtkLookupTable * lt_sl = vtkLookupTable::New();
00372 vtkLookupTable * lt_no = vtkLookupTable::New();
00373 lt_sl->SetNumberOfColors(10);
00374 lt_sl->Build();
00375 lt_no->SetNumberOfColors(10);
00376 lt_no->Build();
00377 for (int i=0; i<10; ++i) lt_sl->SetTableValue(i,CLR["forest_green"].C);
00378 for (int i=0; i<10; ++i) lt_no->SetTableValue(i,CLR["peacock"].C);
00379
00380
00381 SGridIsoSurf iso_sl(sg_sl.GetGrid(), 0.0, lt_sl);
00382 SGridIsoSurf iso_no(sg_no.GetGrid(), 0.0, lt_no);
00383 iso_sl.GetActor()->GetProperty()->SetOpacity(Opac*0.7);
00384 iso_no.GetActor()->GetProperty()->SetOpacity(Opac);
00385 win.AddActor(iso_sl.GetActor());
00386 win.AddActor(iso_no.GetActor());
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 REAL p_ini,q_ini,sin3th_ini;
00399 Tensor2 S_ini;
00400 Stress_p_q_S_sin3th(sig_ini,p_ini,q_ini,S_ini,sin3th_ini);
00401 Sphere sp_ini(p_ini,suc_ini,q_ini, 0.03*p_Max, "yellow");
00402 win.AddActor(sp_ini.GetActor());
00403
00404 std::cout << "VTKSubBar: p_ini=" << p_ini << ", q_ini=" << q_ini << ", suc_ini=" << suc_ini << std::endl;
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415 delete [] F_sl;
00416 delete [] F_no;
00417 lt_sl -> Delete();
00418 lt_no -> Delete();
00419
00420 }
00421
00422 }
00423
00424 inline void ModelWrapper::AddIniStateActorsTo(VTKWin & win, int nPts, bool ShowHH, REAL Opac, REAL & p_Max)
00425 {
00426 }
00427
00428 #endif // MODELWRAPPER_WITH_VTK
00429
00430 #endif // MECHSYS_MODELWRAPPER_H
00431
00432