00001 
00002 
00004 
00005 #include <math.h>
00006 #include "Cell.h"
00007 #include "Display.h"
00008 #include "DNA.h"
00009 #include "Components.h"
00010 #include "Geometry.h"
00011 
00013 
00015 
00016 {
00017         m_pCell=pCell;
00018         SL[0]=0;                
00019         SL[1]=0;
00020         SL[2]=0;
00021         CW = 0.75E-4;   
00022         CL = 1.52E-4;   
00023         DEN = 0.282;            
00024         S = 3.6E-08;                    
00025         V = 5.65E-13;                   
00026         SEPF[0] = 0.0;
00027         SEPF[1] = 0.0;
00028         SEPF[2]=0.0;    
00029         NSEPF = 0;              
00030         CSL[0] = 0.0;
00031         CSL[1]=0.0;
00032         CSL[2]=0.0;
00033         E2=5.62E-4*V;   
00034         E3[0]=0;
00035         E3[1]=0;
00036         E3[2]=0;
00037         double E3TOT = 0.0;     
00038         for(int i=0; i<3; i++)
00039                 E3TOT = E3TOT + E3[i];  
00040         E23 = E3TOT + E2;       
00041 }
00042 
00043 CGeometry::CGeometry()
00044 {
00045 
00046 }
00047 
00048 CGeometry::~CGeometry()
00049 {
00050 
00051 }
00052 
00053 
00054 CGeometry::CGeometry(const CGeometry &rGeom, CCell *pCell)
00055 {
00056         
00057         m_pCell=pCell;
00058 }
00059 
00060 double CGeometry::GetVolume()
00061 {
00062         return V;
00063 }
00064 
00065 
00066 void CGeometry::CheckVolume()
00067 {
00068         double VB=V;                                                                    
00069         ComputeVolume();                                                                        
00070         if(fabs((VB-V)/V) > 0.1)                                                
00071                 m_pCell->GetDisplay()->WarningMessage(1);       
00072         return;
00073 }
00074 
00075 void CGeometry::ComputeVolume()
00076 {
00077         double TotalMass=0.0;                                                   
00078         for(int i=0;i<11;i++)
00079                 TotalMass+=m_pCell->GetComponents()->GetY(i);   
00080         double MassEnv=m_pCell->GetComponents()->GetY(9);       
00081         double VE = MassEnv/0.42/0.5526;                                        
00082         double VC = (TotalMass-MassEnv/0.42)/0.2584;                    
00083         V=VC+VE;                        
00084 }
00085 
00086 void CGeometry::UpdateShape()
00087 {
00088 
00089         if(m_pCell->GetDNA()->CheckTerm())                                              
00090                 AddSepta();
00091         E2=m_pCell->GetComponents()->GetY(12);
00092         double E3TOT=0.0;
00093         for(int i=0;i<3;++i)
00094                 E3TOT += E3[i]*(pow(2,i));      
00095         E23=E2+E3TOT;                           
00096 
00097         double PRCNT=E2/E23;                            
00098         double PRCNTS[3];
00099         for(i=0;i<3;++i)
00100                 PRCNTS[i] = E3[i]/E23;  
00101         double DS=(1.2E6/0.42)*m_pCell->GetComponents()->GetDY9()*m_pCell->GetComponents()->DT; 
00102                                                                         
00103         double SEPFTOT=0.0;
00104         for(i=0;i<3;++i)
00105         {
00106                 SEPF[i] += PRCNTS[i]*DS;        
00107                 SEPFTOT += SEPF[i]*(pow(2,i));  
00108         }
00109 
00110         double DCL = (PRCNT*DS)/(3.14*CW);      
00111         CL+=DCL;                                                
00112         S+=DS;                                                  
00113         CW=CalcWidth();                 
00114         CL=S/(3.14159*CW)-CW-2.0*SL[0]-4.0*SL[1]-8.0*SL[2];     
00115                                                                 
00116         double CN=CW*1.0E4;                             
00117         double CM=(CL+2.0*SL[0]+4.0*SL[1]+8.0*SL[2]+CW)*1.0E4;
00118                                                                         
00119         for(i=0;i<3;++i)
00120                 CSL[i]=SL[i]*1.0E4;                     
00121 }
00122 
00123 void CGeometry::AddSepta()
00124 {
00125         if(NSEPF<3)             
00126         {
00127                 ++NSEPF;                
00128         }
00129         double Y13=m_pCell->GetComponents()->GetY(13);
00130         E3[NSEPF-1]=Y13/pow(2,(NSEPF-1));       
00131         m_pCell->GetComponents()->ResetY(13);
00132 }
00133 
00134 double CGeometry::GetWidth()
00135 {
00136         return CW;
00137 }
00138 
00139 double CGeometry::CalcWidth()
00140 {
00141         int i=0;
00142         
00143         for(i=0;i<100;++i)
00144         {
00145                 double FS=0.0;
00146                 double DFS=0.0;
00147                 for(int j=0;j<3;++j)
00148                 {
00149                         SL[j]=SEPF[j]/(2*3.14159*CW);
00150                         DFS += (pow(0.25,(j+1))*pow(SEPF[j],3));
00151                         FS += (pow(2,(j+1))*pow(SL[j],3));
00152                 }
00153                 double F = -.262*pow(CW,3)+0.25*S*CW-1.047*FS-V;
00154                 double DF = -0.7854*pow(CW,2)+0.25*S+0.1013*DFS/pow(CW,4);
00155                 double CWN=CW-F/DF;
00156                 if((fabs(F)<=0.001)&&(fabs((CW-CWN)/CWN)<=0.001))
00157                 {
00158                         CW=CWN;
00159                         break;
00160                 }
00161                 CW=CWN;                         
00162         }
00163         for(int j=0;j<3;++j)
00164                 SL[j]=SEPF[j]/(2*3.14159*CW);   
00165         
00166         if(i<5)
00167                 return CW;
00168 
00169         m_pCell->GetDisplay()->WarningMessage(2);
00170         return CW;
00171 }
00172 
00173 double CGeometry::GetSurface()
00174 {
00175         return S;
00176 }
00177 
00178 double CGeometry::GetSepf()
00179 {
00180         return SEPF[0];
00181 }
00182 
00183 void CGeometry::Divide()
00184 {
00185         SEPF[0]=SEPF[1];
00186         SEPF[1]=SEPF[2];
00187         SEPF[2]=0.0;            
00188         S=0.5*S;                        
00189         V=0.5*V;                        
00190         CL=0.5*CL;                      
00191         E2=0.5*E2;                      
00192         E3[0]=E3[1];            
00193         E3[1]=E3[2];
00194         E3[2]=0.0;                      
00195         NSEPF=NSEPF-1;  
00196 }