mctools / ncrystal

NCrystal : a library for thermal neutron transport in crystals and other materials
https://mctools.github.io/ncrystal/
Other
39 stars 18 forks source link

SAB table format description #170

Closed dddijulio closed 3 months ago

dddijulio commented 5 months ago

It would be useful to have the format of the SAB tables written in the description of the ncmat files on this page: https://github.com/mctools/ncrystal/wiki/NCMAT-format#dynamic-model-scattering-kernel

tkittel commented 5 months ago

Thanks @dddijulio - just to clarify from your own message: " i.e. is it first all the betas for each alpha or other way around".

That looks like on oversight, I will fix this soonish (for the next release most likely).

tkittel commented 3 months ago

Proposed text ( a bit cumbersome, but mathematically clear I hope):

Of course, the number of entries in the sab field must be equal to the product of the number of entries in the alphagrid and betagrid fields. Furthermore, the ordering of the sab values must be so that if ai is the i'th alphagrid value, bj is the j'th betagrid value, and Na is the number of alphagrid values, then S(ai,bj) is given by the k'th sab value, where k=j*Na+i.

Ok @dddijulio ?

dddijulio commented 3 months ago

Maybe indicating the loop in someway might help? Or showing a simple list? Did I understand it correctly?

for(int j=0; j<Nb; j++) {
    for(int i=0;i<Na, i++){
         S(ai,bj)
    }
}

S(a_1,b_0),S(a_1,b_0),S(a_2,b_0), ... ,S(a_1,b_1),S(a_1,b_1),S(a_2,b_1), ... ,S(a_1,b_2),S(a_1,b_2),S(a_2,b_2), ...   
tkittel commented 3 months ago

Yeah, so that makes sense... except that it is then tied to a specific programming language and how numbers are indexed. I am not 100% sure that your example would hold true in Fortran.

dddijulio commented 3 months ago

maybe the list then? I was thinking some kind of indication of the structure of the loop, or maybe a statement saying that the order runs first over all i values for a given j ?

tkittel commented 3 months ago

Ok, here is another attempt, making the order more clear, but still focused on the data itself rather than a programming language (also, in my last comment I was committing the sin of using C/C++ style zero-based offsets, so I corrected that as well):

new text:

Of course, the number of entries in the sab field must be equal to the product of the number of entries in the alphagrid and betagrid fields. Furthermore, the ordering of the sab values must be so that if ai is the i'th alphagrid value, bj is the j'th betagrid value, and A is the number of alphagrid values, then S(ai,bj) is given by the k'th sab value, where k=(j-1)*A+i. Thus, if B is the number of entries in the betagrid field, the entries in the sab field are ordered as indicated here:

  sab    S(a1,b1) S(a2,b1) S(a3,b1) ... S(aA,b1)
         S(a1,b2) S(a2,b2) S(a3,b2) ... S(aA,b2)
         ...
         S(a1,bB) S(a2,bB) S(a3,bB) ... S(aA,bB)

All ok now @dddijulio ?

dddijulio commented 3 months ago

@tkittel Looks good!

tkittel commented 3 months ago

Btw., I realise that part of why you are asking for a coding loop example is because you are not really asking for to format NCMAT data, you are asking how to use the NCrystal API to access the data after being loaded? It is two different things in principle - if we for instance would one day add the ability to load data directly from ENDF files, there would be no NCMAT data involved at all, and you would then be forced to actually go and look the (very very inlined currently) API documentation :-)

tkittel commented 3 months ago

So this is added for the next NCrystal release, but since it is merely a documentation fix I also went ahead and updated the wiki already now. Thus, I am closing this issue already.