|
| 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