Skip to content

Commit

Permalink
Version 3 including DVC
Browse files Browse the repository at this point in the history
Including DVC
  • Loading branch information
jcpassieux committed Apr 3, 2023
1 parent 89087f1 commit 849d015
Show file tree
Hide file tree
Showing 19 changed files with 1,509 additions and 357 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# pyxel
>**py**thon library for e**x**perimental mechanics using finite **el**ements
**pyxel** is an open-source Finite Element (FE) Digital Image Correlation (DIC) library for experimental mechanics application. It is freely available for research and teaching. It is based on `numpy`, `scipy` and `matplotlib`
**pyxel** is an open-source Finite Element (FE) Digital Image/Volume Correlation (DIC/DVC) library for experimental mechanics application. It is freely available for research and teaching.

<p align="center">
<img src="https://github.com/jcpassieux/pyxel/blob/master/pyxel.png" width="150" title="hover text">
</p>

In its present form, it is restricted to 2D-DIC. Stereo (SDIC) and Digital Volume Correlation (DVC) will be updated later.
The gray level conservation problem is written in the physical space. It relies on camera models (which must be calibrated) and on a dedicated quadrature rule in the FE mesh space. Considering only 2D-DIC and front-parallel camera settings, the implemented camera model is a simplified pinhole model (including only 4 parameters: 2 translations, 1 rotation and the focal length). More complex camera models (including distorsions) could easily be implemented within this framework (next update?). The library natively includes linear and quadratic triangles and quadrilateral elements. The library also exports the results in different format such that the measurements can be post-processed ether with MatPlotLib or using Paraview.
In its present form, it is restricted to 2D-DIC and 3D-DVC. Stereo (SDIC) will be updated later.
The gray level conservation problem is written in the physical space. It relies on camera models (which must be calibrated) and on a dedicated quadrature rule in the FE mesh space. Considering front-parallel camera settings, the implemented camera model is a simplified pinhole model (including only 4 parameters 2D: 2 translations, 1 rotation and the focal length and 7 parameters in 3D: focal length, 3 rotations, 3 translations) . More complex camera models (including distorsions) could easily be implemented within this framework (next update?). The library natively includes linear and quadratic triangles, quadrilateral, tetraedral, hexaedral elements. The library also exports the results in different format such that the measurements can be post-processed ether with MatPlotLib or using Paraview.

1. SCRIPT FILE
- pyxel is a library. For each testcase, a script file must be written.
Expand All @@ -27,11 +27,10 @@ The gray level conservation problem is written in the physical space. It relies
```python
n = np.array([[x0, y0], [x1, y1], ...])
```
- There is an home made mesher for parallelipedic domains, given the approximate elements size in each direction (see examples).
- a (not robust) parser for GMSH and Abaqus meshes is also embeded in the library.
But prefer using existing open-source python parsers.
- There is an home made mesher for parallelipedic domains, given the approximate elements size in each direction (see examples). We recommand to use external meshers like, for instance, `gmsh`
- To read/write the meshes, we rely on the library `meshio`.

3. USING THE LIBRARY
3. USING THE LIBRARY FOR A 2D ANALYSIS
- Open the mesh:
```python
m = px.ReadMesh('mesh.msh')
Expand Down Expand Up @@ -63,7 +62,7 @@ The gray level conservation problem is written in the physical space. It relies
**pyxel** is distributed under the terms of CeCILL which is a french free software license agreement in the spirit of GNU GPL

6. DEPENDANCIES
numpy, scipy, meshio, gmsh, cv2 (opencv-python), numba (optional)
`numpy`, `scipy`, `matplotlib`, `opencv-python`, `scikit-image`, `meshio`, `gmsh`

# References

Expand Down
77 changes: 77 additions & 0 deletions data/dvc_test/run_dvc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

import numpy as np
import pyxel as px

"""
Prior to runnning this code, Please download the dataset below
Lee, Peter, LaVallee, Yan, & Bay, Brian. (2022).
Dynamic X-ray CT of Synthetic magma for Digital Volume Correlation analysis (1.0.0) [Data set].
Zenodo. https://doi.org/10.5281/zenodo.4835668
Then downsample the images to run the sample code faster.
"""

# refname = 'dataset_0.npy'
# defname = 'dataset_1.npy'
# f = px.Volume(refname).Load()
# f.SubSample(2)
# np.save('dataset_0_binning2', f.pix)
# g = px.Volume(defname).Load()
# g.SubSample(2)
# np.save('dataset_1_binning2', g.pix)

#%%
refname = 'dataset_0_binning2.npy'
defname = 'dataset_1_binning2.npy'

f = px.Volume(refname).Load()
print(f.pix.shape)
f.Plot()
f.VTKImage('RefVol')

cpos = np.array([50, 155, 153])
m = px.TetraMeshCylinder(cpos[0], cpos[1], cpos[2], 110, 300, 15)
m.n -= cpos[np.newaxis]
m.Write('mesh.vtk')
cam = px.CameraVol([1, cpos[0], cpos[1], cpos[2], 0, -np.pi/2, 0])
px.PlotMeshImage3d(f, m, cam)

# u, v, w = cam.P(m.n[:,0], m.n[:,1], m.n[:,2])
# m.n = np.c_[u, v, w]
# m.Write('mesh_imageCSys.vtk')

#%% INIT
m.Connectivity()
m.DVCIntegration(5)
f = px.Volume(refname).Load()
g = px.Volume(defname).Load()
f.BuildInterp()
g.BuildInterp()
U0 = px.MultiscaleInit(f, g, m, cam, scales=[3, 2, 1])

#%% RUN
m.GetApproxElementSize(cam, 'min')
m.DVCIntegration(10)
L = m.Tikhonov()
U, res = px.Correlate(f, g, m, cam, U0=U0, l0=15, L=L)

px.PlotMeshImage3d(g, m, cam, U=U)

#%% Export in the Mesh CSYS
m.VTKSol('disp', U)

#%% Export Solution in the Pixel CSys.
u, v, w = cam.P(m.n[:,0], m.n[:,1], m.n[:,2])
n0 = np.c_[u, v, w]
Un = U[m.conn]
u, v, w = cam.P(m.n[:,0] + Un[:,0], m.n[:,1] + Un[:,1], m.n[:,2] + Un[:,2])
n1 = np.c_[u, v, w]

Un = n1 - n0
Upix = np.zeros(m.ndof)
Upix[m.conn] = Un
mpix = m.Copy()
mpix.n = n0
mpix.VTKSol('disp_pix', Upix)

9 changes: 5 additions & 4 deletions pyxel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# in __init__.py

from .mesh import Mesh, StructuredMesh, ReadMesh, PVDFile
from .image import Image
from .camera import Camera, CameraNL
from .mesh import Mesh #, ReadMesh, PVDFile
from .image import Image, Volume
from .camera import Camera, CameraNL, CameraVol
from .utils import *
from .levelset import LSCalibrator
from .material import *
from .dic import *
from .exportpixmap import *
from .mesher import *
from .mesher import *
from .vtktools import VTRWriter
Binary file modified pyxel/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file modified pyxel/__pycache__/camera.cpython-39.pyc
Binary file not shown.
Binary file modified pyxel/__pycache__/dic.cpython-39.pyc
Binary file not shown.
Binary file modified pyxel/__pycache__/image.cpython-39.pyc
Binary file not shown.
Binary file modified pyxel/__pycache__/mesh.cpython-39.pyc
Binary file not shown.
Binary file modified pyxel/__pycache__/mesher.cpython-39.pyc
Binary file not shown.
Binary file modified pyxel/__pycache__/utils.cpython-39.pyc
Binary file not shown.
Binary file added pyxel/__pycache__/volume.cpython-39.pyc
Binary file not shown.
Binary file added pyxel/__pycache__/vtktools.cpython-39.pyc
Binary file not shown.
Loading

0 comments on commit 849d015

Please sign in to comment.