Doubt

260 views
Skip to first unread message

M.R.Datta Prasad

unread,
Oct 24, 2016, 2:36:18 AM10/24/16
to Dedalus Users
I am just interested to know if fn(x,y) or fn(x,z) can be put in Dedalus as a non constant coefficient of a derivative. Whether it can be put in the right hand side of the equation and it will still work for the IVP?

Keaton Burns

unread,
Oct 24, 2016, 7:25:17 AM10/24/16
to dedalu...@googlegroups.com
Hello,

Dedalus currently supports 1-dimensional nonconstant coefficients for the linear terms on the LHS, but yes, a 2D NCC can be put in front of a derivative on the RHS.  You may still have to put some derivative term on the LHS to maintain the differential order of the LHS, which is what sets the number of necessary boundary conditions.  For instance, say you have a NCC called f(x,y).  You could take the horizontal x average of it g(y) = integ_x(f) / Lx, and use that portion of the NCC on the LHS, with the remainder on the RHS, maybe something like: “g*dz(u) + … = (f-g)*dz(u) + …”.

Best,
-Keaton

On October 24, 2016 at 2:36:20 AM, M.R.Datta Prasad (madura...@gmail.com) wrote:

I am just interested to know if fn(x,y) or fn(x,z) can be put in Dedalus as a non constant coefficient of a derivative. Whether it can be put in the right hand side of the equation and it will still work for the IVP?
--
You received this message because you are subscribed to the Google Groups "Dedalus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-user...@googlegroups.com.
To post to this group, send email to dedalu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dedalus-users/a6d4c928-1621-4d0f-a3ab-090a0ec6b5de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Keaton Burns

unread,
Nov 6, 2016, 6:51:50 PM11/6/16
to dedalu...@googlegroups.com, pvg...@gmail.com
Hi Prasanna,

Yeah I think that’s just about right.  Your expression for g is creating an operator, though, so you'll want to evaluate it and then use the result to set the data for g, something like

g_op = integ_x(f) / Lx
g[‘g’] = g_op.evaluate()[‘g’]

Best,
-Keaton

On November 6, 2016 at 6:34:33 AM, pvg...@gmail.com (pvg...@gmail.com) wrote:

Hello Keaton,

I came across this post while searching for NCC.
I also have a NCC in my problem.
I create my f as:

f = domain.new_field()
f.set_scales(domain.dealias,keep_data=False)
f['g'] = x**2 + x**2*y**3

Now to create 'g', should I do like the following ?
g = domain.new_field()
g.set_scales(domain.dealias,keep_data=False)
g['g'] = 1./Lx * integ_x(f)

and then put (f-g) * dz(u) ... in the right hand side & g*dz(u) ... in the left hand side ?

cheers,
Prasanna

Keaton Burns

unread,
Nov 6, 2016, 6:55:17 PM11/6/16
to dedalu...@googlegroups.com, pvg...@gmail.com
Oh also I think my previous post had a typo… assuming f was the original LHS NCC, the equation should be something like “g*dz(u) + … = (g-f)*dz(u) + …” with a flipped sign on the RHS from what I wrote before, since you’re really just adding g to both sides.

-Keaton

pvg...@gmail.com

unread,
Nov 7, 2016, 5:22:09 AM11/7/16
to Dedalus Users, pvg...@gmail.com
Thanks Keaton, I will try this.

cheers,
Prasanna

pvg...@gmail.com

unread,
Nov 8, 2016, 10:53:25 AM11/8/16
to Dedalus Users, pvg...@gmail.com
Hi Keaton,

Should integ_x(f) be in quotes? then it becomes a string doesnt it.

Its saying integ_x is not defined, but in the boundary condition an integ_z is successfully used.

Anyway, if its in quotes, then 'str' has no attribute 'evaluate'.

Is there a problem ?

cheers,
Prasanna


On Monday, November 7, 2016 at 12:55:17 AM UTC+1, Keaton Burns wrote:
Message has been deleted

pvg...@gmail.com

unread,
Nov 10, 2016, 8:51:07 AM11/10/16
to Dedalus Users, pvg...@gmail.com
Hi Keaton,

I managed to analytically integrate and put my 'g' function.

So I created two fields like this:

f = domain.new_field()
f.set_scales(domain.dealias,keep_data=False)
g = domain.new_field()
g.set_scales(domain.dealias,keep_data=False)

However, when I put this : g(y)*dz(u) = (g-f)*dz(u)

The code tells: " NameError: name 'g' is not defined. Should 'g' be a parameter ? Only if the fields are in the right hand side, the code accepts them. So is there a way to treat such NCCs ?

Daniel Lecoanet

unread,
Nov 10, 2016, 9:13:34 AM11/10/16
to dedalu...@googlegroups.com
Hi,

You need to define parameters g and f, i.e.,

problem.parameters['f'] = f
problem.parameters['g'] = g

If you want to treat g has a NCC, you need to do g.meta['x']['constant'] = True.

Also, you don't want to use g(y) in your equation, just g by itself is sufficient.

Daniel

On Thu, Nov 10, 2016 at 8:51 AM, pvg...@gmail.com <pvg...@gmail.com> wrote:
Hi Keaton,

I managed to analytically integrate and put my 'g' function.

So I created two fields like this:

f = domain.new_field()
f.set_scales(domain.dealias,keep_data=False)
g = domain.new_field()
g.set_scales(domain.dealias,keep_data=False)

However, when I put this : g(y)*dz(u) = (g-f)*dz(u)

The code tells: " NameError: name 'g' is not defined. Should 'g' be a parameter ? Only if the fields are in the right hand side, the code accepts them. So is there a way to treat such NCCs ?


On Monday, November 7, 2016 at 12:51:50 AM UTC+1, Keaton Burns wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-users+unsubscribe@googlegroups.com.

To post to this group, send email to dedalu...@googlegroups.com.

Keaton Burns

unread,
Nov 10, 2016, 3:08:16 PM11/10/16
to dedalu...@googlegroups.com, Daniel Lecoanet
And to follow up, the issue before happens when you don't have the integration operator available in the namespace where you were creating the operator.  When you’re manually manipulating fields, you need to import references to any functions/operators you want to use, just like with regular python.  When you enter expressions into the problem interface, via string, this is handled internally when the equations get parsed.  You can also use the field methods, i.e. f.integrate(‘x’), to perform some simple operations.

Best,
-Keaton

pvg...@gmail.com

unread,
Nov 14, 2016, 7:56:00 AM11/14/16
to Dedalus Users, leco...@princeton.edu
Thank you Daniel and Keaton, the code seems to run without any errors now.
I will anyway confirm if there is any discrepancy due to NCC being a function of 2 variables.

Prasanna

pvg...@gmail.com

unread,
Nov 14, 2016, 10:42:01 AM11/14/16
to Dedalus Users, leco...@princeton.edu, pvg...@gmail.com
Well. It seems there is a problem. The values for KE are random at each iteration.

You said: "If you want to treat g has a NCC, you need to do g.meta['x']['constant'] = True"

I thought this statement means g(x) = constant. Am I correct ?

In such a case, I tried running one dimensional NCC, f(x). You have told if it is one dimensional, then it has to be put on the LHS. I did.

I also did: f.meta['y']['constant'] = True

The code gives error saying f is non-constant along separable direction 'x'.

Only if I give f.meta['x','y']['constant'] = True, the code executes which makes no sense. So pls let me know what is the problem.

Keaton Burns

unread,
Nov 14, 2016, 10:56:32 AM11/14/16
to dedalu...@googlegroups.com
Hi Prasanna,

Setting g.meta[‘x’][‘constant’] = True tells the code that g does not vary in x, which should be true by construction, since we setup g(z) to be the horizontal (x) average of f(x,z).  If that doesn’t seem to be working, there may be another problem in the script or in our understanding of your setup, in which case it would probably be best if you could send along a minimal example script showing the issue.

To recap, the overall point is that the LHS NCCs should only be functions of the Chebyshev (z) coordinate, and any field passed as an NCC should be marked as constant in the Fourier (x) directions.

Best,
-Keaton
Message has been deleted

pvg...@gmail.com

unread,
Nov 14, 2016, 12:01:10 PM11/14/16
to Dedalus Users
Hi Keaton,

As you have mentioned LHS NCCs must only be functions of z. My function is f(x,y) * dz(u). Its not f(x,z), so I don't need a g(z) do I ?

Prasanna

Daniel Lecoanet

unread,
Nov 14, 2016, 12:08:13 PM11/14/16
to dedalu...@googlegroups.com
Hi Prasanna,

Non-constant coefficient terms which are treated implicit (i.e., appear on the left hand side of the equals sign) must be functions of only the variable in the Chebyshev direction.  They cannot depend on the variables in Fourier or Sin/Cos directions.  If your problem has Chebyshev in the z direction, and you have a term like f(x,y)*dz(u), you would want to define f_ave to be the integral of f with respect to x and y, and then put the term f_ave*dz(u) on the LHS, and (f(x,y)-f_ave)*dz(u) on the RHS.  In this case, f_ave is just a constant (you could set meta['x','y','z']['constant'] = True).

Hope that makes sense,
Daniel

On Mon, Nov 14, 2016 at 12:01 PM, pvg...@gmail.com <pvg...@gmail.com> wrote:
Hi Keaton,

As you have mentioned LHS NCCs must only be functions of z. My function is f(x,y) * dz(u). Its not f(x,z), so I don't need a g(z) do I ?

Prasanna

--
You received this message because you are subscribed to the Google Groups "Dedalus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-users+unsubscribe@googlegroups.com.

To post to this group, send email to dedalu...@googlegroups.com.

pvg...@gmail.com

unread,
Nov 14, 2016, 12:27:03 PM11/14/16
to Dedalus Users, leco...@princeton.edu
Hi Daniel, thank you, I got it now. I will rewrite it and see.

Prasanna

pvg...@gmail.com

unread,
Nov 21, 2016, 12:07:29 PM11/21/16
to Dedalus Users
Hi Keaton, Daniel, I am not getting the physics correct with this way of putting the NCC. May be my eqns are wrong, however please correct me if my way of putting the NCC is wrong.

A part of my code with the functions and the NCC is shown below:

x_basis = de.Fourier('x', 16, interval=(0, Lx), dealias=3/2)
y_basis = de.Fourier('y', 16, interval=(0, Ly), dealias=3/2)
z_basis = de.Chebyshev('z', 12, interval=(0, Lz), dealias=3/2)
domain = de.Domain([x_basis, y_basis, z_basis], grid_dtype=np.float64)
x,y,z = domain.grids(scales=domain.dealias)

# Applied Field - Bz and By
Bz = domain.new_field()
Bz.set_scales(domain.dealias,keep_data=False)
dxBz = domain.new_field()
dxBz.set_scales(domain.dealias,keep_data=False)
#gc = domain.new_field()
#gc.set_scales(domain.dealias,keep_data=False)

Bz['g']=0.85*np.exp(-(((x-cc)**2)/(2*deltax**2)))+0.15 #Bz is a function of 'x'
dxBz['g']=(0.425*np.exp(-(((cc-x)**2)/(2*deltax**2)))*(2*cc-2*x))/(deltax**2) #dxBz is a function of 'x'

# 2D Boussinesq hydrodynamics
problem = de.IVP(domain, variables=['p','tt','u','v','w','ttz','uz','vz','wz','b1z','b2z','b3z'], time='t')
problem.parameters['Pr'] = 1
problem.parameters['R'] = R
problem.parameters['F'] = F = 1
problem.parameters['Els'] = Els
problem.parameters['Bz'] = Bz
problem.parameters['dxBz'] = dxBz
problem.parameters['gc'] = 1.622672726

problem.add_equation("dx(u) + dy(v) + wz = 0")
problem.add_equation("dt(tt) - Pr*(dx(dx(tt)) + dy(dy(tt)) + dz(ttz)) - w = 0")
problem.add_equation("dt(u) - 1*v - (dx(dx(u)) + dy(dy(u)) + dz(uz)) + dx(p) -1*PAR* gc*dz(b1) = -1*PAR*(1*gc*dz(b1)-(Bz*dz(b1)))") #NCC TERMS HERE

Prasanna

pvg...@gmail.com

unread,
Nov 23, 2016, 7:41:25 AM11/23/16
to Dedalus Users, pvg...@gmail.com
In case the previous post with code is clumsy,

please take a look at this one line which has the NCC,

"Bz(x)*dz(b1) is my NCC term"
Here is the line :

problem.add_equation("dt(u) - 1*v - (dx(dx(u)) + dy(dy(u)) + dz(uz)) + dx(p) -1*PAR* gc*dz(b1) = -1*PAR*(1*gc*dz(b1)-(Bz*dz(b1)))") #NCC TERMS HERE

Please let me know if it is ok.
Also if there is a term f(x)*(u) on the left hand side, should I also treat it like you have previously mentioned ? g=integ_x(f) and put g*(u) = (g*(u) - f*(u)) ??

Prasanna


Daniel Lecoanet

unread,
Nov 23, 2016, 6:31:36 PM11/23/16
to dedalu...@googlegroups.com
Hi Prasanna,

It looks to me like you did the decomposition correctly.  Maybe there is something else in your script which is causing problems.

Daniel

On Wed, Nov 23, 2016 at 4:41 AM, pvg...@gmail.com <pvg...@gmail.com> wrote:
In case the previous post with code is clumsy,

please take a look at this one line which has the NCC,

"Bz(x)*dz(b1) is my NCC term"
Here is the line :
 problem.add_equation("dt(u) - 1*v - (dx(dx(u)) + dy(dy(u)) + dz(uz)) + dx(p)   -1*PAR* gc*dz(b1) = -1*PAR*(1*gc*dz(b1)-(Bz*dz(b1)))") #NCC TERMS HERE

Please let me know if it is ok.
Also if there is a term f(x)*(u) on the left hand side, should I also treat it like you have previously mentioned ? g=integ_x(f) and put g*(u) = (g*(u) - f*(u)) ??

Prasanna
--
You received this message because you are subscribed to the Google Groups "Dedalus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dedalus-users+unsubscribe@googlegroups.com.

To post to this group, send email to dedalu...@googlegroups.com.

pvg...@gmail.com

unread,
Nov 25, 2016, 10:25:56 AM11/25/16
to Dedalus Users, leco...@princeton.edu
Thanks Daniel. I am checking my script if something else is the problem but so far I have not found any. Will look again.

Prasanna

Reply all
Reply to author
Forward
0 new messages