|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- #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");
- }
-
- }
- 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<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<double>(input, "dPdt" , MAXBUFLEN, &data->dPdt);
-
- 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<double> (input, "writeDeltaT", MAXBUFLEN,
- &data->writeDeltaT);
-
- 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->setConstraints!=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);
-
- 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<int> (input, "nThreads" , MAXBUFLEN, &data->nThreads);
- if(data->nThreads<0 ){
- printf("nThreads must be greater than 0!\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->nvar=data->nsp+3; //assign no: of variables (R,T,P,nsp species)
-
- 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);
-
- 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->ratesOutput=fopen("rates.dat","w");
-
- data->innerMassFractions = new double [data->nsp];
- data->HRRdata = new double [data->npts];
- return(data);
- }
-
- void setSaneDefaults(UserData data){
- data->domainLength=1.0e-02;
- data->constantPressure=1;
- data->problemType=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->isotherm=1000.0;
- data->nSaves=30;
- data->writeRates=0;
- data->writeEveryRegrid=0;
- data->writeDeltaT=1e-04;
- 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;
- }
-
|