star-line

Structure for accelerating line importance sampling
git clone git://git.meso-star.fr/star-line.git
Log | Files | Refs | README | LICENSE

commit a30b085f8224d7e411070cec55323a8baf12f392
parent 7a82522883aa6fc6bd352cf9b293953a45f6812e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed, 27 Apr 2022 12:33:00 +0200

Prepare tree data structures to handle line meshing

Diffstat:
Msrc/sln_tree.c | 4+++-
Msrc/sln_tree_build.c | 15+++++++++++++--
Msrc/sln_tree_c.h | 22++++++++++++++++++----
3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/src/sln_tree.c b/src/sln_tree.c @@ -314,6 +314,7 @@ release_tree(ref_T* ref) sln = tree->sln; if(tree->lines_view) SHTR(lines_view_ref_put(tree->lines_view)); darray_node_release(&tree->nodes); + darray_vertex_release(&tree->vertices); MEM_RM(sln->allocator, tree); SLN(device_ref_put(sln)); } @@ -345,6 +346,7 @@ sln_tree_create SLN(device_ref_get(sln)); tree->sln = sln; darray_node_init(sln->allocator, &tree->nodes); + darray_vertex_init(sln->allocator, &tree->vertices); res = create_lines_view(sln, args, &tree->lines_view); if(res != RES_OK) goto error; @@ -417,7 +419,7 @@ int sln_node_is_leaf(const struct sln_node* node) { ASSERT(node); - return node->offset <= 0; + return node->offset == 0; } const struct sln_node* diff --git a/src/sln_tree_build.c b/src/sln_tree_build.c @@ -23,6 +23,17 @@ #define STACK_SIZE 64 /******************************************************************************* + * Helper functions + ******************************************************************************/ +static FINLINE uint32_t +ui64_to_ui32(const uint64_t ui64) +{ + if(ui64 > UINT32_MAX) + VFATAL("%s: overflow %lu.\n", ARG2(FUNC_NAME, ((unsigned long)ui64))); + return (uint32_t)ui64; +} + +/******************************************************************************* * Local functions ******************************************************************************/ res_T @@ -58,7 +69,7 @@ tree_build /* Make a leaf */ if(nlines <= args->max_nlines_per_leaf) { - NODE(inode)->offset = -1; + NODE(inode)->offset = 0; inode = istack ? stack[--istack] : SIZE_MAX; /* Pop the next node */ /* Split the node */ @@ -75,7 +86,7 @@ tree_build ASSERT(ichildren > inode); /* Define the offset from the current node to its children */ - NODE(inode)->offset = (int64_t)(ichildren - inode); + NODE(inode)->offset = ui64_to_ui32((uint64_t)(ichildren - inode)); CREATE_NODE; /* Alloc left child */ CREATE_NODE; /* Alloc right child */ diff --git a/src/sln_tree_c.h b/src/sln_tree_c.h @@ -26,20 +26,32 @@ struct sln_device; struct sln_tree_create_args; struct shtr_lines_view; -struct sln_node { +struct sln_node { /* 32 Bytes */ /* Range of the line indices corresponding to the node. Both the lower and * upper indices are included into the node */ uint64_t range[2]; - int64_t offset; /* Offset toward the node's children (left then right) */ + uint64_t ivertices; /* Index toward the 1st vertex */ + uint32_t nvertices; /* #vertices */ + uint32_t offset; /* Offset toward the node's children (left then right) */ }; -#define SLN_NODE_NULL__ {{0,0},0} +#define SLN_NODE_NULL__ {{0,0},0,0,0} static const struct sln_node SLN_NODE_NULL = SLN_NODE_NULL__; +struct vertex { /* 8 Bytes */ + float wavenumber; /* in cm^-1 */ + float ka; +}; + /* Generate the dynamic array of nodes */ #define DARRAY_DATA struct sln_node #define DARRAY_NAME node #include <rsys/dynamic_array.h> +/* Generate the dynamic array of vertices */ +#define DARRAY_DATA struct vertex +#define DARRAY_NAME vertex +#include <rsys/dynamic_array.h> + struct molecule_params { /* Map the isotope local identifier to its abundance */ double isotopes_abundance[SLN_MAX_ISOTOPES_COUNT]; @@ -49,11 +61,13 @@ struct molecule_params { }; struct sln_tree { - /* Map the molecule id to its parameters (i.e. concentration, cutoff) */ + /* Map the molecule id to its parameters (i.e. concentration, cutoff, + * isotopes abundance) */ struct molecule_params molecules_params[SLN_MAX_MOLECULES_COUNT]; struct shtr_lines_view* lines_view; /* Set of lines */ struct darray_node nodes; /* Nodes used to partition the lines */ + struct darray_vertex vertices; /* List of vertices */ double wavenumber_range[2]; /* Spectral range */ size_t max_nlines_per_leaf;