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_atmosphere.c (1913B)


      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 #include "solstice_c.h"
     18 #include "parser/solparser.h"
     19 #include "parser/solparser_atmosphere.h"
     20 
     21 #include <solstice/ssol.h>
     22 
     23 res_T
     24 solstice_create_atmosphere(struct solstice* solstice)
     25 {
     26   struct ssol_atmosphere* atm = NULL;
     27   struct ssol_data extinction = SSOL_DATA_NULL;
     28   const struct solparser_atmosphere* solparser_atm = NULL;
     29   res_T res = RES_OK;
     30   ASSERT(solstice);
     31 
     32   solparser_atm = solparser_get_atmosphere(solstice->parser);
     33   if(!solparser_atm) return res;
     34 
     35   res = ssol_atmosphere_create(solstice->ssol, &atm);
     36   if(res != RES_OK) goto error;
     37   
     38   res = mtl_to_ssol_data(solstice, &solparser_atm->extinction, &extinction);
     39   if(res != RES_OK) goto error;
     40 
     41   res = ssol_atmosphere_set_extinction(atm, &extinction);
     42   if(res != RES_OK) {
     43     fprintf(stderr, "Could not set atmosphere extinction.\n");
     44     goto error;
     45   }
     46 
     47   res = ssol_scene_attach_atmosphere(solstice->scene, atm);
     48   if(res != RES_OK) {
     49     fprintf(stderr, "Could not attach the atmosphere to the scene.\n");
     50     goto error;
     51   }
     52 
     53 exit:
     54   ssol_data_clear(&extinction);
     55   solstice->atmosphere = atm;
     56   return res;
     57 error:
     58   if(atm) {
     59     SSOL(atmosphere_ref_put(atm));
     60     atm = NULL;
     61   }
     62 
     63   goto exit;
     64 }