TrioCFD 1.9.8
TrioCFD documentation
Loading...
Searching...
No Matches
Ecrire_CGNS_helper.h
1/****************************************************************************
2* Copyright (c) 2026, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15
16#ifndef Ecrire_CGNS_helper_included
17#define Ecrire_CGNS_helper_included
18
19#include <Option_CGNS.h>
20#include <TRUSTTab.h>
21#include <cgns++.h>
22#include <sstream>
23#include <iomanip>
24//#include <regex>
25
26#ifdef HAS_CGNS
27
28#pragma GCC diagnostic push
29#if __GNUC__ > 5 || __clang_major__ > 10
30#pragma GCC diagnostic ignored "-Wsuggest-override"
31#endif
32#ifdef MPI_
33#include <pcgnslib.h>
34#else
35#include <cgnslib.h>
36#endif
37#pragma GCC diagnostic pop
38
39#define CGNS_STR_SIZE 32
40/* #define CGNS_DOUBLE_TYPE CGNS_ENUMV(RealSingle) */
41#define CGNS_DOUBLE_TYPE CGNS_ENUMV(RealDouble)
42
43enum class TYPE_ECRITURE_CGNS { SEQ , PAR_IN, PAR_OVER };
44enum class TYPE_LINK_CGNS { GRID , SOLUTION, FINAL_LINK };
45enum class TYPE_MODE_CGNS { WRITE, MODIFY , READ };
46enum class TYPE_RUN_CGNS { SEQ, PAR };
47
48inline void TRUST_CGNS_ERROR()
49{
50#ifdef MPI_
51 Process::is_sequential() ? cg_error_exit() : cgp_error_exit();
52#else
54 cg_error_exit();
55 else
56 {
57 Cerr << "CGNS error: " << cg_get_error() << finl;
58 Process::exit(); /* OpenMP ?? */
59 }
60#endif
61}
62
63struct Ecrire_CGNS_helper
64{
65 template<TYPE_RUN_CGNS _TYPE_, TYPE_MODE_CGNS _MODE_ = TYPE_MODE_CGNS::WRITE>
66 inline void cgns_open_file(const std::string&, int&, const bool print = true);
67
68 template<TYPE_RUN_CGNS _TYPE_>
69 inline void cgns_close_file(const std::string&, const int, const bool print = true);
70
71 template<TYPE_ECRITURE_CGNS _TYPE_>
72 inline void cgns_write_zone_grid_coord(const int, const int, const int, const char*, const cgsize_t*, int&,
73 const std::vector<double>&, const std::vector<double>&, const std::vector<double>&, int&, int&, int&);
74
75 template<TYPE_ECRITURE_CGNS _TYPE_>
76 inline std::enable_if_t< _TYPE_ != TYPE_ECRITURE_CGNS::SEQ, void>
77 cgns_write_grid_coord_data(const int, const int, const int, const int, const int, const int, const int, const cgsize_t, const cgsize_t,
78 const std::vector<double>&, const std::vector<double>&, const std::vector<double>&);
79
80 template<TYPE_ECRITURE_CGNS _TYPE_>
81 inline void cgns_sol_write(const int, const int, const int, const int, const int, const std::vector<int>&,
82 const std::string&, std::string&, std::string&, std::string&,
83 bool&, bool&, bool&, int&, int&, int&);
84
85 template<TYPE_ECRITURE_CGNS _TYPE_>
86 inline std::enable_if_t< _TYPE_ != TYPE_ECRITURE_CGNS::SEQ, void>
87 cgns_field_write(const int, const int, const int, const int, const std::vector<int>&, const std::string&,
88 const int, const int, const int, const char*, int&, int&, int&);
89
90 template<TYPE_ECRITURE_CGNS _TYPE_>
91 inline std::enable_if_t<_TYPE_ == TYPE_ECRITURE_CGNS::SEQ, void>
92 cgns_field_write_data(const int, const int, const int, const std::vector<int>&, const std::string&,
93 const int, const int, const int, const int,
94 const char * , const DoubleTab& , int& , int& , int&);
95
96 template<TYPE_ECRITURE_CGNS _TYPE_>
97 inline std::enable_if_t<_TYPE_ != TYPE_ECRITURE_CGNS::SEQ, void>
98 cgns_field_write_data(const int, const int, const int, const std::vector<int>&, const std::string&,
99 const int, const int, const int, const int, const int, const int, const int,
100 const cgsize_t, const cgsize_t, const DoubleTab&);
101
102 template<TYPE_ECRITURE_CGNS _TYPE_>
103 inline void cgns_write_iters(const bool, const int, const int , const int, const int, const std::vector<int>&,
104 const std::string&, const std::string&, const std::string&, const std::string&,
105 const std::vector<double>&);
106
107 template<TYPE_ECRITURE_CGNS _TYPE_>
108 inline void cgns_write_iters_deformable(const bool, const bool, const int, const int , const int, const int, const std::vector<int>&,
109 const std::string&, const std::string&, const std::string&, const std::string&, const std::string&,
110 const std::vector<double>&);
111
112 /* helplers utiles pour les links ! */
113 inline void cgns_write_zone_and_classic_links(const bool write_zone, const int fileId, const int baseId, const std::string& zone_name_to_write, const cgsize_t *isize, int& zoneId,
114 const int zone_goto_id, const std::string& linkfile, const std::string& target_base_name, const std::string& target_zone_name,
115 const std::vector<std::string>& connect_names, const char *where, const bool write_connectivity = true);
116
117 inline void cgns_write_solution_classic_links(const std::string& base_linkfile, const std::string& target_base_name, const std::string& target_zone_name,
118 const std::string& LOC, const std::vector<double>& time_post, const char *where);
119
120 inline void cgns_write_zone_and_deformable_links(const bool write_zone, const bool has_field, const int fileId, const int baseId, const std::string& zone_name_to_write, const cgsize_t *isize, int& zoneId,
121 const int zone_goto_id, const std::string& file_prefix, const std::string& target_base_name, const std::string& target_zone_name,
122 const std::vector<std::string>& connect_names, const Nom& nom_dom, const std::string& LOC,
123 const std::vector<double>& time_post, const char *where, const bool write_connectivity = true);
124
125 inline void cgns_write_connectivity_deformable_links(const int fileId, const int baseId, const int zone_goto_id, const std::string& linkfile, const std::string& target_base_name,
126 const std::string& target_zone_name, const std::vector<std::string>& connect_names, const char *where);
127
128 std::string convert_double_to_string(const double t)
129 {
130 // On fait comme dans les latas !
131 char str_temps[100] = "0.0";
132 if (t >= 0.)
133 snprintf(str_temps, 100, "%.10f", t);
134
135 return std::string(str_temps);
136
137// Sinon je laisse cette belle methode au cas ou elle pourrait servir un jour !
138// /* KEEP GOOD PRECISION */
139// std::stringstream ss;
140// ss << std::fixed << std::setprecision(15) << t;
141//
142// std::string ret_str = ss.str();
143//
144// /* REMOVE USELESS 0s */
145// ret_str = std::regex_replace(ret_str, std::regex("([0-9]*\\.[0-9]*?[1-9])0+$"), "$1"); // remove useless 0s
146// ret_str = std::regex_replace(ret_str, std::regex("\\.0+$"), ""); // remove the final .0 if integer
147//
148// return ret_str;
149 }
150};
151
152#include <Ecrire_CGNS_helper.tpp>
153
154#endif /* HAS_CGNS */
155
156#endif /* Ecrire_CGNS_helper_included */
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Definition Process.cpp:455
static bool is_sequential()
Definition Process.cpp:115