This section covers these example workflows:
You can find more example problems in the
INSTALLDIR\v242\ansys\bin\winx64\AITools\aml_examples
directory for
Windows or the INSTALLDIR\v242\ansys\bin\linx64\AITools\aml_examples
directory for Linux.
Defining a material model
#import ansys.mapdl.materials.aml as aml #import numpy as np #Material Definition mymaterial = aml.material(1) mylist = [10,-1,1e-3] myfld = dict() myfld['temp'] = 0.0 mymaterial.add_table("hype","moon",myfld,mylist) mymaterial.print("hype","moon")
Initializing the solve object to setup the material calls
mymaterial.initialize()
Setting up the state variables if needed
Material state is a dictionary object that represents the current state of the
material object and encapsulates current total strain, plastic strain, and other
material specific state variables. In this step, the currentstate
variable holds the material state object's data.
currentstate = mymaterial.get_state() currentstate.set_state['epto'] = [0.001, 0, 0, 0, 0, 0] mymaterial.set_state(currentstate)
Calling the driver and getting results
disp = 0.1 l1 = 1+disp l2 = (1/(l1))**0.5 #Set solution parameters solutiondata = dict() solutiondata['time'] = 101.0 solutiondata['timinc'] = 0.0 defgrad_t = [1,0,0,0,1,0,0,0,1] defgrad = [l1,0,0,0,l2,0,0,0,l2] outputstress = [] jacobian = [] mymaterial.initialize() [outputstress,jacobian,status] = mymaterial.evaluate(solutiondata,defgrad_t,defgrad) print("Stress is ", outputstress) jacobmatrix = np.array(jacobian) jacobmatrix = jacobmatrix.reshape((6,6)) print("Jacobian :") print(jacobmatrix) #get updated state currentstate = mymaterial.get_state() print(currentstate('epto'))
The aml.fit
class is equivalent to the TBFT
command but with a Python interface.
Defining a material model
myliste = [Ce1,Ce2] mylistb = [s1,s2] flddata = dict() flddata['temp'] = 0.0 material.add_table("elas","isot",flddata,myliste) material.print("elas","isot") material.add_table("plas","biso",flddata,mylistb) material.print("plas","biso")
Creating a fitting object and importing parameters
curvefit = aml.fit(1) curvefit.create_fit('myfit')
Adding experimental data
curvefit.add_experiment('unia','Ex4_biso.exp')
Fixing the parameters
curvefit.fix_parameter_value('myfit',1,True)
Performing the optimize operation
solpars = dict() solpars['numiterations'] = 20 solpars['errornorm'] = 1 solpars['rctolerance'] = 0.0 # Residual Change Tolerance solpars['cctolerance'] = 0.0 # curvefit.solve('myfit',solpars) curvefit.print()
Getting fitted parameter values and fitted values
coeffs = curvefit.get_parameter_values('myfit') print(curvefit.generate_fitted_data("myfit",expid))