stardis-solver

Solve coupled heat transfers
git clone git://git.meso-star.fr/stardis-solver.git
Log | Files | Refs | README | LICENSE

sdis_estimator_c.h (3926B)


      1 /* Copyright (C) 2016-2025 |Méso|Star> (contact@meso-star.com)
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 3 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     15 
     16 #ifndef SDIS_ESTIMATOR_C_H
     17 #define SDIS_ESTIMATOR_C_H
     18 
     19 #include "sdis_heat_path.h"
     20 #include "sdis_misc.h"
     21 
     22 #include <rsys/math.h>
     23 #include <rsys/ref_count.h>
     24 
     25 /* Forward declarations */
     26 struct ssp_rng;
     27 struct sdis_device;
     28 struct sdis_estimator;
     29 
     30 enum flux_name {
     31   FLUX_CONVECTIVE,
     32   FLUX_RADIATIVE,
     33   FLUX_IMPOSED,
     34   FLUX_TOTAL,
     35   FLUX_NAMES_COUNT__
     36 };
     37 
     38 struct sdis_estimator {
     39   struct accum temperature;
     40   struct accum realisation_time;
     41   struct accum fluxes[FLUX_NAMES_COUNT__];
     42 
     43   struct {
     44     struct accum power;
     45     double spread;
     46     double time_range[2];
     47   } power;
     48 
     49   size_t nrealisations; /* #successes */
     50   size_t nfailures;
     51 
     52   struct mutex* mutex;
     53   struct darray_heat_path paths; /* Tracked paths */
     54 
     55   /* State of the RNG after the simulation */
     56   struct ssp_rng* rng;
     57 
     58   enum sdis_estimator_type type;
     59   ref_T ref;
     60   struct sdis_device* dev;
     61 };
     62 
     63 /*******************************************************************************
     64  * Estimator local API
     65  ******************************************************************************/
     66 extern LOCAL_SYM res_T
     67 estimator_create
     68   (struct sdis_device* dev,
     69    const enum sdis_estimator_type type,
     70    struct sdis_estimator** estimator);
     71 
     72 /* Thread safe */
     73 extern LOCAL_SYM res_T
     74 estimator_add_and_release_heat_path
     75   (struct sdis_estimator* estimator,
     76    struct sdis_heat_path* path);
     77 
     78 extern LOCAL_SYM res_T
     79 estimator_save_rng_state
     80   (struct sdis_estimator* estimator,
     81    const struct ssp_rng_proxy* proxy);
     82 
     83 /* Must be invoked before any others "estimator_setup" functions */
     84 static INLINE void
     85 estimator_setup_realisations_count
     86   (struct sdis_estimator* estimator,
     87    const size_t nrealisations,
     88    const size_t nsuccesses)
     89 {
     90   ASSERT(estimator && nrealisations && nsuccesses<=nrealisations);
     91   estimator->nrealisations = nsuccesses;
     92   estimator->nfailures = nrealisations - nsuccesses;
     93 }
     94 
     95 static INLINE void
     96 estimator_setup_temperature
     97   (struct sdis_estimator* estim,
     98    const double sum,
     99    const double sum2)
    100 {
    101   ASSERT(estim);
    102   estim->temperature.sum = sum;
    103   estim->temperature.sum2 = sum2;
    104   estim->temperature.count = estim->nrealisations;
    105 }
    106 
    107 static INLINE void
    108 estimator_setup_power
    109   (struct sdis_estimator* estim,
    110    const double sum,
    111    const double sum2,
    112    const double spread,
    113    const double time_range[2])
    114 {
    115   ASSERT(estim && time_range);
    116   estim->power.power.sum = sum;
    117   estim->power.power.sum2 = sum2;
    118   estim->power.power.count = estim->nrealisations;
    119   estim->power.spread = spread;
    120   estim->power.time_range[0] = time_range[0];
    121   estim->power.time_range[1] = time_range[1];
    122 }
    123 
    124 static INLINE void
    125 estimator_setup_realisation_time
    126   (struct sdis_estimator* estim,
    127    const double sum,
    128    const double sum2)
    129 {
    130   ASSERT(estim);
    131   estim->realisation_time.sum = sum;
    132   estim->realisation_time.sum2 = sum2;
    133   estim->realisation_time.count = estim->nrealisations;
    134 }
    135 
    136 static INLINE void
    137 estimator_setup_flux
    138   (struct sdis_estimator* estim,
    139    const enum flux_name name,
    140    const double sum,
    141    const double sum2)
    142 {
    143   ASSERT(estim && (unsigned)name < FLUX_NAMES_COUNT__);
    144   estim->fluxes[name].sum = sum;
    145   estim->fluxes[name].sum2 = sum2;
    146   estim->fluxes[name].count = estim->nrealisations;
    147 }
    148 
    149 #endif /* SDIS_PROBE_ESTIMATOR_C_H */
    150