Droplet Lagrangian Transient One-dimensional Reacting Code Implementation of both liquid and gas phase governing equations.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

175 Zeilen
5.0KB

  1. #pragma once
  2. template<typename T>
  3. int parseNumber(FILE* input, const char* keyword, const size_t bufLen, T* n){
  4. char buf[bufLen];
  5. char buf1[bufLen];
  6. char comment[1];
  7. char *ret;
  8. while (fgets(buf,bufLen, input)!=NULL){
  9. comment[0]=buf[0];
  10. if(strncmp(comment,"#",1)==0){
  11. //printf("Comment!:%s\n",buf);
  12. }
  13. else{
  14. ret=strtok(buf,"=");
  15. if(strcmp(ret,keyword)==0){
  16. /*offset buf by keyword size + 1 for the "="*/
  17. strncpy (buf1, buf+strlen(keyword)+1, bufLen);
  18. printf("%30s: ",keyword);
  19. getFromString(buf1,n);
  20. rewind(input);
  21. return(0);
  22. }
  23. }
  24. }
  25. rewind(input);
  26. return(-1);
  27. }
  28. template<typename T>
  29. int parseArray(FILE* input, const char* keyword, const size_t bufLen,
  30. const size_t arrLen, T y[]){
  31. char buf[bufLen];
  32. char buf1[bufLen];
  33. char comment[1];
  34. char *ret;
  35. while (fgets(buf,bufLen, input)!=NULL){
  36. comment[0]=buf[0];
  37. if(strncmp(comment,"#",1)==0){
  38. //printf("Comment!:%s\n",buf);
  39. }
  40. else{
  41. ret=strtok(buf,"=");
  42. if(strcmp(ret,keyword)==0){
  43. /*offset buf by keyword size + 1 for the "="*/
  44. strncpy (buf1, buf+strlen(keyword)+1, bufLen);
  45. printf("%30s:\n",keyword);
  46. ret=strtok(buf1,",");
  47. size_t j=0;
  48. while(ret!=NULL){
  49. if(j<arrLen){
  50. //y[j]=atof(ret);
  51. getFromString(ret,&y[j]);
  52. }
  53. ret=strtok(NULL,",");
  54. j++;
  55. }
  56. rewind(input);
  57. if(j!=arrLen){
  58. printf("Check no: of values entered for %s\n",keyword);
  59. printf("%lu values required!\n",arrLen);
  60. return(-1);
  61. }
  62. else{
  63. return(0);
  64. }
  65. }
  66. }
  67. }
  68. rewind(input);
  69. return(-1);
  70. }
  71. /* Extract the droplet species and molefractions from input file using template */
  72. /* Generic template function */
  73. template<typename T>
  74. int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<T>& dropPara){
  75. char buf[bufLen];
  76. char buf1[bufLen];
  77. char comment[1];
  78. char *ret;
  79. T n;
  80. while (fgets(buf,bufLen, input)!=NULL){
  81. comment[0]=buf[0];
  82. if(strncmp(comment,"#",1)==0){
  83. //printf("Comment!:%s\n",buf);
  84. }
  85. else{
  86. ret=strtok(buf,"=");
  87. if(strcmp(ret,keyword)==0){
  88. /*offset buf by keyword size + 1 for the "="*/
  89. /* Second argument in the strncpy function is the address !!! */
  90. /* Note: current version of code can only take dropType =0 or 1 */
  91. strncpy(buf1, buf+strlen(keyword)+1, bufLen);
  92. printf("%30s: ",keyword);
  93. if(*dropType ==0){
  94. getFromString(buf1,&n);
  95. dropPara.push_back(n);
  96. }else{
  97. std::istringstream iss(buf1) ;
  98. std::string token;
  99. while(std::getline(iss,token,',')){
  100. T arg = std::stod(token);
  101. dropPara.push_back(arg);
  102. }
  103. printf("%.3f,%.3f\n",dropPara[0],dropPara[1]);
  104. }
  105. rewind(input);
  106. return(0);
  107. }
  108. }
  109. }
  110. rewind(input);
  111. return(-1);
  112. }
  113. /* Specialization for string */
  114. template<>
  115. inline int parseDropSpec<std::string>(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<std::string>& dropPara){
  116. char buf[bufLen];
  117. char buf1[bufLen];
  118. char comment[1];
  119. char *ret;
  120. while (fgets(buf,bufLen, input)!=NULL){
  121. buf[strlen(buf)-1] = '\0' ;
  122. comment[0]=buf[0];
  123. if(strncmp(comment,"#",1)==0){
  124. //printf("Comment!:%s\n",buf);
  125. }
  126. else{
  127. ret=strtok(buf,"=");
  128. if(strcmp(ret,keyword)==0){
  129. /*offset buf by keyword size + 1 for the "="*/
  130. /* Second argument in the strncpy function is the address !!! */
  131. /* Note: current version of code can only take dropType =0 or 1 */
  132. strncpy(buf1, buf+strlen(keyword)+1, bufLen);
  133. printf("%30s: ",keyword);
  134. if(*dropType ==0){
  135. /* Convert from char* to string */
  136. //printf("buf1 is %s!\n",buf1) ;
  137. std::string str;
  138. for(int i=0;i< strlen(buf1);i++){
  139. if(buf1[i] != ' '){
  140. str += buf1[i] ;
  141. }
  142. }
  143. // printf("str is :%s!\n",str.c_str()) ;
  144. dropPara.push_back(str);
  145. printf("%s.\n",dropPara[0].c_str());
  146. }else{
  147. std::istringstream iss(buf1) ;
  148. std::string token;
  149. while(std::getline(iss,token,',')){
  150. //std::stod(token);
  151. dropPara.push_back(token);
  152. }
  153. printf("%s!,%s!\n",dropPara[0].c_str(),dropPara[1].c_str());
  154. }
  155. rewind(input);
  156. return(0);
  157. }
  158. }
  159. }
  160. rewind(input);
  161. return(-1);
  162. }