Convert a TexGen Weave to SwiftComp#
Problem Description#
TexGen writes a textile model as an Abaqus input deck: a voxel mesh, one
element set per yarn, and a per-element fiber orientation kept in a separate
.ori file. Convert that deck into a SwiftComp Structure Gene for 3D solid
homogenization.
The committed 32 x 32 x 8 voxel model contains 8,192 C3D8R elements. TexGen
also places six periodic-constraint driver nodes in the deck, which are not
analysis elements.
Solution#
The .inp states neither the SG dimension nor the model type, so there are
two ways to supply them, one script each; both write the same file.
Method 1: API arguments#
sgdim=3, model_type='SD1' with file_format_in='abaqus'.
"""Method 1: convert a TexGen plain weave with the SG parameters as arguments."""
from __future__ import annotations
import os
from pathlib import Path
import sgio
EXAMPLE_DIR = Path(__file__).resolve().parent
INPUT_FILE = EXAMPLE_DIR / "plain_weave_3d.inp"
OUTPUT_FILE = EXAMPLE_DIR / "plain_weave_3d_sc21.sg"
OUTPUT_PNG = EXAMPLE_DIR / "pyvista.png"
def main() -> None:
"""Convert the TexGen model and save a PyVista PNG view."""
# The TexGen deck states neither the SG dimension nor the model type.
sg = sgio.convert(
file_name_in=os.fspath(INPUT_FILE),
file_name_out=os.fspath(OUTPUT_FILE),
file_format_in="abaqus",
file_format_out="sc",
sgdim=3,
file_version_out="2.1",
model_type="SD1",
)
plotter = sgio.plot_sg_pyvista(
sg,
show_local_axes=True,
local_axis_scale=0.15,
opacity=0.45,
)
plotter.off_screen = True
plotter.show(screenshot=str(OUTPUT_PNG), auto_close=False)
plotter.close()
print(f"Wrote SwiftComp SG: {OUTPUT_FILE}")
print(f"Wrote PyVista screenshot: {OUTPUT_PNG}")
if __name__ == "__main__":
main()
Method 2: SG manifest#
plain_weave_3d.sg.json references the same .inp and holds those parameters,
so the conversion needs no SG arguments. See SG Manifest.
{
"sg_manifest_version": 1,
"model_file": {
"path": "plain_weave_3d.inp",
"format": "abaqus"
},
"sgdim": 3,
"model_type": "SD1"
}
"""Method 2: convert a TexGen plain weave through its SG manifest."""
from __future__ import annotations
import os
from pathlib import Path
import sgio
EXAMPLE_DIR = Path(__file__).resolve().parent
MANIFEST_FILE = EXAMPLE_DIR / "plain_weave_3d.sg.json"
OUTPUT_FILE = EXAMPLE_DIR / "plain_weave_3d_sc21.sg"
OUTPUT_PNG = EXAMPLE_DIR / "pyvista.png"
def main() -> None:
"""Convert the TexGen model and save a PyVista PNG view."""
# plain_weave_3d.sg.json references plain_weave_3d.inp and holds sgdim and
# model type, so the conversion takes no SG arguments. It writes the same
# SwiftComp input as run_1_api.py.
sg = sgio.convert(
file_name_in=os.fspath(MANIFEST_FILE),
file_name_out=os.fspath(OUTPUT_FILE),
file_format_in="sg_manifest",
file_format_out="sc",
file_version_out="2.1",
)
plotter = sgio.plot_sg_pyvista(
sg,
show_local_axes=True,
local_axis_scale=0.15,
opacity=0.45,
)
plotter.off_screen = True
plotter.show(screenshot=str(OUTPUT_PNG), auto_close=False)
plotter.close()
print(f"Wrote SwiftComp SG: {OUTPUT_FILE}")
print(f"Wrote PyVista screenshot: {OUTPUT_PNG}")
if __name__ == "__main__":
main()
Three things the deck carries are read without extra arguments:
the fiber orientations, which live in
plain_weave_3d.oriand are reached through the*Distribution, Input=parameter, resolved relative to the.inpfile’s folder;the
*Expansionthermal expansion data of both materials;omega, which is not in the deck at all — it is computed from the SG bounding box, a volume here because a 3D SG shares all three dimensions with theSD1model. See the omega table in Formats and Model Types; pass--omega(oromega=in Python) to give it by hand.
sgio.plot_sg_pyvista() then renders the converted SG, overlaying each
element’s local axes so the yarn directions can be inspected.
Thermoelastic Variant#
Because the deck defines *Expansion, the same model converts for a
thermoelastic analysis by selecting the physics — no other change:
sgio convert plain_weave_3d.inp plain_weave_3d.sg -ff abaqus -tf sc -d 3 -m SD1 -p thermoelastic
The materials then carry their CTE into the SwiftComp input. See Convert SG Data.
Result#
plain_weave_3d_sc21.sg is written and ready for homogenization, alongside
pyvista.png, which shows the matrix and yarn regions with their local
coordinate axes.
Running the example needs the optional visualization dependency:
uv sync --extra pyvista
uv run python examples/convert_texgen_weave_to_sc/run_1_api.py
uv run python examples/convert_texgen_weave_to_sc/run_2_manifest.py
File List#
run_1_api.py: conversion with SG arguments, plus rendering
run_2_manifest.py: the same conversion through the SG manifest
plain_weave_3d.inp: TexGen Abaqus voxel model
plain_weave_3d.ori: per-element orientation distribution
plain_weave_3d.sg.json: SG manifest referencing the deck
plain_weave_3d_sc21.sg: generated SwiftComp 2.1 Structure Gene
pyvista.png: generated PyVista screenshot