Skip to content

Automatic differentiation of functions called within equations #60

Open
@HildingElmqvist

Description

@HildingElmqvist

DAE index reduction requires that certain equations are differentiated versus time. The symbolic module of Modia contains partial differentiation of certain standard functions. A more general approach should be introduced for Modia. In particular, there will be many different fluid media functions calculating medium properties which needs to be differentiated.

The approach for Modelica is introduced in the paper Using Automatic Differentiation for Partial Derivatives of Functions in Modelica.

A good little first example might be the straightFlanksCam function which I translated to Julia:

function straightFlanksCam(
    theta::Float64;
    R1::Float64=1.0,   # Base circle radii
    R2::Float64=0.5,   # Nose radii
    d::Float64=2.0     # Centre distance
    )
    thetamod = atan(sin(theta), cos(theta)) # to get angle in interval -pi..pi
    fi0 = asin((R1 - R2)/d)
    if thetamod > 0
        fi1 = pi/2 - fi0 - thetamod
    else
        fi1 = - pi/2 + fi0 - thetamod
    end 
    fi2 = atan(R2*cos(fi0), d + R2*sin(fi0))
    if abs(thetamod) > pi/2-fi0
        x = R1*cos(theta)
        y = R1*sin(theta)
    elseif abs(thetamod) >= fi2
        L = R1/cos(fi1)
        x = L*cos(theta)
        y = L*sin(theta)
    else
        L = d*cos(abs(thetamod)) + sqrt(R2^2 - d^2*sin(abs(thetamod))^2)
        x = L*cos(theta)
        y = L*sin(theta)
    end
    return r = [x, y]
end

This function is not used for index reduction but shows another need, i.e. finding the direction of the force on a body, by finding the normal to a parametric surface.

Using AD techniques could initially be tested without integration in Modia.

@MartinOtter will provide other examples involving media functions.

CC: @crlaugh, @jrevels

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions