Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,172 changes: 1,728 additions & 1,444 deletions mcstas-comps/contrib/Monochromator_bent.comp

Large diffs are not rendered by default.

466 changes: 242 additions & 224 deletions mcstas-comps/contrib/Monochromator_bent_complex.comp

Large diffs are not rendered by default.

734 changes: 734 additions & 0 deletions mcstas-comps/share/tinyexpr.c

Large diffs are not rendered by default.

87 changes: 87 additions & 0 deletions mcstas-comps/share/tinyexpr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// SPDX-License-Identifier: Zlib
/*
* TINYEXPR - Tiny recursive descent parser and evaluation engine in C
*
* Copyright (c) 2015-2020 Lewis Van Winkle
*
* http://CodePlea.com
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgement in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/

#ifndef TINYEXPR_H
#define TINYEXPR_H


#ifdef __cplusplus
extern "C" {
#endif



typedef struct te_expr {
int type;
union {double value; const double *bound; const void *function;};
void *parameters[1];
} te_expr;


enum {
TE_VARIABLE = 0,

TE_FUNCTION0 = 8, TE_FUNCTION1, TE_FUNCTION2, TE_FUNCTION3,
TE_FUNCTION4, TE_FUNCTION5, TE_FUNCTION6, TE_FUNCTION7,

TE_CLOSURE0 = 16, TE_CLOSURE1, TE_CLOSURE2, TE_CLOSURE3,
TE_CLOSURE4, TE_CLOSURE5, TE_CLOSURE6, TE_CLOSURE7,

TE_FLAG_PURE = 32
};

typedef struct te_variable {
const char *name;
const void *address;
int type;
void *context;
} te_variable;



/* Parses the input expression, evaluates it, and frees it. */
/* Returns NaN on error. */
double te_interp(const char *expression, int *error);

/* Parses the input expression and binds variables. */
/* Returns NULL on error. */
te_expr *te_compile(const char *expression, const te_variable *variables, int var_count, int *error);

/* Evaluates the expression. */
double te_eval(const te_expr *n);

/* Prints debugging information on the syntax tree. */
void te_print(const te_expr *n);

/* Frees the expression. */
/* This is safe to call on NULL pointers. */
void te_free(te_expr *n);


#ifdef __cplusplus
}
#endif

#endif /*TINYEXPR_H*/
56 changes: 34 additions & 22 deletions mcstas-comps/share/union-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum shape {
};

enum process {
Inhomogenous_incoherent,
Incoherent,
Powder,
Single_crystal,
Expand Down Expand Up @@ -479,6 +480,7 @@ double refraction_Qc;

union data_transfer_union{
// List of pointers to storage structs for all supported physical processes
struct Inhomogenous_incoherent_struct *Inhomogenous_incoherent_struct;
struct Incoherent_physics_storage_struct *pointer_to_a_Incoherent_physics_storage_struct;
struct Powder_physics_storage_struct *pointer_to_a_Powder_physics_storage_struct;
struct Single_crystal_physics_storage_struct *pointer_to_a_Single_crystal_physics_storage_struct;
Expand All @@ -499,36 +501,46 @@ union data_transfer_union{

struct scattering_process_struct
{
char name[256]; // User defined process name
enum process eProcess; // enum value corresponding to this process GPU
double process_p_interact; // double between 0 and 1 that describes the fraction of events forced to undergo this process. -1 for disable
int non_isotropic_rot_index; // -1 if process is isotrpic, otherwise is the index of the process rotation matrix in the volume
int needs_cross_section_focus; // 1 if physics_my needs to call focus functions, otherwise -1
Rotation rotation_matrix; // rotation matrix of process, reported by component in local frame, transformed and moved to volume struct in main

union data_transfer_union data_transfer; // The way to reach the storage space allocated for this process (see examples in process.comp files)

// probability_for_scattering_functions calculates this probability given k_i and parameters
int (*probability_for_scattering_function)(double*,double*,union data_transfer_union,struct focus_data_struct*, _class_particle *_particle);
// prop, k_i, ,parameters , focus data / function

// A scattering_function takes k_i and parameters, returns k_f
int (*scattering_function)(double*,double*,double*,union data_transfer_union,struct focus_data_struct*, _class_particle *_particle);
// k_f, k_i, weight, parameters , focus data / function
};

//Utility function for initialising a scattering_process_struct with default
//values:
void scattering_process_struct_init( struct scattering_process_struct * sps )
char name[256]; // User defined process name
enum process eProcess; // enum value corresponding to this process GPU
double process_p_interact; // double between 0 and 1 that describes the fraction of events forced to undergo this process. -1 for disable
int non_isotropic_rot_index; // -1 if process is isotrpic, otherwise is the index of the process rotation matrix in the volume
int needs_cross_section_focus; // 1 if physics_my needs to call focus functions, otherwise -1
int needs_numerical_integration; // 1 if the process is inhomogenous and therefore needs numerical integration, otherwise -1.
Rotation rotation_matrix; // rotation matrix of process, reported by component in local frame, transformed and moved to volume struct in main
double *inhomogenous_cumul_prob; // The cumulative probability of a process in case of inhomogenous processes
double *inhomogenous_distances; // The distance of each step in which the cumulative probabilities will be calculated.
double *inhomogenous_cumul_distances; // The cumulative distances
double *inhomogenous_mu; // The different attenuation coefficients that are sampled in the numerical integration
double *inhomogenous_prob; // The probability of the process at the different sampled points.
double *inhomogenous_t; // The different times at which mu must be sampled.
int sampl_size; // Maximum number of samplings performed. If it is -1, no sampling has been done, and the arrays must be malloc'ed.
union data_transfer_union data_transfer; // The way to reach the storage space allocated for this process (see examples in process.comp files)

// probability_for_scattering_functions calculates this probability given k_i and parameters
int (*probability_for_scattering_function)(double *, double *, union data_transfer_union, struct focus_data_struct *, _class_particle *_particle);
// prop, k_i, ,parameters , focus data / function

// A scattering_function takes k_i and parameters, returns k_f
int (*scattering_function)(double *, double *, double *, union data_transfer_union, struct focus_data_struct *, _class_particle *_particle);
// k_f, k_i, weight, parameters , focus data / function
};

// Utility function for initialising a scattering_process_struct with default
// values:
void scattering_process_struct_init(struct scattering_process_struct *sps)
{
memset(sps,0,sizeof(struct scattering_process_struct));//catch all
memset(sps, 0, sizeof(struct scattering_process_struct)); // catch all
sps->name[0] = '\0';
sps->probability_for_scattering_function = NULL;
sps->scattering_function = NULL;
sps->non_isotropic_rot_index = -1;
sps->needs_cross_section_focus = -1;
sps->needs_numerical_integration = -1;
sps->sampl_size = -1;
}


union surface_data_transfer_union
{
struct Mirror_surface_storage_struct *pointer_to_a_Mirror_surface_storage_struct;
Expand Down
10 changes: 10 additions & 0 deletions mcstas-comps/share/union-suffix.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ int physics_my(enum process choice, double *my,double *k_initial, union data_tra
int output = 0; // Error return value
#ifdef PROCESS_DETECTOR
switch(choice) {
#ifdef PROCESS_INHOMOGENOUS_INCOHERENT_DETECTOR
case Inhomogenous_incoherent:
output = Inhomogenous_incoherent_physics_my(my, k_initial, data_transfer, focus_data, _particle);
break;
#endif
#ifdef PROCESS_INCOHERENT_DETECTOR
case Incoherent:
output = Incoherent_physics_my(my, k_initial, data_transfer, focus_data, _particle);
Expand Down Expand Up @@ -75,6 +80,11 @@ int physics_scattering(enum process choice, double *k_final, double *k_initial,
int output = 0; // Error return value
#ifdef PROCESS_DETECTOR
switch(choice) {
#ifdef PROCESS_INHOMOGENOUS_INCOHERENT_DETECTOR
case Inhomogenous_incoherent:
output = Inhomogenous_incoherent_physics_scattering(k_final, k_initial, weight, data_transfer, focus_data, _particle);
break;
#endif
#ifdef PROCESS_INCOHERENT_DETECTOR
case Incoherent:
output = Incoherent_physics_scattering(k_final, k_initial, weight, data_transfer, focus_data, _particle);
Expand Down
Loading