First Order Reliability Method (FORM)¶
-
class
paransys.
FORM
¶ This class applies the First Order Reliability Method (FORM) inside Python using ParAnsys as a connection with ANSYS for evaluate FEM models.
It is possible to run simulations without using ANSYS, just defining the limit state equation and all variables.
This code was made following the ideia of ANSYS being a tool for getting the ultimate load of the structure. This works applying a displacement in the loaded node, and then getting the biggest reaction force on that node, following this way the limit state defined here is ‘R-S’, where R are the values get from ANSYS and S the values generated in Python. It’s also possible to work applying the true load on ANSYS, it’s just necessary to formulate a valid limit state equation.
Class methods:
-
ANSYS
(exec_loc=None, run_location='C:\\Programacao\\_MinhasBibliotecas\\paransys\\docs_sphinx\\ansys_anl\\', jobname='file', nproc=2, override=False, cleardir=False, add_flags='')¶ If ANSYS will be used it defines ANSYS properties, for initialize the paransys.ANSYS class.
- exec_locstr, obligatory
Location of ANSYS executable file.
- run_locationstr, optional
ANSYS working directory. Recomended to be a separated directory. Defaults to ansys_anl on current directory.
- jobnamestr, optional
ANSYS jobname. Defaults to ‘file’.
- nprocint, optional
Number of processors. Defaults to 2.
- overridebool, optional
Attempts to delete the .lock file at working directory. It’s useful when ANSYS was interrupted. Defaults to False
- cleardirbool, optional
Delete all the files from ANSYS working directory when call the Run command. Defaults to False
- add_flagsstr, optional
Additional flags to be called with ANSYS. If it’s an academic version use add_flags=’-aa_r’ Do not use ‘-b -i -o’ Flags can be found at https://www.sharcnet.ca/Software/Ansys/16.2.3/en-us/help/ans_ope/Hlp_G_OPE3_1.html
-
CreateVar
(name, distrib, mean, std=0, cv=None, par1=None, par2=None)¶ Create a Variable, random or not.
If it’s used on ANSYS it need to be told, so after this use:
>>> form.SetANSYSVar(name)
- namestr, obligatory
Name of variable.
- distribstr, obligatory
Probabilistic variable distribution type.
For all distributions Mean and Std are related to Normal distribution (the code determines the parameters for the desired distribution).
Available types are: * gaussian (or gauss, normal); * lognormal (or log, logn, ln, lognorm); * gumbel (or gumb, type1); * constant (or const) - Constant value (doesn’t need std).
- meanfloat, obligatory
Standard mean of variable values.
- stdfloat, optional
Standard deviation of variable. You must define it or cv for variables that aren’t constant, if both (cv and std) declared std will be used.
For LogNormal variables it’s recommend to use CV!
- cvfloat, optional
Coeficient of Variation of variable. You must define it or std for variables that aren’t constant, if both (cv and std) declared std will be used.
For LogNormal variables it’s recommend to use CV!
- par1 and par2float, optional
Parameters for future implementations.
-
ExportDataCSV
(filename, description=None)¶ Exports process data to a CSV file.
- filenamestr, obligatory
Name of file that will receive the values, doesn’t need the extension “.csv”, it will be placed automatically.
- descriptionstr, optional
A string that will be write in the beggining of the file.
-
Info
(act=False)¶ Turn on/off the return of the commands to Python.
- actbool, obligatory
True turn On and False turn Off the return of the commands to Python.
-
Options
(option, value=None)¶ Set extra options values.
- optionstr, obligatory
Name of option, listed next.
- valueoptional
Value to be set, type varies with option. If not defined it will return current value.
** Valid options:** For iHLRF method:
iHLRF_forced_lambdk : float Forced value when line search doesnt found a valid
lambdak
. Beinglambdak
the step size.It could be set as
'auto'
, when it is the complement of|y*.gradG|/(|y*|.|gradG|)
. Defaults to ‘auto’.iHLRF_prod_ck : float Scalar value that will be multiplied by calculated
ck
value. For a fixck
value turn it to 0 and then use ‘iHLRF_add_ck’.iHLRF_add_ck : float Scalar value that will be added to
ck
value.iHLRF_par_a : float Value presented as
a
in line search equation for iHLRF.iHLRF_par_b : float Value presented as
b
in line search equation for iHLRF,lambdak
value isb**nk
.iHLRF_step_lambdk_test : float Size of
lambdak
test block, after each block convergence is checked.
- For analyses using ANSYS:
APDLdebug: bool If it’s true it will be print the dict with results imported from ANSYS at each call. Great use for APDL debug.
** If an invalid option or value is set the process could stop (or not).**
-
Run
(maxIter=50, tolRel=0.01, tolLS='auto', dh=0.05, diff='forward', meth='iHLRF')¶ Run the FORM process.
- maxIterinteger, optional
Maximum of iterations that can be performed. After this the process will stop with error. Defaults to 50.
- tolRelfloat, optional
Maximum relative error tolerance, for example on search for X point
|X_k - X_(k-1)|/|X_(k-1)|<=tolRel
. Defaults to 0.005.- tolLSfloat, optional
Maximum absolute error tolerance for limit state function,
|G(X)|~=tolLS
. It should be calibrated based on the magnitude of limit state function.It’s possible to automatically determine it using tolLS=’auto’, it will be set as (tolRel)*(first cycle limit state value).
Defaults to ‘auto’.
- dhfloat, optional
delta_h step when applying derivatives, value applied over means, as h=mean(x)*dh, so,
f'(x) = (f(x+mean(x)*dh)-f(x)) / (mean(x)*dh)
. Defaults to 0.05.- diffstr, optional
Numeric derivative calcultation method. The possible mehtods are:
center: for finite difference method with central difference,
f'(x) = (f(x+h)-f(x-h)) / (2h)
, it needs1 + 2*Nvars
evaluations of the limit state function.forward: for finite difference method with forward difference,
f'(x) = (f(x+h)-f(x)) / h
, it needs1 + Nvars
evaluations of the limit state function.backward: for finite difference method with backward difference,
f'(x) = (f(x)-f(x-h)) / h
, it needs1 + Nvars
evaluations of the limit state function.Defaults to forward.
- methstr, optional
FORM method used. Available methods are:
HLRF: Hasofer Lind Rackwitz and Fiessler method.
iHLRF: improved Hasofer Lind Rackwitz and Fiessler method.
Defaults to iHLRF.
Returns a dictionary with:
status : integer Status of solution, values can be found after this list.
Pf : float Probability of failure.
Beta : float Reliability index.
{DesignPoint} : dictionary of values Dictionary with the design points for each variable.
{gradG} : dictionary of values Dictionary with the final gradient for each variable.
{alpha} : dictionary of values Dictionary with the final director cossines for each variable.
cycles : int Number of iterations performed to obtain the solution.
Status values:
0: no problem;
1: warning, maximum of cycles reached with no convergence of CVPf;
99: undefined error!
-
SetANSYSModel
(inputname, extrafiles=[], directory='C:\\Programacao\\_MinhasBibliotecas\\paransys\\docs_sphinx')¶ Set the input script file to be used on ANSYS and extra files that should be copied together. All this files must be in the same directory set in parameter directory.
- inputnamestr, obligatory
Name with extension of the script that will be executed in the analysis. The script must be done in function of the INPUT variables defined here, (as parameters of ANSYS), and must define/calculate ANSYS parameters with the results using the names defined here.
- extrafileslist of strings, optional
A list of strings containing extra files (with extension) that are necessary to run the script analys, could be an MODEL with the MESH already generated, for example. An example of extrafiles list is:
extrafiles = ['temps.txt', 'model1.ans', 'file.db']
- directorystr, optional
If the script is not in the current running Python directory you should place the entire location, if it’s in a subdirectory of current directory you can use ‘/dirname/filename.ext’. Defaults to current running Python directory.
-
SetANSYSOutVar
(name)¶ Defines a parameter/variable from ANSYS APDL script as an variable to return values for Python.
- namestr, obligatory
Variable/Parameter name, as defined in APDL script.
-
SetANSYSVar
(name)¶ Set a variable as ANSYS variable.
- namestr, obligatory
Name of variable.
-
SetCorrel
(var1, var2, correl)¶ Set the correlation betwen two variables. The values will be transformed by the Nataf process before running.
- var1str, obligatory
First variable name.
- var2str, obligatory
Second variable name.
- correlfloat, obligatory
Correlation betwen var1 and var2.
-
SetLimState
(equat, userf=None)¶ Set the limit state equation.
- equatobligatory
1) It could be a string with the equation of the limit state. It must be write as a function of defined variables (In and Out). 2) It could be a Python function created by the user, just passing the function name in the place of the string.
- userffunction, optional
An user defined function that could be used inside the limit state equation (string), called inside equat as
userf()
.It’s similar to use a function instead of a string in the equat parameter.
For example, you can create a complex Python function with loops, ifs and whatever for evaluate the R part of your limit state function for a concrete beam. An example is showed after.
First example: if ANSYS returns the maximum load on a truss as variable FxMAX, and applied loads to be tested are
(g+q)*sin(theta)
, whereg
,q
, theta are defined random variables created withCreateVar()
.form.SetLimState(equat='FxMAX-(g+q)*sin(theta)')
Note that you can use math expressions as
sin()
,cos()
,tan()
,sqrt()
from Python math module inside the equation.Second example: you have a steel bar in tension that hasn’t hardening. It’s stress is a function of
(eps, fy, E)
, whereeps
is current deformation,fy
is yield stress andE
the elastic moduli, you can create inside your code an function like:def stress(eps, fy, E): if eps > fy/E: return fy else: return eps*E
And now defining
userf=stress
we can:form.SetLimState(equat='userf(eps,fy,E)-q', userf=stress)
where
eps
,fy
,E
andq
are random variables. Note that the function inside the limit state equation should be called asuserf()
with the parameters fromstress
.Or we can do the same using the functions instead of the string:
form.SetLimState(equat=stress)
-
SetStartPoint
(name, value)¶ Set the point, for each variable, that process will start. If it’s not declared it will start with the mean value.
- namestr, obligatory
Variable name.
- valuefloat, obligatory
Starting point for this variable.
-