如何将笛卡尔问题转化为圆柱问题?

2024-09-28 19:31:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Pyvista在笛卡尔坐标系中显示一个回转体结构(TPMS)。我现在尝试以柱坐标显示结构。Pyvista确实显示了一些圆柱形的东西,但单位单元格长度似乎不均匀(虽然没有理由更改此参数,但我的参数“a”保持稳定。这种更改似乎特别沿z方向出现,但我不明白为什么(见图)

我有这个: enter image description here 这是我代码的一部分

谢谢你的帮助

import pyvista as pv
import numpy as np
from numpy import cos, sin, pi
from random import uniform

lattice_par = 1.0  # Unit cell length
a = (2*pi)/lattice_par

res = 200j
r, theta, z = np.mgrid[0:2:res, 0:2*pi:res, 0:4:res]
# consider using non-equidistant r for uniformity

def GyroidCyl(r, theta, z, b=0.8):
    return (sin(a*(r*cos(theta) - 1))*cos(a*(r*sin(theta) - 1))
            + sin(a*(r*sin(theta) - 1))*cos(a*(z - 1))
            + sin(a*(z - 1))*cos(a*(r*cos(theta) - 1))
            - b)

vol3 = GyroidCyl(r, theta, z)

# compute Cartesian coordinates for grid points
x = r * cos(theta)
y = r * sin(theta)

grid = pv.StructuredGrid(x, y, z)
grid["vol3"] = vol3.flatten()
contours3 = grid.contour([0])  # Isosurface = 0

pv.set_plot_theme('document')
p = pv.Plotter()
p.add_mesh(contours3, scalars=contours3.points[:, 2], show_scalar_bar=False, interpolate_before_map=True,
           show_edges=False, smooth_shading=False, render=True)
p.show_axes_all()
p.add_floor()

p.show_grid()
p.add_title('Gyroid in cylindrical coordinates')
p.add_text('Volume Fraction Parameter = ' + str(b))
p.show(window_size=[2040, 1500])

Tags: importaddfalseshowpiressincos
1条回答
网友
1楼 · 发布于 2024-09-28 19:31:16

因此,您在评论中注意到,您正在尝试复制this paper中解释的策略。他们所做的是取一个普通的回转体单元,然后把它转换成一个圆柱壳。如果igloos是圆柱形的,那么回转体单元就是一块雪砖。把它们放在一个挨着一个的地方,把它们堆成一列,你就得到了一个圆柱体

由于我不能使用报纸上的数字,我们必须自己重新制作一些。因此,必须从隐式函数定义的正则gyroid开始

cos(x) sin(y) + cos(y) sin(z) + cos(z) sin(x) = 0

(或其某些变体)。以下是单个单元的外观:

import pyvista as pv
import numpy as np

res = 100j
a = 2*np.pi
x, y, z = np.mgrid[0:a:res, 0:a:res, 0:a:res]

def Gyroid(x, y, z):
    return np.cos(x)*np.sin(y) + np.cos(y)*np.sin(z) + np.cos(z)*np.sin(x)

# compute implicit function
fun_values = Gyroid(x, y, z)

# create grid for contouring
grid = pv.StructuredGrid(x, y, z)
grid["vol3"] = fun_values.ravel('F')
contours3 = grid.contour([0])  # isosurface for 0

# plot the contour, i.e. the gyroid
pv.set_plot_theme('document')
plotter = pv.Plotter()
plotter.add_mesh(contours3, scalars=contours3.points[:, -1],
                 show_scalar_bar=False)
plotter.add_bounding_box()
plotter.enable_terrain_style()
plotter.show_axes()
plotter.show()

single unit cell of the conventional gyroid lattice

使用“单位细胞”一词意味着有一个潜在的无限晶格,它可以通过将这些(矩形)单位细胞整齐地堆叠在一起来构建。通过一些想象,我们可以说服自己这是真的。或者我们可以看看这个公式,注意到由于三角函数,函数在xyz中是周期的,周期为2*pi。这也告诉我们,我们可以通过引入晶格参数abc,将单位单元转换为具有任意矩形尺寸:

cos(kx x) sin(ky y) + cos(ky y) sin(kz z) + cos(kz z) sin(kx x) = 0, where
kx = 2 pi/a
ky = 2 pi/b
kz = 2 pi/c

(这些kxkykz量在固体物理学中称为波矢量。)

相应的更改仅影响标题:

res = 100j
a, b, c = lattice_params = 1, 2, 3
kx, ky, kz = [2*np.pi/lattice_param for lattice_param in lattice_params]
x, y, z = np.mgrid[0:a:res, 0:b:res, 0:c:res]

def Gyroid(x, y, z):
    return (  np.cos(kx*x)*np.sin(ky*y)
            + np.cos(ky*y)*np.sin(kz*z)
            + np.cos(kz*z)*np.sin(kx*x))

gyroid with (1, 3, 5) lattice parameters

这就是我们的出发点。我们要做的是拿这个单元,弯曲它,使它对应于圆柱体上的30度圆弧,然后用这个单元堆叠圆柱体。根据这篇论文,他们用12个单位细胞在一个平面上创建了一个圆(因此产生了30度的幻数),并将三个这样的圆带相互叠放在一起以构建圆柱体

文中还相当清楚地解释了实际映射。而函数的原始{}、{}和{}参数基本上分别在{}、{}和{}之间插值,在新设置中{}在半径范围{}内插值,{}在角度范围{}内插值,{}只是{}。(在xy这两篇文章中,关于这个约定似乎是相反的,但这并不重要。如果它重要,那就留给读者作为练习。)

所以我们需要做的是或多或少地保留当前的网格点,但是转换相应的xyz网格点,使它们位于圆柱体上。这里有一个例子:

import pyvista as pv
import numpy as np

res = 100j
a, b, c = lattice_params = 1, 1, 1
kx, ky, kz = [2*np.pi/lattice_param for lattice_param in lattice_params]
r_aux, phi, z = np.mgrid[0:a:res, 0:b:res, 0:3*c:res]

# convert r_aux range to actual radii
r1, r2 = 1.5, 2
r = r2/a*r_aux + r1/a*(1 - r_aux)

def Gyroid(x, y, z):
    return (  np.cos(kx*x)*np.sin(ky*y)
            + np.cos(ky*y)*np.sin(kz*z)
            + np.cos(kz*z)*np.sin(kx*x))

# compute data for cylindrical gyroid
# r_aux is x, phi / 12 is y and z is z
fun_values = Gyroid(r_aux, phi * 12, z)

# compute Cartesian coordinates for grid points
x = r * np.cos(phi*ky)
y = r * np.sin(phi*ky)
grid = pv.StructuredGrid(x, y, z)
grid["vol3"] = fun_values.ravel('F')
contours3 = grid.contour([0])

# plot cylindrical gyroid
pv.set_plot_theme('document')
plotter = pv.Plotter()
plotter.add_mesh(contours3, scalars=contours3.points[:, -1],
                 show_scalar_bar=False)
plotter.add_bounding_box()
plotter.show_axes()
plotter.enable_terrain_style()
plotter.show()

cylindrical gyroid

如果要查看圆柱形设置中的单个转换单位单元,请为函数使用phiz的单个域,并仅将网格点转换为1/12的整圆:

fun_values = Gyroid(r_aux, phi, z/3)

# compute Cartesian coordinates for grid points
x = r * np.cos(phi*ky/12)
y = r * np.sin(phi*ky/12)
grid = pv.StructuredGrid(x, y, z/3)

但在(不再是一个)单元中不容易看到曲率:

transformed unit cell

相关问题 更多 >