🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

User defined function not working

User: "sudo"
Altair Community Member

I have created a sample user defined function used in a solver variable in motionsolve.

Here is how I did it:

image.png

Here is the py code:

image.png

I tried to run the simulation and plot the results, however I am getting a value of 0 in the primary pulley radius throughout the simualation.

Sort by:
1 - 3 of 31
    User: "GTT Adam"
    Altair Employee
    Accepted Answer

    Hi @sudo,

    I believe that an array must be returned and not a single parameter. If we look at the example provided in MV-1203, they show the following syntax:

    def REQSUB(id, time, par, npar, iflag):
    [D, errflg] = py_sysfnc("DM",[par[0],par[1]]) ## sets "D" as piston
    displacement mag

    result = [0,D,0,0,0,0,0,0] ## lists results for output
    return

    return result ## sends list with results to motionsolve as
    output

    In this example, we can see that the distance measurement is returned as an array called 'result' with 8 inputs. I would try to return your 'result' as an array as well.

    Hope this helps!

    Adam Reid

    User: "sudo"
    Altair Community Member
    OP
    Updated by sudo

    Thanks @GTT Adam .

    Also I noticed that this function is being called just once at the start of the simulation. Would it be possible to call it everystep of the simulation so that I would get the updated values of the parameters that I am passing to the user defined function?

    User: "GTT Adam"
    Altair Employee

    Hi @sudo,

    Since your User Defined Function does not have any inputs, it may only calculate it once. I would try to pass in a dummy parameter so that it tries to calculate something.

    Try passing in USER(34) in the function and instead of result = 34, replace it with result = [0, par[0], 0,0,0,0,0,0]

    Hope this helps!

    Adam Reid