Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions MSUtils/TexGen/2dweave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# =============================================================================
# TexGen: Geometric textile modeller.
# Copyright (C) 2015 Louise Brown

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# =============================================================================

# Python 3 version used runpy module to execute scripts from TexGen GUI which requires import of library
from TexGen.Core import *

# Create a 4x4 2d woven textile with yarn spacing of 5 and thickness 2
# The fifth parameter indicates whether to refine the textile to avoid intersections
Textile = CTextileWeave2D(4, 4, 5, 2, False)

# Set the weave pattern
Textile.SwapPosition(3, 0)
Textile.SwapPosition(2, 1)
Textile.SwapPosition(1, 2)
Textile.SwapPosition(0, 3)

# Adjust the yarn width and height
Textile.SetYarnWidths(4)
Textile.SetYarnHeights(0.8)

# Setup a domain
Textile.AssignDefaultDomain()

# Add the textile
AddTextile(Textile)

###################################################
# Export to voxel mesh and convert to h5 and xdmf
###################################################

from MSUtils.general.vtk2h5 import vtk2h5
from MSUtils.general.h52xdmf import write_xdmf
import os

# choose resolution
nx, ny, nz = 128, 128, 128
vm = CRectangularVoxelMesh()

vm.SaveVoxelMesh(
Textile,
"data/2dweave.vtu",
nx,
ny,
nz,
False,
True,
NO_BOUNDARY_CONDITIONS,
0,
VTU_EXPORT,
)

vtk2h5(
vtk_files=["data/2dweave.vtu"],
h5_file_path="data/TexGen_2dweave.h5",
grp_name="/",
overwrite=True,
data_fields=["YarnIndex", "Orientation"],
)
os.remove("data/2dweave.vtu")
write_xdmf(
h5_filepath="data/TexGen_2dweave.h5",
xdmf_filepath="data/TexGen_2dweave.xdmf",
microstructure_length=[20, 20, 2.2],
time_series=False,
verbose=True,
)
137 changes: 137 additions & 0 deletions MSUtils/TexGen/DecoupledLToLTextile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# DecoupledLToLTextile.py

# Python 3 version used runpy module to execute scripts from TexGen GUI which requires import of library
from TexGen.Core import *

# Set up 3D Weave textile
numBinderLayers = 2
numXYarns = 4
numWefts = 6

warpSpacing = 1.42
weftSpacing = 1.66
warpHeight = 0.3
weftHeight = 0.3

Textile = CTextileDecoupledLToL(
numXYarns,
numWefts,
warpSpacing,
weftSpacing,
warpHeight,
weftHeight,
numBinderLayers,
True,
)

# set number of binder / warp yarns
NumBinderYarns = 2

BinderRatio = 1
WarpRatio = 1
Textile.SetWarpRatio(WarpRatio)
Textile.SetBinderRatio(BinderRatio)

# Set up layers: 2 warp, 3 weft
Textile.SetupLayers(2, 3, numBinderLayers)

# Define offsets for the two binder yarns
binderYarns = [
[[0, 1, 1, 2, 1, 0], [3, 2, 3, 3, 2, 3]],
[[1, 0, 1, 0, 2, 1], [2, 3, 2, 2, 3, 2]],
]

# Check if length of binderYarns positions equal to numWefts
for z in range(NumBinderYarns):
for y in range(numBinderLayers):
if len(binderYarns[z][y]) != numWefts:
raise Exception(
"Too many binder yarn positions specified, must be equal to number of wefts."
)

binderWidth = 1.2
binderHeight = 0.3
warpWidth = 1.2
weftWidth = 1.2

Textile.SetYYarnWidths(weftWidth)
Textile.SetXYarnWidths(warpWidth)
Textile.SetBinderYarnWidths(binderWidth)
Textile.SetBinderYarnHeights(binderHeight)
Textile.SetBinderYarnPower(0.2)
Textile.SetWarpYarnPower(1.0)
Textile.SetWeftYarnPower(1.0)

# Decompose binder yarn offsets into stacks

repeat = BinderRatio + WarpRatio

# Loop for the number of binder yarn stacks
for z in range(NumBinderYarns):
# Loop through the weft stacks
for x in range(numWefts):
zOffsets = IntVector()

# Loop through binder layers
for y in range(numBinderLayers):
zOffsets.push_back(int(binderYarns[z][y][x]))

# Calculate the binder y position (ie warp yarn index)
ind = z / BinderRatio
BinderIndex = WarpRatio + (ind * repeat) + z % BinderRatio
Textile.SetBinderPosition(x, int(BinderIndex), zOffsets)

Textile.SetWeftRepeat(True)
Textile.AssignDefaultDomain()

Textile.SetFibresPerYarn(WARP, 12000)
Textile.SetFibresPerYarn(WEFT, 12000)
Textile.SetFibresPerYarn(BINDER, 12000)
Textile.SetFibreDiameter(WARP, 0.0026, "mm")
Textile.SetFibreDiameter(WEFT, 0.0026, "mm")
Textile.SetFibreDiameter(BINDER, 0.0026, "mm")

Textile.BuildTextile()
AddTextile(Textile)


###################################################
# Export to voxel mesh and convert to h5 and xdmf
###################################################

from MSUtils.general.vtk2h5 import vtk2h5
from MSUtils.general.h52xdmf import write_xdmf
import os

# choose resolution
nx, ny, nz = 128, 128, 128
vm = CRectangularVoxelMesh()

vm.SaveVoxelMesh(
Textile,
"data/DecoupledLToLTextile.vtu",
nx,
ny,
nz,
False,
True,
NO_BOUNDARY_CONDITIONS,
0,
VTU_EXPORT,
)

vtk2h5(
vtk_files=["data/DecoupledLToLTextile.vtu"],
h5_file_path="data/TexGen_DecoupledLToLTextile.h5",
grp_name="/",
overwrite=True,
data_fields=["YarnIndex", "Orientation"],
)
os.remove("data/DecoupledLToLTextile.vtu")
write_xdmf(
h5_filepath="data/TexGen_DecoupledLToLTextile.h5",
xdmf_filepath="data/TexGen_DecoupledLToLTextile.xdmf",
microstructure_length=[9.96, 5.68, 2.31],
time_series=False,
verbose=True,
)
133 changes: 133 additions & 0 deletions MSUtils/TexGen/LayeredTextile2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# =============================================================================
# TexGen: Geometric textile modeller.
# Copyright (C) 2015 Louise Brown

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
# =============================================================================

# Python 3 version used runpy module to execute scripts from TexGen GUI which requires import of library
from TexGen.Core import *

# Create a 4x4 satin weave with yarn spacing of 1 and thickness of 0.2
weave = CTextileWeave2D(4, 4, 1, 0.2, False, False)
weave.SetGapSize(0)

# Set the weave pattern
weave.SwapPosition(0, 3)
weave.SwapPosition(1, 2)
weave.SwapPosition(2, 1)
weave.SwapPosition(3, 0)

# Adjust the yarn widths and heights
weave.SetYarnWidths(0.8)
weave.SetYarnHeights(0.1)

# Assign the domain
weave.AssignDefaultDomain()

# Create a layered textile
LayeredTextile = CTextileLayered()

# Add the first layer with specified offset
Offset = XYZ(0.25, 0.5, 0)
LayeredTextile.AddLayer(weave, Offset)

# Create 2nd textile: Plain weave, spacing of 1 and thickness 0.2
weave1 = CTextileWeave2D(2, 2, 1, 0.25, False, False)
weave1.SetGapSize(0)
weave1.SetYarnWidths(0.8)
weave1.SwapPosition(0, 1)
weave1.SwapPosition(1, 0)
weave1.SetXYarnWidths(0, 0.9)
weave1.SetXYarnHeights(0, 0.12)
weave1.SetXYarnSpacings(0, 1)
weave1.SetXYarnWidths(1, 0.8)
weave1.SetXYarnHeights(1, 0.1)
weave1.SetXYarnSpacings(1, 1)
weave1.SetYYarnWidths(0, 0.8)
weave1.SetYYarnHeights(0, 0.1)
weave1.SetYYarnSpacings(0, 1)
weave1.SetYYarnWidths(1, 0.9)
weave1.SetYYarnHeights(1, 0.12)
weave1.SetYYarnSpacings(1, 1)

weave1.AssignDefaultDomain()

# Offsets for second layer. z offset is height of first textile
Offset = XYZ(0.4, 0.2, 0.2)

# Add the second textile to the layered textile
LayeredTextile.AddLayer(weave1, Offset)

# Get the size of the domain for the second textile
Domain1 = weave1.GetDefaultDomain()
Min = XYZ()
Max = XYZ()
Domain1.GetBoxLimits(Min, Max)

# Get the domain of the first textile
Domain = weave.GetDefaultDomain()
Plane = PLANE()
# Get the domain upper surface
index = Domain.GetPlane(XYZ(0, 0, -1), Plane)
# Offset the domain to include the second textile
Plane.d -= Max.z - Min.z
Domain.SetPlane(index, Plane)

LayeredTextile.AssignDomain(Domain)

# Add the textile with the name "LayeredTextile"
AddTextile("LayeredTextile", LayeredTextile)

###################################################
# Export to voxel mesh and convert to h5 and xdmf
###################################################

from MSUtils.general.vtk2h5 import vtk2h5
from MSUtils.general.h52xdmf import write_xdmf
import os

# choose resolution
nx, ny, nz = 128, 128, 128
vm = CRectangularVoxelMesh()

vm.SaveVoxelMesh(
LayeredTextile,
"data/LayeredTextile2.vtu",
nx,
ny,
nz,
False,
True,
NO_BOUNDARY_CONDITIONS,
0,
VTU_EXPORT,
)

vtk2h5(
vtk_files=["data/LayeredTextile2.vtu"],
h5_file_path="data/TexGen_LayeredTextile2.h5",
grp_name="/",
overwrite=True,
data_fields=["YarnIndex", "Orientation"],
)
os.remove("data/LayeredTextile2.vtu")
write_xdmf(
h5_filepath="data/TexGen_LayeredTextile2.h5",
xdmf_filepath="data/TexGen_LayeredTextile2.xdmf",
microstructure_length=[4, 4, 0.5],
time_series=False,
verbose=True,
)
Loading