From a1c3a6483debddc8720cd450f8fc59fff2c1a9af Mon Sep 17 00:00:00 2001 From: Romain Boman <romain.boman@gmail.com> Date: Thu, 13 Mar 2025 11:49:24 +0100 Subject: [PATCH] add principal strain extraction script --- min_max_strain.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 min_max_strain.py diff --git a/min_max_strain.py b/min_max_strain.py new file mode 100644 index 0000000..41d461f --- /dev/null +++ b/min_max_strain.py @@ -0,0 +1,38 @@ +#! /usr/bin/env python3 +# -*- coding: utf-8 -*- +# +# extract principal strains from results +# (run this script in the workspace folder) + +import gmsh +import numpy as np + +gmsh.initialize() +gmsh.merge('mesh.msh') +gmsh.merge('smooth_strain_tensor.msh') + +dataType, tags, data, time, numComp = gmsh.view.getModelData(1, 0) + +# compute the 3 principal strains from nodal strain tensor + +e1s = [] +e2s = [] +e3s = [] + +for epl in data: + [xx, xy, xz, yx, yy, yz, zx, zy, zz] = epl + # compute the 3 principal strains + epl = np.array([[xx, xy, xz], [yx, yy, yz], [zx, zy, zz]]) + eigvals = np.linalg.eigvals(epl) + eigvals = np.sort(eigvals) + e1s.append(eigvals[0]) + e2s.append(eigvals[1]) + e3s.append(eigvals[2]) + +e1s = np.array(e1s) +e2s = np.array(e2s) +e3s = np.array(e3s) + +# display min of lowest principal strain and max of highest principal strain +print(f'e1_min = {np.min(e1s)}') +print(f'e3_max = {np.max(e3s)}') -- GitLab