ysurf.h

00001 /*************************************************************************************
00002  * MechSys - A C++ library to simulate (Continuum) Mechanical Systems                *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>       *
00004  * Copyright (C) 2005 Raul Dario Durand Farfan  <raul.durand at gmail.com>           *
00005  *                                                                                   *
00006  * This file is part of MechSys.                                                     *
00007  *                                                                                   *
00008  * MechSys is free software; you can redistribute it and/or modify it under the      *
00009  * terms of the GNU General Public License as published by the Free Software         *
00010  * Foundation; either version 2 of the License, or (at your option) any later        *
00011  * version.                                                                          *
00012  *                                                                                   *
00013  * MechSys is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   *
00015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.          *
00016  *                                                                                   *
00017  * You should have received a copy of the GNU General Public License along with      *
00018  * MechSys; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  * Fifth Floor, Boston, MA 02110-1301, USA                                           *
00020  *************************************************************************************/
00021 
00022 #ifndef MECHSYS_YSURF_H
00023 #define MECHSYS_YSURF_H
00024 
00025 #ifdef HAVE_CONFIG_H
00026   #include "config.h"
00027 #else
00028   #ifndef REAL
00029     #define REAL double
00030   #endif
00031 #endif
00032 
00033 #include <string>
00034 
00035 // Tensors
00036 #include "tensors/tensor1.h"
00037 #include "tensors/tensor2.h"
00038 #include "tensors/tensoperators.h"
00039 
00040 // VTK
00041 #include "vtkActor.h"
00042 
00043 // MechSys
00044 #include "vtkwrap/structgrid.h"
00045 #include "vtkwrap/hedgehog.h"
00046 #include "vtkwrap/sgridoutline.h"
00047 #include "vtkwrap/sgridisosurf.h"
00048 #include "vtkwrap/vtkwin.h"
00049 #include "vtkwrap/axes.h"
00050 #include "vtkwrap/arrow.h"
00051 #include "vtkwrap/colors.h"
00052 #include "vtkwrap/cutclip.h"
00053 #include "vtkwrap/vtkwin.h"
00054 #include "util/util.h"
00055 #include "util/string.h"
00056 #include "constmod/failcrit.h"
00057 #include "numerical/meshgrid.h"
00058 #include "tensors/functions.h"
00059 
00060 using Tensors::Sin3Th;
00061 using Tensors::Hid2Sig;
00062 using Util::ToRad;
00063 using Util::Sq3;
00064 using Util::Sq6;
00065 
00066 class YSurf
00067 {
00068     static REAL BIGNUM;
00069     static REAL SMMINSIG;
00070     static REAL Q_MIN;
00071 public:
00072     // Enum
00073     enum Type {YSurf_DP, YSurf_SM, YSurf_AR};
00074 
00075     // Constructor & Destructor
00076      YSurf(Type type, FailCrit const & FCrit, REAL MinP=1.0e-3);
00077     ~YSurf();
00078 
00079     // Config Methdos
00080     YSurf & SetAlpha (REAL           Alpha) { _alpha     = Alpha;        return (*this); }
00081     YSurf & SetBeta  (REAL            Beta) { _beta      = Beta;         return (*this); }
00082     YSurf & SetL     (REAL               L) { _L         = L;            return (*this); }
00083     YSurf & SetPc    (REAL              Pc) { _Pc        = Pc;           return (*this); }
00084     YSurf & SetColor (String const & Color) { _ycolor    = Color;        return (*this); }
00085     YSurf & SetOpac  (REAL         Opacity) { _yopac     = Opacity;      return (*this); }
00086     YSurf & NormHH   (bool     NormalizeHH) { _hh_norm   = NormalizeHH;  return (*this); }
00087     YSurf & HHScale  (REAL     ScaleFactor) { _hh_sf     = ScaleFactor;  return (*this); }
00088     YSurf & HHyfTol  (REAL    YieldFuncTol) { _hh_yf_tol = YieldFuncTol; return (*this); }
00089 
00090     // Config Cut Part of Surfaces
00091     YSurf & CPartWire  (bool         UseWire) { _cpart_wire  = UseWire; return (*this); }
00092     YSurf & CPartColor (char const * Color  ) { _cpart_color = Color;   return (*this); }
00093     YSurf & CPartOpac  (REAL         Opacity) { _cpart_opac  = Opacity; return (*this); }
00094 
00095     // Methods
00096     REAL Func(REAL SI, REAL SII, REAL SIII, REAL * Grad=NULL); // Grad[3]
00097     String Name() const;
00098 
00099     // VTK
00100     vtkActor * GenIsoSurf    (int nPoints);
00101     vtkActor * GenHedgeHog   (int nPoints);
00102     CutClip  * AddOctPlane   (REAL p, bool Positive=true);
00103     void       AddActorsTo   (VTKWin & Win);
00104     void       DelActorsFrom (VTKWin & Win);
00105     vtkActor * GetHHActor    () { if (_hh!=NULL) { return _hh->GetActor(); } else { return NULL; } }
00106     void       DelHedgeHog   () { if (_hh!=NULL) { delete _hh; _hh=NULL; } }
00107 
00108 private:
00109     // Data
00110     Type             _type;
00111     FailCrit const & _fcrit;
00112     REAL             _alpha;
00113     REAL             _beta;
00114     REAL             _L;
00115     REAL             _Pc;
00116     REAL             _min_P;
00117     String           _ycolor;
00118     REAL             _yopac;
00119     SGridIsoSurf   * _ysgiso;
00120     HedgeHog       * _hh;
00121     CutClip        * _cc;
00122     bool             _cpart_wire;
00123     String           _cpart_color;
00124     REAL             _cpart_opac;
00125     bool             _hh_norm;
00126     REAL             _hh_sf;
00127     REAL             _hh_yf_tol;
00128 
00129 }; // class YSurf
00130 
00131 REAL YSurf::BIGNUM   = 1.0e+10;
00132 REAL YSurf::SMMINSIG = 1.0e-4;
00133 REAL YSurf::Q_MIN    = 1.0e-7;
00134 
00135 
00137 
00138 
00139 inline YSurf::YSurf(Type type, FailCrit const & FCrit, REAL MinP) // {{{
00140     : _type           (type),
00141       _fcrit          (FCrit), 
00142       _alpha          (1.0),
00143       _beta           (0.0),
00144       _L              (1.0),
00145       _Pc             (1.0),
00146       _min_P          (MinP), 
00147       _ycolor         (String("blue_light")),
00148       _yopac          (1.0),
00149       _ysgiso         (NULL), 
00150       _hh             (NULL),
00151       _cc             (NULL),
00152       _cpart_wire     (false),
00153       _cpart_color    (String("yellow")),
00154       _cpart_opac     (0.8),
00155       _hh_norm        (false),
00156       _hh_sf          (0.05),
00157       _hh_yf_tol      (0.05)
00158 {
00159 } // }}}
00160 
00161 inline YSurf::~YSurf() // {{{
00162 {
00163     if (_ysgiso !=NULL) delete _ysgiso;
00164     if (_hh     !=NULL) delete _hh;
00165     if (_cc     !=NULL) delete _cc;
00166 } // }}}
00167 
00168 inline REAL YSurf::Func(REAL SI, REAL SII, REAL SIII, REAL * Grad) // {{{
00169 {
00170     REAL P,Q,mu;
00171     REAL      s[3] = {SI,SII,SIII};
00172     REAL      S[3] = {(2.0*SI-SII-SIII)/3.0, (2.0*SII-SIII-SI)/3.0, (2.0*SIII-SI-SII)/3.0};
00173     REAL  dP_ds[3] = {0,0,0};
00174     REAL  dQ_ds[3] = {0,0,0};
00175     REAL   dmu_dth = 0.0;
00176     REAL dth_ds[3] = {0,0,0};
00177     switch (_type)
00178     {
00179         case YSurf_DP:
00180         {
00181             // Function
00182             P  = (SI+SII+SIII)/Sq3();
00183             Q  = sqrt(SI*SI + SII*SII + SIII*SIII - P*P);
00184             mu = _fcrit.kDP();
00185             // Grads
00186             if (Grad!=NULL)
00187             {
00188                 for (int k=0; k<3; ++k) dP_ds[k] = 1.0/Sq3();  if (Q>Q_MIN)
00189                 for (int k=0; k<3; ++k) dQ_ds[k] = S[k]/Q;
00190             }
00191             break;
00192         }
00193         case YSurf_SM:
00194         {
00195             // Function
00196             if (SI   <= SMMINSIG) SI  =SMMINSIG;
00197             if (SII  <= SMMINSIG) SII =SMMINSIG;
00198             if (SIII <= SMMINSIG) SIII=SMMINSIG;
00199             REAL I1 = SI+SII+SIII;
00200             REAL I2 = SI*SII + SII*SIII + SIII*SI;
00201             REAL I3 = SI*SII*SIII;
00202                  P  = sqrt(I3/I2)*(sqrt(SI)+sqrt(SII)+sqrt(SIII));
00203                  Q  = sqrt(SI*SI + SII*SII + SIII*SIII - P*P);
00204                  mu = _fcrit.kSM();
00205             // Grads
00206             if (Grad!=NULL)
00207             {
00208                 REAL t[3] = {sqrt(s[0]), sqrt(s[1]), sqrt(s[2])};
00209                 REAL  srz = sqrt(I3/I2);
00210                 for (int k=0; k<3; ++k) dP_ds[k] = 0.5*P*(1.0/s[k]-(I1-s[k])/I2) + 0.5*srz/t[k];  if (Q>Q_MIN)
00211                 for (int k=0; k<3; ++k) dQ_ds[k] = (s[k] - P*dP_ds[k])/Q;
00212             }
00213             break;
00214         }
00215         case YSurf_AR:
00216         {
00217             REAL sin3th = Sin3Th(SI,SII,SIII);
00218             // Function
00219             P  = (SI+SII+SIII)/Sq3();
00220             Q  = sqrt(SI*SI + SII*SII + SIII*SIII - P*P);
00221             mu = _fcrit.AR_Calc_M(sin3th);
00222             // Grads
00223             if (Grad!=NULL)
00224             {
00225                 for (int k=0; k<3; ++k) dP_ds[k] = 1.0/Sq3();  if (Q>Q_MIN)
00226                 for (int k=0; k<3; ++k) dQ_ds[k] = S[k]/Q;
00227                 if (Q>Q_MIN)
00228                 {
00229                     REAL cos3th = sqrt(1.0-pow(sin3th,2.0));
00230                     if (cos3th>Q_MIN)
00231                     {
00232                                dmu_dth = (0.75*mu*(1.0-_fcrit.AR_w())*cos3th)/(1.0+_fcrit.AR_w()-(1.0-_fcrit.AR_w())*sin3th);
00233                         REAL     SS[3] = {S[0]*S[0],S[1]*S[1],S[2]*S[2]};
00234                         REAL      p_SS = (SS[0]+SS[1]+SS[2])/3.0;
00235                         REAL dev_SS[3] = {SS[0]-p_SS,SS[1]-p_SS,SS[2]-p_SS};   for (int k=0; k<3; ++k)
00236                              dth_ds[k] = (1.0/(Q*Q*cos3th)) * (Sq6()*dev_SS[k]/Q - sin3th*S[k]);
00237                     }
00238                 }
00239             }
00240             break;
00241         }
00242         default:
00243             throw "YSurf::Func Invalid Type";
00244     }
00245     // Grads
00246     REAL T = _alpha*exp(_beta*P);
00247     if (Grad!=NULL)
00248     {
00249         REAL  dT_dP = _beta*T;
00250         REAL  dF_dP = 2.0*(P-_Pc)+pow(Q/mu,2.0)*dT_dP;
00251         REAL  dF_dQ = 2.0*T*Q/(mu*mu);
00252         REAL dF_dmu = -2.0*T*Q*Q/pow(mu,3.0);
00253         for (int k=0; k<3; ++k) Grad[k] = dF_dP*dP_ds[k] + dF_dQ*dQ_ds[k] + dF_dmu*dmu_dth*dth_ds[k];
00254     }
00255     // Function
00256     return pow(P-_Pc,2.0) - _L*_L + T*pow(Q/mu,2.0);
00257 } // }}}
00258 
00259 inline String YSurf::Name() const // {{{
00260 {
00261     switch (_type)
00262     {
00263         case YSurf_DP: { return String("Drucker-Prager Shaped"      ); }
00264         case YSurf_SM: { return String("SMP (Novo) Shaped"          ); }
00265         case YSurf_AR: { return String("Argyris-Sheng et al. Shaped"); }
00266         default:
00267             throw "YSurf::Name: Invalid YSurf Type";
00268     }
00269 } // }}}
00270 
00271 inline vtkActor * YSurf::GenIsoSurf(int nPoints) // {{{
00272 {
00273     // Delete old objects
00274     if (_ysgiso!=NULL) delete _ysgiso;
00275 
00276     // Create a temporary grid around hydrostatic axis
00277     REAL minP=_min_P; REAL maxP=_fcrit.Maxp();
00278     REAL minQ=0.0;    REAL maxQ=_fcrit.Maxp();
00279     REAL minT=0.0;    REAL maxT=ToRad(360.0);
00280     MeshGrid mg(minP,maxP,nPoints, minQ,maxQ,nPoints, minT,maxT,nPoints);
00281     REAL const * P = mg.X();
00282     REAL const * Q = mg.Y();
00283     REAL const * T = mg.Z();
00284     int       Size = mg.Length();
00285 
00286     // Rotate (convert) P,Q,T values into SI,SII,SIII values
00287     REAL * SI   = new REAL [Size];
00288     REAL * SII  = new REAL [Size];
00289     REAL * SIII = new REAL [Size];
00290     REAL * YF   = new REAL [Size];
00291     Hid2Sig(P,Q,T, SI,SII,SIII, Size);
00292     
00293     // Calculate yield function
00294     for (int i=0; i<Size; ++i)
00295         YF[i] = Func(SI[i], SII[i], SIII[i]);
00296 
00297     // Create a VTK structured grid
00298     StructGrid ysg(SII,nPoints, SIII,nPoints, SI,nPoints, YF);
00299 
00300     // LookupTable for colors
00301     vtkLookupTable * lt = vtkLookupTable::New();
00302     lt->SetNumberOfColors(1);
00303     lt->Build();
00304     lt->SetTableValue(0,CLR[_ycolor.GetSTL()].C);
00305 
00306     // Generate the Surfaces
00307     _ysgiso = new SGridIsoSurf (ysg.GetGrid(), 0.0, lt); // for F==0
00308     _ysgiso->GetActor()->GetProperty()->SetOpacity (_yopac);
00309 
00310     // Clean up
00311     delete [] SI;
00312     delete [] SII;
00313     delete [] SIII;
00314     delete [] YF;
00315 
00316     // Return
00317     return _ysgiso->GetActor();
00318 } // }}}
00319 
00320 inline vtkActor * YSurf::GenHedgeHog(int nPoints) // {{{
00321 {
00322     // Delete old objects
00323     if (_hh!=NULL) delete _hh;
00324 
00325     // Create a temporary grid around hydrostatic axis
00326     REAL minP=_min_P; REAL maxP=_fcrit.Maxp();
00327     REAL minQ=0.0;    REAL maxQ=_fcrit.Maxp();
00328     REAL minT=0.0;    REAL maxT=ToRad(360.0);
00329     MeshGrid mg(minP,maxP,nPoints, minQ,maxQ,nPoints, minT,maxT,nPoints);
00330     REAL const * P = mg.X();
00331     REAL const * Q = mg.Y();
00332     REAL const * T = mg.Z();
00333     int       Size = mg.Length();
00334 
00335     // Rotate (convert) P,Q,T values into SI,SII,SIII values
00336     REAL * SI   = new REAL [Size];
00337     REAL * SII  = new REAL [Size];
00338     REAL * SIII = new REAL [Size];
00339     REAL * YF   = new REAL [Size];
00340     Hid2Sig(P,Q,T, SI,SII,SIII, Size);
00341     
00342     // Calculate yield and gradients
00343     StructGrid::VectorTuple * V = new StructGrid::VectorTuple [Size];
00344     for (int i=0; i<Size; ++i)
00345     {
00346         REAL Grad[3];
00347         YF[i] = Func(SI[i], SII[i], SIII[i], Grad);
00348         if (fabs(YF[i])<=_hh_yf_tol)
00349         {
00350             REAL norm=1.0;
00351             if (_hh_norm) norm = sqrt(Grad[0]*Grad[0]+Grad[1]*Grad[1]+Grad[2]*Grad[2]);
00352             if (norm>Q_MIN)
00353             {
00354                 V[i].vx=Grad[1]/norm;
00355                 V[i].vy=Grad[2]/norm;
00356                 V[i].vz=Grad[0]/norm;
00357             }
00358             else
00359             {
00360                 V[i].vx=0.0;
00361                 V[i].vy=0.0;
00362                 V[i].vz=0.0; 
00363             }
00364         }
00365         else
00366         {
00367             V[i].vx=0.0;
00368             V[i].vy=0.0;
00369             V[i].vz=0.0; 
00370         }
00371     }
00372 
00373     // Create a VTK structured grid
00374     StructGrid ysg(SII,nPoints, SIII,nPoints, SI,nPoints, YF, V);
00375 
00376     // Create a Hedgehog
00377     _hh = new HedgeHog (ysg.GetGrid(), _hh_sf);
00378 
00379     // Clean up
00380     delete [] SI;
00381     delete [] SII;
00382     delete [] SIII;
00383     delete [] YF;
00384     delete [] V;
00385 
00386     // Return
00387     return _hh->GetActor();
00388 } // }}}
00389 
00390 inline CutClip * YSurf::AddOctPlane(REAL p, bool Positive) // {{{
00391 {
00392     REAL n=1.0;
00393     if (!Positive) n=-1.0;
00394     _cc = new CutClip;
00395     //p,p,p,n,n,n, _ysgiso->GetIsoSurf()->GetOutputPort(), _ycolor, _yopac, _ycolor, _yopac, _cpart_wire, _cpart_color, _cpart_opac);
00396     return _cc;
00397 } // }}}
00398 
00399 inline void YSurf::AddActorsTo(VTKWin & Win) // {{{
00400 {
00401     if (_ysgiso!=NULL) Win.AddActor(_ysgiso->GetActor());
00402     if (_hh    !=NULL) Win.AddActor(_hh    ->GetActor());
00403     if (_cc    !=NULL) _cc->AddActorsTo(Win);
00404 } // }}}
00405 
00406 inline void YSurf::DelActorsFrom(VTKWin & Win) // {{{
00407 {
00408     if (_ysgiso!=NULL) Win.DelActor(_ysgiso->GetActor());
00409     if (_hh    !=NULL) Win.DelActor(_hh    ->GetActor());
00410     if (_cc    !=NULL) _cc->DelActorsFrom(Win);
00411 } // }}}
00412 
00413 #endif // MECHSYS_YSURF_H
00414 
00415 // vim:fdm=marker

Generated on Wed Jan 24 15:56:25 2007 for MechSys by  doxygen 1.4.7