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-2018 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 /* Index to scan a mesh connectivity */
52 typedef struct {
53 
54  bool owner;
55  int n;
56  int *idx; /* from 0, size = n+1 */
57  int *ids; /* ids from 0 to n-1 (there is no multifold entry) */
58 
60 
61 /* Structure enabling the repeated usage of local dense square matrix
62  associated with a local set of entities */
63 typedef struct {
64 
65  int n_max_ent; // max number of entities by primal cells
66  int n_ent; // current number of entities
67  cs_lnum_t *ids; // list of entity ids (size = n_max_ent)
68  double *val; // local matrix (size: n_max_ent*n_max_ent)
69 
70 } cs_locmat_t;
71 
72 /*============================================================================
73  * Public function prototypes
74  *============================================================================*/
75 
76 /*----------------------------------------------------------------------------*/
87 /*----------------------------------------------------------------------------*/
88 
90 cs_euclidean_norm(int len,
91  const cs_real_t v[]);
92 
93 /*----------------------------------------------------------------------------*/
103 /*----------------------------------------------------------------------------*/
104 
105 cs_real_t
107  const cs_real_t *restrict x,
108  const cs_real_t *restrict weight);
109 
110 /*----------------------------------------------------------------------------*/
118 /*----------------------------------------------------------------------------*/
119 
121 cs_index_create(int n);
122 
123 /*----------------------------------------------------------------------------*/
133 /*----------------------------------------------------------------------------*/
134 
136 cs_index_map(int n,
137  int *idx,
138  int *ids);
139 
140 /*----------------------------------------------------------------------------*/
146 /*----------------------------------------------------------------------------*/
147 
148 void
150 
151 /*----------------------------------------------------------------------------*/
161 /*----------------------------------------------------------------------------*/
162 
164 cs_index_compose(int nc,
165  const cs_connect_index_t *a2b,
166  const cs_connect_index_t *b2c);
167 
168 /*----------------------------------------------------------------------------*/
177 /*----------------------------------------------------------------------------*/
178 
180 cs_index_transpose(int nb,
181  const cs_connect_index_t *a2b);
182 
183 /*----------------------------------------------------------------------------*/
189 /*----------------------------------------------------------------------------*/
190 
191 void
193 
194 /*----------------------------------------------------------------------------*/
203 /*----------------------------------------------------------------------------*/
204 
205 void
206 cs_index_dump(const char *name,
207  FILE *_f,
208  cs_connect_index_t *x);
209 
210 /*----------------------------------------------------------------------------*/
218 /*----------------------------------------------------------------------------*/
219 
220 cs_locmat_t *
221 cs_locmat_create(int n_max_ent);
222 
223 /*----------------------------------------------------------------------------*/
231 /*----------------------------------------------------------------------------*/
232 
233 cs_locmat_t *
235 
236 /*----------------------------------------------------------------------------*/
244 /*----------------------------------------------------------------------------*/
245 
246 void
248  const cs_locmat_t *send);
249 
250 /*----------------------------------------------------------------------------*/
259 /*----------------------------------------------------------------------------*/
260 
261 void
262 cs_locmat_matvec(const cs_locmat_t *loc,
263  const cs_real_t *vec,
264  cs_real_t *matvec);
265 
266 /*----------------------------------------------------------------------------*/
273 /*----------------------------------------------------------------------------*/
274 
275 void
277  const cs_locmat_t *add);
278 
279 /*----------------------------------------------------------------------------*/
287 /*----------------------------------------------------------------------------*/
288 
289 void
292  const cs_locmat_t *add);
293 
294 /*----------------------------------------------------------------------------*/
302 /*----------------------------------------------------------------------------*/
303 
304 void
306  cs_locmat_t *tr);
307 
308 /*----------------------------------------------------------------------------*/
314 /*----------------------------------------------------------------------------*/
315 
316 void
318 
319 /*----------------------------------------------------------------------------*/
326 /*----------------------------------------------------------------------------*/
327 
328 void
329 cs_locmat_dump(int parent_id,
330  const cs_locmat_t *lm);
331 
332 /*----------------------------------------------------------------------------*/
336 /*----------------------------------------------------------------------------*/
337 
338 void
339 cs_dump_array_to_listing(const char *header,
340  const cs_lnum_t size,
341  const cs_real_t array[],
342  int n_cols);
343 
344 void
345 cs_dump_integer_to_listing(const char *header,
346  const cs_lnum_t size,
347  const cs_lnum_t array[],
348  int n_cols);
349 
350 /*----------------------------------------------------------------------------*/
351 
353 
354 #endif /* __CS_TOOLBOX_H__ */
#define restrict
Definition: cs_defs.h:122
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:427
double * val
Definition: cs_cdo_toolbox.h:68
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:572
Definition: cs_cdo_toolbox.h:52
int n
Definition: cs_cdo_toolbox.h:55
cs_locmat_t * cs_locmat_create(int n_max_ent)
Allocate and initialize a cs_locmat_t structure.
Definition: cs_cdo_toolbox.c:477
#define BEGIN_C_DECLS
Definition: cs_defs.h:451
void cs_locmat_dump(int parent_id, const cs_locmat_t *lm)
Dump a local discrete Hodge operator.
Definition: cs_cdo_toolbox.c:731
Definition: cs_field_pointer.h:83
cs_real_t cs_weighted_sum_squared(cs_lnum_t n, const cs_real_t *restrict x, const cs_real_t *restrict weight)
Compute the weighted sum of square values of an array.
Definition: cs_cdo_toolbox.c:120
cs_connect_index_t * cs_index_create(int n)
Create an index structure of size n.
Definition: cs_cdo_toolbox.c:191
int n_ent
Definition: cs_cdo_toolbox.h:66
int * idx
Definition: cs_cdo_toolbox.h:56
void cs_dump_array_to_listing(const char *header, const cs_lnum_t size, const cs_real_t array[], int n_cols)
Dump an array in the listing (For DEBUG)
Definition: cs_cdo_toolbox.c:759
int n_max_ent
Definition: cs_cdo_toolbox.h:65
double cs_real_t
Floating-point value.
Definition: cs_defs.h:297
void cs_locmat_mult_add(cs_locmat_t *loc, cs_real_t alpha, const cs_locmat_t *add)
Give the result of the following operation: loc = loc + alpha*add.
Definition: cs_cdo_toolbox.c:628
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:605
void cs_index_free(cs_connect_index_t **pidx)
Destroy a cs_connect_index_t structure.
Definition: cs_cdo_toolbox.c:247
cs_locmat_t * cs_locmat_free(cs_locmat_t *lm)
Free a cs_locmat_t structure.
Definition: cs_cdo_toolbox.c:518
cs_real_t cs_euclidean_norm(int len, const cs_real_t 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:84
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:354
void cs_dump_integer_to_listing(const char *header, const cs_lnum_t size, const cs_lnum_t array[], int n_cols)
Dump an array in the listing (For DEBUG)
Definition: cs_cdo_toolbox.c:790
bool owner
Definition: cs_cdo_toolbox.h:54
void cs_locmat_asymm(cs_locmat_t *loc)
Set the given matrix into its anti-symmetric part.
Definition: cs_cdo_toolbox.c:695
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:276
cs_lnum_t * ids
Definition: cs_cdo_toolbox.h:67
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:293
#define END_C_DECLS
Definition: cs_defs.h:452
int * ids
Definition: cs_cdo_toolbox.h:57
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:405
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:222
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:544
double precision, dimension(:,:,:), allocatable nc
Definition: atimbr.f90:110
Definition: cs_cdo_toolbox.h:63
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:652