球形坐标Jacobian分区的解决方法

发布于 2025-02-13 13:27:09 字数 1027 浏览 2 评论 0原文

我有数据可视化问题。 简而言之,我正在研究一个涉及极地球形坐标网格的项目,并试图为每个细胞求解ODE(化学反应)的耦合系统。 由于特定的原因,我需要我的状态向量为形式(r^2*sin(theta)*n_i),i = {1,2,3 ...}。

我在下面重写了我的问题的快速示例,您可以按原样运行它。 为什么我认为CST2等于NP.Ones(A [0]。Shape),但没有显示均匀的PCOLORMESH。 更令人惊讶的是,为什么添加配色栏会使此问题消失?

我最好的猜测是,除以r^2*sin(theta),这引起了数值问题,但是我该如何解决呢? (我需要在没有曲率术语的情况下查看我的数据,以解释雅各布分区对我来说似乎是必不可少的)。

import numpy as np
import matplotlib.pylab as plt
fig, ax = plt.subplots()

### Edges
r = np.logspace(np.log10(1), np.log10(4.6), num=14) #cell edges
theta = np.linspace(0+0.001,np.pi-0.001,num=10) 
b = np.meshgrid(r,theta)

### Center
r_c = r[0:-1] + np.ediff1d(r)/2 #get the cell center
theta_c = theta[0:-1] + np.ediff1d(theta)/2
a = np.meshgrid(r_c,theta_c)

### The jacobian division
cst = pow(a[0],2)*np.sin(a[1])
cst2 = np.copy(cst)/pow(a[0],2)/np.sin(a[1])
pcm = ax.pcolormesh(b[0]*np.cos(b[1]),\
                    b[0]*np.sin(b[1]), \
                    cst2,cmap='seismic',edgecolor='black')
# clb = fig.colorbar(pcm, ax=ax, orientation='horizontal') 

I am having data visualization issue.
Short summup, I'm working on a project involving a polar spherical coordinate mesh, and trying to solved coupled system of ODE (chemical reactions) for each cell.
For a specific reason I need my state vector to be of the form (r^2*sin(theta)*n_i), i={1,2,3...}.

I rewrote a quick example of my issue below, you can run it as is.
Why is it that cst2, which I would have assumed equal to a np.ones(a[0].shape), doesn't show a uniform pcolormesh.
And even more surprising to me, why does adding the colorbar make this issue vanish ?

My best guess is that dividing by r^2*sin(theta) causes numerical issues, but how can I workaround this ? (I need to see my data without the curvature term in order to interpret it -> the jacobian division seems mandatory to me at first thought).

import numpy as np
import matplotlib.pylab as plt
fig, ax = plt.subplots()

### Edges
r = np.logspace(np.log10(1), np.log10(4.6), num=14) #cell edges
theta = np.linspace(0+0.001,np.pi-0.001,num=10) 
b = np.meshgrid(r,theta)

### Center
r_c = r[0:-1] + np.ediff1d(r)/2 #get the cell center
theta_c = theta[0:-1] + np.ediff1d(theta)/2
a = np.meshgrid(r_c,theta_c)

### The jacobian division
cst = pow(a[0],2)*np.sin(a[1])
cst2 = np.copy(cst)/pow(a[0],2)/np.sin(a[1])
pcm = ax.pcolormesh(b[0]*np.cos(b[1]),\
                    b[0]*np.sin(b[1]), \
                    cst2,cmap='seismic',edgecolor='black')
# clb = fig.colorbar(pcm, ax=ax, orientation='horizontal') 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神经大条 2025-02-20 13:27:09

调整配方似乎有效。还使用较浅的颜色进行CMAP。

cst2 = np.copy(cst) / (pow(a[0],2)*np.sin(a[1]))
pcm = ax.pcolormesh(b[0]*np.cos(b[1]), \
                    b[0]*np.sin(b[1]), \
                    cst2,cmap='coolwarm',edgecolor='black')

Tweaking the formula slightly seems to work. Also used a lighter color for cmap.

cst2 = np.copy(cst) / (pow(a[0],2)*np.sin(a[1]))
pcm = ax.pcolormesh(b[0]*np.cos(b[1]), \
                    b[0]*np.sin(b[1]), \
                    cst2,cmap='coolwarm',edgecolor='black')

uniform color mesh

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文