HyperWorks Solvers

POST_SUB

POST_SUB

Previous topic Next topic No expanding text in this topic  

POST_SUB

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

Subroutine Type

Modeling

Definition

Used to extract MotionSolve results.

Use

To generate an output file or process the results programmatically, in other words, for
real-time animation or plotting.

 

<Post_UserAPI

    usrsub_param_string = "USER()"

    usrsub_dll_name     = "ms_csubdll"

    usrsub_fnc_name     = "POST_SUB"

/>

Calling Syntax

Fortran

SUBROUTINE POST_SUB (TIME, IFLAG, INTERPOLATION_FLAG)

 

C

void STDCALL POST_SUB (double *time, double *par, int *npar, int *iflag, int *endflag, int *errflg)

 

Python

def POST_SUB(time, par, npar, iflag, endflag):

    return errflg

 

MATLAB

function errflg = POST_SUB(time, par, npar, iflag, endflag)

Input Arguments

[double precision] TIME

The current simulation time.

 

[logical] IFLAG

The initialization flag.

 

[logical] INTERPOLATION_FLAG

The interpolation flag.

Output Values

None.

Comments

1.The Post_Sub is called by MotionSolve at the same time steps when data is written to the MRF file during the simulation.
2.From within Post_Sub, you may also call the other available utility subroutines, such as MODFNC.

Example

The following example writes the X,Y,Z and Euler parameters for each rigid body in the model at each time step into a results XML file:

<Post_UserAPI

    usrsub_param_string = "USER()"

    interpreter         = "Python"

    script_name         = "/post_sub.py"

    usrsub_fnc_name     = "POST_SUB"

/>

The contents of post_sub.py are:

NULL = 0

fout = NULL

nparts = 0

partids = []

 

def POST_SUB(time, par, npar, iflag, endflag):

    global NULL

    global fout

    global nparts

    

    if endflag!=0:

        # Wrap up

        if fout!=NULL:

            fout.write("</MultiBodyResults>\n")

            fout.close()

            del fout

            fout = NULL

        if partids!=[]:

            del partids

            partids  = []

        return 0

 

    if iflag!=0:

        outfile = py_gtonam()

        outfile += "_res.xml"

        fout = open(outfile,"w")

        # XML Header

        fout.write("<?xml version=\"1.0\"?>\n")

        fout.write("<MultiBodyResults>\n")

        # Get ID information

        nparts = py_getnumid("PART")

        if nparts!=0:

            [partids, err_flg] = py_getidlist("PART",nparts)

            if err_flg < 0:

                return err_flg

    else:

        if fout==NULL:

            print "Output file was not opened, no results will be written\n"

            return -1

        fout.write("\t<Results\n")

        fout.write("\t\ttime    = \"%f\">\n" % time)

        # Rigid Body

        for i in range(nparts):

          [grndflag, info] = py_modfnc("Body_Rigid", partids[i], "IsGround")

          if grndflag=="FALSE":

              states = py_get_post_states("PART", partids[i])

              fout.write("\t\t<RigidBody\n")

              fout.write("\t\t\tid      = \"%d\"\n" % partids[i])

              fout.write("\t\t\tx       = \"%-11.8G\"\n" % states[0])

              fout.write("\t\t\ty       = \"%-11.8G\"\n" % states[1])

              fout.write("\t\t\tz       = \"%-11.8G\"\n" % states[2])

              fout.write("\t\t\te0      = \"%-11.8G\"\n" % states[3])

              fout.write("\t\t\te1      = \"%-11.8G\"\n" % states[4])

              fout.write("\t\t\te2      = \"%-11.8G\"\n" % states[5])

              fout.write("\t\t\te3      = \"%-11.8G\"\n" % states[6])

              fout.write("\t\t/>\n")

    return 0

See Also:

Modeling Subroutines