Droplet Lagrangian Transient One-dimensional Reacting Code Implementation of both liquid and gas phase governing equations.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

138 satır
4.6KB

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