Simulation Core
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.
 
 
 
 
 
 

472 lines
19 KiB

  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": 3,
  6. "metadata": {},
  7. "outputs": [
  8. {
  9. "name": "stdout",
  10. "output_type": "stream",
  11. "text": [
  12. "\tGeo/GeoMain.f90 \\\n",
  13. "\n"
  14. ]
  15. }
  16. ],
  17. "source": [
  18. "##Replace space with _ in filenames and list them for put them in makefile\n",
  19. "import os\n",
  20. "dir = 'Geo'\n",
  21. "files = os.listdir(dir)\n",
  22. "fstring = ''\n",
  23. "for f in files:\n",
  24. " if f.endswith('90'):\n",
  25. " newf = f.replace(' ','_')\n",
  26. " os.rename(os.path.join(dir,f),os.path.join(dir,newf))\n",
  27. " if newf.lower().endswith('variables.f90'):\n",
  28. " fstring = '\\t'+os.path.join(dir,newf).replace('\\\\','/') +' \\\\\\n' + fstring\n",
  29. " else:\n",
  30. " fstring = fstring + '\\t'+os.path.join(dir,newf).replace('\\\\','/') +' \\\\\\n'\n",
  31. "\n",
  32. "print(fstring)"
  33. ]
  34. },
  35. {
  36. "attachments": {},
  37. "cell_type": "markdown",
  38. "metadata": {},
  39. "source": [
  40. "## Extract variable names from definition lines"
  41. ]
  42. },
  43. {
  44. "cell_type": "code",
  45. "execution_count": 1,
  46. "metadata": {},
  47. "outputs": [],
  48. "source": [
  49. "# %pwd\n",
  50. "lines = input(\"Enter lines:\").split(\" \")\n",
  51. "lines = [l.strip() for l in lines if len(l.strip())>0]\n",
  52. "vars = []\n",
  53. "for l in lines:\n",
  54. " if '::' in l:\n",
  55. " vars.append(l.split('::')[1].strip())"
  56. ]
  57. },
  58. {
  59. "cell_type": "code",
  60. "execution_count": 8,
  61. "metadata": {},
  62. "outputs": [
  63. {
  64. "data": {
  65. "text/plain": [
  66. "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'"
  67. ]
  68. },
  69. "execution_count": 8,
  70. "metadata": {},
  71. "output_type": "execute_result"
  72. }
  73. ],
  74. "source": [
  75. "import string\n",
  76. "string.ascii_letters"
  77. ]
  78. },
  79. {
  80. "cell_type": "code",
  81. "execution_count": 9,
  82. "metadata": {},
  83. "outputs": [
  84. {
  85. "name": "stdout",
  86. "output_type": "stream",
  87. "text": [
  88. "var: AnnularRegulatorSetControl\n",
  89. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  90. "Char before: \n",
  91. "Char after: \n",
  92. "\n",
  93. "var: AirMasterValve\n",
  94. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  95. "Char before: \n",
  96. "Char after: \n",
  97. "\n",
  98. "var: ByePassValve\n",
  99. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  100. "Char before: \n",
  101. "Char after: \n",
  102. "\n",
  103. "var: AnnularValve\n",
  104. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  105. "Char before: \n",
  106. "Char after: \n",
  107. "\n",
  108. "var: UpperRamsValve\n",
  109. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  110. "Char before: \n",
  111. "Char after: \n",
  112. "\n",
  113. "var: MiddleRamsValve\n",
  114. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  115. "Char before: \n",
  116. "Char after: \n",
  117. "\n",
  118. "var: KillLineValve\n",
  119. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  120. "Char before: \n",
  121. "Char after: \n",
  122. "\n",
  123. "var: ChokeLineValve\n",
  124. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  125. "Char before: \n",
  126. "Char after: \n",
  127. "\n",
  128. "var: LowerRamsValve\n",
  129. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  130. "Char before: \n",
  131. "Char after: \n",
  132. "\n",
  133. "var: ManifoldPressureGauge\n",
  134. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  135. "Char before: \n",
  136. "Char after: \n",
  137. "\n",
  138. "var: AirSupplyPressureGauge\n",
  139. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  140. "Char before: \n",
  141. "Char after: \n",
  142. "\n",
  143. "var: AccumulatorPressureGauge\n",
  144. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  145. "Char before: \n",
  146. "Char after: \n",
  147. "\n",
  148. "var: AnnularPressureGauge\n",
  149. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  150. "Char before: \n",
  151. "Char after: \n",
  152. "\n",
  153. "var: AnnularOpenLED\n",
  154. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  155. "Char before: \n",
  156. "Char after: \n",
  157. "\n",
  158. "var: AnnularCloseLED\n",
  159. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  160. "Char before: \n",
  161. "Char after: \n",
  162. "\n",
  163. "var: UpperRamsOpenLED\n",
  164. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  165. "Char before: \n",
  166. "Char after: \n",
  167. "\n",
  168. "var: UpperRamsCloseLED\n",
  169. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  170. "Char before: \n",
  171. "Char after: \n",
  172. "\n",
  173. "var: MiddleRamsOpenLED\n",
  174. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  175. "Char before: \n",
  176. "Char after: \n",
  177. "\n",
  178. "var: MiddleRamsCloseLED\n",
  179. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  180. "Char before: \n",
  181. "Char after: \n",
  182. "\n",
  183. "var: KillLineOpenLED\n",
  184. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  185. "Char before: \n",
  186. "Char after: \n",
  187. "\n",
  188. "var: KillLineCloseLED\n",
  189. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  190. "Char before: \n",
  191. "Char after: \n",
  192. "\n",
  193. "var: ChokeLineOpenLED\n",
  194. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  195. "Char before: \n",
  196. "Char after: \n",
  197. "\n",
  198. "var: ChokeLineCloseLED\n",
  199. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  200. "Char before: \n",
  201. "Char after: \n",
  202. "\n",
  203. "var: LowerRamsOpenLED\n",
  204. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  205. "Char before: \n",
  206. "Char after: \n",
  207. "\n",
  208. "var: LowerRamsCloseLED\n",
  209. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  210. "Char before: \n",
  211. "Char after: \n",
  212. "\n",
  213. "var: AnnularStatus\n",
  214. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  215. "Char before: \n",
  216. "Char after: \n",
  217. "\n",
  218. "var: UpperRamsStatus\n",
  219. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  220. "Char before: \n",
  221. "Char after: \n",
  222. "\n",
  223. "var: MiddleRamsStatus\n",
  224. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  225. "Char before: \n",
  226. "Char after: \n",
  227. "\n",
  228. "var: LowerRamsStatus\n",
  229. "file = .\\CSharp\\Equipments\\ControlPanels\\CBopControlPanelVariables.f90\n",
  230. "Char before: \n",
  231. "Char after: \n",
  232. "\n"
  233. ]
  234. }
  235. ],
  236. "source": [
  237. "import os\n",
  238. "import sys\n",
  239. "import re\n",
  240. "dir = '.'\n",
  241. "varNameChars = string.ascii_letters + '_'\n",
  242. "log = open(os.path.join(dir,'ReplaceVars.log',),'a')\n",
  243. "end=False\n",
  244. "for dir,subdirs,files in os.walk(dir):\n",
  245. " for filename in files:\n",
  246. " if filename.lower().endswith('.f90'):\n",
  247. " # print(filename)\n",
  248. " file = open(os.path.join(dir,filename))\n",
  249. " code = file.read()\n",
  250. " for var in vars:\n",
  251. " if var not in code:\n",
  252. " continue\n",
  253. " occurs = [m.start() for m in re.finditer(var, code)]\n",
  254. " for occurance in occurs:\n",
  255. " if code[occurs[0]-1] in varNameChars or code[occurs[0]+len(var)] in varNameChars:\n",
  256. " continue\n",
  257. " print(f\"var: {var}\")\n",
  258. " print(f\"file = {os.path.join(dir,filename)}\")\n",
  259. " print(f\"Char before: {code[occurs[0]-1]}\")\n",
  260. " print(f\"Char after: {code[occurs[0]+len(var)]}\")\n",
  261. " end = True\n",
  262. " if end:\n",
  263. " break"
  264. ]
  265. },
  266. {
  267. "cell_type": "code",
  268. "execution_count": 9,
  269. "metadata": {},
  270. "outputs": [
  271. {
  272. "name": "stdout",
  273. "output_type": "stream",
  274. "text": [
  275. "State\n",
  276. "Hoisting\n",
  277. "OperationScenario\n",
  278. "notifications\n",
  279. "permissions\n",
  280. "unitySignals\n",
  281. "StudentStation\n",
  282. "BopStackInput\n",
  283. "BopStackAcc\n",
  284. "RamLine\n",
  285. "AnnularComputational\n",
  286. "Annular\n",
  287. "PipeRam1\n",
  288. "ShearRam\n",
  289. "PipeRam2\n",
  290. "ChokeLine\n",
  291. "KillLine\n",
  292. "Pumps\n",
  293. "RAM\n",
  294. "RAMS\n",
  295. "Choke\n",
  296. "AirDrivenPump\n",
  297. "AirPumpLine\n",
  298. "CHOOKE\n",
  299. "Drawworks\n",
  300. "MudSystem\n",
  301. "MUD\n",
  302. "PUMP\n",
  303. "RTable\n",
  304. "TDS\n",
  305. "GasType(3)\n",
  306. "PressureDisplay\n",
  307. "ObservationPoint(:)\n",
  308. "FricPressDrop\n",
  309. "ROP_Spec\n",
  310. "ROP_Bit\n",
  311. "TDGeo\n",
  312. "F_String(:)\n",
  313. "F_Counts\n",
  314. "F_Interval(:)\n",
  315. "OD_Annulus(4)\n",
  316. "TD_DrillStem\n",
  317. "TD_DrillStems\n",
  318. "TD_String\n",
  319. "TD_Count\n",
  320. "G_StringElement\n",
  321. "TD_Vol\n",
  322. "TD_General\n",
  323. "TD_BOP\n",
  324. "TD_BOPElement(4)\n",
  325. "TD_StConn\n",
  326. "TD_Load\n",
  327. "TD_WellEl\n",
  328. "TD_Casing\n",
  329. "data%State%TD_Liner\n",
  330. "TD_OpenHole\n",
  331. "TD_ROPHole\n",
  332. "TD_WellGeneral\n",
  333. "TD_WellGeo(:)\n",
  334. "EquipmentControl\n",
  335. "BopControlPanel\n",
  336. "ChokeControlPanel\n",
  337. "ChokeManifold\n",
  338. "DataDisplayConsole\n",
  339. "DrillingConsole\n",
  340. "Hook\n",
  341. "StandPipeManifold\n",
  342. "TopDrivePanel\n",
  343. "DrillingWatch\n",
  344. "Tank\n",
  345. "Configuration\n",
  346. "StringConfiguration\n",
  347. "Formation\n",
  348. "Reservoir\n",
  349. "Shoe\n",
  350. "Accumulator\n",
  351. "BopStackSpecification\n",
  352. "Hoisting\n",
  353. "Power\n",
  354. "PumpsSpecification\n",
  355. "RigSize\n",
  356. "CasingLinerChoke\n",
  357. "PathGeneration\n",
  358. "WellSurveyData\n",
  359. "MudProperties\n",
  360. "problems\n",
  361. "BitProblems\n",
  362. "BopProblems\n",
  363. "ChokeProblems\n",
  364. "DrillStemProblems\n",
  365. "GaugesProblems\n",
  366. "HoistingProblems\n",
  367. "KickProblems\n",
  368. "LostProblems\n",
  369. "MudTreatmentProblems\n",
  370. "OtherProblems\n",
  371. "PumpProblems\n",
  372. "RotaryProblems\n"
  373. ]
  374. },
  375. {
  376. "ename": "IndexError",
  377. "evalue": "list index out of range",
  378. "output_type": "error",
  379. "traceback": [
  380. "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
  381. "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)",
  382. "\u001b[1;32mc:\\Projects\\VSIM\\SimulationCore2\\helper.ipynb Cell 6\u001b[0m in \u001b[0;36m<cell line: 3>\u001b[1;34m()\u001b[0m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Projects/VSIM/SimulationCore2/helper.ipynb#W5sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m nsp\u001b[39m+\u001b[39m\u001b[39m=\u001b[39m\u001b[39m1\u001b[39m\n\u001b[0;32m <a href='vscode-notebook-cell:/c%3A/Projects/VSIM/SimulationCore2/helper.ipynb#W5sZmlsZQ%3D%3D?line=6'>7</a>\u001b[0m splits \u001b[39m=\u001b[39m line\u001b[39m.\u001b[39msplit(\u001b[39m\"\u001b[39m\u001b[39m::\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m----> <a href='vscode-notebook-cell:/c%3A/Projects/VSIM/SimulationCore2/helper.ipynb#W5sZmlsZQ%3D%3D?line=7'>8</a>\u001b[0m \u001b[39mprint\u001b[39m(splits[\u001b[39m1\u001b[39;49m]\u001b[39m.\u001b[39mstrip())\n",
  383. "\u001b[1;31mIndexError\u001b[0m: list index out of range"
  384. ]
  385. }
  386. ],
  387. "source": [
  388. "f = open(\"hier.txt\")\n",
  389. "lines = f.readlines()\n",
  390. "for line in lines[1:]:\n",
  391. " nsp=0\n",
  392. " while line[nsp]==' ':\n",
  393. " nsp+=1\n",
  394. " splits = line.split(\"::\")\n",
  395. " print(splits[1].strip())"
  396. ]
  397. },
  398. {
  399. "cell_type": "code",
  400. "execution_count": 4,
  401. "metadata": {},
  402. "outputs": [
  403. {
  404. "data": {
  405. "text/plain": [
  406. "'type SimulationDataType type(SimulationStateType)::State Type(HoistingType)::Hoisting type(OperationScenarioType)::OperationScenario type(NotificationType)::notifications type(PermissionsType):: permissions type(UnitySignalsType):: unitySignals type(StudentStationType)::StudentStation type(BopStackInputType)::BopStackInput type(BopStackAccType)::BopStackAcc type(RamLineType)::RamLine type(AnnularComputationalType)::AnnularComputational type(AnnularType)::Annular type(PipeRams1Type)::PipeRam1 type(ShearRamType)::ShearRam type(PipeRam2Type)::PipeRam2 type(ChokeLineType)::ChokeLine type(KillLineType)::KillLine type(PumpsType)::Pumps TYPE(BOP_TypeVars), DIMENSION(1:6) :: RAM TYPE(BOP_TypeVars2D) :: RAMS type(ChokeType)::Choke type(AirDrivenPumpType)::AirDrivenPump type(AirPumpLineType)::AirPumpLine TYPE(CHOKE_TypeVars), DIMENSION(1:2) :: CHOOKE TYPE(Drawworks_Var) :: Drawworks type(MudSystemType)::MudSystem TYPE(MUD_TypeVars), DIMENSION(1:10) :: MUD TYPE(Pump_Var), DIMENSION(1:3) :: PUMP TYPE(RTable_Var) :: RTable TYPE(TDS_Var) :: TDS TYPE(GasData) :: GasType(3) ! 1 = methane , 2 = Hydrogen sulfide , 3 = Carbon dioxid TYPE(PressureDisplayVARIABLESTYPE) :: PressureDisplay TYPE(ObservationAndGaugePointsInformations) , ALLOCATABLE :: ObservationPoint(:) TYPE(FricPressDropVarsTYPE) :: FricPressDrop TYPE(ROPSpecificationInfo) :: ROP_Spec TYPE(ROPInfo) :: ROP_Bit TYPE(Geo_Data) :: TDGeo TYPE(F_StringData) , Allocatable :: F_String(:) TYPE(F_IntervalsCountsData):: F_Counts TYPE(F_IntervalData) , Allocatable :: F_Interval(:) TYPE(OD_AnnulusData) :: OD_Annulus(4) TYPE(TD_DrillStemInfo), ALLOCATABLE, DIMENSION(:) :: TD_DrillStem TYPE(TD_SeparatedDrillStemInfo), ALLOCATABLE, DIMENSION(:) :: TD_DrillStems TYPE(TD_StringInfo) :: TD_String TYPE(TD_AddRemoveInfo) :: TD_Count TYPE(CStringComponents), ALLOCATABLE, DIMENSION(:) :: G_StringElement TYPE(TD_RemovedVolumeInfo) :: TD_Vol TYPE(TD_GeneralInfo) :: TD_General TYPE(TD_BOPInfo) :: TD_BOP TYPE(CBopElement) :: TD_BOPElement(4) TYPE(TD_StringconnectionInfo) :: TD_StConn TYPE(TD_LoadInfo) :: TD_Load TYPE(TD_WellElementsInfo) :: TD_WellEl TYPE(TD_CasingInfo), ALLOCATABLE, DIMENSION(:) :: TD_Casing TYPE(TD_LinerInfo), ALLOCATABLE, DIMENSION(:) :: data%State%TD_Liner TYPE(TD_OpenHoleInfo), ALLOCATABLE, DIMENSION(:) :: TD_OpenHole TYPE(TD_ROPHoleInfo), ALLOCATABLE, DIMENSION(:) :: TD_ROPHole TYPE(TD_WellGeneralInfo) :: TD_WellGeneral TYPE(TD_WellGeometryData), Allocatable :: TD_WellGeo(:) type(EquipmentControlType)::EquipmentControl type(BopControlPanelType) :: BopControlPanel Type(ChokeControlPanelType)::ChokeControlPanel Type(ChokeManifoldType)::ChokeManifold Type(DataDisplayConsoleType) :: DataDisplayConsole TYPE(DrillingConsoleType) :: DrillingConsole Type(HookType)::Hook type(StandPipeManifoldType)::StandPipeManifold Type(TopDrivePanelType)::TopDrivePanel Type(DrillingWatchType)::DrillingWatch Type(TankType)::Tank type(ConfigurationType)::Configuration Type(StringConfigurationType)::StringConfiguration Type(FormationType) :: Formation Type(ReservoirType)::Reservoir Type(ShoeType)::Shoe Type(AccumulatorType)::Accumulator Type(BopStackSpecificationType)::BopStackSpecification Type(HoistingType)::Hoisting Type(PowerType)::Power Type(PumpSpecificationType)::PumpsSpecification Type(RigSizeType)::RigSize Type(CasingLinerChokeType)::CasingLinerChoke Type(PathGenerationType)::PathGeneration Type(WellSurveyDataType)::WellSurveyData Type(MudPropertiesType)::MudProperties type(ProblemsType)::problems type(BitProblemsType)::BitProblems type(BopProblemsType)::BopProblems type(ChokeProblemsType)::ChokeProblems type(DrillStemProblemsType)::DrillStemProblems type(GaugesProblemsType)::GaugesProblems type(HoistingProblemsType):: HoistingProblems type(KickProblemsType)::KickProblems type(LostProblemsType)::LostProblems type(MudTreatmentProblemsType)::MudTreatmentProblems type(OtherProblemsType)::OtherProblems type(PumpProblemsType)::PumpProblems type(RotaryProblemsType)::RotaryProblems end type SimulationDataType'"
  407. ]
  408. },
  409. "execution_count": 4,
  410. "metadata": {},
  411. "output_type": "execute_result"
  412. }
  413. ],
  414. "source": [
  415. "line"
  416. ]
  417. },
  418. {
  419. "cell_type": "code",
  420. "execution_count": null,
  421. "metadata": {},
  422. "outputs": [],
  423. "source": [
  424. "for fn in modules:\n",
  425. " f = open(fn)\n",
  426. " lines = f.readlines()\n",
  427. " module_filenames = {}\n",
  428. " used_modules = []\n",
  429. " mod_count = 0\n",
  430. " for l in lines:\n",
  431. " l = l.strip().lower()\n",
  432. " if l.startswith('module ') and not l.startswith('module procedure '):\n",
  433. " mod_name = l.split(' ')[1]\n",
  434. " module_filenames[mod_name] = fn\n",
  435. " mod_count +=1\n",
  436. " if l.startswith('use'):\n",
  437. " used_modules.append(l.split(' ')[1])\n",
  438. " if mod_count !=1:\n",
  439. " print(f\"{fn} has {mod_count} modules\")\n",
  440. " module_filenames,used_modules"
  441. ]
  442. }
  443. ],
  444. "metadata": {
  445. "kernelspec": {
  446. "display_name": "base",
  447. "language": "python",
  448. "name": "python3"
  449. },
  450. "language_info": {
  451. "codemirror_mode": {
  452. "name": "ipython",
  453. "version": 3
  454. },
  455. "file_extension": ".py",
  456. "mimetype": "text/x-python",
  457. "name": "python",
  458. "nbconvert_exporter": "python",
  459. "pygments_lexer": "ipython3",
  460. "version": "3.9.12"
  461. },
  462. "orig_nbformat": 4,
  463. "vscode": {
  464. "interpreter": {
  465. "hash": "1ef4a26de7183d96d6da1045a38581e0a15b2215d0c1b98c7b273c6e514c6c7e"
  466. }
  467. }
  468. },
  469. "nbformat": 4,
  470. "nbformat_minor": 2
  471. }