cs_meg_initialization.c 6.48 KB
Newer Older
Alice MAISON's avatar
Alice MAISON committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
/*----------------------------------------------------------------------------*/
/*
  This file is generated by Code_Saturne, a general-purpose CFD tool.
*/
/*----------------------------------------------------------------------------*/

#include "cs_defs.h"

/*----------------------------------------------------------------------------
 * Standard C library headers
 *----------------------------------------------------------------------------*/

#include <assert.h>
#include <math.h>

#if defined(HAVE_MPI)
#include <mpi.h>
#endif

/*----------------------------------------------------------------------------
 *  Local headers
 *----------------------------------------------------------------------------*/

#include "cs_headers.h"
/*----------------------------------------------------------------------------*/

BEGIN_C_DECLS

/*----------------------------------------------------------------------------*/

cs_real_t *
cs_meg_initialization(const cs_zone_t *zone,
                      const char      *field_name)
{
  cs_real_t *new_vals = NULL;

  /*-----------------------------------------------------------------------*/
  /* User defined initialization for variable velocity over zone all_cells */
  if (strcmp(zone->name, "all_cells") == 0 &&
      strcmp(field_name, "velocity") == 0 ) {

    const int vals_size = zone->n_elts * 3;
    BFT_MALLOC(new_vals, vals_size, cs_real_t);


    for (cs_lnum_t e_id = 0; e_id < zone->n_elts; e_id++) {
      cs_lnum_t c_id = zone->elt_ids[e_id];

      new_vals[3 * e_id + 0] =  0. ;
      new_vals[3 * e_id + 1] =  0. ;
      new_vals[3 * e_id + 2] =  0. ;
    }
  }
  /*-----------------------------------------------------------------------*/

  /*----------------------------------------------------------------------*/
  /* User defined initialization for variable thermal over zone all_cells */
  if (strcmp(zone->name, "all_cells") == 0 &&
      strcmp(field_name, "thermal") == 0 ) {

    const int vals_size = zone->n_elts * 1;
    BFT_MALLOC(new_vals, vals_size, cs_real_t);


    for (cs_lnum_t e_id = 0; e_id < zone->n_elts; e_id++) {
      cs_lnum_t c_id = zone->elt_ids[e_id];

      new_vals[e_id] =  293.15 ;
    }
  }
  /*----------------------------------------------------------------------*/

  /*----------------------------------------------------------------------*/
  /* User defined initialization for variable traceur over zone all_cells */
  if (strcmp(zone->name, "all_cells") == 0 &&
      strcmp(field_name, "traceur") == 0 ) {

    const int vals_size = zone->n_elts * 1;
    BFT_MALLOC(new_vals, vals_size, cs_real_t);


    for (cs_lnum_t e_id = 0; e_id < zone->n_elts; e_id++) {
      cs_lnum_t c_id = zone->elt_ids[e_id];

      new_vals[e_id] =  0 ;
    }
  }
  /*----------------------------------------------------------------------*/

  /*------------------------------------------------------------------------*/
  /* User defined initialization for variable velocity over zone dessus_rue */
  if (strcmp(zone->name, "dessus_rue") == 0 &&
      strcmp(field_name, "velocity") == 0 ) {

    const cs_real_3_t *xyz = (cs_real_3_t *)cs_glob_mesh_quantities->cell_cen;

    const int vals_size = zone->n_elts * 3;
    BFT_MALLOC(new_vals, vals_size, cs_real_t);

    const cs_real_t H = cs_notebook_parameter_value_by_name("H");
    const cs_real_t zref = cs_notebook_parameter_value_by_name("zref");
    const cs_real_t Uref = cs_notebook_parameter_value_by_name("Uref");
    const cs_real_t z0 = cs_notebook_parameter_value_by_name("z0");
    const cs_real_t phi = cs_notebook_parameter_value_by_name("phi");
    const cs_real_t pi = cs_math_pi;

    for (cs_lnum_t e_id = 0; e_id < zone->n_elts; e_id++) {
      cs_lnum_t c_id = zone->elt_ids[e_id];
      const cs_real_t z = xyz[c_id][2];

      new_vals[3 * e_id + 0] =  sin(phi * pi / 180) * Uref * log((z - H + z0) / z0) / log((zref - H + z0) / z0) ;
      new_vals[3 * e_id + 1] =  cos(phi * pi / 180) * Uref * log((z - H + z0) / z0) / log((zref - H + z0) / z0) ;
      new_vals[3 * e_id + 2] =  0. ;
    }
  }
  /*------------------------------------------------------------------------*/

  /*--------------------------------------------------------------------------*/
  /* User defined initialization for variable turbulence over zone dessus_rue */
  if (strcmp(zone->name, "dessus_rue") == 0 &&
      strcmp(field_name, "turbulence") == 0 ) {

    const cs_real_3_t *xyz = (cs_real_3_t *)cs_glob_mesh_quantities->cell_cen;

    const int vals_size = zone->n_elts * 2;
    BFT_MALLOC(new_vals, vals_size, cs_real_t);

    const cs_real_t H = cs_notebook_parameter_value_by_name("H");
    const cs_real_t zref = cs_notebook_parameter_value_by_name("zref");
    const cs_real_t Uref = cs_notebook_parameter_value_by_name("Uref");
    const cs_real_t z0 = cs_notebook_parameter_value_by_name("z0");
    const cs_real_t k = cs_notebook_parameter_value_by_name("k");

    for (cs_lnum_t e_id = 0; e_id < zone->n_elts; e_id++) {
      cs_lnum_t c_id = zone->elt_ids[e_id];
      const cs_real_t z = xyz[c_id][2];

      cs_real_t ustar = k * Uref / (log((zref - H + z0) / z0)) ;
      new_vals[2 * e_id + 0] =  (cs_math_pow2((ustar))) / (pow(0.09, 0.5)) ;
      new_vals[2 * e_id + 1] =  (cs_math_pow3((ustar))) / (k * (z - H + z0)) ;
    }
  }
  /*--------------------------------------------------------------------------*/

  /*-----------------------------------------------------------------------*/
  /* User defined initialization for variable thermal over zone dessus_rue */
  if (strcmp(zone->name, "dessus_rue") == 0 &&
      strcmp(field_name, "thermal") == 0 ) {

    const int vals_size = zone->n_elts * 1;
    BFT_MALLOC(new_vals, vals_size, cs_real_t);


    for (cs_lnum_t e_id = 0; e_id < zone->n_elts; e_id++) {
      cs_lnum_t c_id = zone->elt_ids[e_id];

      new_vals[e_id] =  293.15 ;
    }
  }
  /*-----------------------------------------------------------------------*/

  /*-----------------------------------------------------------------------*/
  /* User defined initialization for variable traceur over zone dessus_rue */
  if (strcmp(zone->name, "dessus_rue") == 0 &&
      strcmp(field_name, "traceur") == 0 ) {

    const int vals_size = zone->n_elts * 1;
    BFT_MALLOC(new_vals, vals_size, cs_real_t);


    for (cs_lnum_t e_id = 0; e_id < zone->n_elts; e_id++) {
      cs_lnum_t c_id = zone->elt_ids[e_id];

      new_vals[e_id] =  0 ;
    }
  }
  /*-----------------------------------------------------------------------*/

  return new_vals;
}

/*----------------------------------------------------------------------------*/

END_C_DECLS