solve.h

54 views
Skip to first unread message

Daniel Fuster

unread,
Jul 24, 2025, 9:05:01 AMJul 24
to basilisk-fr
Hello Stephane

I see you changed the interface of solve.h. I am trying to understand what changed looking at this
http://basilisk.fr/src/test/kuramoto.c

I do not really understand why you pass b[] as third argument

mgstats stats = solve (u,
  u[] + dt*(u[-1] - 2.*u[] + u[1])/sq(Delta)
  + dt*(u[-2] - 4.*u[-1] + 6.*u[] - 4.*u[1] + u[2])/sq(sq(Delta)),
  b[]);

it is not a double as expected from the definition of solve. On the other hand it does not make sense to pass a double but rather a scalar, so I guess that b[] is the way you have to pass a scalar

Can you confirm that this is the correct syntax? why you changed with respect to the previous one which was more intuitive? (at least for me..)

thanks in advance
Daniel

Stephane Popinet

unread,
Jul 24, 2025, 9:29:40 AMJul 24
to basil...@googlegroups.com
Hi Daniel,

> I do not really understand why you pass b[] as third argument

Because it is the right-hand-side.

> it is not a double as expected from the definition of solve.

No, b[] is a double (so is b[0], so is b[1,-1] etc.).
b is a scalar.

> On the other hand it does not make sense to pass a double but rather a scalar,
> so I guess that b[] is the way you have to pass a scalar

No, it does not make sense to pass a scalar i.e. b
It makes sense to pass a double i.e. b[]
or 0.
or b[] + 1.
or 2.*b[] + (c[1] - c[-1])/Delta
etc.

> Can you confirm that this is the correct syntax?

yes, b[] is the correct syntax.

> why you changed with respect to the previous one which was more intuitive? (at least for me..)

because it does not make sense to restrict the right-hand-side to the
central value of a single scalar field. For example, with the old syntax
if you wanted to use a right-hand-side which was e.g. c[] + 1. you would
have had to write something like:

scalar b[];
foreach()
b[] = c[] + 1.;
solve (..., b);

with the new syntax you can just write:

solve (..., c[] + 1.);

cheers,

Stephane

PS: you may also want to (re)read

http://basilisk.fr/src/ast/macro.h#macro-expansion


Reply all
Reply to author
Forward
0 new messages