1
$\begingroup$

I am trying to solve coupled sets of (partial) differential equations. For my ODE, I use

ti = 0;
tf = 5;
ri = 0;
rf = 1.5;
ai = 0;
af = 2;
sol[t_, x_, y_, z_, 
    a_] = {X[t, x, y, z, a], Y[t, x, y, z, a], Z[t, x, y, z, a]} /. 
    First[NDSolve[{ D[X[t, x, y, z, a], t] == Y[t, x, y, z, a] ,
        D[Y[t, x, y, z, a], t] == Z[t, x, y, z, a]  + 3.5 t, 
        D[Z[t, x, y, z, a], t] == X[t, x, y, z, a] + 2 Sin[a t] , 
       X[0, x, y, z, a] == Sin[x + y], 
       Y[0, x, y, z, a] == Sin[2 z + y], 
       Z[0, x, y, z, a] == Sin[x + 0.5 z]}, {X, Y, Z}, {t, ti, 
       tf}, {x, ri, rf}, {y, ri, rf}, {z, ri, rf}, {a, ai, af}, 
      MaxSteps -> \[Infinity]]]; // AbsoluteTiming

This solves these equations. Here my question is how to put {x,y,z}, which are at the moment inside a cube, inside a particular manifold,e.q, inside a sphere with radius rf.

For {X,Y,Z}, I also should solve another set of partial differential equations. Here I implemented

sol[t_, x_, y_, z_, 
    a_] = {X[t, x, y, z, a], Y[t, x, y, z, a], Z[t, x, y, z, a]} /. 
    First[
     NDSolve[{ 
       D[X[t, x, y, z, a], t] == 
        Y[t, x, y, z, a] + D[Z[t, x, y, z, a], y] + 0.5 t ,
        D[Y[t, x, y, z, a], t] == 
        Z[t, x, y, z, a] + D[X[t, x, y, z, a], z] , 
        D[Z[t, x, y, z, a], t] == 
        X[t, x, y, z, a] + D[Y[t, x, y, z, a], x] + 2 Sin[a t] , 
       X[0, x, y, z, a] == Cos[a x + y], 
       Y[0, x, y, z, a] == Sin[z + y], 
       Z[0, x, y, z, a] == a Sin[x + z]}, {X, Y, Z}, {t, ti, tf}, {x, 
       ri, rf}, {y, ri, rf}, {z, ri, rf}, {a, ai, af}, 
      MaxSteps -> \[Infinity], 
      Method -> {"MethodOfLines", "TemporalVariable" -> t, 
        "SpatialDiscretization" -> 
         "FiniteElement"}]]; // AbsoluteTiming

But this script is not fully correct as I get these errors enter image description here

Do you have suggestions for resolving these issues?

$\endgroup$

2 Answers 2

2
$\begingroup$

The finite element method in Version 13.2 is available for 1D/1.5D/2D/2.5D and 3D plus time. Your problem is 4D plus time. For this use the tensor product grid method - like in your first example.

$\endgroup$
3
  • $\begingroup$ (+1)Thanks! Replacing FiniteElement with TensorProductGrid solves the second problem. Do you have a suggestion for the first question as well? $\endgroup$
    – Shasa
    Feb 2 at 13:57
  • $\begingroup$ @Shasa If you are thinking in terms of Element[ {x,y,z,a}, Ball[]], then no, the tensor product grid method is for rectangular domains. $\endgroup$
    – user21
    Feb 2 at 14:14
  • $\begingroup$ I see! Thank you for your response. $\endgroup$
    – Shasa
    Feb 2 at 15:37
2
$\begingroup$

I am note sure if I understand this correctly: " how to put {x,y,z}, which are at the moment inside a cube". I assume you want to display the vector field inside a cube. The vector field may e.g. be displayed using SliceVectorPlot3D. But besides x,y,z you have 2 more variables t and a. This may be handled using "Manipulate" (note the plot is rather slow):

ti = 0; tf = 5; ri = 0; rf = 1.5; ai = 0; af = 2;
sol[t_, x_, y_, z_, 
   a_] = {X[t, x, y, z, a], Y[t, x, y, z, a], Z[t, x, y, z, a]} /. 
   First[NDSolve[{D[X[t, x, y, z, a], t] == Y[t, x, y, z, a], 
      D[Y[t, x, y, z, a], t] == Z[t, x, y, z, a] + 3.5 t, 
      D[Z[t, x, y, z, a], t] == X[t, x, y, z, a] + 2 Sin[a t], 
      X[0, x, y, z, a] == Sin[x + y], 
      Y[0, x, y, z, a] == Sin[2 z + y], 
      Z[0, x, y, z, a] == Sin[x + 0.5 z]}, {X, Y, Z}, {t, ti, tf}, {x,
       ri, rf}, {y, ri, rf}, {z, ri, rf}, {a, ai, af}, 
     MaxSteps -> \[Infinity]]];
Manipulate[
 SliceVectorPlot3D[
  sol[0, x, y, z, 0], {x, ri, rf}, {y, ri, rf}, {z, ri, rf}, 
  PlotLabel -> {t, a}]
 , {t, ti, tf}, {a, ai, af}]

enter image description here

For a slices sphere, you may write:

Manipulate[
 SliceVectorPlot3D[sol[0, x, y, z, 0], 
  "CenterCutSphere", {x, -1, 1}, {y, -1, 1}, {z, -1, 1}, 
  PlotLabel -> {t, a}], {t, ti, tf}, {a, ai, af}]

enter image description here

For additional possibilities, look at the help.

$\endgroup$
3
  • $\begingroup$ In my examples, I used {x, ri, rf}, {y, ri, rf}, {z, ri, rf}, but in my first part of the question I was wondering about having sth like {x,y,z} \[Element] sphere? How to implement sphere or another manifold? $\endgroup$
    – Shasa
    Feb 2 at 13:48
  • $\begingroup$ Look what I added. $\endgroup$ Feb 2 at 14:32
  • $\begingroup$ (+1) Thank you for your effort. The answer of @user21 addresses my concern. $\endgroup$
    – Shasa
    Feb 2 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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