Add the HRR related function and parameters into LTORC
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

411 lines
11KB

  1. #include "UserData.h"
  2. #include "parse.h"
  3. void freeUserData(UserData data){
  4. if(data!=NULL){
  5. if(data->trmix!=NULL){
  6. delete data->trmix;
  7. printf("Transport Deleted!\n");
  8. }
  9. if(data->gas!=NULL){
  10. delete data->gas;
  11. printf("Gas Deleted!\n");
  12. }
  13. if(data->adaptiveGrid){
  14. if(data->grid->xOld!=NULL){
  15. delete[] data->grid->xOld;
  16. printf("old grid array Deleted!\n");
  17. }
  18. if(data->grid->x!=NULL){
  19. delete[] data->grid->x;
  20. printf("current grid array Deleted!\n");
  21. }
  22. if(data->grid!=NULL){
  23. free(data->grid);
  24. printf("grid object Freed!\n");
  25. }
  26. }
  27. else{
  28. if(data->uniformGrid!=NULL){
  29. delete[] data->uniformGrid;
  30. printf("uniformGrid deleted!\n");
  31. }
  32. }
  33. if(data->innerMassFractions!=NULL){
  34. delete[] data->innerMassFractions;
  35. printf("innerMassFractions array Deleted!\n");
  36. }
  37. if(data->output!=NULL){
  38. fclose(data->output);
  39. printf("Output File Cleared from Memory!\n");
  40. }
  41. if(data->gridOutput!=NULL){
  42. fclose(data->gridOutput);
  43. printf("Grid Output File Cleared from Memory!\n");
  44. }
  45. //if(data->ratesOutput!=NULL){
  46. // fclose(data->ratesOutput);
  47. // printf("Rates Output File Cleared from Memory!\n");
  48. //}
  49. if(data->globalOutput!=NULL){
  50. fclose(data->globalOutput);
  51. printf("Global Output File Cleared from Memory!\n");
  52. }
  53. }
  54. free(data); /* Free the user data */
  55. printf("\n\n");
  56. }
  57. UserData allocateUserData(FILE *input){
  58. UserData data;
  59. data = (UserData) malloc(sizeof *data);
  60. if(!data){
  61. printf("Allocation Failed!\n");
  62. return(NULL);
  63. }
  64. setSaneDefaults(data);
  65. int ier;
  66. ier=parseNumber<size_t>(input, "basePts" , MAXBUFLEN, &data->npts);
  67. if(ier==-1 || data->npts<=0){
  68. printf("Enter non-zero basePts!\n");
  69. return(NULL);
  70. }
  71. ier=parseNumber<double>(input, "domainLength", MAXBUFLEN, &data->domainLength);
  72. if(ier==-1 || data->domainLength<=0.0e0){
  73. printf("domainLength error!\n");
  74. return(NULL);
  75. }
  76. ier=parseNumber<int>(input, "constantPressure" , MAXBUFLEN, &data->constantPressure);
  77. if(ier==-1 || (data->constantPressure!=0 && data->constantPressure!=1)){
  78. printf("constantPressure error!\n");
  79. return(NULL);
  80. }
  81. ier=parseNumber<int>(input, "problemType" , MAXBUFLEN, &data->problemType);
  82. if(ier==-1 || (data->problemType!=0
  83. && data->problemType!=1
  84. && data->problemType!=2
  85. && data->problemType!=3)){
  86. printf("include valid problemType!\n");
  87. printf("0: premixed combustion with NO equilibrated ignition kernel\n");
  88. printf("1: premixed combustion WITH equilibrated ignition kernel\n");
  89. printf("2: arbitrary initial conditions\n");
  90. printf("3: Restart\n");
  91. return(NULL);
  92. }
  93. ier=parseNumber<double>(input, "dPdt" , MAXBUFLEN, &data->dPdt);
  94. ier=parseNumber<int> (input, "reflectProblem" , MAXBUFLEN, &data->reflectProblem);
  95. if(data->reflectProblem!=0 && data->reflectProblem!=1){
  96. printf("Invalid entry for reflectProblem! Can be only 1 or 0.\n");
  97. return(NULL);
  98. }
  99. ier=parseNumber<double>(input, "mdot" , MAXBUFLEN, &data->mdot);
  100. ier=parseNumber<double>(input, "initialTemperature", MAXBUFLEN,
  101. &data->initialTemperature);
  102. if(ier==-1 || data->initialTemperature<=0.0e0){
  103. printf("Enter positive initialTemperature in K!\n");
  104. return(NULL);
  105. }
  106. ier=parseNumber<double>(input, "initialPressure", MAXBUFLEN,
  107. &data->initialPressure);
  108. if(ier==-1 || data->initialTemperature<=0.0e0){
  109. printf("Enter positive initialPressure in atm!\n");
  110. return(NULL);
  111. }
  112. ier=parseNumber<int> (input, "metric" , MAXBUFLEN, &data->metric);
  113. if(data->metric!=0 && data->metric!=1 && data->metric!=2){
  114. printf("Invalid entry for metric!\n");
  115. printf("0: Cartesian\n");
  116. printf("1: Cylindrical\n");
  117. printf("2: Spherical\n");
  118. return(NULL);
  119. }
  120. ier=parseNumber<double>(input, "QDot", MAXBUFLEN, &data->maxQDot);
  121. if(ier==-1 && data->problemType==0){
  122. printf("Need to specify QDot for problemType 0!\n");
  123. return(NULL);
  124. }
  125. ier=parseNumber<double>(input, "kernelSize", MAXBUFLEN, &data->kernelSize);
  126. if(ier==-1 && data->problemType==0){
  127. printf("Need to specify kernelSize for problemType 0!\n");
  128. return(NULL);
  129. }
  130. ier=parseNumber<double>(input, "ignTime", MAXBUFLEN, &data->ignTime);
  131. if(ier==-1 && data->problemType==0){
  132. printf("Need to specify ignTime for problemType 0!\n");
  133. return(NULL);
  134. }
  135. ier=parseNumber<double>(input, "mixingWidth", MAXBUFLEN,
  136. &data->mixingWidth);
  137. if(ier==-1){
  138. printf("Need to specify mixingWidth!\n");
  139. return(NULL);
  140. }
  141. ier=parseNumber<double>(input, "shift", MAXBUFLEN, &data->shift);
  142. ier=parseNumber<double>(input, "firstRadius", MAXBUFLEN, &data->firstRadius);
  143. ier=parseNumber<double>(input, "wallTemperature", MAXBUFLEN, &data->wallTemperature);
  144. ier=parseNumber<int> (input, "dirichletInner" , MAXBUFLEN,
  145. &data->dirichletInner);
  146. if(data->dirichletInner!=0 && data->dirichletInner!=1){
  147. printf("dirichletInner can either be 0 or 1!\n");
  148. return(NULL);
  149. }
  150. ier=parseNumber<int> (input, "dirichletOuter" , MAXBUFLEN,
  151. &data->dirichletOuter);
  152. if(data->dirichletOuter!=0 && data->dirichletOuter!=1){
  153. printf("dirichletOuter can either be 0 or 1!\n");
  154. return(NULL);
  155. }
  156. ier=parseNumber<int> (input, "adaptiveGrid" , MAXBUFLEN,
  157. &data->adaptiveGrid);
  158. if(ier==-1 || (data->adaptiveGrid!=0 && data->adaptiveGrid!=1)){
  159. printf("specify adaptiveGrid as 0 or 1!\n");
  160. return(NULL);
  161. }
  162. ier=parseNumber<int> (input, "moveGrid" , MAXBUFLEN,
  163. &data->moveGrid);
  164. if(ier==-1 || (data->moveGrid!=0 && data->moveGrid!=1)){
  165. printf("specify moveGrid as 0 or 1!\n");
  166. return(NULL);
  167. }
  168. ier=parseNumber<double> (input, "isotherm" , MAXBUFLEN,
  169. &data->isotherm);
  170. if(ier==-1){
  171. printf("specify temperature of isotherm!\n");
  172. return(NULL);
  173. }
  174. ier=parseNumber<double>(input, "gridOffset", MAXBUFLEN, &data->gridOffset);
  175. ier=parseNumber<int> (input, "nSaves" , MAXBUFLEN, &data->nSaves);
  176. if(data->nSaves<0 ){
  177. printf("nSaves must be greater than 0!\n");
  178. return(NULL);
  179. }
  180. ier=parseNumber<int> (input, "writeRates" , MAXBUFLEN,
  181. &data->writeRates);
  182. if(data->writeRates!=0 && data->writeRates!=1){
  183. printf("writeRates must either be 0 or 1!\n");
  184. return(NULL);
  185. }
  186. ier=parseNumber<int> (input, "writeEveryRegrid", MAXBUFLEN,
  187. &data->writeEveryRegrid);
  188. if(data->writeEveryRegrid!=0 && data->writeEveryRegrid!=1){
  189. printf("writeEveryRegrid must either be 0 or 1!\n");
  190. return(NULL);
  191. }
  192. ier=parseNumber<double> (input, "writeDeltaT", MAXBUFLEN,
  193. &data->writeDeltaT);
  194. ier=parseNumber<int> (input, "setConstraints" , MAXBUFLEN,
  195. &data->setConstraints);
  196. if(data->setConstraints!=0 && data->setConstraints!=1){
  197. printf("setConstraints must either be 0 or 1!\n");
  198. return(NULL);
  199. }
  200. ier=parseNumber<int> (input, "suppressAlg" , MAXBUFLEN,
  201. &data->suppressAlg);
  202. if(data->setConstraints!=0 && data->suppressAlg!=1){
  203. printf("suppressAlg must either be 0 or 1!\n");
  204. return(NULL);
  205. }
  206. ier=parseNumber<int> (input, "dryRun" , MAXBUFLEN,
  207. &data->dryRun);
  208. if(data->dryRun!=0 && data->dryRun!=1){
  209. printf("dryRun must either be 0 or 1!\n");
  210. return(NULL);
  211. }
  212. ier=parseNumber<double> (input, "finalTime" , MAXBUFLEN,
  213. &data->finalTime);
  214. ier=parseNumber<double> (input, "relativeTolerance" , MAXBUFLEN,
  215. &data->relativeTolerance);
  216. ier=parseNumber<double> (input, "radiusTolerance" , MAXBUFLEN,
  217. &data->radiusTolerance);
  218. ier=parseNumber<double> (input, "temperatureTolerance", MAXBUFLEN,
  219. &data->temperatureTolerance);
  220. ier=parseNumber<double> (input, "pressureTolerance", MAXBUFLEN,
  221. &data->pressureTolerance);
  222. ier=parseNumber<double> (input, "massFractionTolerance", MAXBUFLEN,
  223. &data->massFractionTolerance);
  224. ier=parseNumber<double> (input, "bathGasTolerance", MAXBUFLEN,
  225. &data->bathGasTolerance);
  226. char chem[MAXBUFLEN],mix[MAXBUFLEN],tran[MAXBUFLEN];
  227. ier=parseNumber<char>(input, "chemistryFile" , MAXBUFLEN, chem);
  228. if(ier==-1){
  229. printf("Enter chemistryFile!\n");
  230. return(NULL);
  231. }else{
  232. try{
  233. data->gas = new Cantera::IdealGasMix(chem);
  234. data->nsp=data->gas->nSpecies(); //assign no: of species
  235. } catch (Cantera::CanteraError& err) {
  236. printf("Error:\n");
  237. printf("%s\n",err.what());
  238. return(NULL);
  239. }
  240. }
  241. ier=parseNumber<char>(input, "transportModel", MAXBUFLEN, tran);
  242. if(ier==-1){
  243. printf("Enter transportModel!\n");
  244. return(NULL);
  245. }else{
  246. try{
  247. data->trmix = Cantera::newTransportMgr(tran, data->gas);
  248. }catch (Cantera::CanteraError& err) {
  249. printf("Error:\n");
  250. printf("%s\n",err.what());
  251. return(NULL);
  252. }
  253. }
  254. ier=parseNumber<char>(input, "mixtureComposition", MAXBUFLEN, mix);
  255. if(ier==-1){
  256. printf("Enter mixtureComposition!\n");
  257. return(NULL);
  258. }else{
  259. if(data->gas!=NULL){
  260. try{
  261. data->gas->setState_TPX(data->initialTemperature,
  262. data->initialPressure*Cantera::OneAtm,
  263. mix);
  264. }catch (Cantera::CanteraError& err) {
  265. printf("Error:\n");
  266. printf("%s\n",err.what());
  267. return(NULL);
  268. }
  269. }
  270. }
  271. ier=parseNumber<int> (input, "nThreads" , MAXBUFLEN, &data->nThreads);
  272. if(data->nThreads<0 ){
  273. printf("nThreads must be greater than 0!\n");
  274. return(NULL);
  275. }
  276. data->nr=0;
  277. //data->np=data->nr+1;
  278. data->nt=data->nr+1;
  279. data->ny=data->nt+1;
  280. data->np=data->ny+data->nsp;
  281. data->nvar=data->nsp+3; //assign no: of variables (R,T,P,nsp species)
  282. if(!data->adaptiveGrid){
  283. data->uniformGrid = new double [data->npts];
  284. data->neq=data->nvar*data->npts;
  285. }
  286. else{
  287. data->grid=(UserGrid) malloc(sizeof *data->grid);
  288. ier=getGridSettings(input,data->grid);
  289. if(ier==-1)return(NULL);
  290. ier=initializeGrid(data->grid);
  291. if(ier==-1)return(NULL);
  292. ier=reGrid(data->grid, data->grid->position);
  293. if(ier==-1)return(NULL);
  294. data->npts=data->grid->nPts;
  295. data->neq=data->nvar*data->npts;
  296. }
  297. data->output=fopen("output.dat","w");
  298. data->globalOutput=fopen("globalOutput.dat","w");
  299. data->gridOutput=fopen("grid.dat","w");
  300. //data->ratesOutput=fopen("rates.dat","w");
  301. data->innerMassFractions = new double [data->nsp];
  302. data->HRRdata = new double [data->npts];
  303. return(data);
  304. }
  305. void setSaneDefaults(UserData data){
  306. data->domainLength=1.0e-02;
  307. data->constantPressure=1;
  308. data->problemType=1;
  309. data->dPdt=0.0e0;
  310. data->reflectProblem=0;
  311. data->mdot=0.0;
  312. data->initialTemperature=300.0;
  313. data->initialPressure=1.0;
  314. data->metric=0;
  315. data->ignTime=1e-09;
  316. data->maxQDot=0.0e0;
  317. data->maxTemperature=300.0e0;
  318. data->mixingWidth=1e-04;
  319. data->shift=3.0e-03;
  320. data->firstRadius=1e-04;
  321. data->wallTemperature=298.0e0;
  322. data->dirichletInner=0;
  323. data->dirichletOuter=0;
  324. data->adaptiveGrid=0;
  325. data->moveGrid=0;
  326. data->gridOffset=0.0e0;
  327. data->isotherm=1000.0;
  328. data->nSaves=30;
  329. data->writeRates=0;
  330. data->writeEveryRegrid=0;
  331. data->writeDeltaT=1e-04;
  332. data->relativeTolerance=1e-06;
  333. data->radiusTolerance=1e-08;
  334. data->temperatureTolerance=1e-06;
  335. data->pressureTolerance=1e-06;
  336. data->massFractionTolerance=1e-09;
  337. data->bathGasTolerance=1e-06;
  338. data->finalTime=1e-02;
  339. data->tNow=0.0e0;
  340. data->setConstraints=0;
  341. data->suppressAlg=1;
  342. data->regrid=0;
  343. data->gridDirection=1;
  344. data->dryRun=0;
  345. data->nThreads=1;
  346. data->flamePosition[0]=0.0e0;
  347. data->flamePosition[1]=0.0e0;
  348. data->flameTime[0]=0.0e0;
  349. data->flameTime[1]=0.0e0;
  350. data->nTimeSteps=0;
  351. }