Paving the way for Hybrid Twins using Neural Functional Mock-Up Units

Neural Ordinary Differential Equations (NeuralODEs) open up the possibility to enhance the modeling of dynamical systems, in terms of prediction quality and computation time, as well as shortened development time. Port-ing NeuralODEs, the combination of an artificial neural network and an ODE solver, to real engineering applications is still a challenging venture. However, we will show that Neural Functional Mock-up Units (NeuralFMUs), an evolved subgroup of NeuralODEs that contain Functional Mock-up Units (FMUs), are able to cope with these challenges. This paper briefly introduces to the topics Neu-ralODE and NeuralFMU and describes the procedure and considerations to apply this technique to a real engineering use case. Further, different workflows to apply Neu-ralFMUs dependent on tool capabilities and use case requirements are discussed. The presented method is illustrated with the creation of a Hybrid Twin of an hydraulic excavator arm, which features various challenges such as discontinuity, nonlinearity, oscillations and characteristic maps. Finally, we will show that the Hybrid Twin created on basis of measurement data from a real system gives more accurate results compared to a conventional simulation model based on physical equations ( first principle model ).


Introduction
In the following sections, short introductions to the used techniques are given.

NeuralODE
Since their introduction in 2018, Neural Ordinary Differential Equations (NeuralODEs) (Chen et al. 2018)  Figure 1.The topology of a NeuralODE.On basis of the system state x x x(t) the ANN computes the system state derivative ẋ x x(t), which is numerically integrated into the next system state x x x(t + h) by the ODE solver with step size h.
ities with adjoint sensitivity analysis (Bittner 1963).As almost any other machine learning model for learning dynamic systems like recurrent neural networks or long short-term memory networks in (Champaney et al. 2022), plain NeuralODEs need a significant amount of data and are only able to learn physical effects that are represented as part of this data.In real world engineering, there is often far more system knowledge available, which is only partially included or not included at all in the NeuralODE training data set.This knowledge can be used to drastically improve training, by incorporating it into the Neu-ralODE model itself, for example in the form of differential equations.The resulting structure, consisting of ANNs, differential equations and a numerical ODE solver, is further referred to as Physics-enhanced Neural Ordinary Differential Equation (PeNODE) or synonymously hybrid NeuralODE (see Figure 2).
In this case, the ANN needs only to learn the missing physics that is not part of the system of differential equations.Compared to plain NeuralODEs, this allows for the use of smaller ANN topologies with less trainable parameters, which result in faster training times and often much better convergence.Further, introducing physical equations opens up to much better explainability regarding the learned process by the ANN, because a physical interpretation can be given for signals between ANN and physical equations.In practice, this incorporated knowledge might often be the part of the system that is well understood by the engineer and can therefore be modeled easily, for example the kinematics of an industrial robot, whereas the ANN has to learn the remaining physical effects that are challenging to model, like e.g. the friction behavior of the robot joints.

NeuralFMU
If the concept of a PeNODE shall be applied to real world engineering problems, another issue has to be faced: Physical models, designed in dedicated modeling tools, are not available in a symbolic representation of the equation system that can easily be used as parts of a PeNODE.Even if the symbolic ODE is accessible, large and complex systems often count thousands of equations, which is cumbersome to handle.Therefore, modeling PeNODEs on basis of large systems of equations, which are common in industrial applications, is not practicable out of the box.
Fortunately, this can be solved by deploying the model foundation not by a system of equations, but a handy container for such: The Functional Mock-up Unit (FMU) (Blochwitz et al. 2011).The FMU type Model-Exchange (ME) provides an interface in analogy to an ODE system: On basis of the current time t, the system state x x x(t) and optional inputs u u u(t), the system dynamics ẋ x x(t) are calculated.Comparing to the PeNODE model, instead of combining an ODE with an ODE solver and ANN, a ME-FMU is used.This topology (see Figure 3) is referred to as Neural Functional Mock-up Unit (NeuralFMU) and was introduced in (Thummerer, Kircher, and Mikelsons 2021).Because determination of the loss function gradient for NeuralFMUs (and NeuralODEs in general) is computationally expensive compared to gradient determination in plain ANNs without ODE solvers, efficient differentiation is a necessity to achieve an economic training (and therefore development) time.The Julia programming language (Bezanson et al. 2014) offers some of the most powerful frameworks for AD that implement a variety of different approaches, therefore the first library for building and training NeuralFMUs called FMIFlux.jl1 was implemented in this language.As a proof of concept for the applicability of NeuralFMUs in industrial applications, a vehicle longitudinal dynamics model for the prediction of an electric vehicle's energy consumption was enhanced in terms of result accuracy (Thummerer, Stoljar, and Mikelsons 2022).Further, the applicability to medical use cases was shown at the example of a hybrid simulation model of the human cardiovascular system (Thummerer, Tintenherr, and Mikelsons 2021).

Method
Deploying a NeuralFMU for a custom use case can be subdivided into three main tasks.First, the transfer of the First Principle Model (FPM) from modeling environment to the machine learning environment Julia (discussed in subsection 2.1).Second, the actual topology design and training of the NeuralFMU in Julia (subsection 2.2) and third, the reimport of the trained Hybrid Model (HM) from Julia into the original (or another) modeling or simulation environment (subsection 2.3).

From modeling environment to Julia
Because high performance differentiation is not available in most modeling tools, the FPM needs to be transferred from the original modeling tool into Julia (Thummerer, Stoljar, and Mikelsons 2022).This is achieved by using the FMU export functionality of the modeling tool to export an FMU and the Julia library FMI.jl 2 to import the FMU into Julia, see Figure 6 (step 1).After the import of the FPM FMU into Julia, the HM can be designed and trained.

Designing the topology
Basically, a wide range of topologies for NeuralFMUs are thinkable and designing a suitable one might not be intuitive.In the following, different aspects are highlighted and suggestions for decision-making based on requirements are given.

Sequential/Parallel
While the position of the numerical integrator in a Neu-ralODE is fixed, the positions of the FMU(s) and ANN(s) are not.Here, two main topologies can be distinguished.First, the elements can be connected sequentially, so one element is computing results on basis of intermediate results from another element, see Figure 4.A common usecase is an ANN, that corrects the system dynamics retrieved from an insufficient FMU model.Second, elements can be connected in parallel, so multiple elements  are computing results on basis of the same or different inputs, whereas the results need to be merged, as shown in the introduction in Figure 3.This approach is useful for example if the ANN needs to learn an effect that can be added to the existing dynamics (like many friction effects) or only a subpart of the state derivative vector shall be computed by the ANN, whereas the remaining part is determined by the ODE.
If no decision can be made on how the final effect will influence the system, e.g. because of lack of information regarding the unmodeled system part, both topologies can be used at once with minimal overhead: A topology using gates, as introduced in (Thummerer, Stoljar, and Mikelsons 2022) up to 1, but can be treated independently.Dependent on the status of the gates, different edge cases can be parameterized: • For p ANN = 0 and p FMU = 1, the system behaves like the original FMU without any ANN attached to it.
• For p ANN ̸ = 0 and p FMU = 0, the system behaves like a series connection of FMU and ANN.
• For p ANN ̸ = 0 and p FMU ̸ = 0, the system uses the FMU as well as the ANN dynamics.The ANN is able to manipulate the FMU dynamics (series) as well as learning its very own dynamics on given signals (parallel).
Finally, these gate parameters can be trained together with the ANN parameters and so bypass the initialization challenge of (physics-enhanced) NeuralODEs, which was further highlighted in (Thummerer, Stoljar, and Mikelsons 2022).

Data processing between FMUs and ANNs
FMUs and ANNs operate in different numerical ranges.
Whereas the signal interface of FMUs is basically only limited by Float64, ANNs suffer if layer inputs become too large or too small dependent on the used activation functions.Small values from the FMU may not sufficiently influence the ANN output, large values lead to saturation if activation functions with limited output are used, like tanh, sigmoid or relu.A straight forward workaround for this is to scale and shift the FMU's output values to fit the activation function of the ANN, which is further described in (Thummerer, Stoljar, and Mikelsons 2022).To restore signal ranges at the ANN outputs, a post-processing transformation can be added here.If the ANN input signals are matching the outputs, this transformation can be initialized as inverse of the pre-processing transformation.The parameters of these pre-and postprocessing operations can be initialized to suit known signal ranges and further be optimized together (as forward and reverse transformation) or separately (as individual transformations) with the ANN parameters to adapt well to changing signal ranges that might occur with further training convergence.

Signal selection
By design of the Functional Mock-Up Interface (FMI), different signals can be passed between FMU and ANN.Using all available FMU signals (in principle, any system variable can be retrieved by supported FMUs) results in suboptimal training performance, because unnecessary large Jacobian matrices need to be computed during training and the signal information is highly redundant, if besides system states and inputs further dependent variables are connected.Further, connecting signals that have no causal dependency on the physical effects being learned carries the risk of the ANN learning wrong correlations or at least delays training convergence.This motivates to define an efficient and minimal interface.A clever and automatic signal selection during training is an active topic of research.For now, choosing a small set of interface variables is driven by expert knowledge of the system and only some general instructions can be given.One is, that for higher order differential equations (mechanical system are usually modeled as second order ODEs), the order of differentiation of the ODE should be preserved (Thummerer, Stoljar, and Mikelsons 2022).This is achieved by preventing the ANN to modify the derivatives that are also states.For example, consider a translational mechanical system with the states position and velocity and the state derivatives velocity and acceleration.If the ANN is allowed to modify the entire derivative vector (here the velocity and the acceleration), the second order ODE disintegrates into a first order ODE, because the state velocity does not match the integrated acceleration anymore.This can be tackled by allowing the ANN to manipulate only the highest derivatives of the system, in the considered example the derivative acceleration, while passing the derivative velocity directly to the numerical integrator without modifications.

From Julia to modeling environment
After training, the HM needs to be reimported from Julia back into the original (or another) development tool.For this, three different approaches to integrate the newly learned dynamic effect into the original modeling environment are possible and explained in the following sub sections.

Export the HM as FMU
The entire HM, including the FPM as FMU, can be exported as FMU, see Figure 6 (step 2a).This approach is useful if model development has (almost) finished and no other modifications to the structure needs to be done or if the HM is being used in a different modeling tool that features another modeling language (but support for FMI).
From software side, this can be accomplished using the Julia library FMI.jl or the related sub-library FMIExport.jl3directly.An example on how to export NeuralFMUs as FMUs is part of the FMIExport.jlrepository.
From a technical perspective, the FPM FMU (the FMU exported from the original simulation model) is copied to the resources folder of the HM FMU (the FMU being exported from Julia) and most of the FMI functions of the HM FMU are directly connected to the embedded FPM FMU.Because these connections are implemented by redirecting function pointers, the execution performance of the hybrid FMU is only influenced by the ANN dynamics without overhead.To induce the modified dynamics to the HM FMU, some functions need to be extended, which is discussed in the following paragraphs at the example of model-exchange FMUs.

Getting system state derivative
The functions fmi2GetDerivatives (FMI2) and fmi3GetContinuousStateDerivatives (FMI3) need to return the dynamics of the entire HM instead of the FPM FMU.This can be simply achieved by obtaining the FPM FMU state derivative and passing it through the part of the HM topology, that modifies the system state derivative.Finally, the modified state derivatives are returned instead of the derivatives of the FPM FMU.

Setting system state
The functions fmi2SetContinuousStates (FMI2) and fmi3SetContinuousStates (FMI3) set a new state for the FPM FMU.If the system state is manipulated by the HM topology before being passed to the FPM FMU, the HM FMU state is not matching the FPM FMU state.As a consequence, a new state for the FPM FMU needs to be retrieved by optimization through the topology (Thummerer, Stoljar, and Mikelsons 2022).
Getting/Setting ANN parameters Before overwriting the corresponding functions, the model description needs to be extended by new parameter identifiers for the ANN parameters.After that, to be able to read and change the ANN parameterization, the functions fmi2GetReal and fmi2SetReal (FMI2) and fmi3GetFloat64 and fmi3SetFloat64 (FMI3) need to be overwritten to get and set corresponding ANN parameters.
Finally, further functions can be overwritten to add additional functionalities but are not highlighted at this point, for example function calls to fmi2GetDirectionalDerivatives (FMI2), fmi3GetDirectionalDerivatives and fmi3GetAdjointDerivatives (FMI3) can easily be chained to the Julia AD framework to efficiently retrieve partial derivatives.

Export the ANN only
Export as FMU By exporting only the trained ANN as FMU, the FPM can further be used in its original format, maintaining the white-box structure that is known by the modeling engineer, see Figure 6 (step 2b).Exporting ANNs as FMUs is supported by FMIExport.jl,an example is part of the library repository.
Export in a dedicated format Further, the ANN can be exported in a dedicated format instead of being compiled into an FMU, see Figure 6 (step 2c).Two different formats are discussed in the following.From a linguistic point of view, the Modelica language is capable of describing any operation that is performed by an ANN layer.Even more uncommon layers, like the gates layer used in the presented use case, can be expressed with simple mathematical operations and therefore with Modelica.Currently, the ANN is exported as Modelica model by hand, but an automated export is part of an upcoming research project.The Modelica ANN can easily be imported into tools that support the Modelica language.
Further, also the Open Neural Network Exchange4 (ONNX) can be used to export the ANN separately.ONNX is capable of describing conventional as well as custom layers, as long as they are subdivisible into primitive mathematical operations (like e.g. the gates layer).For Julia, an ONNX library is available, called ONNX-NaiveNASflux.jl5 , that is able to import and export ONNX models including custom layers.
Instead of exporting the ANN structure alongside with the identified parameters, it is also possible to export both elements separately.This can be achieved by importing the ANN topology in the original modeling environment and transferring the parameters separately via an arbitrary file format (like CSV, MAT or TXT).Proceedings of the Modelica Conference 2023 October 9-11, 2023, Aachen, Germany DOI 10.3384/ecp204141

Reintegration of the exported ANN in the original modeling environment
The exported formats (FMU, ONNX, Modelica) share the input and output structure.When reintegrating them into the original modeling environment they all behave like data driven sub-models such as characteristic maps.The connection to the original FPM depends on the modeling tool's specifics.If the targeted modeling environment is a Modelica tool, the following has to be considered: The inclusion of the modified dynamics into the original FPM is not straight forward since the original Modelica system is acausal.The definition of variables as states or state derivatives only takes place during compilation.To modify a variable's derivative prior to compilation means to modify/replace equations in the Modelica system.This becomes a limitation, since ...

• . . . component models could be protected,
• . . .there are multiple equations to replace or modify, so the solution is not unique, • . . .sometimes variables/equations do not even exist (but are only created during compilation).
Hence, in general the integration of a causal ANN into the acausal Modelica model is not straightforward, and remains a future research topic.

Experiments
In the experimental part, the NeuralFMU approach is applied to a subsystem of an excavator model.Figure 7 sketches the excavator arm and the considered subsystem.

Motivation
The model of the excavator was developed in Simula-tionX6 during the real excavator's setup period, in which the model was used to test an automatic steering controller.Now, during the operation of the excavator, the model shall be extended and used with measurement data as a Hybrid Twin to detect and predict faults (i.e.deviations, leaks in hydraulic components, etc.) (Gundermann et al. 2018).The Hybrid Twin concept enhances physicsbased models with real data from physical sensors to increase the model's accuracy and prediction capabilities (Chinesta et al. 2019).The advantage of the applied Hybrid Twin of the excavator -a condition monitoring system of the latter -is that the real system requires less scheduled maintenance while at the same time can be repaired in time before serious faults occur.One major prerequisite for detecting deviations using Hybrid Twins is that the simulated nominal behavior must match the measured data very accurately during operation.This can be acchieved by applying the NeuralFMU method to the system.The results for the bucket cylinder subsystem of the excavator (including reimport to the original model) are outlined below.

Model selection for NeuralFMU
The complete, comprehensive model of the excavator contains components of various domains of the SimulationX libraries, such as Multi Body Systems (MBS, i.e. 3D) and 1D mechanics, hydraulics and control signals.The real excavator is equipped with pressure and cylinder position   sensors, the signals of which can be recorded together with the control signals.This allows to collect data of the motion of a single cylinder as well as of the full motion of the excavator arm.Comparing model with data, one will find that there are deviations, e.g. between simulated and measured cylinder positions.
One source of deviation is the friction in the hydraulic cylinders, which is hard to model.Simple models are not able to describe the process accurately enough, sophisticated models are hard to parameterize, and the modeling task is even more complex since different parts in the cylinder system contribute to the effective friction force.To avoid the influence of interaction with connected components, the model is considered for each cylinder sepa-rately.Therefore, the bucket cylinder subsystem and attached mechanics are cut out of the full model and are used with the measured pressure signals in the cylinder chambers as inputs, to focus on the movement of the considered cylinder only.Figure 8 shows the submodel of the bucket cylinder and mechanics, which will be used in experiments, and be referred to as the First Principle Model (FPM).The model already includes some generic friction components -a pressure based force FR_CTL and a damper F_CTL_b, which prevents oscillations.The necessity of including or excluding such components will be examined below.
It shall be mentioned that similar submodels can be created for the other cylinders of the excavator arm, in which case there are more components on the lower end of the kinematic tree which affect the mass and momentum distribution.Note, that the system model is unstable if the center of mass of the rotated components lies above the joint around which the mechanical components rotate when extending or retracting the cylinder.This can lead to difficulties, e.g. when trying to fit the friction force for the boom cylinder.Even with submodels in a stable state, the fitting method is time-consuming and requires knowledge of engineers with system specific experience.
The cylinder chambers in Figure 8 are fed with nonconstant pressure signals, taken from real measurements shown in Figure 9.These pressure signals cause the piston in the cylinder to move.As mentioned, the simulated position deviates from the measurement, which can be seen in Figure 14 which spans the same time sequence.The position of the bucket cylinder will be used as training objective in the NeuralFMU optimization.Further, the measurement data is noisy and contains irregular deviations (e.g.position measurement around 470 s), which cannot be removed by standard filters.

The FMU of the Bucket model
For applying the NeuralFMU method, an FMU of the FPM is generated, with the top bucket cylinder position CTL.dx as the output y. Figure 10 shows two extractionretraction-cycles of the time segment used to train and test the NeuralFMU.For the NeuralFMU training, a single extraction-retraction-cycle ranging from 148 s to 205 s is selected from the data since it covers most of the possible dynamics of the measured series.A second cycle ranging from 205 s to 262 s is used for testing.Please note, that the amount of data for training is very small in terms of machine learning applications and should be increased to contain every aspect of the effect to be learned.Here however, it is shown that even small and incomplete data sets can be used to significantly improve the simulation model.
Table 1.FMU states x x x and output y.

Position
As shown in Table 1, the FMU has three states, which seems not intuitive, since the mechanical system (cf.Figure 8) has only one degree of freedom: the motion around the revolute joint in the four bar.The related states are the angle fourBar.q[2]and the corresponding angular velocity der(fourBar.q[2]).The third state connection12.xis the position of the 1D mechanical connection between force interface (CTL) and hydraulic cylinder port B, which is equivalent to the length of the bucket cylinder.This state is introduced since the 3D-1D force interface creates a constraint on the 1D velocity.Hence a differential equation for the 1D position (connection12.x)exists.Further, the bucket cylinder position CTL.dx is identical to the state connection12.x in the considered simulation range.Because of the zero-crossing behavior in der(fourBar.q[2]),the FMU has state events that must be handled during simulation to obtain correct simulation results (Blochwitz et al. 2011).

The definition of the ANN
The definition of the ANN topology bases on past experience and empirical hyper parameter tuning, and is considered as large enough to cover the dynamics, while being trainable in reasonable time.In addition to a core of two dense layers, pre-and post-processing layers are included, as shown in Figure 11.These shift and scale the value of all inputs to a distribution with mean 0 and standard deviation 1 to suit the applied activation function tanh of the first dense layer.The figure further shows the additional gates layer introduced in subsubsection 2.2.1 which allows efficient training of the unknown friction effect and a solvable initialization for the system.The final ANN topology with 91 parameters is shown in Table 2.
where x i 2 is the simulated bucket cylinder position connection12.xat time instant i, xi 2 the corresponding measured position, and n the number of compared measurement points.(Thummerer, Stoljar, and Mikelsons 2022).The current system state x x x and time t are passed to the FMU, which computes the system state derivative ẋ

Training and testing in Julia
x x.On basis of the state derivatives from FMU, only the revolute joint acceleration x1 is computed by the ANN (featuring pre-and post-processing layers) and linearly combined with the corresponding derivative from the FMU ẋ1 in the gates layer.The remaining FMU derivatives ẋ x x 2,3 only enter the ANN as inputs and are bypassed directly to the final derivative vector x x x, to preserve a second order ODE.3).

FPM without friction model
As introduced, another NeuralFMU is built using an FPM without friction components.Training and testing results for the same sequence are shown in Figure 13.These confirm the fact, that the NeuralFMU can be trained completely without friction components and the ANN can compensate the oscillations of the border-stable system.The loss function value of the NeuralFMU featuring the FPM without friction is 0.0327 m and therefore about 30 % higher than the one trained on basis of the FPM with friction for the same sequence (cf. in Table 3).The accuracy of the case without friction under the same training conditions is lower than the one implementing viscous damping, therefore the model with friction is used for the outlined application.In Figure 8, the extension and modifications of FPM by the ANN are highlighted with red boxes.The bottom right box shows state derivatives (derS), ANN, and modified state derivative of state x 1 (derS1mod).This modified derivative is fed into the modified fourBar component (also highlighted with red box).
The output of the HM with a simple friction model simulated in SimulationX in the interval from 50 s to 500 s is shown in Figure 14.The figure also shows that the bucket cylinder position can be reliably predicted in SimulationX for a measurement sequence that was not used to train and test the NeuralFMU.Comparing the results in the time interval for training and testing, the NeuralFMU shows the same cylinder position in Julia as well as in SimulationX for the original FPM and HM without friction, as can be seen when comparing results in SimulationX (Figure 14 and 15) with results in Julia (Figure 12 and 13).October 9-11, 2023, Aachen, Germany also confirms that the HM without friction is able to damp oscillations for the full measurement sequence.

Conclusion
We started by introducing the concept of a NeuralODE and adapted this machine learning model step by step to suit the requirements of industrial engineering applications, resulting in a so called NeuralFMU.We highlighted a generic workflow, that allows for NeuralFMU development in custom applications, dependent on tool capabilities and further model use.Finally, we exemplified the presented theory at a real engineering use-case: The modeling of a Hybrid Twin of a hydraulic bucket cylinder to be used for process and failure monitoring.
Next, additional features of the FMIFlux.jlpackage be investigated -input values to NeuralFMUs for interaction with other excavator components and the batching method for more effective training on a broader data base.Besides, we plan to apply the workflow to larger submodels and other examples, and to automate parts of the workflow where possible.For the excavator model, the final goal is the creation of the Hybrid Twin for the detection of malfuntions in the system.
Besides physical equations, further system knowledge in the form of ODE properties like stability, oscillation capability, stiffness as well as frequency and damping information can be integrated into the PeNODE training process in form of Eigen-informed NeuralODEs (Thummerer and Mikelsons 2023).All listed properties depend on the eigenvalue positions of the system model over time.By computing eigenvalues and rating their positions as part of the (or an additional) loss function, the desired ODE properties can be enforced for the considered Hybrid Twin and may further improve training and prediction.
are one of the key techniques for data driven modeling of physical systems.NeuralODEs consist of an Artificial Neural Network (ANN) that functions as the right-hand side of an Ordinary Differential Equation (ODE), together with an ODE solver to obtain the solution of the ODE, see Figure 1.Training such models on the ODE solution x x x requires (efficient) differentiation through the ODE solver by Automatic Differentiation (AD) or estimating sensitiv-

Figure 2 .
Figure 2.An example topology for a PeNODE.The system dynamics are determined by an ODE and an ANN, for which a variety of different interconnection topologies are possible.

Figure 3 .
Figure 3.An example topology for a ME NeuralFMU.In this specific case, the system dynamics are determined by an ME-FMU and an ANN in parallel.In general, a wide variety of different interconnection topologies is possible.

Figure 4 .
Figure 4.An example for a sequential NeuralFMU topology.

Figure 6 .
Figure 6.Comparison of different ways on how to deploy NeuralFMUs.Step (1) shows the export of the FPM as FMU from modeling environment and the import of the FMU into Julia.After hybrid modeling and training inside Julia, the entire HM can be exported as FMU (2a), only the ANN as FMU (2b) or a dedicated ANN format like Modelica or ONNX can be used for ANN export (2c).Dependent on the chosen exporting step, the further usability of the HM varies.

Figure 7 .
Figure 7. Sketch of the full excavator arm with all three cylinders.For the NeuralFMU approach, the subsystem controlled by the bucket cylinder (red box) is used.

Figure 8 .
Figure 8.The submodel of the bucket cylinder and mechanics in SimulationX.The model shows different domains (color marked): MBS mechanics (blue), 1D mechanics (green), hydraulics (red), signal blocks for measured pressures and initial position values (orange).The original FPM is shaded with the colors of the domains.The extension of the model to a Hybrid Model (cf.subsection 3.4) is highlighted by the red boxes.

Figure 9 .
Figure 9. Measured pressure signals p A and p B of the two cylinder chambers (normalized, units removed).

Figure 10 .
Figure 10.FMU states x x x (normalized, units removed) during training and testing.State events (discontinuities) are triggered whenever the cylinder reaches or leaves one of the end stops.In the graph, they are shown as gray-dashed horizontal lines.

Figure 11 .
Figure11.The topology of the used NeuralFMU using gates adapted from(Thummerer, Stoljar, and Mikelsons 2022).The current system state x x x and time t are passed to the FMU, which computes the system state derivative ẋx x.On basis of the state derivatives from FMU, only the revolute joint acceleration x1 is computed by the ANN (featuring pre-and post-processing layers) and linearly combined with the corresponding derivative from the FMU ẋ1 in the gates layer.The remaining FMU derivatives ẋx x 2,3 only enter the ANN as inputs and are bypassed directly to the final derivative vector xx x, to preserve a second order ODE.

Figure 12 .
Figure 12.Comparison of bucket cylinder position to data (top) and absolute deviation from data (bottom).The HM is modeled on basis of the FPM with simple friction.

Figure 13 .
Figure 13.Comparison of bucket cylinder position to data (top) and absolute deviation from data (bottom).The HM is modeled on basis of the FPM without friction.from 205 s to 262 s, shown in Figure 12.The test result shows that the loss function value of 0.0228 m doubled compared to the training sequence, but it is still three times smaller than the loss function value of 0.0696 m in Figure15

Figure 14 .
Figure14.Measured data and simulation results of FPM and HM for the bucket cylinder position for the entire measurement.The HM is modeled on basis of the FPM with simple friction.

Figure 15 .
Figure15.Measured data and simulation results FPM and HM for the bucket cylinder position, for the entire measurement.The HM is modeled on basis of the FPM without friction.

Table 2 .
Parameters of the NeuralFMU topology.

Table 3 .
Loss function values.Here, dxIn and dxOut are the state derivatives as calculated by the FPM and modified by the ANN, respectively.prePShift,prePScale,w1,b1,w2, b2, postPScale, postPShift and gates are the optimized parameters of the different layers.To include the ANN in the FPM, equations have to be modified (cf.Sec.2.3.2).In the bucket system (see Figure8), this affects only the equation which defines the angular acceleration in the four bar.The variables defining the FMU state derivatives (cf.Table1) are read from the model components (derS), and are passed as input into the ANN.The modified der(fourBar.q[2])enters the FourBar component as an input (named derS1mod) and is used instead of the original variable.The equation section in the four bar is modified as written below: Listing 1. Equation section of Modelica type of ANN preProcess = (dxIn+prePShift).* prePScale; Paving the way for Hybrid Twins using Neural Functional Mock-Up Units 148 Proceedings of the Modelica Conference 2023 October 9-11, 2023, Aachen, Germany