solstice

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

solparser_c.h (14581B)


      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 SOLPARSER_C_H
     18 #define SOLPARSER_C_H
     19 
     20 #include "solparser.h"
     21 #include "solparser_atmosphere.h"
     22 #include "solparser_entity.h"
     23 #include "solparser_image.h"
     24 #include "solparser_material.h"
     25 #include "solparser_medium.h"
     26 #include "solparser_mtl_data.h"
     27 #include "solparser_pivot.h"
     28 #include "solparser_shape.h"
     29 #include "solparser_spectrum.h"
     30 #include "solparser_sun.h"
     31 
     32 #include <rsys/dynamic_array.h>
     33 #include <rsys/hash_table.h>
     34 #include <rsys/ref_count.h>
     35 #include <rsys/str.h>
     36 
     37 #include <yaml.h>
     38 
     39 struct target_alias {
     40   struct solparser_pivot_id pivot;
     41   const yaml_node_t* alias; /* Anchor */
     42 };
     43 
     44 /* Declare the target_alias array */
     45 #define DARRAY_NAME tgtalias
     46 #define DARRAY_DATA struct target_alias
     47 #include <rsys/dynamic_array.h>
     48 
     49 /* Declare the array of mediums */
     50 #define DARRAY_NAME medium
     51 #define DARRAY_DATA struct solparser_medium
     52 #include <rsys/dynamic_array.h>
     53 
     54 /* Declare the array of dielectric materials */
     55 #define DARRAY_NAME dielectric
     56 #define DARRAY_DATA struct solparser_material_dielectric
     57 #define DARRAY_FUNCTOR_INIT solparser_material_dielectric_init
     58 #include <rsys/dynamic_array.h>
     59 
     60 /* Declare the array of matte materials */
     61 #define DARRAY_NAME matte
     62 #define DARRAY_DATA struct solparser_material_matte
     63 #define DARRAY_FUNCTOR_INIT solparser_material_matte_init
     64 #include <rsys/dynamic_array.h>
     65 
     66 /* Declare the array of mirror materials */
     67 #define DARRAY_NAME mirror
     68 #define DARRAY_DATA struct solparser_material_mirror
     69 #define DARRAY_FUNCTOR_INIT solparser_material_mirror_init
     70 #include <rsys/dynamic_array.h>
     71 
     72 /* Declare the array of thin_dielectric materials */
     73 #define DARRAY_NAME thin_dielectric
     74 #define DARRAY_DATA struct solparser_material_thin_dielectric
     75 #define DARRAY_FUNCTOR_INIT solparser_material_thin_dielectric_init
     76 #include <rsys/dynamic_array.h>
     77 
     78 /* Declare the array of materials  */
     79 #define DARRAY_NAME material
     80 #define DARRAY_DATA struct solparser_material
     81 #include <rsys/dynamic_array.h>
     82 
     83 /* Declare the array of the double sided materials */
     84 #define DARRAY_NAME material2
     85 #define DARRAY_DATA struct solparser_material_double_sided
     86 #include <rsys/dynamic_array.h>
     87 
     88 /* Declare the array of the shapes */
     89 #define DARRAY_NAME shape
     90 #define DARRAY_DATA struct solparser_shape
     91 #include <rsys/dynamic_array.h>
     92 
     93 /* Declare the array of cuboid */
     94 #define DARRAY_NAME cuboid
     95 #define DARRAY_DATA struct solparser_shape_cuboid
     96 #include <rsys/dynamic_array.h>
     97 
     98 /* Declare the array of cylinder */
     99 #define DARRAY_NAME cylinder
    100 #define DARRAY_DATA struct solparser_shape_cylinder
    101 #include <rsys/dynamic_array.h>
    102 
    103 /* Declare the array of images */
    104 #define DARRAY_NAME image
    105 #define DARRAY_DATA struct solparser_image
    106 #define DARRAY_FUNCTOR_INIT solparser_image_init
    107 #define DARRAY_FUNCTOR_RELEASE solparser_image_release
    108 #define DARRAY_FUNCTOR_COPY solparser_image_copy
    109 #define DARRAY_FUNCTOR_COPY_AND_RELEASE solparser_image_copy_and_release
    110 #include <rsys/dynamic_array.h>
    111 
    112 /* Declare the array of imported geometries */
    113 #define DARRAY_NAME impgeom
    114 #define DARRAY_DATA struct solparser_shape_imported_geometry
    115 #define DARRAY_FUNCTOR_INIT solparser_shape_imported_geometry_init
    116 #define DARRAY_FUNCTOR_RELEASE solparser_shape_imported_geometry_release
    117 #define DARRAY_FUNCTOR_COPY solparser_shape_imported_geometry_copy
    118 #define DARRAY_FUNCTOR_COPY_AND_RELEASE \
    119   solparser_shape_imported_geometry_copy_and_release
    120 #include <rsys/dynamic_array.h>
    121 
    122 /* Declare the array of paraboloids */
    123 #define DARRAY_NAME paraboloid
    124 #define DARRAY_DATA struct solparser_shape_paraboloid
    125 #define DARRAY_FUNCTOR_INIT solparser_shape_paraboloid_init
    126 #define DARRAY_FUNCTOR_RELEASE solparser_shape_paraboloid_release
    127 #define DARRAY_FUNCTOR_COPY solparser_shape_paraboloid_copy
    128 #define DARRAY_FUNCTOR_COPY_AND_RELEASE \
    129   solparser_shape_paraboloid_copy_and_release
    130 #include <rsys/dynamic_array.h>
    131 
    132 /* Declare the array of hyperboloids */
    133 #define DARRAY_NAME hyperboloid
    134 #define DARRAY_DATA struct solparser_shape_hyperboloid
    135 #define DARRAY_FUNCTOR_INIT solparser_shape_hyperboloid_init
    136 #define DARRAY_FUNCTOR_RELEASE solparser_shape_hyperboloid_release
    137 #define DARRAY_FUNCTOR_COPY solparser_shape_hyperboloid_copy
    138 #define DARRAY_FUNCTOR_COPY_AND_RELEASE \
    139   solparser_shape_hyperboloid_copy_and_release
    140 #include <rsys/dynamic_array.h>
    141 
    142 /* Declare the array of hemispheres */
    143 #define DARRAY_NAME hemisphere
    144 #define DARRAY_DATA struct solparser_shape_hemisphere
    145 #define DARRAY_FUNCTOR_INIT solparser_shape_hemisphere_init
    146 #define DARRAY_FUNCTOR_RELEASE solparser_shape_hemisphere_release
    147 #define DARRAY_FUNCTOR_COPY solparser_shape_hemisphere_copy
    148 #define DARRAY_FUNCTOR_COPY_AND_RELEASE \
    149   solparser_shape_hemisphere_copy_and_release
    150 #include <rsys/dynamic_array.h>
    151 
    152 /* Declare the array of planes */
    153 #define DARRAY_NAME plane
    154 #define DARRAY_DATA struct solparser_shape_plane
    155 #define DARRAY_FUNCTOR_INIT solparser_shape_plane_init
    156 #define DARRAY_FUNCTOR_RELEASE solparser_shape_plane_release
    157 #define DARRAY_FUNCTOR_COPY solparser_shape_plane_copy
    158 #define DARRAY_FUNCTOR_COPY_AND_RELEASE solparser_shape_plane_copy_and_release
    159 #include <rsys/dynamic_array.h>
    160 
    161 /* Declare the array of spheres */
    162 #define DARRAY_NAME sphere
    163 #define DARRAY_DATA struct solparser_shape_sphere
    164 #include <rsys/dynamic_array.h>
    165 
    166 /* Declare the array of objects */
    167 #define DARRAY_NAME object
    168 #define DARRAY_DATA struct solparser_object
    169 #include <rsys/dynamic_array.h>
    170 
    171 /* Declare the array of geometries */
    172 #define DARRAY_NAME geometry
    173 #define DARRAY_DATA struct solparser_geometry
    174 #define DARRAY_FUNCTOR_INIT solparser_geometry_init
    175 #define DARRAY_FUNCTOR_RELEASE solparser_geometry_release
    176 #define DARRAY_FUNCTOR_COPY solparser_geometry_copy
    177 #define DARRAY_FUNCTOR_COPY_AND_RELEASE solparser_geometry_copy_and_release
    178 #include <rsys/dynamic_array.h>
    179 
    180 /* Declare the array of entities */
    181 #define DARRAY_NAME entity
    182 #define DARRAY_DATA struct solparser_entity
    183 #define DARRAY_FUNCTOR_INIT solparser_entity_init
    184 #define DARRAY_FUNCTOR_RELEASE solparser_entity_release
    185 #define DARRAY_FUNCTOR_COPY solparser_entity_copy
    186 #define DARRAY_FUNCTOR_COPY_AND_RELEASE solparser_entity_copy_and_release
    187 #include <rsys/dynamic_array.h>
    188 
    189 /* Declare the array of anchors */
    190 #define DARRAY_NAME anchor
    191 #define DARRAY_DATA struct solparser_anchor
    192 #define DARRAY_FUNCTOR_INIT solparser_anchor_init
    193 #define DARRAY_FUNCTOR_RELEASE solparser_anchor_release
    194 #define DARRAY_FUNCTOR_COPY solparser_anchor_copy
    195 #define DARRAY_FUNCTOR_COPY_AND_RELEASE solparser_anchor_copy_and_release
    196 #include <rsys/dynamic_array.h>
    197 
    198 /* Declare the array of x_pivots */
    199 #define DARRAY_NAME x_pivot
    200 #define DARRAY_DATA struct solparser_x_pivot
    201 #define DARRAY_FUNCTOR_INIT solparser_x_pivot_init
    202 #include <rsys/dynamic_array.h>
    203 
    204 /* Declare the array of zx_pivots */
    205 #define DARRAY_NAME zx_pivot
    206 #define DARRAY_DATA struct solparser_zx_pivot
    207 #define DARRAY_FUNCTOR_INIT solparser_zx_pivot_init
    208 #include <rsys/dynamic_array.h>
    209 
    210 /* Declare the array of spectra */
    211 #define DARRAY_NAME spectrum
    212 #define DARRAY_DATA struct solparser_spectrum
    213 #define DARRAY_FUNCTOR_INIT solparser_spectrum_init
    214 #define DARRAY_FUNCTOR_RELEASE solparser_spectrum_release
    215 #define DARRAY_FUNCTOR_COPY solparser_spectrum_copy
    216 #define DARRAY_FUNCTOR_COPY_AND_RELEASE solparser_spectrum_copy_and_release
    217 #include <rsys/dynamic_array.h>
    218 
    219 /* Declare the hash table that maps the address of a YAML node to the id of its
    220  * in memory representation. */
    221 #define HTABLE_NAME yaml2sols
    222 #define HTABLE_KEY yaml_node_t*
    223 #define HTABLE_DATA size_t
    224 #include <rsys/hash_table.h>
    225 
    226 struct solparser {
    227   yaml_parser_t parser;
    228   struct str stream_name;
    229   int parser_is_init;
    230 
    231   /* Material */
    232   struct htable_yaml2sols yaml2mtls; /* Cache of materials */
    233   struct darray_image images;
    234   struct darray_material mtls;
    235   struct darray_material2 mtls2; /* Double sided materials */
    236   struct darray_dielectric dielectrics;
    237   struct darray_matte mattes;
    238   struct darray_mirror mirrors;
    239   struct darray_thin_dielectric thin_dielectrics;
    240 
    241   /* Medium */
    242   struct htable_yaml2sols yaml2mediums; /* Cache of mediums */
    243   struct darray_medium mediums;
    244 
    245   /* Use to deferred the setup of the anchor targeted by a pivot */
    246   struct darray_tgtalias tgtaliases;
    247 
    248   /* Shape data */
    249   struct darray_shape shapes; /* Generic loaded shapes */
    250   struct darray_cuboid cuboids;
    251   struct darray_cylinder cylinders;
    252   struct darray_impgeom objs;
    253   struct darray_paraboloid parabols;
    254   struct darray_paraboloid parabolic_cylinders;
    255   struct darray_hyperboloid hyperbols;
    256   struct darray_hemisphere hemispheres;
    257   struct darray_plane planes;
    258   struct darray_sphere spheres;
    259   struct darray_impgeom stls;
    260 
    261   /* Geometries & objects */
    262   struct htable_yaml2sols yaml2geoms; /* Cache of geometries */
    263   struct darray_object objects;
    264   struct darray_geometry geometries;
    265 
    266   /* Sun. Note that only one sun is supported */
    267   const yaml_node_t* sun_key; /* yaml_node_t ptr used to spawn the sun */
    268   struct solparser_sun sun; /* The loaded sun */
    269 
    270   /* Atmosphere. Note that at most one atmosphere is supported */
    271   const yaml_node_t* atmosphere_key; /* ptr of the atmosphere. Can be NULL */
    272   struct solparser_atmosphere atmosphere; /* The loaded atmosphere, if any */
    273 
    274   /* Entity */
    275   struct htable_str2sols str2entities;
    276   struct darray_entity entities;
    277 
    278   /* Miscellaneous */
    279   struct darray_anchor anchors;
    280   struct darray_x_pivot x_pivots;
    281   struct darray_zx_pivot zx_pivots;
    282   struct darray_spectrum spectra;
    283 
    284   ref_T ref;
    285   struct mem_allocator* allocator;
    286 };
    287 
    288 /*******************************************************************************
    289  * Helper functions
    290  ******************************************************************************/
    291 extern LOCAL_SYM void
    292 log_err
    293   (const struct solparser* parser,
    294    const yaml_node_t* node,
    295    const char* fmt,
    296   ...)
    297 #ifdef COMPILER_GCC
    298   __attribute((format(printf, 3, 4)))
    299 #endif
    300   ;
    301 
    302 extern LOCAL_SYM void
    303 log_node
    304   (const struct solparser* parser,
    305    const yaml_node_t* node);
    306 
    307 
    308 /*******************************************************************************
    309  * Miscellaneous parsing functions
    310  ******************************************************************************/
    311 extern LOCAL_SYM res_T
    312 parse_real
    313   (struct solparser* parser,
    314    const yaml_node_t* real,
    315    const double lower_bound,
    316    const double upper_bound,
    317    double* dst);
    318 
    319 extern LOCAL_SYM res_T
    320 parse_realX
    321   (struct solparser* parser,
    322    yaml_document_t* doc,
    323    const yaml_node_t* realX,
    324    const double lower_bound,
    325    const double upper_bound,
    326    const size_t dim,
    327    double dst[]);
    328 
    329 static FINLINE res_T
    330 parse_real2
    331   (struct solparser* parser,
    332    yaml_document_t* doc,
    333    const yaml_node_t* real2,
    334    const double lower_bound,
    335    const double upper_bound,
    336    double dst[2])
    337 {
    338   return parse_realX(parser, doc, real2, lower_bound, upper_bound, 2, dst);
    339 }
    340 
    341 static FINLINE res_T
    342 parse_real3
    343   (struct solparser* parser,
    344    yaml_document_t* doc,
    345    const yaml_node_t* real3,
    346    const double lower_bound,
    347    const double upper_bound,
    348    double dst[3])
    349 {
    350   return parse_realX(parser, doc, real3, lower_bound, upper_bound, 3, dst);
    351 }
    352 
    353 extern LOCAL_SYM res_T
    354 parse_integer
    355   (struct solparser* parser,
    356    yaml_node_t* integer,
    357    const long lower_bound,
    358    const long upper_bound,
    359    long* dst);
    360 
    361 extern LOCAL_SYM res_T
    362 parse_string
    363   (struct solparser* parser,
    364    yaml_node_t* string,
    365    struct str* str);
    366 
    367 extern LOCAL_SYM res_T
    368 parse_transform
    369    (struct solparser* parser,
    370    yaml_document_t* doc,
    371    const yaml_node_t* transform,
    372    double translation[3],
    373    double rotation[3]);
    374 
    375 /*******************************************************************************
    376  * Main parsing functions
    377  ******************************************************************************/
    378 extern LOCAL_SYM res_T
    379 parse_entity
    380   (struct solparser* parser,
    381    yaml_document_t* doc,
    382    yaml_node_t* entity,
    383    struct htable_str2sols* htable,
    384    struct solparser_entity_id* out_isolent);
    385 
    386 extern LOCAL_SYM res_T
    387 parse_image
    388   (struct solparser* parser,
    389    yaml_document_t* doc,
    390    const yaml_node_t* image,
    391    struct solparser_image_id* out_img);
    392 
    393 extern LOCAL_SYM res_T
    394 parse_focals_description
    395   (struct solparser* parser,
    396    yaml_document_t* doc,
    397    const yaml_node_t* desc,
    398    struct solparser_hyperboloid_focals* focals);
    399 
    400 extern LOCAL_SYM res_T
    401 parse_geometry
    402   (struct solparser* parser,
    403    yaml_document_t* doc,
    404    yaml_node_t* geometry,
    405    struct solparser_geometry_id* out_isolgeom);
    406 
    407 extern LOCAL_SYM res_T
    408 parse_material
    409   (struct solparser* parser,
    410    yaml_document_t* doc,
    411    yaml_node_t* mtl,
    412    struct solparser_material_double_sided_id* out_imtl2);
    413 
    414 extern LOCAL_SYM res_T
    415 parse_medium
    416   (struct solparser* parser,
    417    yaml_document_t* doc,
    418    yaml_node_t* medium,
    419    struct solparser_medium_id* out_imedium);
    420 
    421 extern LOCAL_SYM res_T
    422 parse_mtl_data
    423   (struct solparser* parser,
    424    yaml_document_t* doc,
    425    yaml_node_t* mtl_data,
    426    const double lower_bound,
    427    const double upper_bound,
    428    struct solparser_mtl_data* data);
    429 
    430 extern LOCAL_SYM res_T
    431 parse_spectrum
    432   (struct solparser* parser,
    433    yaml_document_t* doc,
    434    const yaml_node_t* spectrum,
    435    const double lower_bound,
    436    const double upper_bound,
    437    struct solparser_spectrum_id* out_ispectrum);
    438 
    439 extern LOCAL_SYM res_T
    440 parse_sun
    441   (struct solparser* parser,
    442    yaml_document_t* doc,
    443    const yaml_node_t* sun,
    444    struct solparser_sun** out_solsun);
    445 
    446 extern LOCAL_SYM res_T
    447 parse_atmosphere
    448   (struct solparser* parser,
    449    yaml_document_t* doc,
    450    yaml_node_t* atm,
    451    struct solparser_atmosphere** out_solatm);
    452 
    453 extern LOCAL_SYM res_T
    454 parse_x_pivot
    455   (struct solparser* parser,
    456    yaml_document_t* doc,
    457    const yaml_node_t* x_pivot,
    458    struct solparser_pivot_id* out_isolpivot);
    459 
    460 extern LOCAL_SYM res_T
    461 parse_zx_pivot
    462   (struct solparser* parser,
    463    yaml_document_t* doc,
    464    const yaml_node_t* zx_pivot,
    465    struct solparser_pivot_id* out_isolpivot);
    466 
    467 #endif /* SOLPARSER_C_H */