| @@ -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) | |||
| @@ -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<size_t>(input, "basePts" , MAXBUFLEN, &data->npts); | |||
| if(ier==-1 || data->npts<=0){ | |||
| printf("Enter non-zero basePts!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<double>(input, "domainLength", MAXBUFLEN, &data->domainLength); | |||
| if(ier==-1 || data->domainLength<=0.0e0){ | |||
| printf("domainLength error!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<double>(input, "Rd", MAXBUFLEN, &data->Rd); | |||
| if(ier==-1 || data->Rd<=0.0e0){ | |||
| printf("Rd error!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<int>(input, "constantPressure" , MAXBUFLEN, &data->constantPressure); | |||
| if(ier==-1 || (data->constantPressure!=0 && data->constantPressure!=1)){ | |||
| printf("constantPressure error!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<int>(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<int>(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<double>(input, "dPdt" , MAXBUFLEN, &data->dPdt); | |||
| ier=parseNumber<double>(input, "Rg" , MAXBUFLEN, &data->Rg); | |||
| if(data->Rg < 0.0){ | |||
| printf("Rg must be greater than 0"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<int> (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<double>(input, "mdot" , MAXBUFLEN, &data->mdot); | |||
| ier=parseNumber<double>(input, "initialTemperature", MAXBUFLEN, | |||
| &data->initialTemperature); | |||
| if(ier==-1 || data->initialTemperature<=0.0e0){ | |||
| printf("Enter positive initialTemperature in K!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<double>(input, "initialPressure", MAXBUFLEN, | |||
| &data->initialPressure); | |||
| if(ier==-1 || data->initialTemperature<=0.0e0){ | |||
| printf("Enter positive initialPressure in atm!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<int> (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<double>(input, "QDot", MAXBUFLEN, &data->maxQDot); | |||
| if(ier==-1 && data->problemType==0){ | |||
| printf("Need to specify QDot for problemType 0!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<double>(input, "kernelSize", MAXBUFLEN, &data->kernelSize); | |||
| if(ier==-1 && data->problemType==0){ | |||
| printf("Need to specify kernelSize for problemType 0!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<double>(input, "ignTime", MAXBUFLEN, &data->ignTime); | |||
| if(ier==-1 && data->problemType==0){ | |||
| printf("Need to specify ignTime for problemType 0!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<double>(input, "mixingWidth", MAXBUFLEN, | |||
| &data->mixingWidth); | |||
| if(ier==-1){ | |||
| printf("Need to specify mixingWidth!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<double>(input, "shift", MAXBUFLEN, &data->shift); | |||
| ier=parseNumber<double>(input, "firstRadius", MAXBUFLEN, &data->firstRadius); | |||
| ier=parseNumber<double>(input, "wallTemperature", MAXBUFLEN, &data->wallTemperature); | |||
| ier=parseNumber<int> (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<int> (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<int> (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<int> (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<double> (input, "isotherm" , MAXBUFLEN, | |||
| &data->isotherm); | |||
| if(ier==-1){ | |||
| printf("specify temperature of isotherm!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<double>(input, "gridOffset", MAXBUFLEN, &data->gridOffset); | |||
| ier=parseNumber<int> (input, "nSaves" , MAXBUFLEN, &data->nSaves); | |||
| if(data->nSaves<0 ){ | |||
| printf("nSaves must be greater than 0!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<int> (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<int> (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<int> (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<int> (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<int> (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<double> (input, "finalTime" , MAXBUFLEN, | |||
| &data->finalTime); | |||
| ier=parseNumber<double> (input, "relativeTolerance" , MAXBUFLEN, | |||
| &data->relativeTolerance); | |||
| ier=parseNumber<double> (input, "radiusTolerance" , MAXBUFLEN, | |||
| &data->radiusTolerance); | |||
| ier=parseNumber<double> (input, "temperatureTolerance", MAXBUFLEN, | |||
| &data->temperatureTolerance); | |||
| ier=parseNumber<double> (input, "pressureTolerance", MAXBUFLEN, | |||
| &data->pressureTolerance); | |||
| ier=parseNumber<double> (input, "massFractionTolerance", MAXBUFLEN, | |||
| &data->massFractionTolerance); | |||
| ier=parseNumber<double> (input, "bathGasTolerance", MAXBUFLEN, | |||
| &data->bathGasTolerance); | |||
| ier=parseNumber<double> (input, "MdotTolerance", MAXBUFLEN, | |||
| &data->MdotTolerance); | |||
| char chem[MAXBUFLEN],mix[MAXBUFLEN],tran[MAXBUFLEN]; | |||
| ier=parseNumber<char>(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<char>(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<char>(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<char>(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<int> (input, "nThreads", MAXBUFLEN, &data->nThreads); | |||
| if(data->nThreads<0 ){ | |||
| printf("nThreads must be greater than 0!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<double>(input, "PCAD", MAXBUFLEN, &data->PCAD); | |||
| ier=parseNumber<double>(input,"RGTC", MAXBUFLEN, &data->RGTC); | |||
| ier=parseNumber<int>(input,"JJRG", MAXBUFLEN, &data->JJRG); | |||
| ier=parseNumber<double>(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; | |||
| } | |||
| @@ -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 | |||
| @@ -1,221 +0,0 @@ | |||
| #ifndef CANTERA_DEF | |||
| #define CANTERA_DEF | |||
| #include <cantera/IdealGasMix.h> | |||
| #include <cantera/transport.h> | |||
| #endif | |||
| #include "gridRoutines.h" | |||
| #include <string> | |||
| #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 | |||
| @@ -1,293 +0,0 @@ | |||
| #include "gridRoutines.h" | |||
| #include <stdio.h> | |||
| 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(c<w){ | |||
| return(w); | |||
| } | |||
| else if(c>1.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;i<nPts;i++){ | |||
| y[i]=x[i]; | |||
| } | |||
| } | |||
| int initializeGrid(UserGrid grid){ | |||
| grid->nPts=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<size_t>(input, "basePts" , MAXBUFLEN, &grid->basePts); | |||
| if(ier==-1)return(-1); | |||
| ier=parseNumber<double>(input, "gridDensitySlope", MAXBUFLEN, &grid->a); | |||
| if(ier==-1)return(-1); | |||
| ier=parseNumber<double>(input, "fineGridHalfWidth", MAXBUFLEN, &grid->w); | |||
| if(ier==-1)return(-1); | |||
| ier=parseNumber<double>(input, "gridRefinement", MAXBUFLEN, &grid->mag); | |||
| if(ier==-1)return(-1); | |||
| ier=parseNumber<double>(input, "leftRefineFactor", MAXBUFLEN, &grid->leftFac); | |||
| if(ier==-1)return(-1); | |||
| ier=parseNumber<double>(input, "rightRefineFactor", MAXBUFLEN, &grid->rightFac); | |||
| if(ier==-1)return(-1); | |||
| ier=parseNumber<int>(input, "refineLeft" , MAXBUFLEN, &grid->refineLeft); | |||
| if(ier==-1)return(-1); | |||
| ier=parseNumber<int>(input, "refineRight" , MAXBUFLEN, &grid->refineRight); | |||
| if(ier==-1)return(-1); | |||
| ier=parseNumber<double>(input, "position" , MAXBUFLEN, &grid->position); | |||
| if(ier==-1)return(-1); | |||
| return(0); | |||
| } | |||
| @@ -1 +0,0 @@ | |||
| gridRoutines.o: gridRoutines.cpp gridRoutines.h parse.h parse.hpp | |||
| @@ -1,89 +0,0 @@ | |||
| #include "parse.h" | |||
| #ifndef GSL_DEF | |||
| #define GSL_DEF | |||
| #include <gsl/gsl_math.h> | |||
| #include <gsl/gsl_spline.h> | |||
| #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 | |||
| @@ -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<double> gamma; | |||
| /* Droplet species composition, C3H8,n-C7H16,etc.*/ | |||
| std::vector<std::string> dropSpec; | |||
| /*droplet initial species mole fractions*/ | |||
| std::vector<double> dropMole; | |||
| //char dropSpec[2][10] = {"propane","n-heptane"}; | |||
| /*droplet species molecular weight*/ | |||
| std::vector<double> 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<size_t> 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<double>& mole,std::vector<double>& gamma) ; | |||
| @@ -1,3 +1,5 @@ | |||
| #pragma once | |||
| #ifndef PRINT_DEF | |||
| #define PRINT_DEF | |||
| #include <string.h> //for strings | |||
| @@ -12,7 +14,7 @@ | |||
| #include <vector> | |||
| #include <sstream> | |||
| #ifndef PARSE_DEF ``` | |||
| #ifndef PARSE_DEF | |||
| #define PARSE_DEF | |||
| #define MAXBUFLEN 200 | |||
| @@ -30,12 +32,101 @@ template<typename T> | |||
| 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<typename T> | |||
| //int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<T>& 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<typename T> | |||
| int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,int* dropType, std::vector<T>& dropPara); | |||
| /* Extract the droplet species and molefractions from input file using template */ | |||
| /* Generic template function */ | |||
| //template<typename T> | |||
| //int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<T>& 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<std::string>(FILE* input, const char* keyword, const size_t bufLen,int* dropType, std::vector<std::string>& dropPara); | |||
| // | |||
| ///* Specialization for string */ | |||
| //template<> | |||
| //int parseDropSpec<std::string>(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<std::string>& dropPara); | |||
| int parseDrop(FILE* input, const char* keyword,char dropSpec[][10],double dropMole[],const size_t bufLen); | |||
| @@ -1,3 +1,5 @@ | |||
| #pragma once | |||
| template<typename T> | |||
| 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<std::string>(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<std::string>& dropPara); | |||
| inline int parseDropSpec<std::string>(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<std::string>& 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); | |||
| } | |||
| @@ -28,6 +28,7 @@ | |||
| #include "UserData.h" | |||
| #include <vector> //add the vector module | |||
| #include <algorithm> | |||
| 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); | |||
| //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<std::string>& composition); | |||
| double getLiquidDensity(const double temp,const double pres, std::vector<std::string>& composition,const std::vector<double>& mole); | |||
| double getLiquidCond(const double temp,const double pres, const std::vector<std::string>& composition); | |||
| double getLiquidCond(const double temp,const double pres, std::vector<std::string>& composition,const std::vector<double>& mole); | |||
| double getLiquidCpb(const double temp,const double pres, const std::vector<std::string>& composition); | |||
| double getLiquidCpb(const double temp,const double pres, const std::vector<std::string>& composition,const std::vector<double>& mole); | |||
| std::vector<double> getLiquidCp(const double temp, const double pres, const std::vector<std::string> &composition); | |||
| double getGasCond(UserData data, double *ydata, size_t gridPoint); | |||
| std::vector<double> getLiquidVH(const double pres,const int dropType); | |||
| void mass2mole(const std::vector<double>& mass,std::vector<double>& mole, UserData data); | |||
| double getLiquidmassdiff(UserData data, double* ydata, size_t gridPoint,const double temp); | |||
| std::vector<double> getLiquidmassvec(UserData data,double* ydata,int gridPoint); | |||
| std::vector<double> getLiquidmolevec(UserData data,double* ydata,int gridPoint); | |||
| std::vector<std::string> components(int dropType); | |||
| std::vector<double> getVapPressure(UserData data, double* ydata,int gridPoint,const std::vector<double> mole_); | |||
| double dropletmass(UserData data,double* ydata); | |||
| void printIddata(UserData data, double* iddata); | |||
| void printPsidata(UserData data,double* psidata); | |||
| @@ -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; | |||
| } | |||
| @@ -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 | |||
| @@ -1,491 +0,0 @@ | |||
| /* | |||
| _____ ___ ____ ____ | |||
| |_ _/ _ \| _ \ / ___| | |||
| | || | | | |_) | | | |||
| | || |_| | _ <| |___ | |||
| |_| \___/|_| \_\\____| | |||
| */ | |||
| #include "UserData.h" | |||
| #include "solution.h" | |||
| #include "residue.h" | |||
| #include "macros.h" | |||
| #include "timing.h" | |||
| #include <ida/ida.h> | |||
| #include <ida/ida_direct.h> | |||
| #include <sunmatrix/sunmatrix_band.h> | |||
| #include <sunlinsol/sunlinsol_lapackband.h> | |||
| //#include <ida/ida_band.h> | |||
| 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); | |||
| } | |||
| @@ -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 | |||
| @@ -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); | |||
| } | |||
| @@ -1 +0,0 @@ | |||
| parse.o: parse.cpp parse.h parse.hpp | |||
| @@ -1,36 +0,0 @@ | |||
| #ifndef PRINT_DEF | |||
| #define PRINT_DEF | |||
| #include <string.h> //for strings | |||
| #include <stdio.h> //for printf,scanf | |||
| #include <stdlib.h> //for atoi, atof | |||
| #include <string> | |||
| #include <cstring> | |||
| #include <iostream> | |||
| #include <stdexcept> | |||
| #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<typename T> | |||
| int parseNumber(FILE* input, const char* keyword, const size_t bufLen, T* n); | |||
| template<typename T> | |||
| 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 | |||
| @@ -1,75 +0,0 @@ | |||
| template<typename T> | |||
| 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<typename T> | |||
| 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<arrLen){ | |||
| //y[j]=atof(ret); | |||
| getFromString(ret,&y[j]); | |||
| } | |||
| ret=strtok(NULL,","); | |||
| j++; | |||
| } | |||
| rewind(input); | |||
| if(j!=arrLen){ | |||
| printf("Check no: of values entered for %s\n",keyword); | |||
| printf("%lu values required!\n",arrLen); | |||
| return(-1); | |||
| } | |||
| else{ | |||
| return(0); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| rewind(input); | |||
| return(-1); | |||
| } | |||
| @@ -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 | |||
| @@ -1,116 +0,0 @@ | |||
| #ifndef SUNDIALS_DEF | |||
| #define SUNDIALS_DEF | |||
| #include <sundials/sundials_types.h> | |||
| #include <nvector/nvector_openmp.h> | |||
| #endif | |||
| #ifndef PRINT_DEF | |||
| #define PRINT_DEF | |||
| #include <string.h> //for strings | |||
| #include <string> | |||
| #include <cstring> | |||
| #include <stdio.h> //for printf,scanf | |||
| #include <stdlib.h> //for atoi, atof | |||
| #endif | |||
| #ifndef CANTERA_DEF | |||
| #define CANTERA_DEF | |||
| #include <cantera/IdealGasMix.h> | |||
| #include <cantera/transport.h> | |||
| #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); | |||
| @@ -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"); | |||
| } | |||
| @@ -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 | |||
| @@ -1,15 +0,0 @@ | |||
| #ifndef PRINT_DEF | |||
| #define PRINT_DEF | |||
| #include <string.h> //for strings | |||
| #include <stdio.h> //for printf,scanf | |||
| #include <stdlib.h> //for atoi, atof | |||
| #endif | |||
| #ifndef SUNDIALS_DEF | |||
| #define SUNDIALS_DEF | |||
| #include <sundials/sundials_types.h> | |||
| #include <nvector/nvector_openmp.h> | |||
| #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); | |||
| @@ -2,7 +2,18 @@ | |||
| #include "parse.h" | |||
| void freeUserData(UserData data){ | |||
| if(data!=NULL){ | |||
| /*destructor for C++ vector*/ | |||
| using Td = std::vector<double>; | |||
| using Ts = std::vector<std::string>; | |||
| using Tt = std::vector<size_t>; | |||
| 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<double>; | |||
| new(&(data->dropSpec)) std::vector<std::string>; | |||
| new(&(data->gamma)) std::vector<double>; | |||
| new(&(data->MW)) std::vector<double>; | |||
| new(&(data->k_drop)) std::vector<size_t>; | |||
| if(!data){ | |||
| printf("Allocation Failed!\n"); | |||
| @@ -83,9 +99,14 @@ UserData allocateUserData(FILE *input){ | |||
| int ier; | |||
| ier=parseNumber<size_t>(input, "basePts" , MAXBUFLEN, &data->npts); | |||
| if(ier==-1 || data->npts<=0){ | |||
| printf("Enter non-zero basePts!\n"); | |||
| ier=parseNumber<size_t>(input, "liquidBasePts" , MAXBUFLEN, &data->l_npts); | |||
| if(ier==-1 || data->l_npts<=0){ | |||
| printf("Enter non-zero liquidbasePts!\n"); | |||
| return(NULL); | |||
| } | |||
| ier=parseNumber<size_t>(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<int>(input,"dropType",MAXBUFLEN,&data->dropType); | |||
| ier=parseNumber<int>(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<double>(input,"dropletMole",MAXBUFLEN,&data->dropType,dropMole); | |||
| ier=parseDropSpec<double>(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<std::string>(input,"dropletComposition",MAXBUFLEN,&data->dropType,dropSpec); | |||
| ier=parseDropSpec<std::string>(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<int>(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<int>(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<double>(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<char>(input, "transportModel", MAXBUFLEN, tran); | |||
| if(ier==-1){ | |||
| printf("Enter transportModel!\n"); | |||
| @@ -371,7 +399,7 @@ UserData allocateUserData(FILE *input){ | |||
| } | |||
| } | |||
| } | |||
| //ier=parseNumber<char>(input, "dropletComposition", MAXBUFLEN, data->dropSpec); | |||
| //if(ier==-1){ | |||
| // printf("Enter composition of droplet!\n"); | |||
| @@ -390,43 +418,62 @@ UserData allocateUserData(FILE *input){ | |||
| ier=parseNumber<double>(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<double>(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<int>(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<double>(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<double> 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<v_.size(); i++){ | |||
| gamma[i] = gammaC_[i] ; | |||
| } | |||
| } | |||
| void getGamma(const std::vector<double>& mole,std::vector<double>& 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; i<v_.size() ; i++){ | |||
| v_[i] = q_[i] * x_[i] / sum_q; | |||
| ksi_[i] = r_[i] * x_[i] / sum_r ; | |||
| } | |||
| l_ = 5 * (r_ - q_) - (r_ - ones_) ; | |||
| sum_l = l_.dot(x_) ; | |||
| /* calculate the gamma_c */ | |||
| for(size_t i=0; i<v_.size() ; i++){ | |||
| gammaC_[i] =std::exp( std::log(ksi_[i]/x_[i]) + 5*q_[i]*std::log(v_[i]/ksi_[i]) + l_[i] - ksi_[i]/x_[i]*sum_l ); | |||
| } | |||
| /******* gamma_R for both propane and n-heptane are 0 **********/ | |||
| /* return the gamma */ | |||
| for(size_t i=0; i<v_.size(); i++){ | |||
| gamma.push_back(gammaC_[i]); | |||
| } | |||
| } | |||
| } | |||
| @@ -33,11 +33,10 @@ void freeAtLast(void* mem, N_Vector *y, | |||
| 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); | |||
| FILE *input =fopen("input.dat","r"); | |||
| UserData data=allocateUserData(input); | |||
| fclose(input); | |||
| data->clockStart=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); | |||
| @@ -85,46 +85,48 @@ int parseDrop(FILE* input, const char* keyword,char dropSpec[][10],double dropMo | |||
| return(-1); | |||
| } | |||
| /* Specialization for string */ | |||
| template<> | |||
| int parseDropSpec<std::string>(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<std::string>& 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); | |||
| } | |||
| ///* Specialization for string */ | |||
| //template<> | |||
| //int parseDropSpec<std::string>(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<std::string>& 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); | |||
| //} | |||
| @@ -1,2 +0,0 @@ | |||
| double get_wall_time(); | |||
| double get_cpu_time(); | |||
| @@ -1,45 +0,0 @@ | |||
| // Windows | |||
| #ifdef _WIN32 | |||
| #include <Windows.h> | |||
| 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 <time.h> | |||
| #include <sys/time.h> | |||
| 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 | |||