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