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 
79 } cs_locmat_t;
80 
81 /* Index to scan a mesh connectivity */
82 typedef struct {
83 
84  bool owner;
85  int n;
86  int *idx; /* from 0, size = n+1 */
87  int *ids; /* ids from 0 to n-1 (there is no multifold entry) */
88 
90 
91 /* ============= *
92  * DATA ANALYSIS *
93  * ============= */
94 
95 typedef union {
96 
98  double value;
99 
100 } cs_data_t;
101 
102 typedef struct {
103 
106  double mean;
107  double sigma;
109 
111 
112 /*============================================================================
113  * Inline Public function prototypes for intensive usage
114  *============================================================================*/
115 
116 /*----------------------------------------------------------------------------*/
125 /*----------------------------------------------------------------------------*/
126 
127 double
128 _dp3(const cs_real_3_t u,
129  const cs_real_3_t v);
130 
131 /*----------------------------------------------------------------------------*/
139 /*----------------------------------------------------------------------------*/
140 
141 double
142 _n3(const cs_real_3_t v);
143 
144 /*----------------------------------------------------------------------------*/
154 /*----------------------------------------------------------------------------*/
155 
156 double
157 _length3(const cs_real_3_t xa,
158  const cs_real_3_t xb);
159 
160 /*----------------------------------------------------------------------------*/
170 /*----------------------------------------------------------------------------*/
171 
172 void
173 _lenunit3(const cs_real_3_t xa,
174  const cs_real_3_t xb,
175  cs_real_t *len,
176  cs_real_3_t *unit);
177 
178 /*----------------------------------------------------------------------------*/
186 /*----------------------------------------------------------------------------*/
187 
188 void
189 _cp3(const cs_real_3_t u,
190  const cs_real_3_t v,
191  cs_real_3_t *w);
192 
193 /*----------------------------------------------------------------------------*/
201 /*----------------------------------------------------------------------------*/
202 
203 void
204 _mv3(const cs_real_t m[3][3],
205  const cs_real_t v[3],
206  cs_real_t mv[3]);
207 
208 /*----------------------------------------------------------------------------*/
216 /*----------------------------------------------------------------------------*/
217 
218 cs_real_t
219 _detmat33(const cs_real_t m[3][3]);
220 
221 /*----------------------------------------------------------------------------*/
228 /*----------------------------------------------------------------------------*/
229 
230 void
231 _invmat33(const cs_real_t in[3][3],
232  cs_real_t inv[3][3]);
233 
234 /*============================================================================
235  * Public function prototypes
236  *============================================================================*/
237 
238 /*----------------------------------------------------------------------------*/
245 /*----------------------------------------------------------------------------*/
246 
247 void
248 cs_toolbox_init(cs_lnum_t ref_size);
249 
250 /*----------------------------------------------------------------------------*/
255 /*----------------------------------------------------------------------------*/
256 
257 void
258 cs_toolbox_finalize(void);
259 
260 /*----------------------------------------------------------------------------*/
271 /*----------------------------------------------------------------------------*/
272 
273 void
274 cs_eigen_mat33(const cs_real_t m[3][3],
275  cs_real_t *eig_ratio,
276  cs_real_t *eig_max);
277 
278 /*----------------------------------------------------------------------------*/
289 /*----------------------------------------------------------------------------*/
290 
291 double
292 cs_surftri(const cs_real_3_t xv,
293  const cs_real_3_t xe,
294  const cs_real_3_t xf);
295 
296 /*----------------------------------------------------------------------------*/
308 /*----------------------------------------------------------------------------*/
309 
310 double
311 cs_voltet(const cs_real_3_t xv,
312  const cs_real_3_t xe,
313  const cs_real_3_t xf,
314  const cs_real_3_t xc);
315 
316 /*----------------------------------------------------------------------------*/
328 /*----------------------------------------------------------------------------*/
329 
330 void
331 cs_daxpy(int size,
332  double alpha,
333  const cs_real_t x[],
334  cs_real_t beta,
335  const cs_real_t y[],
336  cs_real_t *p_z[],
337  bool reset);
338 
339 /*----------------------------------------------------------------------------*/
351 /*----------------------------------------------------------------------------*/
352 
353 double
354 cs_dp(int size,
355  const double v[],
356  const double w[]);
357 
358 /*----------------------------------------------------------------------------*/
369 /*----------------------------------------------------------------------------*/
370 
371 double
373  const double v[]);
374 
375 /*----------------------------------------------------------------------------*/
389 /*----------------------------------------------------------------------------*/
390 
391 double
392 cs_sum(cs_lnum_t size,
393  const double v[],
394  const double w[],
396 
397 /*----------------------------------------------------------------------------*/
404 /*----------------------------------------------------------------------------*/
405 
406 void
407 cs_tmpbuf_alloc(size_t bufsize,
408  cs_tmpbuf_t **p_tb);
409 
410 /*----------------------------------------------------------------------------*/
418 /*----------------------------------------------------------------------------*/
419 
420 cs_tmpbuf_t *
422 
423 /*----------------------------------------------------------------------------*/
435 /*----------------------------------------------------------------------------*/
436 
439  int stride,
440  cs_datatype_t datatype,
441  const void *indata,
442  bool do_abs);
443 
444 /*----------------------------------------------------------------------------*/
454 /*----------------------------------------------------------------------------*/
455 
456 void
457 cs_data_info_dump(const char *name,
458  FILE *f,
459  cs_lnum_t n_elts,
460  cs_datatype_t datatype,
461  const cs_data_info_t dinfo);
462 
463 /*----------------------------------------------------------------------------*/
471 /*----------------------------------------------------------------------------*/
472 
474 cs_index_create(int n);
475 
476 /*----------------------------------------------------------------------------*/
486 /*----------------------------------------------------------------------------*/
487 
489 cs_index_map(int n,
490  int *idx,
491  int *ids);
492 
493 /*----------------------------------------------------------------------------*/
499 /*----------------------------------------------------------------------------*/
500 
501 void
503 
504 /*----------------------------------------------------------------------------*/
514 /*----------------------------------------------------------------------------*/
515 
517 cs_index_compose(int nc,
518  const cs_connect_index_t *a2b,
519  const cs_connect_index_t *b2c);
520 
521 /*----------------------------------------------------------------------------*/
530 /*----------------------------------------------------------------------------*/
531 
533 cs_index_transpose(int nb,
534  const cs_connect_index_t *a2b);
535 
536 /*----------------------------------------------------------------------------*/
542 /*----------------------------------------------------------------------------*/
543 
544 void
546 
547 /*----------------------------------------------------------------------------*/
556 /*----------------------------------------------------------------------------*/
557 
558 void
559 cs_index_dump(const char *name,
560  FILE *_f,
561  cs_connect_index_t *x);
562 
563 /*----------------------------------------------------------------------------*/
571 /*----------------------------------------------------------------------------*/
572 
573 cs_locmat_t *
574 cs_locmat_create(int n_max_ent);
575 
576 /*----------------------------------------------------------------------------*/
584 /*----------------------------------------------------------------------------*/
585 
586 cs_locmat_t *
588 
589 /*----------------------------------------------------------------------------*/
597 /*----------------------------------------------------------------------------*/
598 
599 void
601  const cs_locmat_t *send);
602 
603 /*----------------------------------------------------------------------------*/
612 /*----------------------------------------------------------------------------*/
613 
614 void
615 cs_locmat_matvec(const cs_locmat_t *loc,
616  const cs_real_t *vec,
617  cs_real_t *matvec);
618 
619 /*----------------------------------------------------------------------------*/
626 /*----------------------------------------------------------------------------*/
627 
628 void
630  const cs_locmat_t *add);
631 
632 /*----------------------------------------------------------------------------*/
640 /*----------------------------------------------------------------------------*/
641 
642 void
644  cs_locmat_t *tr);
645 
646 /*----------------------------------------------------------------------------*/
653 /*----------------------------------------------------------------------------*/
654 
655 void
656 cs_locmat_dump(int parent_id,
657  const cs_locmat_t *lm);
658 
659 /*----------------------------------------------------------------------------*/
660 
662 
663 #endif /* __CS_TOOLBOX_H__ */
void cs_eigen_mat33(const cs_real_t m[3][3], cs_real_t *eig_ratio, cs_real_t *eig_max)
Compute the eigenvalues of a 3x3 matrix which is symmetric and real -> Oliver K. Smith "eigenvalues o...
Definition: cs_cdo_toolbox.c:454
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:104
void cs_index_dump(const char *name, FILE *_f, cs_connect_index_t *x)
Dump a cs_connect_index_t structure to a file or into the standard output.
Definition: cs_cdo_toolbox.c:1318
cs_lnum_t number
Definition: cs_cdo_toolbox.h:97
size_t len
Definition: mei_scanner.c:615
void _mv3(const cs_real_t m[3][3], const cs_real_t v[3], cs_real_t mv[3])
Compute the 3x3 matrice by vector product.
Definition: cs_cdo_toolbox.c:327
void cs_locmat_matvec(const cs_locmat_t *loc, const cs_real_t *vec, cs_real_t *matvec)
Compute a local dense matrix-vector product matvec has been previously allocated. ...
Definition: cs_cdo_toolbox.c:1462
Definition: cs_cdo_toolbox.h:52
Definition: cs_cdo_toolbox.h:82
size_t bufsize
Definition: cs_cdo_toolbox.h:65
int n
Definition: cs_cdo_toolbox.h:85
double euclidean_norm
Definition: cs_cdo_toolbox.h:108
double sigma
Definition: cs_cdo_toolbox.h:107
cs_locmat_t * cs_locmat_create(int n_max_ent)
Allocate and initialize a cs_locmat_t structure.
Definition: cs_cdo_toolbox.c:1367
double _n3(const cs_real_3_t v)
Compute the euclidean norm of a vector of dimension 3.
Definition: cs_cdo_toolbox.c:236
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:539
#define BEGIN_C_DECLS
Definition: cs_defs.h:429
void cs_locmat_dump(int parent_id, const cs_locmat_t *lm)
Dump a local discrete Hodge operator.
Definition: cs_cdo_toolbox.c:1562
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:219
Definition: cs_field_pointer.h:82
void cs_tmpbuf_alloc(size_t bufsize, cs_tmpbuf_t **p_tb)
Allocate or reallocate a temporary buffer structure.
Definition: cs_cdo_toolbox.c:876
Definition: cs_cdo_toolbox.h:55
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:573
double mean
Definition: cs_cdo_toolbox.h:106
cs_connect_index_t * cs_index_create(int n)
Create an index structure of size n.
Definition: cs_cdo_toolbox.c:1083
int n_ent
Definition: cs_cdo_toolbox.h:75
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:407
Definition: cs_cdo_toolbox.h:53
int * idx
Definition: cs_cdo_toolbox.h:86
cs_data_t max
Definition: cs_cdo_toolbox.h:105
int n_max_ent
Definition: cs_cdo_toolbox.h:74
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:432
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 xa and xb in a cartesian coordinate system of ...
Definition: cs_cdo_toolbox.c:254
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:733
double precision, dimension(:,:,:), allocatable v
Definition: atimbr.f90:114
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:662
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:768
Definition: cs_cdo_toolbox.h:54
void cs_locmat_add(cs_locmat_t *loc, const cs_locmat_t *add)
Add two local dense matrices: loc += add.
Definition: cs_cdo_toolbox.c:1495
void cs_index_free(cs_connect_index_t **pidx)
Destroy a cs_connect_index_t structure.
Definition: cs_cdo_toolbox.c:1139
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:1029
cs_locmat_t * cs_locmat_free(cs_locmat_t *lm)
Free a cs_locmat_t structure.
Definition: cs_cdo_toolbox.c:1408
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:98
cs_connect_index_t * cs_index_transpose(int nb, const cs_connect_index_t *a2b)
From a cs_connect_index_t struct. A -> B create a new index B -> A.
Definition: cs_cdo_toolbox.c:1246
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 xa and xb in a cartesian coordinate system of ...
Definition: cs_cdo_toolbox.c:279
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:307
bool owner
Definition: cs_cdo_toolbox.h:84
cs_tmpbuf_t * cs_tmpbuf_free(cs_tmpbuf_t *tb)
Free a temporary buffer structure.
Definition: cs_cdo_toolbox.c:911
Definition: cs_cdo_toolbox.h:58
cs_connect_index_t * cs_index_compose(int nc, const cs_connect_index_t *a2b, const cs_connect_index_t *b2c)
From 2 indexes : A -> B and B -> C create a new index A -> C.
Definition: cs_cdo_toolbox.c:1168
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 = p_z.
cs_lnum_t * ids
Definition: cs_cdo_toolbox.h:76
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:292
#define END_C_DECLS
Definition: cs_defs.h:430
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:307
int * ids
Definition: cs_cdo_toolbox.h:87
double * mat
Definition: cs_cdo_toolbox.h:77
void cs_index_sort(cs_connect_index_t *x)
Sort each list related to an entry in a cs_connect_index_t structure.
Definition: cs_cdo_toolbox.c:1297
cs_connect_index_t * cs_index_map(int n, int *idx, int *ids)
Map arrays into an index structure of size n (owner = false)
Definition: cs_cdo_toolbox.c:1114
void cs_locmat_copy(cs_locmat_t *recv, const cs_locmat_t *send)
Copy a cs_locmat_t structure into another cs_locmat_t structure which has been already allocated...
Definition: cs_cdo_toolbox.c:1434
double precision, dimension(:,:,:), allocatable nc
Definition: atimbr.f90:110
Definition: cs_cdo_toolbox.h:56
Definition: cs_cdo_toolbox.h:63
Definition: cs_cdo_toolbox.h:102
void _invmat33(const cs_real_t in[3][3], cs_real_t inv[3][3])
Inverse a 3x3 matrix.
Definition: cs_cdo_toolbox.c:366
Definition: cs_cdo_toolbox.h:95
cs_real_t _detmat33(const cs_real_t m[3][3])
Compute the determinant of a 3x3 matrix.
Definition: cs_cdo_toolbox.c:347
Definition: cs_cdo_toolbox.h:72
void cs_locmat_add_transpose(cs_locmat_t *loc, cs_locmat_t *tr)
Define a new matrix by adding a local matrix with its transpose. Keep the transposed matrix for futur...
Definition: cs_cdo_toolbox.c:1518