star-line

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

commit 1c3d7a18170221d6445d5322385d8655c36f1f36
parent fe3d4473bae17697db5c6d87aa84b21dc5c2d8ee
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Fri,  6 Mar 2026 16:59:13 +0100

Add an option to sln-get to evaluate the spectrum

The caller can now set the -w parameter to specify the number of waves
at which the spectrum is evaluated for the selected node. Both the
actual spectrum value and the value estimated from the grid are printed.

Diffstat:
Mdoc/sln-get.1 | 23+++++++++++++++++++++--
Msrc/sln_get.c | 43++++++++++++++++++++++++++++++++++++++++---
2 files changed, 61 insertions(+), 5 deletions(-)

diff --git a/doc/sln-get.1 b/doc/sln-get.1 @@ -15,7 +15,7 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with this program. If not, see <http://www.gnu.org/licenses/>. -.Dd March 5, 2026 +.Dd March 6, 2026 .Dt SLN-GET 1 .Os .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -28,6 +28,7 @@ .Op Fl hlmnrv .Op Fl L Ar nlevels .Op Fl R Ar nlevels +.Op Fl w Ar wavenumber .Op Ar tree .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh DESCRIPTION @@ -115,6 +116,17 @@ Multiple .Fl v options increase the verbosity. The maximum is 3. +.\"""""""""""""""""""""""""""""""""" +.It Fl w Ar wavenumber +Calculate the spectrum value of the current node at the given +.Ar wavenumber +in cm^-1. +Both the actual spectrum value, calculated from the lines that the node +partitions, and the estimated value from its mesh are printed. +The output format is as follows: +.Bd -literal -offset Ds +"ka(%e) = %e ~ %e\en", wavenumber, ka_node, ka_mesh +.Ed .El .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh EXIT STATUS @@ -142,7 +154,7 @@ sln-get -lrn tree.sln .Pp Descend the tree by first visiting the three left children of the first three levels of the tree -.Pq option Fl L Ar 3 , +.Pq option Fl L Ns Ar 3 , then the right child .Pq option Fl r , and finally the left child @@ -156,6 +168,13 @@ file: .Bd -literal -offset Ds sln-get -L3 -rl -m tree.sln > mesh.txt .Ed +.\"""""""""""""""""""""""""""""""""" +.Pp +Print the spectrum value at 50 cm^-1 for one of the great-grandchildren +of the root: +.Bd -literal -offset Ds +sln-get -L3 -w 50 tree.sln +.Ed .\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh SEE ALSO .Xr sln-build 1 diff --git a/src/sln_get.c b/src/sln_get.c @@ -42,6 +42,7 @@ enum output_type { OUTPUT_TREE_DESCRIPTOR, OUTPUT_NODE_DESCRIPTOR, OUTPUT_NODE_MESH, + OUTPUT_NODE_VALUE, OUTPUT_COUNT__ }; @@ -50,6 +51,8 @@ struct args { enum output_type output_type; + double wavenumber; /* Wave number at which the spectrum is evaluated */ + /* Step of the tree descent. * * A bit set in one of the masks determines which side to descend to move from @@ -66,7 +69,7 @@ struct args { int quit; int verbose; }; -#define ARGS_DEFAULT__ {NULL, OUTPUT_TREE_DESCRIPTOR, 0, 0, 0, 0, 0} +#define ARGS_DEFAULT__ {NULL, OUTPUT_TREE_DESCRIPTOR, 0,0,0,0,0,0} static const struct args ARGS_DEFAULT = ARGS_DEFAULT__; struct cmd { @@ -86,7 +89,8 @@ static const struct cmd CMD_NULL = CMD_NULL__; static void usage(FILE* stream) { - fprintf(stream, "usage: sln-get [-hlmnrv] [tree]\n"); + fprintf(stream, +"usage: sln-get [-hlmnrv] [-L nlevels] [-R nlevels] [-w wavenumber] [tree]\n"); } static void @@ -133,7 +137,7 @@ args_init(struct args* args, int argc, char** argv) *args = ARGS_DEFAULT; - while((opt = getopt(argc, argv, "hL:lmnR:rv")) != -1) { + while((opt = getopt(argc, argv, "hL:lmnR:rvw:")) != -1) { switch(opt) { case 'h': usage(stdout); @@ -154,6 +158,10 @@ args_init(struct args* args, int argc, char** argv) case 'm': args->output_type = OUTPUT_NODE_MESH; break; case 'n': args->output_type = OUTPUT_NODE_DESCRIPTOR; break; case 'v': args->verbose += (args->verbose < 3); break; + case 'w': + args->output_type = OUTPUT_NODE_VALUE; + res = cstr_to_double(optarg, &args->wavenumber); + break; default: res = RES_BAD_ARG; break; } if(res != RES_OK) { @@ -339,6 +347,32 @@ error: } static res_T +print_node_value(const struct cmd* cmd) +{ + struct sln_mesh mesh = SLN_MESH_NULL; + const struct sln_node* node = NULL; + double val_mesh = 0; + double val_node = 0; + res_T res = RES_OK; + ASSERT(cmd); + + if((node = get_node(cmd, NULL)) == NULL) goto exit; /* tree is empty */ + + res = sln_node_get_mesh(cmd->tree, node, &mesh); + if(res != RES_OK) goto error; + + val_mesh = sln_mesh_eval(&mesh, cmd->args.wavenumber); + val_node = sln_node_eval(cmd->tree, node, cmd->args.wavenumber); + + printf("ka(%e) = %e ~ %e\n", cmd->args.wavenumber, val_node, val_mesh); + +exit: + return res; +error: + goto exit; +} + +static res_T cmd_run(const struct cmd* cmd) { res_T res = RES_OK; @@ -353,6 +387,9 @@ cmd_run(const struct cmd* cmd) case OUTPUT_NODE_MESH: res = print_mesh(cmd); break; + case OUTPUT_NODE_VALUE: + res = print_node_value(cmd); + break; default: FATAL("Unreachable code\n"); break; } if(res != RES_OK) goto error;