9
$\begingroup$

I am trying to derive some turbulence model dependencies and I am using Reynolds averaged Navier-Stokes equations. What I am trying to do is to tell Mathematica that OverBar[u] is dependent on x,y,z coordinates and time. However when doing further derivations I would like to avoid writing for example

D[ OverBar[u][x,y,z,t],t]

But rather write just

D[ OverBar[u], t] 

But Mathematica should be aware that OverBar is dependent on other variables, because in other case it just writes that D[ OverBar[u],t] is zero.

EDIT: OverBar[u] is not any particular function. It is just time averaged velocity vector which is in general dependent to spatial coordinates and time. There are no any expressions describing it. It is just bare $\bar u$ that I will find using numerical methods. But for now I want to adjust the turbulence model and derive the difference equation, and I do not want to have D[$\bar{u}$,t] output as zero, but rather $\frac{\partial\bar{u}}{\partial{t}}$. Is that possible in Mathematica?

$\endgroup$
0

2 Answers 2

10
$\begingroup$

Perhaps:

uu := u[x, y, z, t]
uu[x_, y_, z_, t_] := u[x, y, z, t]

So that

D[uu, t] // InputForm
(*
- >Derivative[0, 0, 0, 1][u][x, y, z, t]
*)

and

Dt[uu, t] // InputForm
(*
->          Derivative[0, 0, 0, 1][u][x, y, z, t] + 
   Dt[z, t]*Derivative[0, 0, 1, 0][u][x, y, z, t] + 
   Dt[y, t]*Derivative[0, 1, 0, 0][u][x, y, z, t] + 
   Dt[x, t]*Derivative[1, 0, 0, 0][u][x, y, z, t]
*)

and

 uu[1, 1, 1, 1]
 (*
 -> u[1, 1, 1, 1]
 *)
$\endgroup$
2
  • $\begingroup$ Nice: +1 (and some more characters) $\endgroup$
    – Fabian
    Sep 11, 2012 at 22:12
  • $\begingroup$ That is the smart solution I was looking for. Thanks :] $\endgroup$
    – Misery
    Sep 12, 2012 at 7:57
1
$\begingroup$

I'd look at optional arguments for your function, especially if x, y, and z are not changing or are changing infrequently.

So if I define a function as

function[u_, t_, x_: x, y_: y, z_: z] := u*x^2 + 2*u*y^2 - z^2 + 2*t

I can easily call it without x,y,z arguments:

function[5, 1]

(*2 + 5 x^2 + 10 y^2 - z^2*)

However, if I assign values to x, y, z then the function will update when called.

x = 1;
y = 2;
z = 3;
function[5, 1]

(*38*)

Or, I can call it with temporary values:

function[5, 1, 2, 3, 4]

(*96*)

function[5, 1, a, b, c]

(*2 + 5 a^2 + 10 b^2 - c^2*)

Just remember, the values of x, y, and z must be updated either within the function or before calling it if they change.

$\endgroup$
4
  • $\begingroup$ I don't really understand what you mean. And it doesn't work either :( $\endgroup$
    – Misery
    Sep 11, 2012 at 18:40
  • $\begingroup$ @Misery, to tell a function what values it needs to calculate an output, the function either must have those values pre-defined or included as input. So with the simple function I have up in my answer, the arguments x, y, and z are optional. If they are not specified, they assume whatever values the Global x, y, and z have, either symbolic or numerical $\endgroup$
    – kale
    Sep 11, 2012 at 18:44
  • $\begingroup$ OK, but still D[u,t] is zero. I think I'll just agree with u[t,x,y,z] :[ Thanks for help :) $\endgroup$
    – Misery
    Sep 11, 2012 at 18:46
  • $\begingroup$ @Misery, if you put your function in the Question, I'll adjust the answer to include it. $\endgroup$
    – kale
    Sep 11, 2012 at 18:46

Your Answer

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

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