I'm using a CombiTable2D to describe a variable z as a function of two variables, x and y:
z = f(x, y)
I need to obtain the partial derivatives of z with respect to x and y to use them in the equations defining my model. I couldn't find a straightforward way to achieve this.
I tried using a Modelica function, but I couldn't define a function that uses a CombiTable2D. I also looked into the internals of CombiTable2D and found the getDerTable2DValue function, which seems related to derivatives, but I couldn't determine how to use it for my purpose.
As a workaround, I'm currently computing the derivatives myself using Excel and writing them into two separate tables, dfdx and dfdy. I then save these tables in a .txt file and load them using two separate CombiTable2D objects, one for each derivative.
I expect to get a way so that Modelica computes the partial derivative wrt the table parameters.
This quick solution seems to be working:
block toto
extends Modelica.Blocks.Tables.CombiTable2Ds;
Modelica.Blocks.Interfaces.RealOutput y_der1 annotation (Placement(transformation(extent={{100,-50},{120,-30}}), iconTransformation(extent={{100,-50},{120,-30}})));
Modelica.Blocks.Interfaces.RealOutput y_der2 annotation (Placement(transformation(extent={{100,-90},{120,-70}}), iconTransformation(extent={{100,-90},{120,-70}})));
equation
y_der1 = Modelica.Blocks.Tables.Internal.getDerTable2DValue(
tableID,
u1,
u2,
1,
0);
y_der2 = Modelica.Blocks.Tables.Internal.getDerTable2DValue(
tableID,
u1,
u2,
0,
1);
annotation (uses(Modelica(version="4.0.0")));
end toto;
The obtained derivatives in the case of a linear interpolation seem to be the ones located on the right side of the node if you evaluate the derivatives on a node. But with Akima splines, I obtained consistent results.
I only ran quick tests, so let me know if it works for you.