@@ -149,6 +149,110 @@ execution.step()
149149
150150Scenario manipulators are also supported
151151
152+ # Using ECCO algorithm
153+
154+ Libcosimpy supports ECCO (Energy-Conservation-based Co-Simulation) algorithm based on the work in [ 1] for adaptively
155+ updating the step size of the simulation. The algorithm uses the law of conservation of energy between FMU models that
156+ represent power bonds from bond graph theory.
157+
158+ ## Creating ECCO algorithm manually
159+ The parameters of the algorithm can be specified via the ` EccoParam ` class:
160+
161+ ``` python
162+ params = EccoParams(
163+ safety_factor = 0.8 ,
164+ step_size = 1e-4 ,
165+ min_step_size = 1e-4 ,
166+ max_step_size = 0.01 ,
167+ min_change_rate = 0.2 ,
168+ max_change_rate = 1.5 ,
169+ abs_tolerance = 1e-4 ,
170+ rel_tolerance = 1e-4 ,
171+ p_gain = 0.2 ,
172+ i_gain = 0.15 ,
173+ )
174+ ```
175+
176+ The algorithm be created via ` create_ecco_algorithm ` , which can be used to create a new execution instance:
177+
178+ ``` python
179+ # Create an algorithm instance
180+ ecco_algorithm = CosimAlgorithm.create_ecco_algorithm(params)
181+
182+ # Create execution
183+ execution = CosimExecution.from_algorithm(ecco_algorithm)
184+ ```
185+
186+ The power bond between models is represented by input and output connection pair between two models:
187+
188+ ``` python
189+ # Indicating a power bond between models (indicated by index chassis_index and wheel_index)
190+ ecco_algorithm.add_power_bond(
191+ chassis_index,
192+ chassis_v_out,
193+ chassis_f_in,
194+ wheel_index,
195+ wheel_f_out,
196+ wheel_v_in,
197+ )
198+ ```
199+
200+ The simulation is started as usual via ` simulate_until ` function from ` CosimExecution ` :
201+ ``` python
202+ execution.simulate_until(target_time = 10e9 )
203+ ```
204+
205+ See [ test_ecco_algorithm] ( tests/test_ecco_algorithm.py ) for detailed usage of ECCO algorithm.
206+
207+ ## Creating ECCO algorithm via system structure file
208+
209+ Alternatively, ECCO algorithm can also be created via system structure file:
210+ ``` xml
211+ <OspSystemStructure xmlns =" http://opensimulationplatform.com/MSMI/OSPSystemStructure" version =" 0.1" >
212+ ...
213+ <!-- Specify ecco algorithm -->
214+ <Algorithm >ecco</Algorithm >
215+ ...
216+ <Connections >
217+ <!-- Annotate variable connection as power bond via `powerBond` attribute. Specify
218+ causality of the variable (input or output) -->
219+ <VariableConnection powerBond =" wheelchassis" >
220+ <Variable simulator =" chassis" name =" velocity" causality =" output" />
221+ <Variable simulator =" wheel" name =" in_vel" causality =" input" />
222+ </VariableConnection >
223+ <VariableConnection powerBond =" wheelchassis" >
224+ <Variable simulator =" wheel" name =" out_spring_damper_f" causality =" output" />
225+ <Variable simulator =" chassis" name =" force" causality =" input" />
226+ </VariableConnection >
227+ </Connections >
228+ <!-- Specify ecco algorithm parameters -->
229+ <EccoConfiguration >
230+ <SafetyFactor >0.99</SafetyFactor >
231+ <StepSize >0.0001</StepSize >
232+ <MinimumStepSize >0.00001</MinimumStepSize >
233+ <MaximumStepSize >0.01</MaximumStepSize >
234+ <MinimumChangeRate >0.2</MinimumChangeRate >
235+ <MaximumChangeRate >1.5</MaximumChangeRate >
236+ <ProportionalGain >0.2</ProportionalGain >
237+ <IntegralGain >0.15</IntegralGain >
238+ <RelativeTolerance >1e-6</RelativeTolerance >
239+ <AbsoluteTolerance >1e-6</AbsoluteTolerance >
240+ </EccoConfiguration >
241+ </OspSystemStructure >
242+ ```
243+
244+ Then this file can be loaded via a usual way via ` CosimExecution.from_osp_config_file ` :
245+ ``` python
246+ execution = CosimExecution.from_osp_config_file(osp_path = " tests/data/fmi2/quarter_truck" )
247+ ```
248+
249+ See [ Quarter truck example] ( tests/data/fmi2/quarter_truck/OspSystemStructure.xml ) for detailed usage of ECCO algorithm via system structure file.
250+
251+
252+ ## Reference
253+ [ 1] Sadjina, S. and Pedersen, E., 2020. Energy conservation and coupling error reduction in non-iterative co-simulations. Engineering with Computers, 36, pp.1579-1587.
254+
255+
152256# Tests
153257
154258Tests can be run using the ` pytest ` command in the terminal. ` libcosimc ` log level for all tests can be set in the ` ./tests/conftest.py ` file.
0 commit comments