Convert a TexGen Weave to SwiftComp Solid and Plate SGs#
Problem Description#
One microstructure can serve different macro models. The TexGen plain weave of
Convert a TexGen Weave to SwiftComp is homogenized here both as a 3D solid
(SD1) and as a Kirchhoff-Love plate (PL1), so it needs two SwiftComp 2.1
.sg files.
sgio.convert() could write each file, but it reads the input deck once
per call. This example reads the deck once and writes both files.
Solution#
"""Read a TexGen plain weave once and write SwiftComp SGs for two macro models."""
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_SD = EXAMPLE_DIR / "plain_weave_3d_sc21_sd.sg"
OUTPUT_FILE_PL = EXAMPLE_DIR / "plain_weave_3d_sc21_pl.sg"
def main() -> None:
# Read the TexGen model once; the macro model is given per write below
sg = sgio.read(
filename=os.fspath(INPUT_FILE),
file_format="abaqus",
sgdim=3,
)
sg.analysis_config.physics = 1 # Thermoelastic analysis
# Write one SG per macro model. sg.omega is None, so each write computes
# omega from the mesh bounding box for its own model: the SG volume for
# SD1, the in-plane (y1, y2) area for PL1.
for model_type, output_file in (("SD1", OUTPUT_FILE_SD), ("PL1", OUTPUT_FILE_PL)):
sgio.write(
sg=sg,
filename=os.fspath(output_file),
file_format="sc",
format_version="2.1", # SwiftComp 2.1
model_type=model_type,
)
print(f"Wrote SwiftComp SG ({model_type}): {output_file}")
if __name__ == "__main__":
main()
sgio.read()reads the deck withsgdim=3and nomodel_type: for an Abaqus deck the macro model can be given at write time, so the SG read stays model-neutral.sg.analysis_config.physics = 1selects a thermoelastic analysis. The deck defines the thermal expansion of both materials.sgio.write()runs once per macro model, withmodel_type="SD1"andmodel_type="PL1". Each write uses its own model type without changingsg.
omega is not set by hand. While sg.omega is None, each write computes it
from the SG bounding box over the dimensions the SG shares with its macro
model (see the omega table in Formats and Model Types):
Model |
Shared dimensions |
omega |
|---|---|---|
|
y1, y2, y3 |
volume, 2 x 2 x 0.22 = 0.88 |
|
y1, y2 |
in-plane area, 2 x 2 = 4.0 |
To set omega by hand, pass omega= to sgio.write().
Run the example:
uv run python examples/convert_texgen_weave_to_sc_sd_pl/run.py
Result#
The script writes plain_weave_3d_sc21_sd.sg and plain_weave_3d_sc21_pl.sg.
Running SwiftComp 2.1 on them gives the .k files:
SD1: the 6 x 6 effective stiffness matrix, e.g. C11 = 4.876e10 and C33 = 6.196e9.PL1: the A, B, D plate stiffness, e.g. A11 = 8.923e9, B11 = 8.923e8 and D11 = 1.007e8.
Note
SwiftComp computes plate stiffness about the plane y3 = 0. The TexGen mesh
spans z = -0.01 to 0.21, so that plane lies 0.1 below the mid-plane, which is
why B11 = 0.1 x A11. For the stiffness about the mid-plane, shift the node
coordinates in the script before the PL1 write, e.g.
sg.mesh.points[:, 2] -= 0.1.
File List#
run.py: reads the deck once and writes the
SD1andPL1SGsplain_weave_3d.inp: TexGen Abaqus voxel model
plain_weave_3d.ori: per-element orientation distribution
plain_weave_3d_sc21_sd.sg: generated SwiftComp 2.1 SG for
SD1plain_weave_3d_sc21_pl.sg: generated SwiftComp 2.1 SG for
PL1plain_weave_3d_sc21_sd.sg.k: SwiftComp homogenization result for
SD1plain_weave_3d_sc21_pl.sg.k: SwiftComp homogenization result for
PL1