Convert an Abaqus Cross-Section with an SG Manifest#
Problem Description#
An Abaqus .inp file carries the mesh, materials and composite sections of a
beam cross-section, but not the SG parameters: it cannot state that the model is
a 2D SG, which beam model to use, or which plane the section is drawn in. Store
those parameters in a file instead of passing them as arguments, and convert the
cross-section to SwiftComp.
Solution#
The conversion is done in two ways, one script each; both write the same
sg2_box.sc.
Method 1: API arguments#
sgdim, model_type and model_space are arguments of sgio.read().
Reading sg2_box.sc back still needs model_type, because a SwiftComp input
does not state it.
"""Method 1: pass the SG parameters as arguments of ``sgio.read``."""
import logging
from pathlib import Path
import sgio
logging.basicConfig(level=logging.INFO)
cwd = Path(__file__).resolve().parent
sc_file = cwd / 'sg2_box.sc'
# The Abaqus input holds the mesh, materials and composite sections, but not
# the SG dimension, beam model or the plane the cross-section is drawn in.
sg = sgio.read(
str(cwd / 'sg2_box_composite_section.inp'), 'abaqus',
sgdim=2, model_type='BM1', model_space='xy',
)
print(sg)
sgio.write(sg, str(sc_file), 'sc')
# SwiftComp input defines sgdim and model space, but not the model type.
sg_sc = sgio.read(str(sc_file), 'sc', model_type='BM1')
print(sg_sc.sgdim, sg_sc.model_space, sg_sc.nnodes, sg_sc.nelems)
Method 2: SG manifests#
sg2_box.sg.json is an SG manifest (see SG Manifest) that
references the Abaqus input:
{
"sg_manifest_version": 1,
"model_file": {
"path": "sg2_box_composite_section.inp",
"format": "abaqus"
},
"sgdim": 2,
"model_type": "BM1",
"model_space": "xy"
}
"""Method 2: keep the SG parameters in SG manifests."""
import logging
from pathlib import Path
import sgio
logging.basicConfig(level=logging.INFO)
cwd = Path(__file__).resolve().parent
# sg2_box.sg.json references sg2_box_composite_section.inp and adds what the
# .inp cannot state: SG dimension, beam model and the plane the cross-section
# is drawn in.
sg = sgio.read(str(cwd / 'sg2_box.sg.json'), 'sg_manifest')
print(sg)
# Write a SwiftComp input together with its own manifest. SwiftComp owns the
# materials, sections and model space, so the new manifest only records the
# model file, sgdim and model type. The SwiftComp input is the same one
# run_1_api.py writes.
sgio.write(
sg,
str(cwd / 'sg2_box_sc.sg.json'),
'sg_manifest',
model_file='sg2_box.sc',
model_file_format='swiftcomp',
)
# The SwiftComp manifest reads back as the same structure gene, with no
# arguments.
sg_sc = sgio.read(str(cwd / 'sg2_box_sc.sg.json'), 'sg_manifest')
print(sg_sc.sgdim, sg_sc.model_space, sg_sc.nnodes, sg_sc.nelems)
sgio.read() with 'sg_manifest' reads the manifest and the .inp into one
sgio.StructureGene. sgio.write() with 'sg_manifest' writes the
SwiftComp input and a new manifest. SwiftComp input already holds the materials,
sections and model space, so the new manifest records only the model file, its
format version, sgdim and model_type; reading it back checks the SwiftComp
header against it, so reading it back needs no arguments.
Result#
sg2_box.sc and its manifest sg2_box_sc.sg.json are written:
{
"sg_manifest_version": 1,
"model_file": {
"path": "sg2_box.sc",
"format": "swiftcomp",
"format_version": "2.1"
},
"sgdim": 2,
"model_type": "BM1"
}
uv run python examples/convert_abaqus_cs_with_sg_manifest/run_1_api.py
uv run python examples/convert_abaqus_cs_with_sg_manifest/run_2_manifest.py
File List#
run_1_api.py: Conversion with SG arguments
run_2_manifest.py: Conversion through SG manifests
sg2_box_composite_section.inp: Abaqus cross-section input
sg2_box.sg.json: SG manifest for the Abaqus input
sg2_box.sc: Generated SwiftComp input
sg2_box_sc.sg.json: Generated SG manifest for the SwiftComp input