Example A-4: Manual Manipulation of the Structure (Whole Array)
This example illustrated manual modification of the data array of a VoxelPart instance. Unlike Example A-3, here we change the entire data array.
First, a complete 2D part with a shape of 5×5 voxels is created with a base material of 1 and a voxel size of 0.02 units in all directions. The parameter log_debug is set to True for demonstration purposes.
Afterwards, the an array of random integers between 1 and 3 is created. To do this, the random module of NumPy must be imported:
from numpy import random
The random number generator can then be constructed:
rng = random.default_rng()
With the random number generator prepared, we can create an array of random numbers. We must specify the size, highest and lowest numbers, and the dtype of the random array. These can be extracted from the part’s data array. We will then assign the created array to part.data, thus replacing its previous contents:
random_array = rng.integers(low=1, high=3, size=part.size,
dtype=part.data.dtype, endpoint=True)
part.data = random_array
Finally, The part is exported to an Abaqus™ input file in 2D mode with CPE4R elements. The Non-Empty elements are requested to be exported.
The code can be found in the examples folder of the main repository. It is also included below:
"""Script for Example A-4: Manual Manipulation of the Structure (Whole Array)."""
from numpy import random
from vcams.voxelpart import VoxelPart
# Create the part.
part = VoxelPart(size=(5, 5), base_material=1, voxel_size=(0.02, 0.02), name='Ex A4 Manual Manipulation Whole',
description='Example A-4: A 5*5 2D part filled with all elements replaced with a random array.',
log_debug=True)
# Prepare the random number generator.
rng = random.default_rng()
# Create an array of random integers with the same size and dtype as part.data
# and set the min and max values to 1 and 3, respectively.
random_array = rng.integers(low=1, high=3, size=part.size,
dtype=part.data.dtype, endpoint=True)
# Assign random_array to part.data, which replaces its contents.
part.data = random_array
# Output the part.
part.output_abaqus_inp(file_name='ex_a4_manual_manipulation_whole',
elem_code='CPE4R', dim='2D',
material_elem_sets='Non-Empty')
The final model looks like Fig. 12. Note that elements in different sets are shown in different colors. Also, because of the random nature of this example, each model will be different.
Fig. 12 Final model of Example A-4. Element sets corresponding to MAT-1, MAT-2 and MAT-3 are shown in green, beige, and red, respectively.