programmer's documentation
cs_cdo_toolbox.h
Go to the documentation of this file.
1 #ifndef __CS_CDO_TOOLBOX_H__
2 #define __CS_CDO_TOOLBOX_H__
3 
4 /*============================================================================
5  * Basic operations: dot product, cross product, sum...
6  *============================================================================*/
7 
8 /*
9  This file is part of Code_Saturne, a general-purpose CFD tool.
10 
11  Copyright (C) 1998-2015 EDF S.A.
12 
13  This program is free software; you can redistribute it and/or modify it under
14  the terms of the GNU General Public License as published by the Free Software
15  Foundation; either version 2 of the License, or (at your option) any later
16  version.
17 
18  This program is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21  details.
22 
23  You should have received a copy of the GNU General Public License along with
24  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25  Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 */
27 
28 /*----------------------------------------------------------------------------
29  * Standard C library headers
30  *----------------------------------------------------------------------------*/
31 
32 #include <stdio.h>
33 
34 /*----------------------------------------------------------------------------
35  * Local headers
36  *----------------------------------------------------------------------------*/
37 
38 /*----------------------------------------------------------------------------*/
39 
41 
42 /*============================================================================
43  * Macro definitions
44  *============================================================================*/
45 
46 /*============================================================================
47  * Type definitions
48  *============================================================================*/
49 
50 typedef enum {
51 
52  CS_TOOLBOX_SUM, /* Sum of values*/
53  CS_TOOLBOX_WSUM, /* Weighted sum of values */
54  CS_TOOLBOX_SUMABS, /* Sum of absolute values */
55  CS_TOOLBOX_WSUMABS, /* Weighted sum of absolute values */
56  CS_TOOLBOX_SUM2, /* Sum of squared values */
57  CS_TOOLBOX_WSUM2, /* Weighted sum of squared values */
59 
61 
62 /* Structure for managing temporary buffers */
63 typedef struct {
64 
65  size_t bufsize;
66  void *buf;
67 
68 } cs_tmpbuf_t;
69 
70 /* Structure enabling the repeated usage of local dense matrix associated
71  with a local set of entities */
72 typedef struct {
73 
74  int n_max_ent; // max number of entities by primal cells
75  int n_ent; // current number of entities */
76  cs_lnum_t *ids; // list of entity ids (size = n_max_ent)
77  double *mat; // local matrix (size: n_max_ent*n_max_ent)
78 
80 
81 /* ============= *
82  * DATA ANALYSIS *
83  * ============= */
84 
85 typedef union {
86 
88  double value;
89 
90 } cs_data_t;
91 
92 typedef struct {
93 
96  double mean;
97  double sigma;
99 
101 
102 /*============================================================================
103  * Inline Public function prototypes for intensive usage
104  *============================================================================*/
105 
106 /*----------------------------------------------------------------------------*/
115 /*----------------------------------------------------------------------------*/
116 
117 double
118 _dp3(const cs_real_3_t u,
119  const cs_real_3_t v);
120 
121 /*----------------------------------------------------------------------------*/
129 /*----------------------------------------------------------------------------*/
130 
131 double
132 _n3(const cs_real_3_t v);
133 
134 /*----------------------------------------------------------------------------*/
144 /*----------------------------------------------------------------------------*/
145 
146 double
147 _length3(const cs_real_3_t xa,
148  const cs_real_3_t xb);
149 
150 /*----------------------------------------------------------------------------*/
160 /*----------------------------------------------------------------------------*/
161 
162 void
163 _lenunit3(const cs_real_3_t xa,
164  const cs_real_3_t xb,
165  cs_real_t *len,
166  cs_real_3_t *unit);
167 
168 /*----------------------------------------------------------------------------*/
176 /*----------------------------------------------------------------------------*/
177 
178 void
179 _cp3(const cs_real_3_t u,
180  const cs_real_3_t v,
181  cs_real_3_t *w);
182 
183 /*----------------------------------------------------------------------------*/
191 /*----------------------------------------------------------------------------*/
192 
193 void
194 _mv3(const cs_real_33_t m,
195  const cs_real_3_t v,
196  cs_real_3_t *mv);
197 
198 /*----------------------------------------------------------------------------*/
205 /*----------------------------------------------------------------------------*/
206 
207 void
208 _invmat33(const cs_real_33_t in,
209  cs_real_33_t *inv);
210 
211 /*============================================================================
212  * Public function prototypes
213  *============================================================================*/
214 
215 /*----------------------------------------------------------------------------*/
226 /*----------------------------------------------------------------------------*/
227 
228 double
229 cs_surftri(const cs_real_3_t xv,
230  const cs_real_3_t xe,
231  const cs_real_3_t xf);
232 
233 /*----------------------------------------------------------------------------*/
245 /*----------------------------------------------------------------------------*/
246 
247 double
248 cs_voltet(const cs_real_3_t xv,
249  const cs_real_3_t xe,
250  const cs_real_3_t xf,
251  const cs_real_3_t xc);
252 
253 /*----------------------------------------------------------------------------*/
265 /*----------------------------------------------------------------------------*/
266 
267 void
268 cs_daxpy(int size,
269  double alpha,
270  const cs_real_t x[],
271  cs_real_t beta,
272  const cs_real_t y[],
273  cs_real_t *p_z[],
274  bool reset);
275 
276 /*----------------------------------------------------------------------------*/
288 /*----------------------------------------------------------------------------*/
289 
290 double
291 cs_dp(int size,
292  const double v[],
293  const double w[]);
294 
295 /*----------------------------------------------------------------------------*/
306 /*----------------------------------------------------------------------------*/
307 
308 double
310  const double v[]);
311 
312 /*----------------------------------------------------------------------------*/
326 /*----------------------------------------------------------------------------*/
327 
328 double
329 cs_sum(cs_lnum_t size,
330  const double v[],
331  const double w[],
333 
334 /*----------------------------------------------------------------------------*/
341 /*----------------------------------------------------------------------------*/
342 
343 void
344 cs_toolbox_init(cs_lnum_t ref_size);
345 
346 /*----------------------------------------------------------------------------*/
351 /*----------------------------------------------------------------------------*/
352 
353 void
354 cs_toolbox_finalize(void);
355 
356 /*----------------------------------------------------------------------------*/
363 /*----------------------------------------------------------------------------*/
364 
365 void
366 cs_tmpbuf_alloc(size_t bufsize,
367  cs_tmpbuf_t **p_tb);
368 
369 /*----------------------------------------------------------------------------*/
377 /*----------------------------------------------------------------------------*/
378 
379 cs_tmpbuf_t *
381 
382 /*----------------------------------------------------------------------------*/
390 /*----------------------------------------------------------------------------*/
391 
393 cs_toolbox_locmat_create(int n_max_ent);
394 
395 /*----------------------------------------------------------------------------*/
402 /*----------------------------------------------------------------------------*/
403 
404 void
405 cs_toolbox_locmat_dump(int parent_id,
406  const cs_toolbox_locmat_t *lm);
407 
408 /*----------------------------------------------------------------------------*/
416 /*----------------------------------------------------------------------------*/
417 
420 
421 /*----------------------------------------------------------------------------*/
433 /*----------------------------------------------------------------------------*/
434 
437  int stride,
438  cs_datatype_t datatype,
439  const void *indata,
440  bool do_abs);
441 
442 /*----------------------------------------------------------------------------*/
452 /*----------------------------------------------------------------------------*/
453 
454 void
455 cs_data_info_dump(const char *name,
456  FILE *f,
457  cs_lnum_t n_elts,
458  cs_datatype_t datatype,
459  const cs_data_info_t dinfo);
460 
461 /*----------------------------------------------------------------------------*/
462 
464 
465 #endif /* __CS_TOOLBOX_H__ */
void * buf
Definition: cs_cdo_toolbox.h:66
cs_datatype_t
Definition: cs_defs.h:255
cs_data_t min
Definition: cs_cdo_toolbox.h:94
cs_lnum_t number
Definition: cs_cdo_toolbox.h:87
size_t len
Definition: mei_scanner.c:612
Definition: cs_cdo_toolbox.h:52
size_t bufsize
Definition: cs_cdo_toolbox.h:65
double euclidean_norm
Definition: cs_cdo_toolbox.h:98
void _invmat33(const cs_real_33_t in, cs_real_33_t *inv)
Inverse a 3x3 matrix.
Definition: cs_cdo_toolbox.c:344
double sigma
Definition: cs_cdo_toolbox.h:97
double _n3(const cs_real_3_t v)
Compute the euclidean norm of a vector of dimension 3.
Definition: cs_cdo_toolbox.c:234
double cs_surftri(const cs_real_3_t xv, const cs_real_3_t xe, const cs_real_3_t xf)
Compute the area of the convex_hull generated by 3 points. This corresponds to the computation of the...
Definition: cs_cdo_toolbox.c:389
#define BEGIN_C_DECLS
Definition: cs_defs.h:419
double _dp3(const cs_real_3_t u, const cs_real_3_t v)
Compute a dot product for vector of dimension 3.
Definition: cs_cdo_toolbox.c:217
Definition: cs_field_pointer.h:81
cs_toolbox_locmat_t * cs_toolbox_locmat_create(int n_max_ent)
Allocate and initialize a cs_toolbox_locmat_t structure.
Definition: cs_cdo_toolbox.c:826
void cs_tmpbuf_alloc(size_t bufsize, cs_tmpbuf_t **p_tb)
Allocate or reallocate a temporary buffer structure.
Definition: cs_cdo_toolbox.c:769
Definition: cs_cdo_toolbox.h:55
void _mv3(const cs_real_33_t m, const cs_real_3_t v, cs_real_3_t *mv)
Compute the 3x3 matrice by vector product.
Definition: cs_cdo_toolbox.c:325
double precision, dimension(ncharm), save beta
Definition: cpincl.f90:97
double cs_voltet(const cs_real_3_t xv, const cs_real_3_t xe, const cs_real_3_t xf, const cs_real_3_t xc)
Compute the volume of the convex_hull generated by 4 points. This is equivalent to the computation of...
Definition: cs_cdo_toolbox.c:423
double mean
Definition: cs_cdo_toolbox.h:96
void cs_toolbox_init(cs_lnum_t ref_size)
Allocate and initialize a private structure for this file used for reducing round-off errors during s...
Definition: cs_cdo_toolbox.c:726
void cs_toolbox_locmat_dump(int parent_id, const cs_toolbox_locmat_t *lm)
Dump a local discrete Hodge operator.
Definition: cs_cdo_toolbox.c:866
Definition: cs_cdo_toolbox.h:53
cs_data_t max
Definition: cs_cdo_toolbox.h:95
double precision, dimension(:,:,:), allocatable v
Definition: atimbr.f90:108
void cs_toolbox_finalize(void)
Free a private structure for this file used for reducing round-off errors during summation.
Definition: cs_cdo_toolbox.c:751
Definition: cs_cdo_toolbox.h:57
Definition: cs_field_pointer.h:67
double _length3(const cs_real_3_t xa, const cs_real_3_t xb)
Compute the length (euclidien norm) between two points xu and xv in a cartesian coordinate system of ...
Definition: cs_cdo_toolbox.c:252
double cs_euclidean_norm(int len, const double v[])
Compute the euclidean norm 2 of a vector of size len This algorithm tries to reduce round-off error t...
Definition: cs_cdo_toolbox.c:583
double cs_dp(int size, const double v[], const double w[])
Compute the dot product of two vectors of dimension "size" This algorithm tries to reduce round-off e...
Definition: cs_cdo_toolbox.c:512
cs_lnum_t * ids
Definition: cs_cdo_toolbox.h:76
double cs_sum(cs_lnum_t size, const double v[], const double w[], cs_toolbox_type_sum_t op)
Compute by default the sum of the elements of an array of double Additional operation are also possib...
Definition: cs_cdo_toolbox.c:618
Definition: cs_cdo_toolbox.h:54
cs_toolbox_type_sum_t
Definition: cs_cdo_toolbox.h:50
void cs_data_info_dump(const char *name, FILE *f, cs_lnum_t n_elts, cs_datatype_t datatype, const cs_data_info_t dinfo)
Dump a cs_data_info_t structure.
Definition: cs_cdo_toolbox.c:1020
cs_data_info_t cs_analysis_data(cs_lnum_t n_elts, int stride, cs_datatype_t datatype, const void *indata, bool do_abs)
Compute some simple statistics from an array.
double value
Definition: cs_cdo_toolbox.h:88
cs_toolbox_locmat_t * cs_toolbox_locmat_free(cs_toolbox_locmat_t *lm)
Free a cs_toolbox_locmat_t structure.
Definition: cs_cdo_toolbox.c:898
double * mat
Definition: cs_cdo_toolbox.h:77
void _lenunit3(const cs_real_3_t xa, const cs_real_3_t xb, cs_real_t *len, cs_real_3_t *unit)
Compute the length (euclidien norm) between two points xu and xv in a cartesian coordinate system of ...
Definition: cs_cdo_toolbox.c:277
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:307
cs_tmpbuf_t * cs_tmpbuf_free(cs_tmpbuf_t *tb)
Free a temporary buffer structure.
Definition: cs_cdo_toolbox.c:804
Definition: cs_cdo_toolbox.h:58
Definition: cs_cdo_toolbox.h:72
void cs_daxpy(int size, double alpha, const cs_real_t x[], cs_real_t beta, const cs_real_t y[], cs_real_t *p_z[], bool reset)
Compute alpha*x + beta*y = z.
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:292
#define END_C_DECLS
Definition: cs_defs.h:420
double cs_real_t
Definition: cs_defs.h:296
void _cp3(const cs_real_3_t u, const cs_real_3_t v, cs_real_3_t *w)
Compute the cross product of a vector of dimension 3.
Definition: cs_cdo_toolbox.c:305
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:311
Definition: cs_cdo_toolbox.h:56
Definition: cs_cdo_toolbox.h:63
Definition: cs_cdo_toolbox.h:92
int n_ent
Definition: cs_cdo_toolbox.h:75
int n_max_ent
Definition: cs_cdo_toolbox.h:74
Definition: cs_cdo_toolbox.h:85