STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia ›...

26
Outline Obligatory Introduction Motivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and SciPy B. Malengier Department of Mathematical Analysis Research Group NaM 2 , Gent University EuroScipy 2011, 27 August, Paris Collaborators: PhD-students T.Goessens, P.Li B. Malengier STICK Toolbox, Euroscipy 2011

Transcript of STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia ›...

Page 1: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

STICK: modeling textile using FiPy and SciPy

B. Malengier

Department of Mathematical AnalysisResearch Group NaM2, Gent University

EuroScipy 2011, 27 August, Paris

Collaborators: PhD-students T.Goessens, P.Li

B. Malengier STICK Toolbox, Euroscipy 2011

Page 2: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

Outline

Obligatory Introduction

Motivation

Toolbox in more DetailsInputWhat to run?Fiber modelYarn modelUsing FiPy

B. Malengier STICK Toolbox, Euroscipy 2011

Page 3: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

Funding

Part of this work is funded by

I NOBUG: FP7 EU project number 228639 under the leadership of theDepartment of Textile, UGent. Novel release system and bio-based utilitiesfor mosquito repellent textiles and garments. Part: reagent transportthrough textile materials (from multilayers or µcaps).15.10.2009-14.10.2013.

I ALL4REST: FP7 EU project SME -2010-1-262652-All4Rest under theleadership of AITEX (Spain), Integrated Solutions for Improve the qualityof the rest. Part: thermo-regulating devices in textile rest elements(conductive fibers, PCM µcaps). 01.01.2011-31.12.2012

B. Malengier STICK Toolbox, Euroscipy 2011

Page 4: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

Status

I This is a work in progress. 2 PhD students and myself are developing themodels as needed in the projects

I Much (most?) work remains to be done.

I Decision was taken to create a toolbox that could be reused for otherprojects (noble goal)

I Toolbox was named STICK, Sophisticated Textile Information ComputingKit

I This is an academic environment developing a set of models useful forSMEs in the Textile industry. Belgium has many small textile SMEsconcentrating on technical textiles with a high added value.

B. Malengier STICK Toolbox, Euroscipy 2011

Page 5: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

Motivation

Why open source, why python, ...

These are models created in an academic environment to optimize/understandexisting textile products. Typically one does computations with existing toolkits(fluent, openfoam, freefem, dune, ...), which are saved on some hard-diskshould the need arise to reuse.

A single SME project cannot fund the development of a toolbox for textilesimulation, so one risks to have many diverse unrelated codesets.

Normal workflow: use the toolkit that seems best suited, specialize in it, offerservices with it, extend it via research and PhDs. Only base toolkit is visibleopen source code.

B. Malengier STICK Toolbox, Euroscipy 2011

Page 6: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

Motivation Open Source

I base libraries are in public domain or BSD type, so allow proprietary code

I small SME don’t have the knowledge internally to maintain or develop thecode ⇒ fear bigger players could just take the code makes proprietary orGPL favourable

I university keeps copyright on code, even when done in terms of a (SME)project, so or open source license is used so that SME has access to thecode in the future, or some license of use is determined at start of project(cumbersome, university would not want too broad a license)

I funding of one project does not suffice to create the tool. SME hasbenefits if there is access to the code also after the project.

I as academic researchers we are interested in problem solving and like thatothers use our code. We are not interested in payment (but universityboard will always be on the lookout to maximize profits!!)

Hence GPL is chosen, to alleviate fear of competitor usurping the code, and tomake maximum collaboration and use possible (also in the future when projectitself is finished).

B. Malengier STICK Toolbox, Euroscipy 2011

Page 7: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

Motivation Python-SciPy

I Python is a language most people like a lot when starting with it

I Many programming approaches possible (structural, object oriented,functional)

I Profiling easy, bottlenecks can be done native if needed (Fortran, C, C++)

I NumPy, SciPy mean most base functionality is present. Sufficientpackages that extend it for specialized needs.

I Our master or PhD students don’t have a background of programming...but often know matlab

I Some promise of multi-platform

However, I have yet to find a student that was able to install the entiretoolchain in windows. Why is that? Master students of engineering ormathematics have too little software knowledge or we did not make it easyenough?It is important that windows works for SMEs, also without enthought EPD.

B. Malengier STICK Toolbox, Euroscipy 2011

Page 8: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

Motivation Python-SciPy

I Python is a language most people like a lot when starting with it

I Many programming approaches possible (structural, object oriented,functional)

I Profiling easy, bottlenecks can be done native if needed (Fortran, C, C++)

I NumPy, SciPy mean most base functionality is present. Sufficientpackages that extend it for specialized needs.

I Our master or PhD students don’t have a background of programming...but often know matlab

I Some promise of multi-platform

However, I have yet to find a student that was able to install the entiretoolchain in windows. Why is that? Master students of engineering ormathematics have too little software knowledge or we did not make it easyenough?It is important that windows works for SMEs, also without enthought EPD.

B. Malengier STICK Toolbox, Euroscipy 2011

Page 9: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

Motivation Toolbox

I Higher level code using existing toolkits require a lot of boiler plate code,which is better grouped (eg presentation of textile yarns, defenition of inifiles, inverse code, ...)

I For experimentation, models must be run many times with slightvariations. Generic code to handle this needed.

I We are at a moment in time where normal hardware can run complicatedmulti-physics, multi-scale models. Different tools are however optimal forthe different parts. Some way needed to group this

I Low level improvements should however be done in the base toolkits (scipy,fipy, pysundials, ...). Specific patchsets can be included in the toolbox

I a “red thread” over different textile projects: create the specific model andimprove the toolbox at the same time (loose time to win time)

B. Malengier STICK Toolbox, Euroscipy 2011

Page 10: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

Motivation

3 scales present: fiber, yarn, fabric (&environment).

Different parties interested ininvestigating/optimizing properties:

I types of fiber (strength, thinkness,material, ...)

I construction of yarn (single,twisted, # fibers, ...)

I construction of the fabric(padding, weaving techniques, ...)

Figure: Structure of fabric

Figure: Structure of a yarn cross-section

B. Malengier STICK Toolbox, Euroscipy 2011

Page 11: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

Target User

In a small SME working on added value textile, there is normally a smallresearch unit, consisting of chemical engineers/chemisists or mechanicalengineers. No programming background.

Hence, the interaction with the code should be simple. There is no time for aGUI, so we opt for a cascade of ini files with light input validation: Define thefiber characteristics in an ini file, yarn characteristics (pointing to fiber), fabriccharacteristics (pointing to yarn).

B. Malengier STICK Toolbox, Euroscipy 2011

Page 12: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

Config def

Every part registers the defaults for it’s settings by inheriting a custom writtenConfigManager. A config hence acts as a datastore of the user settings whichis accessible everywhere via a singleton type implementation.

Access: config.get(’fiber.radius pure fiber’)

B. Malengier STICK Toolbox, Euroscipy 2011

Page 13: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

What to run?

A single delegation script to parse command and pass operation correctly

./stick.py yarn2d -i ∼/myinifile.ini

B. Malengier STICK Toolbox, Euroscipy 2011

Page 14: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

Fibers

Fibers can be approximated by circles (neglecting length variations due tosymmetry). Hence reduction to a 1D radial coordinate system is performed.Whatever model is required, ode methods (method of lines) are optimal toobtain solutions fast.

Unfortunately, scipy’s ode solvers are not state of the art. This is not a problemfor our models at the moment, but does not give confidence. Sundials solversare tracked but who maintains?

B. Malengier STICK Toolbox, Euroscipy 2011

Page 15: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

Fibers

Fibers can be approximated by circles (neglecting length variations due tosymmetry). Hence reduction to a 1D radial coordinate system is performed.Whatever model is required, ode methods (method of lines) are optimal toobtain solutions fast.

Unfortunately, scipy’s ode solvers are not state of the art. This is not a problemfor our models at the moment, but does not give confidence. Sundials solversare tracked but who maintains?

B. Malengier STICK Toolbox, Euroscipy 2011

Page 16: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

Yarn

Depending on the requirement, a yarn can be modelled as a 1D radial model,or a 2D model with a specific yarn-fiber layout. The 1D model is similar to theone of 1D fiber model, but fiber properties must be estimated (fromexperiments and upscaling of fiber calculations).For a 2D model, a yarn-fiber layout must be constructed and simulated.

B. Malengier STICK Toolbox, Euroscipy 2011

Page 17: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

Yarn-fiber layout: virtual Location Approach

For the virtual location method the yarn cross-section is firstly divided intoseveral layers (called ’Ring Zones’), based on the radius of fiber in it, then eachlayer is filled with ’virtual locations’ which are circular shaped.

B. Malengier STICK Toolbox, Euroscipy 2011

Page 18: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

Yarn-fiber layout: results

(a) (b) (c) (d)

Figure: (a) Fiber distribution with virtual locations; (b) Fiber distribution withshifted-virtual locations; (c) Fiber distribution with overlapping; (d) Two kinds offibers with irregular distribution

B. Malengier STICK Toolbox, Euroscipy 2011

Page 19: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

Example of higher level recurring code: task for Scipy?

Comparing two large lists as efficiently as possible (find overlap).

chunk_size = 20; indices = sp.arange(len(xpos))

nr_chunks = int(round(len(indices) / chunk_size + 0.5))

for chunk in range(nr_chunks):

chunk_indices = indices[chunk*chunk_size:(chunk+1)*chunk_size]

chunk_size = len(chunk_indices) #last length may be different

tmpself_XvertexCoords = self_XvertexCoords[..., chunk_indices]

tmpradother = rad[...,chunk_indices]

#repeat self_X as many times as vert in other

self_vertexCoordMap = np.repeat(tmpself_XvertexCoords,

other_XvertexCoords.shape[-1], axis=1)

self_radMap = np.repeat(tmpradother, rad.shape[-1], axis=1)

#repeat other_X as many times as chunk_size

other_vertexCoordMap = np.repeat(other_XvertexCoords,

chunk_size, axis=0).reshape((other_XvertexCoords.shape[0],

chunk_size*other_XvertexCoords.shape[-1]))

other_radMap = np.repeat(rad, chunk_size, axis=0).reshape(

(1, chunk_size*rad.shape[-1]))

B. Malengier STICK Toolbox, Euroscipy 2011

Page 20: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

#substract both and calc distance of all pairs

tmp = self_vertexCoordMap - other_vertexCoordMap

tmp = np.sum(tmp*tmp, axis=0) #square of distance

tmp = tmp.reshape((chunk_size,other_XvertexCoords.shape[-1]))

#the required distance everywhere is sum of radius

Dreqsquared = sp.power((1+(NONTOUCH_FAC-1)/2)*(self_radMap + other_radMap), 2)

Dreqsquared = Dreqsquared.reshape((chunk_size,rad.shape[-1]))

#now determine all indices that overlap

result = (tmp < Dreqsquared) # point itself is returned too!

for (nr, ind) in enumerate(chunk_indices):

tooclose[ind] = indices[result[nr]]

dist[ind] = sp.sqrt(tmp[nr][result[nr]])

distreq[ind] = sp.sqrt(Dreqsquared[nr][result[nr]])

return (tooclose, dist, distreq)

B. Malengier STICK Toolbox, Euroscipy 2011

Page 21: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

#substract both and calc distance of all pairs

tmp = self_vertexCoordMap - other_vertexCoordMap

tmp = np.sum(tmp*tmp, axis=0) #square of distance

tmp = tmp.reshape((chunk_size,other_XvertexCoords.shape[-1]))

#the required distance everywhere is sum of radius

Dreqsquared = sp.power((1+(NONTOUCH_FAC-1)/2)*(self_radMap + other_radMap), 2)

Dreqsquared = Dreqsquared.reshape((chunk_size,rad.shape[-1]))

#now determine all indices that overlap

result = (tmp < Dreqsquared) # point itself is returned too!

for (nr, ind) in enumerate(chunk_indices):

tooclose[ind] = indices[result[nr]]

dist[ind] = sp.sqrt(tmp[nr][result[nr]])

distreq[ind] = sp.sqrt(Dreqsquared[nr][result[nr]])

return (tooclose, dist, distreq)

Problem:

I chunk size relates to RAM installed but here fixed to 20

I this could be ran in parallel ....

I Cython/weave after all?

B. Malengier STICK Toolbox, Euroscipy 2011

Page 22: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

FiPy: a finite volume solver in Python

I Finite volume package

I Object oriented PDE solver

I Terms for transient diffusion, convection and standard sources, enablingthe solution of arbitrary combinations of coupled elliptic, hyperbolic andparabolic PDEs.

I Currently implemented models include phase field treatments ofpolycrystalline, dendritic, and electrochemical phase transformations aswell as a level set treatment of the electrodeposition process

B. Malengier STICK Toolbox, Euroscipy 2011

Page 23: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

Example: Lid Driven Cavity.

>>> mesh = Grid2D(nx=N, ny=N, dx=dL, dy=dL)

>>> pressure = CellVariable(mesh=mesh, name=’pressure’)

>>> xVelocity = CellVariable(mesh=mesh, name=’X velocity’)

>>> velocity = FaceVariable(mesh=mesh, rank=1, name=’velocity’))

>>> velocity[0, mesh.getFacesTop().getValue()] = U

[skip]

>>> xVelocityEq = PowerLawConvectionTerm(coeff=velocity) - \

... DiffusionTerm(coeff=viscosity) + pressure.getGrad().dot([1.,0.])

[skip]

>>> bcs = (FixedValue(faces=mesh.getFacesLeft(), value=0.), [skip]

>>> for sweep in range(sweeps): [skip]

... pres = pressureCorrectionEq.sweep(var=pressureCorrection,

... boundaryConditions=bcsPC)

B. Malengier STICK Toolbox, Euroscipy 2011

Page 24: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

Example: Lid Driven Cavity Results

B. Malengier STICK Toolbox, Euroscipy 2011

Page 25: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

InputWhat to run?Fiber modelYarn modelUsing FiPy

FiPy for STICK

I Used for 2d yarn simulation

I Mesh with Gmsh, equations with Fipy, visualization Matplotlib

I Data of fibers comes from fiber model

B. Malengier STICK Toolbox, Euroscipy 2011

Page 26: STICK: modeling textile using FiPy and SciPycage.ugent.be › ~bm › varia › sticktoolbox.pdfMotivation Toolbox in more Details Future Work STICK: modeling textile using FiPy and

OutlineObligatory Introduction

MotivationToolbox in more Details

Future Work

Future Work

I Upscaling to fabric level

I Match/Validate with gas chromatography experiments

I Optimization: best fiber mix, best layer organization, ...

I Extra physics: heat, µcaps, micro-organisms, ...

B. Malengier STICK Toolbox, Euroscipy 2011