Feeds:
Posts
Comments

## Simulating PDE on graphs in R

In R schematically we start with absolute value for undirected graphs and then we can modify this for metric directed graphs if need be easily.  The main issue is to keep functions as n*n matrices with vertex values along the diagonal.  Then the adjacency matrix can be used for gradient calculation.

Since we’re interested first in evolution equations, all we have to do is just evolve in the obvious way in discrete time steps.

d/dt u(x,t0) = (all the terms that required at time t_0)

So then

u(x,t_{k+1}) = u(x,t_k) + (all the terms of the PDE besides d/dt u)

So the only problem is to calculate the terms not involving d/dt and just plugging in.  This can be done right away and then tomorrow I can start playing with simulations of Navier-Stokes-like PDE.

# gradient function

graph.gradient<-function(F0,graph){
n<-length(vertices(graph))

grad<-matrix(0,nrow=n,ncol=n)

A<-adjacency(graph)
for (i in 1:n){
for (j in 1:j){
if (A[i,j]>0){
grad[i,j]<-abs(F0[i]-F0[j])
}
}
}
grad

}
graph.dot<-function(F0,F1,graph){
n<-length(vertices(graph)
A<-adjacency(graph)
s<-0
for (i in 1:n){
for (j in 1:j) {
if (A[i,j]>0){
s<-s+ F0[i,j]*F1[i,j]
}
}
}
s
}
flow.ns<-function(u0, graph,timesteps,epsilon){
H<-graph.laplacian(graph)
diffusion<- H%*%u0
gradient<-graph.gradient(u0,graph)
flow<-matrix(0,nrow=n*n,ncol=timesteps)
u[0,:]<-flatten(u0)
uk<-u0
for (t in 1:timestep){
delta<-diffusion – epsilon*graph.dot(uk,gradient)
uk<-uk+delta
u[t,:]<-flatten(uk)
}
uk
}
Ok now, we have all the code we really need to simulate a PDE on an actual numerical graph on R, including a parameter to check for phase transition if any acting like the Reynold’s number.

Now we can talk about Navier-Stokes on the market graph without any problems and be able to simulate these.  Next step is to begin simulations of PDE on graphs with the aim of understanding PHASE TRANSITIONS.

Advertisements