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-2016 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 #include <math.h>
34 
35 /*----------------------------------------------------------------------------
36  * Local headers
37  *----------------------------------------------------------------------------*/
38 
39 /*----------------------------------------------------------------------------*/
40 
42 
43 /*============================================================================
44  * Macro definitions
45  *============================================================================*/
46 
47 /*============================================================================
48  * Type definitions
49  *============================================================================*/
50 
51 /* Structure for managing temporary buffers */
52 typedef struct {
53 
54  size_t bufsize;
55  void *buf;
56 
57 } cs_tmpbuf_t;
58 
59 /* Index to scan a mesh connectivity */
60 typedef struct {
61 
62  bool owner;
63  int n;
64  int *idx; /* from 0, size = n+1 */
65  int *ids; /* ids from 0 to n-1 (there is no multifold entry) */
66 
68 
69 /* Structure enabling the repeated usage of local dense square matrix
70  associated with a local set of entities */
71 typedef struct {
72 
73  int n_max_ent; // max number of entities by primal cells
74  int n_ent; // current number of entities
75  cs_lnum_t *ids; // list of entity ids (size = n_max_ent)
76  double *val; // local matrix (size: n_max_ent*n_max_ent)
77 
78 } cs_locmat_t;
79 
80 /* Structure enabling the repeated usage of local dense DEC matrix associated
81  with a local set of entities */
82 typedef struct {
83 
84  int n_max_rows; // max number of entries in a row
85  int n_rows; // current number of rows
86  cs_lnum_t *row_ids; // list of entity ids in a row (size = n_max_rows)
87 
88  int n_max_cols; // max number of entries in a column
89  int n_cols; // current number of columns
90  cs_lnum_t *col_ids; // list of entity ids in a col (size = n_max_rows)
91 
92  short int *sgn; // local matrix (size: n_max_rows*n_max_cols)
93 
94 } cs_locdec_t;
95 
96 /* ============= *
97  * DATA ANALYSIS *
98  * ============= */
99 
100 typedef union {
101 
103  double value;
104 
105 } cs_data_t;
106 
107 typedef struct {
108 
111  double mean;
112  double sigma;
114 
116 
117 /*============================================================================
118  * Public function prototypes
119  *============================================================================*/
120 
121 /*----------------------------------------------------------------------------*/
132 /*----------------------------------------------------------------------------*/
133 
134 double
136  const double v[]);
137 
138 /*----------------------------------------------------------------------------*/
148 /*----------------------------------------------------------------------------*/
149 
150 double
152  const double *restrict x,
153  const double *restrict weight);
154 
155 /*----------------------------------------------------------------------------*/
162 /*----------------------------------------------------------------------------*/
163 
164 void
165 cs_tmpbuf_alloc(size_t bufsize,
166  cs_tmpbuf_t **p_tb);
167 
168 /*----------------------------------------------------------------------------*/
176 /*----------------------------------------------------------------------------*/
177 
178 cs_tmpbuf_t *
180 
181 /*----------------------------------------------------------------------------*/
193 /*----------------------------------------------------------------------------*/
194 
197  int stride,
198  cs_datatype_t datatype,
199  const void *indata,
200  bool do_abs);
201 
202 /*----------------------------------------------------------------------------*/
212 /*----------------------------------------------------------------------------*/
213 
214 void
215 cs_data_info_dump(const char *name,
216  FILE *f,
217  cs_lnum_t n_elts,
218  cs_datatype_t datatype,
219  const cs_data_info_t dinfo);
220 
221 /*----------------------------------------------------------------------------*/
229 /*----------------------------------------------------------------------------*/
230 
232 cs_index_create(int n);
233 
234 /*----------------------------------------------------------------------------*/
244 /*----------------------------------------------------------------------------*/
245 
247 cs_index_map(int n,
248  int *idx,
249  int *ids);
250 
251 /*----------------------------------------------------------------------------*/
257 /*----------------------------------------------------------------------------*/
258 
259 void
261 
262 /*----------------------------------------------------------------------------*/
272 /*----------------------------------------------------------------------------*/
273 
275 cs_index_compose(int nc,
276  const cs_connect_index_t *a2b,
277  const cs_connect_index_t *b2c);
278 
279 /*----------------------------------------------------------------------------*/
288 /*----------------------------------------------------------------------------*/
289 
291 cs_index_transpose(int nb,
292  const cs_connect_index_t *a2b);
293 
294 /*----------------------------------------------------------------------------*/
300 /*----------------------------------------------------------------------------*/
301 
302 void
304 
305 /*----------------------------------------------------------------------------*/
314 /*----------------------------------------------------------------------------*/
315 
316 void
317 cs_index_dump(const char *name,
318  FILE *_f,
319  cs_connect_index_t *x);
320 
321 /*----------------------------------------------------------------------------*/
329 /*----------------------------------------------------------------------------*/
330 
331 cs_locmat_t *
332 cs_locmat_create(int n_max_ent);
333 
334 /*----------------------------------------------------------------------------*/
342 /*----------------------------------------------------------------------------*/
343 
344 cs_locmat_t *
346 
347 /*----------------------------------------------------------------------------*/
355 /*----------------------------------------------------------------------------*/
356 
357 void
359  const cs_locmat_t *send);
360 
361 /*----------------------------------------------------------------------------*/
370 /*----------------------------------------------------------------------------*/
371 
372 void
373 cs_locmat_matvec(const cs_locmat_t *loc,
374  const cs_real_t *vec,
375  cs_real_t *matvec);
376 
377 /*----------------------------------------------------------------------------*/
384 /*----------------------------------------------------------------------------*/
385 
386 void
388  const cs_locmat_t *add);
389 
390 /*----------------------------------------------------------------------------*/
398 /*----------------------------------------------------------------------------*/
399 
400 void
402  double alpha,
403  const cs_locmat_t *add);
404 
405 /*----------------------------------------------------------------------------*/
413 /*----------------------------------------------------------------------------*/
414 
415 void
417  cs_locmat_t *tr);
418 
419 /*----------------------------------------------------------------------------*/
426 /*----------------------------------------------------------------------------*/
427 
428 void
429 cs_locmat_dump(int parent_id,
430  const cs_locmat_t *lm);
431 
432 /*----------------------------------------------------------------------------*/
441 /*----------------------------------------------------------------------------*/
442 
443 cs_locdec_t *
444 cs_locdec_create(int n_max_rows,
445  int n_max_cols);
446 
447 /*----------------------------------------------------------------------------*/
455 /*----------------------------------------------------------------------------*/
456 
457 cs_locdec_t *
459 
460 /*----------------------------------------------------------------------------*/
461 
463 
464 #endif /* __CS_TOOLBOX_H__ */
void * buf
Definition: cs_cdo_toolbox.h:55
cs_datatype_t
Definition: cs_defs.h:255
#define restrict
Definition: cs_defs.h:122
cs_data_t min
Definition: cs_cdo_toolbox.h:109
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:741
cs_lnum_t number
Definition: cs_cdo_toolbox.h:102
double * val
Definition: cs_cdo_toolbox.h:76
size_t len
Definition: mei_scanner.c:600
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:886
Definition: cs_cdo_toolbox.h:60
size_t bufsize
Definition: cs_cdo_toolbox.h:54
int n
Definition: cs_cdo_toolbox.h:63
double euclidean_norm
Definition: cs_cdo_toolbox.h:113
void cs_locmat_mult_add(cs_locmat_t *loc, double alpha, const cs_locmat_t *add)
Give the result of the following operation: loc = loc + alpha*add.
Definition: cs_cdo_toolbox.c:942
double sigma
Definition: cs_cdo_toolbox.h:112
cs_locmat_t * cs_locmat_create(int n_max_ent)
Allocate and initialize a cs_locmat_t structure.
Definition: cs_cdo_toolbox.c:791
#define BEGIN_C_DECLS
Definition: cs_defs.h:448
void cs_locmat_dump(int parent_id, const cs_locmat_t *lm)
Dump a local discrete Hodge operator.
Definition: cs_cdo_toolbox.c:1010
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:299
double mean
Definition: cs_cdo_toolbox.h:111
cs_connect_index_t * cs_index_create(int n)
Create an index structure of size n.
Definition: cs_cdo_toolbox.c:506
int n_ent
Definition: cs_cdo_toolbox.h:74
int * idx
Definition: cs_cdo_toolbox.h:64
short int * sgn
Definition: cs_cdo_toolbox.h:92
cs_data_t max
Definition: cs_cdo_toolbox.h:110
int n_max_ent
Definition: cs_cdo_toolbox.h:73
double cs_real_t
Floating-point value.
Definition: cs_defs.h:296
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:200
int n_cols
Definition: cs_cdo_toolbox.h:89
double precision, dimension(:,:,:), allocatable v
Definition: atimbr.f90:114
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:919
void cs_index_free(cs_connect_index_t **pidx)
Destroy a cs_connect_index_t structure.
Definition: cs_cdo_toolbox.c:562
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:452
cs_locmat_t * cs_locmat_free(cs_locmat_t *lm)
Free a cs_locmat_t structure.
Definition: cs_cdo_toolbox.c:832
int n_rows
Definition: cs_cdo_toolbox.h:85
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.
cs_locdec_t * cs_locdec_create(int n_max_rows, int n_max_cols)
Allocate and initialize a cs_locdec_t structure.
Definition: cs_cdo_toolbox.c:1043
double value
Definition: cs_cdo_toolbox.h:103
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:669
cs_lnum_t * col_ids
Definition: cs_cdo_toolbox.h:90
bool owner
Definition: cs_cdo_toolbox.h:62
cs_tmpbuf_t * cs_tmpbuf_free(cs_tmpbuf_t *tb)
Free a temporary buffer structure.
Definition: cs_cdo_toolbox.c:334
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:591
Definition: cs_cdo_toolbox.h:82
cs_lnum_t * ids
Definition: cs_cdo_toolbox.h:75
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:292
#define END_C_DECLS
Definition: cs_defs.h:449
int * ids
Definition: cs_cdo_toolbox.h:65
double cs_weighted_sum_square(cs_lnum_t n, const double *restrict x, const double *restrict weight)
Compute the weighted sum of square values of an array.
Definition: cs_cdo_toolbox.c:231
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:720
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:537
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:858
double precision, dimension(:,:,:), allocatable nc
Definition: atimbr.f90:110
Definition: cs_cdo_toolbox.h:52
cs_locdec_t * cs_locdec_free(cs_locdec_t *m)
Free a cs_locdec_t structure.
Definition: cs_cdo_toolbox.c:1090
cs_lnum_t * row_ids
Definition: cs_cdo_toolbox.h:86
Definition: cs_cdo_toolbox.h:107
int n_max_rows
Definition: cs_cdo_toolbox.h:84
Definition: cs_cdo_toolbox.h:100
Definition: cs_cdo_toolbox.h:71
int n_max_cols
Definition: cs_cdo_toolbox.h:88
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:966