Scalar attributes in basilisk C

271 views
Skip to first unread message

Damien Huet

unread,
Sep 9, 2021, 2:29:29 PM9/9/21
to basilisk-fr
Hello,

I have trouble understanding the syntax of this instruction, found in log-conform.h or navier-stokes/conserving.h:

for (scalar s in {my_vector, my_tensor})
    s.v.x.i = -1; // just a scalar, not the component of a vector

Thanks to the comment I understand the goal: to treat each component of the considered vector or tensor as a scalar, as to apply the same boundary conditions to normal and tangential components. What I have trouble understanding here is the syntax of this instruction: I can't find anywhere (even searching in qcc.c) that a scalar structure has an attribute v, which has an attribute x and so on. Digging in the forum I found a post from Jose where we can see that s.v is a vector, which was unexpected given that s is a scalar.

My question is the following: what is the underlying data structure hidden here, and what is the meaning of all the attributes v, x, i, and even d (found line 409 of grid/cartesian_commons.h)?
As a side note, the above instruction "for (scalar s in {my_vector, my_tensor})    s.v.x.i = -1;" is not allowed outside of an event (it leads to compilation errors, just like when using foreach_dimension() outside of an event). Is there a reason for only allowing these instructions inside events?

Many thanks,

Damien

j.a.v...@gmail.com

unread,
Sep 10, 2021, 5:06:17 AM9/10/21
to basilisk-fr
Hallo Damien,

> What is the meaning of all the attributes v, x, i, and even d

- `i` is used to give every initialized scalar field an integer identifier. Typically the first initialized scalar field gets s1.i = 0, the next s2.i = 1, etc. 

- `x` (and y and z) indicate de scalar fields that represent the components of vector fields.

- These components are scalar fields, and the `.v` attribute is the vector of which it is a component.

- `d` is used to indicate staggering of fields to help delineate between centered, face and vertex variables, for example when interpolating. 

> Is there a reason for only allowing these instructions inside events?

I cannot reproduce your error, It (should) work outside events too.
 
Antoon
Op donderdag 9 september 2021 om 20:29:29 UTC+2 schreef huet...@gmail.com:

Damien Huet

unread,
Sep 20, 2021, 5:24:57 PM9/20/21
to basilisk-fr
Dear Antoon,

Thank you for your answer, and apologies for the delay in my reply.

> `i` is used to give every initialized scalar field an integer identifier. Typically the first initialized scalar field gets s1.i = 0, the next s2.i = 1, etc.
Is this is only valid for scalar that are components of vectors or tensors? Otherwise, in my understanding, checking that a scalar belongs to a vector by doing (assert s.v.x.i >= 0) as can be seen on Jose's post would not work.

> I cannot reproduce your error, It (should) work outside events too.
Attached is a file called outside_events_test.c: if executed as is it runs fine, but if the lines 17 and 22 defining the event "defaults_1" or the lines 24 and 28 defining the event "defaults_2" are commented out, one gets the compilations errors shown in the attached files "fail1" and "fail2". I was simply wondering if this is the expected behaviour of Basilisk C, or if I am doing something wrong. I believe the implication of this (minor) limitation is that the boundary conditions of complex quantities - such as 'tau_p' in log-conform.h - have to be wrapped inside a 'default' event. This means that if a user later wants to overwrite these BC, they have to do so inside another event, which seems to go against the usual way of defining BC in Basilisk.

Many thanks for your time,

Damien
fail2
fail1
outside_events_test.c

j.a.v...@gmail.com

unread,
Sep 21, 2021, 8:01:25 AM9/21/21
to basilisk-fr
Hallo Damien,

The boundary condition assignment issue with `foreach_dimension()` in the global scope is indeed a limitation/bug with qcc.

The for loop (and subsequent assignments) are not allowed outside functions (including events) by design of the C language

Antoon
Op maandag 20 september 2021 om 23:24:57 UTC+2 schreef huet...@gmail.com:

Damien Huet

unread,
Sep 21, 2021, 10:25:18 AM9/21/21
to basilisk-fr
Dear Antoon,

Thank you for clarifying!
Best,

Damien
Reply all
Reply to author
Forward
0 new messages