Preprocessing¶
Tcl to Python¶
- opstool.pre.tcl2py(input_file, output_file, prefix='ops', encoding='utf-8', keep_comments=False)[source]¶
Convert OpenSees
Tclcode to OpenSeesPyPythonformat.Note
This function supports
Tclsyntax and will flatten yourTclcode, includingloops,judgments,assignments,proc, etc.,Do not use assignment statements for OpenSees commands, such as
set ok [analyze 1],set lambdaN [eigen 10], it will trigger an error! This is because this function does not run the OpenSees command at all.If an encoding error is reported, please check the file and delete any special characters that exist, such as some Chinese characters that cannot be encoded.
Parameters¶
- input_filestr
The name of input
.tclfile.- output_filestr
The name of output
.pyfile.- prefixstr, optional
prefix name of openseespy, by default
ops. I.e.,import openseespy.opensees as ops. If None or void str ‘’, the prefix is not used. I.e.,from openseespy.opensees import *.- encoding: str, optional
file encoding format, by default “utf-8”.
- keep_comments: bool, optional
Comments are preserved, by default False. Note that this parameter will replace all opensees commands in the comment line, if any.
Remove void nodes¶
Generate gravity load¶
- opstool.pre.gen_grav_load(exclude_nodes=None, direction='Z', factor=-9.81)¶
Applying the gravity loads.
Note
The mass values are from
nodeMass(nodeTag)command, i.e., ones set inmass()command.Parameters¶
- exclude_nodes: list, default=None
Excluded node tags, whose masses will not be used to generate gravity loads.
- direction: str, default=”Z”
The gravity load direction.
- factor: float, default=-9.81
The factor applied to the mass values, it should be the multiplication of gravitational acceleration and directional indicators, e.g., -9.81, where 9.81 is the gravitational acceleration and -1 indicates along the negative Z axis. Of course, it can be multiplied by an additional factor to account for additional constant loads, e.g., 1.05 * (-9.81).
Returns¶
None
Transform beam uniform and point load from global to local coordinate system¶
- opstool.pre.transform_beam_uniform_load(ele_tags, wx=0.0, wy=0.0, wz=0.0)[source]¶
Transforms a uniformly distributed beam load from the global coordinate system to the local coordinate system. :rtype:
NoneNote
This function will automatically call the EleLoad Command to generate element loads. However, you need to create
timeSeriesand loadpatternobjects externally in advance. The load generated by this function will belong to the load pattern closest to it.Parameters¶
- ele_tagsint, list, tuple, np.ndarray
Beam element tags.
- wxfloat, list, np.ndarray, default=0.0
Uniformly distributed load in the global X direction. If a list or numpy array is provided, the length should be the same as the number of elements.
- wyfloat, list, np.ndarray, default=0.0
Uniformly distributed load in the global Y direction. If a list or numpy array is provided, the length should be the same as the number of elements.
- wzfloat, list, np.ndarray, default=0.0
Uniformly distributed load in the global Z direction. If a list or numpy array is provided, the length should be the same as the number of elements.
- opstool.pre.transform_beam_point_load(ele_tags, px=0.0, py=0.0, pz=0.0, xl=0.5)[source]¶
Transforms point loads for beam elements from global to local coordinates.
- Return type:
None
Parameters¶
- ele_tagsint, list, tuple, np.ndarray
Beam element tags.
- pxfloat, list, np.ndarray, default=0.0
Point load in the global X direction. If a list or numpy array is provided, the length should be the same as the number of elements.
- pyfloat, list, np.ndarray, default=0.0
Point load in the global Y direction. If a list or numpy array is provided, the length should be the same as the number of elements.
- pzfloat, list, np.ndarray, default=0.0
Point load in the global Z direction. If a list or numpy array is provided, the length should be the same as the number of elements.
- xlfloat, list, np.ndarray, default=0.5
The position of the point load along the beam element in a local coord system. If a list or numpy array is provided, the length should be the same as the number of elements.
Transform surface uniform load from local to global coordinate system¶
- opstool.pre.transform_surface_uniform_load(ele_tags, p=0.0)[source]¶
Converts uniform surface loads into equivalent nodal forces in the global coordinate system. According to the static equivalence principle, the distributed load is equivalent to the node load. :rtype:
NoneNote
This function will automatically call the NodalLoad Command to generate nodal loads. However, you need to create
timeSeriesand loadpatternobjects externally in advance. The load generated by this function will belong to the load pattern closest to it.Parameters¶
- ele_tagsint, list, tuple, np.ndarray
Surface element tags.
- pfloat, list, np.ndarray, default=0.0
Uniform surface load magnitude (per unit area) along the surface normal direction. The positive direction of the normal is obtained by the cross-product of the I-J and J-K edges. If a list or numpy array is provided, the length should be the same as the number of elements.
Model Mass¶
- class opstool.pre.ModelMass[source]¶
A class used to generate node masses. Element mass is distributed equally to each connected node.
- add_node_mass(node_tag, mass)[source]¶
Add mass to the existing node mass.
Parameters¶
node_tag: int, node tag. mass: float, mass value.
Returns¶
None
- add_mass_from_line(ele_tags, rho, area)[source]¶
Add mass from two-node line elements.
Parameters¶
- ele_tags: Union[list, int]
Element tag or list.
- rho: Union[list, float]
Mass density or list, if list length shoud same as ele_tags.
- area: Union[list, float]
Cross-sectional area or list, if list length shoud same as ele_tags.
- add_mass_from_surf(ele_tags, rho, d)[source]¶
Add mass from a planar element, including shell.
Parameters¶
- ele_tags: Union[list, int]
Element tag or list.
- rho: Union[list, float]
Mass density or list, if list length shoud same as ele_tags.
- d: Union[list, float]
Element thickness or list, if list length shoud same as ele_tags.
- add_mass_from_brick(ele_tags, rho)[source]¶
Add mass from tetrahedral or hexahedral elements.
Parameters¶
- ele_tags: Union[list, int]
Element tag or list.
- rho: Union[list, float]
Mass density or list, if list length shoud same as ele_tags.
- property nodal_mass¶
Returns:¶
- nodal_mass: dict[int, float]
The nodal mass dict, the key is nodeTag, value is nodal mass.
- generate_ops_node_mass()[source]¶
Call the OpenSeesPy node
masscommand to generate all node masses. The inertia moment of the rotational dof will be ignored.Note
This function will use the
masscommand to generate a lumped mass matrix, and does not apply it repeatedly with the mass parameters when the element is defined. This means that if you use this function, please ignore the mass parameter in the element definition, such as the'-mass'option of somebeam--columnelements, and thedensityparameter innDMaterial.Returns¶
None
- generate_ops_gravity_load(direction, factor=-9.81, exclude_nodes=None)[source]¶
Call the OpenSeesPy
loadcommand to generate a nodal gravity load.Parameters¶
- direction: str,
The gravity load direction.
- factor: float, default=-9.81
The factor applied to the mass values, it should be the multiplication of gravitational acceleration and directional indicators, e.g., -9.81, where 9.81 is the gravitational acceleration and -1 indicates along the negative Z axis. Of course, it can be multiplied by an additional factor to account for additional constant loads, e.g., 1.05 * (-9.81).
- exclude_nodes: list, default=None
Excluded node tags, whose masses will not be used to generate gravity loads.
Returns¶
None
Gmsh to OpenSeesPy¶
- class opstool.pre.Gmsh2OPS(ndm=3, ndf=3)[source]¶
Generate OpenSees code from GMSH.
Parameters¶
- ndm: int, default=3
Model dimension
- ndf: int, default=3
Number of degrees of freedom.
- set_output_file(filename='src.tcl', encoding='utf-8')[source]¶
Parameters:¶
- filename: str, default = “src.tcl”.
The output file-path-name must end with
.tclor.py.- encoding: str, default = “utf-8”.
The file encoding.
- read_gmsh_file(file_path, encoding='utf-8', print_info=True)[source]¶
Read an
.mshfile generated byGMSH.Note
You only need to use one of
read_gmsh_fileandread_gmsh_data.read_gmsh_fileis used to read data from the.mshfile, andread_gmsh_datais used to read data from the runtime memory.Parameters¶
- file_path: str
the file path.
- encoding: str, default=’utf-8’
The file encoding.
- print_info: bool, default=True
Print info.
- read_gmsh_data(print_info=True)[source]¶
Read data from
GMSHat runtime.Note
When using a command such as
gmsh.finalize()to close gmsh, you need to use it after this command, otherwise the data cannot be read.You only need to use one of
read_gmsh_fileandread_gmsh_data.read_gmsh_fileis used to read data from the.mshfile, andread_gmsh_datais used to read data from the runtime memory.
Parameters¶
- print_info: bool, default=True
Print info.
- get_node_tags(dim_entity_tags=None, physical_group_names=None)[source]¶
Return node tags in Gmsh, which will also be the same as in OpenSeesPy.
- Return type:
list
Parameters¶
- dim_entity_tags: list, the GMSH [(dim, entity tag), …].
A list of GMSH dimension and entity tags. If None, physical_group_names will be used.
- physical_group_names: list, tuple, str, or None, default None.
The physical group name or list of physical group names. If None, dim_entity_tags will be used.
Note
If dim_entity_tags and physical_group_names are both None, all entities will be converted.
If dim_entity_tags and physical_group_names are both not None, dim_entity_tags will be used.
Returns¶
- node_tags: list
A list containing node tags.
- create_node_cmds(dim_entity_tags=None, physical_group_names=None)[source]¶
Create
OpenSeesPynodes at runtime.- Return type:
list
Parameters¶
- dim_entity_tags: list, the GMSH [(dim, entity tag), …].
A list of GMSH dimension and entity tags. If None, physical_group_names will be used.
- physical_group_names: list, tuple, str, or None, default None.
The physical group name or list of physical group names. If None, dim_entity_tags will be used.
Note
If dim_entity_tags and physical_group_names are both None, all entities will be converted.
If dim_entity_tags and physical_group_names are both not None, dim_entity_tags will be used.
Returns¶
node_tags: list, a list containing openseespy node tags.
- write_node_file(dim_entity_tags=None, physical_group_names=None)[source]¶
Write a node commands file, Tcl or Python.
Parameters¶
- dim_entity_tags: list, the GMSH [(dim, entity tag), …].
A list of GMSH dimension and entity tags. If None, physical_group_names will be used.
- physical_group_names: list, tuple, str, or None, default None.
The physical group name or list of physical group names. If None, dim_entity_tags will be used.
Note
If dim_entity_tags and physical_group_names are both None, all entities will be converted.
If dim_entity_tags and physical_group_names are both not None, dim_entity_tags will be used.
- get_element_tags(dim_entity_tags=None, physical_group_names=None)[source]¶
Return element tags in Gmsh, which will also be the same as in OpenSeesPy.
- Return type:
list
Parameters¶
- dim_entity_tags: list, the GMSH [(dim, entity tag), …].
A list of dimension and entity tag containing element information that will be converted to OpenSeesPy elements. If None, physical_group_names will be used.
- physical_group_names: list, tuple, str, or None, default None.
The physical group name or list of physical group names. If None, dim_entity_tags will be used.
Note
If dim_entity_tags and physical_group_names are both None, all entities will be converted.
If dim_entity_tags and physical_group_names are both not None, dim_entity_tags will be used.
Returns¶
- ele_tags: list
A list containing element tags.
- create_element_cmds(ops_ele_type, ops_ele_args, dim_entity_tags=None, physical_group_names=None)[source]¶
Create
OpenSeesPyelements at runtime.- Return type:
list
Parameters¶
- ops_ele_type: str
the OpenSeesPy element type to generate.
- ops_ele_args: list
Parameters except OpenSeesPy element tag and coordinate points.
- dim_entity_tags: list, the GMSH [(dim, entity tag), …].
A list of dimension and entity tag containing element information that will be converted to OpenSeesPy elements. If None, physical_group_names will be used.
- physical_group_names: list, tuple, str, or None, default None.
The physical group name or list of physical group names. If None, dim_entity_tags will be used.
Note
If dim_entity_tags and physical_group_names are both None, all entities will be converted.
If dim_entity_tags and physical_group_names are both not None, dim_entity_tags will be used.
Returns¶
ele_tags: list, a list containing openseespy element tags.
- write_element_file(ops_ele_type, ops_ele_args, dim_entity_tags=None, physical_group_names=None)[source]¶
Write elements a command file,
TclorPython.Parameters¶
- ops_ele_type: str
the OpenSeesPy element type to generate.
- ops_ele_args: list
Parameters except OpenSeesPy element tag and coordinate points.
- dim_entity_tags: list, the GMSH [(dim, entity tag), …].
A list of dimension and entity tag containing element information that will be converted to OpenSeesPy elements. If None, physical_group_names will be used.
- physical_group_names: list, tuple, str, or None, default None.
The physical group name or list of physical group names. If None, dim_entity_tags will be used.
Note
If dim_entity_tags and physical_group_names are both None, all entities will be converted.
If dim_entity_tags and physical_group_names are both not None, dim_entity_tags will be used.
Returns¶
ele_tags: list, a list containing openseespy element tags.
- create_fix_cmds(dofs, dim_entity_tags=None, physical_group_names=None)[source]¶
Create fix constraints for OpenSeesPy at runtime.
- Return type:
list
Parameters¶
- dofs: list, degrees of freedom to be constrained.
Forexample, [1, 1, 1] for 3D and 3Dof.
- dim_entity_tags: list, the GMSH [(dim, entity tag), …].
A list of GMSH dimension and entity tags. If None, physical_group_names will be used.
- physical_group_names: list, tuple, str, or None, default None.
The physical group name or list of physical group names. If None, dim_entity_tags will be used.
Note
If dim_entity_tags and physical_group_names are both None, all entities will be converted.
If dim_entity_tags and physical_group_names are both not None, dim_entity_tags will be used.
Returns¶
node_tags: list, a list containing openseespy fixed node tags.
- write_fix_file(dofs, dim_entity_tags=None, physical_group_names=None)[source]¶
Write node fix commands file, Tcl or Python.
Parameters¶
- dofs: list, degrees of freedom to be constrained.
Forexample, [1, 1, 1] for 3D and 3Dof.
- dim_entity_tags: list, the GMSH [(dim, entity tag), …].
A list of GMSH dimension and entity tags. If None, physical_group_names will be used.
- physical_group_names: list, tuple, str, or None, default None.
The physical group name or list of physical group names. If None, dim_entity_tags will be used.
Note
If dim_entity_tags and physical_group_names are both None, all entities will be converted.
If dim_entity_tags and physical_group_names are both not None, dim_entity_tags will be used.
- get_dim_entity_tags(dim=None)[source]¶
Get dim_entity_tags from GMSH.
- Return type:
list
Parameters¶
- dim: int, optional, default None
The dimension tag. If None, all entities will be returned.
Returns¶
dim_entity_tags: list, the GMSH [(dim, entity tag), …].
- get_physical_groups()[source]¶
Get the GMSH physical groups.
- Return type:
dict
Returns¶
gmsh_physical_groups: dict, the GMSH physical groups. dict[key=name, value=[(dim, entity_tag), …]]
- get_boundary_dim_tags(dim_entity_tags=None, physical_group_names=None, include_self=False)[source]¶
Get all boundaries of the GMSH entities, including corner points.
- Return type:
list
Parameters¶
- dim_entity_tags: list, the GMSH [(dim, entity tag), …].
A list of GMSH dimension and entity tags. If None, physical_group_names will be used.
- physical_group_names: list, tuple, str, or None, default None.
The physical group name or list of physical group names. If None, dim_entity_tags will be used.
- include_self: bool, default False
If True, the output contains itself, which is dim_entity_tags.
Note
If dim_entity_tags and physical_group_names are both None, all entities will be converted.
If dim_entity_tags and physical_group_names are both not None, dim_entity_tags will be used.
Returns¶
Boundary dimension and entity tags list.
Unit System¶
- class opstool.pre.UnitSystem(length='m', force='kN', time='sec')[source]¶
A class for unit conversion.
Parameters¶
- length: str, default=”m”
Length unit base. Optional [“inch”, “ft”, “mm”, “cm”, “m”].
- force: str, default=”kN”
Force unit base. Optional [“lb”(“lbf”), “kip”, “n”, “kn”, “mn”, “kgf”, “tonf”].
- time: str, default=”sec”
Time unit base. Optional [“sec”, “msec”].
Note
Mass and stress units can be automatically determined based on length and force units, optional mass units include [“mg”, “g”, “kg”, “ton”(“t”), “slug”], and optional stress units include [“pa”, “kpa”, “mpa”, “gpa”, “bar”, “psi”, “ksi”, “psf”, “ksf”].
You can enter any uppercase and lowercase forms, such as
knandkN,mpaandMPaare equivalent.You can add a number after the unit to indicate a power, such as
m3form*m*m.