6
$\begingroup$

Consider the following graph, which is obtained from a VoronoiMesh

pts = RandomReal[{-1, 1}, {10, 2}];
mesh = VoronoiMesh[pts];
gr = Graph[mesh["Edges"], VertexCoordinates -> mesh["Coordinates"]]

enter image description here

Assume such graph has $M$ vertices. Imagine that, for each vertex position $r_i$ ($1\leq i\leq M$), I want to solve $$ \frac{dr_i}{dt}=F_i(t) $$ for some "force" function $F_i$. This is often known in epithelial biology as the vertex model.

My question is: given gr as the initial condition (or, better said, its vertices positions), is it possible to solve the ODE for each vertex and keep the corresponding edges fixed? That is, between any two connected vertices, the edge connecting them is automatically updated and kept linking the corresponding vertices when they move according to the equation.

$\endgroup$
1
  • 2
    $\begingroup$ Nothing hinders you so solve the ode for the vertex positions and to update gr with gr = SetProperty[gr, VertexCoordinates -> newcoords]. So do not feed NDSolve with gr; just feed it with PropertyValue[gr, VertexCoordinates]. $\endgroup$ Commented Feb 3, 2020 at 20:59

1 Answer 1

9
$\begingroup$

Maybe something like:

SeedRandom[123]
pts = RandomReal[{-1, 1}, {10, 2}];
mesh = VoronoiMesh[pts];
vc = mesh["Coordinates"];

ClearAll[pndsv]
pndsv = ParametricNDSolveValue[{x'[t] == t^2/2  y[t], 
    y'[t] == - x[t] t, x[0] == x0, y[0] == y0}, {x, y}, {t, 10}, {x0, y0}];

grph = Graph[mesh["Edges"], VertexCoordinates -> vc, 
   VertexSize -> Scaled[.03], VertexStyle -> {v_ :> ColorData[97][v]},
   EdgeStyle -> Directive[Thick, Opacity[1], Black], 
   VertexLabels -> Placed["Name", Center], 
   PlotRange -> {{-3, 3}, {-3, 3}}, ImageSize -> 500];

Manipulate[SetProperty[grph,
  {VertexCoordinates -> {v_ :> Through[pndsv[## & @@ vc[[v]]][t]]}, 
   Prolog -> First[ParametricPlot[Evaluate[Table[Through[(pndsv[## & @@ i])@τ], {i, vc}]], 
      {τ, 0.0001, t},
      PlotStyle -> (Opacity[.5, ColorData[97]@#] & /@ VertexList[grph])]]}], 
   {{t, 0}, 0, 10}]

enter image description here

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you, this is brilliant! Any reason for ClearAll[pndsv] line? $\endgroup$
    – sam wolfe
    Commented Feb 4, 2020 at 10:26
  • 2
    $\begingroup$ @samwolfe (answering for kglr) reason is that it is because it is a good programming habit. By clearing the expression you will then explicitly define, you prevent any issues that would arise with predefined values for the expression. $\endgroup$ Commented Feb 5, 2020 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.