After slientruss3d 1.3.x, you can use slientruss3d.generate
module to generate truss data automatically. For now, only simple cube-like
truss can be generated by slientruss3d, but I think this is still a helpful way for anyone who suffers from lake of truss data.
The following is an example figure for how 4-cube truss
looks like. And also introduce some technical terms here.
Generate cube-like trusses and save them into JSON files.
from slientruss3d.truss import Truss
from slientruss3d.type import LinkType, GenerateMethod
from slientruss3d.generate import GenerateRandomCubeTrusses, NoChange
GenerateRandomCubeTrusses(gridRange = (5, 5, 5),
numCubeRange = (5, 5),
numCaseRange = (1, 10),
lengthRange = (50, 150),
forceRange = [(-30000, 30000), (-30000, 30000), (-30000, 30000)],
nForceRange = None,
method = GenerateMethod.Random,
linkType = LinkType.Random,
memberTypes = [[1., 1e7, 0.1]],
isAddPinSupport = True,
isAllowParallel = False,
isDoStructuralAnalysis = False,
isPlotTruss = False,
isPrintMessage = True,
saveFolder = None,
augmenter = NoChange(),
seed = None ) -> list[Truss]
gridRange
: Max range of theglobal cube grid
.numCubeRange
: Range of the total numbers of cube-like truss block on the global grid.numCaseRange
: Range of the numbers of cases for eachnumCubeRange
(only influence names of the saved JSON files).lengthRange
: Range of the edge length (that is, height, width, deepth) for every cube-like truss block.forceRange
: Range of the magnitudes for xyz-axis of the random forces assigned at joints.nForceRange
: Range of the number of joints which will be assigned random external forces. If it'sNone
,nForceRange
~ Uniform(1, Number_of_joints).method
: Algorithm to decide positions to generate cube-like truss blocks.linkType
: Link type of faces of every cube-like truss block.memberTypes
: The member types in the list will be randomly assigned to each member. (list[list] or list[slientruss3d.type.MemberType])isAddPinSupport
: Whether to add pin supports in the generated truss or not.isAllowParallel
: Whether to allow parallel members in the generated truss or not.isDoStructuralAnalysis
: Whether to do structral analysis after each truss be generated.isPlotTruss
: Whether to plot the truss after each truss be generated.isPrintMessage
: Whether to print the message for the generating progress on the screen.saveFolder
: Folder to save the generated result (in JSON file). If it'sNone
, this method won't save the generated result to JSON file.augmenter
: (We will discuss it in the next section)seed
: Set random seed.
Explanation of global cube grid
( gridRange
= (3, 3, 3), numCubeRange
= (2, 2), lengthRange
= (50, 150) for example ) :
Options of linkType
:
- LinekType.LeftBottom_RightTop
- LinekType.RightBottom_LeftTop
- LinekType.Cross
- LinekType.Random (default)
Options of method
:
- GenerateMethod.DFS
- GenerateMethod.BFS
- GenerateMethod.Random (default)
You can do some data augmentation for the cube-like trusses generated by GenerateRandomCubeTrusses
or any other 3D trusses. For example:
from slientruss3d.generate import GenerateRandomCubeTrusses
from slientruss3d.generate import MoveToCentroid, RandomTranslation, AddJointNoise, RandomResetPin, NoChange, TrussDataAugmenterList
# Some parameters for your generated cube truss:
GRID_RANGE = (5, 5, 5)
CUBE_NUMBER = 4
GENERATE_NUMBER = 1
EDGE_LENGTH_RANGE = (100, 200)
EXTERNAL_FORCE_RANGE = [(-1000, 1000), (-1000, 1000), (-1000, 1000)]
IS_DO_STRUCTURAL_ANALYSIS = True
IS_PLOT_GENERATED_TRUSS = True
SAVE_FOLDER = './'
# Data augmentor:
transforms = TrussDataAugmenterList(
NoChange(), # Do nothing
MoveToCentroid(), # Move the centroid of the truss to [0., 0., 0.]
RandomTranslation(translateRange=[-30., 30.]), # Translate the whole truss randomly
AddJointNoise(noiseMeans=[0., 0., 0.], noiseStds=[10., 10., 10.]), # Add guassian noise to all positions of the joints
RandomResetPin(minNumPin=5, maxNumPinRatio=0.6) # Reset the positions and number of pin supports.
)
# Generate cube-like truss:
truss = GenerateRandomCubeTrusses(gridRange=GRID_RANGE,
numCubeRange=(CUBE_NUMBER, CUBE_NUMBER),
numEachRange=(1, GENERATE_NUMBER),
lengthRange=EDGE_LENGTH_RANGE,
forceRange=EXTERNAL_FORCE_RANGE,
isDoStructuralAnalysis=IS_DO_STRUCTURAL_ANALYSIS,
isPlotTruss=IS_PLOT_GENERATED_TRUSS,
saveFolder=SAVE_FOLDER,
seed=42,
augmenter=transforms # <- Do data augmentation !!!
)[0]
Before augmentation:
After augmentation: