solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

solstice.h (6188B)


      1 /* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2016-2018 CNRS
      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 SOLSTICE_H
     18 #define SOLSTICE_H
     19 
     20 #include "parser/solparser_material.h"
     21 #include "receivers/srcvl.h"
     22 #include "solstice_args.h"
     23 
     24 #include <rsys/dynamic_array_double.h>
     25 #include <rsys/hash_table.h>
     26 #include <rsys/logger.h>
     27 #include <rsys/mem_allocator.h>
     28 #include <rsys/str.h>
     29 
     30 /* Library symbol management */
     31 #if defined(SCORE_SHARED_BUILD) /* Build shared library */
     32   #define SCORE_API extern EXPORT_SYM
     33 #elif defined(SCORE_STATIC) /* Use/build static library */
     34   #define SCORE_API extern LOCAL_SYM
     35 #else /* Use shared library */
     36   #define SCORE_API extern IMPORT_SYM
     37 #endif
     38 struct solparser;
     39 struct solstice_node;
     40 struct ssol_device;
     41 struct ssol_material;
     42 struct ssol_object;
     43 struct sanim_node;
     44 
     45 struct solstice_receiver {
     46   struct str name;
     47   struct solstice_node* node;
     48   enum srcvl_side side;
     49   enum srcvl_pp_output per_primitive_output;
     50 };
     51 
     52 static INLINE void
     53 solstice_receiver_init
     54   (struct mem_allocator* allocator, struct solstice_receiver* rcv)
     55 {
     56   ASSERT(rcv);
     57   str_init(allocator, &rcv->name);
     58   rcv->node = NULL;
     59   rcv->side = SRCVL_FRONT_AND_BACK;
     60   rcv->per_primitive_output = SRCVL_PP_NONE;
     61 }
     62 
     63 static INLINE void
     64 solstice_receiver_release(struct solstice_receiver* rcv)
     65 {
     66   ASSERT(rcv);
     67   str_release(&rcv->name);
     68 }
     69 
     70 static INLINE res_T
     71 solstice_receiver_copy
     72   (struct solstice_receiver* dst,
     73    const struct solstice_receiver* src)
     74 {
     75   ASSERT(dst && src);
     76   dst->node = src->node;
     77   dst->side = src->side;
     78   dst->per_primitive_output = src->per_primitive_output;
     79   return str_copy(&dst->name, &src->name);
     80 }
     81 
     82 static INLINE res_T
     83 solstice_receiver_copy_and_release
     84   (struct solstice_receiver* dst,
     85    struct solstice_receiver* src)
     86 {
     87   res_T res = RES_OK;
     88   ASSERT(dst && src);
     89   dst->node = src->node;
     90   dst->side = src->side;
     91   dst->per_primitive_output = src->per_primitive_output;
     92   res = str_copy_and_release(&dst->name, &src->name);
     93   if(res != RES_OK) return res;
     94   solstice_receiver_release(src);
     95   return RES_OK;
     96 }
     97 
     98 static INLINE size_t
     99 cstr_hash(const char* const* key)
    100 {
    101   const char* str;
    102   ASSERT(key);
    103   str = *key;
    104   return hash_fnv64(str, strlen(str));
    105 }
    106 
    107 static INLINE char
    108 cstr_eq(const char* const* a, const char* const* b)
    109 {
    110   ASSERT(a && b);
    111   return strcmp(*a, *b) == 0;
    112 }
    113 
    114 struct solstice_primary {
    115   struct solstice_node* node;
    116 };
    117 
    118 #define DARRAY_NAME nodes
    119 #define DARRAY_DATA struct solstice_node*
    120 #include <rsys/dynamic_array.h>
    121 
    122 #define HTABLE_NAME material
    123 #define HTABLE_KEY size_t
    124 #define HTABLE_DATA struct ssol_material*
    125 #include <rsys/hash_table.h>
    126 #include <rsys/dynamic_array.h>
    127 
    128 #define HTABLE_NAME object
    129 #define HTABLE_KEY size_t
    130 #define HTABLE_DATA struct ssol_object*
    131 #include <rsys/hash_table.h>
    132 
    133 #define HTABLE_NAME anchor
    134 #define HTABLE_KEY size_t
    135 #define HTABLE_DATA struct solstice_node*
    136 #include <rsys/hash_table.h>
    137 
    138 #define DARRAY_NAME receiver
    139 #define DARRAY_DATA struct solstice_receiver
    140 #define DARRAY_FUNCTOR_INIT solstice_receiver_init
    141 #define DARRAY_FUNCTOR_RELEASE solstice_receiver_release
    142 #define DARRAY_FUNCTOR_COPY solstice_receiver_copy
    143 #define DARRAY_FUNCTOR_COPY_AND_RELEASE solstice_receiver_copy_and_release
    144 #include <rsys/dynamic_array.h>
    145 
    146 #define HTABLE_NAME receiver
    147 #define HTABLE_KEY const char* /* Pointer toward the name of the receiver */
    148 #define HTABLE_KEY_FUNCTOR_HASH cstr_hash
    149 #define HTABLE_KEY_FUNCTOR_EQ cstr_eq
    150 #define HTABLE_DATA size_t /* Index of the receiver */
    151 #include <rsys/hash_table.h>
    152 
    153 #define HTABLE_NAME primary
    154 #define HTABLE_KEY struct str
    155 #define HTABLE_KEY_FUNCTOR_INIT str_init
    156 #define HTABLE_KEY_FUNCTOR_RELEASE str_release
    157 #define HTABLE_KEY_FUNCTOR_COPY str_copy
    158 #define HTABLE_KEY_FUNCTOR_COPY_AND_RELEASE str_copy_and_release
    159 #define HTABLE_KEY_FUNCTOR_EQ str_eq
    160 #define HTABLE_KEY_FUNCTOR_HASH str_hash
    161 #define HTABLE_DATA struct solstice_primary
    162 #include <rsys/hash_table.h>
    163 
    164 struct solstice {
    165   struct ssol_device* ssol;
    166   struct ssol_scene* scene;
    167   struct ssol_sun* sun;
    168   struct ssol_atmosphere* atmosphere;
    169 
    170   struct solparser* parser;
    171 
    172   struct htable_material materials;
    173   struct htable_object objects;
    174   struct htable_anchor anchors;
    175   struct htable_receiver receivers;
    176   struct htable_primary primaries;
    177   struct darray_nodes roots;
    178   struct darray_nodes pivots;
    179   struct ssol_material* mtl_virtual; /* Shared virtual material */
    180 
    181   /* List of receivers ordered as submitted by the receiver file */
    182   struct darray_receiver rcvs_list;
    183 
    184   /* Rendering */
    185   struct ssol_camera* camera;
    186   struct ssol_image* framebuffer;
    187   enum solstice_args_render_mode render_mode;
    188   double up[3];
    189   unsigned spp; /* #Samples per pixel */
    190 
    191   /* Dump geometry */
    192   enum solstice_args_dump_format dump_format;
    193   enum solstice_args_dump_split_mode dump_split_mode;
    194 
    195   /* Dump radiative paths mode */
    196   struct ssol_path_tracker path_tracker;
    197 
    198   struct darray_double sun_dirs; /* List of double3 */
    199   struct darray_double sun_angles;
    200 
    201   size_t nexperiments; /* # MC experiments */
    202   FILE* output; /* Output stream */
    203   int dump_paths;
    204 
    205   /* Stream used to load/store RNG state */
    206   FILE* rng_state_input;
    207   FILE* rng_state_output;
    208 
    209   struct logger logger;
    210   struct mem_allocator* allocator;
    211 };
    212 
    213 SCORE_API res_T
    214 solstice_init
    215   (struct mem_allocator* allocator, /* May be NULL <=> use default allocator */
    216    const struct solstice_args* args,
    217    struct solstice* solstice);
    218 
    219 SCORE_API void
    220 solstice_release
    221   (struct solstice* solstice);
    222 
    223 SCORE_API res_T
    224 solstice_run
    225   (struct solstice* solstice);
    226 
    227 #endif /* SOLSTICE_H */
    228