star-gf

Compute Gebhart factors
git clone git://git.meso-star.fr/star-gf.git
Log | Files | Refs | README | LICENSE

sgf.h (5755B)


      1 /* Copyright (C) 2021, 2024 |Meso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2015-2018 EDF S.A., France (syrthes-support@edf.fr)
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     16 
     17 #ifndef SGF_H
     18 #define SGF_H
     19 
     20 #include <rsys/rsys.h>
     21 
     22 /* Library symbol management */
     23 #if defined(SGF_SHARED_BUILD) /* Build shared library */
     24   #define SGF_API extern EXPORT_SYM
     25 #elif defined(SGF_STATIC) /* Use/build static library */
     26   #define SGF_API extern LOCAL_SYM
     27 #else /* Use shared library */
     28   #define SGF_API extern IMPORT_SYM
     29 #endif
     30 
     31 /* Helper macro that asserts if the invocation of the sgf function `Func'
     32  * returns an error. One should use this macro on sgf function calls for which
     33  * no explicit error checking is performed */
     34 #ifndef NDEBUG
     35   #define SGF(Func) ASSERT(sgf_ ## Func == RES_OK)
     36 #else
     37   #define SGF(Func) sgf_ ## Func
     38 #endif
     39 
     40 /* Forward declaration of external types */
     41 struct logger;
     42 struct mem_allocator;
     43 struct ssp_rng;
     44 
     45 struct sgf_scene_desc {
     46   void (*get_indices)(const unsigned itri, unsigned ids[], void* ctx);
     47   void (*get_position)(const unsigned ivert, float pos[], void* ctx);
     48 
     49   double (*get_emissivity)
     50     (const unsigned itri, const unsigned iband, void* ctx);
     51   double (*get_reflectivity)
     52     (const unsigned itri, const unsigned iband, void* ctx);
     53   double (*get_specularity)
     54     (const unsigned itri, const unsigned iband, void* ctx);
     55   double (*get_absorption) /* May be NULL <=> no medium */
     56     (const unsigned itri, const unsigned iband, void* ctx);
     57 
     58   void* context; /* User defined data */
     59   unsigned nprims; /* #primitives */
     60   unsigned nverts; /* #vertices */
     61   unsigned nbands; /* #spectral bands */
     62 };
     63 #define SGF_SCENE_DESC_NULL__ { 0 }
     64 static const struct sgf_scene_desc SGF_SCENE_DESC_NULL =
     65   SGF_SCENE_DESC_NULL__;
     66 
     67 /* Estimated Gebart Factor between 2 faces */
     68 struct sgf_status {
     69   double E; /* Expected value */
     70   double V; /* Variance */
     71   double SE; /* Standard error */
     72   size_t nsteps; /* #realisations */
     73 };
     74 
     75 /* Opaque types */
     76 struct sgf_device;
     77 struct sgf_estimator;
     78 struct sgf_scene;
     79 
     80 /*******************************************************************************
     81  * Device API
     82  ******************************************************************************/
     83 BEGIN_DECLS
     84 
     85 SGF_API res_T
     86 sgf_device_create
     87   (struct logger* logger, /* May be NULL <=> use default logger */
     88    struct mem_allocator* allocator, /* May be NULL <=> Use default allocator */
     89    const int verbose, /* Verbosity level */
     90    struct sgf_device** dev);
     91 
     92 SGF_API res_T
     93 sgf_device_ref_get
     94   (struct sgf_device* dev);
     95 
     96 SGF_API res_T
     97 sgf_device_ref_put
     98   (struct sgf_device* dev);
     99 
    100 /*******************************************************************************
    101  * Scene API
    102  ******************************************************************************/
    103 SGF_API res_T
    104 sgf_scene_create
    105   (struct sgf_device* dev,
    106    struct sgf_scene** scn);
    107 
    108 SGF_API res_T
    109 sgf_scene_ref_get
    110   (struct sgf_scene* scn);
    111 
    112 SGF_API res_T
    113 sgf_scene_ref_put
    114   (struct sgf_scene* scn);
    115 
    116 /* Return RES_BAD_OP if an integration process is currently active onto the
    117  * provided scene */
    118 SGF_API res_T
    119 sgf_scene_setup_3d
    120   (struct sgf_scene* scn,
    121    const struct sgf_scene_desc* desc);
    122 
    123 /* Return RES_BAD_OP if an integration process is currently active onto the
    124  * provided scene */
    125 SGF_API res_T
    126 sgf_scene_setup_2d
    127   (struct sgf_scene* scn,
    128    const struct sgf_scene_desc* desc);
    129 
    130 SGF_API res_T
    131 sgf_scene_primitives_count
    132   (struct sgf_scene* scn,
    133    unsigned* nprims);
    134 
    135 SGF_API res_T
    136 sgf_scene_begin_integration
    137   (struct sgf_scene* scn);
    138 
    139 SGF_API res_T
    140 sgf_scene_end_integration
    141   (struct sgf_scene* scn);
    142 
    143 /*******************************************************************************
    144  * Integration API
    145  ******************************************************************************/
    146 /* Numerical estimation of the Gebhart Factor between `primitive_id' and the
    147  * other scene primitives. The `sgf_scene_begin_integration' function hat to be
    148  * invoked onto the provided scene. RES_BAD_OP is returned if not. This
    149  * function is thread safe and can be invoked by several threads. */
    150 SGF_API res_T
    151 sgf_integrate
    152   (struct sgf_scene* scn,
    153    const size_t primitive_id,
    154    struct ssp_rng* rng,
    155    const size_t steps_count, /* #realisations */
    156    struct sgf_estimator** out_estimator);
    157 
    158 SGF_API res_T
    159 sgf_estimator_ref_get
    160   (struct sgf_estimator* estimator);
    161 
    162 SGF_API res_T
    163 sgf_estimator_ref_put
    164   (struct sgf_estimator* estimator);
    165 
    166 /* Return the estimated Gebhart Factor between the estimator primitive and
    167  * `primitive_id'. */
    168 SGF_API res_T
    169 sgf_estimator_get_status
    170   (struct sgf_estimator* estimator,
    171    const size_t primitive_id,
    172    const size_t spectral_band_id,
    173    struct sgf_status* status);
    174 
    175 /* Return the estimated radiative flux that hit nothing */
    176 SGF_API res_T
    177 sgf_estimator_get_status_infinity
    178   (struct sgf_estimator* estimator,
    179    const size_t spectral_band,
    180    struct sgf_status* status);
    181 
    182 /* Return the estimated radiative flux absorbed by the medium */
    183 SGF_API res_T
    184 sgf_estimator_get_status_medium
    185   (struct sgf_estimator* estimator,
    186    const size_t spectral_band,
    187    struct sgf_status* status);
    188 
    189 END_DECLS
    190 
    191 #endif /* SGF_H */
    192