<jupyter_start><jupyter_text>Part 2: Couple the Brusselator with Diffusion<jupyter_code>def initializeParticles(numParticles, u0, v0):
    u = np.full(numParticles, u0)
    v = np.full(numParticles, v0)
    
    return np.vstack((u, v)).T

def initializeRandomParticles(numParticles, offset):
    u = np.random.uniform(0, 1, numParticles)
    v = np.random.uniform(0, 1, numParticles) + offset
    
    return np.vstack((u, v)).T
# Particle settings
N = 51
numParticles = N**2
lBounds, uBounds = 0, 81
dim, kind = 2, 1
h = (uBounds-lBounds)/(N)
epsilon = h
cutoff = 3*epsilon
cellSide = cutoff
offset = 7
numStren = 2

# Couple with diffusion
a, b, k, D = 1, 1.7, 1, 10
T = 10
dt = 0.01
t = 0
# All particles have same volume
V = h**2

bW = np.round(cutoff/h)
particlePos = p.createParticles(numParticles,dim,lBounds,uBounds,kind)
particleStrength = initializeRandomParticles(numParticles, 0)

particleMat,cellList,numCells = cl.createCellList(particlePos,lBounds,uBounds,cellSide)
verletList = vl.createVerletList(particleMat,cellList,numCells,cutoff)

particleMat = np.hstack((particleMat, particleStrength))
%matplotlib qt5
plt.rcParams["figure.figsize"] = (5, 5)
import time
fig = plt.figure()
ax = fig.add_subplot(111)
plt.ion()

fig.canvas.draw()

X = particleMat[:,0].reshape((N, N))
Y = particleMat[:,1].reshape((N, N))

while True:
    # Run the PSE
    pseSum = pse.applyPSE(particleMat,verletList,epsilon,numStren, dim)

    # Run the Brusselator
    br = np.array(applyBrusselator(particleMat[:,dim+1], particleMat[:,dim+2], a, b, k)).T
    
    # Apply for all strengths
    particleMat[:,(dim+1):] = particleMat[:,(dim+1):] + (pseSum*V*D/(epsilon**2) + br)*dt 

    # Apply periodic boundary conditions
    tempMat = particleMat[:,(dim+1):].reshape((N,N,-1))
    tempMat = pse.periodicBoundaries(tempMat,h,cutoff,bW,N,N)
    particleMat[:,(dim+1):] = tempMat.reshape((numParticles, numStren))
    
    # Concentration across space plot
    U=particleMat[:,dim+1].reshape((N, N))
    ax.clear()
    ax.pcolormesh(X,Y,U, cmap = "RdBu")
    ax.set_title("t = {:0.2f} s".format(t))
    fig.canvas.draw()
    plt.pause(0.001)
    
    # Update the time step
    t += dt<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15443840579710144, 'fraction_numerical': 0.025815217391304348, 'mean_word_length': 4.41421568627451, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '633198', 'license': 'MIT', 'n_tokens_mistral': 892, 'n_tokens_neox': 848, 'n_words': 174, 'path': 'Exercise-7.ipynb', 'repo_name': 'danilexn/STMS-Exercises', 'size': '2208'}