atrstm

Load and structure a combustion gas mixture
git clone git://git.meso-star.fr/atrstm.git
Log | Files | Refs | README | LICENSE

atrstm_rdgfa.c (3283B)


      1 /* Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2020, 2021 Centre National de la Recherche Scientifique
      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 "atrstm_c.h"
     18 #include "atrstm_rdgfa.h"
     19 
     20 #include <astoria/atrtp.h>
     21 
     22 /*******************************************************************************
     23  * Helper function
     24  ******************************************************************************/
     25 static INLINE int
     26 check_fetch_rdgfa_args
     27   (const struct atrstm* atrstm,
     28    const struct atrstm_fetch_rdgfa_args* args)
     29 {
     30   return args
     31       && !SUVM_PRIMITIVE_NONE(&args->prim)
     32       && args->wavelength >= atrstm->wlen_range[0]
     33       && args->wavelength <= atrstm->wlen_range[1];
     34 }
     35 
     36 /*******************************************************************************
     37  * Exported functions
     38  ******************************************************************************/
     39 res_T
     40 atrstm_fetch_rdgfa
     41   (const struct atrstm* atrstm,
     42    const struct atrstm_fetch_rdgfa_args* args,
     43    struct atrstm_rdgfa* rdgfa)
     44 {
     45   struct atrtp_desc atrtp_desc = ATRTP_DESC_NULL;
     46   double soot_primary_particles_count[4];
     47   double soot_primary_particles_diameter[4];
     48   double Np;
     49   double Dp;
     50   int inode;
     51   res_T res = RES_OK;
     52 
     53   if(!atrstm || !check_fetch_rdgfa_args(atrstm, args) || !rdgfa) {
     54     res = RES_BAD_ARG;
     55     goto error;
     56   }
     57 
     58   res = atrtp_get_desc(atrstm->atrtp, &atrtp_desc);
     59   if(res != RES_OK) goto error;
     60 
     61   FOR_EACH(inode, 0, 4) {
     62     const double* node;
     63 
     64     /* Fetch the thermodynamic properties of the node */
     65     node = atrtp_desc_get_node_properties(&atrtp_desc, args->prim.indices[inode]);
     66 
     67     /* Fetch the required node attributes */
     68     soot_primary_particles_count[inode] = 
     69       node[ATRTP_SOOT_PRIMARY_PARTICLES_COUNT];
     70     soot_primary_particles_diameter[inode] = 
     71       node[ATRTP_SOOT_PRIMARY_PARTICLES_DIAMETER];
     72   }
     73 
     74   /* Linearly interpolate the node attributes */
     75   Np = 
     76     soot_primary_particles_count[0] * args->bcoords[0]
     77   + soot_primary_particles_count[1] * args->bcoords[1]
     78   + soot_primary_particles_count[2] * args->bcoords[2]
     79   + soot_primary_particles_count[3] * args->bcoords[3];
     80   Dp = 
     81     soot_primary_particles_diameter[0] * args->bcoords[0]
     82   + soot_primary_particles_diameter[1] * args->bcoords[1]
     83   + soot_primary_particles_diameter[2] * args->bcoords[2]
     84   + soot_primary_particles_diameter[3] * args->bcoords[3];
     85 
     86   /* Setup output data */
     87   rdgfa->wavelength = args->wavelength;
     88   rdgfa->fractal_dimension = atrstm->fractal_dimension;
     89   rdgfa->gyration_radius = compute_gyration_radius
     90     (atrstm->fractal_prefactor, atrstm->fractal_dimension, Np, Dp);
     91 
     92 exit:
     93   return res;
     94 error:
     95   goto exit;
     96 }
     97