@@ -116,7 +116,7 @@ my_model.edit_triad(t3, load={'Tz' : my_model.make_function('Wheel force', tag='
116116# Ouput sensors
117117my_model.make_sensor(' Damper force' , (s1, d1), FmVar.FORCE , tag = ' damper_force' )
118118my_model.make_sensor(' Damper deformation' , s1, FmVar.DEFLECTION , tag = ' damper_deformation' )
119- my_model.make_sensor(' Steering pin deflection' , t0, FmVar.POS , FmDof.TZ , tag = ' pin_deflection' )
119+ my_model.make_sensor(' Steering pin deflection' , t0, FmVar.POS , FmDof.TZ , ' pin_deflection' )
120120
121121my_model.fm_solver_setup(t_inc = 0.005 , t_end = 2.5 , t_quasi = - 1.0 )
122122my_model.fm_solver_tol(1.0e-6 ,1.0e-6 ,1.0e-6 )
@@ -142,7 +142,7 @@ You find this in the *File* menu (*File --> Export --> Export Digital Twin...*).
142142
143143This dialog box shows three alternative ways of exporting the model,
144144but only the ** FMU** option is relevant here. So enable that toggle.
145- Then use the ** Browse...** button to selected the name for the fmu-file.
145+ Then use the ** Browse...** button to select the name for the fmu-file.
146146In the right side of the dialog, you find a list of the input- and output
147147indicators in the model, corresponding to the external functions
148148and output sensors defined in the modelling script.
@@ -232,9 +232,10 @@ Use this as a template for more advanced co-simulation tasks with FEDEM FMUs.
232232[ Download...] ( linked_files/run_fedem_fmu.py )
233233
234234``` python
235- from fmpy import fmi2, read_model_description, extract
236- from pandas import read_csv
237235from sys import argv
236+ from os import path
237+ from pandas import read_csv
238+ from fmpy import fmi2, read_model_description, extract
238239
239240
240241def run (fmu_file , input_file = None , instance_name = " my instance" ):
@@ -249,6 +250,11 @@ def run(fmu_file, input_file=None, instance_name="my instance"):
249250 print (" Extracting" , fmu_file, " ..." )
250251 unzipdir = extract(fmu_file)
251252
253+ # Get absolute path of input_file because the fmu.instantiate() call
254+ # will change the working directory
255+ if input_file is not None :
256+ input_file = path.abspath(input_file)
257+
252258 # Setup the FMU
253259 print (" Setup the FMU" , model.coSimulation.modelIdentifier)
254260 fmu = fmi2.FMU2Slave(guid = model.guid, unzipDirectory = unzipdir,
@@ -263,16 +269,15 @@ def run(fmu_file, input_file=None, instance_name="my instance"):
263269 num_inputs = num_params[0 ] # Number of input sensors
264270 num_output = num_params[1 ] # Number of output sensors
265271
266- # Read the input values into a Dataframe
267- if input_file is None :
268- inputs = None
269- elif num_inputs > 0 :
270- inputs = read_csv(input_file, sep = " \t " )
272+ if input_file is None or num_inputs < 1 :
273+ inputs = None # All inputs are assumed defined internally in the model
274+ else : # Read the input values into a Dataframe
275+ inputs = read_csv(input_file, sep = " ," )
271276
272277 # List of external function indices
273- inpIdx = range (num_inputs)
278+ inp_idx = range (num_inputs)
274279 # List of output sensor indices
275- outIdx = range (num_inputs,num_inputs+ num_output)
280+ out_idx = range (num_inputs, num_inputs+ num_output)
276281
277282 # Time loop, this will run through the FEDEM simulation
278283 # using the time domain setup of the model file used to export the FMU.
@@ -282,13 +287,13 @@ def run(fmu_file, input_file=None, instance_name="my instance"):
282287 while not fmu.getBooleanStatus(fmi2.fmi2Terminated):
283288 if inputs is not None : # Set external function values for next step
284289 # First column of inputs is not used, assuming it contains the time
285- fmu.setReal([* inpIdx ], inputs.iloc[step].tolist()[1 :])
290+ fmu.setReal([* inp_idx ], inputs.iloc[step].tolist()[1 :])
286291
287292 fmu.doStep(0.0 , 0.0 ) # Advance the simulation on step
288293
289294 step += 1
290295 time = fmu.getRealStatus(fmi2.fmi2LastSuccessfulTime)
291- output = fmu.getReal([* outIdx ])
296+ output = fmu.getReal([* out_idx ])
292297 print (f " Here are the outputs at step= { step} time= { time} : " , output)
293298
294299 # Finished, close down
0 commit comments