star-phor

Radiative transfer solver for photoreactors.
git clone https://www.edstar.cnrs.fr/git/star-phor.git
Log | Files | Refs | README | LICENSE

sphor_interface.h (5052B)


      1 /* Copyright (C) 2024-2026 Centre National de la Recherche Scientifique
      2  * Copyright (C) 2024-2026 Clermont Auvergne INP
      3  * Copyright (C) 2024-2026 INSA Lyon
      4  * Copyright (C) 2024-2026 Institut Mines Télécom Albi-Carmaux
      5  * Copyright (C) 2024-2026 Institut National Polytechnique de Toulouse
      6  * Copyright (C) 2024-2026 |Méso|Star> (contact@meso-star.com)
      7  * Copyright (C) 2024-2026 PhotonLyX (info@photonlyx.com)
      8  * Copyright (C) 2024-2026 Université de Lorraine
      9  * Copyright (C) 2024-2026 Université Paul Sabatier
     10  * Copyright (C) 2024-2026 Université Toulouse - Jean Jaurès
     11  *
     12  * This program is free software: you can redistribute it and/or modify
     13  * it under the terms of the GNU General Public License as published by
     14  * the Free Software Foundation, either version 3 of the License, or
     15  * (at your option) any later version.
     16  *
     17  * This program is distributed in the hope that it will be useful,
     18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     20  * GNU General Public License for more details.
     21  *
     22  * You should have received a copy of the GNU General Public License
     23  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     24 
     25 #ifndef SPHOR_INTERFACE_H
     26 #define SPHOR_INTERFACE_H
     27 
     28 #include <rsys/dynamic_array.h>
     29 #include <rsys/rsys.h>
     30 #include <star/sphin.h>
     31 
     32 struct sphin_brdf;
     33 struct sphin_sensor_surface;
     34 struct sphin_source_surface;
     35 struct sphor;
     36 
     37 /* Maximum number of surfaces a single triangle can be part of (per side).
     38  * We use a constant to avoid dynamic memory allocation.
     39  * 4 is chosen as a good balance between efficiency and possibility.
     40  * This value can be adjusted as needed. */
     41 #define MAX_SURFACE_COUNT 4
     42 #define INVALID_ID SIZE_MAX
     43 
     44 struct interface {
     45   /* Interface side; FRONT and BACK */
     46   size_t volumes[2/*#sides*/];
     47   size_t surfaces[2/*#sides*/][MAX_SURFACE_COUNT];
     48   short surface_count[2];
     49 };
     50 #define INTERFACE_NULL__ { \
     51   {INVALID_ID, INVALID_ID}, /* volumes */ \
     52   {{INVALID_ID}, {INVALID_ID}}, /* surfaces */ \
     53   {0, 0} /* surface_count */ \
     54 }
     55 static const struct interface INTERFACE_NULL = INTERFACE_NULL__;
     56 
     57 #define DARRAY_NAME interface
     58 #define DARRAY_DATA struct interface
     59 #include <rsys/dynamic_array.h>
     60 
     61 struct primitive {
     62   const struct interface* interface;
     63   double normal[3]; /* Assumes normal is the same in the entire primitive */
     64   size_t prim_id;
     65   enum sphin_side side;
     66 };
     67 #define PRIMITIVE_NULL__ {NULL, {0,0,0}, INVALID_ID, SPHIN_SIDE_NONE__}
     68 static const struct primitive PRIMITIVE_NULL = PRIMITIVE_NULL__;
     69 
     70 struct primitive_pos {
     71   struct primitive primitive;
     72   double uv[2]; /* Local coordinate */
     73 };
     74 #define PRIMITIVE_POS_NULL__ {PRIMITIVE_NULL__, {0,0}}
     75 static const struct primitive_pos PRIMITIVE_POS_NULL = PRIMITIVE_POS_NULL__;
     76 
     77 struct intersection {
     78   struct primitive_pos position;
     79   double distance;
     80 };
     81 #define INTERSECTION_NULL__ {PRIMITIVE_POS_NULL__, DBL_MAX}
     82 static const struct intersection INTERSECTION_NULL = INTERSECTION_NULL__;
     83 
     84 /* Syntactic sugar */
     85 #define INTERSECTION_NONE(Intersection) ((Intersection)->distance >= DBL_MAX)
     86 
     87 struct ray {
     88   double origin[3];
     89   double direction[3];
     90   double range[2];
     91 
     92   /* Origin of the ray when located on a primitive.
     93    * Used to avoid self intersection */
     94   struct primitive_pos origin_on_prim;
     95 };
     96 #define RAY_DEFAULT__ { \
     97   {0,0,0}, \
     98   {0,0,0}, \
     99   {0, DBL_MAX}, \
    100   PRIMITIVE_POS_NULL__ \
    101 }
    102 static const struct ray RAY_DEFAULT = RAY_DEFAULT__;
    103 
    104 extern LOCAL_SYM res_T
    105 primitive_get_source
    106   (struct sphor* sphor,
    107    const struct primitive* primitive,
    108    struct sphin_source_surface** out_source);
    109 
    110 extern LOCAL_SYM res_T
    111 primitive_get_sensor_surface
    112   (struct sphor* sphor,
    113    const struct primitive* primitive,
    114    struct sphin_sensor_surface** out_sensor);
    115 
    116 extern LOCAL_SYM res_T
    117 primitive_get_brdf
    118   (struct sphor* sphor,
    119    const struct primitive* primitive,
    120    struct sphin_brdf** out_brdf);
    121 
    122 extern LOCAL_SYM res_T
    123 primitive_get_btdf
    124   (struct sphor* sphor,
    125    const struct primitive* primitive,
    126    struct sphin_btdf** out_btdf);
    127 
    128 extern LOCAL_SYM res_T
    129 primitive_get_in_refraction_index
    130   (struct sphor* sphor,
    131    struct primitive* primitive,
    132    double wavelength,
    133    double* n_real,
    134    double* n_imag);
    135 
    136 extern LOCAL_SYM res_T
    137 primitive_get_out_refraction_index
    138   (struct sphor* sphor,
    139    struct primitive* primitive,
    140    double wavelength,
    141    double* n_real,
    142    double* n_imag);
    143 
    144 extern LOCAL_SYM res_T
    145 primitive_get_reflectivity
    146   (struct sphor* sphor,
    147    struct primitive* primitive,
    148    double wavelength,
    149    double cos_theta,
    150    double* reflectivity);
    151 
    152 extern LOCAL_SYM res_T
    153 primitive_get_transmissivity
    154   (struct sphor* sphor,
    155    struct primitive* primitive,
    156    double wavelength,
    157    double cos_theta,
    158    double* transmissivity);
    159 
    160 extern LOCAL_SYM res_T
    161 trace_ray
    162   (const struct sphor* sphor,
    163    const struct ray* ray,
    164    struct intersection* intersection);
    165 
    166 extern LOCAL_SYM res_T
    167 ray_update
    168   (struct ray* ray,
    169    const struct intersection* intersection,
    170    const double dir[3]);
    171 
    172 #endif /* SPHOR_INTERFACE_H */