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

126 lines
3.2KB

  1. template<typename T>
  2. int parseNumber(FILE* input, const char* keyword, const size_t bufLen, T* n){
  3. char buf[bufLen];
  4. char buf1[bufLen];
  5. char comment[1];
  6. char *ret;
  7. while (fgets(buf,bufLen, input)!=NULL){
  8. comment[0]=buf[0];
  9. if(strncmp(comment,"#",1)==0){
  10. //printf("Comment!:%s\n",buf);
  11. }
  12. else{
  13. ret=strtok(buf,"=");
  14. if(strcmp(ret,keyword)==0){
  15. /*offset buf by keyword size + 1 for the "="*/
  16. strncpy (buf1, buf+strlen(keyword)+1, bufLen);
  17. printf("%30s: ",keyword);
  18. getFromString(buf1,n);
  19. rewind(input);
  20. return(0);
  21. }
  22. }
  23. }
  24. rewind(input);
  25. return(-1);
  26. }
  27. template<typename T>
  28. int parseArray(FILE* input, const char* keyword, const size_t bufLen,
  29. const size_t arrLen, T y[]){
  30. char buf[bufLen];
  31. char buf1[bufLen];
  32. char comment[1];
  33. char *ret;
  34. while (fgets(buf,bufLen, input)!=NULL){
  35. comment[0]=buf[0];
  36. if(strncmp(comment,"#",1)==0){
  37. //printf("Comment!:%s\n",buf);
  38. }
  39. else{
  40. ret=strtok(buf,"=");
  41. if(strcmp(ret,keyword)==0){
  42. /*offset buf by keyword size + 1 for the "="*/
  43. strncpy (buf1, buf+strlen(keyword)+1, bufLen);
  44. printf("%30s:\n",keyword);
  45. ret=strtok(buf1,",");
  46. size_t j=0;
  47. while(ret!=NULL){
  48. if(j<arrLen){
  49. //y[j]=atof(ret);
  50. getFromString(ret,&y[j]);
  51. }
  52. ret=strtok(NULL,",");
  53. j++;
  54. }
  55. rewind(input);
  56. if(j!=arrLen){
  57. printf("Check no: of values entered for %s\n",keyword);
  58. printf("%lu values required!\n",arrLen);
  59. return(-1);
  60. }
  61. else{
  62. return(0);
  63. }
  64. }
  65. }
  66. }
  67. rewind(input);
  68. return(-1);
  69. }
  70. /* Extract the droplet species and molefractions from input file using template */
  71. /* Generic template function */
  72. template<typename T>
  73. int parseDropSpec(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<T>& dropPara){
  74. char buf[bufLen];
  75. char buf1[bufLen];
  76. char comment[1];
  77. char *ret;
  78. T* n;
  79. while (fgets(buf,bufLen, input)!=NULL){
  80. comment[0]=buf[0];
  81. if(strncmp(comment,"#",1)==0){
  82. //printf("Comment!:%s\n",buf);
  83. }
  84. else{
  85. ret=strtok(buf,"=");
  86. if(strcmp(ret,keyword)==0){
  87. /*offset buf by keyword size + 1 for the "="*/
  88. /* Second argument in the strncpy function is the address !!! */
  89. /* Note: current version of code can only take dropType =0 or 1 */
  90. strncpy(buf1, buf+strlen(keyword)+1, bufLen);
  91. printf("%10s: ",keyword);
  92. if(*dropType ==0){
  93. getFromString(buf1,n);
  94. dropPara.push_back(*n);
  95. }else{
  96. std::istringstream iss(buf1) ;
  97. std::string token;
  98. while(std::getline(iss,token,',')){
  99. T arg = std::stod(token);
  100. dropPara.push_back(arg);
  101. }
  102. printf("%15.6e,%15.6e\n",dropPara[0],dropPara[1]);
  103. }
  104. rewind(input);
  105. return(0);
  106. }
  107. }
  108. }
  109. rewind(input);
  110. return(-1);
  111. }
  112. /* Specialization for string */
  113. template<>
  114. int parseDropSpec<std::string>(FILE* input, const char* keyword, const size_t bufLen,const int* dropType, std::vector<std::string>& dropPara);