00001 #include "flashcompositional.h"
00002 #include "numericmethods.h"
00003 #include "arrayofvecdouble.h"
00004
00005
00006
00007 void FlashCompositional::flash(double P, const VecDouble &compTotalMoles, FlashData &data)
00008 {
00009 throw new Exception("Invalid Method called FlashCompositional::flash(double P, double T,const VecDouble &compTotalMoles, FlashData &data)");
00010 }
00011
00018 double FlashCompositional::getFluidCompressibility(double P, FlashData &data)
00019 {
00020 return getNumericFluidCompressibility(P,data);
00021
00022 }
00023
00024 void FlashCompositional::getPhasesVolume(double P, const FlashData &data, VecDouble &phasesVol)
00025 {
00026 throw new Exception("This flash module does not override FlashCompositional::getPhasesVolume(double P, const FlashData &data, VecDouble &phasesVol)\nProbably this flash module was not designed for compositional models.\n Please check that reading the config.conf file");
00027 }
00028
00029
00030 FlashCompositional::FlashCompositional(unsigned n_phases,unsigned n_components) :FlashBase(n_phases,n_components)
00031 {
00032
00033
00034 }
00035
00036
00037 const VecDouble& FlashCompositional::getComponentsMolarMass() const
00038 {
00039 throw new Exception("This flash module does not override FlashCompositional::getComponentsMolarMass()\nProbably this flash module was not designed for compositional module.\n Please check that reading the config.conf file");
00040
00041 }
00042
00043
00044 void FlashCompositional::getPhasesViscosities(double P,const FlashData &data,VecDouble &visc)
00045 {
00046 throw new Exception("This flash module does not override FlashCompositional::getPhasesViscosities()\nProbably this flash module was not designed for compositional module.\n Please check that reading the config.conf file");
00047
00048 }
00049
00057 double FlashCompositional::getNumericFluidCompressibility(double P,const FlashData &data,double tol)
00058 {
00059
00060 double h=P*tol;
00061
00062 static FlashData data1(n_phases,n_components);
00063 static VecDouble totalComponents(n_components);
00064 static VecDouble phasesVol(n_phases);
00065 data1.allocateOwnMemory();
00066 data.getTotalComponentsMoles(totalComponents);
00067
00068
00069 flash(P+h,totalComponents,data1);
00070 getPhasesVolume(P+h,data1,phasesVol);
00071 double volPos=NumericMethods::vectorSum(phasesVol);
00072
00073 flash(P-h,totalComponents,data1);
00074 getPhasesVolume(P-h,data1,phasesVol);
00075 double volNeg=NumericMethods::vectorSum(phasesVol);
00076
00077 return -(volPos-volNeg)/(2*h);
00078
00079 }
00080
00088 void FlashCompositional::getNumericTotalVolumeDerivative(double P,const VecDouble &compTotalMoles,VecDouble &compTotalDeriv,double h)
00089 {
00090 static FlashData data(numPhases(),numComponents());
00091 static VecDouble compTotalDX;
00092 static VecDouble phasesVol(numPhases());
00093 compTotalDX=compTotalMoles;
00094
00095 assert(compTotalMoles.size() == compTotalDeriv.size());
00096
00097
00098 for (unsigned cmp=0;cmp<numComponents();cmp++)
00099 {
00100 compTotalDX(cmp)=compTotalMoles(cmp)+h;
00101 flash(P,compTotalDX,data);
00102 getPhasesVolume(P,data,phasesVol);
00103 double posVol=NumericMethods::vectorSum(phasesVol);
00104
00105 compTotalDX(cmp)=compTotalMoles(cmp)-h;
00106 if (compTotalDX(cmp) >= 0.0)
00107 {
00108 flash(P,compTotalDX,data);
00109 getPhasesVolume(P,data,phasesVol);
00110 double negVol=NumericMethods::vectorSum(phasesVol);
00111 compTotalDeriv(cmp)=(posVol-negVol)/(2*h);
00112 compTotalDX(cmp)=compTotalMoles(cmp);
00113 }
00114 else
00115 {
00116 compTotalDX(cmp)=compTotalMoles(cmp);
00117 flash(P,compTotalDX,data);
00118 getPhasesVolume(P,data,phasesVol);
00119 double negVol=NumericMethods::vectorSum(phasesVol);
00120 compTotalDeriv(cmp)=(posVol-negVol)/(h);
00121 }
00122
00123
00124 }
00125
00126 }
00127
00128
00129
00130 void FlashCompositional::getTotalVolumeDerivatives(double P,FlashData &data,VecDouble &dv_dm)
00131 {
00132 throw new Exception("This flash module does not implement FlashCompositional:::getTotalVolumeDerivatives(double P,FlashData &data,VecDouble &dv_dm)\nProbably this flash module was not designed for compositional module.\n Please check that by reading the config.conf file");
00133
00134 }
00135
00136
00137 void FlashCompositional::printOutput()
00138 {
00139
00140 }
00141
00142 void FlashCompositional::flash(Index cell, FlashData &data)
00143 {
00144 m_dataArray.getData(cell,data);
00145 }
00146
00147 void FlashCompositional::execute()
00148 {
00149
00150 const VecDouble &vP=getDynamicModule().getPressureAtCells();
00151 TransportBase &trans=getTransportModule();
00152 assert(vP.size() == trans.getSolutionAtCells().size());
00153 assert(trans.getSolutionAtCells().vecs_size() == numComponents());
00154
00155 static VecDoubleRef m(this->numComponents());
00156
00157
00158 if (m_dataArray.size() == 0)
00159 {
00160 m_dataArray.reinit(numPhases(),numComponents(),trans.getSolutionAtCells().size());
00161 }
00162
00163 unsigned nCells = m_dataArray.size();
00164 FlashData data(numPhases(),numComponents(),NULL);
00165 for (unsigned i=0;i<nCells;i++)
00166 {
00167 m_dataArray.getData(i,data);
00168 trans.getSolutionAtCells().getVecValues(i,&m);
00169 this->flash(vP(i),m,data);
00170 }
00171 }
00172
00173