No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

453 líneas
12KB

  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. if(data->timescaleOutput!=NULL){
  54. fclose(data->timescaleOutput);
  55. printf("Characteristic Timescale Output File Cleared from Memory!\n");
  56. }
  57. }
  58. free(data); /* Free the user data */
  59. printf("\n\n");
  60. }
  61. UserData allocateUserData(FILE *input){
  62. UserData data;
  63. data = (UserData) malloc(sizeof *data);
  64. if(!data){
  65. printf("Allocation Failed!\n");
  66. return(NULL);
  67. }
  68. setSaneDefaults(data);
  69. int ier;
  70. ier=parseNumber<size_t>(input, "basePts" , MAXBUFLEN, &data->npts);
  71. if(ier==-1 || data->npts<=0){
  72. printf("Enter non-zero basePts!\n");
  73. return(NULL);
  74. }
  75. ier=parseNumber<double>(input, "domainLength", MAXBUFLEN, &data->domainLength);
  76. if(ier==-1 || data->domainLength<=0.0e0){
  77. printf("domainLength error!\n");
  78. return(NULL);
  79. }
  80. ier=parseNumber<double>(input, "Rd", MAXBUFLEN, &data->Rd);
  81. if(ier==-1 || data->Rd<=0.0e0){
  82. printf("Rd error!\n");
  83. return(NULL);
  84. }
  85. ier=parseNumber<int>(input, "constantPressure" , MAXBUFLEN, &data->constantPressure);
  86. if(ier==-1 || (data->constantPressure!=0 && data->constantPressure!=1)){
  87. printf("constantPressure error!\n");
  88. return(NULL);
  89. }
  90. ier=parseNumber<int>(input, "problemType" , MAXBUFLEN, &data->problemType);
  91. if(ier==-1 || (data->problemType!=0
  92. && data->problemType!=1
  93. && data->problemType!=2
  94. && data->problemType!=3)){
  95. printf("include valid problemType!\n");
  96. printf("0: premixed combustion with NO equilibrated ignition kernel\n");
  97. printf("1: premixed combustion WITH equilibrated ignition kernel\n");
  98. printf("2: arbitrary initial conditions\n");
  99. printf("3: Restart\n");
  100. return(NULL);
  101. }
  102. ier=parseNumber<int>(input, "quasiSteady" , MAXBUFLEN, &data->quasiSteady);
  103. if(ier==-1 || (data->quasiSteady!=0
  104. && data->quasiSteady!=1)){
  105. printf("include valid quasiSteady!\n");
  106. printf("0: The droplet surface recedes and the droplet losses mass\n");
  107. printf("1: The droplet surface does not move and the droplet mass is constant\n");
  108. return(NULL);
  109. }
  110. ier=parseNumber<double>(input, "dPdt" , MAXBUFLEN, &data->dPdt);
  111. ier=parseNumber<double>(input, "Rg" , MAXBUFLEN, &data->Rg);
  112. if(data->Rg < 0.0){
  113. printf("Rg must be greater than 0");
  114. return(NULL);
  115. }
  116. ier=parseNumber<int> (input, "reflectProblem" , MAXBUFLEN, &data->reflectProblem);
  117. if(data->reflectProblem!=0 && data->reflectProblem!=1){
  118. printf("Invalid entry for reflectProblem! Can be only 1 or 0.\n");
  119. return(NULL);
  120. }
  121. ier=parseNumber<double>(input, "mdot" , MAXBUFLEN, &data->mdot);
  122. ier=parseNumber<double>(input, "initialTemperature", MAXBUFLEN,
  123. &data->initialTemperature);
  124. if(ier==-1 || data->initialTemperature<=0.0e0){
  125. printf("Enter positive initialTemperature in K!\n");
  126. return(NULL);
  127. }
  128. ier=parseNumber<double>(input, "initialPressure", MAXBUFLEN,
  129. &data->initialPressure);
  130. if(ier==-1 || data->initialTemperature<=0.0e0){
  131. printf("Enter positive initialPressure in atm!\n");
  132. return(NULL);
  133. }
  134. ier=parseNumber<int> (input, "metric" , MAXBUFLEN, &data->metric);
  135. if(data->metric!=0 && data->metric!=1 && data->metric!=2){
  136. printf("Invalid entry for metric!\n");
  137. printf("0: Cartesian\n");
  138. printf("1: Cylindrical\n");
  139. printf("2: Spherical\n");
  140. return(NULL);
  141. }
  142. ier=parseNumber<double>(input, "QDot", MAXBUFLEN, &data->maxQDot);
  143. if(ier==-1 && data->problemType==0){
  144. printf("Need to specify QDot for problemType 0!\n");
  145. return(NULL);
  146. }
  147. ier=parseNumber<double>(input, "kernelSize", MAXBUFLEN, &data->kernelSize);
  148. if(ier==-1 && data->problemType==0){
  149. printf("Need to specify kernelSize for problemType 0!\n");
  150. return(NULL);
  151. }
  152. ier=parseNumber<double>(input, "ignTime", MAXBUFLEN, &data->ignTime);
  153. if(ier==-1 && data->problemType==0){
  154. printf("Need to specify ignTime for problemType 0!\n");
  155. return(NULL);
  156. }
  157. ier=parseNumber<double>(input, "mixingWidth", MAXBUFLEN,
  158. &data->mixingWidth);
  159. if(ier==-1){
  160. printf("Need to specify mixingWidth!\n");
  161. return(NULL);
  162. }
  163. ier=parseNumber<double>(input, "shift", MAXBUFLEN, &data->shift);
  164. ier=parseNumber<double>(input, "firstRadius", MAXBUFLEN, &data->firstRadius);
  165. ier=parseNumber<double>(input, "wallTemperature", MAXBUFLEN, &data->wallTemperature);
  166. ier=parseNumber<int> (input, "dirichletInner" , MAXBUFLEN,
  167. &data->dirichletInner);
  168. if(data->dirichletInner!=0 && data->dirichletInner!=1){
  169. printf("dirichletInner can either be 0 or 1!\n");
  170. return(NULL);
  171. }
  172. ier=parseNumber<int> (input, "dirichletOuter" , MAXBUFLEN,
  173. &data->dirichletOuter);
  174. if(data->dirichletOuter!=0 && data->dirichletOuter!=1){
  175. printf("dirichletOuter can either be 0 or 1!\n");
  176. return(NULL);
  177. }
  178. ier=parseNumber<int> (input, "adaptiveGrid" , MAXBUFLEN,
  179. &data->adaptiveGrid);
  180. if(ier==-1 || (data->adaptiveGrid!=0 && data->adaptiveGrid!=1)){
  181. printf("specify adaptiveGrid as 0 or 1!\n");
  182. return(NULL);
  183. }
  184. ier=parseNumber<int> (input, "moveGrid" , MAXBUFLEN,
  185. &data->moveGrid);
  186. if(ier==-1 || (data->moveGrid!=0 && data->moveGrid!=1)){
  187. printf("specify moveGrid as 0 or 1!\n");
  188. return(NULL);
  189. }
  190. ier=parseNumber<double> (input, "isotherm" , MAXBUFLEN,
  191. &data->isotherm);
  192. if(ier==-1){
  193. printf("specify temperature of isotherm!\n");
  194. return(NULL);
  195. }
  196. ier=parseNumber<double>(input, "gridOffset", MAXBUFLEN, &data->gridOffset);
  197. ier=parseNumber<int> (input, "nSaves" , MAXBUFLEN, &data->nSaves);
  198. if(data->nSaves<0 ){
  199. printf("nSaves must be greater than 0!\n");
  200. return(NULL);
  201. }
  202. ier=parseNumber<int> (input, "writeRates" , MAXBUFLEN,
  203. &data->writeRates);
  204. if(data->writeRates!=0 && data->writeRates!=1){
  205. printf("writeRates must either be 0 or 1!\n");
  206. return(NULL);
  207. }
  208. ier=parseNumber<int> (input, "writeEveryRegrid", MAXBUFLEN,
  209. &data->writeEveryRegrid);
  210. if(data->writeEveryRegrid!=0 && data->writeEveryRegrid!=1){
  211. printf("writeEveryRegrid must either be 0 or 1!\n");
  212. return(NULL);
  213. }
  214. ier=parseNumber<int> (input, "setConstraints" , MAXBUFLEN,
  215. &data->setConstraints);
  216. if(data->setConstraints!=0 && data->setConstraints!=1){
  217. printf("setConstraints must either be 0 or 1!\n");
  218. return(NULL);
  219. }
  220. ier=parseNumber<int> (input, "suppressAlg" , MAXBUFLEN,
  221. &data->suppressAlg);
  222. if(data->setConstraints!=0 && data->suppressAlg!=1){
  223. printf("suppressAlg must either be 0 or 1!\n");
  224. return(NULL);
  225. }
  226. ier=parseNumber<int> (input, "dryRun" , MAXBUFLEN,
  227. &data->dryRun);
  228. if(data->dryRun!=0 && data->dryRun!=1){
  229. printf("dryRun must either be 0 or 1!\n");
  230. return(NULL);
  231. }
  232. ier=parseNumber<double> (input, "finalTime" , MAXBUFLEN,
  233. &data->finalTime);
  234. ier=parseNumber<double> (input, "relativeTolerance" , MAXBUFLEN,
  235. &data->relativeTolerance);
  236. ier=parseNumber<double> (input, "radiusTolerance" , MAXBUFLEN,
  237. &data->radiusTolerance);
  238. ier=parseNumber<double> (input, "temperatureTolerance", MAXBUFLEN,
  239. &data->temperatureTolerance);
  240. ier=parseNumber<double> (input, "pressureTolerance", MAXBUFLEN,
  241. &data->pressureTolerance);
  242. ier=parseNumber<double> (input, "massFractionTolerance", MAXBUFLEN,
  243. &data->massFractionTolerance);
  244. ier=parseNumber<double> (input, "bathGasTolerance", MAXBUFLEN,
  245. &data->bathGasTolerance);
  246. ier=parseNumber<double> (input, "MdotTolerance", MAXBUFLEN,
  247. &data->MdotTolerance);
  248. char chem[MAXBUFLEN],mix[MAXBUFLEN],tran[MAXBUFLEN];
  249. ier=parseNumber<char>(input, "chemistryFile" , MAXBUFLEN, chem);
  250. if(ier==-1){
  251. printf("Enter chemistryFile!\n");
  252. return(NULL);
  253. }else{
  254. try{
  255. data->gas = new Cantera::IdealGasMix(chem);
  256. data->nsp=data->gas->nSpecies(); //assign no: of species
  257. } catch (Cantera::CanteraError& err) {
  258. printf("Error:\n");
  259. printf("%s\n",err.what());
  260. return(NULL);
  261. }
  262. }
  263. ier=parseNumber<char>(input, "transportModel", MAXBUFLEN, tran);
  264. if(ier==-1){
  265. printf("Enter transportModel!\n");
  266. return(NULL);
  267. }else{
  268. try{
  269. data->trmix = Cantera::newTransportMgr(tran, data->gas);
  270. }catch (Cantera::CanteraError& err) {
  271. printf("Error:\n");
  272. printf("%s\n",err.what());
  273. return(NULL);
  274. }
  275. }
  276. ier=parseNumber<char>(input, "mixtureComposition", MAXBUFLEN, mix);
  277. if(ier==-1){
  278. printf("Enter mixtureComposition!\n");
  279. return(NULL);
  280. }else{
  281. if(data->gas!=NULL){
  282. try{
  283. data->gas->setState_TPX(data->initialTemperature,
  284. data->initialPressure*Cantera::OneAtm,
  285. mix);
  286. }catch (Cantera::CanteraError& err) {
  287. printf("Error:\n");
  288. printf("%s\n",err.what());
  289. return(NULL);
  290. }
  291. }
  292. }
  293. ier=parseNumber<char>(input, "dropletComposition", MAXBUFLEN, data->dropSpec);
  294. if(ier==-1){
  295. printf("Enter composition of droplet!\n");
  296. return(NULL);
  297. }
  298. ier=parseNumber<int> (input, "nThreads" , MAXBUFLEN, &data->nThreads);
  299. if(data->nThreads<0 ){
  300. printf("nThreads must be greater than 0!\n");
  301. return(NULL);
  302. }
  303. data->nr=0;
  304. //data->np=data->nr+1;
  305. data->nt=data->nr+1;
  306. data->ny=data->nt+1;
  307. data->np=data->ny+data->nsp;
  308. data->nm=data->np+1;
  309. data->nvar=data->nsp+4; //assign no: of variables (R,T,P,Mdot,nsp species)
  310. //Mass of droplet
  311. //data->massDrop=1.0/3.0*pow(data->Rd,3)*997.0; //TODO: The density of the droplet should be a user input
  312. 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
  313. if(!data->adaptiveGrid){
  314. data->uniformGrid = new double [data->npts];
  315. data->neq=data->nvar*data->npts;
  316. }
  317. else{
  318. data->grid=(UserGrid) malloc(sizeof *data->grid);
  319. ier=getGridSettings(input,data->grid);
  320. if(ier==-1)return(NULL);
  321. ier=initializeGrid(data->grid);
  322. if(ier==-1)return(NULL);
  323. ier=reGrid(data->grid, data->grid->position);
  324. if(ier==-1)return(NULL);
  325. data->npts=data->grid->nPts;
  326. data->neq=data->nvar*data->npts;
  327. }
  328. data->output=fopen("output.dat","w");
  329. data->globalOutput=fopen("globalOutput.dat","w");
  330. data->gridOutput=fopen("grid.dat","w");
  331. data->timescaleOutput=fopen("timeScale.dat","w") ;
  332. //data->ratesOutput=fopen("rates.dat","w");
  333. data->innerMassFractions = new double [data->nsp];
  334. //data->wdot_mole = new double [data->nsp] ;
  335. //data->wdot_mass = new double [data->nsp] ;
  336. data->time_scale = new double [(data->npts) * (data->nsp)] ;
  337. //data->MW = new double [data->nsp] ;
  338. return(data);
  339. }
  340. void setSaneDefaults(UserData data){
  341. data->domainLength=1.0e-02;
  342. data->Rd=100.0e-06;
  343. data->constantPressure=1;
  344. data->problemType=1;
  345. data->quasiSteady=1;
  346. data->dPdt=0.0e0;
  347. data->reflectProblem=0;
  348. data->mdot=0.0;
  349. data->initialTemperature=300.0;
  350. data->initialPressure=1.0;
  351. data->metric=0;
  352. data->ignTime=1e-09;
  353. data->maxQDot=0.0e0;
  354. data->maxTemperature=300.0e0;
  355. data->mixingWidth=1e-04;
  356. data->shift=3.0e-03;
  357. data->firstRadius=1e-04;
  358. data->wallTemperature=298.0e0;
  359. data->dirichletInner=0;
  360. data->dirichletOuter=0;
  361. data->adaptiveGrid=0;
  362. data->moveGrid=0;
  363. data->gridOffset=0.0e0;
  364. data->Rg=1.0;
  365. data->isotherm=1000.0;
  366. data->nSaves=30;
  367. data->writeRates=0;
  368. data->writeEveryRegrid=0;
  369. data->relativeTolerance=1e-06;
  370. data->radiusTolerance=1e-08;
  371. data->temperatureTolerance=1e-06;
  372. data->pressureTolerance=1e-06;
  373. data->massFractionTolerance=1e-09;
  374. data->bathGasTolerance=1e-06;
  375. data->finalTime=1e-02;
  376. data->tNow=0.0e0;
  377. data->setConstraints=0;
  378. data->suppressAlg=1;
  379. data->regrid=0;
  380. data->gridDirection=1;
  381. data->dryRun=0;
  382. data->nThreads=1;
  383. data->flamePosition[0]=0.0e0;
  384. data->flamePosition[1]=0.0e0;
  385. data->flameTime[0]=0.0e0;
  386. data->flameTime[1]=0.0e0;
  387. data->nTimeSteps=0;
  388. }