def _init_model(self, solver): if solver == 'numba': solver = PegasusNumba() num_app = ImplicitEulerNumba(root_finder=solver) elif solver == 'python': solver = PegasusPython() num_app = ImplicitEulerPython(root_finder=solver) fr = PowerReservoir(parameters={'k': 0.01, 'alpha': 2.5}, states={'S0': 0.0}, approximation=num_app, id='FR') fr.set_timestep(2.0) self._model = fr
# Set the wd to the one of the file, to avoid absolute paths os.chdir(sys.path[0]) # Initialize solver (default settings) solver_python = PegasusPython() approximator = ImplicitEulerPython(root_finder=solver_python) #%% Run element # Initialize the reservoir reservoir = PowerReservoir( parameters={'k': 0.01, 'alpha': 2.0}, states={'S0': 10.0}, approximation=approximator, id='R' ) reservoir.set_timestep(1.0) # Create input precipitation = np.array([6.5, 3.0, 0.0, 0.0, 0.0, 2.0, 4.0, 8.0, 2.0, 0.0, 0.0, 2.5, 1.0, 0.0, 4.0, 0.0, 1.0, 0.0, 0.0, 0.0]) # Set input reservoir.set_input([precipitation]) # Run the element output = reservoir.get_output()[0] reservoir_state = reservoir.state_array[:, 0] # Plotting fig, ax = plt.subplots(2, 1, sharex=True, figsize=(10, 6)) ax[0].bar(x=range(len(precipitation)), height=precipitation, color='blue')