9.1
general documentation
cs_defs.h
Go to the documentation of this file.
1#ifndef __CS_DEFS_H__
2#define __CS_DEFS_H__
3
4/*============================================================================
5 * Base macro and typedef definitions for system portability
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2025 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 * Autoconf-defined macros
32 *============================================================================*/
33
34#if defined(HAVE_CONFIG_H)
35# include "base/cs_config.h"
36#endif
37
38#ifdef __cplusplus
39#include <type_traits>
40#endif
41
42/*============================================================================
43 * Internationalization
44 *============================================================================*/
45
46#ifdef __cplusplus
47extern "C" {
48#if 0
49} /* Fake brace to force Emacs auto-indentation back to column 0 */
50#endif
51#endif /* __cplusplus */
52
53#if defined(ENABLE_NLS) && defined(HAVE_GETTEXT)
54
55# include <libintl.h>
56# define _(String) dgettext(PACKAGE, String)
57# ifdef gettext_noop
58# define N_(String) gettext_noop(String)
59# else
60# define N_(String) String
61# endif /* gettext_noop */
62
63#else
64
65# define _LIBINTL_H /* Prevent inclusion of <libintl.h> by other files
66 with incorrect or missing checks;
67 TODO locate files causing issues to avoid
68 requiring this workaround */
70# define _(String) (String)
71# define N_(String) String
72# define textdomain(String) (String)
73# define gettext(String) (String)
74# define dgettext(Domain,String) (String)
75# define dcgettext(Domain,String,Type) (String)
76# define bindtextdomain(Domain, Directory) (Domain)
77
78#endif /* ENABLE_NLS && HAVE_GETTEXT */
79
80#ifdef __cplusplus
81}
82#endif /* __cplusplus */
83
84/*============================================================================
85 * Parallelism
86 *============================================================================*/
87
88#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
89
90# include <mpi.h>
91
92# if !defined(MPI_VERSION) /* Defined in up-to-date MPI versions */
93# define MPI_VERSION 1
94# endif
95
96# if MPI_VERSION == 1
97# define MPI_Info int
98# define MPI_INFO_NULL 0
99# endif
100
101#endif
102
103#if defined(HAVE_OPENMP)
104
105# include <omp.h>
106
107#if _OPENMP >= 201307 /* simd construct available from OpenMP 4.0 */
108#undef HAVE_OPENMP_SIMD
109#define HAVE_OPENMP_SIMD 1
110#endif
111
112#endif
113
114/* Do we have accelerator support ? */
115
116#if defined(HAVE_CUDA)
117#define HAVE_ACCEL 1
118#elif defined(HAVE_SYCL)
119#define HAVE_ACCEL 1
120#elif defined(HAVE_OPENMP_TARGET)
121#define HAVE_ACCEL 1
122#endif
123
124/*============================================================================
125 * C99 Qualifiers
126 *============================================================================*/
127
128#ifndef __cplusplus /* C */
129
130/* inline provided by cs_config.h if necessary */
131
132#if !defined(__STDC_VERSION__)
133# define __STDC_VERSION__ 1989
134#endif
135
136/*
137 * Redefinition of "inline" et "restrict" qualifiers incompatible with
138 * some C89 compilers (standard in C99)
139 */
140
141#if (__STDC_VERSION__ < 199901L)
142
143# if defined(__GNUC__)
144# define inline __inline__
145# define restrict __restrict__
146# else
147# define inline
148# define restrict
149# endif
150
151#endif
152
153#else /* C++ */
154
155# if defined(__GNUC__) || defined(__clang__) || defined (__NVCC__)
156# define restrict __restrict__
157# elif defined(_MSC_VER)
158# define restrict __restrict
159# else
160# ifndef HAVE_RESTRICT /* Must be provided by caller */
161# define restrict
162# endif
163# endif
164
165#endif /* __cplusplus */
166
167/* Definition of a DEPRECATED decorator which may be called in the code */
168
169#if defined(__GNUC__) || defined(__clang__)
170# define DEPRECATED __attribute__((deprecated))
171#elif defined(_MSC_VER)
172# define DEPRECATED __declspec(deprecated)
173#else
174# define DEPRECATED
175#endif
176
177/*============================================================================
178 * Definitions that may not always be provided directly by the system
179 *============================================================================*/
180
181/*
182 * Obtain definitions such as that of size_t through stddef.h (C99 standard)
183 * if available (preferred method), or through stdlib.h (which defines
184 * malloc() and family and so must define size_t some way) otherwise.
185 */
186
187#if HAVE_STDDEF_H
188# include <stddef.h>
189#else
190# include <stdlib.h>
191#endif
192
193/*
194 * Usually stdint.h is included by inttypes.h, but only inttypes.h exists
195 * on certain systems, such as Tru64Unix.
196 */
197
198#if HAVE_STDINT_H
199# include <stdint.h>
200#elif HAVE_INTTYPES_H
201# include <inttypes.h>
202#endif
203
204/*
205 * Obtain the definition of off_t.
206 */
207
208#if defined(HAVE_SYS_TYPES_H)
209#include <sys/types.h>
210#endif
211
212/* C99 _Bool type */
213
214#if HAVE_STDBOOL_H
215# include <stdbool.h>
216#else
217# ifndef __cplusplus
218# ifndef HAVE__BOOL
219# define _Bool signed char;
220# endif
221# define bool _Bool
222# define false 0
223# define true 1
224# else
225# define _Bool bool;
226# endif
227# define __bool_true_false_are_defined 1
228#endif
229
230/* C++ assert necessary for template */
231#if defined(__cplusplus)
232#include <typeinfo>
233#include "assert.h"
234#endif
235
236/* int32_t type */
237
238#if !defined(HAVE_INT32_T)
239# if (SIZEOF_INT == 4)
240typedef int int32_t;
241# elif (SIZEOF_SHORT == 4)
242typedef short int32_t;
243# else
244# error
245# endif
246#endif
247
248/* int64_t type */
249
250#if !defined(HAVE_INT64_T)
251# if (SIZEOF_INT == 8)
252typedef int int64_t;
253# elif (SIZEOF_LONG == 8)
254typedef long int64_t;
255# elif (HAVE_LONG_LONG == 8) /* SIZEOF_LONG_LONG not generally available */
256typedef long long int64_t;
257# else
258# error
259# endif
260#endif
261
262/* uint32_t type */
263
264#if !defined(HAVE_UINT32_T)
265# if (SIZEOF_INT == 4)
266typedef unsigned uint32_t;
267# elif (SIZEOF_SHORT == 4)
268typedef unsigned short uint32_t;
269# else
270# error
271# endif
272#endif
273
274/* uint64_t type */
275
276#if !defined(HAVE_UINT64_T)
277# if (SIZEOF_INT == 8)
278typedef unsigned uint64_t;
279# elif (SIZEOF_LONG == 8)
280typedef unsigned long uint64_t;
281# elif (HAVE_LONG_LONG) /* SIZEOF_LONG_LONG not generally available */
282typedef unsigned long long uint64_t;
283# else
284# error
285# endif
286#endif
287
288/* __has_builtin is missing in some cases (e.g. nvcc) */
289
290#ifndef __has_builtin
291 #define __has_builtin(x) 0
292#endif
293
294/* Legacy Intel compiler (retired) reports having
295 * __builtin_FILE() and __builtin_LINE() but generates code calling
296 * nonexisting functions with those names, leading to link errors. */
297#if defined(__INTEL_COMPILER)
298# if __INTEL_COMPILER <= 2000
299# define __has_builtin(x) 0
300# endif
301#endif
302
303/*============================================================================
304 * General types and macros used throughout code_saturne
305 *============================================================================*/
306
307#ifdef __cplusplus
308extern "C" {
309#if 0
310} /* Fake brace to force Emacs auto-indentation back to column 0 */
311#endif
312#endif /* __cplusplus */
313
314/*----------------------------------------------------------------------------
315 * Variable value type.
316 *----------------------------------------------------------------------------*/
318typedef enum {
320 CS_DATATYPE_NULL, /* empty datatype */
321 CS_CHAR, /* character values */
322 CS_FLOAT, /* 4-byte floating point values */
323 CS_DOUBLE, /* 8-byte floating point values */
324 CS_UINT16, /* 2-byte unsigned integer values */
325 CS_INT32, /* 4-byte signed integer values */
326 CS_INT64, /* 8-byte signed integer values */
327 CS_UINT32, /* 4-byte unsigned integer values */
328 CS_UINT64 /* 8-byte unsigned integer values */
329
331
332/*----------------------------------------------------------------------------
333 * Basic types used by code_saturne
334 * They may be modified here to better map to a given library, with the
335 * following constraints:
336 * - cs_lnum_t must be signed
337 * - cs_gnum_t may be signed or unsigned
338 *----------------------------------------------------------------------------*/
339
340/* Global integer index or number */
341
342#if defined(HAVE_LONG_GNUM)
343 typedef uint64_t cs_gnum_t;
344#else
345 typedef unsigned cs_gnum_t;
346#endif
347
348/* Local integer index or number */
349
350#if defined(HAVE_LONG_LNUM)
351 typedef int64_t cs_lnum_t;
352#else
353 typedef int cs_lnum_t;
354#endif
356/* Other types */
358typedef double cs_coord_t; /* Real number (coordinate value) */
360typedef double cs_real_t; /* Fortran double precision */
361typedef char cs_byte_t; /* Byte (untyped memory unit) */
362typedef unsigned short int cs_flag_t; /* Flag storing metadata */
364typedef double cs_nreal_t; /* Real number (normalized value) */
365typedef double cs_dreal_t; /* Local distance */
366typedef double cs_rreal_t; /* Reconstruction distance */
368/* Vector or array block types */
369
370typedef cs_lnum_t cs_lnum_2_t[2]; /* Vector of 2 local numbers */
371typedef cs_lnum_t cs_lnum_3_t[3]; /* Vector of 3 local numbers */
372
373typedef cs_coord_t cs_coord_3_t[3]; /* Vector of 3 real (coordinate)
374 values */
376typedef cs_real_t cs_real_2_t[2]; /* Vector of 2 real values */
377typedef cs_real_t cs_real_3_t[3]; /* Vector of 3 real values */
378typedef cs_real_t cs_real_4_t[4]; /* Vector of 4 real values */
379typedef cs_real_t cs_real_6_t[6]; /* Vector of 6 real values
380 (for symmetric tensor) */
381typedef cs_real_t cs_real_9_t[9]; /* Vector of 9 real values */
382typedef cs_real_t cs_real_10_t[10]; /* Vector of 10 real values */
384typedef cs_real_t cs_real_23_t[2][3]; /* Matrix of 2x3 real values */
386typedef cs_real_t cs_real_33_t[3][3]; /* Matrix of 3x3 real values */
387typedef cs_real_t cs_real_66_t[6][6]; /* Matrix of 6x6 real values */
388typedef cs_real_t cs_real_99_t[9][9]; /* Matrix of 9x9 real values */
390typedef cs_real_t cs_real_333_t[3][3][3]; /* tensor of 3x3x3 real values */
392typedef cs_real_t cs_real_34_t[3][4]; /* Matrix of 3x4 real values */
394typedef cs_real_t cs_real_63_t[6][3]; /* Matrix of 6x3 real values */
396typedef cs_real_t cs_real_69_t[6][9]; /* Matrix of 6x9 real values */
398typedef cs_real_33_t cs_real_332_t[2]; /* vector of 2 3x3 matrices
399 of real values */
400typedef cs_real_66_t cs_real_662_t[2]; /* vector of 2 6x6 matrices
401 of real values */
403typedef cs_nreal_t cs_nreal_3_t[3]; /* Vector of normalized real values
404 (i.e. unit vector) */
405typedef cs_dreal_t cs_dreal_3_t[3]; /* Vector joining 2 local coordinates */
406typedef cs_rreal_t cs_rreal_3_t[3]; /* Reconstruction distance Vector */
408typedef struct {
409
410 double val; /* Value */
411 int id; /* Id related to value */
412
414
415/* Vector-valued quantity stored using its measure (i.e. length) and
416 its direction given by a unitary vector */
418typedef struct {
419
420 double meas;
421 double unitv[3];
422
423} cs_nvec3_t;
424
425/* Mappings to MPI datatypes */
426/*---------------------------*/
427
428#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
429
430# define CS_MPI_REAL MPI_DOUBLE /* If cs_real_t is a double */
431
432/* MPI type for cs_gnum_t integer type (depends on configuration) */
433
434# if defined(HAVE_LONG_GNUM)
435# if (SIZEOF_LONG == 8)
436# define CS_MPI_GNUM MPI_UNSIGNED_LONG
437# elif (SIZEOF_LONG_LONG == 8)
438# if defined(MPI_UNSIGNED_LONG_LONG)
439# define CS_MPI_GNUM MPI_UNSIGNED_LONG_LONG
440# elif defined(MPI_LONG_LONG)
441# define CS_MPI_GNUM MPI_LONG_LONG
442# endif
443# endif
444# if !defined(CS_MPI_GNUM)
445# error
446# endif
447# else
448# define CS_MPI_GNUM MPI_UNSIGNED
449# endif
450
451/* MPI type for cs_lnum_t type */
452
453# if defined(HAVE_LONG_LNUM)
454# define CS_MPI_LNUM MPI_LONG
455# else
456# define CS_MPI_LNUM MPI_INT
457# endif
458
459# define CS_MPI_EFLAG MPI_UNSIGNED /* MPI type for cs_mflag_t type */
460# define CS_MPI_FLAG MPI_UNSIGNED_SHORT /* MPI type for cs_flag_t type */
461# define CS_MPI_COORD MPI_DOUBLE /* MPI type for cs_coord_t type */
462
463#endif /* defined(HAVE_MPI) && !defined(CS_IGNORE_MPI) */
464
465/* Mappings to code_saturne datatypes */
466/*------------------------------------*/
467
468#if defined(HAVE_LONG_GNUM)
469# define CS_GNUM_TYPE CS_UINT64
470#elif (SIZEOF_INT == 8)
471# define CS_GNUM_TYPE CS_UINT64
472#else
473# define CS_GNUM_TYPE CS_UINT32
474#endif
475
476#if defined(HAVE_LONG_LNUM)
477# if (SIZEOF_LONG == 8)
478# define CS_LNUM_TYPE CS_INT64
479# else
480# define CS_LNUM_TYPE CS_INT32
481# endif
482#else
483# if (SIZEOF_INT == 8)
484# define CS_LNUM_TYPE CS_INT64
485# else
486# define CS_LNUM_TYPE CS_INT32
487# endif
488#endif
489
490#if (SIZEOF_INT == 8)
491# define CS_INT_TYPE CS_INT64
492#else
493# define CS_INT_TYPE CS_INT32
494#endif
495
496#if (SIZEOF_INT == 8)
497# define CS_UINT_TYPE CS_UINT64
498#else
499# define CS_UINT_TYPE CS_UINT32
500#endif
502#define CS_FLAG_TYPE CS_UINT16
503#define CS_EFLAG_TYPE CS_UINT_TYPE
504#define CS_REAL_TYPE CS_DOUBLE
505#define CS_COORD_TYPE CS_DOUBLE
506
507/* Minimum size for OpenMP loops
508 * (will need benchmarking and tuning for various systems)
509 *---------------------------------------------------------*/
510
511#define CS_THR_MIN 128
512
513/* Cache line size, or multiple thereof */
514/*--------------------------------------*/
515
516#define CS_CL_SIZE 64
517
518/*----------------------------------------------------------------------------
519 * Type independent min an max (caution: the argument is evaluated)
520 *----------------------------------------------------------------------------*/
522#define CS_ABS(a) ((a) < 0 ? -(a) : (a))
523#define CS_MIN(a,b) ((a) < (b) ? (a) : (b))
524#define CS_MAX(a,b) ((a) > (b) ? (a) : (b))
526/*----------------------------------------------------------------------------
527 * Variable interlace type:
528 * {x1, y1, z1, x2, y2, z2, ...,xn, yn, zn} if interlaced
529 * {x1, x2, ..., xn, y1, y2, ..., yn, z1, z2, ..., zn} if non interlaced
530 *----------------------------------------------------------------------------*/
532typedef enum {
533
534 CS_INTERLACE, /* Variable is interlaced */
535 CS_NO_INTERLACE /* Variable is not interlaced */
536
538
539/*----------------------------------------------------------------------------
540 * Macro used to silence "unused argument" warnings.
541 *
542 * This is useful when a function must match a given function pointer
543 * type, but does not use all possible arguments.
544 *----------------------------------------------------------------------------*/
545
546#define CS_UNUSED(x) (void)(x)
547#define CS_NO_WARN_IF_UNUSED(x) (void)(x)
548
549/*----------------------------------------------------------------------------
550 * Macros for compilation with a C++ compiler
551 *----------------------------------------------------------------------------*/
552
553#undef BEGIN_C_DECLS
554#undef END_C_DECLS
556#if defined(__cplusplus)
557# define BEGIN_C_DECLS extern "C" {
558# define END_C_DECLS }
559#else
560# define BEGIN_C_DECLS
561# define END_C_DECLS
562#endif
563
564/*----------------------------------------------------------------------------
565 * Macro to check if we are compiling for device
566 *----------------------------------------------------------------------------*/
567
568#if defined(__CUDA_ARCH__) || defined(__HIP_DEVICE_COMPILE__) \
569 || defined(__SYCL_DEVICE_ONLY__)
570#define CS_DEVICE_COMPILE
571#endif
572
573/*----------------------------------------------------------------------------
574 * Macros for function type qualifiers
575 *----------------------------------------------------------------------------*/
576
577#ifdef __CUDACC__
578
579#define CS_F_HOST __host__
580#define CS_F_DEVICE __device__
581#define CS_F_HOST_DEVICE __host__ __device__
582#define CS_V_CONSTANT __constant__
584#else
586#define CS_F_HOST
587#define CS_F_DEVICE
588#define CS_F_HOST_DEVICE
589#define CS_V_CONSTANT static const
590
591#endif
592
593/*----------------------------------------------------------------------------
594 * Macros for lambda specifiers
595 *----------------------------------------------------------------------------*/
597#define CS_LAMBDA [=] CS_F_HOST_DEVICE
598#define CS_HOST_LAMBDA [=] CS_F_HOST
599#define CS_CLASS_LAMBDA [=, *this] CS_F_HOST_DEVICE
600
601/*=============================================================================
602 * Global variables
603 *============================================================================*/
604
605/* Empty but non-null string */
606
607extern const char cs_empty_string[];
608
609/* Sizes and names associated with datatypes */
610
611extern const size_t cs_datatype_size[];
612extern const char *cs_datatype_name[];
613
614/* MPI Datatypes associated with code_saturne datatypes */
615
616#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
617
618extern MPI_Datatype cs_datatype_to_mpi[];
619
620#endif
621
622/* Global variables indicating task state */
623
624extern int cs_glob_n_threads; /* Number of threads */
625
626extern int cs_glob_rank_id; /* Rank in main MPI communicator */
627extern int cs_glob_n_ranks; /* Size of main MPI communicator */
628
629extern int cs_glob_node_rank_id; /* Rank on node in main MPI communicator */
630extern int cs_glob_node_n_ranks; /* Number of ranks on node of main
631 MPI communicator */
632
633#if defined(HAVE_MPI) && !defined(CS_IGNORE_MPI)
634
635extern MPI_Comm cs_glob_mpi_comm; /* Main MPI intra-communicator */
636
637#endif
638
639/*----------------------------------------------------------------------------
640 * Function pointer types
641 *----------------------------------------------------------------------------*/
642
643/*----------------------------------------------------------------------------*/
651/*----------------------------------------------------------------------------*/
652
653typedef void *
654(cs_destructor_t)(void *s);
655
656/*=============================================================================
657 * Public functions
658 *============================================================================*/
659
660/*----------------------------------------------------------------------------*/
661/*
662 * \brief Given a base index i, return the next index aligned with a size m.
663 *
664 * \param[in] i base index
665 * \param[in] m block size to align with
666 *
667 * \return aligned index
668 */
669/*----------------------------------------------------------------------------*/
670
671inline static cs_lnum_t
673 cs_lnum_t m)
674{
675 return ((i > 0) ? ((i-1)/m+1)*m : 0);
676}
677
678/*----------------------------------------------------------------------------*/
685/*----------------------------------------------------------------------------*/
686
687inline static int
689{
690#if defined(HAVE_OPENMP)
691 return omp_get_thread_num();
692#else
693 return 0;
694#endif
695}
696
697/*----------------------------------------------------------------------------*/
698
699#ifdef __cplusplus
700}
701#endif /* __cplusplus */
702
703#ifdef __cplusplus
704
705/*=============================================================================
706 * Public C++ templates
707 *============================================================================*/
708
709namespace cs {
710
711/*----------------------------------------------------------------------------*/
712/*
713 * \brief Return absolute value of a number.
714 *
715 * This function is overloaded in cs_math.h for floating-point values.
716 *
717 * \tparam T value type
718 *
719 * \param[in] a value
720 *
721 * \return absolute value of a
722 */
723/*----------------------------------------------------------------------------*/
725template <typename T>
726CS_F_HOST_DEVICE inline T
727abs(const T a)
728{
729 return ((a) < 0 ? -(a) : (a));
730}
731
732/*----------------------------------------------------------------------------*/
733/*
734 * \brief Return minimum of two values.
735 *
736 * This function is overloaded in cs_math.h for floating-point values.
737 *
738 * \tparam T value type
739 *
740 * \param[in] a first value
741 * \param[in] b second value
742 *
743 * \return minimum of a and b
744 */
745/*----------------------------------------------------------------------------*/
747template <typename T>
748CS_F_HOST_DEVICE inline T
749min(const T a,
750 const T b)
751{
752 return ((a) < (b) ? (a) : (b));
753}
754
755/*----------------------------------------------------------------------------*/
756/*
757 * \brief Return maximum of two values.
758 *
759 * This function is overloaded in cs_math.h for floating-point values.
760 *
761 * \tparam T value type
762 *
763 * \param[in] a first value
764 * \param[in] b second value
765 *
766 * \return maximum of a and b
767 */
768/*----------------------------------------------------------------------------*/
770template <typename T>
771CS_F_HOST_DEVICE inline T
772max(const T a,
773 const T b)
774{
775 return ((a) > (b) ? (a) : (b));
776}
777
778/*----------------------------------------------------------------------------*/
779/*
780 * \brief Clamp function for a given scalar value.
781 *
782 * This function is overloaded in cs_math.h for floating-point values.
783 *
784 * \tparam T value type
785 *
786 * \param[in] x initial value
787 * \param[in] xmin min value for clamping
788 * \param[in] xmax max value for clamping
789 *
790 * \return clamped value which is 'x' if xmin < x < xmax or lower/upper bound
791 * otherwise
792 */
793/*----------------------------------------------------------------------------*/
795template <typename T>
796CS_F_HOST_DEVICE inline T
797clamp(const T x,
798 const T xmin,
799 const T xmax)
800{
801 T x_tmp = ((xmin) > (x) ? (xmin) : (x));
802 return ((xmax) < (x_tmp) ? (xmax) : (x_tmp));
803}
804
805/*----------------------------------------------------------------------------*/
809/*----------------------------------------------------------------------------*/
811template <class... Args>
812struct are_integral {
813 enum : bool { value = true};
814};
815
816/*----------------------------------------------------------------------------*/
817
818template <typename T, class... Args>
819struct are_integral<T, Args...> {
820 enum {
821 value = (std::is_integral<T>::value || std::is_enum<T>::value)
823 };
824};
825
826/*----------------------------------------------------------------------------*/
832/*----------------------------------------------------------------------------*/
833
834template <typename... Args>
835struct always_true : std::true_type {};
836
837/*----------------------------------------------------------------------------*/
838
839} // namespace cs
840
841/*----------------------------------------------------------------------------*/
847/*----------------------------------------------------------------------------*/
848
849template <typename T>
850struct dependent_false : std::false_type {};
852template <typename T>
853static inline cs_datatype_t
855{
856 static_assert(dependent_false<T>::value, "Unknown datatype");
857 return CS_DATATYPE_NULL;
858}
859
860/*----------------------------------------------------------------------------*/
861/* Specialized versions of the templated function */
862/*----------------------------------------------------------------------------*/
863
864template <>
865constexpr inline cs_datatype_t
867{
868 return CS_CHAR;
869}
870
871/*----------------------------------------------------------------------------*/
872
873template <>
874constexpr inline cs_datatype_t
876{
877 return CS_FLOAT;
878}
879
880/*----------------------------------------------------------------------------*/
881
882template <>
883constexpr inline cs_datatype_t
885{
886 return CS_DOUBLE;
887}
888
889/*----------------------------------------------------------------------------*/
890
891template <>
892constexpr inline cs_datatype_t
894{
895 return CS_UINT16;
896}
897
898/*----------------------------------------------------------------------------*/
899
900template <>
901constexpr inline cs_datatype_t
903{
904 return CS_UINT32;
905}
906
907/*----------------------------------------------------------------------------*/
908
909template <>
910constexpr inline cs_datatype_t
912{
913 return CS_UINT64;
914}
915
916/*----------------------------------------------------------------------------*/
917
918template <>
919constexpr inline cs_datatype_t
921{
922 return CS_INT32;
923}
924
925/*----------------------------------------------------------------------------*/
926
927template <>
928constexpr inline cs_datatype_t
930{
931 return CS_INT64;
932}
933
934/*----------------------------------------------------------------------------*/
935
936/*----------------------------------------------------------------------------*/
937
938#endif /* __cplusplus */
939
940/*----------------------------------------------------------------------------*/
941
942#endif /* __CS_DEFS_H__ */
int cs_glob_n_ranks
Definition: cs_defs.cpp:175
cs_datatype_t
Definition: cs_defs.h:315
@ CS_FLOAT
Definition: cs_defs.h:319
@ CS_CHAR
Definition: cs_defs.h:318
@ CS_UINT16
Definition: cs_defs.h:321
@ CS_INT64
Definition: cs_defs.h:323
@ CS_UINT64
Definition: cs_defs.h:325
@ CS_DOUBLE
Definition: cs_defs.h:320
@ CS_UINT32
Definition: cs_defs.h:324
@ CS_INT32
Definition: cs_defs.h:322
@ CS_DATATYPE_NULL
Definition: cs_defs.h:317
cs_lnum_t cs_lnum_3_t[3]
Definition: cs_defs.h:368
const char * cs_datatype_name[]
Definition: cs_defs.cpp:143
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:585
constexpr cs_datatype_t cs_datatype_from_type< int32_t >()
Definition: cs_defs.h:917
constexpr cs_datatype_t cs_datatype_from_type< uint16_t >()
Definition: cs_defs.h:890
char cs_byte_t
Definition: cs_defs.h:358
double cs_real_t
Floating-point value.
Definition: cs_defs.h:357
void *() cs_destructor_t(void *s)
Destroy a given structure.
Definition: cs_defs.h:651
cs_rreal_t cs_rreal_3_t[3]
Definition: cs_defs.h:403
constexpr cs_datatype_t cs_datatype_from_type< char >()
Definition: cs_defs.h:863
const size_t cs_datatype_size[]
Definition: cs_defs.cpp:133
static cs_datatype_t cs_datatype_from_type()
Definition: cs_defs.h:851
cs_real_33_t cs_real_332_t[2]
vector of 2 3x3 matrices of floating-point values
Definition: cs_defs.h:395
int cs_glob_node_rank_id
Definition: cs_defs.cpp:177
cs_real_t cs_real_69_t[6][9]
Definition: cs_defs.h:393
cs_nreal_t cs_nreal_3_t[3]
Definition: cs_defs.h:400
const char cs_empty_string[]
Definition: cs_defs.cpp:129
int cs_glob_n_threads
Definition: cs_defs.cpp:172
cs_lnum_t cs_lnum_2_t[2]
vector of 2 local mesh-entity ids
Definition: cs_defs.h:367
static int cs_get_thread_id(void)
Retrieve the associated thread id (0 if no OpenMP or if outside an OpenMP region)
Definition: cs_defs.h:685
int cs_glob_node_n_ranks
Definition: cs_defs.cpp:178
cs_real_t cs_real_4_t[4]
vector of 4 floating-point values
Definition: cs_defs.h:375
double cs_dreal_t
Definition: cs_defs.h:362
cs_real_t cs_real_10_t[10]
Definition: cs_defs.h:379
cs_real_t cs_real_99_t[9][9]
Definition: cs_defs.h:385
double cs_coord_t
Definition: cs_defs.h:355
cs_real_t cs_real_34_t[3][4]
Definition: cs_defs.h:389
cs_real_t cs_real_66_t[6][6]
6x6 matrix of floating-point values
Definition: cs_defs.h:384
cs_real_t cs_real_3_t[3]
vector of 3 floating-point values
Definition: cs_defs.h:374
cs_coord_t cs_coord_3_t[3]
Definition: cs_defs.h:370
cs_real_66_t cs_real_662_t[2]
Definition: cs_defs.h:397
cs_real_t cs_real_2_t[2]
vector of 2 floating-point values
Definition: cs_defs.h:373
unsigned cs_gnum_t
global mesh entity number
Definition: cs_defs.h:342
constexpr cs_datatype_t cs_datatype_from_type< int64_t >()
Definition: cs_defs.h:926
constexpr cs_datatype_t cs_datatype_from_type< float >()
Definition: cs_defs.h:872
cs_interlace_t
Definition: cs_defs.h:529
@ CS_INTERLACE
Definition: cs_defs.h:531
@ CS_NO_INTERLACE
Definition: cs_defs.h:532
cs_real_t cs_real_6_t[6]
vector of 6 floating-point values
Definition: cs_defs.h:376
static cs_lnum_t cs_align(cs_lnum_t i, cs_lnum_t m)
Given a base index i, return the next index aligned with a size m.
Definition: cs_defs.h:669
cs_dreal_t cs_dreal_3_t[3]
Definition: cs_defs.h:402
constexpr cs_datatype_t cs_datatype_from_type< double >()
Definition: cs_defs.h:881
cs_real_t cs_real_333_t[3][3][3]
Definition: cs_defs.h:387
double cs_rreal_t
Definition: cs_defs.h:363
constexpr cs_datatype_t cs_datatype_from_type< uint32_t >()
Definition: cs_defs.h:899
cs_real_t cs_real_33_t[3][3]
3x3 matrix of floating-point values
Definition: cs_defs.h:383
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:350
cs_real_t cs_real_63_t[6][3]
Definition: cs_defs.h:391
double cs_nreal_t
Definition: cs_defs.h:361
constexpr cs_datatype_t cs_datatype_from_type< uint64_t >()
Definition: cs_defs.h:908
cs_real_t cs_real_9_t[9]
Definition: cs_defs.h:378
cs_real_t cs_real_23_t[2][3]
Definition: cs_defs.h:381
unsigned short int cs_flag_t
Definition: cs_defs.h:359
int cs_glob_rank_id
Definition: cs_defs.cpp:174
Definition: cs_array.h:1098
CS_F_HOST_DEVICE T max(const T a, const T b)
Definition: cs_defs.h:769
CS_F_HOST_DEVICE T clamp(const T x, const T xmin, const T xmax)
Definition: cs_defs.h:794
CS_F_HOST_DEVICE T min(const T a, const T b)
Definition: cs_defs.h:746
CS_F_HOST_DEVICE T abs(const T a)
Definition: cs_defs.h:724
Utility template which returns "true" for a given pack. This is necessary of std::enable_if_t<> when ...
Definition: cs_defs.h:832
Utility template to check if a pack of parameters is made of integral types.
Definition: cs_defs.h:809
@ value
Definition: cs_defs.h:810
Definition: cs_defs.h:405
Definition: cs_defs.h:415
Get the cs_datatype_t from a typename.
Definition: cs_defs.h:847