fork download
  1. import re
  2.  
  3. s='''
  4. /*--------------------------------*- C++ -*----------------------------------*\
  5. | ========= | |
  6. | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
  7. | \\ / O peration | Version: 5 |
  8. | \\ / A nd | Web: www.OpenFOAM.org |
  9. | \\/ M anipulation | |
  10. \*---------------------------------------------------------------------------*/
  11. FoamFile
  12. {
  13. version 2.0;
  14. format ascii;
  15. class dictionary;
  16. object blockMeshDict;
  17. }
  18. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  19.  
  20. convertToMeters 0.001;
  21.  
  22. vertices
  23. (
  24. (-20.6 0 -0.5)
  25. (-20.6 25.4 -0.5) /* Some comment */
  26. (0 -25.4 -0.5)
  27. (0 0 -0.5)
  28. (0 25.4 -0.5)
  29. (206 -25.4 -0.5)
  30. (206 0 -0.5)
  31. (206 25.4 -0.5)
  32. (290 -16.6 -0.5)
  33. (290 0 -0.5)
  34. (290 16.6 -0.5)
  35.  
  36. (-20.6 0 0.5)
  37. (-20.6 25.4 0.5)
  38. (0 -25.4 0.5)
  39. (0 0 0.5)
  40. (0 25.4 0.5)
  41. (206 -25.4 0.5)
  42. (206 0 0.5)
  43. (206 25.4 0.5)
  44. (290 -16.6 0.5)
  45. (290 0 0.5)
  46. (290 16.6 0.5)
  47. /*(1 2 3 4)*/ // Commented tuple
  48. //(1 2 3 4)
  49. );
  50.  
  51. /* vertices commented
  52. vertices
  53. (
  54. (-20.6 0 -0.5)
  55. (-20.6 25.4 -0.5)
  56. (0 -25.4 -0.5)
  57. (0 0 -0.5)
  58. (0 25.4 -0.5)
  59. (206 -25.4 -0.5)
  60. (206 0 -0.5)
  61. (206 25.4 -0.5)
  62. (290 -16.6 -0.5)
  63. (290 0 -0.5)
  64. (290 16.6 -0.5)
  65. )
  66. */
  67.  
  68. negY
  69. (
  70. (2 4 1)
  71. (1 3 0.3)
  72. );
  73.  
  74. posY
  75. (
  76. (1 4 2)
  77. (2 3 4)
  78. (2 4 0.25)
  79. );
  80.  
  81. posYR
  82. (
  83. (2 1 1)
  84. (1 1 0.25)
  85. );
  86.  
  87.  
  88. blocks
  89. (
  90. hex (0 3 4 1 11 14 15 12)
  91. (18 30 1)
  92. simpleGrading (0.5 $posY 1)
  93.  
  94. hex (2 5 6 3 13 16 17 14)
  95. (180 27 1)
  96. edgeGrading (4 4 4 4 $negY 1 1 $negY 1 1 1 1)
  97.  
  98. hex (3 6 7 4 14 17 18 15)
  99. (180 30 1)
  100. edgeGrading (4 4 4 4 $posY $posYR $posYR $posY 1 1 1 1)
  101.  
  102. hex (5 8 9 6 16 19 20 17)
  103. (25 27 1)
  104. simpleGrading (2.5 1 1)
  105.  
  106. hex (6 9 10 7 17 20 21 18)
  107. (25 30 1)
  108. simpleGrading (2.5 $posYR 1)
  109. );
  110.  
  111. edges
  112. (
  113. );
  114.  
  115. boundary
  116. (
  117. inlet
  118. {
  119. type patch;
  120. faces
  121. (
  122. (0 1 12 11)
  123. );
  124. }
  125. outlet
  126. {
  127. type patch;
  128. faces
  129. (
  130. (8 9 20 19)
  131. (9 10 21 20)
  132. );
  133. }
  134. upperWall
  135. {
  136. type wall;
  137. faces
  138. (
  139. (1 4 15 12)
  140. (4 7 18 15)
  141. (7 10 21 18)
  142. );
  143. }
  144. lowerWall
  145. {
  146. type wall;
  147. faces
  148. (
  149. (0 3 14 11)
  150. (3 2 13 14)
  151. (2 5 16 13)
  152. (5 8 19 16)
  153. );
  154. }
  155. frontAndBack
  156. {
  157. type empty;
  158. faces
  159. (
  160. (0 3 4 1)
  161. (2 5 6 3)
  162. (3 6 7 4)
  163. (5 8 9 6)
  164. (6 9 10 7)
  165. (11 14 15 12)
  166. (13 16 17 14)
  167. (14 17 18 15)
  168. (16 19 20 17)
  169. (17 20 21 18)
  170. );
  171. }
  172. );
  173. // ************************************************************************* //
  174. '''
  175.  
  176. # Remove comments like "//" until end of line
  177. s = re.sub(r'//.*', '', s)
  178.  
  179. # Remove comments between /* and */
  180. s = re.sub(r'/\*(.|\s)*?\*/', '', s, re.DOTALL)
  181.  
  182. r1 = re.search(r'vertices\s*\(\s*(.*)\s*\)', s, re.DOTALL)
  183. vertices = [(float(v[0]),float(v[1]),float(v[2]))
  184. for v in re.findall(r'\(\s*([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s*\)', r1.group(1))]
  185.  
  186. print(vertices)
Success #stdin #stdout 0.03s 65320KB
stdin
Standard input is empty
stdout
[(-20.6, 0.0, -0.5), (-20.6, 25.4, -0.5), (0.0, -25.4, -0.5), (0.0, 0.0, -0.5), (0.0, 25.4, -0.5), (206.0, -25.4, -0.5), (206.0, 0.0, -0.5), (206.0, 25.4, -0.5), (290.0, -16.6, -0.5), (290.0, 0.0, -0.5), (290.0, 16.6, -0.5), (-20.6, 0.0, 0.5), (-20.6, 25.4, 0.5), (0.0, -25.4, 0.5), (0.0, 0.0, 0.5), (0.0, 25.4, 0.5), (206.0, -25.4, 0.5), (206.0, 0.0, 0.5), (206.0, 25.4, 0.5), (290.0, -16.6, 0.5), (290.0, 0.0, 0.5), (290.0, 16.6, 0.5), (2.0, 4.0, 1.0), (1.0, 3.0, 0.3), (1.0, 4.0, 2.0), (2.0, 3.0, 4.0), (2.0, 4.0, 0.25), (2.0, 1.0, 1.0), (1.0, 1.0, 0.25), (18.0, 30.0, 1.0), (180.0, 27.0, 1.0), (180.0, 30.0, 1.0), (25.0, 27.0, 1.0), (2.5, 1.0, 1.0), (25.0, 30.0, 1.0)]