simulator.opm
Wrap OPM-flow
1"""Wrap OPM-flow""" 2# External imports 3from subprocess import call, DEVNULL 4import os 5import shutil 6 7# Internal imports 8from simulator.eclipse import eclipse 9from misc.system_tools.environ_var import OPMRunEnvironment 10 11 12class flow(eclipse): 13 """ 14 Class for running OPM flow with Eclipse input files. Inherits eclipse parent class for setting up and running 15 simulations, and reading the results. 16 """ 17 18 def call_sim(self, folder=None, wait_for_proc=False): 19 """ 20 Call OPM flow simulator via shell. 21 22 Parameters 23 ---------- 24 folder : str 25 Folder with runfiles. 26 27 wait_for_proc : bool 28 Boolean determining if we wait for the process to be done or not. 29 30 Changelog 31 --------- 32 - ST 18/10-18 33 """ 34 # Filename 35 if folder is not None: 36 filename = folder + self.file 37 else: 38 filename = self.file 39 40 success = True 41 try: 42 with OPMRunEnvironment(filename, 'PRT', ['End of simulation', 'NOSIM']): 43 com = [] 44 if self.options['mpi']: 45 com.extend(self.options['mpi'].split()) 46 com.append(self.options['sim_path'] + 'flow') 47 if self.options['parsing-strictness']: 48 com.extend(['--parsing-strictness=' + self.options['parsing-strictness']]) 49 com.extend(['--output-dir=' + folder, * 50 self.options['sim_flag'].split(), filename + '.DATA']) 51 if 'sim_limit' in self.options: 52 call(com, stdout=DEVNULL, timeout=self.options['sim_limit']) 53 else: 54 call(com, stdout=DEVNULL) 55 raise ValueError # catch errors in run_sim 56 except: 57 print('\nError in the OPM run.') # add rerun? 58 if not os.path.exists('Crashdump'): 59 shutil.copytree(folder, 'Crashdump') 60 success = False 61 62 return success 63 64 def check_sim_end(self, finished_member=None): 65 """ 66 Check in RPT file for "End of simulation" to see if OPM flow is done. 67 68 Changelog 69 --------- 70 - ST 19/10-18 71 """ 72 # Initialize output 73 # member = None 74 # 75 # # Search for output.dat file 76 # for file in os.listdir('En_' + str(finished_member)): # Search within a specific En_folder 77 # if file.endswith('PRT'): # look in PRT file 78 # with open('En_' + str(finished_member) + os.sep + file, 'r') as fid: 79 # for line in fid: 80 # if re.search('End of simulation', line): 81 # # TODO: not do time.sleep() 82 # # time.sleep(0.1) 83 # member = finished_member 84 85 return finished_member 86 87 88class ebos(eclipse): 89 """ 90 Class for running OPM ebos with Eclipse input files. Inherits eclipse parent class for setting up and running 91 simulations, and reading the results. 92 """ 93 94 def call_sim(self, folder=None, wait_for_proc=False): 95 """ 96 Call OPM flow simulator via shell. 97 98 Parameters 99 ---------- 100 folder : str 101 Folder with runfiles. 102 103 wait_for_proc : bool 104 Determines whether to wait for the process to be done or not. 105 106 Changelog 107 --------- 108 - RJL 27/08-19 109 """ 110 # Filename 111 if folder is not None: 112 filename = folder + self.file 113 else: 114 filename = self.file 115 116 # Run simulator 117 if 'sim_path' not in self.options.keys(): 118 self.options['sim_path'] = '' 119 120 with OPMRunEnvironment(filename, 'OUT', 'Timing receipt'): 121 with open(filename+'.OUT', 'w') as f: 122 call([self.options['sim_path'] + 'ebos', '--output-dir=' + folder, 123 *self.options['sim_flag'].split(), filename + '.DATA'], stdout=f) 124 125 def check_sim_end(self, finished_member=None): 126 """ 127 Check in RPT file for "End of simulation" to see if OPM ebos is done. 128 129 Changelog 130 --------- 131 - RJL 27/08-19 132 """ 133 # Initialize output 134 # member = None 135 # 136 # # Search for output.dat file 137 # for file in os.listdir('En_' + str(finished_member)): # Search within a specific En_folder 138 # if file.endswith('OUT'): # look in OUT file 139 # with open('En_' + str(finished_member) + os.sep + file, 'r') as fid: 140 # for line in fid: 141 # if re.search('Timing receipt', line): 142 # # TODO: not do time.sleep() 143 # # time.sleep(0.1) 144 # member = finished_member 145 146 return finished_member
13class flow(eclipse): 14 """ 15 Class for running OPM flow with Eclipse input files. Inherits eclipse parent class for setting up and running 16 simulations, and reading the results. 17 """ 18 19 def call_sim(self, folder=None, wait_for_proc=False): 20 """ 21 Call OPM flow simulator via shell. 22 23 Parameters 24 ---------- 25 folder : str 26 Folder with runfiles. 27 28 wait_for_proc : bool 29 Boolean determining if we wait for the process to be done or not. 30 31 Changelog 32 --------- 33 - ST 18/10-18 34 """ 35 # Filename 36 if folder is not None: 37 filename = folder + self.file 38 else: 39 filename = self.file 40 41 success = True 42 try: 43 with OPMRunEnvironment(filename, 'PRT', ['End of simulation', 'NOSIM']): 44 com = [] 45 if self.options['mpi']: 46 com.extend(self.options['mpi'].split()) 47 com.append(self.options['sim_path'] + 'flow') 48 if self.options['parsing-strictness']: 49 com.extend(['--parsing-strictness=' + self.options['parsing-strictness']]) 50 com.extend(['--output-dir=' + folder, * 51 self.options['sim_flag'].split(), filename + '.DATA']) 52 if 'sim_limit' in self.options: 53 call(com, stdout=DEVNULL, timeout=self.options['sim_limit']) 54 else: 55 call(com, stdout=DEVNULL) 56 raise ValueError # catch errors in run_sim 57 except: 58 print('\nError in the OPM run.') # add rerun? 59 if not os.path.exists('Crashdump'): 60 shutil.copytree(folder, 'Crashdump') 61 success = False 62 63 return success 64 65 def check_sim_end(self, finished_member=None): 66 """ 67 Check in RPT file for "End of simulation" to see if OPM flow is done. 68 69 Changelog 70 --------- 71 - ST 19/10-18 72 """ 73 # Initialize output 74 # member = None 75 # 76 # # Search for output.dat file 77 # for file in os.listdir('En_' + str(finished_member)): # Search within a specific En_folder 78 # if file.endswith('PRT'): # look in PRT file 79 # with open('En_' + str(finished_member) + os.sep + file, 'r') as fid: 80 # for line in fid: 81 # if re.search('End of simulation', line): 82 # # TODO: not do time.sleep() 83 # # time.sleep(0.1) 84 # member = finished_member 85 86 return finished_member
Class for running OPM flow with Eclipse input files. Inherits eclipse parent class for setting up and running simulations, and reading the results.
def
call_sim(self, folder=None, wait_for_proc=False):
19 def call_sim(self, folder=None, wait_for_proc=False): 20 """ 21 Call OPM flow simulator via shell. 22 23 Parameters 24 ---------- 25 folder : str 26 Folder with runfiles. 27 28 wait_for_proc : bool 29 Boolean determining if we wait for the process to be done or not. 30 31 Changelog 32 --------- 33 - ST 18/10-18 34 """ 35 # Filename 36 if folder is not None: 37 filename = folder + self.file 38 else: 39 filename = self.file 40 41 success = True 42 try: 43 with OPMRunEnvironment(filename, 'PRT', ['End of simulation', 'NOSIM']): 44 com = [] 45 if self.options['mpi']: 46 com.extend(self.options['mpi'].split()) 47 com.append(self.options['sim_path'] + 'flow') 48 if self.options['parsing-strictness']: 49 com.extend(['--parsing-strictness=' + self.options['parsing-strictness']]) 50 com.extend(['--output-dir=' + folder, * 51 self.options['sim_flag'].split(), filename + '.DATA']) 52 if 'sim_limit' in self.options: 53 call(com, stdout=DEVNULL, timeout=self.options['sim_limit']) 54 else: 55 call(com, stdout=DEVNULL) 56 raise ValueError # catch errors in run_sim 57 except: 58 print('\nError in the OPM run.') # add rerun? 59 if not os.path.exists('Crashdump'): 60 shutil.copytree(folder, 'Crashdump') 61 success = False 62 63 return success
Call OPM flow simulator via shell.
Parameters
- folder (str): Folder with runfiles.
- wait_for_proc (bool): Boolean determining if we wait for the process to be done or not.
Changelog
- ST 18/10-18
def
check_sim_end(self, finished_member=None):
65 def check_sim_end(self, finished_member=None): 66 """ 67 Check in RPT file for "End of simulation" to see if OPM flow is done. 68 69 Changelog 70 --------- 71 - ST 19/10-18 72 """ 73 # Initialize output 74 # member = None 75 # 76 # # Search for output.dat file 77 # for file in os.listdir('En_' + str(finished_member)): # Search within a specific En_folder 78 # if file.endswith('PRT'): # look in PRT file 79 # with open('En_' + str(finished_member) + os.sep + file, 'r') as fid: 80 # for line in fid: 81 # if re.search('End of simulation', line): 82 # # TODO: not do time.sleep() 83 # # time.sleep(0.1) 84 # member = finished_member 85 86 return finished_member
Check in RPT file for "End of simulation" to see if OPM flow is done.
Changelog
- ST 19/10-18
89class ebos(eclipse): 90 """ 91 Class for running OPM ebos with Eclipse input files. Inherits eclipse parent class for setting up and running 92 simulations, and reading the results. 93 """ 94 95 def call_sim(self, folder=None, wait_for_proc=False): 96 """ 97 Call OPM flow simulator via shell. 98 99 Parameters 100 ---------- 101 folder : str 102 Folder with runfiles. 103 104 wait_for_proc : bool 105 Determines whether to wait for the process to be done or not. 106 107 Changelog 108 --------- 109 - RJL 27/08-19 110 """ 111 # Filename 112 if folder is not None: 113 filename = folder + self.file 114 else: 115 filename = self.file 116 117 # Run simulator 118 if 'sim_path' not in self.options.keys(): 119 self.options['sim_path'] = '' 120 121 with OPMRunEnvironment(filename, 'OUT', 'Timing receipt'): 122 with open(filename+'.OUT', 'w') as f: 123 call([self.options['sim_path'] + 'ebos', '--output-dir=' + folder, 124 *self.options['sim_flag'].split(), filename + '.DATA'], stdout=f) 125 126 def check_sim_end(self, finished_member=None): 127 """ 128 Check in RPT file for "End of simulation" to see if OPM ebos is done. 129 130 Changelog 131 --------- 132 - RJL 27/08-19 133 """ 134 # Initialize output 135 # member = None 136 # 137 # # Search for output.dat file 138 # for file in os.listdir('En_' + str(finished_member)): # Search within a specific En_folder 139 # if file.endswith('OUT'): # look in OUT file 140 # with open('En_' + str(finished_member) + os.sep + file, 'r') as fid: 141 # for line in fid: 142 # if re.search('Timing receipt', line): 143 # # TODO: not do time.sleep() 144 # # time.sleep(0.1) 145 # member = finished_member 146 147 return finished_member
Class for running OPM ebos with Eclipse input files. Inherits eclipse parent class for setting up and running simulations, and reading the results.
def
call_sim(self, folder=None, wait_for_proc=False):
95 def call_sim(self, folder=None, wait_for_proc=False): 96 """ 97 Call OPM flow simulator via shell. 98 99 Parameters 100 ---------- 101 folder : str 102 Folder with runfiles. 103 104 wait_for_proc : bool 105 Determines whether to wait for the process to be done or not. 106 107 Changelog 108 --------- 109 - RJL 27/08-19 110 """ 111 # Filename 112 if folder is not None: 113 filename = folder + self.file 114 else: 115 filename = self.file 116 117 # Run simulator 118 if 'sim_path' not in self.options.keys(): 119 self.options['sim_path'] = '' 120 121 with OPMRunEnvironment(filename, 'OUT', 'Timing receipt'): 122 with open(filename+'.OUT', 'w') as f: 123 call([self.options['sim_path'] + 'ebos', '--output-dir=' + folder, 124 *self.options['sim_flag'].split(), filename + '.DATA'], stdout=f)
Call OPM flow simulator via shell.
Parameters
- folder (str): Folder with runfiles.
- wait_for_proc (bool): Determines whether to wait for the process to be done or not.
Changelog
- RJL 27/08-19
def
check_sim_end(self, finished_member=None):
126 def check_sim_end(self, finished_member=None): 127 """ 128 Check in RPT file for "End of simulation" to see if OPM ebos is done. 129 130 Changelog 131 --------- 132 - RJL 27/08-19 133 """ 134 # Initialize output 135 # member = None 136 # 137 # # Search for output.dat file 138 # for file in os.listdir('En_' + str(finished_member)): # Search within a specific En_folder 139 # if file.endswith('OUT'): # look in OUT file 140 # with open('En_' + str(finished_member) + os.sep + file, 'r') as fid: 141 # for line in fid: 142 # if re.search('Timing receipt', line): 143 # # TODO: not do time.sleep() 144 # # time.sleep(0.1) 145 # member = finished_member 146 147 return finished_member
Check in RPT file for "End of simulation" to see if OPM ebos is done.
Changelog
- RJL 27/08-19