|
<< Click to Display Table of Contents >> Navigation: Users manual > Subroutines > User subroutines > Postprocessing user subroutines |
Post-processing subroutines are computed when the simulation is completed. In this case, to download a file containing the subroutine code, go to the Subroutines tab on the Initial data panel and click Add subroutine in the Subroutines menu that appears. The *.lua file can be located anywhere on the disk.
For a subroutine written in Lua to correctly interact with QForm UK, you need:
•Indicate for which object a calculation will be conducted. For the workpiece - set_target_workpiece(), for tools – set_target_tool();
|
Important |
|---|---|
Simulation of user subroutines that use the fields of stresses, strains and displacements in the tool is possible only after simulation the deformation of the workpiece with the Coupled deformation feature enabled |
|
•Specify user-defined fields by the function result();
•Specify, if necessary, additional input parameters by the function parameter();
•Create the function UserFields() , in which user-defined fields will be computed.
|
Important |
|---|---|
The letter case in the name of UserFields() function is critical, so using the names as Userfields() or userfields() is not allowed |
|
Let's consider an example - a subroutine that calculates the heating/cooling rate in a forged part during deformation:
1 2 3 4 5 6 7 |
|
set_target_workpiece() scale = parameter( "scale",1) rate_of_T = result( "rate_of_T",0) function UserFields(T, prev_T, dt) local rT = scale*(T - prev_T)/dt store(rate_of_T, rT) end |
Let's look at this code in detail:
set_target_workpiece()
Indicates the object with which the subroutine will operate.
scale = parameter("scale", 1)
Defines a scale parameter. The first argument of the function is the name of the parameter that will be displayed in the QForm UK interface, the second one is the default value of the parameter. The parameter value can be changed before running the subroutines via the QForm UK interface. Number of parameters is unlimited.
rate_of_T = result("rate_of_T", 0)
Defines a user-defined field to be calculated in the subroutine. The left part is the name of the variable to be written to. The first argument of the result() function is the name of a variable (which can only contain English letters and the underscore “_”), from which reading occurs in the QForm UK interface, as well as in the subroutine with the prefix _prev. It is recommended to set the same names for the write variable (on the left part) and the read variable. The second parameter is the initial value at the start time, which is optional.
|
Important |
The name of the variable intended for storing user data must not coincide with the names ofstandard variables |
|
function UserFields(T, prev_T, dt)
The UserFields() function calculates the user-defined field in each node of the forged part or tool. A list of input parameters may include the following:
•Standard variables such as T (temperature), strain_plast (plastic strain), etc.
•Names of standard fields in the previous step (for example, prev_strain_plast)
•Names of user-defined fields in the previous step (for example, prev_rate_of_T)
local rT = scale*(T - prev_T)/dt
Declaring a local variable and assigning a value to it using the mathematical operators available in the Lua language (refer to www.lua.ru/doc/5.6.html).
store(rate_of_T, rT)
The store() function – stores the value of a local variable in a user-defined field. The first argument is the name of the user-defined variable for saving (defined by the function result()). The second argument is the value of the user-defined field in the node, which can be a variable, function or expression.
end
An operator indicating the end of a function.