diff --git a/MSUtils/TexGen/2dweave.py b/MSUtils/TexGen/2dweave.py new file mode 100644 index 0000000..a8707ac --- /dev/null +++ b/MSUtils/TexGen/2dweave.py @@ -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, +) diff --git a/MSUtils/TexGen/DecoupledLToLTextile.py b/MSUtils/TexGen/DecoupledLToLTextile.py new file mode 100644 index 0000000..866255b --- /dev/null +++ b/MSUtils/TexGen/DecoupledLToLTextile.py @@ -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, +) diff --git a/MSUtils/TexGen/LayeredTextile2.py b/MSUtils/TexGen/LayeredTextile2.py new file mode 100644 index 0000000..6a9e808 --- /dev/null +++ b/MSUtils/TexGen/LayeredTextile2.py @@ -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, +) diff --git a/MSUtils/TexGen/NonCrimpFabric.py b/MSUtils/TexGen/NonCrimpFabric.py new file mode 100644 index 0000000..7bd538a --- /dev/null +++ b/MSUtils/TexGen/NonCrimpFabric.py @@ -0,0 +1,158 @@ +# ============================================================================= +# 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 textile +Textile = CTextile() + +# Create a python list containing 2 inlay yarns +Yarns = [CYarn(), CYarn()] + +# Define some constants +w = 0.95 +s = 1 +h = 0.2 + +# Add nodes to the yarns to describe the yarn path +Yarns[0].AddNode(CNode(XYZ(0, 0, 0))) +Yarns[0].AddNode(CNode(XYZ(0, s, 0))) + +Yarns[1].AddNode(CNode(XYZ(0, 0, h))) +Yarns[1].AddNode(CNode(XYZ(s, 0, h))) + +# Loop over all the yarns in the list +for Yarn in Yarns: + # Assign a power ellipse to the inlay yarns + InlaySection = CSectionPowerEllipse(w, h, 0.5) + Yarn.AssignSection(CYarnSectionConstant(InlaySection)) + # Add repeats + Yarn.AddRepeat(XYZ(s, 0, 0)) + Yarn.AddRepeat(XYZ(0, s, 0)) + # Set the interpolation function + Yarn.AssignInterpolation(CInterpolationCubic()) + # set the resolution of the surface mesh created + Yarn.SetResolution(40) + # Add the yarn to our textile + Textile.AddYarn(Yarn) + +# Define some more constants for the stitching +a = 0.05 +r = 0.025 +u = 1.5 * h + r +d = -0.5 * h - r + +# Create a stitch yarn +StitchYarn = CYarn() + +# Create stitch yarn path. This path is quite complex and has been +# created with a fair amount of tweaking. Note that the tangents +# at the nodes have been specified for further control on the path. +StitchYarn.AddNode(CNode(XYZ(2 * a, a, u), XYZ(1, 1, 0))) +StitchYarn.AddNode(CNode(XYZ(s + a, s - a, u), XYZ(1, 1, 0))) + +StitchYarn.AddNode(CNode(XYZ(s + a, s, d), XYZ(0, 1, 0))) +StitchYarn.AddNode(CNode(XYZ(s + 2 * a, 2 * s - a, d + a), XYZ(0, 1, 0))) + +StitchYarn.AddNode(CNode(XYZ(s + a, 2 * s, d + a), XYZ(-1, 0, 0))) +StitchYarn.AddNode(CNode(XYZ(s - a, 2 * s, d + a), XYZ(-1, 0, 0))) + +StitchYarn.AddNode(CNode(XYZ(s + a, 2 * s, d + a), XYZ(0, -1, 0))) +StitchYarn.AddNode(CNode(XYZ(s - a, s, d), XYZ(0, -1, 0))) + +StitchYarn.AddNode(CNode(XYZ(s - 2 * a, s + a, u), XYZ(-1, 1, 0))) +StitchYarn.AddNode(CNode(XYZ(-a, 2 * s - a, u), XYZ(-1, 1, 0))) + +StitchYarn.AddNode(CNode(XYZ(-a, 2 * s, d), XYZ(0, 1, 0))) +StitchYarn.AddNode(CNode(XYZ(-2 * a, 3 * s - a, d), XYZ(0, 1, 0))) + +StitchYarn.AddNode(CNode(XYZ(-a, 3 * s, d + a), XYZ(1, 0, 0))) +StitchYarn.AddNode(CNode(XYZ(a, 3 * s, d + a), XYZ(1, 0, 0))) + +StitchYarn.AddNode(CNode(XYZ(2 * a, 3 * s - a, d), XYZ(0, -1, 0))) +StitchYarn.AddNode(CNode(XYZ(a, 2 * s, d), XYZ(0, -1, 0))) + +StitchYarn.AddNode(CNode(XYZ(2 * a, 2 * s + a, u), XYZ(1, 1, 0))) + +# Add the repeat vectors for the stitching +StitchYarn.AddRepeat(XYZ(1, 0, 0)) +StitchYarn.AddRepeat(XYZ(0, 2, 0)) + +# Assign a circular section to the stitch yarns +StitchSection = CSectionEllipse(2 * r, 2 * r) +StitchYarn.AssignSection(CYarnSectionConstant(StitchSection)) +# Set the interpolation functin to Bezier so that +# the yarn tangents specified above are respected +StitchYarn.AssignInterpolation(CInterpolationBezier()) +# Set a lower surface mesh resolution than for the inlays. +# The stitching is so thin that a high resolution is not needed +StitchYarn.SetResolution(8) +# Translate the stitch yarn so that it falls between the inlay yarns +StitchYarn.Translate(XYZ(0.5 * s, 0.5 * s + r, 0)) +# Add the yarn to the textile +Textile.AddYarn(StitchYarn) + +# Create a domain and assign it to the textile +# Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -1), XYZ(4*s, 4*s, 1))) +Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.2), XYZ(4 * s, 4 * s, 0.4))) + +# Add the textile +AddTextile("NonCrimpFabric", 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 = 256, 256, 256 +vm = CRectangularVoxelMesh() + +vm.SaveVoxelMesh( + Textile, + "data/NonCrimpFabric.vtu", + nx, + ny, + nz, + False, + True, + NO_BOUNDARY_CONDITIONS, + 0, + VTU_EXPORT, +) + +vtk2h5( + vtk_files=["data/NonCrimpFabric.vtu"], + h5_file_path="data/TexGen_NonCrimpFabric.h5", + grp_name="/", + overwrite=True, + data_fields=["YarnIndex", "Orientation"], +) +os.remove("data/NonCrimpFabric.vtu") +write_xdmf( + h5_filepath="data/TexGen_NonCrimpFabric.h5", + xdmf_filepath="data/TexGen_NonCrimpFabric.xdmf", + microstructure_length=[4, 4, 0.6], + time_series=False, + verbose=True, +) diff --git a/MSUtils/TexGen/TriaxialBraid.py b/MSUtils/TexGen/TriaxialBraid.py new file mode 100644 index 0000000..34dfbd5 --- /dev/null +++ b/MSUtils/TexGen/TriaxialBraid.py @@ -0,0 +1,137 @@ +# ============================================================================= +# TexGen: Geometric textile modeller. +# Copyright (C) 2006 Martin Sherburn + +# 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. +# ============================================================================= + +from TexGen.Core import * +import math + +# Create a textile +Textile = CTextile() + +# Create a python list containing 3 yarns +Yarns = [CYarn(), CYarn(), CYarn()] + +# Add nodes to the yarns to describe their paths +# First define the angled yarns +Yarns[0].AddNode(CNode(XYZ(0, 0, 0))) +Yarns[0].AddNode(CNode(XYZ(0.5, 0.2887, 0.2))) +Yarns[0].AddNode(CNode(XYZ(1, 0.5774, 0.2))) +Yarns[0].AddNode(CNode(XYZ(1.5, 0.8660, 0))) +Yarns[0].AddNode(CNode(XYZ(2, 1.1547, 0))) + +Yarns[1].AddNode(CNode(XYZ(0, 0, 0.2))) +Yarns[1].AddNode(CNode(XYZ(0.5, -0.2887, 0))) +Yarns[1].AddNode(CNode(XYZ(1, -0.5774, 0))) +Yarns[1].AddNode(CNode(XYZ(1.5, -0.8660, 0.2))) +Yarns[1].AddNode(CNode(XYZ(2, -1.1547, 0.2))) + +# Define a straight yarn +Yarns[2].AddNode(CNode(XYZ(-0.25, 0, 0.1))) +Yarns[2].AddNode(CNode(XYZ(-0.25, 0.57735, 0.1))) + +# Create a lenticular section for the +- angled yarns +AngledSection = CSectionLenticular(0.45, 0.13) + +# The section will be rotated at the appropriate points to avoid interference +# So create an interpolated yarn section +AngledYarnSection = CYarnSectionInterpPosition(True, True) +# This is the rotation angle defined +RotationAngle = math.radians(12) + +# Add rotated sections at 1/8 and 5/8 of the way along the yarn +# at angles of +- RotationAngle +AngledYarnSection.AddSection(1.0 / 8.0, CSectionRotated(AngledSection, -RotationAngle)) +AngledYarnSection.AddSection(5.0 / 8.0, CSectionRotated(AngledSection, RotationAngle)) + +# Add unrotated sections to the interpolation at intervals of 1/4 +AngledYarnSection.AddSection(0.0 / 4.0, AngledSection) +AngledYarnSection.AddSection(1.0 / 4.0, AngledSection) +AngledYarnSection.AddSection(2.0 / 4.0, AngledSection) +AngledYarnSection.AddSection(3.0 / 4.0, AngledSection) + +# Assign the rotating cross-section to the angled yarns +Yarns[0].AssignSection(AngledYarnSection) +Yarns[1].AssignSection(AngledYarnSection) +# Add repeats to those yarns +Yarns[0].AddRepeat(XYZ(2, 0, 0)) +Yarns[1].AddRepeat(XYZ(2, 0, 0)) + +# Create a lenticular section for the straight yarns and assign it +StraightSection = CSectionLenticular(0.6, 0.15) +Yarns[2].AssignSection(CYarnSectionConstant(StraightSection)) +# Add repeats for the straight yarn +Yarns[2].AddRepeat(XYZ(1, 0, 0)) + + +# Loop over all the yarns in the list +for Yarn in Yarns: + # Set the interpolation function + Yarn.AssignInterpolation(CInterpolationCubic()) + # Set the resolution of the surface mesh created + Yarn.SetResolution(20) + # Add common repeat vector to the yarn + Yarn.AddRepeat(XYZ(0, 0.57735, 0)) + # Add the yarn to our textile + Textile.AddYarn(Yarn) + +# Create a domain and assign it to the textile +Textile.AssignDomain(CDomainPlanes(XYZ(0.25, 0.0, -0.1), XYZ(2.25, 0.57735, 0.3))) + +# Add the textile +AddTextile("triaxialbraid", 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/triaxialbraid.vtu", + nx, + ny, + nz, + False, + True, + NO_BOUNDARY_CONDITIONS, + 0, + VTU_EXPORT, +) + +vtk2h5( + vtk_files=["data/triaxialbraid.vtu"], + h5_file_path="data/TexGen_triaxialbraid.h5", + grp_name="/", + overwrite=True, + data_fields=["YarnIndex", "Orientation"], +) +os.remove("data/triaxialbraid.vtu") +write_xdmf( + h5_filepath="data/TexGen_triaxialbraid.h5", + xdmf_filepath="data/TexGen_triaxialbraid.xdmf", + microstructure_length=[2.25, 0.57735, 0.3], + time_series=False, + verbose=True, +) diff --git a/MSUtils/TexGen/WeftKnit.py b/MSUtils/TexGen/WeftKnit.py new file mode 100644 index 0000000..6f7bb85 --- /dev/null +++ b/MSUtils/TexGen/WeftKnit.py @@ -0,0 +1,113 @@ +# ============================================================================= +# TexGen: Geometric textile modeller. +# Copyright (C) 2006 Martin Sherburn + +# 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 textile +Textile = CTextile() + +# Create a yarn +Yarn = CYarn() + +# Define some constants +r = 1 +sx = r * 2.5 +sy = r * 10 +ly = 0.75 * (sx + r) + +# Add nodes to the yarns to describe the yarn path +Yarn.AddNode(CNode(XYZ(0, 0, r))) +Yarn.AddNode(CNode(XYZ(sx + r, ly, 0))) +Yarn.AddNode(CNode(XYZ(sx, ly + 0.5 * sy, -r))) +Yarn.AddNode(CNode(XYZ(sx - r, ly + sy, 0))) +Yarn.AddNode(CNode(XYZ(2 * sx, 2 * ly + sy, r))) +Yarn.AddNode(CNode(XYZ(3 * sx + r, ly + sy, 0))) +Yarn.AddNode(CNode(XYZ(3 * sx, ly + 0.5 * sy, -r))) +Yarn.AddNode(CNode(XYZ(3 * sx - r, ly, 0))) +Yarn.AddNode(CNode(XYZ(4 * sx, 0, r))) + +# Assign a constant circular cross-section +Section = CSectionEllipse(2 * r, 2 * r) +Yarn.AssignSection(CYarnSectionConstant(Section)) + +# Create repeats +Yarn.AddRepeat(XYZ(4 * sx, 0, 0)) +Yarn.AddRepeat(XYZ(0, 2 * sy, 0)) + +# Set the resolution of the surface mesh created +Yarn.SetResolution(20) + +# Add the yarn to the textile +Textile.AddYarn(Yarn) + +# Translate the yarn and add it to the textile +# Note that this could be part of the repeat vectors but it is done like +# this to give the yarns different colours +Yarn.Translate(XYZ(0, sy, 0)) +Textile.AddYarn(Yarn) + +# Create a domain and assign it to the textile +Textile.AssignDomain( + CDomainPlanes(XYZ(0, -ly, -2 * r), XYZ(4 * (r * sx), 4 * sy - ly, 2 * r)) +) + +# Add the textile +AddTextile("weftknit", 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/weftknit.vtu", + nx, + ny, + nz, + False, + True, + NO_BOUNDARY_CONDITIONS, + 0, + VTU_EXPORT, +) + +vtk2h5( + vtk_files=["data/weftknit.vtu"], + h5_file_path="data/TexGen_weftknit.h5", + grp_name="/", + overwrite=True, + data_fields=["YarnIndex", "Orientation"], +) +os.remove("data/weftknit.vtu") +write_xdmf( + h5_filepath="data/TexGen_weftknit.h5", + xdmf_filepath="data/TexGen_weftknit.xdmf", + microstructure_length=[10, 40, 4], + time_series=False, + verbose=True, +) diff --git a/MSUtils/TexGen/WeftKnitClass.py b/MSUtils/TexGen/WeftKnitClass.py new file mode 100644 index 0000000..5ea2907 --- /dev/null +++ b/MSUtils/TexGen/WeftKnitClass.py @@ -0,0 +1,79 @@ +# ============================================================================= +# TexGen: Geometric textile modeller. +# Copyright (C) 2024 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 weft knit textile with 2 wales and courses, wale height 1, loop height 1.2 and yarn thickness 0.15 +# The fifth parameter indicates whether to refine the textile to avoid intersections +WeftKnit = CTextileWeftKnit(2, 2, 1, 1.2, 1, 0.15) + +numSectionPoints = 30 +numSlaveNodes = 60 +WeftKnit.SetResolution(numSectionPoints, numSlaveNodes) + +# Setup a domain +WeftKnit.AssignDefaultDomain() + +# Select knit model (only one available currently) +WeftKnit.SetLoopModel(RAVANDI_2021) + +# Add the textile +AddTextile(WeftKnit) + +################################################### +# 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( + WeftKnit, + "data/weftknitclass.vtu", + nx, + ny, + nz, + False, + True, + NO_BOUNDARY_CONDITIONS, + 0, + VTU_EXPORT, +) + +vtk2h5( + vtk_files=["data/weftknitclass.vtu"], + h5_file_path="data/TexGen_weftknitclass.h5", + grp_name="/", + overwrite=True, + data_fields=["YarnIndex", "Orientation"], +) +os.remove("data/weftknitclass.vtu") +write_xdmf( + h5_filepath="data/TexGen_weftknitclass.h5", + xdmf_filepath="data/TexGen_weftknitclass.xdmf", + microstructure_length=[2, 2, 0.3], + time_series=False, + verbose=True, +) diff --git a/MSUtils/TexGen/cotton.py b/MSUtils/TexGen/cotton.py new file mode 100644 index 0000000..4ef586a --- /dev/null +++ b/MSUtils/TexGen/cotton.py @@ -0,0 +1,109 @@ +# ============================================================================= +# 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 textile +Textile = CTextile() + +# Create a lenticular section +Section = CSectionLenticular(0.3, 0.14) +Section.AssignSectionMesh(CSectionMeshTriangulate(30)) + +# Create 4 yarns +Yarns = (CYarn(), CYarn(), CYarn(), CYarn()) + +# Add nodes to the yarns to describe their paths +Yarns[0].AddNode(CNode(XYZ(0, 0, 0))) +Yarns[0].AddNode(CNode(XYZ(0.35, 0, 0.15))) +Yarns[0].AddNode(CNode(XYZ(0.7, 0, 0))) + +Yarns[1].AddNode(CNode(XYZ(0, 0.35, 0.15))) +Yarns[1].AddNode(CNode(XYZ(0.35, 0.35, 0))) +Yarns[1].AddNode(CNode(XYZ(0.7, 0.35, 0.15))) + +Yarns[2].AddNode(CNode(XYZ(0, 0, 0.15))) +Yarns[2].AddNode(CNode(XYZ(0, 0.35, 0))) +Yarns[2].AddNode(CNode(XYZ(0, 0.7, 0.15))) + +Yarns[3].AddNode(CNode(XYZ(0.35, 0, 0))) +Yarns[3].AddNode(CNode(XYZ(0.35, 0.35, 0.15))) +Yarns[3].AddNode(CNode(XYZ(0.35, 0.7, 0))) + +# We want the same interpolation and section shape for all the yarns so loop over them all +for Yarn in Yarns: + # Set the interpolation function + Yarn.AssignInterpolation(CInterpolationCubic()) + # Assign a constant cross-section all along the yarn + Yarn.AssignSection(CYarnSectionConstant(Section)) + # Set the resolution + Yarn.SetResolution(8) + # Add repeats to the yarn + Yarn.AddRepeat(XYZ(0.7, 0, 0)) + Yarn.AddRepeat(XYZ(0, 0.7, 0)) + # Add the yarn to our textile + Textile.AddYarn(Yarn) + +# Create a domain and assign it to the textile +Textile.AssignDomain(CDomainPlanes(XYZ(0, 0, -0.1), XYZ(0.7, 0.7, 0.25))) + +# Add the textile with the name "cotton" +AddTextile("cotton", 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/cotton.vtu", + nx, + ny, + nz, + False, + True, + NO_BOUNDARY_CONDITIONS, + 0, + VTU_EXPORT, +) + +vtk2h5( + vtk_files=["data/cotton.vtu"], + h5_file_path="data/TexGen_cotton.h5", + grp_name="/", + overwrite=True, + data_fields=["YarnIndex", "Orientation"], +) +os.remove("data/cotton.vtu") +write_xdmf( + h5_filepath="data/TexGen_cotton.h5", + xdmf_filepath="data/TexGen_cotton.xdmf", + microstructure_length=[0.7, 0.7, 0.35], + time_series=False, + verbose=True, +) diff --git a/MSUtils/TexGen/custom_weave1.py b/MSUtils/TexGen/custom_weave1.py new file mode 100644 index 0000000..bce1ca5 --- /dev/null +++ b/MSUtils/TexGen/custom_weave1.py @@ -0,0 +1,81 @@ +from TexGen.Core import * + +NumBinderLayers = 2 +NumXYarns = 3 +NumYYarns = 4 +XSpacing = 1.0 +YSpacing = 1.0 +XHeight = 0.2 +YHeight = 0.2 +weave = CTextileLayerToLayer( + NumXYarns, NumYYarns, XSpacing, YSpacing, XHeight, YHeight, NumBinderLayers +) + +# set number of binder / warp yarns +NumBinderYarns = 3 +NumWarpYarns = NumXYarns - NumBinderYarns +weave.SetWarpRatio(NumWarpYarns) +weave.SetBinderRatio(NumBinderYarns) + +# setup layers: 3 warp, 4 weft +weave.SetupLayers(3, 4, NumBinderLayers) + +# set yarn dimensions: widths / heights +weave.SetYYarnWidths(0.8) +weave.SetYYarnWidths(0.8) +weave.SetBinderYarnWidths(0.4) +weave.SetBinderYarnHeights(0.1) + +# define offsets for the binder yarns (should match NumBinderYarns) +P = [[0, 1, 3, 0], [3, 0, 0, 3], [1, 2, 2, 1]] + +# assign the z-positions to the binder yarns +for y in range(NumWarpYarns, NumXYarns): # loop through number of binder yarns + offset = 0 + for x in range(NumYYarns): # loop through the node positions + weave.SetBinderPosition(x, y, P[y - NumWarpYarns][offset]) + offset += 1 + +weave.AssignDefaultDomain() + + +################################################### +# 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( + weave, + "data/custom_weave1.vtu", + nx, + ny, + nz, + False, + True, + NO_BOUNDARY_CONDITIONS, + 0, + VTU_EXPORT, +) + +vtk2h5( + vtk_files=["data/custom_weave1.vtu"], + h5_file_path="data/TexGen_custom_weave1.h5", + grp_name="/", + overwrite=True, + data_fields=["YarnIndex", "Orientation"], +) +os.remove("data/custom_weave1.vtu") +write_xdmf( + h5_filepath="data/TexGen_custom_weave1.h5", + xdmf_filepath="data/TexGen_custom_weave1.xdmf", + microstructure_length=[4, 3, 1.43], + time_series=False, + verbose=True, +) diff --git a/MSUtils/TexGen/custom_weave2.py b/MSUtils/TexGen/custom_weave2.py new file mode 100644 index 0000000..00dba8f --- /dev/null +++ b/MSUtils/TexGen/custom_weave2.py @@ -0,0 +1,75 @@ +from TexGen.Core import * + +# Create a plain weave textile +t = 0.1 # layer thickness +weave = CTextileWeave2D(2, 2, 0.8, t, True) +weave.SwapPosition(0, 0) +weave.SwapPosition(1, 1) +weave.SetGapSize(0.01) # set a gap between yarns + +# Create the layered textile +LTextile = CTextileLayered() + +# Add a plain weave layer with no offsets +LTextile.AddLayer(weave, XYZ(0, 0, 0)) + +# Add a second plain weave layer, offset in the z-direction +# by the textile thickness and by 0.5 and 0.5 in the x and y directions +LTextile.AddLayer(weave, XYZ(0.5, 0.5, t)) + +# Get the default domain of the plain weave and its min and max coordinates +Domain = weave.GetDefaultDomain() +Min = XYZ() +Max = XYZ() +Domain.GetBoxLimits(Min, Max) + +# Get the domain upper surface +Plane = PLANE() +index = Domain.GetPlane(XYZ(0, 0, -1), Plane) +# Offset the top surface of the domain by the depth of the plain weave domain +Plane.d -= Max.z - Min.z +Domain.SetPlane(index, Plane) + +# Assign the extended domain to the layered textile +LTextile.AssignDomain(Domain) + +################################################### +# 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( + LTextile, + "data/custom_weave2.vtu", + nx, + ny, + nz, + False, + True, + NO_BOUNDARY_CONDITIONS, + 0, + VTU_EXPORT, +) + +vtk2h5( + vtk_files=["data/custom_weave2.vtu"], + h5_file_path="data/TexGen_custom_weave2.h5", + grp_name="/", + overwrite=True, + data_fields=["YarnIndex", "Orientation"], +) +os.remove("data/custom_weave2.vtu") +write_xdmf( + h5_filepath="data/TexGen_custom_weave2.h5", + xdmf_filepath="data/TexGen_custom_weave2.xdmf", + microstructure_length=[1.6, 1.6, 0.22], + time_series=False, + verbose=True, +)