Muscat.IO.AnsysWriter module

Ansys CDB format writer.

class AnsysWriter[source]

Bases: WriterBase

Ansys CDB format writer.

AnsysFormulation

Mapping between the dimensionality of the elements and the Ansys physics keyword ("SOLID3D" for 3D, "SOLID2D" for 2D). Read the file AnsysTools.py (variable MuscatToAnsysFormulation) for more details.

Type:

dict

writeShells

If True the surface elements (dimensionality dim - 1) are written in the CDB file using the Ansys SHELL formulation, together with their associated element tags, by default False.

Type:

bool

writeBeams

If True the beam elements (dimensionality dim - 2) are written in the CDB file using the Ansys BEAM formulation, together with their associated element tags, by default False.

Type:

bool

shellThickness

Thickness used in the SECDATA card of the shell sections, by default 0.01.

Type:

float

CompactIndices(indices: ndarray) List[List[int]][source]

Convert a list of indices into the Ansys CDB compact form.

Parameters:

indices (np.ndarray) – Indices of the elements, one by one.

Returns:

List of lines where consecutive indices are replaced by begin and -end, each line containing at most 8 elements.

Return type:

list

SliceRidges(mesh: Mesh) List[List[int]][source]

Build ordered ridge-node chains from Bar_2 elements tagged Ridges.

Consecutive nodes in each output chain always belong to the same ridge bar element. Chains are split into chunks of at most 100 nodes so they can be used by the Ansys SPLINE command.

Parameters:

mesh (Mesh) – Mesh containing the Bar_2 elements with a Ridges tag.

Returns:

List of node chains, each chain being a list of node ids of length at most 100. An empty list is returned when no Ridges tag is found.

Return type:

list of list of int

Write(mesh: Mesh, remotePoints: dict | None = None) None[source]

Write a CDB file from the mesh information.

Parameters:
  • mesh (Mesh) – The mesh to be exported.

  • remotePoints (dict, optional) – Dictionary describing the remote points to be exported, by default None.

Notes

When remote points are provided, this method mutates the input dictionary by storing the generated pilot node id under the "ID" key of each remote point.

WriteFromFile(mesh: Mesh, file: Path) None[source]

Update an existing CDB file with new mesh information.

The nodes block and the element block of the input file are replaced with the data coming from mesh; all other lines are copied as is.

Parameters:
  • mesh (Mesh) – The mesh providing the new node positions and connectivity.

  • file (Path) – Path to the existing CDB file to update.

WriteNamedSelection(name: str, kind: str, indices: ndarray) None[source]

Write a single CMBLOCK named selection.

Parameters:
  • name (str) – Name of the named selection (component).

  • kind (str) – Kind of entities referenced, either "NODE" or "ELEM".

  • indices (np.ndarray) – One-based ids of the entities of the named selection.

exportMask = {ElementType.Bar_2: [0, 1], ElementType.Bar_3: [0, 1, 2], ElementType.Hexahedron_8: [0, 1, 2, 3, 4, 5, 6, 7], ElementType.Pyramid_5: [0, 1, 2, 3, 4, 4, 5, 5], ElementType.Quadrangle_4: [0, 1, 2, 3], ElementType.Tetrahedron_10: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], ElementType.Tetrahedron_4: [0, 1, 2, 2, 3, 3, 3, 3], ElementType.Triangle_3: [0, 1, 2, 2], ElementType.Triangle_6: [0, 1, 2, 2, 3, 4, 2, 5], ElementType.Wedge_6: [0, 1, 2, 2, 3, 4, 2, 5]}
CheckIntegrity(GUI: bool = False) str[source]

Run all the functional checks of the Ansys CDB writer.

Parameters:

GUI (bool, optional) – Unused, kept for API compatibility with the other modules, by default False.

Returns:

"ok" if every check succeeds.

Return type:

str

CheckIntegrityCompactIndices() str[source]

Check the compaction of element indices into the CDB compact form.

Returns:

"ok" if every assertion succeeds.

Return type:

str

CheckIntegrityExportElementTags() str[source]

Check the export of element tags to the Ansys CDB format.

The file output, the append mode and the filePointer output are all exercised.

Returns:

"ok" if every assertion succeeds.

Return type:

str

CheckIntegritySliceRidges() str[source]

Check the construction of ridge-node chains from Bar_2 elements.

The open chain, the empty mesh (no Ridges tag) and the closed loop (cycle) cases are all exercised.

Returns:

"ok" if every assertion succeeds.

Return type:

str

CheckIntegrityWrite() str[source]

Check the writing of a tetrahedral mesh in the CDB format.

Returns:

"ok" if every assertion succeeds.

Return type:

str

CheckIntegrityWriteFromFile() str[source]

Check the update of an existing CDB file with new mesh information.

Returns:

"ok" if every assertion succeeds.

Return type:

str

CheckIntegrityWriteMultipleTypes() str[source]

Check the writing of several element types of the same dimensionality.

A mesh mixing hexahedra and tetrahedra (two 3D types) must produce two ET cards, a single SOLID EBLOCK and NUMOFF,TYPE,2.

Returns:

"ok" if every assertion succeeds.

Return type:

str

CheckIntegrityWriteQuadratic() str[source]

Check the writing of quadratic elements (more than 8 nodes per element).

This exercises the Tetrahedron_10 branch where the connectivity is written on two lines.

Returns:

"ok" if every assertion succeeds.

Return type:

str

CheckIntegrityWriteWithBeams() str[source]

Check the writing of the beam elements and their tags.

Returns:

"ok" if every assertion succeeds.

Return type:

str

CheckIntegrityWriteWithRemotePoints() str[source]

Check the writing of a mesh together with remote points.

Returns:

"ok" if every assertion succeeds.

Return type:

str

CheckIntegrityWriteWithShells() str[source]

Check the writing of the surface elements and their tags.

Returns:

"ok" if every assertion succeeds.

Return type:

str

ExportElementTagInCDBFormat(mesh: Mesh, tagName: str, fileName: str | None = None, append: bool = False, filePointer: TextIOWrapper | None = None) None[source]

Export a single element tag to the Ansys CDB format.

The original ids of the elements are used.

Parameters:
  • mesh (Mesh) – Mesh from which the element ids of the tag are searched.

  • tagName (str) – Name of the element tag to export.

  • fileName (str, optional) – File name (CDB format) where the element ids of the tag are exported. When None, tagName + ".cdb" is used, by default None.

  • append (bool, optional) – If True the information is appended to the file (mode "a+"), otherwise the file is overwritten (mode "w"), by default False.

  • filePointer (TextIOWrapper, optional) – Already opened file pointer used to write the tag. When provided, fileName and append are ignored, by default None.

ExportElementTagsInCDBFormat(mesh: Mesh, tagNames: List[str], fileName: str | None = None, filePointer: TextIOWrapper | None = None) None[source]

Export several element tags to the Ansys CDB format.

Parameters:
  • mesh (Mesh) – Mesh from which the element ids of each tag are searched.

  • tagNames (list of str) – List of the element tag names to export.

  • fileName (str, optional) – File name (CDB format) where the element ids of each tag are exported, by default None.

  • filePointer (TextIOWrapper, optional) – Already opened file pointer used to write the tags. When provided, fileName is ignored, by default None.

WriteMeshToCDB(fileName: str, mesh: Mesh, file: Path | None = None, remotePoints: dict | None = None, writeShells: bool = False, writeBeams: bool = False) None[source]

Write a mesh in the CDB format (Ansys).

A file is created using the path and the name given by fileName.

Parameters:
  • fileName (str) – Name (with path, relative or absolute) of the file to be created.

  • mesh (Mesh) – The mesh to be exported.

  • file (Path, optional) – Path to an existing CDB file to be updated instead of being written from scratch, by default None.

  • remotePoints (dict, optional) – Dictionary describing the remote points to be exported, by default None.

  • writeShells (bool, optional) – If True the surface elements (dimensionality dim - 1) and their associated tags are written in the CDB file, by default False.

  • writeBeams (bool, optional) – If True the beam elements (dimensionality dim - 2) and their associated tags are written in the CDB file, by default False.