Gmsh2OPS

class opstool.pre.Gmsh2OPS(ndm=3, ndf=3)[source]

Bases: object

Generate OpenSees code from GMSH.

Parameters

ndm: int, default=3

Model dimension

ndf: int, default=3

Number of degrees of freedom.

Methods

create_element_cmds

Create OpenSeesPy elements at runtime.

create_fix_cmds

Create fix constraints for OpenSeesPy at runtime.

create_node_cmds

Create OpenSeesPy nodes at runtime.

get_boundary_dim_tags

Get all boundaries of the GMSH entities, including corner points.

get_dim_entity_tags

Get dim_entity_tags from GMSH.

get_element_tags

Return element tags in Gmsh, which will also be the same as in OpenSeesPy.

get_node_tags

Return node tags in Gmsh, which will also be the same as in OpenSeesPy.

get_physical_groups

Get the GMSH physical groups.

read_gmsh_data

Read data from GMSH at runtime.

read_gmsh_file

Read an .msh file generated by GMSH.

set_output_file

Parameters: filename: str, default = "src.tcl". The output file-path-name must end with .tcl or .py. encoding: str, default = "utf-8". The file encoding.

write_element_file

Write elements a command file, Tcl or Python.

write_fix_file

Write node fix commands file, Tcl or Python.

write_node_file

Write a node commands file, Tcl or Python.

set_output_file(filename='src.tcl', encoding='utf-8')[source]

Parameters:

filename: str, default = “src.tcl”.

The output file-path-name must end with .tcl or .py.

encoding: str, default = “utf-8”.

The file encoding.

read_gmsh_file(file_path, encoding='utf-8', print_info=True)[source]

Read an .msh file generated by GMSH.

Note

You only need to use one of read_gmsh_file and read_gmsh_data. read_gmsh_file is used to read data from the .msh file, and read_gmsh_data is 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 GMSH at 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_file and read_gmsh_data. read_gmsh_file is used to read data from the .msh file, and read_gmsh_data is 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 OpenSeesPy nodes 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=None, dim_entity_tags=None, physical_group_names=None)[source]

Create OpenSeesPy elements at runtime.

Return type:

list

Parameters

ops_ele_type: str

the OpenSeesPy element type to generate.

ops_ele_args: list, default None

Parameters except OpenSeesPy element tag and connected node tags. If None, an empty list will be used.

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=None, dim_entity_tags=None, physical_group_names=None)[source]

Write elements a command file, Tcl or Python.

Parameters

ops_ele_type: str

the OpenSeesPy element type to generate.

ops_ele_args: list, default None

Parameters except OpenSeesPy element tag and connected node tags. If None, an empty list will be used.

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.