Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_simulate_sample_system_with_parameters(self):
ssv_filename = self.ssp_example_path('SampleSystemParameterValues.ssv')
parameter_set = read_ssv(ssv_filename)
filename = self.ssp_example_path('SampleSystem.ssp')
sine = lambda t: np.sin(t * 2 * np.pi)
result = simulate_ssp(filename, stop_time=1.0, step_size=0.01, parameter_set=parameter_set, input={'In1': sine})
# check if the input has been applied correctly
self.assertTrue(np.all(np.abs(result['In1'] - sine(result['time'])) < 0.01))
def test_simulate_sub_system(self):
ssp_filename = self.ssp_example_path('SampleSystemSubSystem.ssp')
sine = lambda t: np.sin(t * 2 * np.pi)
result = simulate_ssp(ssp_filename, stop_time=1.0, step_size=0.01, input={'In1': sine})
# check if the input has been applied correctly
self.assertTrue(np.all(np.abs(result['In1'] - sine(result['time'])) < 0.01))
from fmpy.ssp.simulation import simulate_ssp
from fmpy.util import plot_result
#model_name = "HelloWorld"
#mo_file = "/var/oscli/clones/openstudio-workflow/lib/openstudio/workflow/jobs/HelloWorld.mo"
ssp_filename = sys.argv[1]
run_dir = sys.argv[2] + '/FMU'
fmu_start_time = int(sys.argv[3])
fmu_stop_time = int(sys.argv[4])
fmu_time_step = int(sys.argv[5])
os.mkdir(run_dir)
os.chdir(run_dir)
print("os.getcwd():", os.getcwd())
print("Simulating %s..." % ssp_filename)
result = simulate_ssp(ssp_filename, start_time=fmu_start_time, stop_time=fmu_stop_time, step_size=fmu_time_step, run_dir=run_dir)
show_plot=True
if show_plot:
dir, _ = os.path.split(run_dir)
save_name = dir + '/ssp.png'
save_name2 = dir + '/temp.png'
print("Plotting results in directory:",save_name)
print("run_dir:",run_dir)
#plot_result(result, names=['space.electric_demand', 'space.district_heating', 'space.district_cooling'], window_title=ssp_filename, filename=save_name)
#plot_result(result, names=['space.zone_temp'], window_title=ssp_filename, filename=dir + '/temp.png')
fig1 = pl.figure()
ax1 = fig1.add_subplot()
ax1.plot(result['electric.y'], 'b--')
ax1.plot(result['space.district_heating'], 'r')
ax1.plot(result['space.district_cooling'], 'g')
print("os.environ:", os.environ)
import matplotlib
matplotlib.use('Agg')
from fmpy.ssp.simulation import simulate_ssp
from fmpy.util import plot_result
#model_name = "HelloWorld"
#mo_file = "/var/oscli/clones/openstudio-workflow/lib/openstudio/workflow/jobs/HelloWorld.mo"
ssp_filename = sys.argv[1]
run_dir = sys.argv[2] + '/FMU'
os.mkdir(run_dir)
os.chdir(run_dir)
print("os.getcwd():", os.getcwd())
print("Simulating %s..." % ssp_filename)
result = simulate_ssp(ssp_filename, stop_time=12960000, step_size=600)
show_plot=True
if show_plot:
dir, _ = os.path.split(run_dir)
save_name = dir + '/ssp.png'
print("Plotting results in directory:",save_name)
print("run_dir:",run_dir)
plot_result(result, names=['time', 'space.TRooMea'], window_title=ssp_filename, filename=save_name)
print('result: ', result)
print('Done.')
print("os.environ:", os.environ)
import matplotlib
matplotlib.use('Agg')
from fmpy.ssp.simulation import simulate_ssp
from fmpy.util import plot_result
#model_name = "HelloWorld"
#mo_file = "/var/oscli/clones/openstudio-workflow/lib/openstudio/workflow/jobs/HelloWorld.mo"
ssp_filename = sys.argv[1]
run_dir = sys.argv[2] + '/FMU'
os.mkdir(run_dir)
os.chdir(run_dir)
print("os.getcwd():", os.getcwd())
print("Simulating %s..." % ssp_filename)
result = simulate_ssp(ssp_filename, stop_time=12960000, step_size=600)
show_plot=True
if show_plot:
print("Plotting results...")
dir, _ = os.path.split(ssp_filename)
save_name = dir + 'ssp.png'
plot_result(result, names=['time', 'space.TRooMea'], window_title=ssp_filename, filename=save_name)
print('result: ', result)
print('Done.')
def simulate_controlled_drivetrain(show_plot=True):
""" Download and simulate ControlledDrivetrain.ssp
Parameters:
show_plot plot the results
"""
ssp_filename = r'ControlledDrivetrain.ssp'
download_file('https://github.com/CATIA-Systems/FMPy/releases/download/v0.1.1/' + ssp_filename, checksum='45e667ed')
print("Simulating %s..." % ssp_filename)
result = simulate_ssp(ssp_filename, stop_time=4, step_size=1e-3)
if show_plot:
print("Plotting results...")
plot_result(result, names=['reference.y', 'drivetrain.w', 'controller.y'], window_title=ssp_filename)
print('Done.')
return result