diff --git a/CMakeLists.txt b/CMakeLists.txt index f7e49e1..49571d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,35 +5,38 @@ set(CMAKE_CXX_STANDARD 11) # Define path to header files and libraries -set(HOME /opt/scientific) -set(CANTERA_DIR ${HOME}/cantera-2.4_gnu_blas) -set(IDA_DIR ${HOME}/sundials-3.1.1_intel_mkl) -set(GSL_DIR /usr/lib) -set(COOLPROP_DIR /backup/weiye/CoolProp) -set(FMT_DIR /backup/weiye/fmt) +#set(HOME /opt/scientific) +set(CANTERA_DIR /usr/local) +set(IDA_DIR /usr/local) +set(GSL_DIR /usr/local) +set(COOLPROP_DIR /opt/CoolProp/shared_library/Linux) +set(FMT_DIR /usr/local) set(CANTERA_INCLUDES ${CANTERA_DIR}/include) set(IDA_INCLUDES ${IDA_DIR}/include) -set(GSL_INCLUDES /usr/include/gsl) +set(GSL_INCLUDES ${GSL_DIR}/include/gsl) set(COOLPROP_INCLUDES ${COOLPROP_DIR}/include) set(FMT_INCLUDES ${FMT_DIR}/include) -set(EIGEN_INCLUDES /backup/weiye/eigen-3.4.0) +set(EIGEN_INCLUDES /opt/eigen-3.4.0) # Search for source files aux_source_directory(${PROJECT_SOURCE_DIR}/src SRC_LIST) add_executable(DropletCombustion ${SRC_LIST}) # Set the RPATH parameter -set(CMAKE_INSTALL_RPATH "${IDA_DIR}/lib;${CANTERA_DIR}/lib;${COOLPROP_DIR}/lib;${FMT_DIR}/lib") +set(CMAKE_INSTALL_RPATH "${IDA_DIR}/lib;${CANTERA_DIR}/lib;${GSL_DIR}/lib;${COOLPROP_DIR}/lib;${FMT_DIR}/lib") # Link libraries -target_link_directories(DropletCombustion PRIVATE ${CANTERA_DIR}/lib ${IDA_DIR}/lib ${GSL_DIR} ${COOLPROP_DIR}/lib ${FMT_DIR}/lib) +target_link_directories(DropletCombustion PRIVATE ${CANTERA_DIR}/lib ${IDA_DIR}/lib ${GSL_DIR}/lib ${COOLPROP_DIR}/64bit ${FMT_DIR}/lib ) target_link_libraries(DropletCombustion PRIVATE cantera_shared sundials_nvecopenmp sundials_ida sundials_sunlinsollapackband gsl gslcblas CoolProp fmt) # Include directories target_include_directories(DropletCombustion - PRIVATE ${PROJECT_SOURCE_DIR}/include ${CANTERA_INCLUDES} ${IDA_INCLUDES} ${GSL_INCLUDES} ${COOLPROP_INCLUDES} ${FMT_INCLUDES} ${EIGEN_INCLUDES}) + PRIVATE ${PROJECT_SOURCE_DIR}/include ${CANTERA_INCLUDES} ${IDA_INCLUDES} ${GSL_INCLUDES} ${COOLPROP_INCLUDES} ${FMT_INCLUDES} ${EIGEN_INCLUDES} ) # Set the output path set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) + + + diff --git a/DropletCombustion11 b/DropletCombustion11 deleted file mode 100755 index 2bcebce..0000000 Binary files a/DropletCombustion11 and /dev/null differ diff --git a/DropletCombustion3 b/DropletCombustion3 deleted file mode 100755 index 8f8587a..0000000 Binary files a/DropletCombustion3 and /dev/null differ diff --git a/DropletCombustion4 b/DropletCombustion4 deleted file mode 100755 index cc1dcff..0000000 Binary files a/DropletCombustion4 and /dev/null differ diff --git a/DropletCombustion8 b/DropletCombustion8 deleted file mode 100755 index 925971a..0000000 Binary files a/DropletCombustion8 and /dev/null differ diff --git a/DropletCombustion9 b/DropletCombustion9 deleted file mode 100755 index 925971a..0000000 Binary files a/DropletCombustion9 and /dev/null differ diff --git a/DropletCombustionTest1 b/DropletCombustionTest1 deleted file mode 100755 index 1054c58..0000000 Binary files a/DropletCombustionTest1 and /dev/null differ diff --git a/DropletCombustionTest3 b/DropletCombustionTest3 deleted file mode 100755 index fb8a1d2..0000000 Binary files a/DropletCombustionTest3 and /dev/null differ diff --git a/DropletCombustionTest4 b/DropletCombustionTest4 deleted file mode 100755 index a5ff4fb..0000000 Binary files a/DropletCombustionTest4 and /dev/null differ diff --git a/DropletCombustionTest5 b/DropletCombustionTest5 deleted file mode 100755 index 188d8f4..0000000 Binary files a/DropletCombustionTest5 and /dev/null differ diff --git a/DropletCombustionTest7 b/DropletCombustionTest7 deleted file mode 100755 index 8534194..0000000 Binary files a/DropletCombustionTest7 and /dev/null differ diff --git a/DropletCombustionTest7-Binary b/DropletCombustionTest7-Binary deleted file mode 100755 index 2ff96a9..0000000 Binary files a/DropletCombustionTest7-Binary and /dev/null differ diff --git a/UserData.cpp b/UserData.cpp deleted file mode 100644 index 8473e99..0000000 --- a/UserData.cpp +++ /dev/null @@ -1,499 +0,0 @@ -#include "UserData.h" -#include "parse.h" - -void freeUserData(UserData data){ - if(data!=NULL){ - if(data->trmix!=NULL){ - delete data->trmix; - printf("Transport Deleted!\n"); - - } - if(data->gas!=NULL){ - delete data->gas; - printf("Gas Deleted!\n"); - - } - if(data->adaptiveGrid){ - if(data->grid->xOld!=NULL){ - delete[] data->grid->xOld; - printf("old grid array Deleted!\n"); - } - if(data->grid->x!=NULL){ - delete[] data->grid->x; - printf("current grid array Deleted!\n"); - } - if(data->grid!=NULL){ - free(data->grid); - printf("grid object Freed!\n"); - } - } - else{ - if(data->uniformGrid!=NULL){ - delete[] data->uniformGrid; - printf("uniformGrid deleted!\n"); - } - } - if(data->innerMassFractions!=NULL){ - delete[] data->innerMassFractions; - printf("innerMassFractions array Deleted!\n"); - } - if(data->output!=NULL){ - fclose(data->output); - printf("Output File Cleared from Memory!\n"); - } - if(data->gridOutput!=NULL){ - fclose(data->gridOutput); - printf("Grid Output File Cleared from Memory!\n"); - } - //if(data->ratesOutput!=NULL){ - // fclose(data->ratesOutput); - // printf("Rates Output File Cleared from Memory!\n"); - //} - if(data->globalOutput!=NULL){ - fclose(data->globalOutput); - printf("Global Output File Cleared from Memory!\n"); - } - if(data->timescaleOutput!=NULL){ - fclose(data->timescaleOutput); - printf("Characteristic Timescale Output File Cleared from Memory!\n"); - } - //if(data->rxnROPOutput!=NULL){ - // fclose(data->rxnROPOutput); - // printf("Reactions Rate of Progress Output File Cleared from Memory!\n"); - //} - //if(data->spROPOutput!=NULL){ - // fclose(data->spROPOutput); - // printf("Species Rate of Production Output File Cleared from Memory!\n"); - //} - } - free(data); /* Free the user data */ - printf("\n\n"); -} - -UserData allocateUserData(FILE *input){ - - UserData data; - data = (UserData) malloc(sizeof *data); - - if(!data){ - printf("Allocation Failed!\n"); - return(NULL); - } - setSaneDefaults(data); - - int ier; - - ier=parseNumber(input, "basePts" , MAXBUFLEN, &data->npts); - if(ier==-1 || data->npts<=0){ - printf("Enter non-zero basePts!\n"); - return(NULL); - } - - ier=parseNumber(input, "domainLength", MAXBUFLEN, &data->domainLength); - if(ier==-1 || data->domainLength<=0.0e0){ - printf("domainLength error!\n"); - return(NULL); - } - - ier=parseNumber(input, "Rd", MAXBUFLEN, &data->Rd); - if(ier==-1 || data->Rd<=0.0e0){ - printf("Rd error!\n"); - return(NULL); - } - - ier=parseNumber(input, "constantPressure" , MAXBUFLEN, &data->constantPressure); - if(ier==-1 || (data->constantPressure!=0 && data->constantPressure!=1)){ - printf("constantPressure error!\n"); - return(NULL); - } - - ier=parseNumber(input, "problemType" , MAXBUFLEN, &data->problemType); - if(ier==-1 || (data->problemType!=0 - && data->problemType!=1 - && data->problemType!=2 - && data->problemType!=3)){ - printf("include valid problemType!\n"); - printf("0: premixed combustion with NO equilibrated ignition kernel\n"); - printf("1: premixed combustion WITH equilibrated ignition kernel\n"); - printf("2: arbitrary initial conditions\n"); - printf("3: Restart\n"); - return(NULL); - } - - ier=parseNumber(input, "quasiSteady" , MAXBUFLEN, &data->quasiSteady); - if(ier==-1 || (data->quasiSteady!=0 - && data->quasiSteady!=1)){ - printf("include valid quasiSteady!\n"); - printf("0: The droplet surface recedes and the droplet losses mass\n"); - printf("1: The droplet surface does not move and the droplet mass is constant\n"); - return(NULL); - } - - ier=parseNumber(input, "dPdt" , MAXBUFLEN, &data->dPdt); - - ier=parseNumber(input, "Rg" , MAXBUFLEN, &data->Rg); - if(data->Rg < 0.0){ - printf("Rg must be greater than 0"); - return(NULL); - } - - ier=parseNumber (input, "reflectProblem" , MAXBUFLEN, &data->reflectProblem); - if(data->reflectProblem!=0 && data->reflectProblem!=1){ - printf("Invalid entry for reflectProblem! Can be only 1 or 0.\n"); - return(NULL); - } - - ier=parseNumber(input, "mdot" , MAXBUFLEN, &data->mdot); - - ier=parseNumber(input, "initialTemperature", MAXBUFLEN, - &data->initialTemperature); - if(ier==-1 || data->initialTemperature<=0.0e0){ - printf("Enter positive initialTemperature in K!\n"); - return(NULL); - } - - - ier=parseNumber(input, "initialPressure", MAXBUFLEN, - &data->initialPressure); - if(ier==-1 || data->initialTemperature<=0.0e0){ - printf("Enter positive initialPressure in atm!\n"); - return(NULL); - } - - ier=parseNumber (input, "metric" , MAXBUFLEN, &data->metric); - if(data->metric!=0 && data->metric!=1 && data->metric!=2){ - printf("Invalid entry for metric!\n"); - printf("0: Cartesian\n"); - printf("1: Cylindrical\n"); - printf("2: Spherical\n"); - return(NULL); - } - - ier=parseNumber(input, "QDot", MAXBUFLEN, &data->maxQDot); - if(ier==-1 && data->problemType==0){ - printf("Need to specify QDot for problemType 0!\n"); - return(NULL); - } - - ier=parseNumber(input, "kernelSize", MAXBUFLEN, &data->kernelSize); - if(ier==-1 && data->problemType==0){ - printf("Need to specify kernelSize for problemType 0!\n"); - return(NULL); - } - - ier=parseNumber(input, "ignTime", MAXBUFLEN, &data->ignTime); - if(ier==-1 && data->problemType==0){ - printf("Need to specify ignTime for problemType 0!\n"); - return(NULL); - } - - ier=parseNumber(input, "mixingWidth", MAXBUFLEN, - &data->mixingWidth); - if(ier==-1){ - printf("Need to specify mixingWidth!\n"); - return(NULL); - } - - ier=parseNumber(input, "shift", MAXBUFLEN, &data->shift); - - ier=parseNumber(input, "firstRadius", MAXBUFLEN, &data->firstRadius); - - ier=parseNumber(input, "wallTemperature", MAXBUFLEN, &data->wallTemperature); - - ier=parseNumber (input, "dirichletInner" , MAXBUFLEN, - &data->dirichletInner); - if(data->dirichletInner!=0 && data->dirichletInner!=1){ - printf("dirichletInner can either be 0 or 1!\n"); - return(NULL); - } - - ier=parseNumber (input, "dirichletOuter" , MAXBUFLEN, - &data->dirichletOuter); - if(data->dirichletOuter!=0 && data->dirichletOuter!=1){ - printf("dirichletOuter can either be 0 or 1!\n"); - return(NULL); - } - - ier=parseNumber (input, "adaptiveGrid" , MAXBUFLEN, - &data->adaptiveGrid); - if(ier==-1 || (data->adaptiveGrid!=0 && data->adaptiveGrid!=1)){ - printf("specify adaptiveGrid as 0 or 1!\n"); - return(NULL); - } - - ier=parseNumber (input, "moveGrid" , MAXBUFLEN, - &data->moveGrid); - if(ier==-1 || (data->moveGrid!=0 && data->moveGrid!=1)){ - printf("specify moveGrid as 0 or 1!\n"); - return(NULL); - } - - ier=parseNumber (input, "isotherm" , MAXBUFLEN, - &data->isotherm); - if(ier==-1){ - printf("specify temperature of isotherm!\n"); - return(NULL); - } - - ier=parseNumber(input, "gridOffset", MAXBUFLEN, &data->gridOffset); - - ier=parseNumber (input, "nSaves" , MAXBUFLEN, &data->nSaves); - if(data->nSaves<0 ){ - printf("nSaves must be greater than 0!\n"); - return(NULL); - } - - ier=parseNumber (input, "writeRates" , MAXBUFLEN, - &data->writeRates); - if(data->writeRates!=0 && data->writeRates!=1){ - printf("writeRates must either be 0 or 1!\n"); - return(NULL); - } - - ier=parseNumber (input, "writeEveryRegrid", MAXBUFLEN, - &data->writeEveryRegrid); - if(data->writeEveryRegrid!=0 && data->writeEveryRegrid!=1){ - printf("writeEveryRegrid must either be 0 or 1!\n"); - return(NULL); - } - - ier=parseNumber (input, "setConstraints" , MAXBUFLEN, - &data->setConstraints); - if(data->setConstraints!=0 && data->setConstraints!=1){ - printf("setConstraints must either be 0 or 1!\n"); - return(NULL); - } - - ier=parseNumber (input, "suppressAlg" , MAXBUFLEN, - &data->suppressAlg); - if(data->suppressAlg!=0 && data->suppressAlg!=1){ - printf("suppressAlg must either be 0 or 1!\n"); - return(NULL); - } - - ier=parseNumber (input, "dryRun" , MAXBUFLEN, - &data->dryRun); - if(data->dryRun!=0 && data->dryRun!=1){ - printf("dryRun must either be 0 or 1!\n"); - return(NULL); - } - - ier=parseNumber (input, "finalTime" , MAXBUFLEN, - &data->finalTime); - - ier=parseNumber (input, "relativeTolerance" , MAXBUFLEN, - &data->relativeTolerance); - ier=parseNumber (input, "radiusTolerance" , MAXBUFLEN, - &data->radiusTolerance); - ier=parseNumber (input, "temperatureTolerance", MAXBUFLEN, - &data->temperatureTolerance); - ier=parseNumber (input, "pressureTolerance", MAXBUFLEN, - &data->pressureTolerance); - ier=parseNumber (input, "massFractionTolerance", MAXBUFLEN, - &data->massFractionTolerance); - ier=parseNumber (input, "bathGasTolerance", MAXBUFLEN, - &data->bathGasTolerance); - ier=parseNumber (input, "MdotTolerance", MAXBUFLEN, - &data->MdotTolerance); - - char chem[MAXBUFLEN],mix[MAXBUFLEN],tran[MAXBUFLEN]; - - ier=parseNumber(input, "chemistryFile" , MAXBUFLEN, chem); - if(ier==-1){ - printf("Enter chemistryFile!\n"); - return(NULL); - }else{ - try{ - data->gas = new Cantera::IdealGasMix(chem); - data->nsp=data->gas->nSpecies(); //assign no: of species - - } catch (Cantera::CanteraError& err) { - printf("Error:\n"); - printf("%s\n",err.what()); - return(NULL); - } - } - - ier=parseNumber(input, "transportModel", MAXBUFLEN, tran); - if(ier==-1){ - printf("Enter transportModel!\n"); - return(NULL); - }else{ - try{ - data->trmix = Cantera::newTransportMgr(tran, data->gas); - }catch (Cantera::CanteraError& err) { - printf("Error:\n"); - printf("%s\n",err.what()); - return(NULL); - } - } - - ier=parseNumber(input, "mixtureComposition", MAXBUFLEN, mix); - if(ier==-1){ - printf("Enter mixtureComposition!\n"); - return(NULL); - }else{ - if(data->gas!=NULL){ - try{ - data->gas->setState_TPX(data->initialTemperature, - data->initialPressure*Cantera::OneAtm, - mix); - }catch (Cantera::CanteraError& err) { - printf("Error:\n"); - printf("%s\n",err.what()); - return(NULL); - } - } - } - - //ier=parseNumber(input, "dropletComposition", MAXBUFLEN, data->dropSpec); - //if(ier==-1){ - // printf("Enter composition of droplet!\n"); - // return(NULL); - //} - - ier=parseDrop(input,"dropletComposition",data->dropSpec,data->dropMole,MAXBUFLEN); - ier=parseDrop(input,"dropletDensity",data->dropSpec,data->dropDens,MAXBUFLEN); - - - ier=parseNumber (input, "nThreads", MAXBUFLEN, &data->nThreads); - if(data->nThreads<0 ){ - printf("nThreads must be greater than 0!\n"); - return(NULL); - } - - - ier=parseNumber(input, "PCAD", MAXBUFLEN, &data->PCAD); - ier=parseNumber(input,"RGTC", MAXBUFLEN, &data->RGTC); - ier=parseNumber(input,"JJRG", MAXBUFLEN, &data->JJRG); - ier=parseNumber(input,"deltaT", MAXBUFLEN, &data->deltaT); - - data->nr=0; - //data->np=data->nr+1; - data->nt=data->nr+1; - data->ny=data->nt+1; - data->np=data->ny+data->nsp; - data->nm=data->np+1; - - data->nvar=data->nsp+4; //assign no: of variables (R,T,P,Mdot,nsp species) - - - double MW[2]; - for(int i=0;i<=1;i++){ - int speciesIndex = data->gas->speciesIndex(data->dropSpec[i]); - double weight = data->gas->molecularWeight(speciesIndex); - MW[i]= weight; - } - - double massSum = 0.0; - for(int i=0;i<=1;i++){ - massSum = massSum + data->dropMole[i] * MW[i]; - } - data->dropRho = 0.0; - for(int i=0;i<=1;i++){ - data->dropMassFrac[i] = data->dropMole[i]*MW[i]/massSum; - data->dropRho = data->dropRho + data->dropMassFrac[i]*data->dropDens[i]; - } - printf("Density of droplet is: %.3f [kg/m^3]\n",data->dropRho); - //Mass of droplet - //data->massDrop=1.0/3.0*pow(data->Rd,3)*997.0; //TODO: The density of the droplet should be a user input - //data->massDrop=1.0/3.0*pow(data->Rd,3)*684.00; //TODO: The density of the droplet(n-heptane) should be a user input - data->massDrop=1.0/3.0*pow(data->Rd,3)*data->dropRho; - - if(!data->adaptiveGrid){ - data->uniformGrid = new double [data->npts]; - data->neq=data->nvar*data->npts; - } - else{ - data->grid=(UserGrid) malloc(sizeof *data->grid); - ier=getGridSettings(input,data->grid); - if(ier==-1)return(NULL); - - ier=initializeGrid(data->grid); - if(ier==-1)return(NULL); - - ier=reGrid(data->grid, data->grid->position); - if(ier==-1)return(NULL); - - -// /**************** TEST THE data->grid->xOld *******************/ -// double* ptr = data->grid->xOld ; -// printf("allocateUserData function is called,Start print the first 5 elements of the xOld array : \n"); -// printf("1st:%.6f, 2nd:%.6f, 3rd:%.6f, 4th:%.6f, 5th:%.6f.\n",ptr[0],ptr[1],ptr[2],ptr[3],ptr[4]); - - data->npts=data->grid->nPts; - data->neq=data->nvar*data->npts; - } - - data->output=fopen("output.dat","w"); - data->globalOutput=fopen("globalOutput.dat","w"); - data->gridOutput=fopen("grid.dat","w"); - data->timescaleOutput=fopen("timeScale.dat","w") ; - data->rxnROPOutput=fopen("rxnROP.dat","w"); - data->spROPOutput=fopen("spROP.dat","w"); - //data->ratesOutput=fopen("rates.dat","w"); - - data->innerMassFractions = new double [data->nsp]; - //data->wdot_mole = new double [data->nsp] ; - //data->wdot_mass = new double [data->nsp] ; - data->time_scale = new double [(data->npts) * (data->nsp)] ; - //data->MW = new double [data->nsp] ; - - return(data); -} - -void setSaneDefaults(UserData data){ - data->domainLength=1.0e-02; - data->Rd=100.0e-06; - data->constantPressure=1; - data->problemType=1; - data->quasiSteady=1; - data->dPdt=0.0e0; - data->reflectProblem=0; - data->mdot=0.0; - data->initialTemperature=300.0; - data->initialPressure=1.0; - data->metric=0; - data->ignTime=1e-09; - data->maxQDot=0.0e0; - data->maxTemperature=300.0e0; - data->mixingWidth=1e-04; - data->shift=3.0e-03; - data->firstRadius=1e-04; - data->wallTemperature=298.0e0; - data->dirichletInner=0; - data->dirichletOuter=0; - data->adaptiveGrid=0; - data->moveGrid=0; - data->gridOffset=0.0e0; - data->Rg=1.0; - data->isotherm=1000.0; - data->nSaves=30; - data->writeRates=0; - data->writeEveryRegrid=0; - data->relativeTolerance=1e-06; - data->radiusTolerance=1e-08; - data->temperatureTolerance=1e-06; - data->pressureTolerance=1e-06; - data->massFractionTolerance=1e-09; - data->bathGasTolerance=1e-06; - data->finalTime=1e-02; - data->tNow=0.0e0; - data->setConstraints=0; - data->suppressAlg=1; - data->regrid=0; - data->gridDirection=1; - data->dryRun=0; - data->nThreads=1; - - data->flamePosition[0]=0.0e0; - data->flamePosition[1]=0.0e0; - data->flameTime[0]=0.0e0; - data->flameTime[1]=0.0e0; - data->nTimeSteps=0; - data->PCAD=0.75; - data->RGTC=1.0; - data->JJRG=0; - data->deltaT=200.0; -} - diff --git a/UserData.d b/UserData.d deleted file mode 100644 index 7531ae1..0000000 --- a/UserData.d +++ /dev/null @@ -1,63 +0,0 @@ -UserData.o: UserData.cpp UserData.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/IdealGasMix.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/IdealGasPhase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/ThermoPhase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/Phase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ctexceptions.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/fmt.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ct_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/config.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/format.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/core.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/format-inl.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/format.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/printf.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/ostream.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/ostream.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/Elements.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ct_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/Species.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/AnyMap.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/global.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/AnyMap.inl.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ValueCache.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/MultiSpeciesThermo.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/SpeciesThermoInterpType.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/speciesThermoTypes.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/GasKinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/BulkKinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Kinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/ThermoPhase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/StoichManager.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/stringUtils.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Reaction.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/utilities.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/global.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/RxnRates.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/reaction_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Falloff.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/RateCoeffMgr.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/RxnRates.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/ThirdBodyCalc.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/FalloffMgr.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/reaction_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/FalloffFactory.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/FactoryBase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Reaction.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/importKinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/stringUtils.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportFactory.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportBase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LiquidTransportParams.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportParams.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/numerics/DenseMatrix.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/Array.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/utilities.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LiquidTranInteraction.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LiquidTransportData.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LTPspecies.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportData.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/xml.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ctexceptions.h \ - gridRoutines.h parse.h parse.hpp diff --git a/UserData.h b/UserData.h deleted file mode 100644 index ff713c4..0000000 --- a/UserData.h +++ /dev/null @@ -1,221 +0,0 @@ -#ifndef CANTERA_DEF -#define CANTERA_DEF -#include -#include -#endif - -#include "gridRoutines.h" -#include - -#ifndef USER_DEF -#define USER_DEF -typedef struct UserDataTag{ - /*An ideal gas object from Cantera. Contains thermodynamic and kinetic - * info of all species.*/ - Cantera::IdealGasMix* gas; - /*A Transport object from Cantera. Contains all transport info of all - * species.*/ - Cantera::Transport* trmix; - /* Droplet species composition */ - //char dropSpec[MAXBUFLEN]; - char dropSpec[2][10]; - /* Droplet species mole fractions */ - double dropMole[2]; - /* Droplet species density at given initialTemperature*/ - double dropDens[2]; - /* Droplet species mass fractions*/ - double dropMassFrac[2]; - double dropRho; - /*Length of the domain (in meters):*/ - double domainLength; - /*Initial Droplet Radius (in meters)*/ - double Rd; - /*Droplet Mass*/ - double massDrop; - /*Mass of gas in domain (in kg):*/ - double mass; - /*Parameter that indicates the symmetry of the problem;*/ - /*metric=0:Planar*/ - /*metric=1:Cylindrical*/ - /*metric=2:Spherical*/ - int metric; - /*No: of species:*/ - size_t nsp; - /*No: of equations:*/ - size_t neq; - /*No: of variables:*/ - size_t nvar; - /*Pointer indices (see "macros.h" for aliases that use these):*/ - /*Pointer index for temperature:*/ - size_t nt; - /*Pointer index for species:*/ - size_t ny; - /*Pointer index for spatial coordinate:*/ - size_t nr; - /*Pointer index for pressure:*/ - size_t np; - /*Pointer index for mass flow rate:*/ - size_t nm; - /*Species index of bath gas:*/ - size_t k_bath; - /*Species index of oxidizer:*/ - size_t k_oxidizer; - size_t k_OH; - size_t k_HO2; - /*Species index of droplet composition*/ - /*Index starts with 1 instead of 0*/ - size_t k_drop[2]; - /*User-defined mass flux (kg/m^2/s):*/ - double mdot; - /*Flag to solve isobaric/isochoric problem;*/ - /*constantPressure=1: isobaric*/ - /*constantPressure=0: isochoric*/ - int constantPressure; - /*User-defined dPdt (Pa/s), activates when problem is "isobaric":*/ - double dPdt; - /*Initial temperature of the gas (K):*/ - double initialTemperature; - /*Initial Pressure of the gas (atm):*/ - double initialPressure; - /*Classification of problem type;*/ - /*problemType=0: Mixture is premixed and spatially uniform initially. - * In order for mixture to ignite, an external heat source (finite - * maxQDot) must be used.*/ - /*problemType=1: Mixture is premixed but spatially non-uniform - * initially. Equilibrium products are contained within a hot kernel of - * size given by "shift" and a mixing length scale given by - * "mixingWidth".*/ - /*problemType=2: User specified initial condition. Use file - * "initialCondition.dat".*/ - int problemType; - /*Quasi-Steady Assumption: - *quasiSteady=0: The droplet surface recedes and the droplet losses mass. - *quasiSteady=1: The droplet surface does not move and the droplet mass is constant.*/ - int quasiSteady; - /*Maximum External heat source (K/s):*/ - double maxQDot; - /*Ignition kernel size:*/ - double kernelSize; - - double maxTemperature; - /*Maximum time for which the external heat source is applied (s):*/ - double ignTime; - /*Vector of Mass Fractions used to impose Robin Boundary Condition for - * species at the domain origin:*/ - double* innerMassFractions; - /*Value of temperature to be used if Dirichlet Boundary Conditions are - * imposed for temperature:*/ - double innerTemperature; - double wallTemperature; - /*Isotherm chosen to find the location of a "burning" front (K):*/ - double isotherm; - /*Interval of time integration:*/ - double finalTime; - /*Current time:*/ - double tNow; - /*Flag to reflect initial conditions across center of the domain:*/ - int reflectProblem; - /*Parameters for initial conditions in setting up profiles: - increasing function of x: g=0.5*(erf(x-3*w-shift)/w)+1) - decreasing function of x: f=1-g*/ - double mixingWidth; - double shift; - double firstRadius; - /*Flag to run program without time-integration i.e. simply layout the - * initial conditions and quit:*/ - int dryRun; - /*Relative Tolerance:*/ - double relativeTolerance; - /*Absolute Tolerance for spatial coordinate:*/ - double radiusTolerance; - /*Absolute Tolerance for Temperature:*/ - double temperatureTolerance; - /*Absolute Tolerance for Pressure:*/ - double pressureTolerance; - /*Absolute Tolerance for Mass Fractions:*/ - double massFractionTolerance; - /*Absolute Tolerance for bath gas mass fraction:*/ - double bathGasTolerance; - /*Absolute Tolerance for Mdot:*/ - double MdotTolerance; - /*Flag to set constraints on Mass fractions so they don't acquire - * negative values:*/ - int setConstraints; - /*Flag to suppress error checking on algebraic variables:*/ - int suppressAlg; - /*Number of time-steps elapsed before saving the solution:*/ - int nSaves; - /*Flag to set write for every regrid:*/ - int writeEveryRegrid; - /*Solution output file:*/ - FILE* output; - /*Flag to write the rates (ydot) of solution components into the - * "ratesOutput" file:*/ - int writeRates; - /*Grid output file:*/ - FILE* gridOutput; - ///*Rate of change (ydot) output file (see "writeRates"):*/ - //FILE* ratesOutput; - /*Global properties (mdot, radius of flame, etc.) output file:*/ - FILE* globalOutput; - - /*Flag to adapt grid:*/ - int adaptiveGrid; - /*Flag to move grid:*/ - int moveGrid; - /*Flag to initiate regrid:*/ - int regrid; - /*Integer that specifies grid movement direction: - * gridDirection = -1: Move Left - * gridDirection = +1: Move Right*/ - int gridDirection; - - /*Grid Ratio: This replaces the uniform grid. dX0 and dXf are the grid - spacing at the droplet surface and right boundary, respectivly. The Grid - Ratio is equal to dXf/dX0. A Rg>1 focuses grid points on the droplet - surface while a Rg<1 focuses grid points at the right boundary. A Rg of 1 - is a uniform grid.*/ - double Rg; - /*Total number of points for grid:*/ - size_t npts; - - double gridOffset; - - UserGrid grid; - double* uniformGrid; - - int dirichletInner,dirichletOuter; - - int nThreads; - double clockStart; - - /*These arrays are used to compute dr/dt, which in turn is used to - * compute the flame speed S_u:*/ - double flamePosition[2]; - double flameTime[2]; - size_t nTimeSteps; - - /*Following arrays are used to compute the characteristic time scale of - species*/ - //double* wdot_mole ; - //double* wdot_mass ; - double* time_scale ; - //double* MW; - FILE* timescaleOutput; - - /*Following parameters are used for REGRID function*/ - double PCAD; - double RGTC; - int JJRG; - double deltaT; - - FILE* rxnROPOutput; - FILE* spROPOutput; - - -} *UserData; -UserData allocateUserData(FILE *input); -void setSaneDefaults(UserData data); -void freeUserData(UserData data); -#endif - diff --git a/UserData.o b/UserData.o deleted file mode 100644 index ab3b26a..0000000 Binary files a/UserData.o and /dev/null differ diff --git a/gridRoutines.cpp b/gridRoutines.cpp deleted file mode 100644 index 6f6107b..0000000 --- a/gridRoutines.cpp +++ /dev/null @@ -1,293 +0,0 @@ -#include "gridRoutines.h" -#include - -inline double l(const double* x, - const double* a, - const double* w, - const double* fac, - const int* refineLeft){ - if(*refineLeft==0){ - return(tanh(-*a*(*x+*w*100.0e0))); - }else{ - double l ; - l = tanh(-*a*(*x-*w*(*fac))) ; - - if(l>=0){ - return l*10.0; - }else{ - //return(tanh(-*a*(*x-*w*(*fac)))); - return l; - } - } -} - -//inline double l(const double* x, -// const double* a, -// const double* c, -// const double* w, -// const double* fac, -// const int* refineLeft){ -// if(*refineLeft==0){ -// return(tanh(-*a*(*x+*w*100.0e0))); -// }else{ -// double l ; -// //l = tanh(-*a*(*x-*w*(*fac))) ; -// l = tanh(-*a*(*x-*c)); -// -// if(l>=0){ -// return l*10.0; -// }else{ -// //return(tanh(-*a*(*x-*w*(*fac)))); -// return l; -// } -// } -//} - -inline double r(const double* x, - const double* a, - const double* w, - const double* fac, - const int* refineRight){ - if(*refineRight==0){ - return(tanh(*a*(*x-(1.0e0+*w*100.0e0)))); - }else{ - return(tanh(*a*(*x-(1.0e0-*w*(*fac))))); - } -} - -inline double f(const double* x, - const double* a, - const double* c, - const double* w){ - return(tanh(-*a*(*x-(*c+*w))) - +tanh(-*a*((*x-1.0e0)-(*c+*w))) - +tanh(-*a*((*x+1.0e0)-(*c+*w)))); -} - -inline double g(const double* x, - const double* a, - const double* c, - const double* w){ - return(tanh(*a*(*x-(*c-*w))) - +tanh(*a*((*x-1.0e0)-(*c-*w))) - +tanh(*a*((*x+1.0e0)-(*c-*w)))); -} - -inline double rho(const double* x, - const double* a, - const double* c, - const double* w, - const double* mag, - const double* leftFac, - const double* rightFac, - const int* refineLeft, - const int* refineRight){ - - return(((2.0e0+f(x,a,c,w) - +g(x,a,c,w) - +l(x,a,w,leftFac,refineLeft) -// +l(x,a,c,w,leftFac,refineLeft) - +r(x,a,w,rightFac,refineRight))*0.5e0) - *(*mag-1.0e0)+1.0e0); -} - -size_t maxPoints(const size_t basePts, - const double* a, - const double* w, - const double* mag, - const double* leftFac, - const double* rightFac, - const int* refineLeft, - const int* refineRight){ - double dx=1.0e0/((double)(basePts)-1.0e0); - double y=0.0e0; - size_t i=0; - double r=0.0e0; - double t=0.5e0; - while(y<=1.0e0){ - r=rho(&y,a,&t,w,mag,leftFac,rightFac,refineLeft,refineRight); - y=y+(dx/r); - i++; - } - return(i); -} - -void fillGrid(const size_t* basePts, - const size_t* nPts, - const double* a, - const double* c, - const double* w, - const double* mag, - const double* leftFac, - const double* rightFac, - const int* refineLeft, - const int* refineRight, - double x[]){ - - FILE* out;out=fopen("tmp.dat","w"); - - double y=0.0e0; - double r=0.0e0; - double dx=1.0e0/((double)(*basePts)-1.0e0); - for(size_t j=0;j<*nPts;j++){ - r=rho(&y,a,c,w,mag,leftFac,rightFac,refineLeft,refineRight); // Point density? - fprintf(out, "%15.15e\n",dx/r); // writing number of points per section to tmp.dat - y=y+(dx/r); // y is the total number of points? - } - fclose(out); - - double dxp[*nPts-1]; - for (size_t j = 0; j < *nPts; j++) { - dxp[j]=0.0e0; - } - - FILE* tmp;tmp=fopen("tmp.dat","r"); - char buf[MAXBUFLEN]; - size_t i=0; - while (fgets(buf,MAXBUFLEN, tmp)!=NULL){ - sscanf(buf, "%lf", &y); - dxp[i]=y; - i++; - } - fclose(tmp); - - double sum=0.0e0; - double err=0.0e0; - double fix=0.0e0; - double arr[*nPts-1] ; - size_t halfboundII = 0; - for(size_t j=0;j<*nPts-1;j++){ - sum+=dxp[j]; - arr[j]=sum; - } - - for(size_t j=0;j<*nPts;j++){ - if(arr[j] > 0.5e0){ - halfboundII = j; - break; - } - } - - err=1.0e0-sum; - printf("sum before correction: %15.6e\n",sum); - printf("err before correction: %15.6e\n",err); - - //fix=err/((double)(*nPts)); - fix = err/((double)(*nPts-1-(halfboundII+1))); - - sum=0.0e0; - for(size_t j=0;j<*nPts-1;j++){ - // dxp[j]+=fix; - if(j>halfboundII){ - dxp[j]=dxp[j]+fix ; - } - sum+=dxp[j]; - } - err=1.0e0-sum; - printf("sum after correction:%15.6e\n",sum); - printf("err after correction: %15.6e\n",err); - - x[0]=0.0e0; - for(size_t j=0;j<*nPts-1;j++){ - x[j+1]=x[j]+dxp[j]; - } - x[*nPts-1]=1.0e0; - -} - -double safePosition(double c, double w){ - if(c1.0e0-w){ - return(1.0e0-w); - } - else{ - return(c); - } -} - -int reGrid(UserGrid grid, double position){ - - printf("before regrid: %ld\n", grid->nPts); - double xx[grid->nPts]; - - fillGrid(&grid->basePts, - &grid->nPts, - &grid->a, - &position, - &grid->w, - &grid->mag, - &grid->leftFac, - &grid->rightFac, - &grid->refineLeft, - &grid->refineRight, - xx); - - for (size_t i = 0; i < grid->nPts; i++) { - grid->x[i]=xx[i]; - } - return(0); -} - -void storeGrid(const double* x, double *y, const size_t nPts){ - for(size_t i=0;inPts=maxPoints(grid->basePts, - &grid->a, - &grid->w, - &grid->mag, - &grid->leftFac, - &grid->rightFac, - &grid->refineLeft, - &grid->refineRight); - printf("nPts: %ld\n",grid->nPts); - grid->leastMove=grid->w; - - grid->x = new double [grid->nPts]; - grid->xOld = new double [grid->nPts]; - for (size_t i = 0; i < grid->nPts; i++) { - grid->x[i]=0.0e0; - grid->xOld[i]=0.0e0; - } - return(0); -} - -int getGridSettings(FILE *input, UserGrid grid){ - - int ier=0; - - ier=parseNumber(input, "basePts" , MAXBUFLEN, &grid->basePts); - if(ier==-1)return(-1); - - ier=parseNumber(input, "gridDensitySlope", MAXBUFLEN, &grid->a); - if(ier==-1)return(-1); - - ier=parseNumber(input, "fineGridHalfWidth", MAXBUFLEN, &grid->w); - if(ier==-1)return(-1); - - ier=parseNumber(input, "gridRefinement", MAXBUFLEN, &grid->mag); - if(ier==-1)return(-1); - - ier=parseNumber(input, "leftRefineFactor", MAXBUFLEN, &grid->leftFac); - if(ier==-1)return(-1); - - ier=parseNumber(input, "rightRefineFactor", MAXBUFLEN, &grid->rightFac); - if(ier==-1)return(-1); - - ier=parseNumber(input, "refineLeft" , MAXBUFLEN, &grid->refineLeft); - if(ier==-1)return(-1); - - ier=parseNumber(input, "refineRight" , MAXBUFLEN, &grid->refineRight); - if(ier==-1)return(-1); - - ier=parseNumber(input, "position" , MAXBUFLEN, &grid->position); - if(ier==-1)return(-1); - - return(0); -} - diff --git a/gridRoutines.d b/gridRoutines.d deleted file mode 100644 index 80fc6ad..0000000 --- a/gridRoutines.d +++ /dev/null @@ -1 +0,0 @@ -gridRoutines.o: gridRoutines.cpp gridRoutines.h parse.h parse.hpp diff --git a/gridRoutines.h b/gridRoutines.h deleted file mode 100644 index 9352fd7..0000000 --- a/gridRoutines.h +++ /dev/null @@ -1,89 +0,0 @@ -#include "parse.h" - -#ifndef GSL_DEF -#define GSL_DEF -#include -#include -#endif - -#ifndef GRID_DEF -#define GRID_DEF - -typedef struct gridTag{ - - size_t basePts; - size_t nPts; - double position; - double leastMove; - double a; - double w; - double mag; - double leftFac; - double rightFac; - int refineLeft; - int refineRight; - double* x; - double* xOld; - -} *UserGrid; - -inline double l(const double* x, - const double* a, - const double* w, - const double* fac, - const int* refineLeft); - -//inline double l(const double* x, -// const double* a, -// const double* c, -// const double* w, -// const double* fac, -// const int* refineLeft); - -inline double r(const double* x, - const double* a, - const double* w, - const double* fac, - const int* refineRight); - -inline double f(const double* x, - const double* a, - const double* c, - const double* w); - -inline double g(const double* x, - const double* a, - const double* c, - const double* w); - -inline double rho(const double* x, - const double* a, - const double* c, - const double* w, - const double* mag, - const double* leftFac, - const double* rightFac, - const int* refineLeft, - const int* refineRight); - -size_t maxPoints(const size_t basePts, - const double* a, - const double* w, - const double* mag, - const double* leftFac, - const double* rightFac, - const int* refineLeft, - const int* refineRight); - - -double safePosition(double c, double w); - -int reGrid(UserGrid grid, double position); - -void storeGrid(const double* x, double *y, const size_t nPts); - -int initializeGrid(UserGrid grid); - -int getGridSettings(FILE *input, UserGrid grid); - -#endif diff --git a/gridRoutines.o b/gridRoutines.o deleted file mode 100644 index b397aa2..0000000 Binary files a/gridRoutines.o and /dev/null differ diff --git a/include/UserData.h b/include/UserData.h index a5b8acb..5f21874 100644 --- a/include/UserData.h +++ b/include/UserData.h @@ -34,11 +34,13 @@ typedef struct UserDataTag{ /* Current version only support single and binary component(s) droplet */ int dropType; /* Droplet species gamma using UNIFAC method */ - double gamma[2]; - /* Droplet species composition */ + std::vector gamma; + /* Droplet species composition, C3H8,n-C7H16,etc.*/ std::vector dropSpec; + /*droplet initial species mole fractions*/ std::vector dropMole; - //char dropSpec[2][10] = {"propane","n-heptane"}; + /*droplet species molecular weight*/ + std::vector MW; /* Droplet species mole fractions */ //double dropMoleFrac[2]; @@ -55,8 +57,10 @@ typedef struct UserDataTag{ /*metric=0:Planar*/ /*metric=1:Cylindrical*/ /*metric=2:Spherical*/ - int metric; - /*No: of species:*/ + int metric; + /* Gas phase relevent #s and Pointer index */ + /* Variables to be solved in the gas phase: T,Yi,r,P,mdot */ + /*No: of species in the gas phase:*/ size_t nsp; /*No: of equations:*/ size_t neq; @@ -73,6 +77,25 @@ typedef struct UserDataTag{ size_t np; /*Pointer index for mass flow rate:*/ size_t nm; + + /*No: of species in the liquid phase:*/ +// size_t l_nsp; + // /*No: of equations:*/ + // size_t l_neq; + // /*No: of variables:*/ + // size_t l_nvar; + // /*Pointer indices (see "macros.h" for aliases that use these):*/ + // /*Pointer index for temperature:*/ + // size_t l_nt; + // /*Pointer index for species:*/ + // size_t l_ny; + // /*Pointer index for spatial coordinate:*/ + // size_t l_nr; + // /*Pointer index for pressure:*/ + // size_t l_np; + // /*Pointer index for mass flow rate:*/ + // size_t l_nm; + /*Species index of bath gas:*/ size_t k_bath; /*Species index of oxidizer:*/ @@ -81,7 +104,8 @@ typedef struct UserDataTag{ size_t k_HO2; /*Species index of droplet composition*/ /*Index starts with 1 instead of 0*/ - size_t k_drop[2]; + /*Similar to dropMole and dropSpec,size of k_drop should be based on droplet type*/ + std::vector k_drop; /*User-defined mass flux (kg/m^2/s):*/ double mdot; /*Flag to solve isobaric/isochoric problem;*/ @@ -195,6 +219,10 @@ typedef struct UserDataTag{ double Rg; /*Total number of points for grid:*/ size_t npts; + /*Number of points for liquid phase:*/ + size_t l_npts; + /*Number of points for gas phase:*/ + size_t g_npts; double gridOffset; @@ -236,5 +264,5 @@ void setSaneDefaults(UserData data); void freeUserData(UserData data); #endif -void getGamma(const double mole[],double gamma[]) ; +void getGamma(const std::vector& mole,std::vector& gamma) ; diff --git a/include/parse.h b/include/parse.h index 92aebf0..ff42390 100644 --- a/include/parse.h +++ b/include/parse.h @@ -1,3 +1,5 @@ +#pragma once + #ifndef PRINT_DEF #define PRINT_DEF #include //for strings @@ -12,7 +14,7 @@ #include #include -#ifndef PARSE_DEF ``` +#ifndef PARSE_DEF #define PARSE_DEF #define MAXBUFLEN 200 @@ -30,12 +32,101 @@ template int parseArray(FILE* input, const char* keyword, const size_t bufLen, const size_t arrLen, T y[]); +// +///*template function for parsing initial mole fraction in the droplet*/ +//template +//int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector& dropPara){ +// char buf[bufLen]; +// char buf1[bufLen]; +// char comment[1]; +// char *ret; +// +// while (fgets(buf,bufLen, input)!=NULL){ +// comment[0]=buf[0]; +// if(strncmp(comment,"#",1)==0){ +// //printf("Comment!:%s\n",buf); +// } +// else{ +// ret=strtok(buf,"="); +// if(strcmp(ret,keyword)==0){ +// /*offset buf by keyword size + 1 for the "="*/ +// /* Second argument in the strncpy function is the address !!! */ +// /* Note: current version of code can only take dropType =0 or 1 */ +// strncpy(buf1, buf+strlen(keyword)+1, bufLen); +// printf("%10s: ",keyword); +// if(*dropType ==0){ +// /* Convert from char* to double */ +//// std::string str(buf1); +//// dropPara.push_back(str); +// T temp_num = std::stod(buf1) ; +// dropPara.push_back(temp_num) ; +// printf("%.3f\n",dropPara[0]); +// }else{ +// std::istringstream iss(buf1) ; +// std::string token; +// while(std::getline(iss,token,',')){ +// T temp_num = std::stod(token); +// dropPara.push_back(temp_num); +// } +// printf("%.3f,%.3f\n",dropPara[0],dropPara[1]); +// } +// rewind(input); +// return(0); +// } +// } +// } +// rewind(input); +// return(-1); +//} -template -int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,int* dropType, std::vector& dropPara); +/* Extract the droplet species and molefractions from input file using template */ +/* Generic template function */ +//template +//int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector& dropPara){ +// char buf[bufLen]; +// char buf1[bufLen]; +// char comment[1]; +// char *ret; +// T* n; +// +// while (fgets(buf,bufLen, input)!=NULL){ +// comment[0]=buf[0]; +// if(strncmp(comment,"#",1)==0){ +// //printf("Comment!:%s\n",buf); +// } +// else{ +// ret=strtok(buf,"="); +// if(strcmp(ret,keyword)==0){ +// /*offset buf by keyword size + 1 for the "="*/ +// /* Second argument in the strncpy function is the address !!! */ +// /* Note: current version of code can only take dropType =0 or 1 */ +// strncpy(buf1, buf+strlen(keyword)+1, bufLen); +// printf("%10s: ",keyword); +// if(*dropType ==0){ +// getFromString(buf1,n); +// dropPara.push_back(*n); +// }else{ +// std::istringstream iss(buf1) ; +// std::string token; +// while(std::getline(iss,token,',')){ +// T arg = std::stod(token); +// dropPara.push_back(arg); +// } +// printf("%15.6e,%15.6e\n",dropPara[0],dropPara[1]); +// } +// rewind(input); +// return(0); +// } +// } +// } +// rewind(input); +// return(-1); +//} -template<> -int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,int* dropType, std::vector& dropPara); +// +///* Specialization for string */ +//template<> +//int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector& dropPara); int parseDrop(FILE* input, const char* keyword,char dropSpec[][10],double dropMole[],const size_t bufLen); diff --git a/include/parse.hpp b/include/parse.hpp index 247ab60..52363ca 100644 --- a/include/parse.hpp +++ b/include/parse.hpp @@ -1,3 +1,5 @@ +#pragma once + template int parseNumber(FILE* input, const char* keyword, const size_t bufLen, T* n){ @@ -83,7 +85,7 @@ int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const in char buf1[bufLen]; char comment[1]; char *ret; - T* n; + T n; while (fgets(buf,bufLen, input)!=NULL){ comment[0]=buf[0]; @@ -99,8 +101,8 @@ int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const in strncpy(buf1, buf+strlen(keyword)+1, bufLen); printf("%10s: ",keyword); if(*dropType ==0){ - getFromString(buf1,n); - dropPara.push_back(*n); + getFromString(buf1,&n); + dropPara.push_back(n); }else{ std::istringstream iss(buf1) ; std::string token; @@ -108,7 +110,7 @@ int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const in T arg = std::stod(token); dropPara.push_back(arg); } - printf("%15.6e,%15.6e\n",dropPara[0],dropPara[1]); + printf("%.3f,%.3f\n",dropPara[0],dropPara[1]); } rewind(input); return(0); @@ -121,5 +123,52 @@ int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const in /* Specialization for string */ template<> -int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector& dropPara); +inline int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector& dropPara){ + char buf[bufLen]; + char buf1[bufLen]; + char comment[1]; + char *ret; + while (fgets(buf,bufLen, input)!=NULL){ + buf[strlen(buf)-1] = '\0' ; + comment[0]=buf[0]; + if(strncmp(comment,"#",1)==0){ + //printf("Comment!:%s\n",buf); + } + else{ + ret=strtok(buf,"="); + if(strcmp(ret,keyword)==0){ + /*offset buf by keyword size + 1 for the "="*/ + /* Second argument in the strncpy function is the address !!! */ + /* Note: current version of code can only take dropType =0 or 1 */ + strncpy(buf1, buf+strlen(keyword)+1, bufLen); + printf("%10s: ",keyword); + if(*dropType ==0){ + /* Convert from char* to string */ + //printf("buf1 is %s!\n",buf1) ; + std::string str; + for(int i=0;i< strlen(buf1);i++){ + if(buf1[i] != ' '){ + str += buf1[i] ; + } + } +// printf("str is :%s!\n",str.c_str()) ; + dropPara.push_back(str); + printf("%s.\n",dropPara[0].c_str()); + }else{ + std::istringstream iss(buf1) ; + std::string token; + while(std::getline(iss,token,',')){ + //std::stod(token); + dropPara.push_back(token); + } + printf("%s!,%s!\n",dropPara[0].c_str(),dropPara[1].c_str()); + } + rewind(input); + return(0); + } + } + } + rewind(input); + return(-1); +} diff --git a/include/residue.h b/include/residue.h index b4e325f..bb122d1 100644 --- a/include/residue.h +++ b/include/residue.h @@ -28,6 +28,7 @@ #include "UserData.h" #include //add the vector module +#include void REGRID(double* ydata,double* ydotdata,UserData data); @@ -67,11 +68,14 @@ inline double calc_area(double x,int* i); void updateSolution(double* y, double* ydot, const size_t nvar, const double xOld[],const double xNew[],const size_t npts); -void readInitialCondition(FILE* input, double* ydata, const size_t nvar, const size_t nr, const size_t nPts); +//void readInitialCondition(FILE* input, double* ydata, const size_t nvar, const size_t nr, const size_t nPts); + +void readInitialCondition(FILE* input, double* ydata, const size_t nvar, const size_t nr, const size_t nPts, const size_t l_nPts, double Rg); double systemMass(double* ydata, UserData data); int initializePsiGrid(double* ydata, double* psidata, UserData data); +int initializePsiEtaGrid(double* ydata, double* psidata, UserData data); int setInitialCondition(N_Vector* y, N_Vector* ydot, @@ -86,7 +90,10 @@ void getTransport(UserData data, double *rho, double *lambda, double *YV); - +void getGasMassFlux(UserData data, + double *ydata, + size_t gridPoint, + double* YV) ; int residue(double t, N_Vector y, N_Vector ydot, @@ -97,6 +104,7 @@ void trackFlameOH(N_Vector y,UserData data); void trackFlame(N_Vector y,UserData data); size_t BathGasIndex(UserData data); size_t oxidizerIndex(UserData data); +size_t specIndex(UserData data,const char *specName); inline double Qdot(double* t, double* x, @@ -123,7 +131,34 @@ void resetTolerance(UserData data, N_Vector* y,N_Vector* atolv); void getReactions(UserData data,N_Vector* y,FILE* output); void getSpecies(UserData data,N_Vector* y,FILE* output); -double getLiquidRho(double dropMole[],double temp,double pres); -double getLiquidCp(double dropMole[],double temp,double pres); -double getLiquidHv(double dropMole[],double temp,double pres); -double getLiquidMaxT(double dropMole[],double pres); \ No newline at end of file +//double getLiquidRho(double dropMole[],double temp,double pres); +//double getLiquidCp(double dropMole[],double temp,double pres); +//double getLiquidHv(double dropMole[],double temp,double pres); +//double getLiquidMaxT(double dropMole[],double pres); + +double getLiquidDensity(const double temp,const double pres, const std::vector& composition); +double getLiquidDensity(const double temp,const double pres, std::vector& composition,const std::vector& mole); + +double getLiquidCond(const double temp,const double pres, const std::vector& composition); +double getLiquidCond(const double temp,const double pres, std::vector& composition,const std::vector& mole); + +double getLiquidCpb(const double temp,const double pres, const std::vector& composition); +double getLiquidCpb(const double temp,const double pres, const std::vector& composition,const std::vector& mole); + +std::vector getLiquidCp(const double temp, const double pres, const std::vector &composition); +double getGasCond(UserData data, double *ydata, size_t gridPoint); +std::vector getLiquidVH(const double pres,const int dropType); + +void mass2mole(const std::vector& mass,std::vector& mole, UserData data); + +double getLiquidmassdiff(UserData data, double* ydata, size_t gridPoint,const double temp); +std::vector getLiquidmassvec(UserData data,double* ydata,int gridPoint); +std::vector getLiquidmolevec(UserData data,double* ydata,int gridPoint); +std::vector components(int dropType); + +std::vector getVapPressure(UserData data, double* ydata,int gridPoint,const std::vector mole_); + +double dropletmass(UserData data,double* ydata); + +void printIddata(UserData data, double* iddata); +void printPsidata(UserData data,double* psidata); diff --git a/include/timing.hpp b/include/timing.hpp index e07e3eb..18a8d9b 100644 --- a/include/timing.hpp +++ b/include/timing.hpp @@ -39,6 +39,7 @@ double get_wall_time(){ } return (double)time.tv_sec + (double)time.tv_usec * .000001; } + double get_cpu_time(){ return (double)clock() / CLOCKS_PER_SEC; } diff --git a/lagrangianCombustion2 b/lagrangianCombustion2 deleted file mode 100755 index 78125e7..0000000 Binary files a/lagrangianCombustion2 and /dev/null differ diff --git a/macros.h b/macros.h deleted file mode 100644 index bcfbc8c..0000000 --- a/macros.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef MACRO_DEF -#define MACRO_DEF -//#define SUNDIALS_DOUBLE_PRECISION 1 -//#define SUNDIALS_SINGLE_PRECISION 1 - -#define ZERO RCONST(0.0) -#define HALF RCONST(0.5) -#define ONE RCONST(1.0) -#define TWO RCONST(2.0) -#define THREE RCONST(3.0) -#define FOUR RCONST(4.0) -#define TEN RCONST(10.0) - -/* In order to keep begin the index numbers from 1 instead of 0, we define - * macros here. Also, we define macros to ease referencing various variables in - * the sundials nvector. - */ -#define WORK(i) WORK[i-1] -#define XNEW(i) XNEW[i-1] - -#define psi(i) psidata[i-1] - -#define T(i) ydata[((i-1)*data->nvar)+data->nt] -#define Y(i,k) ydata[((i-1)*data->nvar)+data->ny+k-1] -#define R(i) ydata[((i-1)*data->nvar)+data->nr] -#define P(i) ydata[((i-1)*data->nvar)+data->np] -#define Mdot(i) ydata[((i-1)*data->nvar)+data->nm] - -#define Tdot(i) ydotdata[((i-1)*data->nvar)+data->nt] -#define Ydot(i,k) ydotdata[((i-1)*data->nvar)+data->ny+k-1] -#define Rdot(i) ydotdata[((i-1)*data->nvar)+data->nr] -#define Pdot(i) ydotdata[((i-1)*data->nvar)+data->np] -#define Mdotdot(i) ydotdata[((i-1)*data->nvar)+data->nm] - -#define Tres(i) resdata[((i-1)*data->nvar)+data->nt] -#define Yres(i,k) resdata[((i-1)*data->nvar)+data->ny+k-1] -#define Rres(i) resdata[((i-1)*data->nvar)+data->nr] -#define Pres(i) resdata[((i-1)*data->nvar)+data->np] -#define Mdotres(i) resdata[((i-1)*data->nvar)+data->nm] - -#define Tid(i) iddata[((i-1)*data->nvar)+data->nt] -#define Yid(i,k) iddata[((i-1)*data->nvar)+data->ny+k-1] -#define Rid(i) iddata[((i-1)*data->nvar)+data->nr] -#define Pid(i) iddata[((i-1)*data->nvar)+data->np] -#define Mdotid(i) iddata[((i-1)*data->nvar)+data->nm] - -#define Yav(i) Yav[i-1] -#define YAvg(i) YAvg[i-1] -#define YVmhalf(i) YVmhalf[i-1] -#define YVphalf(i) YVphalf[i-1] -#define X(i) X[i-1] -#define Xp(i) Xp[i-1] -#define Xgradhalf(i) Xgradhalf[i-1] -#define XLeft(i) XLeft[i-1] -#define XRight(i) XRight[i-1] -#define gradX(i) gradX[i-1] -#define wdot(i) wdot[i-1] -#define enthalpy(i) enthalpy[i-1] -#define energy(i) energy[i-1] -#define Cp(i) Cp[i-1] - -#define atolT(i) atolvdata[((i-1)*data->nvar)+data->nt] -#define atolY(i,k) atolvdata[((i-1)*data->nvar)+data->ny+k-1] -#define atolR(i) atolvdata[((i-1)*data->nvar)+data->nr] -#define atolP(i) atolvdata[((i-1)*data->nvar)+data->np] -#define atolMdot(i) atolvdata[((i-1)*data->nvar)+data->nm] - - -#define constraintsY(i,k) constraintsdata[((i-1)*data->nvar)+data->ny+k-1] -#define constraintsR(i) constraintsdata[((i-1)*data->nvar)+data->nr] - -/*Following marcos are defined to calculate the characteristic time-scale */ -#define wdot_mole(i) wdot_mole[i-1] -#define wdot_mass(i) wdot_mass[i-1] -#define MW(i) MW[i-1] -#define time_scale(i,k) time_scale[(i-1)*data->nsp+k-1] -#define concentra(i) concentra[i-1] - - -#endif diff --git a/main.cpp b/main.cpp deleted file mode 100644 index ab0e15f..0000000 --- a/main.cpp +++ /dev/null @@ -1,491 +0,0 @@ -/* - _____ ___ ____ ____ -|_ _/ _ \| _ \ / ___| - | || | | | |_) | | - | || |_| | _ <| |___ - |_| \___/|_| \_\\____| - -*/ - -#include "UserData.h" -#include "solution.h" -#include "residue.h" -#include "macros.h" -#include "timing.h" - -#include -#include -#include -#include -//#include - -static int check_flag(void *flagvalue, - const char *funcname, - int opt); - -void freeAtLast(void* mem, N_Vector *y, - N_Vector *ydot, - N_Vector *res, - N_Vector *id, - N_Vector *atolv, - N_Vector *constraints,UserData data); - -int main(){ - - // Read input file specifying the details of the case and store them - FILE *input;input=fopen("input.dat","r"); - UserData data;data=NULL;data=allocateUserData(input); - fclose(input); - data->clockStart=get_wall_time(); - - -// /**************** TEST THE xOld *******************/ -// double* ptr1 = data->grid->xOld ; -// printf("After allocateUserData in main.cpp,Start print the first 5 elements of the xOld array : \n"); -// printf("1st:%.6f, 2nd:%.6f, 3rd:%.6f, 4th:%.6f, 5th:%.6f.\n",ptr1[0],ptr1[1],ptr1[2],ptr1[3],ptr1[4]); - - if(data==NULL){ - printf("check input file!\n"); - freeUserData(data); - return(-1); - } - - // Allocate solution variables - long int ier,mu,ml,count,netf,ncfn,njevals,nrevals; - realtype tNow,*atolvdata,*constraintsdata,finalTime,dtMax,tolsfac; - - - N_Vector y,ydot,id,res,atolv,constraints; - y=ydot=id=res=atolv=constraints=NULL; - ier=allocateSolution(data->neq,data->nThreads,&y,&ydot,&id,&res,&atolv,&constraints); - ier=setAlgebraicVariables(&id,data); - - -// /**************** TEST THE xOld *******************/ -// double* ptr2 = data->grid->xOld ; -// printf("Before setInitialCondition in main.cpp,Start print the first 5 elements of the xOld array : \n"); -// printf("1st:%.6f, 2nd:%.6f, 3rd:%.6f, 4th:%.6f, 5th:%.6f.\n",ptr2[0],ptr2[1],ptr2[2],ptr2[3],ptr2[4]); - - ier=setInitialCondition(&y,&ydot,data); - if(ier==-1)return(-1); - tNow=data->tNow; - finalTime=data->finalTime; - //TODO: dtMax should be a user input - dtMax = 1e-4; - - double* ydata; - double* ydotdata; - ydata = N_VGetArrayPointer_OpenMP(y); - ydotdata = N_VGetArrayPointer_OpenMP(ydot); - ////////// DEBUG /////////////////// - //double* resdata; - //double* iddata; - //resdata = N_VGetArrayPointer_OpenMP(res); - //iddata = N_VGetArrayPointer_OpenMP(id); - /////////////////////////////////// - - void *mem;mem=NULL;mem = IDACreate(); - ier = IDASetUserData(mem, data); - ier = IDASetId(mem, id); - ier = IDAInit(mem, residue, tNow, y, ydot); - - // Atol array - atolvdata = N_VGetArrayPointer_OpenMP(atolv); - for (size_t i = 1; i <=data->npts; i++) { - atolT(i) = data->temperatureTolerance; - for (size_t k = 1; k <=data->nsp; k++) { - if(k!=data->k_bath){ - atolY(i,k) = data->massFractionTolerance; - } - else{ - atolY(i,k) = data->bathGasTolerance; - } - - } - atolR(i) = data->radiusTolerance; - atolP(i) = data->pressureTolerance; - atolMdot(i) = data->MdotTolerance; - } - ier = IDASVtolerances(mem, data->relativeTolerance, atolv); - - mu = 2*data->nvar; ml = mu; - SUNMatrix A; A=NULL; - A=SUNBandMatrix(data->neq,mu,ml,mu+ml); - SUNLinearSolver LS; LS=NULL; - //LS=SUNBandLinearSolver(y,A); - LS=SUNLapackBand(y,A); - ier=IDADlsSetLinearSolver(mem,LS,A); - //ier = IDABand(mem, data->neq, mu, ml); - - constraintsdata = N_VGetArrayPointer_OpenMP(constraints); - if(data->setConstraints){ - for (size_t i = 1; i <=data->npts; i++) { - for (size_t k = 1; k <=data->nsp; k++) { - constraintsY(i,k) = ONE; - } - } - ier=IDASetConstraints(mem, constraints); - } - - if(!data->quasiSteady){ - constraintsR(1) = ONE; - ier=IDASetConstraints(mem, constraints); - } - - ier = IDASetSuppressAlg(mem, data->suppressAlg); - if(check_flag(&ier, "IDASetSuppressAlg", 1)) return(1); - - //ier= IDASetMaxNumStepsIC(mem, 1); - //ier= IDASetMaxNumJacsIC(mem,8); - //ier= IDASetMaxNumItersIC(mem,100); - //ier= IDASetMaxBacksIC(mem,2000); - //ier = IDASetLineSearchOffIC(mem,SUNTRUE); - - //////// DEBUG /////////// - //if(data->dryRun){ - // ier = residue(tNow,y, ydot, res, data); - // for(size_t k=0; k < data->nvar*data->npts; k++){ - // printf("%i: %15.6e\n",k,resdata[k]); - // } - // for(size_t k=0; k < data->nvar*data->npts; k++){ - // if(iddata[k] == 1){ - // ydotdata[k] = -resdata[k]; - // } - // } - // ier = residue(tNow,y, ydot, res, data); - // for(size_t k=0; k < data->nvar*data->npts; k++){ - // printf("%i: %15.6e\n",k,resdata[k]); - // } - //} - //for(size_t k=0; k < data->neq; k++){ - // if(iddata[k] == 1){ - // ydotdata[k] = -resdata[k]; - // } - //} - ////////////////////////// - - if(!data->dryRun){ - printf("Calculating Initial Conditions:\n"); - printf("Cross your fingers...\n"); - - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, 1e-5*finalTime); - - //If at first IDACalcIC doesn't succeed, try, try, try again: - for (int i = 0; i < 10; i++) { - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, (1e-01+pow(10,i)*finalTime)); - - /************* Print the #of iterations ************/ - //printf("This the %dth try of calculating initial conditions. \n",i); - - if(ier==0){ - break; - } - } - - //...or else cry again :( - if(check_flag(&ier, "IDACalcIC", 1)){ - freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); - return(-1); - }else{ - printf("Initial (Consistent) Conditions Calculated!\n"); - } - ier = IDASetInitStep(mem,1e-12); - } - - printSpaceTimeHeader(data); - printGlobalHeader(data); - printTimescaleHeader(data); - printSpaceTimeOutput(tNow, &y, data->output, data); - printSpaceTimeOutput(tNow, &y, data->gridOutput, data); - -// getTimescale(data,&y) ; -// printTimescaleOutput(tNow, &y, data->timescaleOutput,data); - - - if(!data->dryRun){ - count=0; - double dt=1e-08; - double t1=0.0e0; - double xOld=0.0e0; - double x=0.0e0; - double dx=0.0e0; - double dxMin=1.0e0; - double dxRatio=dx/dxMin; - int move=0; - int kcur=0; - int RGCOUNT=0; - size_t ii=0; - if(data->adaptiveGrid){ - dxMin=data->grid->leastMove; - xOld=maxCurvPosition(ydata, data->nt, data->nvar, - data->grid->x, data->npts); - //xOld=isothermPosition(ydata, data->isotherm, data->nt, - // data->nvar, data->grid->x, data->npts); - } - while (tNow<=finalTime && R(1)>100e-9) { - t1=tNow; - - /*Floor small value to zero*/ - floorSmallValue(data, &y); - - - if(data->quasiSteady){ - ier = IDASolve(mem, finalTime, &tNow, y, ydot, IDA_ONE_STEP); - }else{ - /*This prevents the solver from taking a step so large that - *the droplet radius becomes negative. - *TODO:Try adding the constraint that the droplet radius must - * be a positive number*/ - ier = IDASolve(mem, tNow+dtMax, &tNow, y, ydot, IDA_ONE_STEP); - //ier = IDASolve(mem, tNow+dtMax, &tNow, y, ydot, IDA_NORMAL); - } - - if(check_flag(&ier, "IDASolve", 1)){ - freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); - return(-1); - } - dt=tNow-t1; - ier = IDAGetCurrentOrder(mem, &kcur); - - /******** Print the max Temperature *********/ - double maxT = 0.00; - maxT = maxTemperature(ydata,data->nt,data->nvar,data->npts); - printf("Maximum temperature is : %.3f[K] \n",maxT); - - if(data->adaptiveGrid==1 && data->moveGrid==1){ - x=maxCurvPosition(ydata, data->nt, data->nvar, - data->grid->x, data->npts); - //x=isothermPosition(ydata, data->isotherm, data->nt, - // data->nvar, data->grid->x, data->npts); - - //x=maxGradPosition(ydata, data->nt, data->nvar, - // data->grid->x, data->npts); - dx=x-xOld; - - if(dx*dxMin>0.0e0){ - move=1; - }else{ - move=-1; - } - - //if(fabs(dx)>=dxMin && x+(double)(move)*0.5e0*dxMin<=1.0e0){ - dxRatio=fabs(dx/dxMin); - - /************ Print xOld, x,dx,dxMin,dxRatio ******************/ - printf("xOld = %.6f, x = %.6f,",xOld,x); - printf("dx = %.6f, dxMin = %.6f, dxRatio = %.3f\n",dx,dxMin,dxRatio); - - if(dxRatio>=1.0e0 && dxRatio<=2.0e0){ - printf("Regridding!\n"); - - data->regrid=1; - printSpaceTimeOutput(tNow, &y, data->gridOutput, data); - - ier=reGrid(data->grid, x+(double)(move)*0.5e0*dxMin); - if(ier==-1){ - freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); - return(-1); - } - - updateSolution(ydata, ydotdata, data->nvar, - data->grid->xOld,data->grid->x,data->npts); - storeGrid(data->grid->x,data->grid->xOld,data->npts); - xOld=x; - - printf("Regrid Complete! Restarting Problem at %15.6e s\n",tNow); - ier = IDAReInit(mem, tNow, y, ydot); - if(check_flag(&ier, "IDAReInit", 1)){ - freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); - return(-1); - } - ier = IDASetInitStep(mem,1e-01*dt); - printf("Reinitialized! Calculating Initial Conditions:\n"); - printf("Cross your fingers...\n"); - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+1e-01*dt); - if(check_flag(&ier, "IDACalcIC", 1)){ - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+1e+01*dt); - } - //Every once in a while, for reasons - //that befuddle this mathematically - //lesser author, IDACalcIC fails. Here, - //I desperately try to make it converge - //again by sampling increasingly larger - //time-steps: - for (int i = 0; i < 10; i++) { - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+(1e-01+pow(10,i)*dt)); - if(ier==0){ - break; - } - } - //Failure :( Back to the drawing board: - if(check_flag(&ier, "IDACalcIC", 1)){ - freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); - return(-1); - } - printf("Initial (Consistent) Conditions Calculated!\n"); - printf("------------------------------------------\n\n"); - if(data->writeEveryRegrid){ - printSpaceTimeOutput(tNow, &y, data->output, data); - FILE* fp; - fp=fopen("restart.bin","w"); - writeRestart(tNow, &y, &ydot, fp, data); - fclose(fp); - } - - } - } - - /*reset the tolerance after ignition*/ - //resetTolerance(data,&y,&atolv); - - /*regrid and update the solution based on R,re-initialize the problem*/ - /*For the time being,we only allow TORC to REGRID once for each run*/ - - if(data->JJRG ==1 && (maxT >= data->initialTemperature+data->deltaT)){ - if(RGCOUNT<1){ - RGCOUNT = RGCOUNT +1; - REGRID(ydata,ydotdata,data); - initializePsiGrid(ydata,data->uniformGrid,data); - printf("REGRID Complete!Restarting Problem at %15.6e s\n",tNow); - ier = IDAReInit(mem,tNow,y,ydot); - - if(check_flag(&ier,"IDAReInit",1)){ - freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); - return(-1); - } - - ier= IDASetInitStep(mem,1e-01*dt); - //ier= IDASetInitStep(mem,0.0); - printf("Reinitialized!Calculating Initial Conditions:\n"); - printf("Cross your fingers...\n"); - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+1e-01*dt); - if(check_flag(&ier, "IDACalcIC", 1)){ - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+1e+01*dt); - } - //Every once in a while, for reasons - //that befuddle this mathematically - //lesser author, IDACalcIC fails. Here, - //I desperately try to make it converge - //again by sampling increasingly larger - //time-steps: - for (int i = 0; i < 10; i++) { - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+(1e-01+pow(10,i)*dt)); - if(ier==0){ - break; - } - } - //Failure :( Back to the drawing board: - if(check_flag(&ier, "IDACalcIC", 1)){ - freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); - return(-1); - } - printf("Initial (Consistent) Conditions Calculated!\n"); - printf("------------------------------------------\n\n"); - - } - } - - /*Floor small value to zero*/ - floorSmallValue(data, &y); - - if(count%data->nSaves==0 && !data->writeEveryRegrid){ - printSpaceTimeOutput(tNow, &y, data->output, data); - //if(data->writeRates){ - // printSpaceTimeRates(tNow, ydot, data); - //} - } - - /*Get and Print Rxns Rate of Progress and Specie Rate of Production data*/ - /*Following code snippet will be executed only once*/ - if(ii==0 && maxT >=(data->initialTemperature+data->deltaT)){ - getReactions(data,&y,data->rxnROPOutput); - getSpecies(data,&y,data->spROPOutput); - ii++; - } -// getTimescale(data,&y); -// if(count%data->nSaves==0){ -// printTimescaleOutput(tNow,&y, data->timescaleOutput,data); -// //printSpaceTimeOutput(tNow, &y, data->output, data); -// //if(data->writeRates){ -// // printSpaceTimeRates(tNow, ydot, data); -// //} -// } - - /*Print global variables only if time-step is of high order!*/ - if(data->nTimeSteps==0){ - data->flamePosition[0]=0.0e0; - data->flamePosition[1]=0.0e0; - data->flameTime[0]=tNow; - data->flameTime[1]=tNow; - } - - ier = IDAGetNumErrTestFails(mem, &netf); - ier = IDAGetNumNonlinSolvConvFails(mem, &ncfn); - ier = IDADlsGetNumJacEvals(mem, &njevals); - ier = IDADlsGetNumResEvals(mem, &nrevals); - printf("etf = %ld ," - "nlsf= %ld ," - "J=%ld ," - "R=%ld ," - "o=%d ,",netf, ncfn, njevals, nrevals, kcur); - printf("Time=%15.6e s,",tNow); - printf("dt=%15.6e s,",dt); - printf("frac: %15.6e\n",dxRatio); - count++; - data->nTimeSteps=count; - } - } - - SUNLinSolFree(LS); - SUNMatDestroy(A); - freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); - - return(0); -} - -void freeAtLast(void* mem, - N_Vector *y, - N_Vector *ydot, - N_Vector *res, - N_Vector *id, - N_Vector *atolv, - N_Vector *constraints,UserData data){ - - IDAFree(&mem); - freeSolution(y,ydot,res,id,atolv,constraints); - freeUserData(data); -} - -static int check_flag(void *flagvalue, const char *funcname, int opt) -{ - int *errflag; - - /* Check if SUNDIALS function returned NULL pointer - no memory allocated */ - if (opt == 0 && flagvalue == NULL) { - fprintf(stderr, - "\nSUNDIALS_ERROR: %s() failed - returned NULL pointer\n\n", - funcname); - return(1); - } - - /* Check if flag < 0 */ - else if (opt == 1) { - errflag = (int *) flagvalue; - if (*errflag < 0) { - fprintf(stderr, - "\nSUNDIALS_ERROR: %s() failed with flag = %d\n\n", - funcname, *errflag); - return(1); - } - } - - /* Check if function returned NULL pointer - no memory allocated */ - else if (opt == 2 && flagvalue == NULL) { - fprintf(stderr, - "\nMEMORY_ERROR: %s() failed - returned NULL pointer\n\n", - funcname); - return(1); - } - - return(0); -} diff --git a/main.d b/main.d deleted file mode 100644 index d585097..0000000 --- a/main.d +++ /dev/null @@ -1,77 +0,0 @@ -main.o: main.cpp UserData.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/IdealGasMix.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/IdealGasPhase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/ThermoPhase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/Phase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ctexceptions.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/fmt.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ct_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/config.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/format.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/core.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/format-inl.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/format.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/printf.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/ostream.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/ostream.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/Elements.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ct_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/Species.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/AnyMap.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/global.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/AnyMap.inl.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ValueCache.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/MultiSpeciesThermo.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/SpeciesThermoInterpType.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/speciesThermoTypes.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/GasKinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/BulkKinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Kinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/ThermoPhase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/StoichManager.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/stringUtils.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Reaction.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/utilities.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/global.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/RxnRates.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/reaction_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Falloff.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/RateCoeffMgr.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/RxnRates.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/ThirdBodyCalc.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/FalloffMgr.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/reaction_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/FalloffFactory.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/FactoryBase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Reaction.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/importKinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/stringUtils.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportFactory.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportBase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LiquidTransportParams.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportParams.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/numerics/DenseMatrix.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/Array.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/utilities.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LiquidTranInteraction.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LiquidTransportData.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LTPspecies.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportData.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/xml.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ctexceptions.h \ - gridRoutines.h parse.h parse.hpp solution.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_types.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_config.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/nvector/nvector_openmp.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_nvector.h \ - residue.h macros.h timing.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/ida/ida.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/ida/ida_direct.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_direct.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_matrix.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_linearsolver.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_iterative.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sunmatrix/sunmatrix_band.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sunlinsol/sunlinsol_lapackband.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_lapack.h diff --git a/main.o b/main.o deleted file mode 100644 index ba7f899..0000000 Binary files a/main.o and /dev/null differ diff --git a/parse.cpp b/parse.cpp deleted file mode 100644 index d2e6e9f..0000000 --- a/parse.cpp +++ /dev/null @@ -1,79 +0,0 @@ -#include "parse.h" -void getFromString (const char* buf, int* n){ - *n=atoi(buf); - printf("%d\n",*n); -} - -void getFromString (const char* buf, size_t* n){ - *n=(size_t)(atoi(buf)); - printf("%lu\n",*n); -} - -void getFromString (const char* buf, double* n){ - *n=(double)(atof(buf)); - printf("%15.6e\n",*n); -} - -void getFromString (const char* buf, char* n){ - sscanf(buf,"%s",n); - printf("%s\n",n); -} - -/*Extract droplet species and mole fractions*/ -int parseDrop(FILE* input, const char* keyword,char dropSpec[][10],double dropMole[],const size_t bufLen){ - char buf[bufLen]; - char buf1[bufLen]; - char comment[1]; - char *ret; - while (fgets(buf,bufLen, input)!=NULL){ - comment[0]=buf[0]; - if(strncmp(comment,"#",1)==0){ - } - else{ - strcpy(buf1,buf); - ret=strtok(buf,"="); - //DEBUG - //printf("Current KEYWORD in input: %20s \n",ret); - if(strcmp(ret,keyword)==0){ - char* modifiedFuel = NULL; - char* equalSign = strstr(buf1,"="); - if(equalSign!= NULL){ - modifiedFuel = new char [strlen(equalSign)+1]; - strcpy(modifiedFuel,equalSign+1); - //DEBUG - //printf("modifiedFuel:%20s \n",modifiedFuel); - char* token = strtok(modifiedFuel,","); - int index = 0 ; - char* list[2]; - while(token!= NULL){ - //DEBUG - //printf("TOKEN :%20s \n",token); - list[index] = token; - token = strtok(NULL,","); - index++; - } - //for (int i=0;i<2;i++){ - // printf("%20s",list[i]); - //} - for(int i=0;i<2;i++){ - char* name= strtok(list[i],":"); - char* value = strtok(NULL,":"); - //DEBUG - // printf("Name:%10s,Value:%10s \n",name,value); - strcpy(dropSpec[i],name); - dropMole[i]=std::stod(value); - // printf("In the dropArray,Name:%10s,Value:%.3f\n",dropSpec[i],dropMole[i]); - } - delete[] modifiedFuel; - } - printf("%10s:%10s:%.3f,%10s:%.3f\n",keyword,dropSpec[0],dropMole[0],dropSpec[1],dropMole[1]); - //printf("IF statement is execuated. \n"); - rewind(input); - //delete[] modifiedFuel; - return(0); - } - } - } - rewind(input); - return(-1); -} diff --git a/parse.d b/parse.d deleted file mode 100644 index 7abe434..0000000 --- a/parse.d +++ /dev/null @@ -1 +0,0 @@ -parse.o: parse.cpp parse.h parse.hpp diff --git a/parse.h b/parse.h deleted file mode 100644 index 894bd12..0000000 --- a/parse.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef PRINT_DEF -#define PRINT_DEF -#include //for strings -#include //for printf,scanf -#include //for atoi, atof -#include -#include -#include -#include -#endif - -#ifndef PARSE_DEF -#define PARSE_DEF -#define MAXBUFLEN 200 - -void getFromString (const char* buf, int* n); -void getFromString (const char* buf, size_t* n); -void getFromString (const char* buf, double* n); -void getFromString (const char* buf, char* n); - -int parseString(FILE* input, const char* keyword, const size_t bufLen, char* n); - -template -int parseNumber(FILE* input, const char* keyword, const size_t bufLen, T* n); - -template -int parseArray(FILE* input, const char* keyword, const size_t bufLen, - const size_t arrLen, T y[]); - -int parseDrop(FILE* input, const char* keyword,char dropSpec[][10],double dropMole[],const size_t bufLen); - -#include "parse.hpp" - -#endif - - diff --git a/parse.hpp b/parse.hpp deleted file mode 100644 index 6c10a9a..0000000 --- a/parse.hpp +++ /dev/null @@ -1,75 +0,0 @@ -template -int parseNumber(FILE* input, const char* keyword, const size_t bufLen, T* n){ - - char buf[bufLen]; - char buf1[bufLen]; - char comment[1]; - char *ret; - - while (fgets(buf,bufLen, input)!=NULL){ - comment[0]=buf[0]; - if(strncmp(comment,"#",1)==0){ - //printf("Comment!:%s\n",buf); - } - else{ - ret=strtok(buf,"="); - if(strcmp(ret,keyword)==0){ - /*offset buf by keyword size + 1 for the "="*/ - strncpy (buf1, buf+strlen(keyword)+1, bufLen); - printf("%30s: ",keyword); - getFromString(buf1,n); - rewind(input); - return(0); - } - } - } - rewind(input); - return(-1); -} - -template -int parseArray(FILE* input, const char* keyword, const size_t bufLen, - const size_t arrLen, T y[]){ - - char buf[bufLen]; - char buf1[bufLen]; - char comment[1]; - char *ret; - - while (fgets(buf,bufLen, input)!=NULL){ - comment[0]=buf[0]; - if(strncmp(comment,"#",1)==0){ - //printf("Comment!:%s\n",buf); - } - else{ - ret=strtok(buf,"="); - - if(strcmp(ret,keyword)==0){ - /*offset buf by keyword size + 1 for the "="*/ - strncpy (buf1, buf+strlen(keyword)+1, bufLen); - printf("%30s:\n",keyword); - ret=strtok(buf1,","); - size_t j=0; - while(ret!=NULL){ - if(j -#include -#endif -#include "residue.h" -#include "macros.h" -#include -#include -#include "timing.hpp" - -void REGRID(double* ydata,double* ydotdata,UserData data){ - size_t nPts = data->npts; - size_t nvar = data->nvar; - double WORK[nPts],XNEW[nPts],XOLD[nPts]; - double P,R,R0,R1,R2,TV1,TV2,XLEN,B1,B2; - double DX,DDX; - double DETA,ETAJ,DEL; - size_t ISTART; - P = data->PCAD; - R = data->RGTC; - R0 =1.0 - P; - R1 =P*R/(R+1.0); - R2 =P - R1 ; - TV1 = 0.0; - TV2 = 0.0; - - for(size_t i=2;i<=nPts;i++){ - TV1 = TV1 + fabs(T(i)-T(i-1)); - } - - for(size_t i=2;i<=nPts-1;i++){ - TV2 = TV2 + fabs( (T(i+1)-T(i))/(R(i+1)-R(i)) - (T(i)-T(i-1))/(R(i)-R(i-1)) ); - } - - XLEN = R(nPts) - R(1); - B1 = R1* XLEN/ ( (1.0-P)*TV1); - B2 = R2* XLEN/ ( (1.0-P)*TV2); - - //Compute partial sum of weight function - WORK(1) =0.0; - DX = 0.0; - for(size_t i=2;i<=nPts-1;i++){ - DX = R(i) - R(i-1) ; - WORK(i) = DX + B1*fabs(T(i)-T(i-1)) + WORK(i-1)+B2*fabs( (T(i+1)-T(i))/(R(i+1)-R(i)) - (T(i)-T(i-1))/(R(i)-R(i-1)) ); - } - - DDX = R(nPts) - R(nPts-1); - WORK(nPts) = WORK(nPts-1) +DDX ; - - for(size_t i=2;i<=nPts;i++){ - WORK(i) = WORK(i)/WORK(nPts); - } - - XNEW(1)=R(1); - XNEW(nPts)=R(nPts); - ISTART =2; - //double DETA; - DETA = 1.0/(nPts-1) ; - - //Fill new grid XNEW[nPts],duplicate from PREMIX REGRID SUBROUTINE - for(size_t j=2;j<=nPts-1;j++){ - ETAJ= (j-1)*DETA; - - for(size_t i=ISTART;i<=nPts;i++){ - if(ETAJ <= WORK(i)){ - DEL = (ETAJ-WORK(i-1))/(WORK(i)-WORK(i-1)) ; - XNEW(j)=R(i-1)+(R(i)-R(i-1))*DEL; - break; - }else{ - ISTART =i; - } - - } - } - - //Interpolate solution based on XNEW[]&XOLD[] - for(size_t i=1;i<=nPts;i++){ - XOLD[i-1]=R(i); - } - - INTERPO(ydata,ydotdata,nvar,nPts,XNEW,XOLD); -} - - -void INTERPO(double* y,double* ydot,const size_t nvar,size_t nPts,const double XNEW[], const double XOLD[]){ - double ytemp[nPts],ydottemp[nPts] ; - - gsl_interp_accel* acc; - gsl_spline* spline; - acc = gsl_interp_accel_alloc(); - spline = gsl_spline_alloc(gsl_interp_steffen,nPts); - - gsl_interp_accel* accdot; - gsl_spline* splinedot; - accdot = gsl_interp_accel_alloc(); - splinedot = gsl_spline_alloc(gsl_interp_steffen,nPts); - - for(size_t j=0;j maxT){ - maxT = TempT ; - pos = x[i-1]; - } - } - return(pos); -} - -double maxTemperature(const double* y,const size_t nt,const size_t nvar ,size_t nPts){ - double maxT = 0.0e0; - double TempT = 0.0e0; - //int index = 0 ; - for (size_t i=1;i<=nPts;i++){ - TempT = y[(i-1)*nvar+nt] ; - if(TempT > maxT){ - maxT = TempT ; - } - } - return(maxT); -} -//Index here is 1-based -int maxTemperatureIndex(const double* y,const size_t nt,const size_t nvar ,size_t nPts){ - double maxT = 0.0e0; - double TempT = 0.0e0; - int index = 0 ; - for (size_t i=1;i<=nPts;i++){ - TempT = y[(i-1)*nvar+nt] ; - if(TempT > maxT){ - maxT = TempT ; - index = i; - } - } - return(index); -} - -double maxCurvPositionR(const double* y, const size_t nt, - const size_t nvar, const size_t nr, size_t nPts){ - double maxCurvT=0.0e0; - double gradTp=0.0e0; - double gradTm=0.0e0; - double curvT=0.0e0; - double dx=0.0e0; - double dr=0.0e0; - double pos=0.0e0; - size_t j,jm,jp; - size_t r,rp,rm; - for (size_t i = 1; i =maxCurvT) { - maxCurvT=curvT; - pos=y[r]; - } - } - return(pos); -} - -int maxCurvIndexR(const double* y, const size_t nt, - const size_t nvar, const size_t nr, size_t nPts){ - double maxCurvT=0.0e0; - double gradTp=0.0e0; - double gradTm=0.0e0; - double curvT=0.0e0; - double dx=0.0e0; - double dr=0.0e0; - int pos=0; - size_t j,jm,jp; - size_t r,rm,rp; - for (size_t i = 1; i =maxCurvT) { - maxCurvT=curvT; - pos=i; - } - } - return(pos); -} - -double maxGradPosition(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts){ - double maxGradT=0.0e0; - double gradT=0.0e0; - double pos=0.0e0; - size_t j,jm; - for (size_t i = 1; i =maxGradT) { - maxGradT=gradT; - pos=x[i]; - } - } - return(pos); -} - -int maxGradIndex(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts){ - double maxGradT=0.0e0; - double gradT=0.0e0; - int pos=0; - size_t j,jm; - for (size_t i = 1; i =maxGradT) { - maxGradT=gradT; - pos=i; - } - } - return(pos); -} - -double maxCurvPosition(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts){ - double maxCurvT=0.0e0; - double gradTp=0.0e0; - double gradTm=0.0e0; - double curvT=0.0e0; - double dx=0.0e0; - double pos=0.0e0; - size_t j,jm,jp; - for (size_t i = 1; i =maxCurvT) { - maxCurvT=curvT; - pos=x[i]; - } - } - return(pos); -} - -int maxCurvIndex(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts){ - double maxCurvT=0.0e0; - double gradTp=0.0e0; - double gradTm=0.0e0; - double curvT=0.0e0; - double dx=0.0e0; - int pos=0; - size_t j,jm,jp; - for (size_t i = 1; i =maxCurvT) { - maxCurvT=curvT; - pos=i; - } - } - return(pos); -} - -//double isothermPosition(const double* y, const double T, const size_t nt, -// const size_t nvar, const double* x, const size_t nPts){ -// double pos=x[nPts-1]; -// size_t j; -// for (size_t i = 1; i =T) { - pos=x[i]; - break; - } - } - return(pos); -} - -void updateSolution(double* y, double* ydot, const size_t nvar, - const double xOld[],const double xNew[],const size_t nPts){ - - double ytemp[nPts],ydottemp[nPts]; - - gsl_interp_accel* acc; - gsl_spline* spline; - acc = gsl_interp_accel_alloc(); - spline = gsl_spline_alloc(gsl_interp_steffen, nPts); - - gsl_interp_accel* accdot; - gsl_spline* splinedot; - accdot = gsl_interp_accel_alloc(); - splinedot = gsl_spline_alloc(gsl_interp_steffen, nPts); - - for (size_t j = 0; j < nvar; j++) { - - for (size_t i = 0; i < nPts; i++) { - ytemp[i]=y[j+i*nvar]; - ydottemp[i]=ydot[j+i*nvar]; - } - - gsl_spline_init(spline,xOld,ytemp,nPts); - gsl_spline_init(splinedot,xOld,ydottemp,nPts); - - for (size_t i = 0; i < nPts; i++) { - - y[j+i*nvar]=gsl_spline_eval(spline,xNew[i],acc); - ydot[j+i*nvar]=gsl_spline_eval(splinedot,xNew[i],accdot); - } - } - - //Exploring "fixing" boundary conditions: - //for (size_t j = 1; j < nvar; j++) { - // //printf("%15.6e\t%15.6e\n", y[j],y[j+nvar]); - // y[j]=y[j+nvar]; - // //y[j+(nPts-1)*nvar]=y[j+(nPts-2)*nvar]; - // //ydot[j+nvar]=ydot[j]; - //} - //y[0]=0.0e0; - - gsl_interp_accel_free(acc); - gsl_spline_free(spline); - - gsl_interp_accel_free(accdot); - gsl_spline_free(splinedot); -} - -//Locate bath gas: -size_t BathGasIndex(UserData data){ - size_t index=0; - double max1; - double max=data->gas->massFraction(0); - for(size_t k=1;knsp;k++){ - max1=data->gas->massFraction(k); - if(max1>=max){ - max=max1; - index=k; - } - } - return(index+1); -} - -//Locate Oxidizer: -size_t oxidizerIndex(UserData data){ - size_t index=0; - for(size_t k=1;knsp;k++){ - if(data->gas->speciesName(k-1)=="O2"){ - index=k; - } - } - return(index); -} - -//Locate OH: -size_t OHIndex(UserData data){ - size_t index=0; - for(size_t k=1;knsp;k++){ - if(data->gas->speciesName(k-1)=="OH"){ - index=k; - } - } - return(index); -} - -//Locate HO2: -size_t HO2Index(UserData data){ - size_t index=0; - for(size_t k=1;knsp;k++){ - if(data->gas->speciesName(k-1)=="HO2"){ - index=k; - } - } - return(index); -} - -//Locate species index: -size_t specIndex(UserData data,char *specName){ - size_t index=0; - for(size_t k=1;knsp;k++){ - if(data->gas->speciesName(k-1)==specName){ - index=k; - } - } - return(index); -} - -int setAlgebraicVariables(N_Vector* id, UserData data){ - double *iddata; - char* specPtr[2]; - - N_VConst(ONE, *id); - iddata = N_VGetArrayPointer_OpenMP(*id); - data->k_bath=BathGasIndex(data); - data->k_oxidizer=oxidizerIndex(data); - data->k_OH=OHIndex(data); - data->k_HO2=HO2Index(data); - //use char* pointer to get the address - for(int i=0;i<2;i++){ - specPtr[i] = data->dropSpec[i]; - } - data->k_drop[0]=specIndex(data,specPtr[0]); - data->k_drop[1]=specIndex(data,specPtr[1]); - - printf("Oxidizer index: %lu\n",data->k_oxidizer); - printf("Bath gas index:%lu\n",data->k_bath); - printf("Droplet species index:%lu,%lu\n",data->k_drop[0],data->k_drop[1]); - for (size_t i = 1; i <=data->npts; i++) { - /*Algebraic variables: indicated by ZERO.*/ - Rid(i)=ZERO; - Pid(i)=ZERO; - Yid(i,data->k_bath)=ZERO; - Mdotid(i)=ZERO; - } - Mdotid(1)=ZERO; - Rid(1)=ONE; - Yid(1,data->k_drop[0])=ZERO; - Yid(1,data->k_drop[1])=ZERO; - Tid(data->npts)=ZERO; - if(data->constantPressure){ - Pid(data->npts)=ONE; - }else{ - Pid(data->npts)=ZERO; - Rid(data->npts)=ONE; - } - if(data->dirichletInner){ - Tid(1)=ZERO; - }else{ - Tid(1)=ONE; - } - if(data->dirichletOuter){ - for (size_t k = 1; k <=data->nsp; k++) { - if(k!=data->k_bath){ - Yid(data->npts,k)=ONE; - } - Yid(1,k)=ZERO; - Tid(data->npts)=ONE; - } - }else{ - for (size_t k = 1; k <=data->nsp; k++){ - Yid(1,k)=ZERO; - Yid(data->npts,k)=ZERO; - Tid(data->npts)=ZERO; - } - } - return(0); -} - -inline double calc_area(double x,int* i){ - switch (*i) { - case 0: - return(ONE); - case 1: - return(x); - case 2: - return(x*x); - default: - return(ONE); - } -} - -void readInitialCondition(FILE* input, double* ydata, const size_t nvar, const size_t nr, const size_t nPts, double Rg){ - - FILE* output;output=fopen("test.dat","w"); - - size_t bufLen=10000; - size_t nRows=0; - size_t nColumns=nvar; - - char buf[bufLen]; - char buf1[bufLen]; - char comment[1]; - char *ret; - - while (fgets(buf,bufLen, input)!=NULL){ - comment[0]=buf[0]; - if(strncmp(comment,"#",1)!=0){ - nRows++; - } - } - rewind(input); - - printf("nRows: %ld\n", nRows); - double y[nRows*nColumns]; - - size_t i=0; - while (fgets(buf,bufLen, input)!=NULL){ - comment[0]=buf[0]; - if(strncmp(comment,"#",1)==0){ - } - else{ - ret=strtok(buf,"\t"); - size_t j=0; - y[i*nColumns+j]=(double)(atof(ret)); - j++; - while(ret!=NULL){ - ret=strtok(NULL,"\t"); - if(jnpts; i++) { - data->gas->setState_TPY(T(i), P(i), &Y(i,1)); - rho=data->gas->density(); - //psi(i)=psi(i-1)+rho*(R(i)-R(i-1))*calc_area(HALF*(R(i)+R(i-1)),&m); - mass+=rho*(R(i)-R(i-1))*calc_area(R(i),&data->metric); - } - return(mass); -} - - -int initializePsiGrid(double* ydata, double* psidata, UserData data){ - - double rho,rhom; - /*Create a psi grid that corresponds CONSISTENTLY to the spatial grid - * "R" created above. Note that the Lagrangian variable psi has units - * of kg. */ - psi(1)=ZERO; - for (size_t i = 2; i <=data->npts; i++) { - data->gas->setState_TPY(T(i), P(i), &Y(i,1)); - rho=data->gas->density(); - data->gas->setState_TPY(T(i-1), P(i-1), &Y(i-1,1)); - rhom=data->gas->density(); - //psi(i)=psi(i-1)+rho*(R(i)-R(i-1))*calc_area(HALF*(R(i)+R(i-1)),&data->metric); - //psi(i)=psi(i-1)+rho*(R(i)-R(i-1))*calc_area(R(i),&data->metric); - psi(i)=psi(i-1)+(R(i)-R(i-1))*(rho*calc_area(R(i),&data->metric)+rhom*calc_area(R(i-1),&data->metric))/TWO; - } - - /*The mass of the entire system is the value of psi at the last grid - * point. Normalize psi by this mass so that it varies from zero to - * one. This makes psi dimensionless. So the mass needs to be - * multiplied back in the approporiate places in the governing - * equations so that units match.*/ - data->mass=psi(data->npts); - for (size_t i = 1; i <=data->npts; i++) { - psi(i)=psi(i)/data->mass; - } - return(0); -} - - -int setInitialCondition(N_Vector* y, - N_Vector* ydot, - UserData data){ - double* ydata; - double* ydotdata; - double* psidata; - double* innerMassFractionsData, Rd, massDrop; - double rhomhalf, lambdamhalf, YVmhalf[data->nsp]; - double f=ZERO; - double g=ZERO; - - double perturb,rho; - double epsilon=ZERO; - int m,ier; - ydata = N_VGetArrayPointer_OpenMP(*y); - ydotdata = N_VGetArrayPointer_OpenMP(*ydot); - innerMassFractionsData = data->innerMassFractions; - Rd = data->Rd; - massDrop = data->massDrop; - - //Mass of droplet - //massDrop=1.0/3.0*Rd*Rd*Rd*997.0; //TODO: The density of the droplet should be a user input - //massDrop=1.0/3.0*Rd*Rd*Rd*684.0; //TODO:The density of the droplet(n-heptane) should be a user input - massDrop = 1.0/3.0*Rd*Rd*Rd*data->dropRho; - if(data->adaptiveGrid){ - psidata = data->grid->xOld; - } - else{ - psidata = data->uniformGrid; - } - - m=data->metric; - - data->innerTemperature=data->initialTemperature; - for (size_t k = 1; k <=data->nsp; k++) { - innerMassFractionsData[k-1]=data->gas->massFraction(k-1); - } - - //Define Grid: - double dR=(data->domainLength)/((double)(data->npts)-1.0e0); - double dv=(pow(data->domainLength,1+data->metric)-pow(data->firstRadius*data->domainLength,1+data->metric))/((double)(data->npts)-1.0e0); - - //Initialize the R(i),T(i)(data->initialTemperature),Y(i,k),P(i) - for (size_t i = 1; i <=data->npts; i++) { - if(data->metric==0){ - R(i)=Rd+(double)((i-1)*dR); - }else{ - if(i==1){ - R(i)=ZERO; - }else if(i==2){ - R(i)=data->firstRadius*data->domainLength; - }else{ - R(i)=pow(pow(R(i-1),1+data->metric)+dv,1.0/((double)(1+data->metric))); - } - } - T(i)=data->initialTemperature; - for (size_t k = 1; k <=data->nsp; k++) { - Y(i,k)=data->gas->massFraction(k-1); //Indexing different in Cantera - } - P(i)=data->initialPressure*Cantera::OneAtm; - } - R(data->npts)=data->domainLength+data->Rd; - -// /********** test R(i) and the volumn between grids *****************/ -// printf("Print the first 4 R(i)s and volumn between them: \n") ; -// printf("Grids: 1st:%2.6e,2nd:%2.6e,3rd:%2.6e,4th:%2.6e \n",R(1),R(2),R(3),R(4)); -// double v1,v2,v3,v4,v5; -// v1 =pow(R(2),1+data->metric) - pow(R(1),1+data->metric); -// v2 =pow(R(3),1+data->metric) - pow(R(2),1+data->metric); -// v3 =pow(R(4),1+data->metric) - pow(R(3),1+data->metric); -// v4 =pow(R(5),1+data->metric) - pow(R(4),1+data->metric); -// v5 =pow(R(6),1+data->metric) - pow(R(5),1+data->metric); -// printf("Volumn: 1st:%2.6e,2nd:%2.6e,3rd:%2.6e,4th:%2.6e,5th:%2.6e\n",v1,v2,v3,v4,v5) ; - - - double Tmax; - double Tmin=data->initialTemperature; - double w=data->mixingWidth; - double YN2=ZERO; - double YO2=ZERO; - double YFuel,YOxidizer,sum; - - //if(data->problemType==0){ - // data->gas->equilibrate("HP"); - // data->maxTemperature=data->gas->temperature(); - //} - //else if(data->problemType==1){ - // /*Premixed Combustion: Equilibrium products comprise ignition - // * kernel at t=0. The width of the kernel is "mixingWidth" - // * shifted by "shift" from the center.*/ - // data->gas->equilibrate("HP"); - // Tmax=data->gas->temperature(); - // for (size_t i = 1; i <=data->npts; i++) { - // g=HALF*(tanh((R(i)-data->shift)/w)+ONE); //increasing function of x - // f=ONE-g; //decreasing function of x - // T(i)=(Tmax-Tmin)*f+Tmin; - // for (size_t k = 1; k <=data->nsp; k++) { - // Y(i,k)=(data->gas->massFraction(k-1)-Y(i,k))*f+Y(i,k); - // } - // } - // if(data->dirichletOuter){ - // T(data->npts)=data->wallTemperature; - // } - //} - //else if(data->problemType==2){ - // FILE* input; - // if(input=fopen("initialCondition.dat","r")){ - // readInitialCondition(input, ydata, data->nvar, data->nr, data->npts); - // fclose(input); - // } - // else{ - // printf("file initialCondition.dat not found!\n"); - // return(-1); - // } - //} - - initializePsiGrid(ydata,psidata,data); - - if(data->adaptiveGrid){ - // if(data->problemType!=0){ - // data->grid->position=maxGradPosition(ydata, data->nt, data->nvar, - // data->grid->xOld, data->npts); - // //data->grid->position=maxCurvPosition(ydata, data->nt, data->nvar, - // // data->grid->xOld, data->npts); - // } - // else{ - // } - if(data->problemType!=3){ - data->grid->position=0.0e0; - double x=data->grid->position+data->gridOffset*data->grid->leastMove; - printf("New grid center:%15.6e\n",x); - -// /**************** TEST THE data->grid->xOld *******************/ -// double* ptr3 = data->grid->xOld ; -// printf("SetInitialCondition function is called,before reGrid,Start print the first 5 elements of the xOld array : \n"); -// printf("1st:%.6f, 2nd:%.6f, 3rd:%.6f, 4th:%.6f, 5th:%.6f.\n",ptr3[0],ptr3[1],ptr3[2],ptr3[3],ptr3[4]); - - ier=reGrid(data->grid, x); - if(ier==-1)return(-1); - -// /**************** TEST THE data->grid->xOld *******************/ -// double* ptr = data->grid->xOld ; -// printf("SetInitialCondition function is called,after reGrid,Start print the first 5 elements of the xOld array : \n"); -// printf("1st:%.6f, 2nd:%.6f, 3rd:%.6f, 4th:%.6f, 5th:%.6f.\n",ptr[0],ptr[1],ptr[2],ptr[3],ptr[4]); - - - updateSolution(ydata, ydotdata, data->nvar, - data->grid->xOld,data->grid->x,data->npts); - storeGrid(data->grid->x,data->grid->xOld,data->npts); - } - } - else{ - double Rg = data->Rg, dpsi0; - int NN = data->npts-2; - double psiNew[data->npts]; - - dpsi0 = (pow(Rg,1.0/NN) - 1.0)/(pow(Rg,(NN+1.0)/NN) - 1.0); - psiNew[0] = 0; - for (size_t i = 1; i < data->npts-1; i++) { - psiNew[i]=psiNew[i-1]+dpsi0*pow(Rg,(i-1.0)/NN); - } - psiNew[data->npts-1] = 1.0; - printf("Last point:%15.6e\n",psiNew[data->npts-1]); - updateSolution(ydata, ydotdata, data->nvar, - data->uniformGrid,psiNew,data->npts); - storeGrid(psiNew,data->uniformGrid,data->npts); - - //double psiNew[data->npts]; - //double dpsi=1.0e0/((double)(data->npts)-1.0e0); - //for (size_t i = 0; i < data->npts; i++) { - // psiNew[i]=(double)(i)*dpsi; - //} - //printf("Last point:%15.6e\n",psiNew[data->npts-1]); - //updateSolution(ydata, ydotdata, data->nvar, - // data->uniformGrid,psiNew,data->npts); - //storeGrid(psiNew,data->uniformGrid,data->npts); - } - - if(data->problemType==0){ - data->gas->equilibrate("HP"); - data->maxTemperature=data->gas->temperature(); - } - else if(data->problemType==1){ - /*Premixed Combustion: Equilibrium products comprise ignition - * kernel at t=0. The width of the kernel is "mixingWidth" - * shifted by "shift" from the center.*/ - data->gas->equilibrate("HP"); - Tmax=data->gas->temperature(); - for (size_t i = 1; i <=data->npts; i++) { - g=HALF*(tanh((R(i)-data->shift)/w)+ONE); //increasing function of x - f=ONE-g; //decreasing function of x - T(i)=(Tmax-Tmin)*f+Tmin; - for (size_t k = 1; k <=data->nsp; k++) { - Y(i,k)=(data->gas->massFraction(k-1)-Y(i,k))*f+Y(i,k); - } - } - if(data->dirichletOuter){ - T(data->npts)=data->wallTemperature; - } - } - else if(data->problemType==2){ - FILE* input; - if(input=fopen("initialCondition.dat","r")){ - readInitialCondition(input, ydata, data->nvar, data->nr, data->npts, data->Rg); - fclose(input); - } - else{ - printf("file initialCondition.dat not found!\n"); - return(-1); - } - initializePsiGrid(ydata,psidata,data); - } - else if(data->problemType==3){ - FILE* input; - if(input=fopen("restart.bin","r")){ - readRestart(y, ydot, input, data); - fclose(input); - printf("Restart solution loaded!\n"); - printf("Problem starting at t=%15.6e\n",data->tNow); - return(0); - } - else{ - printf("file restart.bin not found!\n"); - return(-1); - } - } - - if(data->reflectProblem){ - double temp; - int j=1; - while (data->npts+1-2*j>=0) { - temp=T(j); - T(j)=T(data->npts+1-j); - T(data->npts+1-j)=temp; - for (size_t k = 1; k <=data->nsp; k++) { - temp=Y(j,k); - Y(j,k)=Y(data->npts+1-j,k); - Y(data->npts+1-j,k)=temp; - } - j=j+1; - } - } - - /*Floor small values to zero*/ - for (size_t i = 1; i <=data->npts; i++) { - for (size_t k = 1; k <=data->nsp; k++) { - if(fabs(Y(i,k))<=data->massFractionTolerance){ - Y(i,k)=0.0e0; - } - } - } - - //Set grid to location of maximum curvature calculated by r instead of x: - if(data->adaptiveGrid){ - //data->grid->position=maxCurvPosition(ydata, data->nt, data->nvar, - // data->grid->x, data->npts); - int maxCurvII = 0; - maxCurvII = maxCurvIndexR(ydata,data->nt,data->nvar,data->nr,data->npts); - - data->grid->position = data->grid->x[maxCurvII]; - ier=reGrid(data->grid, data->grid->position); - updateSolution(ydata, ydotdata, data->nvar, - data->grid->xOld,data->grid->x,data->npts); - storeGrid(data->grid->x,data->grid->xOld,data->npts); - - /******** Test the maxCurvPosition and related variables *******/ - printf("The maxCurvPositition(based on r) is : %.6f,Temperature is : %.3f \n",data->grid->position,T(maxCurvII+1)); - } - - - /*Ensure consistent boundary conditions*/ - //T(1)=T(2); - //for (size_t k = 1; k <=data->nsp; k++) { - // Y(1,k)=Y(2,k); - // Y(data->npts,k)=Y(data->npts-1,k); - //} - - return(0); -} - -inline double Qdot(double* t, - double* x, - double* ignTime, - double* kernelSize, - double* maxQdot){ - double qdot; - if(*x<=*kernelSize){ - if((*t)<=(*ignTime)){ - qdot=(*maxQdot); - } - else{ - qdot=0.0e0; - } - }else{ - qdot=0.0e0; - } - return(qdot); -} - -inline void setGas(UserData data, - double *ydata, - size_t gridPoint){ - data->gas->setTemperature(T(gridPoint)); - data->gas->setMassFractions_NoNorm(&Y(gridPoint,1)); - data->gas->setPressure(P(gridPoint)); -} - -void getTransport(UserData data, - double *ydata, - size_t gridPoint, - double *rho, - double *lambda, - double YV[]){ - - double YAvg[data->nsp], - XLeft[data->nsp], - XRight[data->nsp], - gradX[data->nsp]; - - setGas(data,ydata,gridPoint); - data->gas->getMoleFractions(XLeft); - setGas(data,ydata,gridPoint+1); - data->gas->getMoleFractions(XRight); - - for (size_t k = 1; k <=data->nsp; k++) { - YAvg(k)=HALF*(Y(gridPoint,k)+ - Y(gridPoint+1,k)); - gradX(k)=(XRight(k)-XLeft(k))/ - (R(gridPoint+1)-R(gridPoint)); - } - double TAvg = HALF*(T(gridPoint)+T(gridPoint+1)); - double gradT=(T(gridPoint+1)-T(gridPoint))/ - (R(gridPoint+1)-R(gridPoint)); - - - data->gas->setTemperature(TAvg); - data->gas->setMassFractions_NoNorm(YAvg); - data->gas->setPressure(P(gridPoint)); - - *rho=data->gas->density(); - *lambda=data->trmix->thermalConductivity(); - data->trmix->getSpeciesFluxes(1,&gradT,data->nsp, - gradX,data->nsp,YV); - //setGas(data,ydata,gridPoint); -} - -int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data){ - - /*Declare and fetch nvectors and user data:*/ - - double *ydata, *ydotdata, *resdata, *psidata, *innerMassFractionsData; - - UserData data; - data = (UserData)user_data; - size_t npts=data->npts; - size_t nsp=data->nsp; - size_t k_bath = data->k_bath; - size_t k_drop[2] = {data->k_drop[0],data->k_drop[1]}; - - ydata = N_VGetArrayPointer_OpenMP(y); - ydotdata= N_VGetArrayPointer_OpenMP(ydot); - resdata = N_VGetArrayPointer_OpenMP(res); - if(data->adaptiveGrid==1){ - psidata = data->grid->x; - }else{ - psidata = data->uniformGrid; - } - - innerMassFractionsData = data->innerMassFractions; - - /* Grid stencil:*/ - - /*-------|---------*---------|---------*---------|-------*/ - /*-------|---------*---------|---------*---------|-------*/ - /*-------|---------*---------|---------*---------|-------*/ - /*-------m-------mhalf-------j-------phalf-------p-------*/ - /*-------|---------*---------|---------*---------|-------*/ - /*-------|---------*---------|---------*---------|-------*/ - /*-------|<=======dxm=======>|<=======dxp=======>|-------*/ - /*-------|---------*<======dxav=======>*---------|-------*/ - /*-------|<================dxpm=================>|-------*/ - - /* Various variables defined for book-keeping and storing previously - * calculated values: - * rho : densities at points m, mhalf, j, p, and phalf. - * area : the matric at points m, mhalf, j, p, and phalf. - * m : exponent that determines geometry; - * lambda : thermal conductivities at mhalf and phalf. - * mdot : mass flow rate at m, j, and p. - * X : mole fractions at j and p. - * YV : diffusion fluxes at mhalf and phalf. - * Tgrad : temperature gradient at mhalf and phalf. - * Tav : average temperature between two points. - * Pav : average pressure between two points. - * Yav : average mass fractions between two points. - * Xgradhalf : mole fraction gradient at j. - * Cpb : mass based bulk specific heat. - * tranTerm : transient terms. - * advTerm : advection terms. - * diffTerm : diffusion terms. - * srcTerm : source terms. - */ - - double rhomhalf, rhom, lambdamhalf, YVmhalf[nsp], - rho, - rhophalf, lambdaphalf, YVphalf[nsp], - Cpb, Cvb, Cp[nsp], Cpl[2], dHvl[2], rhol, wdot[nsp], enthalpy[nsp], energy[nsp], - tranTerm, diffTerm, srcTerm, advTerm, - area,areamhalf,areaphalf,aream,areamhalfsq,areaphalfsq; - - /*Aliases for difference coefficients:*/ - double cendfm, cendfc, cendfp; - /*Aliases for various grid spacings:*/ - double dpsip, dpsiav, dpsipm, dpsim, dpsimm; - dpsip=dpsiav=dpsipm=dpsim=dpsimm=ONE; - //double mass, mdotIn; - double mass, massDrop; - double sum, sum1, sum2, sum3; - - size_t j,k; - int m; - m=data->metric; //Unitless - mass=data->mass; //Units: kg - //massDrop=data->massDrop; //Units: kg - //mdotIn=data->mdot*calc_area(R(npts),&m); //Units: kg/s - -// /*evaluate properties at j=1*************************/ - setGas(data,ydata,1); - rhom=data->gas->density(); - Cpb=data->gas->cp_mass(); //J/kg/K - Cvb=data->gas->cv_mass(); //J/kg/K - //TODO: Create user input model for these. They should not be constant - //Cpl=4.182e03; //J/kg/K for liquid water - //Cpl= 5.67508633e-07*pow(T(1),4) - 7.78060597e-04*pow(T(1),3) + 4.08310544e-01*pow(T(1),2) //J/kg/K for liquid water - // - 9.62429538e+01*T(1) + 1.27131046e+04; - - /*Update specific heat:Cpl for liquid proprane&n-heptane&dodecane*/ - /*Based on the existiong data,a linear expression is used*/ - // Cpl= 12.10476*T(1) - 746.60143; // Unit:J/(kg*K), Need to be improved later - //Cpl[0] = 2.423*T(1)+1661.074; //Unit:J/(kg*K),range:1atm,propane - Cpl[0] = 3.336*T(1)+1289.5; //Unit:J/(kg*K),range:1atm,n-Heptane - Cpl[1] = 3.815*T(1)+1081.8; //Unit:J/(kg*K),range:1atm,n-Dodecane - double Cp_l = 0.0; - for(size_t i=0;i<=1;i++){ - Cp_l=Cp_l+Cpl[i]*data->dropMassFrac[i]; - } - - //dHvl=2.260e6; //J/kg heat of vaporization of water - //double Tr = T(1)/647.1; //Reduced Temperature: Droplet Temperature divided by critical temperature of water - //dHvl= 5.2053e07*pow(1-Tr,0.3199 - 0.212*Tr + 0.25795*Tr*Tr)/18.01; //J/kg latent heat of vaporization of water - - double Tr1 = T(1)/369.8; //Reduced Temperature; - dHvl[0] = 6.32716e5*exp(-0.0208*Tr1)*pow((1-Tr1),0.3766); //Unit:J/kg,Latent Heat of Vaporizaiton of Liquid n-propane,NIST - - double Tr2 = T(1)/540.2; //Reduced Temperature:Droplet Temperature divided by critical temperature of liquid n-heptane, Source:NIST - dHvl[1] = 5.366e5*exp(-0.2831*Tr2) * pow((1-Tr2),0.2831); //Unit:J/kg, latent heat of vaporization of liquid n-heptane, Source: NIST - - double dHv_l = 0.0; - for(size_t i=0;i<=1;i++){ - dHv_l=dHv_l+dHvl[i]*data->dropMassFrac[i]; - } - - /*Following section is related to the property of water*/ - //rhol = 997.0; - //massDrop=1.0/3.0*R(1)*R(1)*R(1)*997.0; //TODO: The density of the droplet should be a user input - - /*Following section is related to the property of liquid n-heptane and n-dodecane (mainly density rho)*/ - /*Density of these two species should be temperature dependent*/ - //data->dropDens[0] = -1.046*T(1)+823.794; //Unit:kg/m^3,density of propane @1atm - data->dropDens[0] = -0.858*T(1)+933.854; //Unit:kg/m^3,density of n-Heptane @1atm - data->dropDens[1] = -0.782*T(1)+979.643; //Unit:kg/m^3,density of n-Dodecane @1atm - //rhol = data->dropRho; //Unit:kg/m^3 - rhol = 0.0; - for(size_t i=0;i<=1;i++){ - rhol = rhol + data->dropMassFrac[i]*data->dropDens[i]; - } - massDrop = 1.0/3.0*R(1)*R(1)*R(1)*rhol; //Unit:kg, this is the mass of liquid droplet - - aream= calc_area(R(1),&m); - - - /*******************************************************************/ - /*Calculate values at j=2's m and mhalf*****************************/ - - getTransport(data, ydata, 1, &rhomhalf,&lambdamhalf,YVmhalf); - areamhalf= calc_area(HALF*(R(1)+R(2)),&m); - aream = calc_area(R(1),&m); - areamhalfsq= areamhalf*areamhalf; - - /*******************************************************************/ - - /*Fill up res with left side (center) boundary conditions:**********/ - /*We impose zero fluxes at the center:*/ - - - /*Mass:*/ - if(data->quasiSteady){ - Rres(1)=Rdot(1); // Should remain satisfied for quasi-steady droplet - }else{ - Rres(1)=Rdot(1) + Mdot(1)/rhol/aream; - } - - /*Species:*/ - sum=ZERO; - - //TODO: Antoine Parameters should be part of user input, not hardcoded - //Yres(1,k_drop)=Y(1,k_drop) - 1.0e5*pow(10,4.6543-(1435.264/(T(1)-64.848)))*data->gas->molecularWeight(k_drop-1) - // / P(1) / data->gas->meanMolecularWeight(); - //Yres(1,k_drop)=Y(1,k_drop) - 1.0e3*pow(2.71828,16.7-(4060.0/(T(1)-37.0)))*data->gas->molecularWeight(k_drop-1) - // / P(1) / data->gas->meanMolecularWeight(); - //Yres(1,k_drop)=Y(1,k_drop)-2.566785e-02; - - /*Following using the Antoine Parameters to calculate the pressure of volatile component(n-heptane)*/ - //Antoine parameter from NIST website - double p_i[2]={0.0,0.0} ; - - p_i[0] = 1.0e5*pow(10,4.53678-(1149.36/(T(1)+24.906)))*data->dropMassFrac[0] ; //unit:Pa,For N-PROPANE - p_i[1] = 1.0e5*pow(10,4.02832-(1268.636/(T(1)-56.199)))*data->dropMassFrac[1] ; //unit:Pa,FOR N-HEPTANE - //p_i = 1.0e3*pow(2.71828,16.7-(4060.0/(T(1)-37.0))); //Unit:Pa,FOR WATER - //Yres(1,k_drop)=Y(1,k_drop) - p_i * data->gas->molecularWeight(k_drop-1) - // / P(1) / data->gas->meanMolecularWeight(); - for(size_t i=0;i<=1;i++){ - Yres(1,k_drop[i])=Y(1,k_drop[i])-p_i[i]*data->gas->molecularWeight(k_drop[i]-1)/(P(1)*data->gas->meanMolecularWeight()); - } - - - sum=sum+Y(1,k_drop[0])+Y(1,k_drop[1]); - - //Mdotres(1)=Mdot(1) - (YVmhalf(k_drop)*areamhalf) / (1-Y(1,k_drop)); //Evaporating mass - Mdotres(1)= Mdot(1) - ((YVmhalf(k_drop[0])+YVmhalf(k_drop[1])) *areamhalf) / (1-Y(1,k_drop[0])-Y(1,k_drop[1]) ); //Evaporating mass - for (k = 1; k <=nsp; k++) { - if(k!=k_bath && k!=k_drop[0] && k!=k_drop[1]){ - //TODO: May need to include chemical source term - Yres(1,k)=Y(1,k)*Mdot(1) + YVmhalf(k)*areamhalf; - //Yres(1,k)=YVmhalf(k)*areamhalf; - sum=sum+Y(1,k); - //if(fabs(Mdot(1))>1e-14){ - ///Yres(1,k)=innerMassFractionsData[k-1]- - /// Y(1,k)- - /// (YVmhalf(k)*areamhalf)/Mdot(1); - - //} - //else{ - // //Yres(1,k)=Y(1,k)-innerMassFractionsData[k-1]; - // Yres(1,k)=Y(2,k)-Y(1,k); - // /*The below flux boundary condition makes the - // * problem more prone to diverge. How does one - // * fix this?*/ - // //Yres(1,k)=YVmhalf(k); - //} - } - } - Yres(1,k_bath)=ONE-sum-Y(1,k_bath); - - /*Energy:*/ - if(data->dirichletInner){ - //Tres(1)=Tdot(1); - //Tres(1)=T(1)-data->innerTemperature; - /*Following code should be revised in the future*/ - //Tres(1)=lambdamhalf*rhomhalf*areamhalfsq*(T(2)-T(1))/((psi(2)-psi(1))*mass)/dHv_l - YVmhalf(k_drop)*areamhalf/(1-Y(1,k_drop)); - }else{ - //Tres(1)=Tdot(1) - - // (rhomhalf*areamhalfsq*lambdamhalf*(T(2)-T(1))/((psi(2)-psi(1))*mass) - Mdot(1)*dHvl) - // / (massDrop * Cpl); - - //Tres(1)=Tdot(1) - - // (areamhalf*lambdamhalf*(T(2)-T(1))/(R(2)-R(1)) - Mdot(1)*dHvl) - // / (massDrop * Cpl); - Tres(1)=Tdot(1) - - (areamhalf*lambdamhalf*(T(2)-T(1))/(R(2)-R(1)) - Mdot(1)*dHv_l) - / (massDrop * Cp_l); - - - - //Tres(1)=T(2)-T(1); - //Tres(1)=Tdot(1) - (Pdot(1)/(rhom*Cpb)) - // +(double)(data->metric+1)*(rhomhalf*lambdamhalf*areamhalfsq*(T(2)-T(1))/psi(2)-psi(1)); - } - - /*Pressure:*/ - Pres(1)=P(2)-P(1); - /*Fill up res with governing equations at inner points:*************/ - for (j = 2; j < npts; j++) { - - /*evaluate various mesh differences*/// - dpsip = (psi(j+1) - psi(j) )*mass; - dpsim = (psi(j) - psi(j-1))*mass; - dpsiav = HALF*(psi(j+1) - psi(j-1))*mass; - dpsipm = (psi(j+1) - psi(j-1))*mass; - /***********************************/// - - /*evaluate various central difference coefficients*/ - cendfm = - dpsip / (dpsim*dpsipm); - cendfc = (dpsip-dpsim) / (dpsip*dpsim); - cendfp = dpsim / (dpsip*dpsipm); - /**************************************************/ - - - /*evaluate properties at j*************************/ - setGas(data,ydata,j); - rho=data->gas->density(); //kg/m^3 - Cpb=data->gas->cp_mass(); //J/kg/K - Cvb=data->gas->cv_mass(); //J/kg/K - data->gas->getNetProductionRates(wdot); //kmol/m^3 - data->gas->getEnthalpy_RT(enthalpy); //unitless - data->gas->getCp_R(Cp); //unitless - area = calc_area(R(j),&m); //m^2 - - /*evaluate properties at p*************************/ - getTransport(data, ydata, j, &rhophalf,&lambdaphalf,YVphalf); - areaphalf= calc_area(HALF*(R(j)+R(j+1)),&m); - areaphalfsq= areaphalf*areaphalf; - /**************************************************/// - - /*Evaporating Mass*/ - Mdotres(j)=Mdot(j) - Mdot(j-1); - - /*Mass:*/ - /* ∂r/∂ψ = 1/ρA */ - Rres(j)=((R(j)-R(j-1))/dpsim)-(TWO/(rhom*aream+rho*area)); - - /*Energy:*/ - /* ∂T/∂t = - ṁ(∂T/∂ψ) - * + (∂/∂ψ)(λρA²∂T/∂ψ) - * - (A/cₚ) ∑ YᵢVᵢcₚᵢ(∂T/∂ψ) - * - (1/ρcₚ)∑ ώᵢhᵢ - * + (1/ρcₚ)(∂P/∂t) */ - /*Notes: - * λ has units J/m/s/K. - * YᵢVᵢ has units kg/m^2/s. - * hᵢ has units J/kmol, so we must multiply the enthalpy - * defined above (getEnthalpy_RT) by T (K) and the gas constant - * (J/kmol/K) to get the right units. - * cₚᵢ has units J/kg/K, so we must multiply the specific heat - * defined above (getCp_R) by the gas constant (J/kmol/K) and - * divide by the molecular weight (kg/kmol) to get the right - * units. - * */ - - //enthalpy formulation: - //tranTerm = Tdot(j) - (Pdot(j)/(rho*Cpb)); - tranTerm = Tdot(j); - sum=ZERO; - sum1=ZERO; - for (k = 1; k <=nsp; k++) { - sum=sum+wdot(k)*enthalpy(k); - sum1=sum1+(Cp(k)/data->gas->molecularWeight(k-1))*rho - *HALF*(YVmhalf(k)+YVphalf(k)); - } - sum=sum*Cantera::GasConstant*T(j); - sum1=sum1*Cantera::GasConstant; - diffTerm =(( (rhophalf*areaphalfsq*lambdaphalf*(T(j+1)-T(j))/dpsip) - -(rhomhalf*areamhalfsq*lambdamhalf*(T(j)-T(j-1))/dpsim) ) - /(dpsiav*Cpb) ) - -(sum1*area*(cendfp*T(j+1) - +cendfc*T(j) - +cendfm*T(j-1))/Cpb); - srcTerm = (sum-Qdot(&t,&R(j),&data->ignTime,&data->kernelSize,&data->maxQDot))/(rho*Cpb); // Qdot is forced heating to cause ignition, sum is the conversion of chemical enthalpy to sensible enthalpy - advTerm = (Mdot(j)*(T(j)-T(j-1))/dpsim); - Tres(j)= tranTerm - (Pdot(j)/(rho*Cpb)) - +advTerm - -diffTerm - +srcTerm; - - // //energy formulation: - // tranTerm = Tdot(j); - // sum=ZERO; - // sum1=ZERO; - // sum2=ZERO; - // sum3=ZERO; - // for (k = 1; k <=nsp; k++) { - // energy(k)=enthalpy(k)-ONE; - // sum=sum+wdot(k)*energy(k); - // sum1=sum1+(Cp(k)/data->gas->molecularWeight(k-1))*rho - // *HALF*(YVmhalf(k)+YVphalf(k)); - // sum2=sum2+(YVmhalf(k)/data->gas->molecularWeight(k-1)); - // sum3=sum3+(YVphalf(k)/data->gas->molecularWeight(k-1)); - // } - // sum=sum*Cantera::GasConstant*T(j); - // sum1=sum1*Cantera::GasConstant; - // diffTerm =(( (rhophalf*areaphalfsq*lambdaphalf*(T(j+1)-T(j))/dpsip) - // -(rhomhalf*areamhalfsq*lambdamhalf*(T(j)-T(j-1))/dpsim) ) - // /(dpsiav*Cvb) ) - // -(sum1*area*(cendfp*T(j+1) - // +cendfc*T(j) - // +cendfm*T(j-1))/Cvb); - // srcTerm = (sum-Qdot(&t,&R(j),&data->ignTime,&data->kernelSize,&data->maxQDot))/(rho*Cvb); - // advTerm = (mdotIn*(T(j)-T(j-1))/dpsim); - // advTerm = advTerm + (Cantera::GasConstant*T(j)*area/Cvb)*((sum3-sum2)/dpsiav); - // Tres(j)= tranTerm - // +advTerm - // -diffTerm - // +srcTerm; - - /*Species:*/ - /* ∂Yᵢ/∂t = - ṁ(∂Yᵢ/∂ψ) - * - (∂/∂ψ)(AYᵢVᵢ) - * + (ώᵢWᵢ/ρ) */ - - sum=ZERO; - for (k = 1; k <=nsp; k++) { - if(k!=k_bath){ - tranTerm = Ydot(j,k); - diffTerm = (YVphalf(k)*areaphalf - -YVmhalf(k)*areamhalf)/dpsiav; - srcTerm = wdot(k) - *(data->gas->molecularWeight(k-1))/rho; - advTerm = (Mdot(j)*(Y(j,k)-Y(j-1,k))/dpsim); - - Yres(j,k)= tranTerm - +advTerm - +diffTerm - -srcTerm; - - sum=sum+Y(j,k); - } - } - Yres(j,k_bath)=ONE-sum-Y(j,k_bath); - - /*Pressure:*/ - Pres(j) = P(j+1)-P(j); - - /*Assign values evaluated at p and phalf to m - * and mhalf to save some cpu cost:****************/ - areamhalf=areaphalf; - areamhalfsq=areaphalfsq; - aream=area; - rhom=rho; - rhomhalf=rhophalf; - lambdamhalf=lambdaphalf; - for (k = 1; k <=nsp; k++) { - YVmhalf(k)=YVphalf(k); - } - /**************************************************/ - - } - /*******************************************************************/// - - - /*Fill up res with right side (wall) boundary conditions:***********/ - /*We impose zero fluxes at the wall:*/ - setGas(data,ydata,npts); - rho=data->gas->density(); - area = calc_area(R(npts),&m); - - /*Mass:*/ - dpsim=(psi(npts)-psi(npts-1))*mass; - Rres(npts)=((R(npts)-R(npts-1))/dpsim)-(TWO/(rhom*aream+rho*area)); - - /*Energy:*/ - if(data->dirichletOuter){ - //Tres(npts)=T(npts)-data->wallTemperature; - Tres(npts)=Tdot(npts); - } - else{ - Tres(npts)=T(npts)-T(npts-1); - } - - /*Species:*/ - sum=ZERO; - if(data->dirichletOuter){ - for (k = 1; k <=nsp; k++) { - if(k!=k_bath){ - Yres(npts,k)=Ydot(npts,k); - sum=sum+Y(npts,k); - } - } - } - else{ - for (k = 1; k <=nsp; k++) { - if(k!=k_bath){ - Yres(npts,k)=Y(npts,k)-Y(npts-1,k); - //Yres(npts,k)=YVmhalf(k); - sum=sum+Y(npts,k); - } - } - } - Yres(npts,k_bath)=ONE-sum-Y(npts,k_bath); - - - /*Pressure:*/ - if(data->constantPressure){ - Pres(npts)=Pdot(npts)-data->dPdt; - } - else{ - Pres(npts)=R(npts)-data->domainLength; - //Pres(npts)=Rdot(npts); - } - - /*Evaporating Mass*/ - Mdotres(npts)=Mdot(npts) - Mdot(npts-1); - - //for (j = 1; j <=npts; j++) { - // //for (k = 1; k <=nsp; k++) { - // // Yres(j,k)=Ydot(j,k); - // //} - // //Tres(j)=Tdot(j); - //} - - return(0); - -} - -void printSpaceTimeHeader(UserData data) -{ - fprintf((data->output), "%15s\t","#1"); - for (size_t k = 1; k <=data->nvar+1; k++) { - fprintf((data->output), "%15lu\t",k+1); - } - fprintf((data->output), "%15lu\n",data->nvar+3); - - fprintf((data->output), "%15s\t%15s\t%15s\t","#psi","time(s)","dpsi"); - fprintf((data->output), "%15s\t%15s\t","radius(m)","Temp(K)"); - for (size_t k = 1; k <=data->nsp; k++) { - fprintf((data->output), "%15s\t",data->gas->speciesName(k-1).c_str()); - } - fprintf((data->output), "%15s\t","Pressure(Pa)"); - fprintf((data->output), "%15s\n","Mdot (kg/s)"); -} - -void printSpaceTimeOutput(double t, N_Vector* y, FILE* output, UserData data) -{ - double *ydata,*psidata; - ydata = N_VGetArrayPointer_OpenMP(*y); - - if(data->adaptiveGrid){ - psidata = data->grid->x; - }else{ - psidata = data->uniformGrid; - } - - for (size_t i = 0; i < data->npts; i++) { - fprintf(output, "%15.9e\t%15.9e\t",psi(i+1),t); - if(i==0){ - fprintf(output, "%15.9e\t",psi(2)-psi(1)); - } - else{ - fprintf(output, "%15.6e\t",psi(i+1)-psi(i)); - } - for (size_t j = 0; j < data->nvar; j++) { - if(j!=data->nvar-1){ - fprintf(output, "%15.9e\t",ydata[j+i*data->nvar]); - }else{ - fprintf(output, "%15.9e",ydata[j+i*data->nvar]); - } - } - fprintf(output, "\n"); - } - fprintf(output, "\n"); -} - -void writeRestart(double t, N_Vector* y, N_Vector* ydot, FILE* output, UserData data){ - double *ydata,*psidata, *ydotdata; - ydata = N_VGetArrayPointer_OpenMP(*y); - ydotdata = N_VGetArrayPointer_OpenMP(*ydot); - if(data->adaptiveGrid){ - psidata = data->grid->x; - }else{ - psidata = data->uniformGrid; - } - fwrite(&t, sizeof(t), 1, output); //write time - fwrite(psidata, data->npts*sizeof(psidata), 1, output); //write grid - fwrite(ydata, data->neq*sizeof(ydata), 1, output); //write solution - fwrite(ydotdata, data->neq*sizeof(ydotdata), 1, output); //write solutiondot -} - -void readRestart(N_Vector* y, N_Vector* ydot, FILE* input, UserData data){ - double *ydata,*psidata, *ydotdata; - double t; - if(data->adaptiveGrid){ - psidata = data->grid->x; - }else{ - psidata = data->uniformGrid; - } - ydata = N_VGetArrayPointer_OpenMP(*y); - ydotdata = N_VGetArrayPointer_OpenMP(*ydot); - fread(&t, sizeof(t), 1, input); - data->tNow=t; - fread(psidata, data->npts*sizeof(psidata), 1, input); - fread(ydata, data->neq*sizeof(ydata), 1, input); - fread(ydotdata, data->neq*sizeof(ydotdata), 1, input); - if(data->adaptiveGrid){ - storeGrid(data->grid->x,data->grid->xOld,data->npts); - } -} - -void printGlobalHeader(UserData data) -{ - fprintf((data->globalOutput), "%8s\t","#Time(s)"); - //fprintf((data->globalOutput), "%15s","S_u(exp*)(m/s)"); - fprintf((data->globalOutput), "%15s","bFlux(kg/m^2/s)"); - fprintf((data->globalOutput), "%16s"," IsothermPos(m)"); - fprintf((data->globalOutput), "%15s\t","Pressure(Pa)"); - fprintf((data->globalOutput), "%15s\t","Pdot(Pa/s)"); - fprintf((data->globalOutput), "%15s\t","gamma"); - fprintf((data->globalOutput), "%15s\t","S_u(m/s)"); - fprintf((data->globalOutput), "%15s\t","Tu(K)"); - fprintf((data->globalOutput), "\n"); -} -// -//void printSpaceTimeRates(double t, N_Vector ydot, UserData data) -//{ -// double *ydotdata,*psidata; -// ydotdata = N_VGetArrayPointer_OpenMP(ydot); -// psidata = N_VGetArrayPointer_OpenMP(data->grid); -// for (int i = 0; i < data->npts; i++) { -// fprintf((data->ratesOutput), "%15.6e\t%15.6e\t",psi(i+1),t); -// for (int j = 0; j < data->nvar; j++) { -// fprintf((data->ratesOutput), "%15.6e\t",ydotdata[j+i*data->nvar]); -// } -// fprintf((data->ratesOutput), "\n"); -// } -// fprintf((data->ratesOutput), "\n\n"); -//} -// -void printGlobalVariables(double t, N_Vector* y, N_Vector* ydot, UserData data) -{ - double *ydata,*ydotdata, *innerMassFractionsData, *psidata; - innerMassFractionsData = data->innerMassFractions; - - if(data->adaptiveGrid){ - psidata = data->grid->x; - }else{ - psidata = data->uniformGrid; - } - - double TAvg, RAvg, YAvg, psiAvg; - ydata = N_VGetArrayPointer_OpenMP(*y); - ydotdata = N_VGetArrayPointer_OpenMP(*ydot); - TAvg=data->isotherm; - double sum=ZERO; - double dpsim,area,aream,drdt; - double Cpb,Cvb,gamma,rho,flameArea,Tu; - - - /*Find the isotherm chosen by the user*/ - size_t j=1; - size_t jj=1; - size_t jjj=1; - double wdot[data->nsp]; - double wdotMax=0.0e0; - double advTerm=0.0e0; - psiAvg=0.0e0; - if(T(data->npts)>T(1)){ - while (T(j)k_oxidizer-1]-Y(data->npts,data->k_oxidizer); - while (fabs((T(jj+1)-T(jj))/T(jj))>1e-08) { - jj=jj+1; - } - - setGas(data,ydata,jj); - Tu=T(jj); - rho=data->gas->density(); - Cpb=data->gas->cp_mass(); //J/kg/K - Cvb=data->gas->cv_mass(); //J/kg/K - gamma=Cpb/Cvb; - - } - else{ - while (T(j)>TAvg) { - j=j+1; - } - YAvg=innerMassFractionsData[data->k_oxidizer-1]-Y(1,data->k_oxidizer); - while (fabs((T(data->npts-jj-1)-T(data->npts-jj))/T(data->npts-jj))>1e-08) { - jj=jj+1; - } - - setGas(data,ydata,data->npts-jj); - Tu=T(data->npts-jj); - rho=data->gas->density(); - Cpb=data->gas->cp_mass(); //J/kg/K - Cvb=data->gas->cv_mass(); //J/kg/K - gamma=Cpb/Cvb; - } - if(T(j)nt, data->nvar, - //// data->grid->x, data->npts); - //nMax=maxGradIndex(ydata, data->nt, data->nvar, - // data->grid->x, data->npts); - //advTerm=(T(nMax)-T(nMax-1))/(data->mass*(psi(nMax)-psi(nMax-1))); - //aream=calc_area(R(nMax),&data->metric); - ////setGas(data,ydata,nMax); - ////rho=data->gas->density(); - //psiAvg=-Tdot(nMax)/(rho*aream*advTerm); - ////if(t>data->ignTime){ - //// for(size_t n=2;nnpts;n++){ - //// setGas(data,ydata,n); - //// data->gas->getNetProductionRates(wdot); //kmol/m^3 - //// advTerm=(T(n)-T(n-1))/(data->mass*(psi(n)-psi(n-1))); - //// if(fabs(wdot[data->k_oxidizer-1])>=wdotMax){ - //// aream=calc_area(R(n),&data->metric); - //// psiAvg=-Tdot(n)/(rho*aream*advTerm); - //// wdotMax=fabs(wdot[data->k_oxidizer-1]); - //// } - //// } - ////} - ////else{ - //// psiAvg=0.0e0; - ////} - - - //drdt=(RAvg-data->flamePosition[1])/(t-data->flameTime[1]); - //data->flamePosition[0]=data->flamePosition[1]; - //data->flamePosition[1]=RAvg; - //data->flameTime[0]=data->flameTime[1]; - //data->flameTime[1]=t; - //flameArea=calc_area(RAvg,&data->metric); - - /*Use the Trapezoidal rule to calculate the mass burning rate based on - * the consumption of O2*/ - aream= calc_area(R(1)+1e-03*data->domainLength,&data->metric); - for (j = 2; j npts; j++) { - dpsim=(psi(j)-psi(j-1))*data->mass; - area= calc_area(R(j),&data->metric); - sum=sum+HALF*dpsim*((Ydot(j-1,data->k_oxidizer)/aream) - +(Ydot(j,data->k_oxidizer)/area)); - aream=area; - } - - //double maxOH,maxHO2; - //maxOH=0.0e0; - //maxHO2=0.0e0; - //for(j=1;jnpts;j++){ - // if(Y(j,data->k_OH)>maxOH){ - // maxOH=Y(j,data->k_OH); - // } - //} - //for(j=1;jnpts;j++){ - // if(Y(j,data->k_HO2)>maxHO2){ - // maxHO2=Y(j,data->k_HO2); - // } - //} - - fprintf((data->globalOutput), "%15.6e\t",t); - //fprintf((data->globalOutput), "%15.6e\t",psiAvg); - fprintf((data->globalOutput), "%15.6e\t",fabs(sum)/YAvg); - fprintf((data->globalOutput), "%15.6e\t",RAvg); - fprintf((data->globalOutput), "%15.6e\t",P(data->npts)); - fprintf((data->globalOutput), "%15.6e\t",Pdot(data->npts)); - fprintf((data->globalOutput), "%15.6e\t",gamma); - fprintf((data->globalOutput), "%15.6e\t",fabs(sum)/(YAvg*rho)); - fprintf((data->globalOutput), "%15.6e\t",Tu); - fprintf((data->globalOutput), "\n"); -} - -// -//void printSpaceTimeOutputInterpolated(double t, N_Vector y, UserData data) -//{ -// double *ydata,*psidata; -// ydata = N_VGetArrayPointer_OpenMP(y); -// psidata = N_VGetArrayPointer_OpenMP(data->grid); -// for (int i = 0; i < data->npts; i++) { -// fprintf((data->gridOutput), "%15.6e\t%15.6e\t",psi(i+1),t); -// for (int j = 0; j < data->nvar; j++) { -// fprintf((data->gridOutput), "%15.6e\t",ydata[j+i*data->nvar]); -// } -// fprintf((data->gridOutput), "\n"); -// } -// fprintf((data->gridOutput), "\n\n"); -//} -// -// -////void repairSolution(N_Vector y, N_Vector ydot, UserData data){ -//// int npts=data->npts; -//// double *ydata; -//// double *ydotdata; -//// ydata = N_VGetArrayPointer_OpenMP(y); -//// ydotdata = N_VGetArrayPointer_OpenMP(ydot); -//// -//// T(2)=T(1); -//// T(npts-1)=T(npts); -//// Tdot(2)=Tdot(1); -//// Tdot(npts-1)=Tdot(npts); -//// for (int k = 1; k <=data->nsp; k++) { -//// Y(2,k)=Y(1,k); -//// Y(npts-1,k)=Y(npts,k); -//// -//// Ydot(2,k)=Ydot(1,k); -//// Ydot(npts-1,k)=Ydot(npts,k); -//// } -////} - - -/*Following functions are added to derive the characteristic time scale of species*/ -void getTimescale(UserData data, N_Vector* y){ - size_t i, k, nsp,npts ; - nsp = data->nsp ; - npts = data->npts ; - double rho, wdot_mole[nsp], wdot_mass[nsp],MW[nsp],concentra[nsp]; - //double time_scale[npts*nsp] ; - - double* ydata ; - ydata = N_VGetArrayPointer_OpenMP(*y); //access the data stored in N_Vector* y - - for(i=1; i<= npts;i++){ - setGas(data,ydata,i); //set the gas state at each grid point - rho = data->gas->density(); //get the averaged density at each grid point, Unit:kg/m^3 - data->gas->getNetProductionRates(wdot_mole) ; //Unit:kmol/(m^3 * s) - - for(k=1; k<= nsp; k++){ - MW(k) = data->gas->molecularWeight(k-1) ; //Unit:kg/kmol - } - - for(k=1; k<= nsp; k++){ - wdot_mass(k) = wdot_mole(k) * MW(k) ; //Unit:kg/(m^3 * s) - } - - for(k=1; k<= nsp; k++){ - concentra(k) = Y(i,k) * rho ; //Unit:kg/m^3 - } - - for(k=1;k<= nsp;k++){ - data->time_scale(i,k) = concentra(k)/(wdot_mass(k)+ 1.00e-16) ; - } - - } -} - - -void printTimescaleHeader(UserData data) -{ - fprintf((data->timescaleOutput), "%15s\t","#1"); - for (size_t k = 1; k <=data->nsp+1; k++) { - fprintf((data->timescaleOutput), "%15lu\t",k+1); - } - fprintf((data->timescaleOutput), "%15lu\n",data->nsp+3); - - - fprintf((data->timescaleOutput), "%15s\t%15s\t%15s\t","#time","radius","Temp(K)"); - //fprintf((data->output), "%15s\t%15s\t","radius(m)","Temp(K)"); - for (size_t k = 1; k <=(data->nsp); k++) { - fprintf((data->timescaleOutput), "%15s\t",data->gas->speciesName(k-1).c_str()); - } - //fprintf((data->output), "%15s\t","Pressure(Pa)"); - //fprintf((data->timescaleOutput), "%15s\n",data->gas->speciesName(data->nsp-1).c_str()); - //fprintf((data->output), "%15s\n","Mdot (kg/s)"); - fprintf((data->timescaleOutput), "\n"); -} - -void printTimescaleOutput(double t,N_Vector* y,FILE* output,UserData data) -{ - double* ydata; - ydata = N_VGetArrayPointer_OpenMP(*y); - - for(size_t i=1 ; i<= data->npts; i++){ - fprintf(output, "%15.9e\t%15.9e\t",t,R(i)); - fprintf(output, "%15.9e\t",T(i)); - - for(size_t k=1; k<=data->nsp;k++){ - fprintf(output, "%15.9e\t",data->time_scale(i,k)); - } - fprintf(output, "\n"); - } - fprintf(output, "\n"); -} - -void floorSmallValue(UserData data, N_Vector* y) -{ - double* ydata; - ydata = N_VGetArrayPointer_OpenMP(*y); - //double sum = 0.00; - size_t k_bath = data->k_bath; - - /*Floor small values to zero*/ - for (size_t i = 1; i <=data->npts; i++) { - for (size_t k = 1; k <=data->nsp; k++) { - if(fabs(Y(i,k))<=data->massFractionTolerance){ - Y(i,k)=0.0e0; - } - } - } - - /*Dump the error to the bath gas*/ - for (size_t i = 1; i <=data->npts; i++) { - double sum = 0.00; - for (size_t k = 1; k <=data->nsp; k++) { - if(k!=k_bath){ - sum = sum + Y(i,k); - } - } - Y(i,k_bath) = ONE-sum; - } - - -} - -void resetTolerance(UserData data, N_Vector* y,N_Vector* atolv) -{ - double* ydata; - realtype* atolvdata; - ydata = N_VGetArrayPointer_OpenMP(*y); - atolvdata = N_VGetArrayPointer_OpenMP(*atolv); - double relTol,radTol,tempTol,presTol,massFracTol,bathGasTol,mdotTol; - double maxT=0.00, deltaT=400.0; - relTol = 1.0e-03 ; - radTol = 1.0e-05 ; - tempTol = 1.0e-03 ; - presTol = 1.0e-3 ; - massFracTol = 1.0e-06; - bathGasTol = 1.0e-05 ; - mdotTol = 1.0e-10 ; - - - /*Get the maximum Temperature*/ - for (size_t i =1;i <= data->npts;i++){ - if(T(i) > maxT){ - maxT = T(i); - } - } - - /*reset the tolerance when maxT > initialTemperature +deltaT*/ - if(maxT >= (data->initialTemperature + deltaT)){ - data->relativeTolerance = relTol; - - for(size_t i =1; i<=data->npts; i++){ - atolT(i) = tempTol; - atolR(i) = radTol ; - atolP(i) = presTol ; - atolMdot(i) = mdotTol ; - - for(size_t k =1; k<= data->nsp; k++){ - if(k!=data->k_bath){ - atolY(i,k) = massFracTol; - }else{ - atolY(i,k) = bathGasTol; - } - } - } - } - -} - -void getReactions(UserData data,N_Vector* y,FILE* output){ - double Tmax; - double* ydata; - //double deltaT = 400.0; - //int i = 0; - size_t nRxns; - int index; - nRxns = data->gas->nReactions(); - //DEBUG - printf("Total Number of Rxns:%zu \n",nRxns); - double fwdROP[nRxns],revROP[nRxns],netROP[nRxns]; - std::string* rxnArr = new std::string[nRxns]; - /*DEBUG*/ - printf("Memory Allocation for Rxns Array Succeed!\n"); - ydata = N_VGetArrayPointer_OpenMP(*y); - Tmax = maxTemperature(ydata,data->nt,data->nvar,data->npts); - //get the rxns' equation array - for(size_t ii=0;iigas->reactionString(ii); - } - if(Tmax>=(data->initialTemperature+data->deltaT)){ - index = maxTemperatureIndex(ydata,data->nt,data->nvar,data->npts); - setGas(data,ydata,index); - /*Get forward/reverse/net rate of progress of rxns*/ - data->gas->getRevRatesOfProgress(revROP); - data->gas->getFwdRatesOfProgress(fwdROP); - data->gas->getNetRatesOfProgress(netROP); - for(size_t j=0 ; jnsp],revROP[data->nsp],netROP[data->nsp]; - std::string* spArr = new std::string[data->nsp]; - /*DEBUG*/ - printf("Memory Allocation for Species Array Succeed!\n"); - ydata = N_VGetArrayPointer_OpenMP(*y); - Tmax = maxTemperature(ydata,data->nt,data->nvar,data->npts); - //get the species name array - for(size_t ii=0;iinsp;ii++){ - spArr[ii]= data->gas->speciesName(ii); - } - - if(Tmax>=(data->initialTemperature+data->deltaT)){ - //i = i + 1 ; - index = maxTemperatureIndex(ydata,data->nt,data->nvar,data->npts); - setGas(data,ydata,index); - /*Get forward/reverse/net rate of progress of rxns*/ - data->gas->getDestructionRates(revROP); - data->gas->getCreationRates(fwdROP); - data->gas->getNetProductionRates(netROP); - /*Print data to the pertinent output file*/ - for(size_t j=0 ; jnsp; j++){ - fprintf(output,"%15s\t",spArr[j]); - fprintf(output,"%15.9e\t%15.9e\t%15.9e\t\n",fwdROP[j],revROP[j],netROP[j]); - } - fprintf(output, "\n"); - fclose(output); - } - delete[] spArr; -} diff --git a/residue.d b/residue.d deleted file mode 100644 index d15b94b..0000000 --- a/residue.d +++ /dev/null @@ -1,67 +0,0 @@ -residue.o: residue.cpp residue.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_types.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_config.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/nvector/nvector_openmp.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_nvector.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/IdealGasMix.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/IdealGasPhase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/ThermoPhase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/Phase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ctexceptions.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/fmt.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ct_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/config.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/format.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/core.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/format-inl.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/format.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/printf.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/ostream.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/ext/fmt/ostream.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/Elements.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ct_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/Species.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/AnyMap.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/global.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/AnyMap.inl.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ValueCache.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/MultiSpeciesThermo.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/SpeciesThermoInterpType.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/speciesThermoTypes.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/GasKinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/BulkKinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Kinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/thermo/ThermoPhase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/StoichManager.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/stringUtils.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Reaction.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/utilities.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/global.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/RxnRates.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/reaction_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Falloff.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/RateCoeffMgr.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/RxnRates.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/ThirdBodyCalc.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/FalloffMgr.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/reaction_defs.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/FalloffFactory.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/FactoryBase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/Reaction.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/kinetics/importKinetics.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/stringUtils.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportFactory.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportBase.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LiquidTransportParams.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportParams.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/numerics/DenseMatrix.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/Array.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/utilities.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LiquidTranInteraction.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LiquidTransportData.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/LTPspecies.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/transport/TransportData.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/xml.h \ - /opt/scientific/cantera-2.4_gnu_blas/include/cantera/base/ctexceptions.h \ - UserData.h gridRoutines.h parse.h parse.hpp macros.h timing.hpp diff --git a/residue.h b/residue.h deleted file mode 100644 index eb29392..0000000 --- a/residue.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef SUNDIALS_DEF -#define SUNDIALS_DEF -#include -#include -#endif - -#ifndef PRINT_DEF -#define PRINT_DEF -#include //for strings -#include -#include -#include //for printf,scanf -#include //for atoi, atof -#endif - -#ifndef CANTERA_DEF -#define CANTERA_DEF -#include -#include -#endif - -#include "UserData.h" - -void REGRID(double* ydata,double* ydotdata,UserData data); - -void INTERPO(double* y,double* ydot,const size_t nvar,size_t nPts,const double XNEW[], const double XOLD[]); - -double maxTemperaturePosition(const double* y,const size_t nt,const size_t nvar,const double* x ,size_t nPts); - -double maxTemperature(const double* y,const size_t nt, const size_t nvar, size_t nPts); - -int maxTemperatureIndex(const double* y,const size_t nt,const size_t nvar ,size_t nPts); - -double maxCurvPositionR(const double* y, const size_t nt, - const size_t nvar, const size_t nr, size_t nPts); - -int maxCurvIndexR(const double* y, const size_t nt, - const size_t nvar, const size_t nr, size_t nPts); - -double maxGradPosition(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts); - -int maxGradIndex(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts); - -double maxCurvPosition(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts); - -int maxCurvIndex(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts); - -double isothermPosition(const double* y, const double T, const size_t nt, - const size_t nvar, const double* x, const size_t nPts); - -int setAlgebraicVariables(N_Vector *id,UserData data); - -inline double calc_area(double x,int* i); - -void updateSolution(double* y, double* ydot, const size_t nvar, - const double xOld[],const double xNew[],const size_t npts); - -void readInitialCondition(FILE* input, double* ydata, const size_t nvar, const size_t nr, const size_t nPts); - -double systemMass(double* ydata, UserData data); - -int initializePsiGrid(double* ydata, double* psidata, UserData data); - -int setInitialCondition(N_Vector* y, - N_Vector* ydot, - UserData data); - - -inline void setGas(UserData data, double *ydata, size_t gridPoint); - -void getTransport(UserData data, - double *ydata, - size_t gridPoint, - double *rho, - double *lambda, - double *YV); - -int residue(double t, - N_Vector y, - N_Vector ydot, - N_Vector res, - void *user_data); - -void trackFlameOH(N_Vector y,UserData data); -void trackFlame(N_Vector y,UserData data); -size_t BathGasIndex(UserData data); -size_t oxidizerIndex(UserData data); - -inline double Qdot(double* t, - double* x, - double* ignTime, - double* kernelSize, - double* maxQdot); - -void printSpaceTimeHeader(UserData data); -void printSpaceTimeOutput(double t, N_Vector* y, FILE* output, UserData data); -void printSpaceTimeRates(double t, N_Vector ydot, UserData data); -void printGlobalHeader(UserData data); -void printGlobalVariables(double t, N_Vector* y, N_Vector* ydot, UserData data); -void printSpaceTimeOutputInterpolated(double t, N_Vector y, UserData data); - -void writeRestart(double t, N_Vector* y, N_Vector* ydot, FILE* output, UserData data); -void readRestart(N_Vector* y, N_Vector* ydot, FILE* input, UserData data); - -void getTimescale(UserData data, N_Vector* y); -void printTimescaleHeader(UserData data); -void printTimescaleOutput(double t,N_Vector* y,FILE* output,UserData data); -void floorSmallValue(UserData data, N_Vector* y); -void resetTolerance(UserData data, N_Vector* y,N_Vector* atolv); - -void getReactions(UserData data,N_Vector* y,FILE* output); -void getSpecies(UserData data,N_Vector* y,FILE* output); diff --git a/residue.o b/residue.o deleted file mode 100644 index 37cdc94..0000000 Binary files a/residue.o and /dev/null differ diff --git a/solution.cpp b/solution.cpp deleted file mode 100644 index 9e13b06..0000000 --- a/solution.cpp +++ /dev/null @@ -1,90 +0,0 @@ -#include "solution.h" -int allocateSolution(size_t neq, - int nThreads, - N_Vector *y, - N_Vector *ydot, - N_Vector *res, - N_Vector *id, - N_Vector *atolv, - N_Vector *constraints){ - - - *y = N_VNew_OpenMP(neq,nThreads); - if(*y==NULL){ - printf("Allocation Failed!\n"); - return(1); - } - N_VConst((realtype)(0.0e0), *y); - - *ydot = N_VNew_OpenMP(neq,nThreads); - if(*ydot==NULL){ - printf("Allocation Failed!\n"); - return(1); - } - N_VConst((realtype)(0.0e0), *ydot); - - *res = N_VNew_OpenMP(neq,nThreads); - if(*res==NULL){ - printf("Allocation Failed!\n"); - return(1); - } - N_VConst((realtype)(0.0e0), *res); - - *id = N_VNew_OpenMP(neq,nThreads); - if(*id==NULL){ - printf("Allocation Failed!\n"); - return(1); - } - N_VConst((realtype)(1.0e0), *id); - - *atolv = N_VNew_OpenMP(neq,nThreads); - if(*atolv==NULL){ - printf("Allocation Failed!\n"); - return(1); - } - N_VConst((realtype)(0.0e0), *atolv); - - *constraints = N_VNew_OpenMP(neq,nThreads); - if(*constraints==NULL){ - printf("Allocation Failed!\n"); - return(1); - } - N_VConst((realtype)(0.0e0), *constraints); - - return(0); -} - -void freeSolution(N_Vector *y, - N_Vector *ydot, - N_Vector *res, - N_Vector *id, - N_Vector *atolv, - N_Vector *constraints){ - - if(*y!=NULL){ - N_VDestroy_OpenMP(*y); - printf("y Destroyed!\n"); - } - if(*ydot!=NULL){ - N_VDestroy_OpenMP(*ydot); - printf("ydot Destroyed!\n"); - } - if(*res!=NULL){ - N_VDestroy_OpenMP(*res); - printf("res Destroyed!\n"); - } - if(*id!=NULL){ - N_VDestroy_OpenMP(*id); - printf("id Destroyed!\n"); - } - if(*atolv!=NULL){ - N_VDestroy_OpenMP(*atolv); - printf("atolv Destroyed!\n"); - } - - if(*constraints!=NULL){ - N_VDestroy_OpenMP(*constraints); - printf("constraints Destroyed!\n"); - } - printf("\n\n"); -} diff --git a/solution.d b/solution.d deleted file mode 100644 index c73e56c..0000000 --- a/solution.d +++ /dev/null @@ -1,5 +0,0 @@ -solution.o: solution.cpp solution.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_types.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_config.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/nvector/nvector_openmp.h \ - /opt/scientific/sundials-3.1.1_intel_mkl/include/sundials/sundials_nvector.h diff --git a/solution.h b/solution.h deleted file mode 100644 index 7f220c3..0000000 --- a/solution.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef PRINT_DEF -#define PRINT_DEF -#include //for strings -#include //for printf,scanf -#include //for atoi, atof -#endif - -#ifndef SUNDIALS_DEF -#define SUNDIALS_DEF -#include -#include -#endif - -int allocateSolution(size_t neq, int nThreads, N_Vector *y, N_Vector *ydot, N_Vector *res, N_Vector *id, N_Vector *atolv, N_Vector *constraints); -void freeSolution(N_Vector *y, N_Vector *ydot, N_Vector *res, N_Vector *id, N_Vector *atolv, N_Vector *constraints); diff --git a/solution.o b/solution.o deleted file mode 100644 index f6e84ed..0000000 Binary files a/solution.o and /dev/null differ diff --git a/src/UserData.cpp b/src/UserData.cpp index 995d1f1..d43b70c 100644 --- a/src/UserData.cpp +++ b/src/UserData.cpp @@ -2,7 +2,18 @@ #include "parse.h" void freeUserData(UserData data){ + if(data!=NULL){ + /*destructor for C++ vector*/ + using Td = std::vector; + using Ts = std::vector; + using Tt = std::vector; + data->dropMole.~Td(); + data->dropSpec.~Ts(); + data->gamma.~Td(); + data->MW.~Td(); + data->k_drop.~Tt(); + if(data->trmix!=NULL){ delete data->trmix; printf("Transport Deleted!\n"); @@ -53,10 +64,10 @@ void freeUserData(UserData data){ fclose(data->globalOutput); printf("Global Output File Cleared from Memory!\n"); } - if(data->timescaleOutput!=NULL){ - fclose(data->timescaleOutput); - printf("Characteristic Timescale Output File Cleared from Memory!\n"); - } + // if(data->timescaleOutput!=NULL){ + // fclose(data->timescaleOutput); + // printf("Characteristic Timescale Output File Cleared from Memory!\n"); + // } //if(data->rxnROPOutput!=NULL){ // fclose(data->rxnROPOutput); // printf("Reactions Rate of Progress Output File Cleared from Memory!\n"); @@ -74,6 +85,11 @@ UserData allocateUserData(FILE *input){ UserData data; data = (UserData) malloc(sizeof *data); + new(&(data->dropMole)) std::vector; + new(&(data->dropSpec)) std::vector; + new(&(data->gamma)) std::vector; + new(&(data->MW)) std::vector; + new(&(data->k_drop)) std::vector; if(!data){ printf("Allocation Failed!\n"); @@ -83,9 +99,14 @@ UserData allocateUserData(FILE *input){ int ier; - ier=parseNumber(input, "basePts" , MAXBUFLEN, &data->npts); - if(ier==-1 || data->npts<=0){ - printf("Enter non-zero basePts!\n"); + ier=parseNumber(input, "liquidBasePts" , MAXBUFLEN, &data->l_npts); + if(ier==-1 || data->l_npts<=0){ + printf("Enter non-zero liquidbasePts!\n"); + return(NULL); + } + ier=parseNumber(input, "gasBasePts" , MAXBUFLEN, &data->g_npts); + if(ier==-1 || data->g_npts<=0){ + printf("Enter non-zero gasBasePts!\n"); return(NULL); } @@ -120,16 +141,16 @@ UserData allocateUserData(FILE *input){ return(NULL); } - ier=parseNumber(input,"dropType",MAXBUFLEN,&data->dropType); + ier=parseNumber(input,"dropletType",MAXBUFLEN,&data->dropType); if(ier==-1 || (data->dropType!=0 && data->dropType!=1)){ printf("include valid dropletType!\n"); printf("0: single component droplet\n"); - printf("1: multi-component droplet\n"); + printf("1: bi-component droplet\n"); return(NULL); } - ier=parseDropSpec(input,"dropletMole",MAXBUFLEN,&data->dropType,dropMole); + ier=parseDropSpec(input,"dropletMole",MAXBUFLEN,&data->dropType,data->dropMole); if(ier== -1){ printf("include correct format for droplet mole fraction!\n"); printf("single composition droplet: dropletMole:1.00\n"); @@ -137,7 +158,7 @@ UserData allocateUserData(FILE *input){ return(NULL); } - ier=parseDropSpec(input,"dropletComposition",MAXBUFLEN,&data->dropType,dropSpec); + ier=parseDropSpec(input,"dropletComposition",MAXBUFLEN,&data->dropType,data->dropSpec); if(ier== -1){ printf("include correct format for droplet composition!\n"); printf("single composition droplet: dropletComposition:n-heptane\n"); @@ -146,14 +167,14 @@ UserData allocateUserData(FILE *input){ } - //ier=parseNumber(input, "quasiSteady" , MAXBUFLEN, &data->quasiSteady); - //if(ier==-1 || (data->quasiSteady!=0 - // && data->quasiSteady!=1)){ - // printf("include valid quasiSteady!\n"); - // printf("0: The droplet surface recedes and the droplet losses mass\n"); - // printf("1: The droplet surface does not move and the droplet mass is constant\n"); - // return(NULL); - //} + ier=parseNumber(input, "quasiSteady" , MAXBUFLEN, &data->quasiSteady); + if(ier==-1 || (data->quasiSteady!=0 + && data->quasiSteady!=1)){ + printf("include valid quasiSteady!\n"); + printf("0: The droplet surface recedes and the droplet losses mass\n"); + printf("1: The droplet surface does not move and the droplet mass is constant\n"); + return(NULL); + } ier=parseNumber(input, "dPdt", MAXBUFLEN, &data->dPdt); @@ -340,6 +361,13 @@ UserData allocateUserData(FILE *input){ } } +// /*No. of liquid phase species is determined by droplet type, either 1 or 2*/ +// if(data->dropType==0){ +// data->l_nsp=1; +// }else{ +// data->l_nsp=2; +// } + ier=parseNumber(input, "transportModel", MAXBUFLEN, tran); if(ier==-1){ printf("Enter transportModel!\n"); @@ -371,7 +399,7 @@ UserData allocateUserData(FILE *input){ } } } - + //ier=parseNumber(input, "dropletComposition", MAXBUFLEN, data->dropSpec); //if(ier==-1){ // printf("Enter composition of droplet!\n"); @@ -390,43 +418,62 @@ UserData allocateUserData(FILE *input){ ier=parseNumber(input, "PCAD", MAXBUFLEN, &data->PCAD); - if(ier==-1){ - printf("Enter PCAD value!\n"); - return(NULL); - } + // if(ier==-1){ + // printf("Enter PCAD value!\n"); + // return(NULL); + // } ier=parseNumber(input,"RGTC", MAXBUFLEN, &data->RGTC); - if(ier==-1){ - printf("Enter PGTC value!\n"); - return(NULL); - } + // if(ier==-1){ + // printf("Enter PGTC value!\n"); + // return(NULL); + // } ier=parseNumber(input,"JJRG", MAXBUFLEN, &data->JJRG); - if(ier==-1){ - printf("Enter JJRG value!\n"); - return(NULL); - } + // if(ier==-1){ + // printf("Enter JJRG value!\n"); + // return(NULL); + // } ier=parseNumber(input,"deltaT", MAXBUFLEN, &data->deltaT); - if(ier==-1){ - printf("Enter deltaT value!\n"); - return(NULL); - } + // if(ier==-1){ + // printf("Enter deltaT value!\n"); + // return(NULL); + // } data->nr=0; //data->np=data->nr+1; data->nt=data->nr+1; data->ny=data->nt+1; data->np=data->ny+data->nsp; - data->nm=data->np+1; - + data->nm=data->np+1; data->nvar=data->nsp+4; //assign no: of variables (R,T,P,Mdot,nsp species) - - double MW[2]; - for(int i=0;i<=1;i++){ - int speciesIndex = data->gas->speciesIndex(data->dropSpec[i]); - double weight = data->gas->molecularWeight(speciesIndex); - MW[i]= weight; + // data->l_nr=0; + // data->np=data->nr+1; + // data->l_nt=data->l_nr+1; + // data->l_ny=data->l_nt+1; + // data->l_np=data->l_ny+data->l_nsp; //l_nsp is either 1 or 2 + // data->l_nm=data->l_np+1; + // data->l_nvar=data->l_nsp+4; + + data->npts = data->l_npts+data->g_npts; + //std::vector MW(data->dropMole.size()); + for(size_t ii=0;ii< data->dropMole.size();ii++){ +// printf("Print inside the loop.\n" ) ; +// printf("Print dropSpec component :%s! \n",data->dropSpec[0].c_str()); +// size_t index = 0; + for(size_t k = 1; k <= data->nsp; k++) { + printf("spcies name :%s! \t",data->gas->speciesName(k-1).c_str()); + if(data->gas->speciesName(k - 1)==data->dropSpec[ii] ) { +// index = k; + double weight = data->gas->molecularWeight(k-1); + printf("Molecular weight is: %.3f. \n",weight) ; + data->MW.push_back(weight); + } + } + } +// printf("MW array size: %zu\n",data->MW.size()); + for(auto & arg :data->MW){ + printf("Molecular weight : %.3f. \n",arg) ; } - // double massSum = 0.0; // for(int i=0;i<=1;i++){ // massSum = massSum + data->dropMole[i] * MW[i]; @@ -437,19 +484,29 @@ UserData allocateUserData(FILE *input){ // data->dropRho = data->dropRho + data->dropMassFrac[i]*data->dropDens[i]; // } - printf("Density of droplet is: %.3f [kg/m^3]\n",data->dropRho); - //Mass of droplet + // printf("Density of droplet is: %.3f [kg/m^3]\n",data->dropRho); + // Mass of droplet //data->massDrop=1.0/3.0*pow(data->Rd,3)*997.0; //TODO: The density of the droplet should be a user input //data->massDrop=1.0/3.0*pow(data->Rd,3)*684.00; //TODO: The density of the droplet(n-heptane) should be a user input - data->massDrop=1.0/3.0*pow(data->Rd,3)*data->dropRho; + // data->massDrop=1.0/3.0*pow(data->Rd,3)*data->dropRho; /* Update the gamma using UNIFAC method for propane and n-heptane */ - getGamma(data->dropMole,data->gamma) ; - printf("Gamma of Propane and n-heptane are %.3f and %.3f .\n",data->gamma[0],data->gamma[1]) ; + /*Note: gamma only need to be calculated when droplet type = 1, i.e. bi-component*/ + getGamma(data->dropMole,data->gamma); +// printf("Gamma of Propane and n-heptane are %.3f and %.3f .\n",data->gamma[0],data->gamma[1]) ; + if(data->dropType == 0){ + printf("Single component droplet problem, activity coeffcient is 1. \n"); + }else{ + for(auto & arg : data->gamma) { + printf("Initial activity coeffcient %.3f .\n",arg); + } + } if(!data->adaptiveGrid){ data->uniformGrid = new double [data->npts]; - data->neq=data->nvar*data->npts; + // data->g_neq=data->g_nvar*data->g_npts; + // data->l_neq=data->l_nvar*data->l_npts; + data->neq=data->npts*data->nvar; } else{ data->grid=(UserGrid) malloc(sizeof *data->grid); @@ -469,9 +526,9 @@ UserData allocateUserData(FILE *input){ data->output=fopen("output.dat","w"); data->globalOutput=fopen("globalOutput.dat","w"); data->gridOutput=fopen("grid.dat","w"); - data->timescaleOutput=fopen("timeScale.dat","w") ; - data->rxnROPOutput=fopen("rxnROP.dat","w"); - data->spROPOutput=fopen("spROP.dat","w"); + // data->timescaleOutput=fopen("timeScale.dat","w") ; + // data->rxnROPOutput=fopen("rxnROP.dat","w"); + // data->spROPOutput=fopen("spROP.dat","w"); //data->ratesOutput=fopen("rates.dat","w"); data->innerMassFractions = new double [data->nsp]; @@ -518,6 +575,7 @@ void setSaneDefaults(UserData data){ data->pressureTolerance=1e-06; data->massFractionTolerance=1e-09; data->bathGasTolerance=1e-06; + data->MdotTolerance=1e-09; data->finalTime=1e-02; data->tNow=0.0e0; data->setConstraints=0; @@ -571,5 +629,46 @@ void getGamma(const double mole[],double gamma[]){ for(int i=0; i& mole,std::vector& gamma){ + size_t sz = mole.size(); + if (sz == 1){ + gamma.push_back(1); + }else{ + gamma.reserve(mole.size()); + /* define relevant matrix */ + Eigen::Matrix2d nu_ ; + nu_ << 2,1,2,5; + /* define relevant vectors */ + Eigen::Vector2d R_(0.9011,0.6744),Q_(0.8480,0.5400); + Eigen::Vector2d r_,q_,x_,l_,ones_(1.0,1.0),v_,ksi_,gammaC_; + double sum_q, sum_r,sum_l; + + r_ = nu_ * R_ ; + q_ = nu_ * Q_ ; + x_ << mole[0], mole[1] ; + + sum_q = x_.dot(q_) ; + sum_r = x_.dot(r_) ; + + for(size_t i=0; iclockStart=get_wall_time(); - + data->clockStart=get_wall_time(); // /**************** TEST THE xOld *******************/ // double* ptr1 = data->grid->xOld ; @@ -118,7 +117,7 @@ int main(){ ier=IDADlsSetLinearSolver(mem,LS,A); //ier = IDABand(mem, data->neq, mu, ml); - constraintsdata = N_VGetArrayPointer_OpenMP(constraints); + constraintsdata = N_VGetArrayPointer_OpenMP(constraints); if(data->setConstraints){ for (size_t i = 1; i <=data->npts; i++) { for (size_t k = 1; k <=data->nsp; k++) { @@ -137,9 +136,11 @@ int main(){ if(check_flag(&ier, "IDASetSuppressAlg", 1)) return(1); //ier= IDASetMaxNumStepsIC(mem, 1); - //ier= IDASetMaxNumJacsIC(mem,8); - //ier= IDASetMaxNumItersIC(mem,100); - //ier= IDASetMaxBacksIC(mem,2000); +// ier= IDASetMaxNumStepsIC(mem, 8); + //ier= IDASetMaxNumJacsIC(mem,8); +// ier= IDASetMaxNumItersIC(mem,100); +// ier= IDASetMaxBacksIC(mem,2000); +// ier= IDASetMaxBacksIC(mem,1000); //ier = IDASetLineSearchOffIC(mem,SUNTRUE); //////// DEBUG /////////// @@ -169,7 +170,8 @@ int main(){ printf("Calculating Initial Conditions:\n"); printf("Cross your fingers...\n"); - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, 1e-5*finalTime); +// ier = IDACalcIC(mem, IDA_YA_YDP_INIT, 1e-5*finalTime); + ier = IDACalcIC(mem, IDA_YA_YDP_INIT, 1e-7*finalTime); //If at first IDACalcIC doesn't succeed, try, try, try again: for (int i = 0; i < 10; i++) { @@ -195,7 +197,7 @@ int main(){ printSpaceTimeHeader(data); printGlobalHeader(data); - printTimescaleHeader(data); + //printTimescaleHeader(data); printSpaceTimeOutput(tNow, &y, data->output, data); printSpaceTimeOutput(tNow, &y, data->gridOutput, data); @@ -223,11 +225,11 @@ int main(){ //xOld=isothermPosition(ydata, data->isotherm, data->nt, // data->nvar, data->grid->x, data->npts); } - while (tNow<=finalTime && R(1)>100e-9) { + while (tNow<=finalTime && R(data->l_npts)>100e-9) { t1=tNow; /*Floor small value to zero*/ - floorSmallValue(data, &y); + // floorSmallValue(data, &y); if(data->quasiSteady){ @@ -249,9 +251,9 @@ int main(){ ier = IDAGetCurrentOrder(mem, &kcur); /******** Print the max Temperature *********/ - double maxT = 0.00; - maxT = maxTemperature(ydata,data->nt,data->nvar,data->npts); - printf("Maximum temperature is : %.3f[K] \n",maxT); + // double maxT = 0.00; + // maxT = maxTemperature(ydata,data->nt,data->nvar,data->npts); + // printf("Maximum temperature is : %.3f[K] \n",maxT); if(data->adaptiveGrid==1 && data->moveGrid==1){ x=maxCurvPosition(ydata, data->nt, data->nvar, @@ -337,65 +339,64 @@ int main(){ } /*Print Liquid Thermodynamic data*/ - double rho = getLiquidRho(data->dropMole,T(1),P(1)); - double Cp = getLiquidCp(data->dropMole,T(1),P(1)); - double deltaH = getLiquidHv(data->dropMole,T(1),P(1)); - double boil_T = getLiquidMaxT(data->dropMole,P(1)); - printf("The Mean Density of Liquid Phase:%6.3e [kg/m^3]\n",rho); - printf("The Mean Specific Heat Capacity of Liquid Phase:%6.3e [J/(kg*K)]\n",Cp); - printf("The Mean Heat of Evaporation of Liquid Phase:%6.3e [J/kg]\n",deltaH); - printf("The Boiling Point of More Volitile Component (Propane):%6.3e [K]\n",boil_T); - printf("Temperature at the liquid/gas phase interface:%6.3e [K]\n\n",T(1)); + // double rho = getLiquidRho(data->dropMole,T(1),P(1)); + // double Cp = getLiquidCp(data->dropMole,T(1),P(1)); + // double deltaH = getLiquidHv(data->dropMole,T(1),P(1)); + // double boil_T = getLiquidMaxT(data->dropMole,P(1)); + // printf("The Mean Density of Liquid Phase:%6.3e [kg/m^3]\n",rho); + // printf("The Mean Specific Heat Capacity of Liquid Phase:%6.3e [J/(kg*K)]\n",Cp); + // printf("The Mean Heat of Evaporation of Liquid Phase:%6.3e [J/kg]\n",deltaH); + // printf("The Boiling Point of More Volitile Component (Propane):%6.3e [K]\n",boil_T); + // printf("Temperature at the liquid/gas phase interface:%6.3e [K]\n\n",T(1)); /*reset the tolerance after ignition*/ //resetTolerance(data,&y,&atolv); /*regrid and update the solution based on R,re-initialize the problem*/ /*For the time being,we only allow TORC to REGRID once for each run*/ - - if(data->JJRG ==1 && (maxT >= data->initialTemperature+data->deltaT)){ - if(RGCOUNT<1){ - RGCOUNT = RGCOUNT +1; - REGRID(ydata,ydotdata,data); - initializePsiGrid(ydata,data->uniformGrid,data); - printf("REGRID Complete!Restarting Problem at %15.6e s\n",tNow); - ier = IDAReInit(mem,tNow,y,ydot); - - if(check_flag(&ier,"IDAReInit",1)){ - freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); - return(-1); - } - - ier= IDASetInitStep(mem,1e-01*dt); - //ier= IDASetInitStep(mem,0.0); - printf("Reinitialized!Calculating Initial Conditions:\n"); - printf("Cross your fingers...\n"); - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+1e-01*dt); - if(check_flag(&ier, "IDACalcIC", 1)){ - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+1e+01*dt); - } - //Every once in a while, for reasons - //that befuddle this mathematically - //lesser author, IDACalcIC fails. Here, - //I desperately try to make it converge - //again by sampling increasingly larger - //time-steps: - for (int i = 0; i < 10; i++) { - ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+(1e-01+pow(10,i)*dt)); - if(ier==0){ - break; - } - } - //Failure :( Back to the drawing board: - if(check_flag(&ier, "IDACalcIC", 1)){ - freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); - return(-1); - } - printf("Initial (Consistent) Conditions Calculated!\n"); - printf("------------------------------------------\n\n"); - - } - } +// if(data->JJRG ==1 && (maxT >= data->initialTemperature+data->deltaT)){ +// if(RGCOUNT<1){ +// RGCOUNT = RGCOUNT +1; +// REGRID(ydata,ydotdata,data); +// initializePsiGrid(ydata,data->uniformGrid,data); +// printf("REGRID Complete!Restarting Problem at %15.6e s\n",tNow); +// ier = IDAReInit(mem,tNow,y,ydot); +// +// if(check_flag(&ier,"IDAReInit",1)){ +// freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); +// return(-1); +// } +// +// ier= IDASetInitStep(mem,1e-01*dt); +// //ier= IDASetInitStep(mem,0.0); +// printf("Reinitialized!Calculating Initial Conditions:\n"); +// printf("Cross your fingers...\n"); +// ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+1e-01*dt); +// if(check_flag(&ier, "IDACalcIC", 1)){ +// ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+1e+01*dt); +// } +// //Every once in a while, for reasons +// //that befuddle this mathematically +// //lesser author, IDACalcIC fails. Here, +// //I desperately try to make it converge +// //again by sampling increasingly larger +// //time-steps: +// for (int i = 0; i < 10; i++) { +// ier = IDACalcIC(mem, IDA_YA_YDP_INIT, tNow+(1e-01+pow(10,i)*dt)); +// if(ier==0){ +// break; +// } +// } +// //Failure :( Back to the drawing board: +// if(check_flag(&ier, "IDACalcIC", 1)){ +// freeAtLast(mem,&y,&ydot,&res,&id,&atolv,&constraints,data); +// return(-1); +// } +// printf("Initial (Consistent) Conditions Calculated!\n"); +// printf("------------------------------------------\n\n"); +// +// } +// } /*Floor small value to zero*/ //floorSmallValue(data, &y); @@ -409,11 +410,11 @@ int main(){ /*Get and Print Rxns Rate of Progress and Specie Rate of Production data*/ /*Following code snippet will be executed only once*/ - if(ii==0 && maxT >=(data->initialTemperature+data->deltaT)){ - getReactions(data,&y,data->rxnROPOutput); - getSpecies(data,&y,data->spROPOutput); - ii++; - } + // if(ii==0 && maxT >=(data->initialTemperature+data->deltaT)){ + // getReactions(data,&y,data->rxnROPOutput); + // getSpecies(data,&y,data->spROPOutput); + // ii++; + // } // getTimescale(data,&y); // if(count%data->nSaves==0){ // printTimescaleOutput(tNow,&y, data->timescaleOutput,data); diff --git a/src/parse.cpp b/src/parse.cpp index a4060ce..4e31908 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -85,46 +85,48 @@ int parseDrop(FILE* input, const char* keyword,char dropSpec[][10],double dropMo return(-1); } -/* Specialization for string */ -template<> -int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector& dropPara){ - char buf[bufLen]; - char buf1[bufLen]; - char comment[1]; - char *ret; - while (fgets(buf,bufLen, input)!=NULL){ - comment[0]=buf[0]; - if(strncmp(comment,"#",1)==0){ - //printf("Comment!:%s\n",buf); - } - else{ - ret=strtok(buf,"="); - if(strcmp(ret,keyword)==0){ - /*offset buf by keyword size + 1 for the "="*/ - /* Second argument in the strncpy function is the address !!! */ - /* Note: current version of code can only take dropType =0 or 1 */ - strncpy(buf1, buf+strlen(keyword)+1, bufLen); - printf("%10s: ",keyword); - if(*dropType ==0){ - /* Convert from char* to string */ - std::string str(buf1); - dropPara.push_back(str); - printf("%s\n",dropPara[0].c_str()); - }else{ - std::istringstream iss(buf1) ; - std::string token; - while(std::getline(iss,token,',')){ - //std::stod(token); - dropPara.push_back(token); - } - printf("%s,%s\n",dropPara[0].c_str(),dropPara[1].c_str()); - } - rewind(input); - return(0); - } - } - } - rewind(input); - return(-1); -} \ No newline at end of file + +///* Specialization for string */ +//template<> +//int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector& dropPara){ +// char buf[bufLen]; +// char buf1[bufLen]; +// char comment[1]; +// char *ret; +// +// while (fgets(buf,bufLen, input)!=NULL){ +// comment[0]=buf[0]; +// if(strncmp(comment,"#",1)==0){ +// //printf("Comment!:%s\n",buf); +// } +// else{ +// ret=strtok(buf,"="); +// if(strcmp(ret,keyword)==0){ +// /*offset buf by keyword size + 1 for the "="*/ +// /* Second argument in the strncpy function is the address !!! */ +// /* Note: current version of code can only take dropType =0 or 1 */ +// strncpy(buf1, buf+strlen(keyword)+1, bufLen); +// printf("%10s: ",keyword); +// if(*dropType ==0){ +// /* Convert from char* to string */ +// std::string str(buf1); +// dropPara.push_back(str); +// printf("%s\n",dropPara[0].c_str()); +// }else{ +// std::istringstream iss(buf1) ; +// std::string token; +// while(std::getline(iss,token,',')){ +// //std::stod(token); +// dropPara.push_back(token); +// } +// printf("%s,%s\n",dropPara[0].c_str(),dropPara[1].c_str()); +// } +// rewind(input); +// return(0); +// } +// } +// } +// rewind(input); +// return(-1); +//} \ No newline at end of file diff --git a/src/residue.cpp b/src/residue.cpp index 4c92286..de2a133 100644 --- a/src/residue.cpp +++ b/src/residue.cpp @@ -1,114 +1,118 @@ #ifndef GSL_DEF #define GSL_DEF + #include #include + #endif + #include "residue.h" #include "macros.h" #include #include #include "timing.hpp" -void REGRID(double* ydata,double* ydotdata,UserData data){ +void REGRID(double *ydata, double *ydotdata, UserData data) { size_t nPts = data->npts; size_t nvar = data->nvar; - double WORK[nPts],XNEW[nPts],XOLD[nPts]; - double P,R,R0,R1,R2,TV1,TV2,XLEN,B1,B2; - double DX,DDX; - double DETA,ETAJ,DEL; - size_t ISTART; + double WORK[nPts], XNEW[nPts], XOLD[nPts]; + double P, R, R0, R1, R2, TV1, TV2, XLEN, B1, B2; + double DX, DDX; + double DETA, ETAJ, DEL; + size_t ISTART; P = data->PCAD; R = data->RGTC; - R0 =1.0 - P; - R1 =P*R/(R+1.0); - R2 =P - R1 ; - TV1 = 0.0; + R0 = 1.0 - P; + R1 = P * R / (R + 1.0); + R2 = P - R1; + TV1 = 0.0; TV2 = 0.0; - for(size_t i=2;i<=nPts;i++){ - TV1 = TV1 + fabs(T(i)-T(i-1)); + for (size_t i = 2; i <= nPts; i++) { + TV1 = TV1 + fabs(T(i) - T(i - 1)); } - - for(size_t i=2;i<=nPts-1;i++){ - TV2 = TV2 + fabs( (T(i+1)-T(i))/(R(i+1)-R(i)) - (T(i)-T(i-1))/(R(i)-R(i-1)) ); + + for (size_t i = 2; i <= nPts - 1; i++) { + TV2 = TV2 + fabs((T(i + 1) - T(i)) / (R(i + 1) - R(i)) - (T(i) - T(i - 1)) / (R(i) - R(i - 1))); } - - XLEN = R(nPts) - R(1); - B1 = R1* XLEN/ ( (1.0-P)*TV1); - B2 = R2* XLEN/ ( (1.0-P)*TV2); + + XLEN = R(nPts) - R(1); + B1 = R1 * XLEN / ((1.0 - P) * TV1); + B2 = R2 * XLEN / ((1.0 - P) * TV2); //Compute partial sum of weight function - WORK(1) =0.0; + WORK(1) = 0.0; DX = 0.0; - for(size_t i=2;i<=nPts-1;i++){ - DX = R(i) - R(i-1) ; - WORK(i) = DX + B1*fabs(T(i)-T(i-1)) + WORK(i-1)+B2*fabs( (T(i+1)-T(i))/(R(i+1)-R(i)) - (T(i)-T(i-1))/(R(i)-R(i-1)) ); + for (size_t i = 2; i <= nPts - 1; i++) { + DX = R(i) - R(i - 1); + WORK(i) = DX + B1 * fabs(T(i) - T(i - 1)) + WORK(i - 1) + + B2 * fabs((T(i + 1) - T(i)) / (R(i + 1) - R(i)) - (T(i) - T(i - 1)) / (R(i) - R(i - 1))); } - - DDX = R(nPts) - R(nPts-1); - WORK(nPts) = WORK(nPts-1) +DDX ; - - for(size_t i=2;i<=nPts;i++){ - WORK(i) = WORK(i)/WORK(nPts); + + DDX = R(nPts) - R(nPts - 1); + WORK(nPts) = WORK(nPts - 1) + DDX; + + for (size_t i = 2; i <= nPts; i++) { + WORK(i) = WORK(i) / WORK(nPts); } - - XNEW(1)=R(1); - XNEW(nPts)=R(nPts); - ISTART =2; + + XNEW(1) = R(1); + XNEW(nPts) = R(nPts); + ISTART = 2; //double DETA; - DETA = 1.0/(nPts-1) ; + DETA = 1.0 / (nPts - 1); //Fill new grid XNEW[nPts],duplicate from PREMIX REGRID SUBROUTINE - for(size_t j=2;j<=nPts-1;j++){ - ETAJ= (j-1)*DETA; + for (size_t j = 2; j <= nPts - 1; j++) { + ETAJ = (j - 1) * DETA; - for(size_t i=ISTART;i<=nPts;i++){ - if(ETAJ <= WORK(i)){ - DEL = (ETAJ-WORK(i-1))/(WORK(i)-WORK(i-1)) ; - XNEW(j)=R(i-1)+(R(i)-R(i-1))*DEL; + for (size_t i = ISTART; i <= nPts; i++) { + if (ETAJ <= WORK(i)) { + DEL = (ETAJ - WORK(i - 1)) / (WORK(i) - WORK(i - 1)); + XNEW(j) = R(i - 1) + (R(i) - R(i - 1)) * DEL; break; - }else{ - ISTART =i; + } else { + ISTART = i; } } } //Interpolate solution based on XNEW[]&XOLD[] - for(size_t i=1;i<=nPts;i++){ - XOLD[i-1]=R(i); + for (size_t i = 1; i <= nPts; i++) { + XOLD[i - 1] = R(i); } - INTERPO(ydata,ydotdata,nvar,nPts,XNEW,XOLD); + INTERPO(ydata, ydotdata, nvar, nPts, XNEW, XOLD); } -void INTERPO(double* y,double* ydot,const size_t nvar,size_t nPts,const double XNEW[], const double XOLD[]){ - double ytemp[nPts],ydottemp[nPts] ; - - gsl_interp_accel* acc; - gsl_spline* spline; +void INTERPO(double *y, double *ydot, const size_t nvar, size_t nPts, const double XNEW[], const double XOLD[]) { + double ytemp[nPts], ydottemp[nPts]; + + gsl_interp_accel *acc; + gsl_spline *spline; acc = gsl_interp_accel_alloc(); - spline = gsl_spline_alloc(gsl_interp_steffen,nPts); - - gsl_interp_accel* accdot; - gsl_spline* splinedot; + spline = gsl_spline_alloc(gsl_interp_steffen, nPts); + + gsl_interp_accel *accdot; + gsl_spline *splinedot; accdot = gsl_interp_accel_alloc(); - splinedot = gsl_spline_alloc(gsl_interp_steffen,nPts); + splinedot = gsl_spline_alloc(gsl_interp_steffen, nPts); - for(size_t j=0;j maxT){ - maxT = TempT ; - pos = x[i-1]; + for (size_t i = 1; i <= nPts; i++) { + TempT = y[(i - 1) * nvar + nt]; + if (TempT > maxT) { + maxT = TempT; + pos = x[i - 1]; } } - return(pos); + return (pos); } -double maxTemperature(const double* y,const size_t nt,const size_t nvar ,size_t nPts){ +double maxTemperature(const double *y, const size_t nt, const size_t nvar, size_t nPts) { double maxT = 0.0e0; double TempT = 0.0e0; - //int index = 0 ; - for (size_t i=1;i<=nPts;i++){ - TempT = y[(i-1)*nvar+nt] ; - if(TempT > maxT){ - maxT = TempT ; + //int index = 0 ; + for (size_t i = 1; i <= nPts; i++) { + TempT = y[(i - 1) * nvar + nt]; + if (TempT > maxT) { + maxT = TempT; } } - return(maxT); + return (maxT); } + //Index here is 1-based -int maxTemperatureIndex(const double* y,const size_t nt,const size_t nvar ,size_t nPts){ +int maxTemperatureIndex(const double *y, const size_t nt, const size_t nvar, size_t nPts) { double maxT = 0.0e0; double TempT = 0.0e0; - int index = 0 ; - for (size_t i=1;i<=nPts;i++){ - TempT = y[(i-1)*nvar+nt] ; - if(TempT > maxT){ - maxT = TempT ; - index = i; + int index = 0; + for (size_t i = 1; i <= nPts; i++) { + TempT = y[(i - 1) * nvar + nt]; + if (TempT > maxT) { + maxT = TempT; + index = i; } } - return(index); + return (index); } -double maxCurvPositionR(const double* y, const size_t nt, - const size_t nvar, const size_t nr, size_t nPts){ - double maxCurvT=0.0e0; - double gradTp=0.0e0; - double gradTm=0.0e0; - double curvT=0.0e0; - double dx=0.0e0; - double dr=0.0e0; - double pos=0.0e0; - size_t j,jm,jp; - size_t r,rp,rm; - for (size_t i = 1; i =maxCurvT) { - maxCurvT=curvT; - pos=y[r]; - } - } - return(pos); +double maxCurvPositionR(const double *y, const size_t nt, + const size_t nvar, const size_t nr, size_t nPts) { + double maxCurvT = 0.0e0; + double gradTp = 0.0e0; + double gradTm = 0.0e0; + double curvT = 0.0e0; + double dx = 0.0e0; + double dr = 0.0e0; + double pos = 0.0e0; + size_t j, jm, jp; + size_t r, rp, rm; + for (size_t i = 1; i < nPts - 1; i++) { + j = i * nvar + nt; + jm = (i - 1) * nvar + nt; + jp = (i + 1) * nvar + nt; + r = i * nvar + nr; + rm = (i - 1) * nvar + nr; + rp = (i + 1) * nvar + nr; + //gradTp=fabs((y[jp]-y[j])/(x[i+1]-x[i])); + //gradTm=fabs((y[j]-y[jm])/(x[i]-x[i-1])); + //dx=0.5e0*((x[i]+x[i+1])-(x[i-1]+x[i])); + //curvT=(gradTp-gradTm)/dx; + gradTp = fabs((y[jp] - y[j]) / (y[rp] - y[r])); + gradTp = fabs((y[j] - y[jm]) / (y[r] - y[rm])); + dr = 0.5e0 * (y[rp] - y[rm]); + curvT = (gradTp - gradTm) / dr; + if (curvT >= maxCurvT) { + maxCurvT = curvT; + pos = y[r]; + } + } + return (pos); } -int maxCurvIndexR(const double* y, const size_t nt, - const size_t nvar, const size_t nr, size_t nPts){ - double maxCurvT=0.0e0; - double gradTp=0.0e0; - double gradTm=0.0e0; - double curvT=0.0e0; - double dx=0.0e0; - double dr=0.0e0; - int pos=0; - size_t j,jm,jp; - size_t r,rm,rp; - for (size_t i = 1; i =maxCurvT) { - maxCurvT=curvT; - pos=i; - } - } - return(pos); +int maxCurvIndexR(const double *y, const size_t nt, + const size_t nvar, const size_t nr, size_t nPts) { + double maxCurvT = 0.0e0; + double gradTp = 0.0e0; + double gradTm = 0.0e0; + double curvT = 0.0e0; + double dx = 0.0e0; + double dr = 0.0e0; + int pos = 0; + size_t j, jm, jp; + size_t r, rm, rp; + for (size_t i = 1; i < nPts - 1; i++) { + j = i * nvar + nt; + jm = (i - 1) * nvar + nt; + jp = (i + 1) * nvar + nt; + r = i * nvar + nr; + rm = (i - 1) * nvar + nr; + rp = (i + 1) * nvar + nr; + //gradTp=fabs((y[jp]-y[j])/(x[i+1]-x[i])); + //gradTm=fabs((y[j]-y[jm])/(x[i]-x[i-1])); + //dx=0.5e0*((x[i]+x[i+1])-(x[i-1]+x[i])); + //curvT=(gradTp-gradTm)/dx; + gradTp = fabs((y[jp] - y[j]) / (y[rp] - y[r])); + gradTp = fabs((y[j] - y[jm]) / (y[r] - y[rm])); + dr = 0.5e0 * (y[rp] - y[rm]); + curvT = (gradTp - gradTm) / dr; + if (curvT >= maxCurvT) { + maxCurvT = curvT; + pos = i; + } + } + return (pos); } -double maxGradPosition(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts){ - double maxGradT=0.0e0; - double gradT=0.0e0; - double pos=0.0e0; - size_t j,jm; - for (size_t i = 1; i =maxGradT) { - maxGradT=gradT; - pos=x[i]; - } - } - return(pos); +double maxGradPosition(const double *y, const size_t nt, + const size_t nvar, const double *x, size_t nPts) { + double maxGradT = 0.0e0; + double gradT = 0.0e0; + double pos = 0.0e0; + size_t j, jm; + for (size_t i = 1; i < nPts; i++) { + j = i * nvar + nt; + jm = (i - 1) * nvar + nt; + gradT = fabs((y[j] - y[jm]) / (x[i] - x[i - 1])); + if (gradT >= maxGradT) { + maxGradT = gradT; + pos = x[i]; + } + } + return (pos); } -int maxGradIndex(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts){ - double maxGradT=0.0e0; - double gradT=0.0e0; - int pos=0; - size_t j,jm; - for (size_t i = 1; i =maxGradT) { - maxGradT=gradT; - pos=i; - } - } - return(pos); +int maxGradIndex(const double *y, const size_t nt, + const size_t nvar, const double *x, size_t nPts) { + double maxGradT = 0.0e0; + double gradT = 0.0e0; + int pos = 0; + size_t j, jm; + for (size_t i = 1; i < nPts; i++) { + j = i * nvar + nt; + jm = (i - 1) * nvar + nt; + gradT = fabs((y[j] - y[jm]) / (x[i] - x[i - 1])); + if (gradT >= maxGradT) { + maxGradT = gradT; + pos = i; + } + } + return (pos); } -double maxCurvPosition(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts){ - double maxCurvT=0.0e0; - double gradTp=0.0e0; - double gradTm=0.0e0; - double curvT=0.0e0; - double dx=0.0e0; - double pos=0.0e0; - size_t j,jm,jp; - for (size_t i = 1; i =maxCurvT) { - maxCurvT=curvT; - pos=x[i]; - } - } - return(pos); +double maxCurvPosition(const double *y, const size_t nt, + const size_t nvar, const double *x, size_t nPts) { + double maxCurvT = 0.0e0; + double gradTp = 0.0e0; + double gradTm = 0.0e0; + double curvT = 0.0e0; + double dx = 0.0e0; + double pos = 0.0e0; + size_t j, jm, jp; + for (size_t i = 1; i < nPts - 1; i++) { + j = i * nvar + nt; + jm = (i - 1) * nvar + nt; + jp = (i + 1) * nvar + nt; + gradTp = fabs((y[jp] - y[j]) / (x[i + 1] - x[i])); + gradTm = fabs((y[j] - y[jm]) / (x[i] - x[i - 1])); + dx = 0.5e0 * ((x[i] + x[i + 1]) - (x[i - 1] + x[i])); + curvT = (gradTp - gradTm) / dx; + if (curvT >= maxCurvT) { + maxCurvT = curvT; + pos = x[i]; + } + } + return (pos); } -int maxCurvIndex(const double* y, const size_t nt, - const size_t nvar, const double* x, size_t nPts){ - double maxCurvT=0.0e0; - double gradTp=0.0e0; - double gradTm=0.0e0; - double curvT=0.0e0; - double dx=0.0e0; - int pos=0; - size_t j,jm,jp; - for (size_t i = 1; i =maxCurvT) { - maxCurvT=curvT; - pos=i; - } - } - return(pos); +int maxCurvIndex(const double *y, const size_t nt, + const size_t nvar, const double *x, size_t nPts) { + double maxCurvT = 0.0e0; + double gradTp = 0.0e0; + double gradTm = 0.0e0; + double curvT = 0.0e0; + double dx = 0.0e0; + int pos = 0; + size_t j, jm, jp; + for (size_t i = 1; i < nPts - 1; i++) { + j = i * nvar + nt; + jm = (i - 1) * nvar + nt; + jp = (i + 1) * nvar + nt; + gradTp = fabs((y[jp] - y[j]) / (x[i + 1] - x[i])); + gradTm = fabs((y[j] - y[jm]) / (x[i] - x[i - 1])); + dx = 0.5e0 * ((x[i] + x[i + 1]) - (x[i - 1] + x[i])); + curvT = (gradTp - gradTm) / dx; + if (curvT >= maxCurvT) { + maxCurvT = curvT; + pos = i; + } + } + return (pos); } -//double isothermPosition(const double* y, const double T, const size_t nt, +//double isothermPosition(const double* y, const double T, const size_t nt, // const size_t nvar, const double* x, const size_t nPts){ // double pos=x[nPts-1]; // size_t j; @@ -331,731 +336,1417 @@ int maxCurvIndex(const double* y, const size_t nt, //} //******************* scan the temperature from left to right ******************// -double isothermPosition(const double* y, const double T, const size_t nt, - const size_t nvar, const double* x, const size_t nPts){ - double pos=x[0]; - size_t j; - for (size_t i = 0; i =T) { - pos=x[i]; - break; - } - } - return(pos); +double isothermPosition(const double *y, const double T, const size_t nt, + const size_t nvar, const double *x, const size_t nPts) { + double pos = x[0]; + size_t j; + for (size_t i = 0; i < nPts; i++) { + j = i * nvar + nt; + if (y[j] >= T) { + pos = x[i]; + break; + } + } + return (pos); } -void updateSolution(double* y, double* ydot, const size_t nvar, - const double xOld[],const double xNew[],const size_t nPts){ +void updateSolution(double *y, double *ydot, const size_t nvar, + const double xOld[], const double xNew[], const size_t nPts) { + + double ytemp[nPts], ydottemp[nPts]; - double ytemp[nPts],ydottemp[nPts]; + gsl_interp_accel *acc; + gsl_spline *spline; + acc = gsl_interp_accel_alloc(); + spline = gsl_spline_alloc(gsl_interp_steffen, nPts); - gsl_interp_accel* acc; - gsl_spline* spline; - acc = gsl_interp_accel_alloc(); - spline = gsl_spline_alloc(gsl_interp_steffen, nPts); + gsl_interp_accel *accdot; + gsl_spline *splinedot; + accdot = gsl_interp_accel_alloc(); + splinedot = gsl_spline_alloc(gsl_interp_steffen, nPts); - gsl_interp_accel* accdot; - gsl_spline* splinedot; - accdot = gsl_interp_accel_alloc(); - splinedot = gsl_spline_alloc(gsl_interp_steffen, nPts); + for (size_t j = 0; j < nvar; j++) { - for (size_t j = 0; j < nvar; j++) { + for (size_t i = 0; i < nPts; i++) { + ytemp[i] = y[j + i * nvar]; + ydottemp[i] = ydot[j + i * nvar]; + } - for (size_t i = 0; i < nPts; i++) { - ytemp[i]=y[j+i*nvar]; - ydottemp[i]=ydot[j+i*nvar]; - } + gsl_spline_init(spline, xOld, ytemp, nPts); + gsl_spline_init(splinedot, xOld, ydottemp, nPts); - gsl_spline_init(spline,xOld,ytemp,nPts); - gsl_spline_init(splinedot,xOld,ydottemp,nPts); + for (size_t i = 0; i < nPts; i++) { - for (size_t i = 0; i < nPts; i++) { + y[j + i * nvar] = gsl_spline_eval(spline, xNew[i], acc); + ydot[j + i * nvar] = gsl_spline_eval(splinedot, xNew[i], accdot); + } + } - y[j+i*nvar]=gsl_spline_eval(spline,xNew[i],acc); - ydot[j+i*nvar]=gsl_spline_eval(splinedot,xNew[i],accdot); - } - } + //Exploring "fixing" boundary conditions: + //for (size_t j = 1; j < nvar; j++) { + // //printf("%15.6e\t%15.6e\n", y[j],y[j+nvar]); + // y[j]=y[j+nvar]; + // //y[j+(nPts-1)*nvar]=y[j+(nPts-2)*nvar]; + // //ydot[j+nvar]=ydot[j]; + //} + //y[0]=0.0e0; - //Exploring "fixing" boundary conditions: - //for (size_t j = 1; j < nvar; j++) { - // //printf("%15.6e\t%15.6e\n", y[j],y[j+nvar]); - // y[j]=y[j+nvar]; - // //y[j+(nPts-1)*nvar]=y[j+(nPts-2)*nvar]; - // //ydot[j+nvar]=ydot[j]; - //} - //y[0]=0.0e0; - - gsl_interp_accel_free(acc); - gsl_spline_free(spline); + gsl_interp_accel_free(acc); + gsl_spline_free(spline); - gsl_interp_accel_free(accdot); - gsl_spline_free(splinedot); + gsl_interp_accel_free(accdot); + gsl_spline_free(splinedot); } //Locate bath gas: -size_t BathGasIndex(UserData data){ - size_t index=0; - double max1; - double max=data->gas->massFraction(0); - for(size_t k=1;knsp;k++){ - max1=data->gas->massFraction(k); - if(max1>=max){ - max=max1; - index=k; - } - } - return(index+1); +size_t BathGasIndex(UserData data) { + size_t index = 0; + double max1; + double max = data->gas->massFraction(0); + for (size_t k = 1; k < data->nsp; k++) { + max1 = data->gas->massFraction(k); + if (max1 >= max) { + max = max1; + index = k; + } + } + return (index + 1); } //Locate Oxidizer: -size_t oxidizerIndex(UserData data){ - size_t index=0; - for(size_t k=1;knsp;k++){ - if(data->gas->speciesName(k-1)=="O2"){ - index=k; - } - } - return(index); +size_t oxidizerIndex(UserData data) { + size_t index = 0; + for (size_t k = 1; k < data->nsp; k++) { + if (data->gas->speciesName(k - 1) == "O2") { + index = k; + } + } + return (index); } //Locate OH: -size_t OHIndex(UserData data){ - size_t index=0; - for(size_t k=1;knsp;k++){ - if(data->gas->speciesName(k-1)=="OH"){ - index=k; - } - } - return(index); +size_t OHIndex(UserData data) { + size_t index = 0; + for (size_t k = 1; k < data->nsp; k++) { + if (data->gas->speciesName(k - 1) == "OH") { + index = k; + } + } + return (index); } //Locate HO2: -size_t HO2Index(UserData data){ - size_t index=0; - for(size_t k=1;knsp;k++){ - if(data->gas->speciesName(k-1)=="HO2"){ - index=k; - } - } - return(index); +size_t HO2Index(UserData data) { + size_t index = 0; + for (size_t k = 1; k < data->nsp; k++) { + if (data->gas->speciesName(k - 1) == "HO2") { + index = k; + } + } + return (index); } //Locate species index: -size_t specIndex(UserData data,char *specName){ - size_t index=0; - for(size_t k=1;knsp;k++){ - if(data->gas->speciesName(k-1)==specName){ - index=k; - } - } - return(index); +/*1-based index*/ +size_t specIndex(UserData data, const char *specName) { + size_t index = 0; + for (size_t k = 1; k <= data->nsp; k++) { + if (data->gas->speciesName(k - 1) == specName) { + index = k; + } + } + return (index); } -int setAlgebraicVariables(N_Vector* id, UserData data,const double* ydata){ - double *iddata; - char* specPtr[2]; - - N_VConst(ONE, *id); - iddata = N_VGetArrayPointer_OpenMP(*id); - data->k_bath=BathGasIndex(data); - data->k_oxidizer=oxidizerIndex(data); - data->k_OH=OHIndex(data); - data->k_HO2=HO2Index(data); - //use char* pointer to get the address - for(int i=0;i<2;i++){ - specPtr[i] = data->dropSpec[i]; - } - data->k_drop[0]=specIndex(data,specPtr[0]); - data->k_drop[1]=specIndex(data,specPtr[1]); - - printf("Oxidizer index: %lu\n",data->k_oxidizer); - printf("Bath gas index:%lu\n",data->k_bath); - printf("Droplet species index:%lu,%lu\n",data->k_drop[0],data->k_drop[1]); - for (size_t i = 1; i <=data->npts; i++) { - /*Algebraic variables: indicated by ZERO.*/ - Rid(i)=ZERO; - Pid(i)=ZERO; - Yid(i,data->k_bath)=ZERO; - Mdotid(i)=ZERO; - } - Mdotid(1)=ZERO; - Rid(1)=ONE; - Yid(1,data->k_drop[0])=ZERO; - Yid(1,data->k_drop[1])=ZERO; - Tid(data->npts)=ZERO; - if(data->constantPressure){ - Pid(data->npts)=ONE; - }else{ - Pid(data->npts)=ZERO; - Rid(data->npts)=ONE; - } - if(data->dirichletInner){ - Tid(1)=ZERO; - }else{ - //double T_boil = getLiquidMaxT(data->dropMole,P(1)); - //if(T(1) <= T_boil){ - // Tid(1)=ONE; - //}else{ - // Tid(1)=ZERO; - //} - Tid(1)=ONE; - } - if(data->dirichletOuter){ - for (size_t k = 1; k <=data->nsp; k++) { - if(k!=data->k_bath){ - Yid(data->npts,k)=ONE; - } - Yid(1,k)=ZERO; - Tid(data->npts)=ONE; - } - }else{ - for (size_t k = 1; k <=data->nsp; k++){ - Yid(1,k)=ZERO; - Yid(data->npts,k)=ZERO; - Tid(data->npts)=ZERO; - } - } - return(0); +/*a similar function will be used*/ +/*therefore the original function will be commented out*/ +// int setAlgebraicVariables(N_Vector* id, UserData data,const double* ydata){ +// double *iddata; +// //char* specPtr[2]; + +// N_VConst(ONE, *id); +// iddata = N_VGetArrayPointer_OpenMP(*id); +// data->k_bath=BathGasIndex(data); +// data->k_oxidizer=oxidizerIndex(data); +// data->k_OH=OHIndex(data); +// data->k_HO2=HO2Index(data); +// /*use char* pointer to get the address*/ +// // for(int i=0;i<2;i++){ +// // specPtr[i] = data->dropSpec[i]; +// // } +// // data->k_drop[0]=specIndex(data,specPtr[0]); +// // data->k_drop[1]=specIndex(data,specPtr[1]); + +// for (size_t i = 0; i < data->dropMole.size(); i++){ +// size_t index = specIndex(data,data->dropSpec[i]); +// data->k_drop.push_back(index); +// } + +// printf("Oxidizer index: %lu\n",data->k_oxidizer); +// printf("Bath gas index:%lu\n",data->k_bath); +// printf("Droplet species index: "); +// for (size_t i = 0; i < data->dropMole.size(); i++) +// { +// printf("%lu\t",data->k_drop[i]); +// } +// printf("\n"); + +// /*set governing equations' id*/ +// for (size_t i = 1; i <=data->npts; i++) { +// /*Algebraic variables: indicated by ZERO.*/ +// Rid(i)=ZERO; +// Pid(i)=ZERO; +// Yid(i,data->k_bath)=ZERO; +// Mdotid(i)=ZERO; +// } +// Mdotid(1)=ZERO; +// Rid(1)=ONE; +// Yid(1,data->k_drop[0])=ZERO; +// Yid(1,data->k_drop[1])=ZERO; +// Tid(data->npts)=ZERO; +// if(data->constantPressure){ +// Pid(data->npts)=ONE; +// }else{ +// Pid(data->npts)=ZERO; +// Rid(data->npts)=ONE; +// } +// if(data->dirichletInner){ +// Tid(1)=ZERO; +// }else{ +// //double T_boil = getLiquidMaxT(data->dropMole,P(1)); +// //if(T(1) <= T_boil){ +// // Tid(1)=ONE; +// //}else{ +// // Tid(1)=ZERO; +// //} +// Tid(1)=ONE; +// } +// if(data->dirichletOuter){ +// for (size_t k = 1; k <=data->nsp; k++) { +// if(k!=data->k_bath){ +// Yid(data->npts,k)=ONE; +// } +// Yid(1,k)=ZERO; +// Tid(data->npts)=ONE; +// } +// }else{ +// for (size_t k = 1; k <=data->nsp; k++){ +// Yid(1,k)=ZERO; +// Yid(data->npts,k)=ZERO; +// Tid(data->npts)=ZERO; +// } +// } +// return(0); +// } + +int setAlgebraicVariables(N_Vector *id, UserData data, const double *ydata) { + double *iddata; + //char* specPtr[2]; + + N_VConst(ONE, *id); + iddata = N_VGetArrayPointer_OpenMP(*id); + data->k_bath = BathGasIndex(data); + data->k_oxidizer = oxidizerIndex(data); + data->k_OH = OHIndex(data); + data->k_HO2 = HO2Index(data); + /*use char* pointer to get the address*/ + // for(int i=0;i<2;i++){ + // specPtr[i] = data->dropSpec[i]; + // } + // data->k_drop[0]=specIndex(data,specPtr[0]); + // data->k_drop[1]=specIndex(data,specPtr[1]); + + for (size_t i = 0; i < data->dropMole.size(); i++) { + size_t index = 0; + for (size_t k = 1; k <= data->nsp; k++) { + if (data->gas->speciesName(k - 1) == data->dropSpec[i]) { + index = k; + } + } +// size_t index = specIndex(data, data->dropSpec[i].c_str()); + data->k_drop.push_back(index); + } + + printf("Oxidizer index: %lu\n", data->k_oxidizer); + printf("Bath gas index:%lu\n", data->k_bath); + printf("Droplet species index: "); + + for(auto & arg : data->k_drop){ + printf("%lu,\t",arg) ; + } + printf("\n"); + + /*set governing equations' id*/ + for (size_t i = 1; i <= data->npts; i++) { + /*Algebraic variables: indicated by ZERO.*/ + Rid(i) = ZERO; + Pid(i) = ZERO; + Yid(i, data->k_bath) = ZERO; + Mdotid(i) = ZERO; + Tid(i) = ONE; + } + Mdotid(1) = ZERO; + + /*set radius ids*/ + Rid(1) = ONE; + Rid(data->l_npts) = ONE; + + /*set temperature ids*/ + Tid(1) = ZERO; + Tid(data->l_npts) = ZERO; + Tid(data->l_npts + 1) = ZERO; + + /*set liquid phase mass fraction (y) ids*/ + if (data->dropType == 0) { + for (size_t k = 1; k <= data->nsp; k++) { + for (size_t i = 1; i <= data->l_npts; i++) { + if (i == 1) { + Yid(i, k) = ONE; + } else { + Yid(i, k) = ZERO; + } + } + } + } else { + for (size_t i = 1; i <= data->l_npts; i++) { + for (size_t k = 1; k <= data->nsp; k++) { + if (i == 1) { + if (k == data->k_drop[0] || k == data->k_drop[1]) { + Yid(i, k) = ZERO; + } else { + Yid(i, k) = ONE; + } + } else if (i == data->l_npts) { + Yid(i, k) = ZERO; + } else { + if (k == data->k_drop[0]) { + Yid(i, k) = ONE; + } else { + Yid(i, k) = ZERO; + } + } + } + } + + } + +// for (size_t k = 1; k <= data->nsp; k++) { +// Yid(data->l_npts + 1, k) = ZERO; +// } + + /*set gas phase mass fraction (y) ids*/ + for (size_t i = (data->l_npts + 1); i <= (data->npts - 1); i++) { + for (size_t k = 1; k <= data->nsp; k++) { + if (i == (data->l_npts + 1)) { + Yid(i, k) = ZERO; + } else { + if (k == data->k_bath) { + Yid(i, k) = ZERO; + } else { + Yid(i, k) = ONE; + } + } + } + } + + //Yid(1,data->k_drop[0])=ZERO; + //Yid(1,data->k_drop[1])=ZERO; + //Tid(data->npts)=ZERO; + + // if(data->dirichletInner){ + // Tid(1)=ZERO; + // }else{ + // //double T_boil = getLiquidMaxT(data->dropMole,P(1)); + // //if(T(1) <= T_boil){ + // // Tid(1)=ONE; + // //}else{ + // // Tid(1)=ZERO; + // //} + // Tid(1)=ONE; + // } + if (data->constantPressure) { + Pid(data->npts) = ONE; + } else { + Pid(data->npts) = ZERO; + /*Rres(npts) seems to be algebric all the time?*/ + Rid(data->npts) = ONE; + } + if (data->dirichletOuter) { + for (size_t k = 1; k <= data->nsp; k++) { + if (k != data->k_bath) { + Yid(data->npts, k) = ONE; + } + //Yid(1,k)=ZERO; + Tid(data->npts) = ONE; + } + } else { + for (size_t k = 1; k <= data->nsp; k++) { + //Yid(1,k)=ZERO; + Yid(data->npts, k) = ZERO; + Tid(data->npts) = ZERO; + } + } + + printIddata(data,iddata); + return (0); } -inline double calc_area(double x,int* i){ - switch (*i) { - case 0: - return(ONE); - case 1: - return(x); - case 2: - return(x*x); - default: - return(ONE); - } +inline double calc_area(double x, int *i) { + switch (*i) { + case 0: + return (ONE); + case 1: + return (x); + case 2: + return (x * x); + default: + return (ONE); + } } +/*Similar to function:"setInitialCondition"*/ +/*"readInitialCondition" will also be revised here for two-phase LTORC*/ +// void readInitialCondition(FILE* input, double* ydata, const size_t nvar, const size_t nr, const size_t nPts, double Rg){ + +// FILE* output;output=fopen("test.dat","w"); + +// size_t bufLen=10000; +// size_t nRows=0; +// size_t nColumns=nvar; + +// char buf[bufLen]; +// char buf1[bufLen]; +// char comment[1]; +// char *ret; + +// while (fgets(buf,bufLen, input)!=NULL){ +// comment[0]=buf[0]; +// if(strncmp(comment,"#",1)!=0){ +// nRows++; +// } +// } +// rewind(input); + +// printf("nRows: %ld\n", nRows); +// double y[nRows*nColumns]; + +// size_t i=0; +// while (fgets(buf,bufLen, input)!=NULL){ +// comment[0]=buf[0]; +// if(strncmp(comment,"#",1)==0){ +// } +// else{ +// ret=strtok(buf,"\t"); +// size_t j=0; +// y[i*nColumns+j]=(double)(atof(ret)); +// j++; +// while(ret!=NULL){ +// ret=strtok(NULL,"\t"); +// if(jnpts; i++) { - data->gas->setState_TPY(T(i), P(i), &Y(i,1)); - rho=data->gas->density(); - //psi(i)=psi(i-1)+rho*(R(i)-R(i-1))*calc_area(HALF*(R(i)+R(i-1)),&m); - mass+=rho*(R(i)-R(i-1))*calc_area(R(i),&data->metric); - } - return(mass); + double ratio = pow(Rg,1.0/NN); + for (size_t ii = (l_nPts + 1); ii <= (nPts - 2); ii++) { + xNew[ii] = xNew[ii - 1] + dX0 * pow(ratio,(ii-l_nPts-1)) ; + } + xNew[nPts - 1] = xOld[nRows - 1]; + + /*pass variable data from ytemp[] to ydata[] array using spline interpolation*/ + /*interpolate the liquid phase state variables with old array of size (interII+1)*/ + double ytemp0[interII + 1]; + double xOld0[interII + 1]; + std::copy(xOld, xOld + interII + 1, xOld0); + gsl_interp_accel *acc; + gsl_spline *spline; + acc = gsl_interp_accel_alloc(); + spline = gsl_spline_alloc(gsl_interp_steffen, interII + 1); + for (size_t j = 0; j < nColumns; j++) { + for (size_t k = 0; k < (interII + 1); k++) { + ytemp0[k] = y[j + k * nColumns]; + } + gsl_spline_init(spline, xOld0, ytemp0, interII + 1); + + for (size_t k = 0; k < l_nPts; k++) { + ydata[j + k * nColumns] = gsl_spline_eval(spline, xNew[k], acc); + } + } + gsl_interp_accel_free(acc); + gsl_spline_free(spline); + + /*interpolate the gas phase state variables with old array of size (nRows-interII-1)*/ + double ytemp1[nRows - interII - 1]; + double xOld1[nRows - interII - 1]; + std::copy(xOld + interII + 1, xOld + nRows, xOld1); + gsl_interp_accel *acc1; + gsl_spline *spline1; + acc1 = gsl_interp_accel_alloc(); + spline1 = gsl_spline_alloc(gsl_interp_steffen, nRows - interII - 1); + for (size_t j = 0; j < nColumns; j++) { + + for (size_t k = (interII + 1); k < nRows; k++) { + // ytemp[k]=y[j+k*nColumns]; + ytemp1[k - interII - 1] = y[j + k * nColumns]; + } + + gsl_spline_init(spline1, xOld1, ytemp1, nRows - interII - 1); + + for (size_t k = l_nPts; k < nPts; k++) { + ydata[j + k * nColumns] = gsl_spline_eval(spline1, xNew[k], acc); + } + } + gsl_interp_accel_free(acc1); + gsl_spline_free(spline1); } +double systemMass(double *ydata, UserData data) { + double mass = 0.0e0; + double rho; + for (size_t i = 2; i <= data->npts; i++) { + data->gas->setState_TPY(T(i), P(i), &Y(i, 1)); + rho = data->gas->density(); + //psi(i)=psi(i-1)+rho*(R(i)-R(i-1))*calc_area(HALF*(R(i)+R(i-1)),&m); + mass += rho * (R(i) - R(i - 1)) * calc_area(R(i), &data->metric); + } + return (mass); +} -int initializePsiGrid(double* ydata, double* psidata, UserData data){ +/*a different function:initializePsiEtaGrid is implement*/ +/*similar to the following function, it create a psi grid in the gas phase*/ +/*and a eta grid in the liquid phase*/ +int initializePsiGrid(double *ydata, double *psidata, UserData data) { - double rho,rhom; - /*Create a psi grid that corresponds CONSISTENTLY to the spatial grid + double rho, rhom; + /*Create a psi grid that corresponds CONSISTENTLY to the spatial grid * "R" created above. Note that the Lagrangian variable psi has units * of kg. */ - psi(1)=ZERO; - for (size_t i = 2; i <=data->npts; i++) { - data->gas->setState_TPY(T(i), P(i), &Y(i,1)); - rho=data->gas->density(); - data->gas->setState_TPY(T(i-1), P(i-1), &Y(i-1,1)); - rhom=data->gas->density(); - //psi(i)=psi(i-1)+rho*(R(i)-R(i-1))*calc_area(HALF*(R(i)+R(i-1)),&data->metric); - //psi(i)=psi(i-1)+rho*(R(i)-R(i-1))*calc_area(R(i),&data->metric); - psi(i)=psi(i-1)+(R(i)-R(i-1))*(rho*calc_area(R(i),&data->metric)+rhom*calc_area(R(i-1),&data->metric))/TWO; - } - - /*The mass of the entire system is the value of psi at the last grid + psi(1) = ZERO; + for (size_t i = 2; i <= data->npts; i++) { + data->gas->setState_TPY(T(i), P(i), &Y(i, 1)); + rho = data->gas->density(); + data->gas->setState_TPY(T(i - 1), P(i - 1), &Y(i - 1, 1)); + rhom = data->gas->density(); + //psi(i)=psi(i-1)+rho*(R(i)-R(i-1))*calc_area(HALF*(R(i)+R(i-1)),&data->metric); + //psi(i)=psi(i-1)+rho*(R(i)-R(i-1))*calc_area(R(i),&data->metric); + psi(i) = psi(i - 1) + (R(i) - R(i - 1)) * + (rho * calc_area(R(i), &data->metric) + rhom * calc_area(R(i - 1), &data->metric)) / TWO; + } + + /*The mass of the entire system is the value of psi at the last grid * point. Normalize psi by this mass so that it varies from zero to * one. This makes psi dimensionless. So the mass needs to be * multiplied back in the approporiate places in the governing * equations so that units match.*/ - data->mass=psi(data->npts); - for (size_t i = 1; i <=data->npts; i++) { - psi(i)=psi(i)/data->mass; - } - return(0); + data->mass = psi(data->npts); + for (size_t i = 1; i <= data->npts; i++) { + psi(i) = psi(i) / data->mass; + } + return (0); } +/*create the psi grid in the gas phase and eta grid in the liquid phase*/ +/*note: psi has units of kg. while eta is dimensionless*/ +int initializePsiEtaGrid(double *ydata, double *psidata, UserData data) { + double rho, rhom, rhop; + /*Create a psi grid that corresponds CONSISTENTLY to the spatial grid + * "R" created above. Note that the Lagrangian variable psi has units + * of kg. */ + /*create the psi grid in gas phase*/ + psi(data->l_npts + 1) = ZERO; + for (size_t i = data->l_npts + 2; i <= data->npts; i++) { + data->gas->setState_TPY(T(i), P(i), &Y(i, 1)); + rho = data->gas->density(); + data->gas->setState_TPY(T(i - 1), P(i - 1), &Y(i - 1, 1)); + rhom = data->gas->density(); + //psi(i)=psi(i-1)+rho*(R(i)-R(i-1))*calc_area(HALF*(R(i)+R(i-1)),&data->metric); + //psi(i)=psi(i-1)+rho*(R(i)-R(i-1))*calc_area(R(i),&data->metric); + psi(i) = psi(i - 1) + (R(i) - R(i - 1)) * + (rho * calc_area(R(i), &data->metric) + rhom * calc_area(R(i - 1), &data->metric)) / TWO; + } + + /*create the \eta grid for liquid phase*/ + /*for the time being, liquid phase species are hard coded*/ + std::vector composition = components(data->dropType); + psi(data->l_npts) = ZERO; + if (data->dropType == 0) { + for (size_t i = data->l_npts - 1; i >= 1; i--) { + rho = getLiquidDensity(T(i), P(i), composition); + rhop = getLiquidDensity(T(i + 1), P(i + 1), composition); + psi(i) = psi(i + 1) + (R(i + 1) - R(i)) * + (rho * calc_area(R(i), &data->metric) + rhop * calc_area(R(i + 1), &data->metric)) / + TWO; + } + } else if (data->dropType == 1) { + for (size_t i = data->l_npts - 1; i >= 1; i--) { + std::vector moleFrac, moleFracp; + moleFrac = getLiquidmolevec(data, ydata, i); + moleFracp = getLiquidmolevec(data, ydata, i + 1); + rho = getLiquidDensity(T(i), P(i), composition, moleFrac); + rhop = getLiquidDensity(T(i + 1), P(i + 1), composition, moleFracp); + psi(i) = psi(i + 1) + (R(i + 1) - R(i)) * + (rho * calc_area(R(i), &data->metric) + rhop * calc_area(R(i + 1), &data->metric)) / + TWO; + } + } + /*according to the mehtod described by Stauch et al.*/ + /*eta should be dimensionless, so we normalize the eta with total mass of droplet*/ + double dropmass = psi(1); + for (size_t i = data->l_npts; i >= 1; i--) { + psi(i) = psi(i) / dropmass; + } + + /*The mass of the entire system is the value of psi at the last grid + * point. Normalize psi by this mass so that it varies from zero to + * one. This makes psi dimensionless. So the mass needs to be + * multiplied back in the approporiate places in the governing + * equations so that units match.*/ + + // data->mass=psi(data->npts); + // for (size_t i = 1; i <=data->npts; i++) { + // psi(i)=psi(i)/data->mass; + // } + -int setInitialCondition(N_Vector* y, - N_Vector* ydot, - UserData data){ - double* ydata; - double* ydotdata; - double* psidata; - double* innerMassFractionsData, Rd, massDrop; - double rhomhalf, lambdamhalf, YVmhalf[data->nsp]; - double f=ZERO; - double g=ZERO; - - double perturb,rho; - double epsilon=ZERO; - int m,ier; - ydata = N_VGetArrayPointer_OpenMP(*y); - ydotdata = N_VGetArrayPointer_OpenMP(*ydot); - innerMassFractionsData = data->innerMassFractions; - Rd = data->Rd; - massDrop = data->massDrop; - - //Mass of droplet - //massDrop=1.0/3.0*Rd*Rd*Rd*997.0; //TODO: The density of the droplet should be a user input - //massDrop=1.0/3.0*Rd*Rd*Rd*684.0; //TODO:The density of the droplet(n-heptane) should be a user input - massDrop = 1.0/3.0*Rd*Rd*Rd*data->dropRho; - if(data->adaptiveGrid){ - psidata = data->grid->xOld; - } - else{ - psidata = data->uniformGrid; - } - - m=data->metric; - - data->innerTemperature=data->initialTemperature; - for (size_t k = 1; k <=data->nsp; k++) { - innerMassFractionsData[k-1]=data->gas->massFraction(k-1); - } - - //Define Grid: - double dR=(data->domainLength)/((double)(data->npts)-1.0e0); - double dv=(pow(data->domainLength,1+data->metric)-pow(data->firstRadius*data->domainLength,1+data->metric))/((double)(data->npts)-1.0e0); - - //Initialize the R(i),T(i)(data->initialTemperature),Y(i,k),P(i) - for (size_t i = 1; i <=data->npts; i++) { - if(data->metric==0){ - R(i)=Rd+(double)((i-1)*dR); - }else{ - if(i==1){ - R(i)=ZERO; - }else if(i==2){ - R(i)=data->firstRadius*data->domainLength; - }else{ - R(i)=pow(pow(R(i-1),1+data->metric)+dv,1.0/((double)(1+data->metric))); - } - } - T(i)=data->initialTemperature; - for (size_t k = 1; k <=data->nsp; k++) { - Y(i,k)=data->gas->massFraction(k-1); //Indexing different in Cantera - } - P(i)=data->initialPressure*Cantera::OneAtm; - } - R(data->npts)=data->domainLength+data->Rd; + return (0); +} + +/*A different setInitialCondition is implemented based on the problemType =2 */ +/*As such, the following function is commented*/ +// int setInitialCondition(N_Vector* y, +// N_Vector* ydot, +// UserData data){ +// double* ydata; +// double* ydotdata; +// double* psidata; +// double* innerMassFractionsData, Rd, massDrop; +// double rhomhalf, lambdamhalf, YVmhalf[data->nsp]; +// double f=ZERO; +// double g=ZERO; + +// double perturb,rho; +// double epsilon=ZERO; +// int m,ier; +// ydata = N_VGetArrayPointer_OpenMP(*y); +// ydotdata = N_VGetArrayPointer_OpenMP(*ydot); +// innerMassFractionsData = data->innerMassFractions; +// Rd = data->Rd; +// // massDrop = data->massDrop; + +// //Mass of droplet +// //massDrop=1.0/3.0*Rd*Rd*Rd*997.0; //TODO: The density of the droplet should be a user input +// // massDrop=1.0/3.0*Rd*Rd*Rd*684.0; //TODO:The density of the droplet(n-heptane) should be a user input +// // massDrop = 1.0/3.0*Rd*Rd*Rd*data->dropRho; +// if(data->adaptiveGrid){ +// psidata = data->grid->xOld; +// } +// else{ +// psidata = data->uniformGrid; +// } + +// m=data->metric; + +// data->innerTemperature=data->initialTemperature; +// for (size_t k = 1; k <=data->nsp; k++) { +// innerMassFractionsData[k-1]=data->gas->massFraction(k-1); +// } + +// //Define Grid: +// double dR=(data->domainLength)/((double)(data->npts)-1.0e0); +// double dv=(pow(data->domainLength,1+data->metric)-pow(data->firstRadius*data->domainLength,1+data->metric))/((double)(data->npts)-1.0e0); + +// //Initialize the R(i),T(i)(data->initialTemperature),Y(i,k),P(i) +// for (size_t i = 1; i <=data->npts; i++) { +// if(data->metric==0){ +// R(i)=Rd+(double)((i-1)*dR); +// }else{ +// if(i==1){ +// R(i)=ZERO; +// }else if(i==2){ +// R(i)=data->firstRadius*data->domainLength; +// }else{ +// R(i)=pow(pow(R(i-1),1+data->metric)+dv,1.0/((double)(1+data->metric))); +// } +// } +// T(i)=data->initialTemperature; +// for (size_t k = 1; k <=data->nsp; k++) { +// Y(i,k)=data->gas->massFraction(k-1); //Indexing different in Cantera +// } +// P(i)=data->initialPressure*Cantera::OneAtm; +// } +// R(data->npts)=data->domainLength+data->Rd; + +// // /********** test R(i) and the volumn between grids *****************/ +// // printf("Print the first 4 R(i)s and volumn between them: \n") ; +// // printf("Grids: 1st:%2.6e,2nd:%2.6e,3rd:%2.6e,4th:%2.6e \n",R(1),R(2),R(3),R(4)); +// // double v1,v2,v3,v4,v5; +// // v1 =pow(R(2),1+data->metric) - pow(R(1),1+data->metric); +// // v2 =pow(R(3),1+data->metric) - pow(R(2),1+data->metric); +// // v3 =pow(R(4),1+data->metric) - pow(R(3),1+data->metric); +// // v4 =pow(R(5),1+data->metric) - pow(R(4),1+data->metric); +// // v5 =pow(R(6),1+data->metric) - pow(R(5),1+data->metric); +// // printf("Volumn: 1st:%2.6e,2nd:%2.6e,3rd:%2.6e,4th:%2.6e,5th:%2.6e\n",v1,v2,v3,v4,v5) ; + + +// double Tmax; +// double Tmin=data->initialTemperature; +// double w=data->mixingWidth; +// double YN2=ZERO; +// double YO2=ZERO; +// double YFuel,YOxidizer,sum; + +// //if(data->problemType==0){ +// // data->gas->equilibrate("HP"); +// // data->maxTemperature=data->gas->temperature(); +// //} +// //else if(data->problemType==1){ +// // /*Premixed Combustion: Equilibrium products comprise ignition +// // * kernel at t=0. The width of the kernel is "mixingWidth" +// // * shifted by "shift" from the center.*/ +// // data->gas->equilibrate("HP"); +// // Tmax=data->gas->temperature(); +// // for (size_t i = 1; i <=data->npts; i++) { +// // g=HALF*(tanh((R(i)-data->shift)/w)+ONE); //increasing function of x +// // f=ONE-g; //decreasing function of x +// // T(i)=(Tmax-Tmin)*f+Tmin; +// // for (size_t k = 1; k <=data->nsp; k++) { +// // Y(i,k)=(data->gas->massFraction(k-1)-Y(i,k))*f+Y(i,k); +// // } +// // } +// // if(data->dirichletOuter){ +// // T(data->npts)=data->wallTemperature; +// // } +// //} +// //else if(data->problemType==2){ +// // FILE* input; +// // if(input=fopen("initialCondition.dat","r")){ +// // readInitialCondition(input, ydata, data->nvar, data->nr, data->npts); +// // fclose(input); +// // } +// // else{ +// // printf("file initialCondition.dat not found!\n"); +// // return(-1); +// // } +// //} + +// initializePsiGrid(ydata,psidata,data); + +// if(data->adaptiveGrid){ +// // if(data->problemType!=0){ +// // data->grid->position=maxGradPosition(ydata, data->nt, data->nvar, +// // data->grid->xOld, data->npts); +// // //data->grid->position=maxCurvPosition(ydata, data->nt, data->nvar, +// // // data->grid->xOld, data->npts); +// // } +// // else{ +// // } +// if(data->problemType!=3){ +// data->grid->position=0.0e0; +// double x=data->grid->position+data->gridOffset*data->grid->leastMove; +// printf("New grid center:%15.6e\n",x); + +// ier=reGrid(data->grid, x); +// if(ier==-1)return(-1); + +// updateSolution(ydata, ydotdata, data->nvar, +// data->grid->xOld,data->grid->x,data->npts); +// storeGrid(data->grid->x,data->grid->xOld,data->npts); +// } +// } +// else{ +// double Rg = data->Rg, dpsi0; +// int NN = data->npts-2; +// double psiNew[data->npts]; + +// dpsi0 = (pow(Rg,1.0/NN) - 1.0)/(pow(Rg,(NN+1.0)/NN) - 1.0); +// psiNew[0] = 0; +// for (size_t i = 1; i < data->npts-1; i++) { +// psiNew[i]=psiNew[i-1]+dpsi0*pow(Rg,(i-1.0)/NN); +// } +// psiNew[data->npts-1] = 1.0; +// printf("Last point:%15.6e\n",psiNew[data->npts-1]); +// updateSolution(ydata, ydotdata, data->nvar, +// data->uniformGrid,psiNew,data->npts); +// storeGrid(psiNew,data->uniformGrid,data->npts); + +// //double psiNew[data->npts]; +// //double dpsi=1.0e0/((double)(data->npts)-1.0e0); +// //for (size_t i = 0; i < data->npts; i++) { +// // psiNew[i]=(double)(i)*dpsi; +// //} +// //printf("Last point:%15.6e\n",psiNew[data->npts-1]); +// //updateSolution(ydata, ydotdata, data->nvar, +// // data->uniformGrid,psiNew,data->npts); +// //storeGrid(psiNew,data->uniformGrid,data->npts); +// } + +// if(data->problemType==0){ +// data->gas->equilibrate("HP"); +// data->maxTemperature=data->gas->temperature(); +// } +// else if(data->problemType==1){ +// /*Premixed Combustion: Equilibrium products comprise ignition +// * kernel at t=0. The width of the kernel is "mixingWidth" +// * shifted by "shift" from the center.*/ +// data->gas->equilibrate("HP"); +// Tmax=data->gas->temperature(); +// for (size_t i = 1; i <=data->npts; i++) { +// g=HALF*(tanh((R(i)-data->shift)/w)+ONE); //increasing function of x +// f=ONE-g; //decreasing function of x +// T(i)=(Tmax-Tmin)*f+Tmin; +// for (size_t k = 1; k <=data->nsp; k++) { +// Y(i,k)=(data->gas->massFraction(k-1)-Y(i,k))*f+Y(i,k); +// } +// } +// if(data->dirichletOuter){ +// T(data->npts)=data->wallTemperature; +// } +// } +// else if(data->problemType==2){ +// FILE* input; +// if(input=fopen("initialCondition.dat","r")){ +// readInitialCondition(input, ydata, data->nvar, data->nr, data->npts, data->Rg); +// fclose(input); +// } +// else{ +// printf("file initialCondition.dat not found!\n"); +// return(-1); +// } +// initializePsiGrid(ydata,psidata,data); +// } +// else if(data->problemType==3){ +// FILE* input; +// if(input=fopen("restart.bin","r")){ +// readRestart(y, ydot, input, data); +// fclose(input); +// printf("Restart solution loaded!\n"); +// printf("Problem starting at t=%15.6e\n",data->tNow); +// return(0); +// } +// else{ +// printf("file restart.bin not found!\n"); +// return(-1); +// } +// } + +// if(data->reflectProblem){ +// double temp; +// int j=1; +// while (data->npts+1-2*j>=0) { +// temp=T(j); +// T(j)=T(data->npts+1-j); +// T(data->npts+1-j)=temp; +// for (size_t k = 1; k <=data->nsp; k++) { +// temp=Y(j,k); +// Y(j,k)=Y(data->npts+1-j,k); +// Y(data->npts+1-j,k)=temp; +// } +// j=j+1; +// } +// } + +// /*Floor small values to zero*/ +// for (size_t i = 1; i <=data->npts; i++) { +// for (size_t k = 1; k <=data->nsp; k++) { +// if(fabs(Y(i,k))<=data->massFractionTolerance){ +// Y(i,k)=0.0e0; +// } +// } +// } + +// //Set grid to location of maximum curvature calculated by r instead of x: +// if(data->adaptiveGrid){ +// //data->grid->position=maxCurvPosition(ydata, data->nt, data->nvar, +// // data->grid->x, data->npts); +// int maxCurvII = 0; +// maxCurvII = maxCurvIndexR(ydata,data->nt,data->nvar,data->nr,data->npts); + +// data->grid->position = data->grid->x[maxCurvII]; +// ier=reGrid(data->grid, data->grid->position); +// updateSolution(ydata, ydotdata, data->nvar, +// data->grid->xOld,data->grid->x,data->npts); +// storeGrid(data->grid->x,data->grid->xOld,data->npts); + +// /******** Test the maxCurvPosition and related variables *******/ +// printf("The maxCurvPositition(based on r) is : %.6f,Temperature is : %.3f \n",data->grid->position,T(maxCurvII+1)); +// } + + +// /*Ensure consistent boundary conditions*/ +// //T(1)=T(2); +// //for (size_t k = 1; k <=data->nsp; k++) { +// // Y(1,k)=Y(2,k); +// // Y(data->npts,k)=Y(data->npts-1,k); +// //} + +// return(0); +// } + +/*Revise the setInitialCondition function to be suitable for two-phase TORC*/ +int setInitialCondition(N_Vector *y, + N_Vector *ydot, + UserData data) { + double *ydata; + double *ydotdata; + double *psidata; + double *innerMassFractionsData, Rd, massDrop; + double rhomhalf, lambdamhalf, YVmhalf[data->nsp]; + double f = ZERO; + double g = ZERO; + + double perturb, rho; + double epsilon = ZERO; + int m, ier; + ydata = N_VGetArrayPointer_OpenMP(*y); + ydotdata = N_VGetArrayPointer_OpenMP(*ydot); + innerMassFractionsData = data->innerMassFractions; + Rd = data->Rd; + // massDrop = data->massDrop; + + //Mass of droplet + // massDrop=1.0/3.0*Rd*Rd*Rd*997.0; //TODO: The density of the droplet should be a user input + // massDrop=1.0/3.0*Rd*Rd*Rd*684.0; //TODO:The density of the droplet(n-heptane) should be a user input + // massDrop = 1.0/3.0*Rd*Rd*Rd*data->dropRho; + if (data->adaptiveGrid) { + psidata = data->grid->xOld; + } else { + psidata = data->uniformGrid; + } + + m = data->metric; + + data->innerTemperature = data->initialTemperature; + for (size_t k = 1; k <= data->nsp; k++) { + innerMassFractionsData[k - 1] = data->gas->massFraction(k - 1); + } + + //Define Grid: + double dR = (data->domainLength) / ((double) (data->g_npts) - 1.0e0); + double dv = (pow(data->domainLength, 1 + data->metric) - + pow(data->firstRadius * data->domainLength, 1 + data->metric)) / ((double) (data->g_npts) - 1.0e0); + + + // //Initialize the R(i),T(i)(data->initialTemperature),Y(i,k),P(i) + // for (size_t i = 1; i <=data->npts; i++) { + // if(data->metric==0){ + // R(i)=Rd+(double)((i-1)*dR); + // }else{ + // if(i==1){ + // R(i)=ZERO; + // }else if(i==2){ + // R(i)=data->firstRadius*data->domainLength; + // }else{ + // R(i)=pow(pow(R(i-1),1+data->metric)+dv,1.0/((double)(1+data->metric))); + // } + // } + // T(i)=data->initialTemperature; + // for (size_t k = 1; k <=data->nsp; k++) { + // Y(i,k)=data->gas->massFraction(k-1); //Indexing different in Cantera + // } + // P(i)=data->initialPressure*Cantera::OneAtm; + // } + // R(data->npts)=data->domainLength+data->Rd; + + // /********** test R(i) and the volumn between grids *****************/ -// printf("Print the first 4 R(i)s and volumn between them: \n") ; +// printf("Print the first 4 R(i)s and volumn between them: \n") ; // printf("Grids: 1st:%2.6e,2nd:%2.6e,3rd:%2.6e,4th:%2.6e \n",R(1),R(2),R(3),R(4)); -// double v1,v2,v3,v4,v5; +// double v1,v2,v3,v4,v5; // v1 =pow(R(2),1+data->metric) - pow(R(1),1+data->metric); // v2 =pow(R(3),1+data->metric) - pow(R(2),1+data->metric); // v3 =pow(R(4),1+data->metric) - pow(R(3),1+data->metric); -// v4 =pow(R(5),1+data->metric) - pow(R(4),1+data->metric); +// v4 =pow(R(5),1+data->metric) - pow(R(4),1+data->metric); // v5 =pow(R(6),1+data->metric) - pow(R(5),1+data->metric); -// printf("Volumn: 1st:%2.6e,2nd:%2.6e,3rd:%2.6e,4th:%2.6e,5th:%2.6e\n",v1,v2,v3,v4,v5) ; - - - double Tmax; - double Tmin=data->initialTemperature; - double w=data->mixingWidth; - double YN2=ZERO; - double YO2=ZERO; - double YFuel,YOxidizer,sum; - - //if(data->problemType==0){ - // data->gas->equilibrate("HP"); - // data->maxTemperature=data->gas->temperature(); - //} - //else if(data->problemType==1){ - // /*Premixed Combustion: Equilibrium products comprise ignition - // * kernel at t=0. The width of the kernel is "mixingWidth" - // * shifted by "shift" from the center.*/ - // data->gas->equilibrate("HP"); - // Tmax=data->gas->temperature(); - // for (size_t i = 1; i <=data->npts; i++) { - // g=HALF*(tanh((R(i)-data->shift)/w)+ONE); //increasing function of x - // f=ONE-g; //decreasing function of x - // T(i)=(Tmax-Tmin)*f+Tmin; - // for (size_t k = 1; k <=data->nsp; k++) { - // Y(i,k)=(data->gas->massFraction(k-1)-Y(i,k))*f+Y(i,k); - // } - // } - // if(data->dirichletOuter){ - // T(data->npts)=data->wallTemperature; - // } - //} - //else if(data->problemType==2){ - // FILE* input; - // if(input=fopen("initialCondition.dat","r")){ - // readInitialCondition(input, ydata, data->nvar, data->nr, data->npts); - // fclose(input); - // } - // else{ - // printf("file initialCondition.dat not found!\n"); - // return(-1); - // } - //} - - initializePsiGrid(ydata,psidata,data); - - if(data->adaptiveGrid){ - // if(data->problemType!=0){ - // data->grid->position=maxGradPosition(ydata, data->nt, data->nvar, - // data->grid->xOld, data->npts); - // //data->grid->position=maxCurvPosition(ydata, data->nt, data->nvar, - // // data->grid->xOld, data->npts); - // } - // else{ - // } - if(data->problemType!=3){ - data->grid->position=0.0e0; - double x=data->grid->position+data->gridOffset*data->grid->leastMove; - printf("New grid center:%15.6e\n",x); - -// /**************** TEST THE data->grid->xOld *******************/ -// double* ptr3 = data->grid->xOld ; -// printf("SetInitialCondition function is called,before reGrid,Start print the first 5 elements of the xOld array : \n"); -// printf("1st:%.6f, 2nd:%.6f, 3rd:%.6f, 4th:%.6f, 5th:%.6f.\n",ptr3[0],ptr3[1],ptr3[2],ptr3[3],ptr3[4]); - - ier=reGrid(data->grid, x); - if(ier==-1)return(-1); - -// /**************** TEST THE data->grid->xOld *******************/ -// double* ptr = data->grid->xOld ; -// printf("SetInitialCondition function is called,after reGrid,Start print the first 5 elements of the xOld array : \n"); -// printf("1st:%.6f, 2nd:%.6f, 3rd:%.6f, 4th:%.6f, 5th:%.6f.\n",ptr[0],ptr[1],ptr[2],ptr[3],ptr[4]); - - - updateSolution(ydata, ydotdata, data->nvar, - data->grid->xOld,data->grid->x,data->npts); - storeGrid(data->grid->x,data->grid->xOld,data->npts); - } - } - else{ - double Rg = data->Rg, dpsi0; - int NN = data->npts-2; - double psiNew[data->npts]; - - dpsi0 = (pow(Rg,1.0/NN) - 1.0)/(pow(Rg,(NN+1.0)/NN) - 1.0); - psiNew[0] = 0; - for (size_t i = 1; i < data->npts-1; i++) { - psiNew[i]=psiNew[i-1]+dpsi0*pow(Rg,(i-1.0)/NN); - } - psiNew[data->npts-1] = 1.0; - printf("Last point:%15.6e\n",psiNew[data->npts-1]); - updateSolution(ydata, ydotdata, data->nvar, - data->uniformGrid,psiNew,data->npts); - storeGrid(psiNew,data->uniformGrid,data->npts); - - //double psiNew[data->npts]; - //double dpsi=1.0e0/((double)(data->npts)-1.0e0); - //for (size_t i = 0; i < data->npts; i++) { - // psiNew[i]=(double)(i)*dpsi; - //} - //printf("Last point:%15.6e\n",psiNew[data->npts-1]); - //updateSolution(ydata, ydotdata, data->nvar, - // data->uniformGrid,psiNew,data->npts); - //storeGrid(psiNew,data->uniformGrid,data->npts); - } - - if(data->problemType==0){ - data->gas->equilibrate("HP"); - data->maxTemperature=data->gas->temperature(); - } - else if(data->problemType==1){ - /*Premixed Combustion: Equilibrium products comprise ignition +// printf("Volumn: 1st:%2.6e,2nd:%2.6e,3rd:%2.6e,4th:%2.6e,5th:%2.6e\n",v1,v2,v3,v4,v5) ; + + double Tmax; + double Tmin = data->initialTemperature; + double w = data->mixingWidth; + double YN2 = ZERO; + double YO2 = ZERO; + double YFuel, YOxidizer, sum; + + //if(data->problemType==0){ + // data->gas->equilibrate("HP"); + // data->maxTemperature=data->gas->temperature(); + //} + //else if(data->problemType==1){ + // /*Premixed Combustion: Equilibrium products comprise ignition + // * kernel at t=0. The width of the kernel is "mixingWidth" + // * shifted by "shift" from the center.*/ + // data->gas->equilibrate("HP"); + // Tmax=data->gas->temperature(); + // for (size_t i = 1; i <=data->npts; i++) { + // g=HALF*(tanh((R(i)-data->shift)/w)+ONE); //increasing function of x + // f=ONE-g; //decreasing function of x + // T(i)=(Tmax-Tmin)*f+Tmin; + // for (size_t k = 1; k <=data->nsp; k++) { + // Y(i,k)=(data->gas->massFraction(k-1)-Y(i,k))*f+Y(i,k); + // } + // } + // if(data->dirichletOuter){ + // T(data->npts)=data->wallTemperature; + // } + //} + //else if(data->problemType==2){ + // FILE* input; + // if(input=fopen("initialCondition.dat","r")){ + // readInitialCondition(input, ydata, data->nvar, data->nr, data->npts); + // fclose(input); + // } + // else{ + // printf("file initialCondition.dat not found!\n"); + // return(-1); + // } + //} + + // initializePsiGrid(ydata,psidata,data); + + + // if(data->adaptiveGrid){ + // // if(data->problemType!=0){ + // // data->grid->position=maxGradPosition(ydata, data->nt, data->nvar, + // // data->grid->xOld, data->npts); + // // //data->grid->position=maxCurvPosition(ydata, data->nt, data->nvar, + // // // data->grid->xOld, data->npts); + // // } + // // else{ + // // } + // if(data->problemType!=3){ + // data->grid->position=0.0e0; + // double x=data->grid->position+data->gridOffset*data->grid->leastMove; + // printf("New grid center:%15.6e\n",x); + + // ier=reGrid(data->grid, x); + // if(ier==-1)return(-1); + + // updateSolution(ydata, ydotdata, data->nvar, + // data->grid->xOld,data->grid->x,data->npts); + // storeGrid(data->grid->x,data->grid->xOld,data->npts); + // } + // } + // else{ + // double Rg = data->Rg, dpsi0; + // int NN = data->npts-2; + // double psiNew[data->npts]; + + // dpsi0 = (pow(Rg,1.0/NN) - 1.0)/(pow(Rg,(NN+1.0)/NN) - 1.0); + // psiNew[0] = 0; + // for (size_t i = 1; i < data->npts-1; i++) { + // psiNew[i]=psiNew[i-1]+dpsi0*pow(Rg,(i-1.0)/NN); + // } + // psiNew[data->npts-1] = 1.0; + // printf("Last point:%15.6e\n",psiNew[data->npts-1]); + // updateSolution(ydata, ydotdata, data->nvar, + // data->uniformGrid,psiNew,data->npts); + // storeGrid(psiNew,data->uniformGrid,data->npts); + + // //double psiNew[data->npts]; + // //double dpsi=1.0e0/((double)(data->npts)-1.0e0); + // //for (size_t i = 0; i < data->npts; i++) { + // // psiNew[i]=(double)(i)*dpsi; + // //} + // //printf("Last point:%15.6e\n",psiNew[data->npts-1]); + // //updateSolution(ydata, ydotdata, data->nvar, + // // data->uniformGrid,psiNew,data->npts); + // //storeGrid(psiNew,data->uniformGrid,data->npts); + // } + + if (data->problemType == 0) { + data->gas->equilibrate("HP"); + data->maxTemperature = data->gas->temperature(); + } else if (data->problemType == 1) { + /*Premixed Combustion: Equilibrium products comprise ignition * kernel at t=0. The width of the kernel is "mixingWidth" * shifted by "shift" from the center.*/ - data->gas->equilibrate("HP"); - Tmax=data->gas->temperature(); - for (size_t i = 1; i <=data->npts; i++) { - g=HALF*(tanh((R(i)-data->shift)/w)+ONE); //increasing function of x - f=ONE-g; //decreasing function of x - T(i)=(Tmax-Tmin)*f+Tmin; - for (size_t k = 1; k <=data->nsp; k++) { - Y(i,k)=(data->gas->massFraction(k-1)-Y(i,k))*f+Y(i,k); - } - } - if(data->dirichletOuter){ - T(data->npts)=data->wallTemperature; - } - } - else if(data->problemType==2){ - FILE* input; - if(input=fopen("initialCondition.dat","r")){ - readInitialCondition(input, ydata, data->nvar, data->nr, data->npts, data->Rg); - fclose(input); - } - else{ - printf("file initialCondition.dat not found!\n"); - return(-1); - } - initializePsiGrid(ydata,psidata,data); - } - else if(data->problemType==3){ - FILE* input; - if(input=fopen("restart.bin","r")){ - readRestart(y, ydot, input, data); - fclose(input); - printf("Restart solution loaded!\n"); - printf("Problem starting at t=%15.6e\n",data->tNow); - return(0); - } - else{ - printf("file restart.bin not found!\n"); - return(-1); - } - } - - if(data->reflectProblem){ - double temp; - int j=1; - while (data->npts+1-2*j>=0) { - temp=T(j); - T(j)=T(data->npts+1-j); - T(data->npts+1-j)=temp; - for (size_t k = 1; k <=data->nsp; k++) { - temp=Y(j,k); - Y(j,k)=Y(data->npts+1-j,k); - Y(data->npts+1-j,k)=temp; - } - j=j+1; - } - } - - /*Floor small values to zero*/ - for (size_t i = 1; i <=data->npts; i++) { - for (size_t k = 1; k <=data->nsp; k++) { - if(fabs(Y(i,k))<=data->massFractionTolerance){ - Y(i,k)=0.0e0; - } - } - } - - //Set grid to location of maximum curvature calculated by r instead of x: - if(data->adaptiveGrid){ - //data->grid->position=maxCurvPosition(ydata, data->nt, data->nvar, - // data->grid->x, data->npts); - int maxCurvII = 0; - maxCurvII = maxCurvIndexR(ydata,data->nt,data->nvar,data->nr,data->npts); - + data->gas->equilibrate("HP"); + Tmax = data->gas->temperature(); + for (size_t i = 1; i <= data->npts; i++) { + g = HALF * (tanh((R(i) - data->shift) / w) + ONE); //increasing function of x + f = ONE - g; //decreasing function of x + T(i) = (Tmax - Tmin) * f + Tmin; + for (size_t k = 1; k <= data->nsp; k++) { + Y(i, k) = (data->gas->massFraction(k - 1) - Y(i, k)) * f + Y(i, k); + } + } + if (data->dirichletOuter) { + T(data->npts) = data->wallTemperature; + } + } else if (data->problemType == 2) { + FILE *input; + if (input = fopen("initialCondition.dat", "r")) { + readInitialCondition(input, ydata, data->nvar, data->nr, data->npts, data->l_npts, data->Rg); + fclose(input); + } else { + printf("file initialCondition.dat not found!\n"); + return (-1); + } + // initializePsiGrid(ydata,psidata,data); + initializePsiEtaGrid(ydata, psidata, data); + } else if (data->problemType == 3) { + FILE *input; + if (input = fopen("restart.bin", "r")) { + readRestart(y, ydot, input, data); + fclose(input); + printf("Restart solution loaded!\n"); + printf("Problem starting at t=%15.6e\n", data->tNow); + return (0); + } else { + printf("file restart.bin not found!\n"); + return (-1); + } + } + + if (data->reflectProblem) { + double temp; + int j = 1; + while (data->npts + 1 - 2 * j >= 0) { + temp = T(j); + T(j) = T(data->npts + 1 - j); + T(data->npts + 1 - j) = temp; + for (size_t k = 1; k <= data->nsp; k++) { + temp = Y(j, k); + Y(j, k) = Y(data->npts + 1 - j, k); + Y(data->npts + 1 - j, k) = temp; + } + j = j + 1; + } + } + + /*Floor small values to zero*/ + for (size_t i = 1; i <= data->npts; i++) { + for (size_t k = 1; k <= data->nsp; k++) { + if (fabs(Y(i, k)) <= data->massFractionTolerance) { + Y(i, k) = 0.0e0; + } + } + } + + //Set grid to location of maximum curvature calculated by r instead of x: + if (data->adaptiveGrid) { + //data->grid->position=maxCurvPosition(ydata, data->nt, data->nvar, + // data->grid->x, data->npts); + int maxCurvII = 0; + maxCurvII = maxCurvIndexR(ydata, data->nt, data->nvar, data->nr, data->npts); + data->grid->position = data->grid->x[maxCurvII]; - ier=reGrid(data->grid, data->grid->position); - updateSolution(ydata, ydotdata, data->nvar, - data->grid->xOld,data->grid->x,data->npts); - storeGrid(data->grid->x,data->grid->xOld,data->npts); - + ier = reGrid(data->grid, data->grid->position); + updateSolution(ydata, ydotdata, data->nvar, + data->grid->xOld, data->grid->x, data->npts); + storeGrid(data->grid->x, data->grid->xOld, data->npts); + /******** Test the maxCurvPosition and related variables *******/ - printf("The maxCurvPositition(based on r) is : %.6f,Temperature is : %.3f \n",data->grid->position,T(maxCurvII+1)); - } + printf("The maxCurvPositition(based on r) is : %.6f,Temperature is : %.3f \n", data->grid->position, + T(maxCurvII + 1)); + } - /*Ensure consistent boundary conditions*/ - //T(1)=T(2); - //for (size_t k = 1; k <=data->nsp; k++) { - // Y(1,k)=Y(2,k); - // Y(data->npts,k)=Y(data->npts-1,k); - //} + /*Ensure consistent boundary conditions*/ + //T(1)=T(2); + //for (size_t k = 1; k <=data->nsp; k++) { + // Y(1,k)=Y(2,k); + // Y(data->npts,k)=Y(data->npts-1,k); + //} + printPsidata(data,psidata); - return(0); + return (0); } -inline double Qdot(double* t, - double* x, - double* ignTime, - double* kernelSize, - double* maxQdot){ - double qdot; - if(*x<=*kernelSize){ - if((*t)<=(*ignTime)){ - qdot=(*maxQdot); - } - else{ - qdot=0.0e0; - } - }else{ - qdot=0.0e0; - } - return(qdot); +inline double Qdot(double *t, + double *x, + double *ignTime, + double *kernelSize, + double *maxQdot) { + double qdot; + if (*x <= *kernelSize) { + if ((*t) <= (*ignTime)) { + qdot = (*maxQdot); + } else { + qdot = 0.0e0; + } + } else { + qdot = 0.0e0; + } + return (qdot); } -inline void setGas(UserData data, - double *ydata, - size_t gridPoint){ - data->gas->setTemperature(T(gridPoint)); - data->gas->setMassFractions_NoNorm(&Y(gridPoint,1)); - data->gas->setPressure(P(gridPoint)); +inline void setGas(UserData data, + double *ydata, + size_t gridPoint) { + data->gas->setTemperature(T(gridPoint)); + data->gas->setMassFractions_NoNorm(&Y(gridPoint, 1)); + data->gas->setPressure(P(gridPoint)); } -void getTransport(UserData data, - double *ydata, - size_t gridPoint, - double *rho, - double *lambda, - double YV[]){ - - double YAvg[data->nsp], - XLeft[data->nsp], - XRight[data->nsp], - gradX[data->nsp]; - - setGas(data,ydata,gridPoint); - data->gas->getMoleFractions(XLeft); - setGas(data,ydata,gridPoint+1); - data->gas->getMoleFractions(XRight); - - for (size_t k = 1; k <=data->nsp; k++) { - YAvg(k)=HALF*(Y(gridPoint,k)+ - Y(gridPoint+1,k)); - gradX(k)=(XRight(k)-XLeft(k))/ - (R(gridPoint+1)-R(gridPoint)); - } - double TAvg = HALF*(T(gridPoint)+T(gridPoint+1)); - double gradT=(T(gridPoint+1)-T(gridPoint))/ - (R(gridPoint+1)-R(gridPoint)); - - - data->gas->setTemperature(TAvg); - data->gas->setMassFractions_NoNorm(YAvg); - data->gas->setPressure(P(gridPoint)); - - *rho=data->gas->density(); - *lambda=data->trmix->thermalConductivity(); - data->trmix->getSpeciesFluxes(1,&gradT,data->nsp, - gradX,data->nsp,YV); - //setGas(data,ydata,gridPoint); +void getTransport(UserData data, + double *ydata, + size_t gridPoint, + double *rho, + double *lambda, + double YV[]) { + + double YAvg[data->nsp], + XLeft[data->nsp], + XRight[data->nsp], + gradX[data->nsp]; + + setGas(data, ydata, gridPoint); + data->gas->getMoleFractions(XLeft); + setGas(data, ydata, gridPoint + 1); + data->gas->getMoleFractions(XRight); + + for (size_t k = 1; k <= data->nsp; k++) { + YAvg(k) = HALF * (Y(gridPoint, k) + + Y(gridPoint + 1, k)); + gradX(k) = (XRight(k) - XLeft(k)) / + (R(gridPoint + 1) - R(gridPoint)); + } + double TAvg = HALF * (T(gridPoint) + T(gridPoint + 1)); + double gradT = (T(gridPoint + 1) - T(gridPoint)) / + (R(gridPoint + 1) - R(gridPoint)); + + + data->gas->setTemperature(TAvg); + data->gas->setMassFractions_NoNorm(YAvg); + data->gas->setPressure(P(gridPoint)); + + *rho = data->gas->density(); + *lambda = data->trmix->thermalConductivity(); + data->trmix->getSpeciesFluxes(1, &gradT, data->nsp, + gradX, data->nsp, YV); + //setGas(data,ydata,gridPoint); +} + +void getGasMassFlux(UserData data, + double *ydata, + size_t gridPoint, + double YV[]) { + + double YAvg[data->nsp], + XLeft[data->nsp], + XRight[data->nsp], + gradX[data->nsp]; + + setGas(data, ydata, gridPoint); + data->gas->getMoleFractions(XLeft); + setGas(data, ydata, gridPoint + 1); + data->gas->getMoleFractions(XRight); + + for (size_t k = 1; k <= data->nsp; k++) { + YAvg(k) = HALF * (Y(gridPoint, k) + + Y(gridPoint + 1, k)); + gradX(k) = (XRight(k) - XLeft(k)) / + (R(gridPoint + 1) - R(gridPoint)); + } + double TAvg = HALF * (T(gridPoint) + T(gridPoint + 1)); + double gradT = (T(gridPoint + 1) - T(gridPoint)) / + (R(gridPoint + 1) - R(gridPoint)); + + + data->gas->setTemperature(TAvg); + data->gas->setMassFractions_NoNorm(YAvg); + data->gas->setPressure(P(gridPoint)); + + data->trmix->getSpeciesFluxes(1, &gradT, data->nsp, + gradX, data->nsp, YV); + //setGas(data,ydata,gridPoint); } -int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data){ - - /*Declare and fetch nvectors and user data:*/ - - double *ydata, *ydotdata, *resdata, *psidata, *innerMassFractionsData; - - UserData data; - data = (UserData)user_data; - size_t npts=data->npts; - size_t nsp=data->nsp; - size_t k_bath = data->k_bath; - size_t k_drop[2] = {data->k_drop[0],data->k_drop[1]}; - - ydata = N_VGetArrayPointer_OpenMP(y); - ydotdata= N_VGetArrayPointer_OpenMP(ydot); - resdata = N_VGetArrayPointer_OpenMP(res); - if(data->adaptiveGrid==1){ - psidata = data->grid->x; - }else{ - psidata = data->uniformGrid; - } - - innerMassFractionsData = data->innerMassFractions; - - /* Grid stencil:*/ - - /*-------|---------*---------|---------*---------|-------*/ - /*-------|---------*---------|---------*---------|-------*/ - /*-------|---------*---------|---------*---------|-------*/ - /*-------m-------mhalf-------j-------phalf-------p-------*/ - /*-------|---------*---------|---------*---------|-------*/ - /*-------|---------*---------|---------*---------|-------*/ - /*-------|<=======dxm=======>|<=======dxp=======>|-------*/ - /*-------|---------*<======dxav=======>*---------|-------*/ - /*-------|<================dxpm=================>|-------*/ - - /* Various variables defined for book-keeping and storing previously +int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data) { + + /*Declare and fetch nvectors and user data:*/ + double *ydata, *ydotdata, *resdata, *psidata, *innerMassFractionsData; + + UserData data; + data = (UserData) user_data; + size_t npts = data->npts; + size_t nsp = data->nsp; + size_t k_bath = data->k_bath; + size_t l_npts = data->l_npts; + int dropType = data->dropType; + + std::vector k_drop = data->k_drop; + std::vector dropSpec = data->dropSpec; + std::vector composition = components(data->dropType); + std::vector dropMole = data->dropMole; + + ydata = N_VGetArrayPointer_OpenMP(y); + ydotdata = N_VGetArrayPointer_OpenMP(ydot); + resdata = N_VGetArrayPointer_OpenMP(res); + if (data->adaptiveGrid == 1) { + psidata = data->grid->x; + } else { + psidata = data->uniformGrid; + } + + innerMassFractionsData = data->innerMassFractions; + + /* Grid stencil:*/ + + /*-------|---------*---------|---------*---------|-------*/ + /*-------|---------*---------|---------*---------|-------*/ + /*-------|---------*---------|---------*---------|-------*/ + /*-------m-------mhalf-------j-------phalf-------p-------*/ + /*-------|---------*---------|---------*---------|-------*/ + /*-------|---------*---------|---------*---------|-------*/ + /*-------|<=======dxm=======>|<=======dxp=======>|-------*/ + /*-------|---------*<======dxav=======>*---------|-------*/ + /*-------|<================dxpm=================>|-------*/ + + /* Various variables defined for book-keeping and storing previously * calculated values: * rho : densities at points m, mhalf, j, p, and phalf. * area : the matric at points m, mhalf, j, p, and phalf. @@ -1076,55 +1767,248 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data){ * srcTerm : source terms. */ - double rhomhalf, rhom, lambdamhalf, YVmhalf[nsp], - rho, - rhophalf, lambdaphalf, YVphalf[nsp], - Cpb, Cvb, Cp[nsp], Cpl[2], dHvl[2], rhol, wdot[nsp], enthalpy[nsp], energy[nsp],T_boil, - tranTerm, diffTerm, srcTerm, advTerm, - area,areamhalf,areaphalf,aream,areamhalfsq,areaphalfsq; - - /*Aliases for difference coefficients:*/ - double cendfm, cendfc, cendfp; - /*Aliases for various grid spacings:*/ - double dpsip, dpsiav, dpsipm, dpsim, dpsimm; - dpsip=dpsiav=dpsipm=dpsim=dpsimm=ONE; - //double mass, mdotIn; - double mass, massDrop; - double sum, sum1, sum2, sum3; - - size_t j,k; - int m; - m=data->metric; //Unitless - mass=data->mass; //Units: kg - //massDrop=data->massDrop; //Units: kg - //mdotIn=data->mdot*calc_area(R(npts),&m); //Units: kg/s - -// /*evaluate properties at j=1*************************/ - setGas(data,ydata,1); - rhom=data->gas->density(); - Cpb=data->gas->cp_mass(); //J/kg/K - Cvb=data->gas->cv_mass(); //J/kg/K - //TODO: Create user input model for these. They should not be constant - //Cpl=4.182e03; //J/kg/K for liquid water - //Cpl= 5.67508633e-07*pow(T(1),4) - 7.78060597e-04*pow(T(1),3) + 4.08310544e-01*pow(T(1),2) //J/kg/K for liquid water + double rhomhalf, rhom, lambdamhalf, YVmhalf[nsp], + rho, Diffcoeffphalf, Diffcoeffmhalf,propYVmhalf,propYVphalf, + rhophalf, lambdaphalf, YVphalf[nsp], + Cpb, Cvb, Cp[nsp], Cpl[2], dHvl[2], rhol, wdot[nsp], enthalpy[nsp], energy[nsp], T_boil, + tranTerm, diffTerm, srcTerm, advTerm, + area, areamhalf, areaphalf, aream, areamhalfsq, areaphalfsq; + + /*Aliases for difference coefficients:*/ + double cendfm, cendfc, cendfp; + /*Aliases for various grid spacings:*/ + double dpsip, dpsiav, dpsipm, dpsim, dpsimm; + dpsip = dpsiav = dpsipm = dpsim = dpsimm = ONE; + //double mass, mdotIn; + double mass, massDrop; + double sum, sum1, sum2, sum3; + + std::vector vapheat, mole_,liquidCp,vapPres; + +// size_t j, k; + int m; + m = data->metric; //Unitless + mass = data->mass; //Units: kg + + /*evaluate and implement the governing equations in the liquid phase*/ + + /*implement res @ left boundary i.e., first grid point*/ + Rres(1) = Rdot(1); + if (dropType == 0) { + // Yres(1,data->k_drop[0]) = Ydot(1,data->k_drop[0]); + for (size_t k = 1; k <= nsp; k++) { + Yres(1, k) = Ydot(1, k); + } + } else { + for (size_t k = 1; k <= nsp; k++) { + if (k == k_drop[0]) { + Yres(1, k) = Y(2, k) - Y(1, k); + } else if (k == k_drop[1]) { + Yres(1, k) = ONE - Y(1, k_drop[0]) - Y(1, k); + } else { + Yres(1, k) = Ydot(1, k); + } + } + } + Pres(1) = P(2) - P(1); + Mdotres(1) = Mdot(2) - Mdot(1); + Tres(1) = T(2) - T(1); + + /*set governing equations at intermediate grid points */ + massDrop = dropletmass(data, ydata); + if (dropType == 0) { + for (size_t j = 2; j <= l_npts - 1; j++) { + /*Mass:*/ + /* ∂r/∂ψ = 1/ρA */ + dpsim = - (psi(j) - psi(j - 1)); + dpsip = - (psi(j + 1) - psi(j)); + dpsiav = - (HALF * (psi(j + 1) - psi(j - 1))); + rho = getLiquidDensity(T(j), P(j), composition); + rhom = getLiquidDensity(T(j - 1), P(j - 1), composition); + rhophalf = getLiquidDensity(HALF * (T(j) + T(j + 1)), HALF * (P(j) + P(j + 1)), composition); + rhomhalf = getLiquidDensity(HALF * (T(j) + T(j - 1)), HALF * (P(j) + P(j - 1)), composition); + + Cpb = getLiquidCpb(T(j), P(j), composition); + lambdaphalf = getLiquidCond(HALF * (T(j) + T(j + 1)), HALF * (P(j) + P(j + 1)), composition); + lambdamhalf = getLiquidCond(HALF * (T(j) + T(j - 1)), HALF * (P(j) + P(j - 1)), composition); + + aream = calc_area(R(j - 1), &m); + areamhalf = calc_area(HALF * (R(j) + R(j - 1)), &m); + areaphalf = calc_area(HALF * (R(j + 1) + R(j)), &m); + areamhalfsq = areamhalf * areamhalf; + areaphalfsq = areaphalf * areaphalf; + area = calc_area(R(j), &m); + + Rres(j) = ((R(j) - R(j - 1)) / dpsim) - massDrop * (TWO / (rhom * aream + rho * area)); + Mdotres(j) = Mdot(j + 1) - Mdot(j); + Pres(j) = P(j + 1) - P(j); + for (size_t k = 1; k <= nsp; k++) { + Yres(j, k) = Y(j, k) - Y(j - 1, k); + } + + tranTerm = Tdot(j); + advTerm = psi(j) * (-Mdot(j)) / massDrop * (T(j) - T(j - 1)) / dpsim ; + diffTerm = 1 / (Cpb * massDrop * massDrop) * + (rhophalf * areaphalfsq * lambdaphalf * (T(j + 1) - T(j)) / dpsip - + rhomhalf * areamhalfsq * lambdamhalf * (T(j) - T(j - 1)) / dpsim) / dpsiav; + Tres(j) = tranTerm - advTerm - diffTerm; + } + + /*Fill up the res at l_npts*/ + rho = getLiquidDensity(T(l_npts), P(l_npts), composition); + area = calc_area(R(l_npts), &m); + lambdamhalf = getLiquidCond(T(l_npts), P(l_npts), composition); + lambdaphalf = getGasCond(data, ydata, l_npts+1); + vapheat = getLiquidVH(P(l_npts+1), data->dropType); + + Rres(l_npts) = Mdot(l_npts) + rho * Rdot(l_npts) * area; + Mdotres(l_npts) = Mdot(l_npts + 1) - Mdot(l_npts); + Pres(l_npts) = P(l_npts + 1) - P(l_npts); + for (size_t k = 1; k <= nsp; k++) { + Yres(l_npts, k) = Y(l_npts, k) - Y(l_npts - 1, k); + } + Tres(l_npts) = lambdamhalf * (T(l_npts) - T(l_npts - 1)) / (R(l_npts) - R(l_npts - 1)) * area + + Mdot(l_npts) * vapheat[0] - + lambdaphalf * (T(l_npts + 2) - T(l_npts + 1)) / (R(l_npts + 2) - R(l_npts + 1)) * area; + } else { + /*binary component case*/ + /*implementation of liquid phase inner grid points*/ + for (size_t j = 2; j <= l_npts - 1; j++) { + mole_ = getLiquidmolevec(data, ydata, j); + + dpsim = - (psi(j) - psi(j - 1)); + dpsip = - (psi(j + 1) - psi(j)); + dpsiav = - (HALF * (psi(j + 1) - psi(j - 1))); + + /*evaluate various central difference coefficients*/ + cendfm = -dpsip / (dpsim * dpsipm); + cendfc = (dpsip - dpsim) / (dpsip * dpsim); + cendfp = dpsim / (dpsip * dpsipm); + /**************************************************/ + + rho = getLiquidDensity(T(j), P(j), composition, mole_); + rhom = getLiquidDensity(T(j - 1), P(j - 1), composition, mole_); + rhophalf = getLiquidDensity(HALF * (T(j) + T(j + 1)), HALF * (P(j) + P(j + 1)), composition, mole_); + rhomhalf = getLiquidDensity(HALF * (T(j) + T(j - 1)), HALF * (P(j) + P(j - 1)), composition, mole_); + + Cpb = getLiquidCpb(T(j), P(j), composition, mole_); + liquidCp = getLiquidCp(T(j),P(j),composition); + + lambdaphalf = getLiquidCond(HALF * (T(j) + T(j + 1)), HALF * (P(j) + P(j + 1)), composition, mole_); + lambdamhalf = getLiquidCond(HALF * (T(j) + T(j - 1)), HALF * (P(j) + P(j - 1)), composition, mole_); + + aream = calc_area(R(j - 1), &m); + areamhalf = calc_area(HALF * (R(j) + R(j - 1)), &m); + areaphalf = calc_area(HALF * (R(j + 1) + R(j)), &m); + areamhalfsq = areamhalf * areamhalf; + areaphalfsq = areaphalf * areaphalf; + area = calc_area(R(j), &m); + + Diffcoeffphalf = getLiquidmassdiff(data, ydata, j, HALF * (T(j) + T(j + 1))); + Diffcoeffmhalf = getLiquidmassdiff(data, ydata, j, HALF * (T(j) + T(j - 1))); + + Rres(j) = ((R(j) - R(j - 1)) / dpsim) - massDrop * (TWO / (rhom * aream + rho * area)); + Mdotres(j) = Mdot(j + 1) - Mdot(j); + Pres(j) = P(j + 1) - P(j); + + propYVphalf = (-Diffcoeffphalf * (Y(j + 1, k_drop[0]) - Y(j, k_drop[0])) / (R(j + 1) - R(j))); + propYVmhalf = (-Diffcoeffmhalf * (Y(j, k_drop[0]) - Y(j - 1, k_drop[0])) / (R(j) - R(j - 1))); + + liquidCp = getLiquidCp(T(j),P(j),composition); + /*species equation*/ + for (size_t k = 1; k <= nsp; k++) { + if (k != k_drop[0] && k != k_drop[1]) { + Yres(j, k) = Y(j, k) - Y(j - 1, k); + } else if (k == k_drop[0]) { + tranTerm = Ydot(j, k); + advTerm = 1 / massDrop * (psi(j) * (-Mdot(j))) * (Y(j, k) - Y(j - 1, k)) / dpsim; + diffTerm = 1 / massDrop * + (areaphalf * rhophalf * propYVphalf + - areamhalf * rhomhalf * propYVmhalf ) + / dpsiav; + Yres(j, k) = tranTerm - advTerm + diffTerm; + } else{ + Yres(j,k) = ONE - Y(j,k_drop[0]); + } + } + /*energy equation*/ + tranTerm = Tdot(j); + advTerm = 1/massDrop *(psi(j)*(-Mdot(j)))* (T(j)-T(j-1))/(psi(j)-psi(j-1)); + double diffTerm1 = 1/(Cpb*massDrop*massDrop) * ( (rhophalf*areaphalfsq*lambdaphalf*(T(j+1)-T(j))/(psi(j+1)-psi(j)) ) + - (rhomhalf*areamhalfsq*lambdamhalf*(T(j)-T(j-1))/(psi(j)-psi(j-1)) ) ) /dpsiav; + double diffTerm2 = area/(Cpb*massDrop)*rho*(cendfp*T(j+1)+cendfc*T(j)+cendfm*T(j-1)) * + (HALF*((propYVphalf+propYVmhalf)*liquidCp[0]+(-propYVphalf-propYVmhalf)*liquidCp[1])) ; + diffTerm = diffTerm1 - diffTerm2 ; + Tres(j) = tranTerm - advTerm - diffTerm ; + } + + /*implementation of right boundary of liquid phase*/ + mole_ = getLiquidmolevec(data,ydata,l_npts); + rho = getLiquidDensity(T(l_npts), P(l_npts), composition,mole_); + area = calc_area(R(l_npts), &m); + lambdamhalf = getLiquidCond(T(l_npts), P(l_npts), composition,mole_); + lambdaphalf = getGasCond(data, ydata, l_npts+1); + + propYVmhalf = (-Diffcoeffmhalf * (Y(l_npts, k_drop[0]) - Y(l_npts - 1, k_drop[0])) / (R(l_npts) - R(l_npts - 1))); + getGasMassFlux(data,ydata,l_npts+1,YVphalf); + + Diffcoeffmhalf = getLiquidmassdiff(data, ydata, l_npts, HALF * (T(l_npts) + T(l_npts - 1))); + vapheat = getLiquidVH(P(l_npts), data->dropType); + + Rres(l_npts) = Mdot(l_npts) + rho * Rdot(l_npts) * area; + Mdotres(l_npts) = Mdot(l_npts + 1) - Mdot(l_npts); + Pres(l_npts) = P(l_npts + 1) - P(l_npts); + + /*species formualtion*/ + for (size_t k = 1; k <= nsp; k++) { + if (k == k_drop[0]) { + Yres(l_npts, k) = Mdot(l_npts) * Y(l_npts, k) + area * rho * + (-Diffcoeffmhalf * (Y(l_npts, k) - Y(l_npts - 1, k)) / + (R(l_npts) - R(l_npts - 1))) + - Mdot(l_npts) * Y(l_npts + 1, k) - area * YVphalf[k_drop[0] - 1]; + } else if (k == k_drop[1]) { + Yres(l_npts, k) = ONE - Y(l_npts, k_drop[0]) - Y(l_npts, k); + } else { + Yres(l_npts, k) = Y(l_npts, k) - Y(l_npts - 1, k); + } + } + + /*temperature formulation*/ + double epsilon = Y(l_npts + 1, k_drop[0]) + YVphalf[k_drop[0] - 1] * area / Mdot(l_npts); + Tres(l_npts) = lambdamhalf * (T(l_npts) - T(l_npts - 1)) / (R(l_npts) - R(l_npts - 1)) * area + + Mdot(l_npts) * (epsilon * vapheat[0] + (1 - epsilon) * vapheat[1]) + - lambdaphalf * (T(l_npts + 2) - T(l_npts + 1)) / (R(l_npts + 2) - R(l_npts + 1)) * area; + } + + //massDrop=data->massDrop; //Units: kg + //mdotIn=data->mdot*calc_area(R(npts),&m); //Units: kg/s + +// /*evaluate properties at j=l_npts+1 *************************/ + setGas(data, ydata, l_npts+1); + rhom = data->gas->density(); + Cpb = data->gas->cp_mass(); //J/kg/K + Cvb = data->gas->cv_mass(); //J/kg/K + //TODO: Create user input model for these. They should not be constant + //Cpl=4.182e03; //J/kg/K for liquid water + //Cpl= 5.67508633e-07*pow(T(1),4) - 7.78060597e-04*pow(T(1),3) + 4.08310544e-01*pow(T(1),2) //J/kg/K for liquid water // - 9.62429538e+01*T(1) + 1.27131046e+04; - + /*Update specific heat:Cpl for liquid proprane&n-heptane&dodecane*/ - /*Based on the existiong data,a linear expression is used*/ - // Cpl= 12.10476*T(1) - 746.60143; // Unit:J/(kg*K), Need to be improved later - //Cpl[0] = 2.423*T(1)+1661.074; //Unit:J/(kg*K),range:1atm,propane + /*Based on the existiong data,a linear expression is used*/ + // Cpl= 12.10476*T(1) - 746.60143; // Unit:J/(kg*K), Need to be improved later + //Cpl[0] = 2.423*T(1)+1661.074; //Unit:J/(kg*K),range:1atm,propane //Cpl[0] = 3.336*T(1)+1289.5; //Unit:J/(kg*K),range:1atm,n-Heptane //Cpl[1] = 3.815*T(1)+1081.8; //Unit:J/(kg*K),range:1atm,n-Dodecane - double Cp_l = 0.0; - Cp_l = getLiquidCp(data->dropMole,T(1),P(1)); +// double Cp_l = 0.0; +// Cp_l = getLiquidCp(data->dropMole,T(1),P(1)); //for(size_t i=0;i<=1;i++){ // Cp_l=Cp_l+Cpl[i]*data->dropMassFrac[i]; //} - //dHvl=2.260e6; //J/kg heat of vaporization of water - //double Tr = T(1)/647.1; //Reduced Temperature: Droplet Temperature divided by critical temperature of water - //dHvl= 5.2053e07*pow(1-Tr,0.3199 - 0.212*Tr + 0.25795*Tr*Tr)/18.01; //J/kg latent heat of vaporization of water - + //dHvl=2.260e6; //J/kg heat of vaporization of water + //double Tr = T(1)/647.1; //Reduced Temperature: Droplet Temperature divided by critical temperature of water + //dHvl= 5.2053e07*pow(1-Tr,0.3199 - 0.212*Tr + 0.25795*Tr*Tr)/18.01; //J/kg latent heat of vaporization of water + //double Tr1 = T(1)/369.8; //Reduced Temperature; //dHvl[0] = 6.32716e5*exp(-0.0208*Tr1)*pow((1-Tr1),0.3766); //Unit:J/kg,Latent Heat of Vaporizaiton of Liquid n-propane,NIST @@ -1132,191 +2016,234 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data){ //dHvl[0] = 5.366e5*exp(-0.2831*Tr2) * pow((1-Tr2),0.2831); //Unit:J/kg, latent heat of vaporization of liquid n-heptane, Source: NIST //dHvl[1] = 358.118e3; //Unit:J/kg,latent heat of vaporization of n-dodecane,Source:NIST - - double dHv_l = 0.0; - dHv_l = getLiquidHv(data->dropMole,T(1),P(1)); + +// double dHv_l = 0.0; +// dHv_l = getLiquidHv(data->dropMole,T(1),P(1)); //for(size_t i=0;i<=1;i++){ // dHv_l=dHv_l+dHvl[i]*data->dropMassFrac[i]; //} /*Following section is related to the property of water*/ - //rhol = 997.0; - //massDrop=1.0/3.0*R(1)*R(1)*R(1)*997.0; //TODO: The density of the droplet should be a user input - + //rhol = 997.0; + //massDrop=1.0/3.0*R(1)*R(1)*R(1)*997.0; //TODO: The density of the droplet should be a user input + /*Following section is related to the property of liquid n-heptane and n-dodecane (mainly density rho)*/ /*Density of these two species should be temperature dependent*/ //data->dropDens[0] = -1.046*T(1)+823.794; //Unit:kg/m^3,density of propane @1atm //data->dropDens[0] = -0.858*T(1)+933.854; //Unit:kg/m^3,density of n-Heptane @1atm //data->dropDens[1] = -0.782*T(1)+979.643; //Unit:kg/m^3,density of n-Dodecane @1atm //rhol = data->dropRho; //Unit:kg/m^3 - rhol = 0.0; - rhol = getLiquidRho(data->dropMole,T(1),P(1)); +// rhol = 0.0; +// rhol = getLiquidRho(data->dropMole,T(1),P(1)); //for(size_t i=0;i<=1;i++){ // rhol = rhol + data->dropMassFrac[i]*data->dropDens[i]; //} - massDrop = 1.0/3.0*R(1)*R(1)*R(1)*rhol; //Unit:kg, this is the mass of liquid droplet +// massDrop = 1.0/3.0*R(1)*R(1)*R(1)*rhol; //Unit:kg, this is the mass of liquid droplet + +// aream = calc_area(R(1), &m); + + + /*******************************************************************/ + /*Calculate values at j=l_npts+2 's m and mhalf*****************************/ +// getTransport(data, ydata, 1, &rhomhalf, &lambdamhalf, YVmhalf); +// areamhalf = calc_area(HALF * (R(1) + R(2)), &m); +// aream = calc_area(R(1), &m); +// areamhalfsq = areamhalf * areamhalf; + + getTransport(data, ydata, l_npts+1, &rhomhalf, &lambdamhalf, YVmhalf); + areamhalf = calc_area(HALF * (R(l_npts+1) + R(l_npts+2)), &m); + aream = calc_area(R(l_npts+1), &m); + areamhalfsq = areamhalf * areamhalf; + + /*******************************************************************/ + + /*Fill up res with left side (center) boundary conditions:**********/ + /*We impose zero fluxes at the center:*/ + + + /*Mass:*/ + if (data->quasiSteady) { +// Rres(1) = Rdot(1); // Should remain satisfied for quasi-steady droplet + Rres(l_npts+1) = Rdot(l_npts) ; + } else { + Rres(l_npts+1) = R(l_npts+1) - R(l_npts) ; +// Rres(1) = Rdot(1) + Mdot(1) / rhol / aream; + } + + //TODO: Antoine Parameters should be part of user input, not hardcoded + //Yres(1,k_drop)=Y(1,k_drop) - 1.0e5*pow(10,4.6543-(1435.264/(T(1)-64.848)))*data->gas->molecularWeight(k_drop-1) + // / P(1) / data->gas->meanMolecularWeight(); + //Yres(1,k_drop)=Y(1,k_drop) - 1.0e3*pow(2.71828,16.7-(4060.0/(T(1)-37.0)))*data->gas->molecularWeight(k_drop-1) + // / P(1) / data->gas->meanMolecularWeight(); + //Yres(1,k_drop)=Y(1,k_drop)-2.566785e-02; - aream= calc_area(R(1),&m); - - - /*******************************************************************/ - /*Calculate values at j=2's m and mhalf*****************************/ - - getTransport(data, ydata, 1, &rhomhalf,&lambdamhalf,YVmhalf); - areamhalf= calc_area(HALF*(R(1)+R(2)),&m); - aream = calc_area(R(1),&m); - areamhalfsq= areamhalf*areamhalf; - - /*******************************************************************/ - - /*Fill up res with left side (center) boundary conditions:**********/ - /*We impose zero fluxes at the center:*/ - - - /*Mass:*/ - if(data->quasiSteady){ - Rres(1)=Rdot(1); // Should remain satisfied for quasi-steady droplet - }else{ - Rres(1)=Rdot(1) + Mdot(1)/rhol/aream; - } - - /*Species:*/ - sum=ZERO; - - //TODO: Antoine Parameters should be part of user input, not hardcoded - //Yres(1,k_drop)=Y(1,k_drop) - 1.0e5*pow(10,4.6543-(1435.264/(T(1)-64.848)))*data->gas->molecularWeight(k_drop-1) - // / P(1) / data->gas->meanMolecularWeight(); - //Yres(1,k_drop)=Y(1,k_drop) - 1.0e3*pow(2.71828,16.7-(4060.0/(T(1)-37.0)))*data->gas->molecularWeight(k_drop-1) - // / P(1) / data->gas->meanMolecularWeight(); - //Yres(1,k_drop)=Y(1,k_drop)-2.566785e-02; - /*Following using the Antoine Parameters to calculate the pressure of volatile component(n-heptane)*/ /*Antoine parameter from NIST website*/ /*Raoult's Law is applied to calculate the partial vapor pressure*/ - double p_i[2]={0.0,0.0} ; - p_i[0] = 1.0e5*pow(10,4.53678-(1149.36/(T(1)+24.906)))*data->dropMole[0]*data->gamma[0] ; //unit:Pa,Helgeson and Sage,1967,Propane - //p_i[0] = 1.0e5*pow(10,4.02832-(1268.636/(T(1)-56.199)))*data->dropMole[0] ; - p_i[1] = 1.0e5*pow(10,4.02832-(1268.636/(T(1)-56.199)))*data->dropMole[1]*data->gamma[1] ; //unit:Pa,n-Heptane +// double p_i[2] = {0.0, 0.0}; +// p_i[0] = 1.0e5 * pow(10, 4.53678 - (1149.36 / (T(1) + 24.906))) * data->dropMole[0] * +// data->gamma[0]; //unit:Pa,Helgeson and Sage,1967,Propane +// //p_i[0] = 1.0e5*pow(10,4.02832-(1268.636/(T(1)-56.199)))*data->dropMole[0] ; +// p_i[1] = 1.0e5 * pow(10, 4.02832 - (1268.636 / (T(1) - 56.199))) * data->dropMole[1] * +// data->gamma[1]; //unit:Pa,n-Heptane //p_i[1] = 1.0e5*pow(10,4.10549-(1625.928/(T(1)-92.839)))*data->dropMole[1] ; //Unit:Pa.Williamham and Taylor,n-dodecane + /*for both dropletTypes(0,1),implementations of Rres,Tres,Pres are the same + * only Yres and Mdotres are different */ + /*Species:*/ + sum = ZERO; + /*single component case*/ + if (dropType == 0) { + double hepPres = 1.0e5 * pow(10, 4.02832 - (1268.636 / (T(l_npts+1) - 56.199))); + Yres(l_npts + 1, k_drop[0]) = Y(l_npts + 1, k_drop[0]) - hepPres * data->gas->molecularWeight(k_drop[0] - 1) / + (P(l_npts + 1) * data->gas->meanMolecularWeight()); + sum = sum + Y(l_npts + 1, k_drop[0]); + Mdotres(l_npts + 1) = Mdot(l_npts + 1) - (YVmhalf(k_drop[0]) * areamhalf) / (1 - Y(l_npts + 1, k_drop[0])); + for (size_t k = 1; k <= nsp; k++) { + if (k != k_bath && k != k_drop[0]) { + Yres(l_npts + 1, k) = Y(l_npts + 1, k) * Mdot(l_npts + 1) + YVmhalf(k) * areamhalf; + sum = sum + Y(l_npts + 1, k); + } + } + Yres(l_npts + 1, k_bath) = ONE - sum - Y(l_npts + 1, k_bath); + } + + /*binary componet case for gas phase LHS boundary*/ + if(dropType == 1){ + mole_ = getLiquidmolevec(data,ydata,l_npts); + vapPres = getVapPressure(data,ydata,l_npts+1,mole_); + + for (size_t i = 0; i < k_drop.size(); i++) { + Yres(l_npts+1, k_drop[i]) = Y(l_npts+1, k_drop[i]) - vapPres[i] * data->gas->molecularWeight(k_drop[i] - 1) / + (P(l_npts+1) * data->gas->meanMolecularWeight()); + sum = sum + Y(l_npts+1, k_drop[i]); + } + Mdotres(l_npts+1) = Mdot(l_npts+1) - ((YVmhalf(k_drop[0]) + YVmhalf(k_drop[1])) * areamhalf) / + (1 - Y(l_npts+1, k_drop[0]) - Y(l_npts+1, k_drop[1])); + for (size_t k = 1; k <= nsp; k++) { + if (k != k_bath && k != k_drop[0] && k != k_drop[1]) { + //TODO: May need to include chemical source term + Yres(l_npts+1, k) = Y(l_npts+1, k) * Mdot(l_npts+1) + YVmhalf(k) * areamhalf; + //Yres(1,k)=YVmhalf(k)*areamhalf; + sum = sum + Y(l_npts+1, k); + //if(fabs(Mdot(1))>1e-14){ + ///Yres(1,k)=innerMassFractionsData[k-1]- + /// Y(1,k)- + /// (YVmhalf(k)*areamhalf)/Mdot(1); + + //} + //else{ + // //Yres(1,k)=Y(1,k)-innerMassFractionsData[k-1]; + // Yres(1,k)=Y(2,k)-Y(1,k); + // /*The below flux boundary condition makes the + // * problem more prone to diverge. How does one + // * fix this?*/ + // //Yres(1,k)=YVmhalf(k); + //} + } + } + Yres(l_npts+1, k_bath) = ONE - sum - Y(l_npts+1, k_bath); + } + + //p_i = 1.0e3*pow(2.71828,16.7-(4060.0/(T(1)-37.0))); //Unit:Pa,FOR WATER - //Yres(1,k_drop)=Y(1,k_drop) - p_i * data->gas->molecularWeight(k_drop-1) - // / P(1) / data->gas->meanMolecularWeight(); - for(size_t i=0;i<=1;i++){ - Yres(1,k_drop[i])=Y(1,k_drop[i])-p_i[i]*data->gas->molecularWeight(k_drop[i]-1)/(P(1)*data->gas->meanMolecularWeight()); - } - - sum=sum+Y(1,k_drop[0])+Y(1,k_drop[1]); - - //Mdotres(1)=Mdot(1) - (YVmhalf(k_drop)*areamhalf) / (1-Y(1,k_drop)); //Evaporating mass - Mdotres(1)= Mdot(1) - ((YVmhalf(k_drop[0])+YVmhalf(k_drop[1])) *areamhalf) / (1-Y(1,k_drop[0])-Y(1,k_drop[1]) ); //Evaporating mass - for (k = 1; k <=nsp; k++) { - if(k!=k_bath && k!=k_drop[0] && k!=k_drop[1]){ - //TODO: May need to include chemical source term - Yres(1,k)=Y(1,k)*Mdot(1) + YVmhalf(k)*areamhalf; - //Yres(1,k)=YVmhalf(k)*areamhalf; - sum=sum+Y(1,k); - //if(fabs(Mdot(1))>1e-14){ - ///Yres(1,k)=innerMassFractionsData[k-1]- - /// Y(1,k)- - /// (YVmhalf(k)*areamhalf)/Mdot(1); - - //} - //else{ - // //Yres(1,k)=Y(1,k)-innerMassFractionsData[k-1]; - // Yres(1,k)=Y(2,k)-Y(1,k); - // /*The below flux boundary condition makes the - // * problem more prone to diverge. How does one - // * fix this?*/ - // //Yres(1,k)=YVmhalf(k); - //} - } - } - Yres(1,k_bath)=ONE-sum-Y(1,k_bath); - - /*Energy:*/ - if(data->dirichletInner){ - //Tres(1)=Tdot(1); - //Tres(1)=T(1)-data->innerTemperature; + //Yres(1,k_drop)=Y(1,k_drop) - p_i * data->gas->molecularWeight(k_drop-1) + // / P(1) / data->gas->meanMolecularWeight(); + + + + + //Mdotres(1)=Mdot(1) - (YVmhalf(k_drop)*areamhalf) / (1-Y(1,k_drop)); //Evaporating mass + + + + /*Energy:*/ + if (data->dirichletInner) { + //Tres(1)=Tdot(1); + //Tres(1)=T(1)-data->innerTemperature; /*Following code should be revised in the future*/ - //Tres(1)=lambdamhalf*rhomhalf*areamhalfsq*(T(2)-T(1))/((psi(2)-psi(1))*mass)/dHv_l - YVmhalf(k_drop)*areamhalf/(1-Y(1,k_drop)); - }else{ - //Tres(1)=Tdot(1) - - // (rhomhalf*areamhalfsq*lambdamhalf*(T(2)-T(1))/((psi(2)-psi(1))*mass) - Mdot(1)*dHvl) - // / (massDrop * Cpl); - - //Tres(1)=Tdot(1) - - // (areamhalf*lambdamhalf*(T(2)-T(1))/(R(2)-R(1)) - Mdot(1)*dHvl) - // / (massDrop * Cpl); - - /**** Boundary Condition for Temperature @ 1st grid point, - * Temperature should not exceed boiling temperature of each liquid component *****/ - T_boil = getLiquidMaxT(data->dropMole,P(1)); - if(T(1) <= T_boil) - { - Tres(1)=Tdot(1) - - (areamhalf*lambdamhalf*(T(2)-T(1))/(R(2)-R(1)) - Mdot(1)*dHv_l) - / (massDrop * Cp_l); - }else{ - //Tres(1)=T(1)-T_boil; - Tres(1)=Tdot(1); - } - - //Tres(1)=T(2)-T(1); - //Tres(1)=Tdot(1) - (Pdot(1)/(rhom*Cpb)) - // +(double)(data->metric+1)*(rhomhalf*lambdamhalf*areamhalfsq*(T(2)-T(1))/psi(2)-psi(1)); - } - - /*Pressure:*/ - Pres(1)=P(2)-P(1); - /*Fill up res with governing equations at inner points:*************/ - for (j = 2; j < npts; j++) { - - /*evaluate various mesh differences*/// - dpsip = (psi(j+1) - psi(j) )*mass; - dpsim = (psi(j) - psi(j-1))*mass; - dpsiav = HALF*(psi(j+1) - psi(j-1))*mass; - dpsipm = (psi(j+1) - psi(j-1))*mass; - /***********************************/// - - /*evaluate various central difference coefficients*/ - cendfm = - dpsip / (dpsim*dpsipm); - cendfc = (dpsip-dpsim) / (dpsip*dpsim); - cendfp = dpsim / (dpsip*dpsipm); - /**************************************************/ - - - /*evaluate properties at j*************************/ - setGas(data,ydata,j); - rho=data->gas->density(); //kg/m^3 - Cpb=data->gas->cp_mass(); //J/kg/K - Cvb=data->gas->cv_mass(); //J/kg/K - data->gas->getNetProductionRates(wdot); //kmol/m^3 - data->gas->getEnthalpy_RT(enthalpy); //unitless - data->gas->getCp_R(Cp); //unitless - area = calc_area(R(j),&m); //m^2 - - /*evaluate properties at p*************************/ - getTransport(data, ydata, j, &rhophalf,&lambdaphalf,YVphalf); - areaphalf= calc_area(HALF*(R(j)+R(j+1)),&m); - areaphalfsq= areaphalf*areaphalf; - /**************************************************/// - - /*Evaporating Mass*/ - Mdotres(j)=Mdot(j) - Mdot(j-1); - - /*Mass:*/ - /* ∂r/∂ψ = 1/ρA */ - Rres(j)=((R(j)-R(j-1))/dpsim)-(TWO/(rhom*aream+rho*area)); - - /*Energy:*/ - /* ∂T/∂t = - ṁ(∂T/∂ψ) - * + (∂/∂ψ)(λρA²∂T/∂ψ) - * - (A/cₚ) ∑ YᵢVᵢcₚᵢ(∂T/∂ψ) - * - (1/ρcₚ)∑ ώᵢhᵢ + //Tres(1)=lambdamhalf*rhomhalf*areamhalfsq*(T(2)-T(1))/((psi(2)-psi(1))*mass)/dHv_l - YVmhalf(k_drop)*areamhalf/(1-Y(1,k_drop)); + } else { + //Tres(1)=Tdot(1) - + // (rhomhalf*areamhalfsq*lambdamhalf*(T(2)-T(1))/((psi(2)-psi(1))*mass) - Mdot(1)*dHvl) + // / (massDrop * Cpl); + + //Tres(1)=Tdot(1) - + // (areamhalf*lambdamhalf*(T(2)-T(1))/(R(2)-R(1)) - Mdot(1)*dHvl) + // / (massDrop * Cpl); + + /**** Boundary Condition for Temperature @ 1st grid point, + *** Temperature should not exceed boiling temperature of each liquid component *****/ +// T_boil = getLiquidMaxT(data->dropMole, P(1)); +// if (T(1) <= T_boil) { +// Tres(1) = Tdot(1) - +// (areamhalf * lambdamhalf * (T(2) - T(1)) / (R(2) - R(1)) - Mdot(1) * dHv_l) +// / (massDrop * Cp_l); +// } else { +// //Tres(1)=T(1)-T_boil; +// Tres(1) = Tdot(1); +// } + Tres(l_npts+1) = T(l_npts+1) - T(l_npts) ; + + //Tres(1)=T(2)-T(1); + //Tres(1)=Tdot(1) - (Pdot(1)/(rhom*Cpb)) + // +(double)(data->metric+1)*(rhomhalf*lambdamhalf*areamhalfsq*(T(2)-T(1))/psi(2)-psi(1)); + } + + /*Pressure:*/ + Pres(l_npts+1) = P(l_npts+2) - P(l_npts+1); + /*Fill up res with governing equations at inner points:*************/ + for (size_t j = l_npts+2 ; j < npts; j++) { + + /*evaluate various mesh differences*/// +// dpsip = (psi(j + 1) - psi(j)) * mass; +// dpsim = (psi(j) - psi(j - 1)) * mass; +// dpsiav = HALF * (psi(j + 1) - psi(j - 1)) * mass; +// dpsipm = (psi(j + 1) - psi(j - 1)) * mass; + dpsip = (psi(j + 1) - psi(j)) ; + dpsim = (psi(j) - psi(j - 1)) ; + dpsiav = HALF * (psi(j + 1) - psi(j - 1)) ; + dpsipm = (psi(j + 1) - psi(j - 1)) ; + /***********************************/// + + /*evaluate various central difference coefficients*/ + cendfm = -dpsip / (dpsim * dpsipm); + cendfc = (dpsip - dpsim) / (dpsip * dpsim); + cendfp = dpsim / (dpsip * dpsipm); + /**************************************************/ + + + /*evaluate properties at j*************************/ + setGas(data, ydata, j); + rho = data->gas->density(); //kg/m^3 + Cpb = data->gas->cp_mass(); //J/kg/K + Cvb = data->gas->cv_mass(); //J/kg/K + data->gas->getNetProductionRates(wdot); //kmol/m^3 + data->gas->getEnthalpy_RT(enthalpy); //unitless + data->gas->getCp_R(Cp); //unitless + area = calc_area(R(j), &m); //m^2 + + /*evaluate properties at p*************************/ + getTransport(data, ydata, j, &rhophalf, &lambdaphalf, YVphalf); + areaphalf = calc_area(HALF * (R(j) + R(j + 1)), &m); + areaphalfsq = areaphalf * areaphalf; + /**************************************************/// + + /*Evaporating Mass*/ + Mdotres(j) = Mdot(j) - Mdot(j - 1); + + /*Mass:*/ + /* ∂r/∂ψ = 1/ρA */ + Rres(j) = ((R(j) - R(j - 1)) / dpsim) - (TWO / (rhom * aream + rho * area)); + + /*Energy:*/ + /* ∂T/∂t = - ṁ(∂T/∂ψ) + * + (∂/∂ψ)(λρA²∂T/∂ψ) + * - (A/cₚ) ∑ YᵢVᵢcₚᵢ(∂T/∂ψ) + * - (1/ρcₚ)∑ ώᵢhᵢ * + (1/ρcₚ)(∂P/∂t) */ - /*Notes: + /*Notes: * λ has units J/m/s/K. * YᵢVᵢ has units kg/m^2/s. * hᵢ has units J/kmol, so we must multiply the enthalpy @@ -1328,266 +2255,261 @@ int residue(double t, N_Vector y, N_Vector ydot, N_Vector res, void *user_data){ * units. * */ - //enthalpy formulation: - //tranTerm = Tdot(j) - (Pdot(j)/(rho*Cpb)); - tranTerm = Tdot(j); - sum=ZERO; - sum1=ZERO; - for (k = 1; k <=nsp; k++) { - sum=sum+wdot(k)*enthalpy(k); - sum1=sum1+(Cp(k)/data->gas->molecularWeight(k-1))*rho - *HALF*(YVmhalf(k)+YVphalf(k)); - } - sum=sum*Cantera::GasConstant*T(j); - sum1=sum1*Cantera::GasConstant; - diffTerm =(( (rhophalf*areaphalfsq*lambdaphalf*(T(j+1)-T(j))/dpsip) - -(rhomhalf*areamhalfsq*lambdamhalf*(T(j)-T(j-1))/dpsim) ) - /(dpsiav*Cpb) ) - -(sum1*area*(cendfp*T(j+1) - +cendfc*T(j) - +cendfm*T(j-1))/Cpb); - srcTerm = (sum-Qdot(&t,&R(j),&data->ignTime,&data->kernelSize,&data->maxQDot))/(rho*Cpb); // Qdot is forced heating to cause ignition, sum is the conversion of chemical enthalpy to sensible enthalpy - advTerm = (Mdot(j)*(T(j)-T(j-1))/dpsim); - Tres(j)= tranTerm - (Pdot(j)/(rho*Cpb)) - +advTerm - -diffTerm - +srcTerm; - - // //energy formulation: - // tranTerm = Tdot(j); - // sum=ZERO; - // sum1=ZERO; - // sum2=ZERO; - // sum3=ZERO; - // for (k = 1; k <=nsp; k++) { - // energy(k)=enthalpy(k)-ONE; - // sum=sum+wdot(k)*energy(k); - // sum1=sum1+(Cp(k)/data->gas->molecularWeight(k-1))*rho - // *HALF*(YVmhalf(k)+YVphalf(k)); - // sum2=sum2+(YVmhalf(k)/data->gas->molecularWeight(k-1)); - // sum3=sum3+(YVphalf(k)/data->gas->molecularWeight(k-1)); - // } - // sum=sum*Cantera::GasConstant*T(j); - // sum1=sum1*Cantera::GasConstant; - // diffTerm =(( (rhophalf*areaphalfsq*lambdaphalf*(T(j+1)-T(j))/dpsip) - // -(rhomhalf*areamhalfsq*lambdamhalf*(T(j)-T(j-1))/dpsim) ) - // /(dpsiav*Cvb) ) - // -(sum1*area*(cendfp*T(j+1) - // +cendfc*T(j) - // +cendfm*T(j-1))/Cvb); - // srcTerm = (sum-Qdot(&t,&R(j),&data->ignTime,&data->kernelSize,&data->maxQDot))/(rho*Cvb); - // advTerm = (mdotIn*(T(j)-T(j-1))/dpsim); - // advTerm = advTerm + (Cantera::GasConstant*T(j)*area/Cvb)*((sum3-sum2)/dpsiav); - // Tres(j)= tranTerm - // +advTerm - // -diffTerm - // +srcTerm; - - /*Species:*/ - /* ∂Yᵢ/∂t = - ṁ(∂Yᵢ/∂ψ) - * - (∂/∂ψ)(AYᵢVᵢ) + //enthalpy formulation: + //tranTerm = Tdot(j) - (Pdot(j)/(rho*Cpb)); + tranTerm = Tdot(j); + sum = ZERO; + sum1 = ZERO; + for (size_t k = 1; k <= nsp; k++) { + sum = sum + wdot(k) * enthalpy(k); + sum1 = sum1 + (Cp(k) / data->gas->molecularWeight(k - 1)) * HALF * (YVmhalf(k) + YVphalf(k)); + } + sum = sum * Cantera::GasConstant * T(j); + sum1 = sum1 * Cantera::GasConstant; + diffTerm = (((rhophalf * areaphalfsq * lambdaphalf * (T(j + 1) - T(j)) / dpsip) + - (rhomhalf * areamhalfsq * lambdamhalf * (T(j) - T(j - 1)) / dpsim)) + / (dpsiav * Cpb)) + - (sum1 * area * (cendfp * T(j + 1) + + cendfc * T(j) + + cendfm * T(j - 1)) / Cpb); + srcTerm = (sum - Qdot(&t, &R(j), &data->ignTime, &data->kernelSize, &data->maxQDot)) / (rho * + Cpb); // Qdot is forced heating to cause ignition, sum is the conversion of chemical enthalpy to sensible enthalpy + advTerm = (Mdot(j) * (T(j) - T(j - 1)) / dpsim); + Tres(j) = tranTerm - (Pdot(j) / (rho * Cpb)) + + advTerm + - diffTerm + + srcTerm; + + // //energy formulation: + // tranTerm = Tdot(j); + // sum=ZERO; + // sum1=ZERO; + // sum2=ZERO; + // sum3=ZERO; + // for (k = 1; k <=nsp; k++) { + // energy(k)=enthalpy(k)-ONE; + // sum=sum+wdot(k)*energy(k); + // sum1=sum1+(Cp(k)/data->gas->molecularWeight(k-1))*rho + // *HALF*(YVmhalf(k)+YVphalf(k)); + // sum2=sum2+(YVmhalf(k)/data->gas->molecularWeight(k-1)); + // sum3=sum3+(YVphalf(k)/data->gas->molecularWeight(k-1)); + // } + // sum=sum*Cantera::GasConstant*T(j); + // sum1=sum1*Cantera::GasConstant; + // diffTerm =(( (rhophalf*areaphalfsq*lambdaphalf*(T(j+1)-T(j))/dpsip) + // -(rhomhalf*areamhalfsq*lambdamhalf*(T(j)-T(j-1))/dpsim) ) + // /(dpsiav*Cvb) ) + // -(sum1*area*(cendfp*T(j+1) + // +cendfc*T(j) + // +cendfm*T(j-1))/Cvb); + // srcTerm = (sum-Qdot(&t,&R(j),&data->ignTime,&data->kernelSize,&data->maxQDot))/(rho*Cvb); + // advTerm = (mdotIn*(T(j)-T(j-1))/dpsim); + // advTerm = advTerm + (Cantera::GasConstant*T(j)*area/Cvb)*((sum3-sum2)/dpsiav); + // Tres(j)= tranTerm + // +advTerm + // -diffTerm + // +srcTerm; + + /*Species:*/ + /* ∂Yᵢ/∂t = - ṁ(∂Yᵢ/∂ψ) + * - (∂/∂ψ)(AYᵢVᵢ) * + (ώᵢWᵢ/ρ) */ - sum=ZERO; - for (k = 1; k <=nsp; k++) { - if(k!=k_bath){ - tranTerm = Ydot(j,k); - diffTerm = (YVphalf(k)*areaphalf - -YVmhalf(k)*areamhalf)/dpsiav; - srcTerm = wdot(k) - *(data->gas->molecularWeight(k-1))/rho; - advTerm = (Mdot(j)*(Y(j,k)-Y(j-1,k))/dpsim); - - Yres(j,k)= tranTerm - +advTerm - +diffTerm - -srcTerm; - - sum=sum+Y(j,k); - } - } - Yres(j,k_bath)=ONE-sum-Y(j,k_bath); - - /*Pressure:*/ - Pres(j) = P(j+1)-P(j); - - /*Assign values evaluated at p and phalf to m + sum = ZERO; + for (size_t k = 1; k <= nsp; k++) { + if (k != k_bath) { + tranTerm = Ydot(j, k); + diffTerm = (YVphalf(k) * areaphalf + - YVmhalf(k) * areamhalf) / dpsiav; + srcTerm = wdot(k) + * (data->gas->molecularWeight(k - 1)) / rho; + advTerm = (Mdot(j) * (Y(j, k) - Y(j - 1, k)) / dpsim); + + Yres(j, k) = tranTerm + + advTerm + + diffTerm + - srcTerm; + + sum = sum + Y(j, k); + } + } + Yres(j, k_bath) = ONE - sum - Y(j, k_bath); + + /*Pressure:*/ + Pres(j) = P(j + 1) - P(j); + + /*Assign values evaluated at p and phalf to m * and mhalf to save some cpu cost:****************/ - areamhalf=areaphalf; - areamhalfsq=areaphalfsq; - aream=area; - rhom=rho; - rhomhalf=rhophalf; - lambdamhalf=lambdaphalf; - for (k = 1; k <=nsp; k++) { - YVmhalf(k)=YVphalf(k); - } - /**************************************************/ - - } - /*******************************************************************/// - - - /*Fill up res with right side (wall) boundary conditions:***********/ - /*We impose zero fluxes at the wall:*/ - setGas(data,ydata,npts); - rho=data->gas->density(); - area = calc_area(R(npts),&m); - - /*Mass:*/ - dpsim=(psi(npts)-psi(npts-1))*mass; - Rres(npts)=((R(npts)-R(npts-1))/dpsim)-(TWO/(rhom*aream+rho*area)); - - /*Energy:*/ - if(data->dirichletOuter){ - //Tres(npts)=T(npts)-data->wallTemperature; - Tres(npts)=Tdot(npts); - } - else{ - Tres(npts)=T(npts)-T(npts-1); - } - - /*Species:*/ - sum=ZERO; - if(data->dirichletOuter){ - for (k = 1; k <=nsp; k++) { - if(k!=k_bath){ - Yres(npts,k)=Ydot(npts,k); - sum=sum+Y(npts,k); - } - } - } - else{ - for (k = 1; k <=nsp; k++) { - if(k!=k_bath){ - Yres(npts,k)=Y(npts,k)-Y(npts-1,k); - //Yres(npts,k)=YVmhalf(k); - sum=sum+Y(npts,k); - } - } - } - Yres(npts,k_bath)=ONE-sum-Y(npts,k_bath); - - - /*Pressure:*/ - if(data->constantPressure){ - Pres(npts)=Pdot(npts)-data->dPdt; - } - else{ - Pres(npts)=R(npts)-data->domainLength; - //Pres(npts)=Rdot(npts); - } - - /*Evaporating Mass*/ - Mdotres(npts)=Mdot(npts) - Mdot(npts-1); - - //for (j = 1; j <=npts; j++) { - // //for (k = 1; k <=nsp; k++) { - // // Yres(j,k)=Ydot(j,k); - // //} - // //Tres(j)=Tdot(j); - //} - - return(0); + areamhalf = areaphalf; + areamhalfsq = areaphalfsq; + aream = area; + rhom = rho; + rhomhalf = rhophalf; + lambdamhalf = lambdaphalf; + for (size_t k = 1; k <= nsp; k++) { + YVmhalf(k) = YVphalf(k); + } + /**************************************************/ + + } + /*******************************************************************/// + + + /*Fill up res with right side (wall) boundary conditions:***********/ + /*We impose zero fluxes at the wall:*/ + setGas(data, ydata, npts); + rho = data->gas->density(); + area = calc_area(R(npts), &m); + + /*Mass:*/ +// dpsim = (psi(npts) - psi(npts - 1)) * mass; + dpsim = (psi(npts) - psi(npts - 1)) ; + Rres(npts) = ((R(npts) - R(npts - 1)) / dpsim) - (TWO / (rhom * aream + rho * area)); + + /*Energy:*/ + if (data->dirichletOuter) { + //Tres(npts)=T(npts)-data->wallTemperature; + Tres(npts) = Tdot(npts); + } else { + Tres(npts) = T(npts) - T(npts - 1); + } + + /*Species:*/ + sum = ZERO; + if (data->dirichletOuter) { + for (size_t k = 1; k <= nsp; k++) { + if (k != k_bath) { + Yres(npts, k) = Ydot(npts, k); + sum = sum + Y(npts, k); + } + } + } else { + for (size_t k = 1; k <= nsp; k++) { + if (k != k_bath) { + Yres(npts, k) = Y(npts, k) - Y(npts - 1, k); + //Yres(npts,k)=YVmhalf(k); + sum = sum + Y(npts, k); + } + } + } + Yres(npts, k_bath) = ONE - sum - Y(npts, k_bath); + + + /*Pressure:*/ + if (data->constantPressure) { + Pres(npts) = Pdot(npts) - data->dPdt; + } else { + Pres(npts) = R(npts) - data->domainLength; + //Pres(npts)=Rdot(npts); + } + + /*Evaporating Mass*/ + Mdotres(npts) = Mdot(npts) - Mdot(npts - 1); + + //for (j = 1; j <=npts; j++) { + // //for (k = 1; k <=nsp; k++) { + // // Yres(j,k)=Ydot(j,k); + // //} + // //Tres(j)=Tdot(j); + //} + + return (0); } -void printSpaceTimeHeader(UserData data) -{ - fprintf((data->output), "%15s\t","#1"); - for (size_t k = 1; k <=data->nvar+1; k++) { - fprintf((data->output), "%15lu\t",k+1); - } - fprintf((data->output), "%15lu\n",data->nvar+3); - - fprintf((data->output), "%15s\t%15s\t%15s\t","#psi","time(s)","dpsi"); - fprintf((data->output), "%15s\t%15s\t","radius(m)","Temp(K)"); - for (size_t k = 1; k <=data->nsp; k++) { - fprintf((data->output), "%15s\t",data->gas->speciesName(k-1).c_str()); - } - fprintf((data->output), "%15s\t","Pressure(Pa)"); - fprintf((data->output), "%15s\n","Mdot (kg/s)"); +void printSpaceTimeHeader(UserData data) { + fprintf((data->output), "%15s\t", "#1"); + for (size_t k = 1; k <= data->nvar + 1; k++) { + fprintf((data->output), "%15lu\t", k + 1); + } + fprintf((data->output), "%15lu\n", data->nvar + 3); + + fprintf((data->output), "%15s\t%15s\t%15s\t", "#psi", "time(s)", "dpsi"); + fprintf((data->output), "%15s\t%15s\t", "radius(m)", "Temp(K)"); + for (size_t k = 1; k <= data->nsp; k++) { + fprintf((data->output), "%15s\t", data->gas->speciesName(k - 1).c_str()); + } + fprintf((data->output), "%15s\t", "Pressure(Pa)"); + fprintf((data->output), "%15s\n", "Mdot (kg/s)"); } -void printSpaceTimeOutput(double t, N_Vector* y, FILE* output, UserData data) -{ - double *ydata,*psidata; - ydata = N_VGetArrayPointer_OpenMP(*y); - - if(data->adaptiveGrid){ - psidata = data->grid->x; - }else{ - psidata = data->uniformGrid; - } - - for (size_t i = 0; i < data->npts; i++) { - fprintf(output, "%15.9e\t%15.9e\t",psi(i+1),t); - if(i==0){ - fprintf(output, "%15.9e\t",psi(2)-psi(1)); - } - else{ - fprintf(output, "%15.6e\t",psi(i+1)-psi(i)); - } - for (size_t j = 0; j < data->nvar; j++) { - if(j!=data->nvar-1){ - fprintf(output, "%15.9e\t",ydata[j+i*data->nvar]); - }else{ - fprintf(output, "%15.9e",ydata[j+i*data->nvar]); - } - } - fprintf(output, "\n"); - } - fprintf(output, "\n"); +void printSpaceTimeOutput(double t, N_Vector *y, FILE *output, UserData data) { + double *ydata, *psidata; + ydata = N_VGetArrayPointer_OpenMP(*y); + + if (data->adaptiveGrid) { + psidata = data->grid->x; + } else { + psidata = data->uniformGrid; + } + + for (size_t i = 0; i < data->npts; i++) { + fprintf(output, "%15.9e\t%15.9e\t", psi(i + 1), t); + if (i == 0) { + fprintf(output, "%15.9e\t", psi(2) - psi(1)); + } else { + fprintf(output, "%15.6e\t", psi(i + 1) - psi(i)); + } + for (size_t j = 0; j < data->nvar; j++) { + if (j != data->nvar - 1) { + fprintf(output, "%15.9e\t", ydata[j + i * data->nvar]); + } else { + fprintf(output, "%15.9e", ydata[j + i * data->nvar]); + } + } + fprintf(output, "\n"); + } + fprintf(output, "\n"); } -void writeRestart(double t, N_Vector* y, N_Vector* ydot, FILE* output, UserData data){ - double *ydata,*psidata, *ydotdata; - ydata = N_VGetArrayPointer_OpenMP(*y); - ydotdata = N_VGetArrayPointer_OpenMP(*ydot); - if(data->adaptiveGrid){ - psidata = data->grid->x; - }else{ - psidata = data->uniformGrid; - } - fwrite(&t, sizeof(t), 1, output); //write time - fwrite(psidata, data->npts*sizeof(psidata), 1, output); //write grid - fwrite(ydata, data->neq*sizeof(ydata), 1, output); //write solution - fwrite(ydotdata, data->neq*sizeof(ydotdata), 1, output); //write solutiondot +void writeRestart(double t, N_Vector *y, N_Vector *ydot, FILE *output, UserData data) { + double *ydata, *psidata, *ydotdata; + ydata = N_VGetArrayPointer_OpenMP(*y); + ydotdata = N_VGetArrayPointer_OpenMP(*ydot); + if (data->adaptiveGrid) { + psidata = data->grid->x; + } else { + psidata = data->uniformGrid; + } + fwrite(&t, sizeof(t), 1, output); //write time + fwrite(psidata, data->npts * sizeof(psidata), 1, output); //write grid + fwrite(ydata, data->neq * sizeof(ydata), 1, output); //write solution + fwrite(ydotdata, data->neq * sizeof(ydotdata), 1, output); //write solutiondot } -void readRestart(N_Vector* y, N_Vector* ydot, FILE* input, UserData data){ - double *ydata,*psidata, *ydotdata; - double t; - if(data->adaptiveGrid){ - psidata = data->grid->x; - }else{ - psidata = data->uniformGrid; - } - ydata = N_VGetArrayPointer_OpenMP(*y); - ydotdata = N_VGetArrayPointer_OpenMP(*ydot); - fread(&t, sizeof(t), 1, input); - data->tNow=t; - fread(psidata, data->npts*sizeof(psidata), 1, input); - fread(ydata, data->neq*sizeof(ydata), 1, input); - fread(ydotdata, data->neq*sizeof(ydotdata), 1, input); - if(data->adaptiveGrid){ - storeGrid(data->grid->x,data->grid->xOld,data->npts); - } +void readRestart(N_Vector *y, N_Vector *ydot, FILE *input, UserData data) { + double *ydata, *psidata, *ydotdata; + double t; + if (data->adaptiveGrid) { + psidata = data->grid->x; + } else { + psidata = data->uniformGrid; + } + ydata = N_VGetArrayPointer_OpenMP(*y); + ydotdata = N_VGetArrayPointer_OpenMP(*ydot); + fread(&t, sizeof(t), 1, input); + data->tNow = t; + fread(psidata, data->npts * sizeof(psidata), 1, input); + fread(ydata, data->neq * sizeof(ydata), 1, input); + fread(ydotdata, data->neq * sizeof(ydotdata), 1, input); + if (data->adaptiveGrid) { + storeGrid(data->grid->x, data->grid->xOld, data->npts); + } } -void printGlobalHeader(UserData data) -{ - fprintf((data->globalOutput), "%8s\t","#Time(s)"); - //fprintf((data->globalOutput), "%15s","S_u(exp*)(m/s)"); - fprintf((data->globalOutput), "%15s","bFlux(kg/m^2/s)"); - fprintf((data->globalOutput), "%16s"," IsothermPos(m)"); - fprintf((data->globalOutput), "%15s\t","Pressure(Pa)"); - fprintf((data->globalOutput), "%15s\t","Pdot(Pa/s)"); - fprintf((data->globalOutput), "%15s\t","gamma"); - fprintf((data->globalOutput), "%15s\t","S_u(m/s)"); - fprintf((data->globalOutput), "%15s\t","Tu(K)"); - fprintf((data->globalOutput), "\n"); +void printGlobalHeader(UserData data) { + fprintf((data->globalOutput), "%8s\t", "#Time(s)"); + //fprintf((data->globalOutput), "%15s","S_u(exp*)(m/s)"); + fprintf((data->globalOutput), "%15s", "bFlux(kg/m^2/s)"); + fprintf((data->globalOutput), "%16s", " IsothermPos(m)"); + fprintf((data->globalOutput), "%15s\t", "Pressure(Pa)"); + fprintf((data->globalOutput), "%15s\t", "Pdot(Pa/s)"); + fprintf((data->globalOutput), "%15s\t", "gamma"); + fprintf((data->globalOutput), "%15s\t", "S_u(m/s)"); + fprintf((data->globalOutput), "%15s\t", "Tu(K)"); + fprintf((data->globalOutput), "\n"); } + // //void printSpaceTimeRates(double t, N_Vector ydot, UserData data) //{ @@ -1604,144 +2526,141 @@ void printGlobalHeader(UserData data) // fprintf((data->ratesOutput), "\n\n"); //} // -void printGlobalVariables(double t, N_Vector* y, N_Vector* ydot, UserData data) -{ - double *ydata,*ydotdata, *innerMassFractionsData, *psidata; - innerMassFractionsData = data->innerMassFractions; - - if(data->adaptiveGrid){ - psidata = data->grid->x; - }else{ - psidata = data->uniformGrid; - } - - double TAvg, RAvg, YAvg, psiAvg; - ydata = N_VGetArrayPointer_OpenMP(*y); - ydotdata = N_VGetArrayPointer_OpenMP(*ydot); - TAvg=data->isotherm; - double sum=ZERO; - double dpsim,area,aream,drdt; - double Cpb,Cvb,gamma,rho,flameArea,Tu; - - - /*Find the isotherm chosen by the user*/ - size_t j=1; - size_t jj=1; - size_t jjj=1; - double wdot[data->nsp]; - double wdotMax=0.0e0; - double advTerm=0.0e0; - psiAvg=0.0e0; - if(T(data->npts)>T(1)){ - while (T(j)k_oxidizer-1]-Y(data->npts,data->k_oxidizer); - while (fabs((T(jj+1)-T(jj))/T(jj))>1e-08) { - jj=jj+1; - } - - setGas(data,ydata,jj); - Tu=T(jj); - rho=data->gas->density(); - Cpb=data->gas->cp_mass(); //J/kg/K - Cvb=data->gas->cv_mass(); //J/kg/K - gamma=Cpb/Cvb; - - } - else{ - while (T(j)>TAvg) { - j=j+1; - } - YAvg=innerMassFractionsData[data->k_oxidizer-1]-Y(1,data->k_oxidizer); - while (fabs((T(data->npts-jj-1)-T(data->npts-jj))/T(data->npts-jj))>1e-08) { - jj=jj+1; - } - - setGas(data,ydata,data->npts-jj); - Tu=T(data->npts-jj); - rho=data->gas->density(); - Cpb=data->gas->cp_mass(); //J/kg/K - Cvb=data->gas->cv_mass(); //J/kg/K - gamma=Cpb/Cvb; - } - if(T(j)nt, data->nvar, - //// data->grid->x, data->npts); - //nMax=maxGradIndex(ydata, data->nt, data->nvar, - // data->grid->x, data->npts); - //advTerm=(T(nMax)-T(nMax-1))/(data->mass*(psi(nMax)-psi(nMax-1))); - //aream=calc_area(R(nMax),&data->metric); - ////setGas(data,ydata,nMax); - ////rho=data->gas->density(); - //psiAvg=-Tdot(nMax)/(rho*aream*advTerm); - ////if(t>data->ignTime){ - //// for(size_t n=2;nnpts;n++){ - //// setGas(data,ydata,n); - //// data->gas->getNetProductionRates(wdot); //kmol/m^3 - //// advTerm=(T(n)-T(n-1))/(data->mass*(psi(n)-psi(n-1))); - //// if(fabs(wdot[data->k_oxidizer-1])>=wdotMax){ - //// aream=calc_area(R(n),&data->metric); - //// psiAvg=-Tdot(n)/(rho*aream*advTerm); - //// wdotMax=fabs(wdot[data->k_oxidizer-1]); - //// } - //// } - ////} - ////else{ - //// psiAvg=0.0e0; - ////} - - - //drdt=(RAvg-data->flamePosition[1])/(t-data->flameTime[1]); - //data->flamePosition[0]=data->flamePosition[1]; - //data->flamePosition[1]=RAvg; - //data->flameTime[0]=data->flameTime[1]; - //data->flameTime[1]=t; - //flameArea=calc_area(RAvg,&data->metric); - - /*Use the Trapezoidal rule to calculate the mass burning rate based on +void printGlobalVariables(double t, N_Vector *y, N_Vector *ydot, UserData data) { + double *ydata, *ydotdata, *innerMassFractionsData, *psidata; + innerMassFractionsData = data->innerMassFractions; + + if (data->adaptiveGrid) { + psidata = data->grid->x; + } else { + psidata = data->uniformGrid; + } + + double TAvg, RAvg, YAvg, psiAvg; + ydata = N_VGetArrayPointer_OpenMP(*y); + ydotdata = N_VGetArrayPointer_OpenMP(*ydot); + TAvg = data->isotherm; + double sum = ZERO; + double dpsim, area, aream, drdt; + double Cpb, Cvb, gamma, rho, flameArea, Tu; + + + /*Find the isotherm chosen by the user*/ + size_t j = 1; + size_t jj = 1; + size_t jjj = 1; + double wdot[data->nsp]; + double wdotMax = 0.0e0; + double advTerm = 0.0e0; + psiAvg = 0.0e0; + if (T(data->npts) > T(1)) { + while (T(j) < TAvg) { + j = j + 1; + } + YAvg = innerMassFractionsData[data->k_oxidizer - 1] - Y(data->npts, data->k_oxidizer); + while (fabs((T(jj + 1) - T(jj)) / T(jj)) > 1e-08) { + jj = jj + 1; + } + + setGas(data, ydata, jj); + Tu = T(jj); + rho = data->gas->density(); + Cpb = data->gas->cp_mass(); //J/kg/K + Cvb = data->gas->cv_mass(); //J/kg/K + gamma = Cpb / Cvb; + + } else { + while (T(j) > TAvg) { + j = j + 1; + } + YAvg = innerMassFractionsData[data->k_oxidizer - 1] - Y(1, data->k_oxidizer); + while (fabs((T(data->npts - jj - 1) - T(data->npts - jj)) / T(data->npts - jj)) > 1e-08) { + jj = jj + 1; + } + + setGas(data, ydata, data->npts - jj); + Tu = T(data->npts - jj); + rho = data->gas->density(); + Cpb = data->gas->cp_mass(); //J/kg/K + Cvb = data->gas->cv_mass(); //J/kg/K + gamma = Cpb / Cvb; + } + if (T(j) < TAvg) { + RAvg = ((R(j + 1) - R(j)) / (T(j + 1) - T(j))) * (TAvg - T(j)) + R(j); + } else { + RAvg = ((R(j) - R(j - 1)) / (T(j) - T(j - 1))) * (TAvg - T(j - 1)) + R(j - 1); + } + + ////Experimental burning speed calculation: + //int nMax=0; + ////nMax=maxCurvIndex(ydata, data->nt, data->nvar, + //// data->grid->x, data->npts); + //nMax=maxGradIndex(ydata, data->nt, data->nvar, + // data->grid->x, data->npts); + //advTerm=(T(nMax)-T(nMax-1))/(data->mass*(psi(nMax)-psi(nMax-1))); + //aream=calc_area(R(nMax),&data->metric); + ////setGas(data,ydata,nMax); + ////rho=data->gas->density(); + //psiAvg=-Tdot(nMax)/(rho*aream*advTerm); + ////if(t>data->ignTime){ + //// for(size_t n=2;nnpts;n++){ + //// setGas(data,ydata,n); + //// data->gas->getNetProductionRates(wdot); //kmol/m^3 + //// advTerm=(T(n)-T(n-1))/(data->mass*(psi(n)-psi(n-1))); + //// if(fabs(wdot[data->k_oxidizer-1])>=wdotMax){ + //// aream=calc_area(R(n),&data->metric); + //// psiAvg=-Tdot(n)/(rho*aream*advTerm); + //// wdotMax=fabs(wdot[data->k_oxidizer-1]); + //// } + //// } + ////} + ////else{ + //// psiAvg=0.0e0; + ////} + + + //drdt=(RAvg-data->flamePosition[1])/(t-data->flameTime[1]); + //data->flamePosition[0]=data->flamePosition[1]; + //data->flamePosition[1]=RAvg; + //data->flameTime[0]=data->flameTime[1]; + //data->flameTime[1]=t; + //flameArea=calc_area(RAvg,&data->metric); + + /*Use the Trapezoidal rule to calculate the mass burning rate based on * the consumption of O2*/ - aream= calc_area(R(1)+1e-03*data->domainLength,&data->metric); - for (j = 2; j npts; j++) { - dpsim=(psi(j)-psi(j-1))*data->mass; - area= calc_area(R(j),&data->metric); - sum=sum+HALF*dpsim*((Ydot(j-1,data->k_oxidizer)/aream) - +(Ydot(j,data->k_oxidizer)/area)); - aream=area; - } - - //double maxOH,maxHO2; - //maxOH=0.0e0; - //maxHO2=0.0e0; - //for(j=1;jnpts;j++){ - // if(Y(j,data->k_OH)>maxOH){ - // maxOH=Y(j,data->k_OH); - // } - //} - //for(j=1;jnpts;j++){ - // if(Y(j,data->k_HO2)>maxHO2){ - // maxHO2=Y(j,data->k_HO2); - // } - //} - - fprintf((data->globalOutput), "%15.6e\t",t); - //fprintf((data->globalOutput), "%15.6e\t",psiAvg); - fprintf((data->globalOutput), "%15.6e\t",fabs(sum)/YAvg); - fprintf((data->globalOutput), "%15.6e\t",RAvg); - fprintf((data->globalOutput), "%15.6e\t",P(data->npts)); - fprintf((data->globalOutput), "%15.6e\t",Pdot(data->npts)); - fprintf((data->globalOutput), "%15.6e\t",gamma); - fprintf((data->globalOutput), "%15.6e\t",fabs(sum)/(YAvg*rho)); - fprintf((data->globalOutput), "%15.6e\t",Tu); - fprintf((data->globalOutput), "\n"); + aream = calc_area(R(1) + 1e-03 * data->domainLength, &data->metric); + for (j = 2; j < data->npts; j++) { + dpsim = (psi(j) - psi(j - 1)) * data->mass; + area = calc_area(R(j), &data->metric); + sum = sum + HALF * dpsim * ((Ydot(j - 1, data->k_oxidizer) / aream) + + (Ydot(j, data->k_oxidizer) / area)); + aream = area; + } + + //double maxOH,maxHO2; + //maxOH=0.0e0; + //maxHO2=0.0e0; + //for(j=1;jnpts;j++){ + // if(Y(j,data->k_OH)>maxOH){ + // maxOH=Y(j,data->k_OH); + // } + //} + //for(j=1;jnpts;j++){ + // if(Y(j,data->k_HO2)>maxHO2){ + // maxHO2=Y(j,data->k_HO2); + // } + //} + + fprintf((data->globalOutput), "%15.6e\t", t); + //fprintf((data->globalOutput), "%15.6e\t",psiAvg); + fprintf((data->globalOutput), "%15.6e\t", fabs(sum) / YAvg); + fprintf((data->globalOutput), "%15.6e\t", RAvg); + fprintf((data->globalOutput), "%15.6e\t", P(data->npts)); + fprintf((data->globalOutput), "%15.6e\t", Pdot(data->npts)); + fprintf((data->globalOutput), "%15.6e\t", gamma); + fprintf((data->globalOutput), "%15.6e\t", fabs(sum) / (YAvg * rho)); + fprintf((data->globalOutput), "%15.6e\t", Tu); + fprintf((data->globalOutput), "\n"); } // @@ -1765,8 +2684,8 @@ void printGlobalVariables(double t, N_Vector* y, N_Vector* ydot, UserData data) //// int npts=data->npts; //// double *ydata; //// double *ydotdata; -//// ydata = N_VGetArrayPointer_OpenMP(y); -//// ydotdata = N_VGetArrayPointer_OpenMP(ydot); +//// ydata = N_VGetArrayPointer_OpenMP(y); +//// ydotdata = N_VGetArrayPointer_OpenMP(ydot); //// //// T(2)=T(1); //// T(npts-1)=T(npts); @@ -1783,147 +2702,143 @@ void printGlobalVariables(double t, N_Vector* y, N_Vector* ydot, UserData data) /*Following functions are added to derive the characteristic time scale of species*/ -void getTimescale(UserData data, N_Vector* y){ - size_t i, k, nsp,npts ; - nsp = data->nsp ; - npts = data->npts ; - double rho, wdot_mole[nsp], wdot_mass[nsp],MW[nsp],concentra[nsp]; - //double time_scale[npts*nsp] ; - - double* ydata ; - ydata = N_VGetArrayPointer_OpenMP(*y); //access the data stored in N_Vector* y - - for(i=1; i<= npts;i++){ - setGas(data,ydata,i); //set the gas state at each grid point - rho = data->gas->density(); //get the averaged density at each grid point, Unit:kg/m^3 - data->gas->getNetProductionRates(wdot_mole) ; //Unit:kmol/(m^3 * s) - - for(k=1; k<= nsp; k++){ - MW(k) = data->gas->molecularWeight(k-1) ; //Unit:kg/kmol - } - - for(k=1; k<= nsp; k++){ - wdot_mass(k) = wdot_mole(k) * MW(k) ; //Unit:kg/(m^3 * s) - } - - for(k=1; k<= nsp; k++){ - concentra(k) = Y(i,k) * rho ; //Unit:kg/m^3 - } - - for(k=1;k<= nsp;k++){ - data->time_scale(i,k) = concentra(k)/(wdot_mass(k)+ 1.00e-16) ; - } - - } +void getTimescale(UserData data, N_Vector *y) { + size_t i, k, nsp, npts; + nsp = data->nsp; + npts = data->npts; + double rho, wdot_mole[nsp], wdot_mass[nsp], MW[nsp], concentra[nsp]; + //double time_scale[npts*nsp] ; + + double *ydata; + ydata = N_VGetArrayPointer_OpenMP(*y); //access the data stored in N_Vector* y + + for (i = 1; i <= npts; i++) { + setGas(data, ydata, i); //set the gas state at each grid point + rho = data->gas->density(); //get the averaged density at each grid point, Unit:kg/m^3 + data->gas->getNetProductionRates(wdot_mole); //Unit:kmol/(m^3 * s) + + for (k = 1; k <= nsp; k++) { + MW(k) = data->gas->molecularWeight(k - 1); //Unit:kg/kmol + } + + for (k = 1; k <= nsp; k++) { + wdot_mass(k) = wdot_mole(k) * MW(k); //Unit:kg/(m^3 * s) + } + + for (k = 1; k <= nsp; k++) { + concentra(k) = Y(i, k) * rho; //Unit:kg/m^3 + } + + for (k = 1; k <= nsp; k++) { + data->time_scale(i, k) = concentra(k) / (wdot_mass(k) + 1.00e-16); + } + + } } -void printTimescaleHeader(UserData data) -{ - fprintf((data->timescaleOutput), "%15s\t","#1"); - for (size_t k = 1; k <=data->nsp+1; k++) { - fprintf((data->timescaleOutput), "%15lu\t",k+1); - } - fprintf((data->timescaleOutput), "%15lu\n",data->nsp+3); - - - fprintf((data->timescaleOutput), "%15s\t%15s\t%15s\t","#time","radius","Temp(K)"); - //fprintf((data->output), "%15s\t%15s\t","radius(m)","Temp(K)"); - for (size_t k = 1; k <=(data->nsp); k++) { - fprintf((data->timescaleOutput), "%15s\t",data->gas->speciesName(k-1).c_str()); - } - //fprintf((data->output), "%15s\t","Pressure(Pa)"); - //fprintf((data->timescaleOutput), "%15s\n",data->gas->speciesName(data->nsp-1).c_str()); - //fprintf((data->output), "%15s\n","Mdot (kg/s)"); - fprintf((data->timescaleOutput), "\n"); +void printTimescaleHeader(UserData data) { + fprintf((data->timescaleOutput), "%15s\t", "#1"); + for (size_t k = 1; k <= data->nsp + 1; k++) { + fprintf((data->timescaleOutput), "%15lu\t", k + 1); + } + fprintf((data->timescaleOutput), "%15lu\n", data->nsp + 3); + + + fprintf((data->timescaleOutput), "%15s\t%15s\t%15s\t", "#time", "radius", "Temp(K)"); + //fprintf((data->output), "%15s\t%15s\t","radius(m)","Temp(K)"); + for (size_t k = 1; k <= (data->nsp); k++) { + fprintf((data->timescaleOutput), "%15s\t", data->gas->speciesName(k - 1).c_str()); + } + //fprintf((data->output), "%15s\t","Pressure(Pa)"); + //fprintf((data->timescaleOutput), "%15s\n",data->gas->speciesName(data->nsp-1).c_str()); + //fprintf((data->output), "%15s\n","Mdot (kg/s)"); + fprintf((data->timescaleOutput), "\n"); } -void printTimescaleOutput(double t,N_Vector* y,FILE* output,UserData data) -{ - double* ydata; - ydata = N_VGetArrayPointer_OpenMP(*y); - - for(size_t i=1 ; i<= data->npts; i++){ - fprintf(output, "%15.9e\t%15.9e\t",t,R(i)); - fprintf(output, "%15.9e\t",T(i)); - - for(size_t k=1; k<=data->nsp;k++){ - fprintf(output, "%15.9e\t",data->time_scale(i,k)); - } - fprintf(output, "\n"); - } - fprintf(output, "\n"); +void printTimescaleOutput(double t, N_Vector *y, FILE *output, UserData data) { + double *ydata; + ydata = N_VGetArrayPointer_OpenMP(*y); + + for (size_t i = 1; i <= data->npts; i++) { + fprintf(output, "%15.9e\t%15.9e\t", t, R(i)); + fprintf(output, "%15.9e\t", T(i)); + + for (size_t k = 1; k <= data->nsp; k++) { + fprintf(output, "%15.9e\t", data->time_scale(i, k)); + } + fprintf(output, "\n"); + } + fprintf(output, "\n"); } -void floorSmallValue(UserData data, N_Vector* y) -{ - double* ydata; +void floorSmallValue(UserData data, N_Vector *y) { + double *ydata; ydata = N_VGetArrayPointer_OpenMP(*y); - //double sum = 0.00; + //double sum = 0.00; size_t k_bath = data->k_bath; - - /*Floor small values to zero*/ - for (size_t i = 1; i <=data->npts; i++) { - for (size_t k = 1; k <=data->nsp; k++) { - if(fabs(Y(i,k))<=data->massFractionTolerance){ - Y(i,k)=0.0e0; - } - } - } - + + /*Floor small values to zero*/ + for (size_t i = 1; i <= data->npts; i++) { + for (size_t k = 1; k <= data->nsp; k++) { + if (fabs(Y(i, k)) <= data->massFractionTolerance) { + Y(i, k) = 0.0e0; + } + } + } + /*Dump the error to the bath gas*/ - for (size_t i = 1; i <=data->npts; i++) { + for (size_t i = 1; i <= data->npts; i++) { double sum = 0.00; - for (size_t k = 1; k <=data->nsp; k++) { - if(k!=k_bath){ - sum = sum + Y(i,k); - } - } - Y(i,k_bath) = ONE-sum; - } - + for (size_t k = 1; k <= data->nsp; k++) { + if (k != k_bath) { + sum = sum + Y(i, k); + } + } + Y(i, k_bath) = ONE - sum; + } + } -void resetTolerance(UserData data, N_Vector* y,N_Vector* atolv) -{ - double* ydata; - realtype* atolvdata; +void resetTolerance(UserData data, N_Vector *y, N_Vector *atolv) { + double *ydata; + realtype *atolvdata; ydata = N_VGetArrayPointer_OpenMP(*y); atolvdata = N_VGetArrayPointer_OpenMP(*atolv); - double relTol,radTol,tempTol,presTol,massFracTol,bathGasTol,mdotTol; - double maxT=0.00, deltaT=400.0; - relTol = 1.0e-03 ; - radTol = 1.0e-05 ; - tempTol = 1.0e-03 ; - presTol = 1.0e-3 ; - massFracTol = 1.0e-06; - bathGasTol = 1.0e-05 ; - mdotTol = 1.0e-10 ; + double relTol, radTol, tempTol, presTol, massFracTol, bathGasTol, mdotTol; + double maxT = 0.00, deltaT = 400.0; + relTol = 1.0e-03; + radTol = 1.0e-05; + tempTol = 1.0e-03; + presTol = 1.0e-3; + massFracTol = 1.0e-06; + bathGasTol = 1.0e-05; + mdotTol = 1.0e-10; /*Get the maximum Temperature*/ - for (size_t i =1;i <= data->npts;i++){ - if(T(i) > maxT){ + for (size_t i = 1; i <= data->npts; i++) { + if (T(i) > maxT) { maxT = T(i); } } /*reset the tolerance when maxT > initialTemperature +deltaT*/ - if(maxT >= (data->initialTemperature + deltaT)){ + if (maxT >= (data->initialTemperature + deltaT)) { data->relativeTolerance = relTol; - for(size_t i =1; i<=data->npts; i++){ - atolT(i) = tempTol; - atolR(i) = radTol ; - atolP(i) = presTol ; - atolMdot(i) = mdotTol ; - - for(size_t k =1; k<= data->nsp; k++){ - if(k!=data->k_bath){ - atolY(i,k) = massFracTol; - }else{ - atolY(i,k) = bathGasTol; + for (size_t i = 1; i <= data->npts; i++) { + atolT(i) = tempTol; + atolR(i) = radTol; + atolP(i) = presTol; + atolMdot(i) = mdotTol; + + for (size_t k = 1; k <= data->nsp; k++) { + if (k != data->k_bath) { + atolY(i, k) = massFracTol; + } else { + atolY(i, k) = bathGasTol; } } } @@ -1931,145 +2846,444 @@ void resetTolerance(UserData data, N_Vector* y,N_Vector* atolv) } -void getReactions(UserData data,N_Vector* y,FILE* output){ +void getReactions(UserData data, N_Vector *y, FILE *output) { double Tmax; - double* ydata; + double *ydata; //double deltaT = 400.0; //int i = 0; size_t nRxns; int index; nRxns = data->gas->nReactions(); //DEBUG - printf("Total Number of Rxns:%zu \n",nRxns); - double fwdROP[nRxns],revROP[nRxns],netROP[nRxns]; - std::string* rxnArr = new std::string[nRxns]; + printf("Total Number of Rxns:%zu \n", nRxns); + double fwdROP[nRxns], revROP[nRxns], netROP[nRxns]; + std::string *rxnArr = new std::string[nRxns]; ydata = N_VGetArrayPointer_OpenMP(*y); - Tmax = maxTemperature(ydata,data->nt,data->nvar,data->npts); + Tmax = maxTemperature(ydata, data->nt, data->nvar, data->npts); //get the rxns' equation array - for(size_t ii=0;iigas->reactionString(ii); + for (size_t ii = 0; ii < nRxns; ii++) { + rxnArr[ii] = data->gas->reactionString(ii); } printf("Printing Rxns Rate Of Progress Data......\n"); - if(Tmax >= (data->initialTemperature+data->deltaT)){ - index = maxTemperatureIndex(ydata,data->nt,data->nvar,data->npts); - setGas(data,ydata,index); + if (Tmax >= (data->initialTemperature + data->deltaT)) { + index = maxTemperatureIndex(ydata, data->nt, data->nvar, data->npts); + setGas(data, ydata, index); /*Get forward/reverse/net rate of progress of rxns*/ data->gas->getRevRatesOfProgress(revROP); data->gas->getFwdRatesOfProgress(fwdROP); data->gas->getNetRatesOfProgress(netROP); - for(size_t j=0 ; jnsp],revROP[data->nsp],netROP[data->nsp]; - std::string* spArr = new std::string[data->nsp]; + double fwdROP[data->nsp], revROP[data->nsp], netROP[data->nsp]; + std::string *spArr = new std::string[data->nsp]; ydata = N_VGetArrayPointer_OpenMP(*y); - Tmax = maxTemperature(ydata,data->nt,data->nvar,data->npts); + Tmax = maxTemperature(ydata, data->nt, data->nvar, data->npts); //get the species name array - for(size_t ii=0;iinsp;ii++){ - spArr[ii]= data->gas->speciesName(ii); + for (size_t ii = 0; ii < data->nsp; ii++) { + spArr[ii] = data->gas->speciesName(ii); } printf("Printing Species Rate of Production/Destruction Data......\n"); - if(Tmax>=(data->initialTemperature+data->deltaT)){ - index = maxTemperatureIndex(ydata,data->nt,data->nvar,data->npts); - setGas(data,ydata,index); + if (Tmax >= (data->initialTemperature + data->deltaT)) { + index = maxTemperatureIndex(ydata, data->nt, data->nvar, data->npts); + setGas(data, ydata, index); /*Get forward/reverse/net rate of progress of rxns*/ data->gas->getDestructionRates(revROP); data->gas->getCreationRates(fwdROP); data->gas->getNetProductionRates(netROP); /*Print data to the pertinent output file*/ - for(size_t j=0 ; jnsp; j++){ - fprintf(output,"%15s\t",spArr[j].c_str()); - fprintf(output,"%15.9e\t%15.9e\t%15.9e\t\n",fwdROP[j],revROP[j],netROP[j]); - } - fprintf(output, "\n"); + for (size_t j = 0; j < data->nsp; j++) { + fprintf(output, "%15s\t", spArr[j].c_str()); + fprintf(output, "%15.9e\t%15.9e\t%15.9e\t\n", fwdROP[j], revROP[j], netROP[j]); + } + fprintf(output, "\n"); fclose(output); } delete[] spArr; } -//rho : density of liquid phase -double getLiquidRho(double dropMole[],double temp,double pres){ - std::vector fluids; - fluids.push_back("Propane"); - fluids.push_back("n-Heptane"); - - std::vector Temperature(1,temp),Pressure(1,pres); - std::vector outputs; - outputs.push_back("D"); - - std::vector moles; - moles.push_back(dropMole[0]); - moles.push_back(dropMole[1]); - double density = CoolProp::PropsSImulti(outputs,"T",Temperature,"P",Pressure,"",fluids,moles)[0][0]; //Unit:kg/m^3 - - return density; + +// +////rho : density of liquid phase +//double getLiquidRho(double dropMole[],double temp,double pres){ +// std::vector fluids; +// fluids.push_back("Propane"); +// fluids.push_back("n-Heptane"); +// +// std::vector Temperature(1,temp),Pressure(1,pres); +// std::vector outputs; +// outputs.push_back("D"); +// +// std::vector moles; +// moles.push_back(dropMole[0]); +// moles.push_back(dropMole[1]); +// double density = CoolProp::PropsSImulti(outputs,"T",Temperature,"P",Pressure,"",fluids,moles)[0][0]; //Unit:kg/m^3 +// +// return density; +//} + +////Cp,l : specific heat capacity at constant pressure of liquid phase +//double getLiquidCp(double dropMole[],double temp,double pres){ +// std::vector fluids; +// fluids.push_back("Propane"); +// fluids.push_back("n-Heptane"); +// +// std::vector Temperature(1,temp),Pressure(1,pres); +// std::vector outputs; +// outputs.push_back("CPMASS"); +// +// std::vector moles; +// moles.push_back(dropMole[0]); +// moles.push_back(dropMole[1]); +// double cp = CoolProp::PropsSImulti(outputs,"T",Temperature,"P",Pressure,"",fluids,moles)[0][0]; //Unit:J/(kg*K) +// +// return cp; +//} + +////Hv : heat of vaporization of liquid phase at constant pressure +//double getLiquidHv(double dropMole[],double temp,double pres){ +// std::vector fluids; +// fluids.push_back("Propane"); +// fluids.push_back("n-Heptane"); +// +// std::vector Temperature(1,temp),Pressure(1,pres); +// std::vector outputs; +// outputs.push_back("H"); +// +// std::vector moles; +// moles.push_back(dropMole[0]); +// moles.push_back(dropMole[1]); +// +// std::vector state1(1,1.0); +// std::vector state2(1,0.0); +// +// double H_V = CoolProp::PropsSImulti(outputs,"P",Pressure,"Q",state1,"",fluids,moles)[0][0]; //Unit:J/kg +// double H_L = CoolProp::PropsSImulti(outputs,"P",Pressure,"Q",state2,"",fluids,moles)[0][0]; //Unit:J/kg +// double delta_H = H_V - H_L; +// +// return delta_H; +//} + +////MaxT : maximum allowed tempereture of liquid phase +////Also the boiling point of more volitile component +//double getLiquidMaxT(double dropMole[],double pres){ +// std::vector fluids; +// fluids.push_back("Propane"); +// //fluids.push_back("n-Heptane"); +// +// std::vector Pressure(1,pres); +// std::vector outputs; +// outputs.push_back("T"); +// +// double temperature = CoolProp::PropsSI(outputs[0], "P", Pressure[0],"Q",1.0,fluids[0]); +// +// return temperature; +//} + +/*function overloading for single and bi-component*/ +/*calculate the liquid phase density based on droplet type and T,P,X(Y)*/ +/*single component case*/ +double getLiquidDensity(const double temp, const double pres, const std::vector &composition) { + std::vector Temperature(1, temp), Pressure(1, pres); + + double density = CoolProp::PropsSI("D", "T", Temperature[0], "P", Pressure[0], composition[0]); //Unit:kg/m^3 + return density; +} + +/*binary component case*/ +double getLiquidDensity(const double temp, const double pres, std::vector &composition, + const std::vector &mole) { + std::vector Temperature(1, temp), Pressure(1, pres); + std::vector outputs; + outputs.push_back("D"); + + double density = CoolProp::PropsSImulti(outputs, "T", Temperature, "P", Pressure, "", composition, + mole)[0][0]; //Unit:kg/m^3 + return density; +} + +double getLiquidCond(const double temp, const double pres, const std::vector &composition) { + std::vector Temperature(1, temp), Pressure(1, pres); + double k = CoolProp::PropsSI("conductivity", "T", Temperature[0], "P", Pressure[0], composition[0]); + return k; //Unit:W/m/K (kg*m/s^3/K) +} + +/*binary component case*/ +double getLiquidCond(const double temp, const double pres, std::vector &composition, + const std::vector &mole) { + std::vector Temperature(1, temp), Pressure(1, pres); + std::vector outputs; + outputs.push_back("conductivity"); + + double k = CoolProp::PropsSImulti(outputs, "T", Temperature, "P", Pressure, "", composition, + mole)[0][0]; + return k; //Unit:W/m/K (kg*m/s^3/K) +} + +/*Cpb:total liquid phase specific heat capacity at constant pressure*/ +double getLiquidCpb(const double temp,const double pres, const std::vector& composition){ + std::vector Temperature(1, temp), Pressure(1, pres); + double k = CoolProp::PropsSI("Cpmass", "T", Temperature[0], "P", Pressure[0], composition[0]); //Unit:kg/m^3 + return k; //unit:J/kg/K +} + +/*binary component case*/ +double getLiquidCpb(const double temp, const double pres, const std::vector &composition, + const std::vector &mole) { + std::vector Temperature(1, temp), Pressure(1, pres); + std::vector outputs; + outputs.push_back("Cpmass"); + + double k = CoolProp::PropsSImulti(outputs, "T", Temperature, "P", Pressure, "", composition, + mole)[0][0]; //Unit:kg/m^3 + return k; //unit:J/kg/K +} + +/*get Cp vector for binary componet droplet*/ +std::vector getLiquidCp(const double temp, const double pres, const std::vector &composition){ + std::vector k ; + double k_temp; + std::vector Temperature(1, temp), Pressure(1, pres); + for(auto & species : composition){ + k_temp = CoolProp::PropsSI("Cpmass", "T", Temperature[0], "P", Pressure[0], species); + k.push_back(k_temp) ; + } + return k; +} + + +/*get gas phase thermal conductivity*/ +double getGasCond(UserData data, double *ydata, size_t gridPoint) { + double k; + setGas(data, ydata, gridPoint); + k = data->trmix->thermalConductivity(); + return k; //unit:W/(m*K) +} + +/*latent heat of vaporizaiton*/ +/*unit: J/kg*/ +std::vector getLiquidVH(const double pres, const int dropType) { + double H, H_V, H_L; + std::vector vapheat; + std::vector fluids; + std::vector Pressure(1, pres); + + fluids = components(dropType); + + if (dropType == 0) { +// fluids.push_back("nHeptane"); + H_V = CoolProp::PropsSI("H", "P", Pressure[0], "Q", 1, fluids[0]); + H_L = CoolProp::PropsSI("H", "P", Pressure[0], "Q", 0, fluids[0]); + H = H_V - H_L; + vapheat.push_back(H); + } else { + for (size_t i = 0; i < fluids.size(); i++) { + H_V = CoolProp::PropsSI("H", "P", Pressure[0], "Q", 1, fluids[i]); + H_L = CoolProp::PropsSI("H", "P", Pressure[0], "Q", 0, fluids[i]); + H = H_V - H_L; + vapheat.push_back(H); + } + } + return vapheat; //unit:J/kg +} + +/*convert mass fraction to mole fraction*/ +/*size of both arrays should be identical*/ +void mass2mole(const std::vector &mass, std::vector &mole, UserData data) { + mole.reserve(mass.size()); + double sum = 0.0; + double x_temp; + for (size_t i = 0; i < data->dropMole.size(); i++) { + sum = sum + mass[i] / data->MW[i]; + } + + x_temp = mass[0] / (data->MW[0] * sum); + mole.push_back(x_temp); + mole.push_back(ONE - x_temp); } -//Cp,l : specific heat capacity at constant pressure of liquid phase -double getLiquidCp(double dropMole[],double temp,double pres){ - std::vector fluids; - fluids.push_back("Propane"); - fluids.push_back("n-Heptane"); - - std::vector Temperature(1,temp),Pressure(1,pres); - std::vector outputs; - outputs.push_back("CPMASS"); - - std::vector moles; - moles.push_back(dropMole[0]); - moles.push_back(dropMole[1]); - double cp = CoolProp::PropsSImulti(outputs,"T",Temperature,"P",Pressure,"",fluids,moles)[0][0]; //Unit:J/(kg*K) - - return cp; +/*liquid mass diffusivity D for binary component case*/ +double getLiquidmassdiff(UserData data, double *ydata, size_t gridPoint, const double temp) { + std::vector V_ = {75.86, 162.34}; //molar volume at normal boiling point, unit: cm^3/mol + std::vector visc_, mole_, mass_, D_inf_; + double visc_temp, D, Dinf_temp; + std::vector composition = components(data->dropType); + + for (size_t i = 0; i < data->dropMole.size(); i++) { + visc_temp = 1000.0 * CoolProp::PropsSI("V", "T", temp, "Q", 0, composition[i]); //unit: mPa*s + visc_.push_back(visc_temp); + } + mole_ = getLiquidmolevec(data, ydata, gridPoint); + + for (size_t i = 0; i < data->dropMole.size(); i++) { + if (i == 0) { + Dinf_temp = 9.89e-8 * temp * pow(visc_[1], -0.907) * pow(V_[0], -0.45) * pow(V_[1], 0.265); + D_inf_.push_back(Dinf_temp); + } else { + Dinf_temp = 9.89e-8 * temp * pow(visc_[0], -0.907) * pow(V_[1], -0.45) * pow(V_[0], 0.265); + D_inf_.push_back(Dinf_temp); + } + } + + D = mole_[1] * D_inf_[0] + mole_[0] * D_inf_[1]; //unit:cm^2/s + return (D / 10000); //unit:m^2/s } -//Hv : heat of vaporization of liquid phase at constant pressure -double getLiquidHv(double dropMole[],double temp,double pres){ - std::vector fluids; - fluids.push_back("Propane"); - fluids.push_back("n-Heptane"); - - std::vector Temperature(1,temp),Pressure(1,pres); - std::vector outputs; - outputs.push_back("H"); +//double dropletmass(UserData data,double* ydata){ +// double mass = 0.0 ; +// double rho,rhop; +// if (data->dropType==0){ +// for (size_t i = data->l_npts-1; i>=1 ; i--) { +// std::vector str; +// str.push_back("nHeptane"); +// rho = getLiquidDensity(T(i), P(i), str); +// rhop = getLiquidDensity(T(i + 1), P(i + 1), str); +// mass = mass + (R(i + 1) - R(i)) * (rho * calc_area(R(i), &data->metric) + +// rhop * calc_area(R(i + 1), &data->metric)) / TWO; +// } +// }else if(data->dropType==1){ +// for (size_t i = data->l_npts-1; i>=1 ; i--){ +// std::vector str; +// std::vector massFrac,massFracp,moleFrac,moleFracp; +// str.push_back("propane"); +// str.push_back("nHeptane"); +// for (size_t j = 0; j < data->dropMole.size(); j++){ +// massFrac.push_back(Y(i,data->k_drop[j])); +// massFracp.push_back(Y(i+1,data->k_drop[j])); +// } +// /*convert mass fraction to mole fraction*/ +// mass2mole(massFrac,moleFrac,data); +// mass2mole(massFracp,moleFracp,data); +// rho = getLiquidDensity(T(i),P(i),str,moleFrac); +// rhop = getLiquidDensity(T(i+1),P(i+1),str,moleFracp); +// mass = mass +(R(i+1)-R(i))*(rho*calc_area(R(i),&data->metric)+rhop*calc_area(R(i+1),&data->metric))/TWO; +// } +// } +// return mass ; +//} + + +// List of fluid components per dropType +std::vector components(int dropType) { + if (dropType == 0) { + return {"nHeptane"}; + } else if (dropType == 1) { + return {"propane", "nHeptane"}; + } + return {}; +} + +/*calculat droplet mass*/ +double dropletmass(UserData data, double *ydata) { + double mass = 0.0; + double rho, rhop; + + for (size_t i = data->l_npts - 1; i >= 1; i--) { + std::vector composition = components(data->dropType); + + if (data->dropType == 0) { + rho = getLiquidDensity(T(i), P(i), composition); + rhop = getLiquidDensity(T(i + 1), P(i + 1), composition); - std::vector moles; - moles.push_back(dropMole[0]); - moles.push_back(dropMole[1]); + } else if (data->dropType == 1) { + std::vector moleFrac, moleFracp; + moleFrac = getLiquidmolevec(data, ydata, i); + moleFracp = getLiquidmolevec(data, ydata, i); - std::vector state1(1,1.0); - std::vector state2(1,0.0); + rho = getLiquidDensity(T(i), P(i), composition, moleFrac); + rhop = getLiquidDensity(T(i + 1), P(i + 1), composition, moleFracp); + } - double H_V = CoolProp::PropsSImulti(outputs,"P",Pressure,"Q",state1,"",fluids,moles)[0][0]; //Unit:J/kg - double H_L = CoolProp::PropsSImulti(outputs,"P",Pressure,"Q",state2,"",fluids,moles)[0][0]; //Unit:J/kg - double delta_H = H_V - H_L; + double area = calc_area(R(i), &data->metric); + double areap = calc_area(R(i + 1), &data->metric); + mass += (R(i + 1) - R(i)) * (rho * area + rhop * areap) / TWO; + } + return mass; +} - return delta_H; +std::vector getLiquidmassvec(UserData data, double *ydata, int gridPoint) { + std::vector mass_; + mass_.push_back(Y(gridPoint, data->k_drop[0])); + mass_.push_back(Y(gridPoint, data->k_drop[1])); + return mass_; } -//MaxT : maximum allowed tempereture of liquid phase -//Also the boiling point of more volitile component -double getLiquidMaxT(double dropMole[],double pres){ - std::vector fluids; - fluids.push_back("Propane"); - //fluids.push_back("n-Heptane"); - - std::vector Pressure(1,pres); - std::vector outputs; - outputs.push_back("T"); - - double temperature = CoolProp::PropsSI(outputs[0], "P", Pressure[0],"Q",1.0,fluids[0]); - - return temperature; +std::vector getLiquidmolevec(UserData data, double *ydata, int gridPoint) { + std::vector mass_, mole_; + mass_ = getLiquidmassvec(data, ydata, gridPoint); + mass2mole(mass_, mole_, data); + return mole_; } +/*return droplet species vapor pressure at interface, unit:Pa*/ +std::vector getVapPressure(UserData data, double* ydata,int gridPoint,const std::vector mole_){ + std::vector vapPres; + vapPres.reserve(mole_.size()) ; + std::vector gamma_; + getGamma(mole_,gamma_) ; + //propane + double p1 = 1.0e5 * pow(10, 4.53678 - (1149.36 / (T(gridPoint) + 24.906))) * mole_[0] * + gamma_[0]; + //heptane + double p2 = 1.0e5 * pow(10, 4.02832 - (1268.636 / (T(gridPoint) - 56.199))) * mole_[1] * + gamma_[1]; + vapPres.push_back(p1); + vapPres.push_back(p2); + return vapPres; +} + +void printIddata(UserData data, double *iddata) { + FILE *file; + file = fopen("id.dat", "w"); + fprintf(file, "%15s\t%15s\t", "Rid", "Tid"); + for (size_t k = 1; k <= data->nsp; k++) { + fprintf(file, "%15s\t", data->gas->speciesName(k - 1).c_str()); + } + fprintf(file, "%15s\t", "Pid"); + fprintf(file, "%15s\n", "Mdotid"); + + for (size_t i = 1; i <= data->npts; i++) { + fprintf(file, "%15lu\t", (size_t) Rid(i)); + fprintf(file, "%15lu\t", (size_t) Tid(i)); + for (size_t k = 1; k <= data->nsp; k++) { + fprintf(file, "%15lu\t", (size_t) Yid(i, k)); + } + fprintf(file, "%15lu\t", (size_t) Pid(i)); + fprintf(file, "%15lu\n", (size_t) Mdotid(i)); + } + + fclose(file); +} + +void printPsidata(UserData data, double* psidata) { + FILE *file; + file = fopen("psi.dat", "w"); +// fprintf(file, "%15s\t%15s\t", "Rid", "Tid"); + for (size_t j = 1; j <= data->npts; j++) { + fprintf(file, "%lu\t", j); + } + fprintf(file, "\n"); + + for (size_t j = 1; j <= data->npts; j++) { +// fprintf(file, "%15lu\t", (size_t) Rid(i)); +// fprintf(file, "%15lu\t", (size_t) Tid(i)); +// for (size_t k = 1; k <= data->nsp; k++) { +// fprintf(file, "%15lu\t", (size_t) Yid(i, k)); +// } +// fprintf(file, "%15lu\t", (size_t) Pid(i)); +// fprintf(file, "%15lu\n", (size_t) Mdotid(i)); + fprintf(file,"%15.6e\t", psi(j)); + } + fprintf(file, "\n"); + fclose(file); +} \ No newline at end of file diff --git a/timing.h b/timing.h deleted file mode 100644 index b65b3d3..0000000 --- a/timing.h +++ /dev/null @@ -1,2 +0,0 @@ -double get_wall_time(); -double get_cpu_time(); diff --git a/timing.hpp b/timing.hpp deleted file mode 100644 index e07e3eb..0000000 --- a/timing.hpp +++ /dev/null @@ -1,45 +0,0 @@ -// Windows -#ifdef _WIN32 -#include -double get_wall_time(){ - LARGE_INTEGER time,freq; - if (!QueryPerformanceFrequency(&freq)){ - // Handle error - return 0; - } - if (!QueryPerformanceCounter(&time)){ - // Handle error - return 0; - } - return (double)time.QuadPart / freq.QuadPart; -} -double get_cpu_time(){ - FILETIME a,b,c,d; - if (GetProcessTimes(GetCurrentProcess(),&a,&b,&c,&d) != 0){ - // Returns total user time. - // Can be tweaked to include kernel times as well. - return - (double)(d.dwLowDateTime | - ((unsigned long long)d.dwHighDateTime << 32)) * 0.0000001; - }else{ - // Handle error - return 0; - } -} - -// Posix/Linux -#else -#include -#include -double get_wall_time(){ - struct timeval time; - if (gettimeofday(&time,NULL)){ - // Handle error - return 0; - } - return (double)time.tv_sec + (double)time.tv_usec * .000001; -} -double get_cpu_time(){ - return (double)clock() / CLOCKS_PER_SEC; -} -#endif