Droplet Lagrangian Transient One-dimensional Reacting Code Implementation of both liquid and gas phase governing equations.
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.

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