Templates#
Templates to generate python scripts.
User’s Guide#
The ScriptTemplate class provides a simple interface to generate python scripts from
templates.
CompressionTemplate#
- class CompressionTemplate(params: Optional[Union[Dict[str, Dict[str, Union[str, int, float, bool]]], PathLike, str]] = None)[source]#
This is a template for compression.
Examples
>>> from abqpy.template import CompressionTemplate >>> template = CompressionTemplate(params='params.toml') >>> template.write('script.py') >>> template = CompressionTemplate() >>> template.write('script.py', param1=1, param2=2)
Details of required parameters
- width#
- Type: float, defaults to 1.0
Width of the rectangle
- length#
- Type: float, defaults to 1.0
Length of the rectangle
- height#
- Type: float, defaults to 1.0
Height of the rectangle
- E#
- Type: float, defaults to 1.0
Young’s modulus
- nu#
- Type: float, defaults to 0.3
Poisson’s ratio
- timePeriod#
- Type: float, defaults to 1.0
Time period
- maxNumInc#
- Type: int, defaults to 1000
Maximum number of increments
- initialInc#
- Type: float, defaults to 0.1
Initial increment
- minInc#
- Type: float, defaults to 0.01
Minimum increment
- maxInc#
- Type: float, defaults to 1.0
Maximum increment
- pressure#
- Type: float, defaults to 1.0
Pressure
- mesh_size#
- Type: float, defaults to 0.1
Mesh size
- job_name#
- Type: str, defaults to Job-1
Job name
User config file (A toml or json file)
# User configuration file width = 1.0 length = 1.0 height = 1.0 E = 1.0 nu = 0.3 timePeriod = 1.0 maxNumInc = 100 initialInc = 1.0 minInc = 1.0e-6 maxInc = 1.0 pressure = 1.0 mesh_size = 0.1 job_name = 'Job-1'
The template source code
from abaqus import * from abaqusConstants import * from caeModules import * from driverUtils import * executeOnCaeStartup() # Model model = mdb.models['Model-1'] # Part sketch = model.ConstrainedSketch(name='sketch', sheetSize=1.0) sketch.rectangle((0, 0), ({{ width }}, {{ length }})) part = model.Part(name='part', dimensionality=THREE_D, type=DEFORMABLE_BODY) part.BaseSolidExtrude(sketch=sketch, depth={{ height }}) # Create sets part.Set(name='set-all', cells=part.cells.findAt(coordinates=(({{ width / 2 }}, {{ length / 2 }}, {{ height / 2 }}),))) part.Set(name='set-bottom', faces=part.faces.findAt(coordinates=(({{ width / 2 }}, {{ length / 2 }}, 0.0),))) part.Set(name='set-top', faces=part.faces.findAt(coordinates=(({{ width / 2 }}, {{ length / 2 }}, {{ height }}),))) part.Surface(name='surface-top', side1Faces=part.faces.findAt(coordinates=(({{ width / 2 }}, {{ length / 2 }}, {{ height }}),))) # Assembly model.rootAssembly.DatumCsysByDefault(CARTESIAN) model.rootAssembly.Instance(name='instance', part=part, dependent=ON) # Material material = model.Material(name='material') material.Elastic(table=(({{ E }}, {{ mu }}),)) material.Density(table=(({{ rho }},),)) # Section model.HomogeneousSolidSection(name='section', material='material', thickness=None) part.SectionAssignment(region=part.sets['set-all'], sectionName='section') # Step step = model.StaticStep(name='Step-1', previous='Initial', description='', timePeriod={{ timePeriod }}, timeIncrementationMethod=AUTOMATIC, maxNumInc={{ maxNumInc }}, initialInc= {{ initialInc }}, minInc= {{ minInc }}, maxInc= {{ maxInc }}) # Output request field = model.FieldOutputRequest('F-Output-1', createStepName='Step-1', variables=('S', 'E', 'U')) # Boundary condition bottom_instance = model.rootAssembly.instances['instance'].sets['set-bottom'] bc = model.DisplacementBC(name='BC-1', createStepName='Initial', region=bottom_instance, u3=SET) # Load top_instance = model.rootAssembly.instances['instance'].surfaces['surface-top'] pressure = model.Pressure('pressure', createStepName='Step-1', region=top_instance, magnitude={{ pressure }}) # Mesh elem1 = mesh.ElemType(elemCode=C3D8R) elem2 = mesh.ElemType(elemCode=C3D6) elem3 = mesh.ElemType(elemCode=C3D4) part.setElementType(regions=(part.cells,), elemTypes=(elem1, elem2, elem3)) part.seedPart(size={{ mesh_size }}) part.generateMesh() # Job job = mdb.Job(name='{{ job_name }}', model='Model-1') job.writeInput() # Submit the job job.submit() job.waitForCompletion() # Save abaqus model mdb.saveAs('compression.cae')
The template config file (A toml or json file)
# Define parameters for the template [width] type = "float" description = "Width of the rectangle" default = 1.0 min = 0.1 [length] type = "float" description = "Length of the rectangle" default = 1.0 min = 0.1 [height] type = "float" description = "Height of the rectangle" default = 1.0 min = 0.1 [E] type = "float" description = "Young's modulus" default = 1.0 min = 0.1 [nu] type = "float" description = "Poisson's ratio" default = 0.3 min = 0.0 max = 0.499 [timePeriod] type = "float" description = "Time period" default = 1.0 min = 0.0 [maxNumInc] type = "int" description = "Maximum number of increments" default = 1000 min = 10 [initialInc] type = "float" description = "Initial increment" default = 0.1 min = 0.0001 [minInc] type = "float" description = "Minimum increment" default = 0.01 min = 0.0001 [maxInc] type = "float" description = "Maximum increment" default = 1.0 min = 0.0001 [pressure] type = "float" description = "Pressure" default = 1.0 min = 0.0 [mesh_size] type = "float" description = "Mesh size" default = 0.1 min = 0.0001 [job_name] type = "str" description = "Job name" default = "Job-1"
ScriptTemplate#
- class ScriptTemplate(template: Union[PathLike, str], config: Optional[Union[Dict[str, Dict[str, Union[str, int, float, bool]]], PathLike, str]] = None, params: Optional[Union[Dict[str, Dict[str, Union[str, int, float, bool]]], PathLike, str]] = None)[source]#
A template class for Abaqus script.
Examples
>>> from abqpy.template import ScriptTemplate >>> template = ScriptTemplate(template='template.py', config='config.toml', params='params.toml') >>> template.write('script.py') >>> template = ScriptTemplate(template='template.py', config='config.toml') >>> template.write('script.py', param1=1, param2=2)
- check(correct_bounds=True, **kwargs)[source]#
Check if the parameters are valid, if valid, return the processed parameters as a dict.
- Parameters:
correct_bounds (
bool, optional) – Whether to correct the parameters to the bounds, by default True**kwargs – The parameters to check.
- Returns:
The original or corrected parameters.
- Return type:
Dict- Raises:
ValueError – If the parameters are invalid.