8.3
general documentation
cs_rotation.h
Go to the documentation of this file.
1#ifndef __CS_ROTATION_H__
2#define __CS_ROTATION_H__
3
4/*============================================================================
5 * Rotation modeling features.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2024 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
30/*----------------------------------------------------------------------------
31 * Standard C library headers
32 *----------------------------------------------------------------------------*/
33
34#include "cs_defs.h"
35
36/*----------------------------------------------------------------------------*/
37
39
40/*=============================================================================
41 * Local Type Definitions
42 *============================================================================*/
43
44/* Rotation structure */
45
46typedef struct {
47
48 double omega;
49 double angle;
50 double axis[3];
51 double invariant[3];
52
54
55/*============================================================================
56 * Global variables
57 *============================================================================*/
58
60
61/*============================================================================
62 * Public function prototypes
63 *============================================================================*/
64
65/*----------------------------------------------------------------------------
66 * Define a global rotation.
67 *
68 * The rotation vector's length determines the angular velocity (in rad/s).
69 *
70 * parameters:
71 * omega_x <-- rotation vector x component
72 * omega_y <-- rotation vector y component
73 * omega_z <-- rotation vector z component
74 * invariant_x <-- invariant point x component
75 * invariant_y <-- invariant point y component
76 * invariant_z <-- invariant point z component
77 *----------------------------------------------------------------------------*/
78
79void
80cs_rotation_define(double omega_x,
81 double omega_y,
82 double omega_z,
83 double invariant_x,
84 double invariant_y,
85 double invariant_z);
86
87/*----------------------------------------------------------------------------
88 * Compute rotation matrix
89 *
90 * parameters:
91 * theta <-- rotation angle, in radians
92 * axis <-- rotation axis direction vector
93 * invariant_point <-- invariant point coordinates
94 * matrix -> resulting rotation matrix
95 *---------------------------------------------------------------------------*/
96
97void
99 const double axis[3],
100 const double invariant_point[3],
101 double matrix[3][4]);
102
103/*----------------------------------------------------------------------------
104 * Update coordinates based on a global rotation and time.
105 *
106 * parameters:
107 * n_coords <-- number of coordinates
108 * t_rot <-- time since rotation start
109 * coords <-> coordinates array
110 *----------------------------------------------------------------------------*/
111
112void
114 double t_rot,
115 cs_real_3_t coords[]);
116
117/*----------------------------------------------------------------------------
118 * Compute rotation velocity relative to fixed coordinates at a given point.
119 *
120 * parameters:
121 * r <-- pointer to rotation structure
122 * coords <-- coordinates at point
123 * vr --> relative velocity
124 *---------------------------------------------------------------------------*/
125
126static inline void
128 const cs_real_t coords[3],
129 cs_real_t vr[3])
130{
131 vr[0] = (- r->axis[2] * (coords[1] - r->invariant[1])
132 + r->axis[1] * (coords[2] - r->invariant[2])) * r->omega;
133 vr[1] = ( r->axis[2] * (coords[0] - r->invariant[0])
134 - r->axis[0] * (coords[2] - r->invariant[2])) * r->omega;
135 vr[2] = (- r->axis[1] * (coords[0] - r->invariant[0])
136 + r->axis[0] * (coords[1] - r->invariant[1])) * r->omega;
137}
138
139/*----------------------------------------------------------------------------
140 * Add a Coriolis term to a vector.
141 *
142 * parameters:
143 * r <-- pointer to rotation structure
144 * c <-- multiplicative coefficient
145 * v <-- velocity
146 * vr <-> vector to which Coriolis term is added
147 *---------------------------------------------------------------------------*/
148
149CS_F_HOST_DEVICE static inline void
151 cs_real_t c,
152 const cs_real_t v[3],
153 cs_real_t vr[3])
154{
155 double f = r->omega * c;
156
157 vr[0] += (- r->axis[2]*v[1] + r->axis[1]*v[2]) * f;
158 vr[1] += (- r->axis[0]*v[2] + r->axis[2]*v[0]) * f;
159 vr[2] += (- r->axis[1]*v[0] + r->axis[0]*v[1]) * f;
160}
161
162/*----------------------------------------------------------------------------
163 * Compute a vector Coriolis term.
164 *
165 * parameters:
166 * r <-- pointer to rotation structure
167 * c <-- multiplicative coefficient
168 * v <-- velocity
169 * vr --> vector associted to Coriolis term
170 *---------------------------------------------------------------------------*/
171
172static inline void
174 cs_real_t c,
175 const cs_real_t v[3],
176 cs_real_t vr[3])
177{
178 double f = r->omega * c;
179
180 vr[0] = (- r->axis[2]*v[1] + r->axis[1]*v[2]) * f;
181 vr[1] = (- r->axis[0]*v[2] + r->axis[2]*v[0]) * f;
182 vr[2] = (- r->axis[1]*v[0] + r->axis[0]*v[1]) * f;
183}
184
185/*----------------------------------------------------------------------------
186 * Add the dual tensor of a rotation vector to a tensor
187 * The dual tensor is such that:
188 * tr[i][j] * v[j] = (omage ^ v)_(ij)
189 *
190 * parameters:
191 * r <-- pointer to rotation structure
192 * c <-- multiplicative coefficient
193 * tr <-> tensor to which dual tensor of rotation is added
194 *---------------------------------------------------------------------------*/
195
196CS_F_HOST_DEVICE static inline void
198 cs_real_t c,
199 cs_real_t tr[3][3])
200{
201 double f = r->omega * c;
202
203 tr[0][1] -= r->axis[2]*f;
204 tr[0][2] += r->axis[1]*f;
205
206 tr[1][0] += r->axis[2]*f;
207 tr[1][2] -= r->axis[0]*f;
208
209 tr[2][0] -= r->axis[1]*f;
210 tr[2][1] += r->axis[0]*f;
211}
212
213/*----------------------------------------------------------------------------
214 * Compute the dual tensor of a rotation vector
215 * The dual tensor is such that:
216 * tr[i][j] * v[j] = (omage ^ v)_(ij)
217 *
218 * parameters:
219 * r <-- pointer to rotation structure
220 * c <-- multiplicative coefficient
221 * tr --> dual tensor of rotation
222 *---------------------------------------------------------------------------*/
223
224CS_F_HOST_DEVICE static inline void
226 cs_real_t c,
227 cs_real_t tr[3][3])
228{
229 double f = r->omega * c;
230
231 tr[0][0] = 0.;
232 tr[0][1] = - r->axis[2]*f;
233 tr[0][2] = r->axis[1]*f;
234
235 tr[1][0] = r->axis[2]*f;
236 tr[1][1] = 0.;
237 tr[1][2] = - r->axis[0]*f;
238
239 tr[2][0] = - r->axis[1]*f;
240 tr[2][1] = r->axis[0]*f;
241 tr[2][2] = 0.;
242}
243
244/*----------------------------------------------------------------------------*/
253/*----------------------------------------------------------------------------*/
254
255void
257 const cs_real_t coords[3],
258 const cs_real_t v[3],
259 cs_real_t vc[3]);
260
261/*----------------------------------------------------------------------------
262 * Copy rotation structure values to an array
263 *
264 * This may be useful to avoid requiring specific type mappings for MPI or
265 * other programming languages.
266 *
267 * parameters:
268 * r_num <-- rotation number (1 to n numbering, 0 for none)
269 * fra --> flat rotation array: axis (0-2), invariant(3-5),
270 * omega (6), angle(7)
271 *---------------------------------------------------------------------------*/
272
273void
274cs_rotation_to_array(int r_num,
275 cs_real_t fra[8]);
276
277/*----------------------------------------------------------------------------*/
278
280
281#endif /* __CS_ROTATION_H__ */
#define BEGIN_C_DECLS
Definition: cs_defs.h:542
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:561
double cs_real_t
Floating-point value.
Definition: cs_defs.h:342
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:359
#define END_C_DECLS
Definition: cs_defs.h:543
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:335
void cs_rotation_cyl_v(const cs_rotation_t *r, const cs_real_t coords[3], const cs_real_t v[3], cs_real_t vc[3])
Express a vector in the cyclindrical system associated to a rotation.
Definition: cs_rotation.cpp:376
void cs_rotation_matrix(double theta, const double axis[3], const double invariant_point[3], double matrix[3][4])
Compute rotation matrix.
Definition: cs_rotation.cpp:256
cs_rotation_t * cs_glob_rotation
void cs_rotation_define(double omega_x, double omega_y, double omega_z, double invariant_x, double invariant_y, double invariant_z)
Define a global rotation.
Definition: cs_rotation.cpp:219
static void cs_rotation_velocity(const cs_rotation_t *r, const cs_real_t coords[3], cs_real_t vr[3])
Compute velocity relative to a fixed frame at a given point.
Definition: cs_rotation.h:127
static void cs_rotation_coriolis_v(const cs_rotation_t *r, cs_real_t c, const cs_real_t v[3], cs_real_t vr[3])
Compute a vector Coriolis term.
Definition: cs_rotation.h:173
static CS_F_HOST_DEVICE void cs_rotation_add_coriolis_t(const cs_rotation_t *r, cs_real_t c, cs_real_t tr[3][3])
Add the dual tensor of a rotation vector to a tensor.
Definition: cs_rotation.h:197
void cs_rotation_to_array(int r_num, cs_real_t fra[8])
Copy rotation structure values to an array.
Definition: cs_rotation.cpp:431
void cs_rotation_update_coords(cs_lnum_t n_coords, double t_rot, cs_real_3_t coords[])
Update coordinates based on a global rotation and time.
Definition: cs_rotation.cpp:346
static CS_F_HOST_DEVICE void cs_rotation_coriolis_t(const cs_rotation_t *r, cs_real_t c, cs_real_t tr[3][3])
Compute the dual tensor of a rotation vector.
Definition: cs_rotation.h:225
static CS_F_HOST_DEVICE void cs_rotation_add_coriolis_v(const cs_rotation_t *r, cs_real_t c, const cs_real_t v[3], cs_real_t vr[3])
Add a Coriolis term to a vector.
Definition: cs_rotation.h:150
double precision, dimension(:,:,:), allocatable theta
Definition: atimbr.f90:122
double precision, dimension(:,:,:), allocatable v
Definition: atimbr.f90:113
Subdomain rotation description.
Definition: cs_rotation.h:46
double axis[3]
Definition: cs_rotation.h:50
double angle
Definition: cs_rotation.h:49
double invariant[3]
Definition: cs_rotation.h:51
double omega
Definition: cs_rotation.h:48