16#ifndef Ecrire_CGNS_helper_tpp_included
17#define Ecrire_CGNS_helper_tpp_included
21template<TYPE_RUN_CGNS _TYPE_, TYPE_MODE_CGNS _MODE_>
22inline void Ecrire_CGNS_helper::cgns_open_file(
const std::string& fn,
int& fileId,
const bool is_print)
24 constexpr bool is_SEQ = (_TYPE_ == TYPE_RUN_CGNS::SEQ), is_WRITE = (_MODE_ == TYPE_MODE_CGNS::WRITE), is_MODIFY = (_MODE_ == TYPE_MODE_CGNS::MODIFY);
27 if (cg_open(fn.c_str(), is_WRITE ? CG_MODE_WRITE : ( is_MODIFY ? CG_MODE_MODIFY : CG_MODE_READ), &fileId) != CG_OK)
29 Cerr <<
"Error Ecrire_CGNS_helper::cgns_open_file : cg_open !" << finl;
34 Cerr <<
"**** CGNS file " << fn <<
" opened !" << finl;
39 if (cgp_open(fn.c_str(), is_WRITE ? CG_MODE_WRITE : ( is_MODIFY ? CG_MODE_MODIFY : CG_MODE_READ), &fileId) != CG_OK)
41 Cerr <<
"Error Ecrire_CGNS_helper::cgns_open_file : cgp_open !" << finl;
46 Cerr <<
"**** Parallel CGNS file " << fn <<
" opened !" << finl;
48 Cerr <<
"Parallel CGNS files need MPI installed ... " << finl;
54template<TYPE_RUN_CGNS _TYPE_>
55inline void Ecrire_CGNS_helper::cgns_close_file(
const std::string& fn,
const int fileId,
const bool is_print)
57 constexpr bool is_SEQ = (_TYPE_ == TYPE_RUN_CGNS::SEQ);
60 if (cg_close(fileId) != CG_OK)
62 Cerr <<
"Error Ecrire_CGNS_helper::cgns_close_file : cg_close !" << finl;
67 Cerr <<
"**** CGNS file " << fn <<
" closed !" << finl;
72 if (cgp_close(fileId) != CG_OK)
74 Cerr <<
"Error Ecrire_CGNS_helper::cgns_close_file : cgp_close !" << finl;
79 Cerr <<
"**** Parallel CGNS file " << fn <<
" closed !" << finl;
81 Cerr <<
"Parallel CGNS files need MPI installed ... " << finl;
87template<TYPE_ECRITURE_CGNS _TYPE_>
88inline void Ecrire_CGNS_helper::cgns_write_zone_grid_coord(
const int icelldim,
const int fileId,
const int baseId,
const char *zonename,
const cgsize_t *isize,
int& zoneId,
89 const std::vector<double>& xCoords,
const std::vector<double>& yCoords,
const std::vector<double>& zCoords,
90 int& coordsIdx,
int& coordsIdy,
int& coordsIdz)
92 constexpr bool is_SEQ = (_TYPE_ == TYPE_ECRITURE_CGNS::SEQ);
94 if (cg_zone_write(fileId, baseId, zonename, isize, CGNS_ENUMV(Unstructured), &zoneId) != CG_OK)
95 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_zone_grid_coord : cg_zone_write !" << finl, TRUST_CGNS_ERROR();
99 if (cg_coord_write(fileId, baseId, zoneId, CGNS_DOUBLE_TYPE,
"CoordinateX", xCoords.data(), &coordsIdx) != CG_OK)
100 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_zone_grid_coord : cg_coord_write - X !" << finl, TRUST_CGNS_ERROR();
102 if (cg_coord_write(fileId, baseId, zoneId, CGNS_DOUBLE_TYPE,
"CoordinateY", yCoords.data(), &coordsIdy) != CG_OK)
103 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_zone_grid_coord : cg_coord_write - Y !" << finl, TRUST_CGNS_ERROR();
106 if (cg_coord_write(fileId, baseId, zoneId, CGNS_DOUBLE_TYPE,
"CoordinateZ", zCoords.data(), &coordsIdz) != CG_OK)
107 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_zone_grid_coord : cg_coord_write - Z !" << finl, TRUST_CGNS_ERROR();
113 if (cg_grid_write(fileId, baseId, zoneId,
"GridCoordinates", &gridId) != CG_OK)
114 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_zone_grid_coord : cg_grid_write !" << finl, TRUST_CGNS_ERROR();
116 if (cgp_coord_write(fileId, baseId, zoneId, CGNS_DOUBLE_TYPE,
"CoordinateX", &coordsIdx) != CG_OK)
117 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_zone_grid_coord : cgp_coord_write - X !" << finl, TRUST_CGNS_ERROR();
119 if (cgp_coord_write(fileId, baseId, zoneId, CGNS_DOUBLE_TYPE,
"CoordinateY", &coordsIdy) != CG_OK)
120 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_zone_grid_coord : cgp_coord_write - Y !" << finl, TRUST_CGNS_ERROR();
123 if (cgp_coord_write(fileId, baseId, zoneId, CGNS_DOUBLE_TYPE,
"CoordinateZ", &coordsIdz) != CG_OK)
124 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_zone_grid_coord : cgp_coord_write - Z !" << finl, TRUST_CGNS_ERROR();
129template<TYPE_ECRITURE_CGNS _TYPE_>
130inline std::enable_if_t<_TYPE_ != TYPE_ECRITURE_CGNS::SEQ, void>
131Ecrire_CGNS_helper::cgns_write_grid_coord_data(
const int icelldim,
const int fileId,
const int baseId,
const int zoneId,
132 const int coordsIdx,
const int coordsIdy,
const int coordsIdz,
const cgsize_t min,
const cgsize_t max,
133 const std::vector<double>& xCoords,
const std::vector<double>& yCoords,
const std::vector<double>& zCoords)
136 if (cgp_coord_write_data(fileId, baseId, zoneId, coordsIdx, &min, &max, xCoords.data()) != CG_OK)
137 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_grid_coord_data : cgp_coord_write_data - X !" << finl, TRUST_CGNS_ERROR();
139 if (cgp_coord_write_data(fileId, baseId, zoneId, coordsIdy, &min, &max, yCoords.data()) != CG_OK)
140 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_grid_coord_data : cgp_coord_write_data - Y !" << finl, TRUST_CGNS_ERROR();
144 if (cgp_coord_write_data(fileId, baseId, zoneId, coordsIdz, &min, &max, zCoords.data()) != CG_OK)
145 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_grid_coord_data : cgp_coord_write_data - Z !" << finl, TRUST_CGNS_ERROR();
149template<TYPE_ECRITURE_CGNS _TYPE_>
150inline void Ecrire_CGNS_helper::cgns_sol_write(
const int nb_zones_to_write,
const int fileId,
const int baseId,
const int ind,
151 const int iteration,
const std::vector<int>& zoneId,
const std::string& LOC,
152 std::string& solname_som, std::string& solname_elem, std::string& solname_faces,
153 bool& solname_som_written,
bool& solname_elem_written,
bool& solname_faces_written,
154 int& flowId_som,
int& flowId_elem,
int& flowId_faces)
157 constexpr bool is_SEQ = (_TYPE_ == TYPE_ECRITURE_CGNS::SEQ), is_PAR_OVER = (_TYPE_ == TYPE_ECRITURE_CGNS::PAR_OVER);
158 std::string solname =
"FlowSolution_itr_" + std::to_string(iteration);
159 solname.resize(CGNS_STR_SIZE,
' ');
161 if (!solname_som_written && LOC ==
"SOM")
163 solname_som += solname;
166 for (
int ii = 0; ii != nb_zones_to_write; ii++)
168 if (cg_sol_write(fileId, baseId, zoneId[is_PAR_OVER ? ii : ind], solname.c_str(), CGNS_ENUMV(Vertex), &flowId_som) != CG_OK)
169 Cerr <<
"Error Ecrire_CGNS_helper::cgns_sol_write : cg_sol_write -- SOM !" << finl, TRUST_CGNS_ERROR();
172 if (cg_goto(fileId, baseId,
"Zone_t", zoneId[is_PAR_OVER ? ii : ind],
"FlowSolution_t", flowId_som,
"end") != CG_OK)
173 Cerr <<
"Error Ecrire_CGNS_helper::cgns_sol_write : cg_goto -- SOM !" << finl, TRUST_CGNS_ERROR();
177 solname_som_written =
true;
180 if (!solname_elem_written && LOC ==
"ELEM")
182 solname_elem += solname;
185 for (
int ii = 0; ii != nb_zones_to_write; ii++)
187 if (cg_sol_write(fileId, baseId, zoneId[is_PAR_OVER ? ii : ind], solname.c_str(), CGNS_ENUMV(CellCenter), &flowId_elem) != CG_OK)
188 Cerr <<
"Error Ecrire_CGNS_helper::cgns_sol_write : cg_sol_write -- ELEM !" << finl, TRUST_CGNS_ERROR();
191 if (cg_goto(fileId, baseId,
"Zone_t", zoneId[is_PAR_OVER ? ii : ind],
"FlowSolution_t", flowId_elem,
"end") != CG_OK)
192 Cerr <<
"Error Ecrire_CGNS_helper::cgns_sol_write : cg_goto -- ELEM !" << finl, TRUST_CGNS_ERROR();
196 solname_elem_written =
true;
199 if (!solname_faces_written && LOC ==
"FACES")
201 solname_faces += solname;
204 for (
int ii = 0; ii != nb_zones_to_write; ii++)
206 if (cg_sol_write(fileId, baseId, zoneId[is_PAR_OVER ? ii : ind], solname.c_str(), CGNS_ENUMV(CellCenter), &flowId_faces) != CG_OK)
207 Cerr <<
"Error Ecrire_CGNS_helper::cgns_sol_write : cg_sol_write -- FACES !" << finl, TRUST_CGNS_ERROR();
210 if (cg_goto(fileId, baseId,
"Zone_t", zoneId[is_PAR_OVER ? ii : ind],
"FlowSolution_t", flowId_faces,
"end") != CG_OK)
211 Cerr <<
"Error Ecrire_CGNS_helper::cgns_sol_write : cg_goto -- FACES !" << finl, TRUST_CGNS_ERROR();
215 solname_faces_written =
true;
219template<TYPE_ECRITURE_CGNS _TYPE_>
220inline std::enable_if_t<_TYPE_ != TYPE_ECRITURE_CGNS::SEQ, void>
221Ecrire_CGNS_helper::cgns_field_write(
const int nb_zones_to_write,
const int fileId,
const int baseId,
const int ind,
const std::vector<int>& zoneId,
const std::string& LOC,
222 const int flowId_som,
const int flowId_elem,
const int flowId_faces,
223 const char * id_champ,
int& fieldId_som,
int& fieldId_elem,
int& fieldId_faces)
226 constexpr bool is_PAR_OVER = (_TYPE_ == TYPE_ECRITURE_CGNS::PAR_OVER);
227 for (
int ii = 0; ii != nb_zones_to_write; ii++)
231 if (cgp_field_write(fileId, baseId, zoneId[is_PAR_OVER ? ii : ind], flowId_som, CGNS_DOUBLE_TYPE, id_champ, &fieldId_som) != CG_OK)
232 Cerr <<
"Error Ecrire_CGNS_helper::cgns_field_write : cgp_field_write -- SOM !" << finl, TRUST_CGNS_ERROR();
234 else if (LOC ==
"ELEM")
236 if (cgp_field_write(fileId, baseId, zoneId[is_PAR_OVER ? ii : ind], flowId_elem, CGNS_DOUBLE_TYPE, id_champ, &fieldId_elem) != CG_OK)
237 Cerr <<
"Error Ecrire_CGNS_helper::cgns_field_write : cgp_field_write -- ELEM !" << finl, TRUST_CGNS_ERROR();
239 else if (LOC ==
"FACES")
241 if (cgp_field_write(fileId, baseId, zoneId[is_PAR_OVER ? ii : ind], flowId_faces, CGNS_DOUBLE_TYPE, id_champ, &fieldId_faces) != CG_OK)
242 Cerr <<
"Error Ecrire_CGNS_helper::cgns_field_write : cgp_field_write -- FACES !" << finl, TRUST_CGNS_ERROR();
245 throw std::runtime_error(
"Ecrire_CGNS_helper::cgns_field_write => Unsupported LOC : " + LOC);
250template<TYPE_ECRITURE_CGNS _TYPE_>
251inline std::enable_if_t<_TYPE_ == TYPE_ECRITURE_CGNS::SEQ, void>
252Ecrire_CGNS_helper::cgns_field_write_data(
const int fileId,
const int baseId,
const int ind,
const std::vector<int>& zoneId,
253 const std::string& LOC,
const int flowId_som,
const int flowId_elem,
const int flowId_faces,
const int comp,
254 const char * id_champ,
const DoubleTab& valeurs,
int& fieldId_som,
int& fieldId_elem,
int& fieldId_faces)
260 if (cg_field_write(fileId, baseId, zoneId[ind], flowId_som, CGNS_DOUBLE_TYPE, id_champ, valeurs.
addr(), &fieldId_som) != CG_OK)
261 Cerr <<
"Error Ecrire_CGNS::cgns_write_field_seq : cg_field_write -- SOM !" << finl, TRUST_CGNS_ERROR();
263 else if (LOC ==
"ELEM")
265 if (cg_field_write(fileId, baseId, zoneId[ind], flowId_elem, CGNS_DOUBLE_TYPE, id_champ, valeurs.
addr(), &fieldId_elem) != CG_OK)
266 Cerr <<
"Error Ecrire_CGNS::cgns_write_field_seq : cg_field_write -- ELEM !" << finl, TRUST_CGNS_ERROR();
268 else if (LOC ==
"FACES")
270 if (cg_field_write(fileId, baseId, zoneId[ind], flowId_faces, CGNS_DOUBLE_TYPE, id_champ, valeurs.
addr(), &fieldId_faces) != CG_OK)
271 Cerr <<
"Error Ecrire_CGNS::cgns_write_field_seq : cg_field_write -- FACES !" << finl, TRUST_CGNS_ERROR();
274 throw std::runtime_error(
"Ecrire_CGNS_helper::cgns_field_write_data => Unsupported LOC : " + LOC);
279 DoubleTrav field_cgns(nb);
280 for (
int i = 0; i < nb; i++)
281 field_cgns(i) = valeurs(i, comp);
285 if (cg_field_write(fileId, baseId, zoneId[ind], flowId_som, CGNS_DOUBLE_TYPE, id_champ, field_cgns.addr(), &fieldId_som) != CG_OK)
286 Cerr <<
"Error Ecrire_CGNS::cgns_write_field_seq : cg_field_write -- SOM !" << finl, TRUST_CGNS_ERROR();
288 else if (LOC ==
"ELEM")
290 if (cg_field_write(fileId, baseId, zoneId[ind], flowId_elem, CGNS_DOUBLE_TYPE, id_champ, field_cgns.addr(), &fieldId_elem) != CG_OK)
291 Cerr <<
"Error Ecrire_CGNS::cgns_write_field_seq : cg_field_write -- ELEM !" << finl, TRUST_CGNS_ERROR();
293 else if (LOC ==
"FACES")
295 if (cg_field_write(fileId, baseId, zoneId[ind], flowId_faces, CGNS_DOUBLE_TYPE, id_champ, field_cgns.addr(), &fieldId_faces) != CG_OK)
296 Cerr <<
"Error Ecrire_CGNS::cgns_write_field_seq : cg_field_write -- FACES !" << finl, TRUST_CGNS_ERROR();
299 throw std::runtime_error(
"Ecrire_CGNS_helper::cgns_field_write_data => Unsupported LOC : " + LOC);
303template<TYPE_ECRITURE_CGNS _TYPE_>
304inline std::enable_if_t<_TYPE_ != TYPE_ECRITURE_CGNS::SEQ, void>
305Ecrire_CGNS_helper::cgns_field_write_data(
const int fileId,
const int baseId,
const int ind,
const std::vector<int>& zoneId,
const std::string& LOC,
306 const int flowId_som,
const int flowId_elem,
const int flowId_faces,
307 const int fieldId_som,
const int fieldId_elem,
const int fieldId_faces,
308 const int comp,
const cgsize_t min,
const cgsize_t max,
const DoubleTab& valeurs)
315 if (cgp_field_write_data(fileId, baseId, zoneId[ind], flowId_som, fieldId_som, &min, &max, valeurs.
addr()) != CG_OK)
316 Cerr <<
"Error Ecrire_CGNS_helper::cgns_field_write_data : cgp_field_write_data -- SOM !" << finl, TRUST_CGNS_ERROR();
318 else if (LOC ==
"ELEM")
320 if (cgp_field_write_data(fileId, baseId, zoneId[ind], flowId_elem, fieldId_elem, &min, &max, valeurs.
addr()) != CG_OK)
321 Cerr <<
"Error Ecrire_CGNS_helper::cgns_field_write_data : cgp_field_write_data -- ELEM !" << finl, TRUST_CGNS_ERROR();
323 else if (LOC ==
"FACES")
325 if (cgp_field_write_data(fileId, baseId, zoneId[ind], flowId_faces, fieldId_faces, &min, &max, valeurs.
addr()) != CG_OK)
326 Cerr <<
"Error Ecrire_CGNS_helper::cgns_field_write_data : cgp_field_write_data -- FACES !" << finl, TRUST_CGNS_ERROR();
329 throw std::runtime_error(
"Ecrire_CGNS_helper::cgns_field_write_data => Unsupported LOC : " + LOC);
334 DoubleTrav field_cgns(nb);
335 for (
int i = 0; i < nb; i++)
336 field_cgns(i) = valeurs(i, comp);
340 if (cgp_field_write_data(fileId, baseId, zoneId[ind], flowId_som, fieldId_som, &min, &max, field_cgns.addr()) != CG_OK)
341 Cerr <<
"Error Ecrire_CGNS_helper::cgns_field_write_data : cgp_field_write_data -- SOM !" << finl, TRUST_CGNS_ERROR();
343 else if (LOC ==
"ELEM")
345 if (cgp_field_write_data(fileId, baseId, zoneId[ind], flowId_elem, fieldId_elem, &min, &max, field_cgns.addr()) != CG_OK)
346 Cerr <<
"Error Ecrire_CGNS_helper::cgns_field_write_data : cgp_field_write_data -- ELEM !" << finl, TRUST_CGNS_ERROR();
348 else if (LOC ==
"FACES")
350 if (cgp_field_write_data(fileId, baseId, zoneId[ind], flowId_faces, fieldId_faces, &min, &max, field_cgns.addr()) != CG_OK)
351 Cerr <<
"Error Ecrire_CGNS_helper::cgns_field_write_data : cgp_field_write_data -- FACES !" << finl, TRUST_CGNS_ERROR();
354 throw std::runtime_error(
"Ecrire_CGNS_helper::cgns_field_write_data => Unsupported LOC : " + LOC);
359template<TYPE_ECRITURE_CGNS _TYPE_>
360inline void Ecrire_CGNS_helper::cgns_write_iters(
const bool has_field,
const int nb_zones_to_write,
const int fileId,
const int baseId,
const int ind,
const std::vector<int>& zoneId,
361 const std::string& LOC,
const std::string& solname_som,
const std::string& solname_elem,
const std::string& solname_faces,
const std::vector<double>& time_post)
363 cgns_write_iters_deformable<_TYPE_>(
false , has_field, nb_zones_to_write, fileId, baseId, ind, zoneId,
364 LOC, solname_som, solname_elem, solname_faces, solname_elem , time_post);
367template<TYPE_ECRITURE_CGNS _TYPE_>
368inline void Ecrire_CGNS_helper::cgns_write_iters_deformable(
const bool is_deformable,
const bool has_field,
const int nb_zones_to_write,
const int fileId,
const int baseId,
const int ind,
const std::vector<int>& zoneId,
369 const std::string& LOC,
const std::string& solname_som,
const std::string& solname_elem,
const std::string& solname_faces,
const std::string& grid_name,
370 const std::vector<double>& time_post)
372 const int nsteps =
static_cast<int>(time_post.size());
373 const cgsize_t nuse =
static_cast<cgsize_t
>(nsteps);
377 auto delete_all_arrays_named = [](
const char *arrname)
381 if (cg_delete_node(
const_cast<char*
>(arrname)) == CG_OK)
continue;
388 if (cg_biter_write(fileId, baseId,
"TimeIterValues", nsteps) != CG_OK)
389 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_iters : cg_biter_write !" << finl, TRUST_CGNS_ERROR();
392 if (cg_goto(fileId, baseId,
"BaseIterativeData_t", 1,
"end") != CG_OK)
393 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_iters : cg_goto !" << finl, TRUST_CGNS_ERROR();
396 delete_all_arrays_named(
"TimeValues");
397 if (cg_array_write(
"TimeValues", CGNS_DOUBLE_TYPE, 1, &nuse, time_post.data()) != CG_OK)
398 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_iters : cg_array_write !" << finl, TRUST_CGNS_ERROR();
400 if (cg_simulation_type_write(fileId, baseId, CGNS_ENUMV(TimeAccurate)) != CG_OK)
401 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_iters : cg_simulation_type_write !" << finl, TRUST_CGNS_ERROR();
403 const char* solname = (LOC ==
"SOM") ? solname_som.c_str() : (LOC ==
"FACES") ? solname_faces.c_str() : solname_elem.c_str();
405 const cgsize_t idata[2] = { CGNS_STR_SIZE , nuse};
407 constexpr bool is_PAR_OVER = (_TYPE_ == TYPE_ECRITURE_CGNS::PAR_OVER);
410 for (
int ii = 0; ii != nb_zones_to_write; ii++)
411 if (zoneId[is_PAR_OVER || is_comm_group ? ii : ind] != -123)
414 if (cg_ziter_write(fileId, baseId, zoneId[is_PAR_OVER || is_comm_group ? ii : ind],
"ZoneIterativeData") != CG_OK)
415 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_iters : cg_ziter_write !" << finl, cg_error_exit();
417 if (cg_goto(fileId, baseId,
"Zone_t", zoneId[is_PAR_OVER || is_comm_group ? ii : ind],
"ZoneIterativeData_t", 1,
"end") != CG_OK)
418 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_iters : cg_goto !" << finl, TRUST_CGNS_ERROR();
422 delete_all_arrays_named(
"GridCoordinatesPointers");
423 assert(grid_name.size() ==
static_cast<size_t>(CGNS_STR_SIZE) * nuse);
424 if (cg_array_write(
"GridCoordinatesPointers", CGNS_ENUMV(Character), 2, idata, grid_name.c_str()) != CG_OK)
425 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_iters : cg_array_write GridCoordinatesPointers !" << finl, TRUST_CGNS_ERROR();
430 delete_all_arrays_named(
"FlowSolutionPointers");
431 if (cg_array_write(
"FlowSolutionPointers", CGNS_ENUMV(Character), 2, idata, solname) != CG_OK)
432 Cerr <<
"Error Ecrire_CGNS_helper::cgns_write_iters : cg_array_write FlowSolutionPointers !" << finl, TRUST_CGNS_ERROR();
437inline void Ecrire_CGNS_helper::cgns_write_zone_and_classic_links(
const bool write_zone,
const int fileId,
const int baseId,
const std::string& zone_name_to_write,
438 const cgsize_t *isize,
int& zoneId,
const int zone_goto_id,
439 const std::string& linkfile,
const std::string& target_base_name,
const std::string& target_zone_name,
440 const std::vector<std::string>& connect_names,
const char *where,
const bool write_connectivity)
443 if (cg_zone_write(fileId, baseId, zone_name_to_write.c_str(), isize, CGNS_ENUMV(Unstructured), &zoneId) != CG_OK)
444 Cerr <<
"Error " << where <<
" : cg_zone_write !" << finl, TRUST_CGNS_ERROR();
446 if (cg_goto(fileId, baseId,
"Zone_t", zone_goto_id,
"end") != CG_OK)
447 Cerr <<
"Error " << where <<
" : cg_goto Zone_t !" << finl, TRUST_CGNS_ERROR();
449 std::string linkpath =
"/" + target_base_name +
"/" + target_zone_name +
"/GridCoordinates/";
451 if (cg_link_write(
"GridCoordinates", linkfile.c_str(), linkpath.c_str()) != CG_OK)
452 Cerr <<
"Error " << where <<
" : cg_link_write GridCoordinates !" << finl, TRUST_CGNS_ERROR();
454 if (write_connectivity)
455 for (
const auto &itr_conn : connect_names)
457 linkpath =
"/" + target_base_name +
"/" + target_zone_name +
"/" + itr_conn +
"/";
459 if (cg_link_write(itr_conn.c_str(), linkfile.c_str(), linkpath.c_str()) != CG_OK)
460 Cerr <<
"Error " << where <<
" : cg_link_write connectivity " << itr_conn <<
" !" << finl, TRUST_CGNS_ERROR();
464inline void Ecrire_CGNS_helper::cgns_write_solution_classic_links(
const std::string& base_linkfile,
const std::string& target_base_name,
const std::string& target_zone_name,
465 const std::string& LOC,
const std::vector<double>& time_post,
const char *where)
468 for (
auto& itr_t : time_post)
470 const std::string solname =
"FlowSolution_itr_" + std::to_string(idx);
472 base_linkfile +
".solution." + convert_double_to_string(itr_t) +
".cgns";
473 const std::string linkpath =
"/" + target_base_name +
"/" + target_zone_name +
"/" + solname +
"/";
475 if (cg_link_write(solname.c_str(), linkfile.c_str(), linkpath.c_str()) != CG_OK)
476 Cerr <<
"Error " << where <<
" : cg_link_write solution !" << finl, TRUST_CGNS_ERROR();
481inline void Ecrire_CGNS_helper::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,
482 const cgsize_t *isize,
int& zoneId,
const int zone_goto_id,
483 const std::string& file_prefix,
const std::string& target_base_name,
const std::string& target_zone_name,
484 const std::vector<std::string>& connect_names,
const Nom& nom_dom,
const std::string& LOC,
485 const std::vector<double>& time_post,
const char *where,
const bool write_connectivity)
488 if (cg_zone_write(fileId, baseId, zone_name_to_write.c_str(), isize, CGNS_ENUMV(Unstructured), &zoneId) != CG_OK)
489 Cerr <<
"Error " << where <<
" : cg_zone_write !" << finl, TRUST_CGNS_ERROR();
491 if (cg_goto(fileId, baseId,
"Zone_t", zone_goto_id,
"end") != CG_OK)
492 Cerr <<
"Error " << where <<
" : cg_goto Zone_t !" << finl, TRUST_CGNS_ERROR();
494 std::string linkfile, linkpath, grid_name_loc;
495 bool conn_written =
false;
498 for (
const auto &itr_t : time_post)
501 file_prefix +
".solution." + convert_double_to_string(itr_t) +
".cgns";
503 linkpath =
"/" + target_base_name +
"/" + target_zone_name +
"/GridCoordinates/";
505 grid_name_loc =
"GridCoordinates";
508 grid_name_loc +=
"_itr_";
509 grid_name_loc += std::to_string(idx);
512 if (cg_link_write(grid_name_loc.c_str(), linkfile.c_str(), linkpath.c_str()) != CG_OK)
513 Cerr <<
"Error " << where <<
" : cg_link_write GridCoordinates !" << finl, TRUST_CGNS_ERROR();
517 if (write_connectivity)
518 for (
const auto &itr_conn : connect_names)
520 linkpath =
"/" + target_base_name +
"/" + target_zone_name +
"/" + itr_conn +
"/";
522 if (cg_link_write(itr_conn.c_str(), linkfile.c_str(), linkpath.c_str()) != CG_OK)
523 Cerr <<
"Error " << where <<
" : cg_link_write connectivity !" << finl, TRUST_CGNS_ERROR();
530 const std::string solname =
"FlowSolution_itr_" + std::to_string(idx);
531 linkpath =
"/" + nom_dom.
getString() +
"/" + nom_dom.
getString() +
"/" + solname +
"/";
533 if (cg_link_write(solname.c_str(), linkfile.c_str(), linkpath.c_str()) != CG_OK)
534 Cerr <<
"Error " << where <<
" : cg_link_write FlowSolution " << solname <<
" !" << finl, TRUST_CGNS_ERROR();
540inline void Ecrire_CGNS_helper::cgns_write_connectivity_deformable_links(
const int fileId,
const int baseId,
const int zone_goto_id,
const std::string& linkfile,
541 const std::string& target_base_name,
const std::string& target_zone_name,
542 const std::vector<std::string>& connect_names,
const char *where)
544 if (cg_goto(fileId, baseId,
"Zone_t", zone_goto_id,
"end") != CG_OK)
545 Cerr <<
"Error " << where <<
" : cg_goto Zone_t !" << finl, TRUST_CGNS_ERROR();
547 for (
auto &itr_conn : connect_names)
549 const std::string linkpath =
"/" + target_base_name +
"/" + target_zone_name +
"/" + itr_conn +
"/";
551 if (cg_link_write(itr_conn.c_str(), linkfile.c_str(), linkpath.c_str()) != CG_OK)
552 Cerr <<
"Error " << where <<
" : cg_link_write connectivity !" << finl, TRUST_CGNS_ERROR();
class Nom Une chaine de caractere pour nommer les objets de TRUST
const std::string & getString() const
static bool LINKED_FILES_PER_COMM_GROUP
static bool SINGLE_FILE_PER_COMM_GROUP
_SIZE_ dimension(int d) const