File: cs_cdo_scheme_geometry.c

package info (click to toggle)
code-saturne 4.3.3%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 77,992 kB
  • sloc: ansic: 281,257; f90: 122,305; python: 56,490; makefile: 3,915; xml: 3,285; cpp: 3,183; sh: 1,139; lex: 176; yacc: 101; sed: 16
file content (371 lines) | stat: -rw-r--r-- 14,669 bytes parent folder | download
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/*============================================================================
 * Geometric computations for building discretization operators which is
 * shared by several files
 *============================================================================*/

/*
  This file is part of Code_Saturne, a general-purpose CFD tool.

  Copyright (C) 1998-2016 EDF S.A.

  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free Software
  Foundation; either version 2 of the License, or (at your option) any later
  version.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
  Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#include "cs_defs.h"

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

#include <assert.h>

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

#include <bft_printf.h>

/*----------------------------------------------------------------------------
 * Header for the current file
 *----------------------------------------------------------------------------*/

#include "cs_cdo_scheme_geometry.h"

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

BEGIN_C_DECLS

/*=============================================================================
 * Local Macro definitions and structure definitions
 *============================================================================*/

/* Redefined the name of functions from cs_math to get shorter names */
#define _dp3  cs_math_3_dot_product

/*============================================================================
 * Private function prototypes
 *============================================================================*/

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute for a face the weight related to each vertex w_{v,f}
 *         This weight is equal to |dc(v) cap f|/|f| so that the sum of the
 *         weights is equal to 1.
 *         Compute also the volume pefc attached to each edge of the face
 *
 * \param[in]       f          id of the face in the cell-wise numbering
 * \param[in]       pfq        primal face quantities
 * \param[in]       cm         pointer to a cs_cell_mesh_t structure
 * \param[in]       hf_coef    coefficient related to the height of p_{f,c}
 * \param[in]       f_coef     coefficient related to the area of f
 * \param[in, out]  wvf        pointer to an array storing the weight/vertex
 * \param[in, out]  pefc_vol   pointer to an array storing the volume of pefc

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

inline static void
_get_wvf_pefcvol(short int                 f,
                 const cs_quant_t          pfq,
                 const cs_cell_mesh_t     *cm,
                 const double              hf_coef,
                 const double              f_coef,
                 cs_real_t                *wvf,
                 cs_real_t                *pefc_vol)
{
  double  xef_len;
  cs_real_3_t  xef_un, cp;

  assert(hf_coef > 0);

  /* Reset weights */
  for (int ii = 0; ii < cm->n_vc; ii++) wvf[ii] = 0;

  /* Compute a weight for each vertex of the current face */
  for (int ii = 0, i = cm->f2e_idx[f]; i < cm->f2e_idx[f+1]; i++, ii++) {

    const short int  e = cm->f2e_ids[i];
    const cs_quant_t  peq = cm->edge[e];

    cs_math_3_length_unitv(peq.center, pfq.center, &xef_len, xef_un);
    cs_math_3_cross_product(xef_un, peq.unitv, cp);

    const double  tef = 0.5 * xef_len * peq.meas * cs_math_3_norm(cp);
    const double  ef_contrib = tef * f_coef; // tef = s(v1,e,f) + s(v2, e, f)

    pefc_vol[ii] = tef * hf_coef;
    wvf[cm->e2v_ids[2*e]] += ef_contrib;     // for v1
    wvf[cm->e2v_ids[2*e+1]] += ef_contrib;   // for v2

  } /* End of loop on face edges */

}

/*============================================================================
 * Public function prototypes
 *============================================================================*/

/*----------------------------------------------------------------------------*/
/*!
 * \brief   Compute the gradient of a Lagrange hat function related to primal
 *          vertices in a p_{ef,c} subvolume of a cell c where e is an edge
 *          belonging to the face f with vertices v1 and v2
 *
 * \param[in]       v1        number of the first vertex in cell numbering
 * \param[in]       v2        number of the second vertex in cell numbering
 * \param[in]       deq       dual edge quantities
 * \param[in]       uvc       xc --> xv unit tangent vector
 * \param[in]       lvc       xc --> xv vector length
 * \param[in, out]  grd_v1   gradient of Lagrange function related to v1
 * \param[in, out]  grd_v2   gradient of Lagrange function related to v2
 */
/*----------------------------------------------------------------------------*/

void
cs_compute_grd_ve(const short int      v1,
                  const short int      v2,
                  const cs_nvec3_t     deq,
                  const cs_real_3_t    uvc[],
                  const cs_real_t      lvc[],
                  cs_real_t           *grd_v1,
                  cs_real_t           *grd_v2)
{
  double  hv;
  cs_real_3_t  unormal;

  /* Gradient for v1
     Normal direction to the plane in opposition to v1
     Height from this plane to the vertex v1 */
  cs_math_3_cross_product(uvc[v2], deq.unitv, unormal);
  hv = lvc[v1] * _dp3(uvc[v1], unormal);
  assert(fabs(hv) > cs_math_get_machine_epsilon()); /* Sanity check */

  const double  ohv1 = 1/hv;
  for (int k = 0; k < 3; k++)
    grd_v1[k] = unormal[k] * ohv1;

  /* Gradient for v2
     Normal direction to the plane in opposition to v2
     Height from this plane to the vertex v2 */
  cs_math_3_cross_product(uvc[v1], deq.unitv, unormal);
  hv = lvc[v2] * _dp3(uvc[v2], unormal);
  assert(fabs(hv) > cs_math_get_machine_epsilon()); /* Sanity check */

  const double  ohv2 = 1/hv;
  for (int k = 0; k < 3; k++)
    grd_v2[k] = unormal[k] * ohv2;
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute tef (the are of the triangle of base e and apex f
 *         Compute also the value of the constant gradient attached to xc in
 *         p_{f,c}
 *
 * \param[in]      f        id of the face in the cell-wise numbering
 * \param[in]      cm       pointer to a cs_cell_mesh_t structure
 * \param[in, out] tef      pointer to an array storing area of tef triangles
 * \param[in, out] grd_c    gradient of the Lagrange function related to xc
 */
/*----------------------------------------------------------------------------*/

void
cs_compute_tef_grdc(short int                 f,
                    const cs_cell_mesh_t     *cm,
                    cs_real_t                *tef,
                    cs_real_t                *grd_c)
{
  double  xef_len;
  cs_real_3_t  xef_un, un;

  const cs_quant_t  pfq = cm->face[f];
  const cs_nvec3_t  deq = cm->dedge[f];

  /* Compute the area of each triangle of base e and apex f */
  for (int i = cm->f2e_idx[f], ii = 0; i < cm->f2e_idx[f+1]; i++, ii++) {

    const short int  e = cm->f2e_ids[i];
    const cs_quant_t  peq = cm->edge[e];

    cs_math_3_length_unitv(peq.center, pfq.center, &xef_len, xef_un);
    cs_math_3_cross_product(xef_un, peq.unitv, un);

    /* tef = ||(xe -xf) x e||/2 = s(v1,e,f) + s(v2, e, f) */
    tef[ii] = 0.5 * xef_len*peq.meas * cs_math_3_norm(un);

  } /* End of loop on face edges */

  /* Compute the gradient of the Lagrange function related to xc
     which is constant inside p_{f,c} */
  const double  hf = _dp3(pfq.unitv, deq.unitv) * deq.meas;
  const cs_real_t  ohf = -cm->f_sgn[f]/hf;
  for (int k = 0; k < 3; k++)
    grd_c[k] = ohf * pfq.unitv[k];
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute for a face the weight related to each vertex w_{v,f}
 *         This weight is equal to |dc(v) cap f|/|f| so that the sum of the
 *         weights is equal to 1.
 *         Compute also the volume pefc attached to each edge of the face
 *         wvf should be allocated to n_max_vbyc and pefc_vol to n_max_ebyf
 *
 * \param[in]      f          id of the face in the cell-wise numbering
 * \param[in]      cm         pointer to a cs_cell_mesh_t structure
 * \param[in, out] wvf        pointer to an array storing the weight/vertex
 * \param[in, out] pefc_vol   pointer to an array storing the volume of pefc
 */
/*----------------------------------------------------------------------------*/

void
cs_compute_fwbs_q0(short int                 f,
                   const cs_cell_mesh_t     *cm,
                   cs_real_t                *wvf,
                   cs_real_t                *pefc_vol)
{
  const cs_quant_t  pfq = cm->face[f];
  const cs_nvec3_t  deq = cm->dedge[f];
  const double  h_coef = cs_math_onethird * _dp3(pfq.unitv, deq.unitv)*deq.meas;
  const double  f_coef = 0.5/pfq.meas;

  assert(h_coef > 0);

  /* Compute geometric quantities */
  _get_wvf_pefcvol(f, pfq, cm, h_coef, f_coef, wvf, pefc_vol);
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute for a face the weight related to each vertex w_{v,f}
 *         This weight is equal to |dc(v) cap f|/|f| so that the sum of the
 *         weights is equal to 1.
 *         Compute also the volume pefc attached to each edge of the face
 *         wvf should be allocated to n_max_vbyc and pefc_vol to n_max_ebyf
 *
 * \param[in]      f          id of the face in the cell-wise numbering
 * \param[in]      cm         pointer to a cs_cell_mesh_t structure
 * \param[in, out] wvf        pointer to an array storing the weight/vertex
 * \param[in, out] pefc_vol   pointer to an array storing the volume of pefc
 *
 * \return the volume of p_{f,c}
 */
/*----------------------------------------------------------------------------*/

double
cs_compute_fwbs_q1(short int                 f,
                   const cs_cell_mesh_t     *cm,
                   cs_real_t                *wvf,
                   cs_real_t                *pefc_vol)
{
  const cs_quant_t  pfq = cm->face[f];
  const cs_nvec3_t  deq = cm->dedge[f];
  const double  h_coef = cs_math_onethird * _dp3(pfq.unitv, deq.unitv)*deq.meas;
  const double  f_coef = 0.5/pfq.meas;

  /* Compute geometric quantities */
  _get_wvf_pefcvol(f, pfq, cm, h_coef, f_coef, wvf, pefc_vol);

  return  h_coef * pfq.meas; // volume of p_{f,c}
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute for a face the weight related to each vertex w_{v,f}
 *         This weight is equal to |dc(v) cap f|/|f| so that the sum of the
 *         weights is equal to 1.
 *         Compute also the volume pefc attached to each edge of the face
 *         wvf should be allocated to n_max_vbyc and pefc_vol to n_max_ebyf
 *
 * \param[in]      f          id of the face in the cell-wise numbering
 * \param[in]      cm         pointer to a cs_cell_mesh_t structure
 * \param[in, out] grd_c      gradient of the Lagrange function related to xc
 * \param[in, out] wvf        pointer to an array storing the weight/vertex
 * \param[in, out] pefc_vol   pointer to an array storing the volume of pefc
 */
/*----------------------------------------------------------------------------*/

void
cs_compute_fwbs_q2(short int                f,
                   const cs_cell_mesh_t    *cm,
                   cs_real_3_t              grd_c,
                   cs_real_t               *wvf,
                   cs_real_t               *pefc_vol)
{
  const cs_quant_t  pfq = cm->face[f];
  const cs_nvec3_t  deq = cm->dedge[f];
  const double  hf = _dp3(pfq.unitv, deq.unitv) * deq.meas;
  const double  f_coef = 0.5/pfq.meas;

  assert(hf > 0);

  /* Compute geometric quantities */
  _get_wvf_pefcvol(f, pfq, cm, cs_math_onethird * hf, f_coef, wvf, pefc_vol);

  /* Compute the gradient of the Lagrange function related to xc
     which is constant inside p_{f,c} */
  const cs_real_t  ohf = -cm->f_sgn[f]/hf;
  for (int k = 0; k < 3; k++)
    grd_c[k] = ohf * pfq.unitv[k];
}

/*----------------------------------------------------------------------------*/
/*!
 * \brief  Compute for a face the weight related to each vertex w_{v,f}
 *         This weight is equal to |dc(v) cap f|/|f| so that the sum of the
 *         weights is equal to 1.
 *         Compute also the volume pefc attached to each edge of the face
 *         wvf should be allocated to n_max_vbyc and pefc_vol to n_max_ebyf
 *
 * \param[in]      f          id of the face in the cell-wise numbering
 * \param[in]      cm         pointer to a cs_cell_mesh_t structure
 * \param[in, out] grd_c      gradient of the Lagrange function related to xc
 * \param[in, out] wvf        pointer to an array storing the weight/vertex
 * \param[in, out] pefc_vol   pointer to an array storing the volume of pefc
 *
 * \return the volume of p_{f,c}
 */
/*----------------------------------------------------------------------------*/

double
cs_compute_fwbs_q3(short int                 f,
                   const cs_cell_mesh_t     *cm,
                   cs_real_3_t               grd_c,
                   cs_real_t                *wvf,
                   cs_real_t                *pefc_vol)
{
  const cs_quant_t  pfq = cm->face[f];
  const cs_nvec3_t  deq = cm->dedge[f];
  const double  hf = _dp3(pfq.unitv, deq.unitv)*deq.meas;
  const double  h_coef = cs_math_onethird * hf;
  const double  f_coef = 0.5/pfq.meas;

  /* Compute geometric quantities */
  _get_wvf_pefcvol(f, pfq, cm, h_coef, f_coef, wvf, pefc_vol);

  /* Compute the gradient of the Lagrange function related to xc
     which is constant inside p_{f,c} */
  const cs_real_t  ohf = -cm->f_sgn[f]/hf;
  for (int k = 0; k < 3; k++)
    grd_c[k] = ohf * pfq.unitv[k];

  return  h_coef * pfq.meas; // volume of p_{f,c}
}

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

#undef _dp3

END_C_DECLS