schiff

Estimate the radiative properties of soft particless
git clone git://git.meso-star.com/schiff.git
Log | Files | Refs | README | LICENSE

schiff_mesh.h (4555B)


      1 /* Copyright (C) 2015-2016 CNRS
      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 SCHIFF_MESH_H
     17 #define SCHIFF_MESH_H
     18 
     19 #include <rsys/dynamic_array_float.h>
     20 #include <rsys/dynamic_array_uint.h>
     21 
     22 struct sin_cos { double angle, sinus, cosine; };
     23 
     24 #define DARRAY_NAME sincos
     25 #define DARRAY_DATA struct sin_cos
     26 #include <rsys/dynamic_array.h>
     27 
     28 enum schiff_coordinates {
     29   SCHIFF_NO_COORDINATE, /* No coordinate is setuped */
     30   SCHIFF_POLAR,
     31   SCHIFF_CARTESIAN
     32 };
     33 
     34 struct schiff_mesh {
     35   enum schiff_coordinates coordinates;
     36   union {
     37     struct darray_float cartesian;
     38     struct darray_uint polar;
     39   } vertices;
     40   struct darray_uint indices;
     41 
     42   /* Used only by polar coordinates */
     43   struct darray_sincos thetas; /* List of thetas, cos(theta) , sin(theta) */
     44   struct darray_sincos phis; /* List of phis, cos(phi), sin(phi) */
     45 
     46   int is_init;
     47 };
     48 
     49 extern LOCAL_SYM res_T
     50 schiff_mesh_init_sphere
     51   (struct mem_allocator* allocator,
     52    struct schiff_mesh* mesh,
     53    const unsigned nthetas); /* # discret points along 2PI */
     54 
     55 extern LOCAL_SYM res_T
     56 schiff_mesh_init_sphere_polar
     57   (struct mem_allocator* allocator,
     58    struct schiff_mesh* mesh,
     59    const unsigned nthetas);
     60 
     61 extern LOCAL_SYM res_T
     62 schiff_mesh_init_cylinder
     63   (struct mem_allocator* allocator,
     64    struct schiff_mesh* mesh,
     65    const unsigned nslices);
     66 
     67 /* Initialise the indices of the helical pipe. The vertices are still not
     68  * defined. Use the schiff_mesh_setup_helical_pipe to define these data */
     69 extern LOCAL_SYM res_T
     70 schiff_mesh_init_helical_pipe
     71   (struct mem_allocator* allocator,
     72    struct schiff_mesh* mesh,
     73    const unsigned nsteps_helicoid,
     74    const unsigned nsteps_circle);
     75 
     76 extern LOCAL_SYM res_T
     77 schiff_mesh_helical_pipe_create_vertices
     78   (const struct schiff_mesh* mesh,
     79    const double pitch,
     80    const double height,
     81    const double radius_helicoid,
     82    const double radius_circle,
     83    /* The 2 following attribs are assumed to be equal to attributes used by the
     84     * init function */
     85    const unsigned nsteps_helicoid,
     86    const unsigned nsteps_circle,
     87    size_t* out_nvertices,
     88    float** out_vertices);
     89 
     90 extern LOCAL_SYM void
     91 schiff_mesh_helical_pipe_destroy_vertices
     92   (const struct schiff_mesh* mesh,
     93    float* vertices);
     94 
     95 extern LOCAL_SYM void
     96 schiff_mesh_release
     97   (struct schiff_mesh* mesh);
     98 
     99 static INLINE void
    100 schiff_mesh_get_indices
    101   (const struct schiff_mesh* mesh,
    102    const unsigned itri,
    103    unsigned ids[3])
    104 {
    105   const size_t i = itri * 3;
    106   ASSERT(mesh);
    107   ASSERT(darray_uint_size_get(&mesh->indices) % 3 == 0);
    108   ASSERT(itri < darray_uint_size_get(&mesh->indices) / 3);
    109   ids[0] = darray_uint_cdata_get(&mesh->indices)[i + 0];
    110   ids[1] = darray_uint_cdata_get(&mesh->indices)[i + 1];
    111   ids[2] = darray_uint_cdata_get(&mesh->indices)[i + 2];
    112 }
    113 
    114 static INLINE void
    115 schiff_mesh_get_cartesian_position
    116   (const struct schiff_mesh* mesh,
    117    const unsigned ivert,
    118    float vertex[3])
    119 {
    120   const size_t i = ivert * 3;
    121   ASSERT(mesh && vertex && mesh->coordinates == SCHIFF_CARTESIAN);
    122   ASSERT(darray_float_size_get(&mesh->vertices.cartesian) % 3 == 0);
    123   ASSERT(ivert < darray_float_size_get(&mesh->vertices.cartesian) / 3);
    124   vertex[0] = darray_float_cdata_get(&mesh->vertices.cartesian)[i + 0];
    125   vertex[1] = darray_float_cdata_get(&mesh->vertices.cartesian)[i + 1];
    126   vertex[2] = darray_float_cdata_get(&mesh->vertices.cartesian)[i + 2];
    127 }
    128 
    129 static INLINE void
    130 schiff_mesh_get_polar_position
    131   (const struct schiff_mesh* mesh,
    132    const unsigned ivert,
    133    struct sin_cos angles[2])
    134 {
    135   const size_t i = ivert * 2;
    136   const unsigned* iangles;
    137   ASSERT(mesh && angles && mesh->coordinates == SCHIFF_POLAR);
    138   ASSERT(darray_uint_size_get(&mesh->vertices.polar) % 2 == 0);
    139   ASSERT(ivert < darray_uint_size_get(&mesh->vertices.polar) / 2);
    140 
    141   iangles = darray_uint_cdata_get(&mesh->vertices.polar) + i;
    142   angles[0] = darray_sincos_cdata_get(&mesh->thetas)[iangles[0]];
    143   angles[1] = darray_sincos_cdata_get(&mesh->phis)[iangles[1]];
    144 }
    145 
    146 #endif /* SBOX_SCHIFF_MESH_H */
    147