def load_wanda_case(n_clicks, wanda_case): if wanda_case is None: raise PreventUpdate print(wanda_case) global wanda_model wanda_model = pywanda.WandaModel(wanda_case, wanda_bin) wanda_model.reload_output() options = get_options(wanda_model.get_all_components_str()) return options
def run_scenario(self): model = pywanda.WandaModel(self.model_file, self.bin) if self.only_figures: model.reload_output() else: for parameter in self.parameters: parameter.set_parameter(model) model.save_model_input() model.run_steady() model.run_unsteady() result = self.get_results(model) self.create_graphs(model) model.close() return result
def test_wandaplot_text(mocker): mocker.patch('pywanda.WandaModel') model = pywanda.WandaModel( r'Examples\example_data\Sewage_transient.wdi', r'c:\Program Files (x86)\Deltares\Wanda 4.6\Bin\\') with PdfPages('test_wandaplottext.pdf') as pdf: counter = 1 subplots_table = [PlotText("Testing text")] plot(model, subplots_table, 'Title', 'Case title', 'Case description', '11201234', 'Section name', f'Fig A.{counter}', company_image=None, fontsize=10) pdf.savefig() plt.close()
def main(): n_runs = 50 # total number of runs per worker which need to be performed n_workers = 8 # Number of parallel workers which will be used. The optimal number depends on your PC cwd = os.getcwd() wandacase_fullpath = os.path.join(cwd, "example_data", "Sewage_transient.wdi") wanda_bin_directory = r'c:\Program Files (x86)\Deltares\Wanda 4.6\Bin\\' model = pw.WandaModel(wandacase_fullpath, wanda_bin_directory) parameters = [ MonteCarloInputProperty(" PIPES", "Wall roughness", 2.5 / 1000, 0.5 / 1000, "normal", True), MonteCarloInputProperty("BOUNDH B1", "Head at t = 0 [s]", -5, 5, "uniform"), MonteCarloInputProperty("BOUNDH B3", "Head at t = 0 [s]", -3, 3, "uniform"), MonteCarloInputProperty("GENERAL", "Bulk modulus", 1.8e9, 2.5e9, "uniform") ] outputs = [ MonteCarloOutputProperty(" PIPES", "Pressure", keyword=True), MonteCarloOutputProperty(" PIPES", "Pressure", keyword=True, extreme="MAX") ] analysis = WandaMonteCarlo(model, parameters, outputs, nruns=n_runs, n_workers=n_workers) analysis.run(n_workers=8) df = analysis.get_results() print(df.head()) analysis.plot_results(filename_prefix="test", width=1000, height=800) analysis.cleanup()
def test_wandaplot_table(mocker): mocker.patch('pywanda.WandaModel') model = pywanda.WandaModel( r'Examples\example_data\Sewage_transient.wdi', r'c:\Program Files (x86)\Deltares\Wanda 4.6\Bin\\') df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), columns=['Aaa', 'Bbb', 'Ccc']) with PdfPages('test_wandaplottable.pdf') as pdf: counter = 1 subplots_table = [PlotTable(df, df.columns)] plot(model, subplots_table, 'Title', 'Case title', 'Case description', '11201234', 'Section name', f'Fig A.{counter}', company_image=None, fontsize=10) pdf.savefig() plt.close()
def worker(n_runs, wandacase, working_directory, parameters, outputs, worker_id): # Every process gets its own Wandacase and Wandabin wandacase_directory, casename = os.path.split(wandacase) dst = os.path.join(working_directory, str(worker_id), casename) wandabin = os.path.join(working_directory, str(worker_id), "bin") model = pw.WandaModel(str(dst), str(wandabin + "\\")) results = [] for i in range(n_runs): run_id = (n_runs * worker_id) + i # if(run_id == None): # break print("Worker #" + str(worker_id) + " running task ID: " + str(run_id)) for para in parameters: para.update(model) model.save_model_input() try: model.run_steady() except Exception as inst: print("Error in running steady thread " + str(worker_id)) print(inst) break try: model.run_unsteady() except Exception as inst: print("Error in running unsteady thread " + str(worker_id)) print(inst) break model.reload_input() model.reload_output() extreme_values = [] for output in outputs: extreme_values.append(output.get_extreme(model)) results.append(extreme_values) model.close() return results