1 year ago

#365228

test-img

Jansen

Creating a structured non-rectangular mesh in python

I am trying to model the temperature distribution in a rocket nozzle, I am doing this with the heat equation solved using finite difference method. In order to apply this method I need my mesh to fit the geometry of my modelled rocket engine. I have trouble doing this as the meshgrid function seems to only work for rectangular mesh's.

I tried using the code bellow, and want the mesh to only go up to the red line, but cannot find a way of doing this.

import numpy as np
import matplotlib.pyplot as pl
from mpl_toolkits import mplot3d

# Grid spacing size
Dx = 0.1
L = 10
L_T = 2
D_T = 1
D_C = 2
D_E = 5
maxtime = 10

# forming the x grid spacing
x = np.arange(0,L,Dx)

y = np.zeros(len(x))
# factor to scale loop so have integers
m = 10
# gradient of the engine line
M = (D_C-D_T)/(L_T)
#inital height of engine is at combustion point.
y[0] = D_C
for i in range(1,int(L_T*m),int(Dx*m)):
    y[i] = y[i-1] - M*Dx
    #Y[i] = np.arange(0,y[i])
for i in range(int(L_T*m),int(L*m),int(Dx*m)):
    y[i] = y[i-1] + M*Dx

# set meshgrids
Xg , Yg = np.meshgrid(x,y)
pl.scatter(Xg,Yg)

pl.plot(x,y,c='red')

python

mesh

numerical-methods

0 Answers

Your Answer

Accepted video resources