Skip to content

Commit d1e5342

Browse files
authored
Integrate TexGen (#4)
1 parent a8061e3 commit d1e5342

File tree

14 files changed

+9780
-8787
lines changed

14 files changed

+9780
-8787
lines changed

MSUtils/TexGen/2dweave.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# =============================================================================
2+
# TexGen: Geometric textile modeller.
3+
# Copyright (C) 2015 Louise Brown
4+
5+
# This program is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU General Public License
7+
# as published by the Free Software Foundation; either version 2
8+
# of the License, or (at your option) any later version.
9+
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
# =============================================================================
19+
20+
# Python 3 version used runpy module to execute scripts from TexGen GUI which requires import of library
21+
from TexGen.Core import *
22+
23+
# Create a 4x4 2d woven textile with yarn spacing of 5 and thickness 2
24+
# The fifth parameter indicates whether to refine the textile to avoid intersections
25+
Textile = CTextileWeave2D(4, 4, 5, 2, False)
26+
27+
# Set the weave pattern
28+
Textile.SwapPosition(3, 0)
29+
Textile.SwapPosition(2, 1)
30+
Textile.SwapPosition(1, 2)
31+
Textile.SwapPosition(0, 3)
32+
33+
# Adjust the yarn width and height
34+
Textile.SetYarnWidths(4)
35+
Textile.SetYarnHeights(0.8)
36+
37+
# Setup a domain
38+
Textile.AssignDefaultDomain()
39+
40+
# Add the textile
41+
AddTextile(Textile)
42+
43+
###################################################
44+
# Export to voxel mesh and convert to h5 and xdmf
45+
###################################################
46+
47+
from MSUtils.general.vtk2h5 import vtk2h5
48+
from MSUtils.general.h52xdmf import write_xdmf
49+
import os
50+
51+
# choose resolution
52+
nx, ny, nz = 128, 128, 128
53+
vm = CRectangularVoxelMesh()
54+
55+
vm.SaveVoxelMesh(
56+
Textile,
57+
"data/2dweave.vtu",
58+
nx,
59+
ny,
60+
nz,
61+
False,
62+
True,
63+
NO_BOUNDARY_CONDITIONS,
64+
0,
65+
VTU_EXPORT,
66+
)
67+
68+
vtk2h5(
69+
vtk_files=["data/2dweave.vtu"],
70+
h5_file_path="data/TexGen_2dweave.h5",
71+
grp_name="/",
72+
overwrite=True,
73+
data_fields=["YarnIndex", "Orientation"],
74+
)
75+
os.remove("data/2dweave.vtu")
76+
write_xdmf(
77+
h5_filepath="data/TexGen_2dweave.h5",
78+
xdmf_filepath="data/TexGen_2dweave.xdmf",
79+
microstructure_length=[20, 20, 2.2],
80+
time_series=False,
81+
verbose=True,
82+
)
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# DecoupledLToLTextile.py
2+
3+
# Python 3 version used runpy module to execute scripts from TexGen GUI which requires import of library
4+
from TexGen.Core import *
5+
6+
# Set up 3D Weave textile
7+
numBinderLayers = 2
8+
numXYarns = 4
9+
numWefts = 6
10+
11+
warpSpacing = 1.42
12+
weftSpacing = 1.66
13+
warpHeight = 0.3
14+
weftHeight = 0.3
15+
16+
Textile = CTextileDecoupledLToL(
17+
numXYarns,
18+
numWefts,
19+
warpSpacing,
20+
weftSpacing,
21+
warpHeight,
22+
weftHeight,
23+
numBinderLayers,
24+
True,
25+
)
26+
27+
# set number of binder / warp yarns
28+
NumBinderYarns = 2
29+
30+
BinderRatio = 1
31+
WarpRatio = 1
32+
Textile.SetWarpRatio(WarpRatio)
33+
Textile.SetBinderRatio(BinderRatio)
34+
35+
# Set up layers: 2 warp, 3 weft
36+
Textile.SetupLayers(2, 3, numBinderLayers)
37+
38+
# Define offsets for the two binder yarns
39+
binderYarns = [
40+
[[0, 1, 1, 2, 1, 0], [3, 2, 3, 3, 2, 3]],
41+
[[1, 0, 1, 0, 2, 1], [2, 3, 2, 2, 3, 2]],
42+
]
43+
44+
# Check if length of binderYarns positions equal to numWefts
45+
for z in range(NumBinderYarns):
46+
for y in range(numBinderLayers):
47+
if len(binderYarns[z][y]) != numWefts:
48+
raise Exception(
49+
"Too many binder yarn positions specified, must be equal to number of wefts."
50+
)
51+
52+
binderWidth = 1.2
53+
binderHeight = 0.3
54+
warpWidth = 1.2
55+
weftWidth = 1.2
56+
57+
Textile.SetYYarnWidths(weftWidth)
58+
Textile.SetXYarnWidths(warpWidth)
59+
Textile.SetBinderYarnWidths(binderWidth)
60+
Textile.SetBinderYarnHeights(binderHeight)
61+
Textile.SetBinderYarnPower(0.2)
62+
Textile.SetWarpYarnPower(1.0)
63+
Textile.SetWeftYarnPower(1.0)
64+
65+
# Decompose binder yarn offsets into stacks
66+
67+
repeat = BinderRatio + WarpRatio
68+
69+
# Loop for the number of binder yarn stacks
70+
for z in range(NumBinderYarns):
71+
# Loop through the weft stacks
72+
for x in range(numWefts):
73+
zOffsets = IntVector()
74+
75+
# Loop through binder layers
76+
for y in range(numBinderLayers):
77+
zOffsets.push_back(int(binderYarns[z][y][x]))
78+
79+
# Calculate the binder y position (ie warp yarn index)
80+
ind = z / BinderRatio
81+
BinderIndex = WarpRatio + (ind * repeat) + z % BinderRatio
82+
Textile.SetBinderPosition(x, int(BinderIndex), zOffsets)
83+
84+
Textile.SetWeftRepeat(True)
85+
Textile.AssignDefaultDomain()
86+
87+
Textile.SetFibresPerYarn(WARP, 12000)
88+
Textile.SetFibresPerYarn(WEFT, 12000)
89+
Textile.SetFibresPerYarn(BINDER, 12000)
90+
Textile.SetFibreDiameter(WARP, 0.0026, "mm")
91+
Textile.SetFibreDiameter(WEFT, 0.0026, "mm")
92+
Textile.SetFibreDiameter(BINDER, 0.0026, "mm")
93+
94+
Textile.BuildTextile()
95+
AddTextile(Textile)
96+
97+
98+
###################################################
99+
# Export to voxel mesh and convert to h5 and xdmf
100+
###################################################
101+
102+
from MSUtils.general.vtk2h5 import vtk2h5
103+
from MSUtils.general.h52xdmf import write_xdmf
104+
import os
105+
106+
# choose resolution
107+
nx, ny, nz = 128, 128, 128
108+
vm = CRectangularVoxelMesh()
109+
110+
vm.SaveVoxelMesh(
111+
Textile,
112+
"data/DecoupledLToLTextile.vtu",
113+
nx,
114+
ny,
115+
nz,
116+
False,
117+
True,
118+
NO_BOUNDARY_CONDITIONS,
119+
0,
120+
VTU_EXPORT,
121+
)
122+
123+
vtk2h5(
124+
vtk_files=["data/DecoupledLToLTextile.vtu"],
125+
h5_file_path="data/TexGen_DecoupledLToLTextile.h5",
126+
grp_name="/",
127+
overwrite=True,
128+
data_fields=["YarnIndex", "Orientation"],
129+
)
130+
os.remove("data/DecoupledLToLTextile.vtu")
131+
write_xdmf(
132+
h5_filepath="data/TexGen_DecoupledLToLTextile.h5",
133+
xdmf_filepath="data/TexGen_DecoupledLToLTextile.xdmf",
134+
microstructure_length=[9.96, 5.68, 2.31],
135+
time_series=False,
136+
verbose=True,
137+
)

MSUtils/TexGen/LayeredTextile2.py

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# =============================================================================
2+
# TexGen: Geometric textile modeller.
3+
# Copyright (C) 2015 Louise Brown
4+
5+
# This program is free software; you can redistribute it and/or
6+
# modify it under the terms of the GNU General Public License
7+
# as published by the Free Software Foundation; either version 2
8+
# of the License, or (at your option) any later version.
9+
10+
# This program is distributed in the hope that it will be useful,
11+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
# GNU General Public License for more details.
14+
15+
# You should have received a copy of the GNU General Public License
16+
# along with this program; if not, write to the Free Software
17+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18+
# =============================================================================
19+
20+
# Python 3 version used runpy module to execute scripts from TexGen GUI which requires import of library
21+
from TexGen.Core import *
22+
23+
# Create a 4x4 satin weave with yarn spacing of 1 and thickness of 0.2
24+
weave = CTextileWeave2D(4, 4, 1, 0.2, False, False)
25+
weave.SetGapSize(0)
26+
27+
# Set the weave pattern
28+
weave.SwapPosition(0, 3)
29+
weave.SwapPosition(1, 2)
30+
weave.SwapPosition(2, 1)
31+
weave.SwapPosition(3, 0)
32+
33+
# Adjust the yarn widths and heights
34+
weave.SetYarnWidths(0.8)
35+
weave.SetYarnHeights(0.1)
36+
37+
# Assign the domain
38+
weave.AssignDefaultDomain()
39+
40+
# Create a layered textile
41+
LayeredTextile = CTextileLayered()
42+
43+
# Add the first layer with specified offset
44+
Offset = XYZ(0.25, 0.5, 0)
45+
LayeredTextile.AddLayer(weave, Offset)
46+
47+
# Create 2nd textile: Plain weave, spacing of 1 and thickness 0.2
48+
weave1 = CTextileWeave2D(2, 2, 1, 0.25, False, False)
49+
weave1.SetGapSize(0)
50+
weave1.SetYarnWidths(0.8)
51+
weave1.SwapPosition(0, 1)
52+
weave1.SwapPosition(1, 0)
53+
weave1.SetXYarnWidths(0, 0.9)
54+
weave1.SetXYarnHeights(0, 0.12)
55+
weave1.SetXYarnSpacings(0, 1)
56+
weave1.SetXYarnWidths(1, 0.8)
57+
weave1.SetXYarnHeights(1, 0.1)
58+
weave1.SetXYarnSpacings(1, 1)
59+
weave1.SetYYarnWidths(0, 0.8)
60+
weave1.SetYYarnHeights(0, 0.1)
61+
weave1.SetYYarnSpacings(0, 1)
62+
weave1.SetYYarnWidths(1, 0.9)
63+
weave1.SetYYarnHeights(1, 0.12)
64+
weave1.SetYYarnSpacings(1, 1)
65+
66+
weave1.AssignDefaultDomain()
67+
68+
# Offsets for second layer. z offset is height of first textile
69+
Offset = XYZ(0.4, 0.2, 0.2)
70+
71+
# Add the second textile to the layered textile
72+
LayeredTextile.AddLayer(weave1, Offset)
73+
74+
# Get the size of the domain for the second textile
75+
Domain1 = weave1.GetDefaultDomain()
76+
Min = XYZ()
77+
Max = XYZ()
78+
Domain1.GetBoxLimits(Min, Max)
79+
80+
# Get the domain of the first textile
81+
Domain = weave.GetDefaultDomain()
82+
Plane = PLANE()
83+
# Get the domain upper surface
84+
index = Domain.GetPlane(XYZ(0, 0, -1), Plane)
85+
# Offset the domain to include the second textile
86+
Plane.d -= Max.z - Min.z
87+
Domain.SetPlane(index, Plane)
88+
89+
LayeredTextile.AssignDomain(Domain)
90+
91+
# Add the textile with the name "LayeredTextile"
92+
AddTextile("LayeredTextile", LayeredTextile)
93+
94+
###################################################
95+
# Export to voxel mesh and convert to h5 and xdmf
96+
###################################################
97+
98+
from MSUtils.general.vtk2h5 import vtk2h5
99+
from MSUtils.general.h52xdmf import write_xdmf
100+
import os
101+
102+
# choose resolution
103+
nx, ny, nz = 128, 128, 128
104+
vm = CRectangularVoxelMesh()
105+
106+
vm.SaveVoxelMesh(
107+
LayeredTextile,
108+
"data/LayeredTextile2.vtu",
109+
nx,
110+
ny,
111+
nz,
112+
False,
113+
True,
114+
NO_BOUNDARY_CONDITIONS,
115+
0,
116+
VTU_EXPORT,
117+
)
118+
119+
vtk2h5(
120+
vtk_files=["data/LayeredTextile2.vtu"],
121+
h5_file_path="data/TexGen_LayeredTextile2.h5",
122+
grp_name="/",
123+
overwrite=True,
124+
data_fields=["YarnIndex", "Orientation"],
125+
)
126+
os.remove("data/LayeredTextile2.vtu")
127+
write_xdmf(
128+
h5_filepath="data/TexGen_LayeredTextile2.h5",
129+
xdmf_filepath="data/TexGen_LayeredTextile2.xdmf",
130+
microstructure_length=[4, 4, 0.5],
131+
time_series=False,
132+
verbose=True,
133+
)

0 commit comments

Comments
 (0)