star-line

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

commit fff640c248a207ecd9be6de45feb6fb05f69cf4e
parent 9faba14464e3f5a7f750353c8a2ba61c443eba73
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  6 Feb 2026 11:46:32 +0100

Finalize a first version of the sln-build tool.

The sln_mixture API was what was missing to load the molecular
parameters needed to build the acceleration structure. The command can
now be executed to completion, i.e., until the tree is built and written
to output.

The makefile has been updated accordingly to install its executable and
the associated manual pages.

Note that the execution time of sln-build can be very long. This is due
to the strategy currently used to mesh the lines. The lines are
over-meshed, up to several million vertices, whereas they only have a
few vertices after being simplified by the decimation algorithm.
Changing the way the rays are initially meshed is therefore the next
step to work on.

Diffstat:
MMakefile | 6++++++
Msrc/sln_build.c | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 79 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile @@ -142,15 +142,21 @@ install: library pkg utils }; \ if [ "$(LIB_TYPE)" = "STATIC" ]; then mode=644; else mode=755; fi; \ install "$${mode}" "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \ + install 755 "$(DESTDIR)$(BINPREFIX)" sln-build; \ install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" sln.pc; \ install 644 "$(DESTDIR)$(INCPREFIX)/star" src/sln.h; \ + install 644 "$(DESTDIR)$(MANPREFIX)/man1" doc/sln-build.1; \ + install 644 "$(DESTDIR)$(MANPREFIX)/man5" doc/sln-mixture.5; \ install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-line" COPYING README.md uninstall: rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)" + rm -f "$(DESTDIR)$(BINPREFIX)/sln-build" rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/sln.pc" rm -f "$(DESTDIR)$(BINPREFIX)/sln" rm -f "$(DESTDIR)$(INCPREFIX)/star/sln.h" + rm -f "$(DESTDIR)$(MANPREFIX)/man1/sln-build.1" + rm -f "$(DESTDIR)$(MANPREFIX)/man5/sln-mixture.5" rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-line/COPYING" rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-line/README.md" diff --git a/src/sln_build.c b/src/sln_build.c @@ -83,11 +83,14 @@ struct args { static const struct args ARGS_DEFAULT = ARGS_DEFAULT__; struct cmd { + struct args args; + struct sln_device* sln; + struct sln_mixture* mixture; struct shtr* shtr; struct shtr_line_list* lines; - struct shtr_isotope_metadata* molparams; + struct shtr_isotope_metadata* molparam; FILE* output; }; @@ -364,20 +367,45 @@ error: goto exit; } +static res_T +setup_tree_mixture + (const struct cmd* cmd, + struct sln_molecule molecules[SHTR_MAX_MOLECULE_COUNT]) +{ + int i = 0; + int n = 0; + res_T res = RES_OK; + ASSERT(cmd && molecules); + + n = sln_mixture_get_molecule_count(cmd->mixture); + FOR_EACH(i, 0, n) { + enum shtr_molecule_id id = sln_mixture_get_molecule_id(cmd->mixture, i); + res = sln_mixture_get_molecule(cmd->mixture, i, molecules+id); + if(res != RES_OK) goto error; + } + +exit: + return res; +error: + goto exit; +} + static void cmd_release(struct cmd* cmd) { ASSERT(cmd); if(cmd->sln) SLN(device_ref_put(cmd->sln)); + if(cmd->mixture) SLN(mixture_ref_put(cmd->mixture)); if(cmd->shtr) SHTR(ref_put(cmd->shtr)); if(cmd->lines) SHTR(line_list_ref_put(cmd->lines)); - if(cmd->molparams) SHTR(isotope_metadata_ref_put(cmd->molparams)); + if(cmd->molparam) SHTR(isotope_metadata_ref_put(cmd->molparam)); } static res_T cmd_init(struct cmd* cmd, const struct args* args) { struct sln_device_create_args sln_args = SLN_DEVICE_CREATE_ARGS_DEFAULT; + struct sln_mixture_load_args mixture_args = SLN_MIXTURE_LOAD_ARGS_NULL; struct shtr_create_args shtr_args = SHTR_CREATE_ARGS_DEFAULT; res_T res = RES_OK; @@ -393,15 +421,22 @@ cmd_init(struct cmd* cmd, const struct args* args) res = sln_device_create(&sln_args, &cmd->sln); if(res != RES_OK) goto error; - res = load_lines(cmd, args); + res = shtr_isotope_metadata_load(cmd->shtr, args->molparams, &cmd->molparam); if(res != RES_OK) goto error; - res = shtr_isotope_metadata_load(cmd->shtr, args->molparams, &cmd->molparams); + mixture_args.filename = args->mixture; + mixture_args.molparam = cmd->molparam; + res = sln_mixture_load(cmd->sln, &mixture_args, &cmd->mixture); if(res != RES_OK) goto error; res = setup_output(cmd, args); if(res != RES_OK) goto error; + res = load_lines(cmd, args); + if(res != RES_OK) goto error; + + cmd->args = *args; + exit: return res; error: @@ -409,6 +444,39 @@ error: goto exit; } +static res_T +cmd_run(struct cmd* cmd) +{ + struct sln_tree_create_args tree_args = SLN_TREE_CREATE_ARGS_DEFAULT; + struct sln_tree* tree = NULL; + res_T res = RES_OK; + + ASSERT(cmd); + + tree_args.metadata = cmd->molparam; + tree_args.lines = cmd->lines; + tree_args.pressure = cmd->args.pressure; + tree_args.temperature = cmd->args.temperature; + tree_args.nvertices_hint = cmd->args.nvertices_hint; + tree_args.mesh_decimation_err = cmd->args.mesh_decimation_err; + tree_args.mesh_type = cmd->args.mesh_type; + + res = setup_tree_mixture(cmd, tree_args.molecules); + if(res != RES_OK) goto error; + + res = sln_tree_create(cmd->sln, &tree_args, &tree); + if(res != RES_OK) goto error; + + res = sln_tree_write(tree, cmd->output); + if(res != RES_OK) goto error; + +exit: + if(tree) SLN(tree_ref_put(tree)); + return res; +error: + goto exit; +} + /******************************************************************************* * The program ******************************************************************************/ @@ -424,6 +492,7 @@ main(int argc, char** argv) if(args.quit) goto exit; if((res = cmd_init(&cmd, &args)) != RES_OK) goto error; + if((res = cmd_run(&cmd)) != RES_OK) goto error; exit: cmd_release(&cmd);