16#include <Sortie_Fichier_base.h>
17#include <Format_Post_CGNS.h>
18#include <Comm_Group_MPI.h>
19#include <communications.h>
20#include <TRUST_2_MED.h>
21#include <Ecrire_CGNS.h>
22#include <Domaine_VF.h>
31void Ecrire_CGNS::cgns_set_base_name(
const Nom& fn)
36 if (dir_to_use ==
"." || dir_to_use ==
"./")
39 while (!dir_to_use.empty() && dir_to_use.back() ==
'/')
40 dir_to_use.pop_back();
42 if (!dir_to_use.empty())
43 baseFile_name_ = dir_to_use +
"/" + fn.
getString();
48void Ecrire_CGNS::cgns_resetTime(
const double t,
const std::string& dirname,
const Nom& basefile)
51 Process::exit(
"\nError in Ecrire_CGNS::cgns_resetTime. The name of the directory is empty !!! \n");
54 solname_elem_ =
"", solname_som_ =
"", solname_faces_ =
"";
55 grid_name_ =
"", grid_name_loc_ =
"";
56 need_post_field_ =
true, first_time_post_ =
true;
57 has_elem_field_ =
false, has_faces_field_ =
false, has_som_field_ =
false;
58 solname_elem_written_ =
false, solname_som_written_ =
false, solname_faces_written_ =
false;
59 multi_loc_deformable_support_linked_ =
false, grid_name_written_ =
false;
60 grid_file_opened_ =
false, solution_file_opened_ =
false;
61 ensure_modify_done_ =
false, singlefile_open_ =
false;
62 flowId_elem_ = 0, flowId_som_ = 0, flowId_faces_ = 0;
63 fieldId_elem_ = 0, fieldId_som_ = 0, fieldId_faces_ = 0;
64 step_single_file_counter_ = 0;
66 fieldName_dumped_.clear(), time_post_.clear();
68 fld_loc_map_.clear(), doms_written_.clear();
69 baseId_.clear(), zoneId_.clear(), sizeId_.clear();
70 baseZone_name_.clear(), connectname_.clear();
71 cellDim_.clear(), zoneId_par_.clear();
75 baseFile_name_vect_.push_back(baseFile_name_);
77 std::string dir_to_use(dirname);
80 if (dir_to_use ==
"." || dir_to_use ==
"./")
84 while (!dir_to_use.empty() && dir_to_use.back() ==
'/')
85 dir_to_use.pop_back();
87 if (!dir_to_use.empty())
88 baseFile_name_ = dir_to_use +
"/" + basefile.
getString();
93 if (std::find(baseFile_name_vect_.begin(), baseFile_name_vect_.end(), baseFile_name_) != baseFile_name_vect_.end())
95 baseFile_name_ +=
"_reset_";
96 baseFile_name_ += std::to_string(
static_cast<int>(baseFile_name_vect_.size()));
100void Ecrire_CGNS::cgns_associer_domaine_dis(
const Domaine_dis_base& domaine_dis_base)
102 domaine_dis_ = domaine_dis_base;
105void Ecrire_CGNS::cgns_init_MPI()
108 if (is_comm_group_mode())
111 if (cgp_mpi_comm(comm_loc.get_mpi_comm()) != CG_OK)
112 Cerr <<
"Error Ecrire_CGNS::cgns_init_MPI : cgp_mpi_comm -- Comm_Group_MPI !" << finl, TRUST_CGNS_ERROR();
114 if (proc_maitre_local_comm_ == -123)
115 init_proc_maitre_local_comm();
119 if (cgp_mpi_comm( Comm_Group_MPI::get_trio_u_world()) != CG_OK)
120 Cerr <<
"Error Ecrire_CGNS::cgns_init_MPI : cgp_mpi_comm -- trio_u_world !" << finl, TRUST_CGNS_ERROR();
127 if (cgp_pio_mode((CGNS_ENUMT(PIOmode_t)) CGP_INDEPENDENT) != CG_OK)
128 Cerr <<
"Error Ecrire_CGNS::cgns_init_MPI : cgp_pio_mode !" << finl, TRUST_CGNS_ERROR();
132void Ecrire_CGNS::cgns_open_file()
138 if (is_lagrangian_)
return;
143 std::string fn = baseFile_name_ +
".cgns";
147 if (is_single_file_comm_group_mode())
149 fn = (Nom(baseFile_name_)).nom_me(proc_maitre_local_comm_).getString() +
".cgns";
151 cgns_helper_.cgns_open_file<TYPE_RUN_CGNS::PAR>(fn, fileId_,
false);
152 Cerr <<
"**** Multiple parallel CGNS files " << baseFile_name_ <<
"_XXXX.cgns opened !" << finl;
155 cgns_helper_.cgns_open_file<TYPE_RUN_CGNS::PAR>(fn, fileId_);
158 cgns_helper_.cgns_open_file<TYPE_RUN_CGNS::SEQ>(fn, fileId_);
160 singlefile_open_ =
true;
163void Ecrire_CGNS::fill_infos_loc()
165 has_elem_field_ =
false, has_faces_field_ =
false, has_som_field_ =
false;
166 if (postraiter_domaine_)
168 has_som_field_ =
true;
169 has_elem_field_ =
true;
174 assert (
static_cast<int>(loc_vect_->size()) <= 3);
176 if (
static_cast<int>(loc_vect_->size()) == 0)
178 need_post_field_ =
false;
182 for (
auto& itr : loc_vect_.valeur())
184 if (itr ==
"FACES") has_faces_field_ =
true;
185 else if (itr ==
"SOM") has_som_field_ =
true;
186 else if (itr ==
"ELEM") has_elem_field_ =
true;
188 throw std::runtime_error(
"Ecrire_CGNS::fill_infos_loc => Unsupported LOC : " + itr);
191 if (has_faces_field_ && is_deformable_)
193 Cerr <<
"Error in Ecrire_CGNS::" << __func__ <<
" !!! Postprocessing face fields with a deformable problem is not yet allowed ..." << finl;
194 Cerr <<
"Contact the TRUST team" << finl;
201 Cerr <<
"Error in Ecrire_CGNS::" << __func__ <<
" !!! You can not use the CGNS option PARALLEL_OVER_ZONE with your problem ..." << finl;
202 Cerr <<
"Contact the TRUST team" << finl;
207void Ecrire_CGNS::finir_ecriture(
double temps)
209 if (postraiter_domaine_)
return;
213 cgns_close_grid_or_solution_link_file(temps, TYPE_LINK_CGNS::SOLUTION);
217 cgns_write_final_link_file_lagrangian();
219 cgns_write_final_link_file();
223 if (singlefile_open_)
232 if (will_flush || will_close)
234 if (!first_time_post_ && !is_single_file_comm_group_mode())
238 cgns_flush_to_disk();
244 cgns_helper_.cgns_close_file<TYPE_RUN_CGNS::PAR>(baseFile_name_ , fileId_,
false );
246 cgns_helper_.cgns_close_file<TYPE_RUN_CGNS::SEQ>(baseFile_name_ , fileId_,
false );
248 singlefile_open_ =
false;
253 if (is_single_file_comm_group_mode())
254 cgns_write_final_link_file_for_single_file_comm_group();
257void Ecrire_CGNS::cgns_finir()
265 if (!is_single_file_comm_group_mode())
266 if (!postraiter_domaine_ && !first_time_post_)
269 if (!singlefile_open_)
return;
271 std::string fn = baseFile_name_ +
".cgns";
275 if (is_single_file_comm_group_mode())
277 cgns_helper_.cgns_close_file<TYPE_RUN_CGNS::PAR>(fn , fileId_,
false);
278 Cerr <<
"**** Multiple parallel CGNS files " << baseFile_name_ <<
"_XXXX.cgns closed !" << finl;
281 cgns_helper_.cgns_close_file<TYPE_RUN_CGNS::PAR>(fn, fileId_);
284 cgns_helper_.cgns_close_file<TYPE_RUN_CGNS::SEQ>(fn, fileId_);
287void Ecrire_CGNS::cgns_add_time(
const double t)
289 if (first_time_post_ && !time_post_.empty())
290 first_time_post_ =
false;
293 cgns_open_solution_link_file(t);
296 if (!first_time_post_ || is_deformable_)
297 cgns_open_solution_link_file(t);
302 step_single_file_counter_++;
304 if (!singlefile_open_)
306 if (!first_time_post_)
308 std::string fn = baseFile_name_ +
".cgns";
312 if (is_single_file_comm_group_mode())
314 fn = (Nom(baseFile_name_)).nom_me(proc_maitre_local_comm_).getString() +
".cgns";
315 cgns_helper_.cgns_open_file<TYPE_RUN_CGNS::PAR, TYPE_MODE_CGNS::MODIFY>(fn, fileId_,
false);
318 cgns_helper_.cgns_open_file<TYPE_RUN_CGNS::PAR, TYPE_MODE_CGNS::MODIFY>(fn, fileId_,
false);
321 cgns_helper_.cgns_open_file<TYPE_RUN_CGNS::SEQ, TYPE_MODE_CGNS::MODIFY>(fn, fileId_,
false);
324 singlefile_open_ =
true;
328 time_post_.push_back(t);
329 fieldName_dumped_.clear();
330 flowId_elem_++, flowId_som_++, flowId_faces_++;
331 fieldId_elem_ = 0, fieldId_som_ = 0, fieldId_faces_ = 0;
332 solname_elem_written_ =
false, solname_som_written_ =
false, solname_faces_written_ =
false;
333 multi_loc_deformable_support_linked_ =
false, grid_name_written_ =
false;
336void Ecrire_CGNS::cgns_flush_to_disk()
const
340 if (cg_get_cgio(fileId_, &cgio_num) != CG_OK)
341 Cerr <<
"Error Ecrire_CGNS::cgns_flush_to_disk : cg_get_cgio !" << finl, TRUST_CGNS_ERROR();
343 if (cgio_flush_to_disk(cgio_num) != 0)
344 Cerr <<
"Error Ecrire_CGNS::cgns_flush_to_disk : cgio_flush_to_disk !" << finl, TRUST_CGNS_ERROR();
347void Ecrire_CGNS::ensure_modify_open_singlefile()
352 std::string fn = baseFile_name_ +
".cgns";
356 cgns_helper_.cgns_close_file<TYPE_RUN_CGNS::PAR>(fn , fileId_,
false);
358 cgns_helper_.cgns_close_file<TYPE_RUN_CGNS::SEQ>(fn , fileId_,
false);
363 if (is_single_file_comm_group_mode())
365 fn = (Nom(baseFile_name_)).nom_me(proc_maitre_local_comm_).getString() +
".cgns";
366 cgns_helper_.cgns_open_file<TYPE_RUN_CGNS::PAR, TYPE_MODE_CGNS::MODIFY>(fn, fileId_,
false);
369 cgns_helper_.cgns_open_file<TYPE_RUN_CGNS::PAR, TYPE_MODE_CGNS::MODIFY>(fn, fileId_,
false);
372 cgns_helper_.cgns_open_file<TYPE_RUN_CGNS::SEQ, TYPE_MODE_CGNS::MODIFY>(fn, fileId_,
false);
374 ensure_modify_done_ =
true;
377void Ecrire_CGNS::update_grid_name()
379 grid_name_loc_ =
"GridCoordinates";
381 if (!first_time_post_)
383 grid_name_loc_ +=
"_itr_";
384 grid_name_loc_ += std::to_string(
static_cast<int>(time_post_.size() - 1));
387 std::string c = grid_name_loc_;
388 c.resize(CGNS_STR_SIZE,
' ');
391 grid_name_written_ =
true;
394void Ecrire_CGNS::cgns_write_domaine(
const Domaine * dom,
const Nom& nom_dom,
const DoubleTab& som,
const IntTab& elem,
const Motcle& type_e)
396 if (!grid_name_written_ && (first_time_post_ || is_deformable_))
399 std::string nom_dom_modifie = TRUST_2_CGNS::modify_domaine_name_for_post(nom_dom);
402 if (!grid_file_opened_)
403 cgns_open_grid_base_link_file();
408 cgns_write_domaine_par_over_zone(dom, Nom(nom_dom_modifie), som, elem, type_e);
410 cgns_write_domaine_par_in_zone(dom, Nom(nom_dom_modifie), som, elem, type_e);
413 cgns_write_domaine_seq(dom, Nom(nom_dom_modifie), som, elem, type_e);
416void Ecrire_CGNS::cgns_write_field(
const Domaine& domaine,
const Noms& noms_compo,
double temps,
417 const Nom& id_du_champ,
const Nom& id_du_domaine,
const Nom& localisation,
418 const DoubleTab& valeurs)
420 assert (need_post_field_);
422 if (fld_loc_map_.empty())
423 cgns_fill_field_loc_map(domaine.le_nom());
425 if (is_deformable_ && !multi_loc_deformable_support_linked_)
426 link_multi_loc_support_pb_deformable();
429 const std::string LOC = Motcle(localisation).getString();
431 assert(fld_loc_map_.count(LOC));
434 for (
int i = 0; i < nb_cmp; i++)
436 const Motcle field_name = nb_cmp > 1 ? Motcle(noms_compo[i]) : id_du_champ;
437 const std::string field_name_check = is_lagrangian_ ? field_name.
getString() + LOC : field_name.
getString();
439 if (fieldName_dumped_.insert(field_name_check).second)
442 cgns_write_field_par_over_zone(i , temps, field_name, id_du_domaine, localisation, fld_loc_map_.at(LOC), valeurs);
444 cgns_write_field_par_in_zone(i , temps, field_name, id_du_domaine, localisation, fld_loc_map_.at(LOC), valeurs);
447 Cerr <<
"Field " << field_name <<
" is already written => we skip it ..." << finl;
451 for (
int i = 0; i < nb_cmp; i++)
453 const Motcle field_name = nb_cmp > 1 ? Motcle(noms_compo[i]) : id_du_champ;
454 const std::string field_name_check = is_lagrangian_ ? field_name.
getString() + LOC : field_name.
getString();
456 if (fieldName_dumped_.insert(field_name_check).second)
457 cgns_write_field_seq(i , temps, field_name, id_du_domaine, localisation, fld_loc_map_.at(LOC), valeurs);
459 Cerr <<
"Field " << field_name <<
" is already written => we skip it ..." << finl;
468void Ecrire_CGNS::cgns_fill_field_loc_map(
const Nom& nom_dom_init)
470 assert (
static_cast<int>(time_post_.size()) == 1 && first_time_post_);
473 enum class InitMode { SOLUTIONLINK, LINKEDBASE };
475 auto modify_name_for_support = [&](
const std::string& loc)
477 Nom nom_dom = nom_dom_init;
479 nom_dom += loc.c_str();
483 auto insert_loc_map_and_init = [&](
const std::string& loc, InitMode mode)
485 assert(!fld_loc_map_.count(loc));
486 const Nom nom_dom = modify_name_for_support(loc);
487 fld_loc_map_.insert({ loc, nom_dom });
490 (mode == InitMode::SOLUTIONLINK) ? cgns_init_solution_link_file(loc, nom_dom) :
491 add_new_linked_base(loc, nom_dom);
495 if (has_faces_field_ && !is_dual_)
497 Cerr <<
"### Building a new CGNS zone to host the fields located at FACES !" << finl;
498 cgns_write_domaine_dual(nom_dom_init, 0 , modify_name_for_support(
"FACES"));
503 if (!multi_loc_deformable_support_linked_)
505 if (has_elem_field_) insert_loc_map_and_init(
"ELEM", InitMode::SOLUTIONLINK);
507 if (has_som_field_) insert_loc_map_and_init(
"SOM", InitMode::SOLUTIONLINK);
509 if (has_faces_field_)
Process::exit(
"Error in Ecrire_CGNS::cgns_fill_field_loc_map : FACES fields are not yet supported ! \n");
514 if (has_elem_field_) insert_loc_map_and_init(
"ELEM", InitMode::LINKEDBASE);
516 if (has_som_field_) insert_loc_map_and_init(
"SOM", InitMode::LINKEDBASE);
518 if (has_faces_field_) insert_loc_map_and_init(
"FACES", InitMode::LINKEDBASE);
523 if (grid_file_opened_ && !is_deformable_)
524 cgns_close_grid_or_solution_link_file(0. , TYPE_LINK_CGNS::GRID,
false);
526 if (!solution_file_opened_ || (is_deformable_ && !multi_loc_deformable_support_linked_))
528 if (has_elem_field_) insert_loc_map_and_init(
"ELEM", InitMode::SOLUTIONLINK);
530 if (has_som_field_) insert_loc_map_and_init(
"SOM", InitMode::SOLUTIONLINK);
532 if (has_faces_field_) insert_loc_map_and_init(
"FACES", InitMode::SOLUTIONLINK);
535 cgns_open_solution_link_file(time_post_.back());
540void Ecrire_CGNS::cgns_write_iters()
542 if (first_time_post_ || is_lagrangian_)
return;
545 ensure_modify_open_singlefile();
547 for (
auto &itr : doms_written_)
549 bool has_field =
false;
550 std::string LOC =
"rien";
551 TRUST_2_CGNS::init_has_field_and_loc_iters(itr, fld_loc_map_, has_field, LOC);
553 const int ind_glob = TRUST_2_CGNS::get_index_nom_vector(doms_written_, itr);
554 assert(ind_glob > -1);
557 cgns_helper_.cgns_write_iters_deformable<TYPE_ECRITURE_CGNS::SEQ>(
true , has_field, 1 , fileId_, baseId_[ind_glob],
558 ind_glob , zoneId_, LOC, solname_som_, solname_elem_, solname_faces_, grid_name_, time_post_);
562 int ind_base = TRUST_2_CGNS::get_base_domain_idx(doms_written_, itr, has_field, LOC, ind_glob);
563 const TRUST_2_CGNS& TRUST2CGNS = T2CGNS_[ind_base];
564 const int nb_zones_to_write = TRUST2CGNS.nb_procs_writing();
566 cgns_helper_.cgns_write_iters<TYPE_ECRITURE_CGNS::PAR_OVER>(has_field, nb_zones_to_write, fileId_, baseId_[ind_glob], ind_glob, zoneId_par_[ind_glob], LOC,
567 solname_som_, solname_elem_, solname_faces_, time_post_);
571 cgns_helper_.cgns_write_iters<TYPE_ECRITURE_CGNS::SEQ>(has_field, 1 , fileId_, baseId_[ind_glob], ind_glob, zoneId_, LOC,
572 solname_som_, solname_elem_, solname_faces_, time_post_);
581void Ecrire_CGNS::cgns_write_domaine_seq(
const Domaine * domaine,
const Nom& nom_dom,
const DoubleTab& les_som,
const IntTab& les_elem,
const Motcle& type_elem)
583 if (is_deformable_ && !first_time_post_)
585 cgns_write_domaine_deformable_seq(domaine, nom_dom, les_som, les_elem, type_elem);
590 T2CGNS_.push_back(TRUST_2_CGNS());
591 TRUST_2_CGNS& TRUST2CGNS = T2CGNS_.back();
592 TRUST2CGNS.associer_domaine_TRUST(domaine, domaine_dis_ ? &(domaine_dis_.valeur()) :
nullptr,
593 les_som, les_elem, postraiter_domaine_, discr_type_);
596 assert(fs_dual_.size() > 0 && ef_dual_.size() > 0);
597 TRUST2CGNS.associer_connec_pour_dual(fs_dual_, ef_dual_);
600 doms_written_.push_back(nom_dom);
602 CGNS_TYPE cgns_type_elem = TRUST2CGNS.convert_elem_type(type_elem);
603 const bool is_polyedre = (type_elem ==
"POLYEDRE" || type_elem ==
"PRISME" || type_elem ==
"PRISME_HEXAG");
604 const int icelldim = TRUST2CGNS.topo_dim_from_elem(cgns_type_elem, is_polyedre);
608 std::vector<double> xCoords, yCoords, zCoords;
609 TRUST2CGNS.fill_coords(xCoords, yCoords, zCoords);
614 baseId_.push_back(-123);
615 char basename[CGNS_STR_SIZE];
616 strcpy(basename, nom_dom.
getChar());
618 if (cg_base_write(fileId_, basename, icelldim, iphysdim, &baseId_.back()) != CG_OK)
619 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_seq : cg_base_write !" << finl, TRUST_CGNS_ERROR();
622 const cgsize_t isize[3] = { (cgsize_t)nb_som , (cgsize_t)nb_elem , 0 };
624 cgns_fill_info_grid_link_file(basename, cgns_type_elem, icelldim, nb_som, nb_elem, is_polyedre);
626 zoneId_.push_back(-123);
632 cgns_helper_.cgns_write_zone_grid_coord<TYPE_ECRITURE_CGNS::SEQ>(icelldim, fileId_, baseId_.back(), basename , isize,
633 zoneId_.back(), xCoords, yCoords, zCoords, coordsId, coordsId, coordsId);
637 cgsize_t start = 1, end;
639 if (cgns_type_elem == CGNS_ENUMV(NGON_n))
641 assert (domaine !=
nullptr);
642 std::vector<cgsize_t> sf, sf_offset;
644 end = start +
static_cast<cgsize_t
>(TRUST2CGNS.convert_connectivity_ngon(sf, sf_offset, is_polyedre)) -1;
646 if (cg_poly_section_write(fileId_, baseId_.back(), zoneId_.back(),
"NGON_n", CGNS_ENUMV(NGON_n), start, end, 0, sf.data(), sf_offset.data(), §ionId))
651 std::vector<cgsize_t> ef, ef_offset;
654 end = start +
static_cast<cgsize_t
>(TRUST2CGNS.convert_connectivity_nface(ef, ef_offset)) -1;
656 if (cg_poly_section_write(fileId_, baseId_.back(), zoneId_.back(),
"NFACE_n", CGNS_ENUMV(NFACE_n), start, end, 0, ef.data(), ef_offset.data(), §ionId))
662 std::vector<cgsize_t> elems;
663 const int nsom = TRUST2CGNS.convert_connectivity(cgns_type_elem, elems);
665 end = start +
static_cast<cgsize_t
>(elems.
size()) / nsom - 1;
667 if (cg_section_write(fileId_, baseId_.back(), zoneId_.back(),
"Elem", cgns_type_elem, start, end, 0, elems.
data(), §ionId) != CG_OK)
668 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_seq : cg_section_write !" << finl, TRUST_CGNS_ERROR();
671 TRUST2CGNS.clear_vectors();
674void Ecrire_CGNS::cgns_write_field_seq(
const int comp,
const double temps,
const Nom& id_du_champ,
const Nom& id_du_domaine,
const Nom& localisation,
const Nom& nom_dom,
const DoubleTab& valeurs)
676 const std::string LOC = Motcle(localisation).getString();
677 Motcle id_du_champ_modifie = TRUST_2_CGNS::modify_field_name_for_post(id_du_champ, id_du_domaine, LOC, fieldId_som_, fieldId_elem_, fieldId_faces_);
678 const Nom& id_champ = id_du_champ_modifie;
681 const int ind = TRUST_2_CGNS::get_index_nom_vector(doms_written_, nom_dom);
684 const int nb_vals = valeurs.
dimension(0);
689 cgns_helper_.cgns_sol_write<TYPE_ECRITURE_CGNS::SEQ>(1 , fileId_, baseId_[ind], ind,
690 static_cast<int>(time_post_.size() - 1), zoneId_, LOC,
691 solname_som_, solname_elem_, solname_faces_,
692 solname_som_written_, solname_elem_written_, solname_faces_written_,
693 flowId_som_, flowId_elem_, flowId_faces_);
698 const Domaine_VF& dom_vf = ref_cast(Domaine_VF, domaine_dis_.valeur());
700 TRUST_2_CGNS::map_face_values(dom_vf, valeurs, new_vals);
702 cgns_helper_.cgns_field_write_data<TYPE_ECRITURE_CGNS::SEQ>(fileId_, baseId_[ind], ind, zoneId_, LOC,
703 flowId_som_, flowId_elem_, flowId_faces_, comp,
704 id_champ, new_vals, fieldId_som_, fieldId_elem_, fieldId_faces_);
708 cgns_helper_.cgns_field_write_data<TYPE_ECRITURE_CGNS::SEQ>(fileId_, baseId_[ind], ind, zoneId_, LOC,
709 flowId_som_, flowId_elem_, flowId_faces_, comp,
710 id_champ, valeurs, fieldId_som_, fieldId_elem_, fieldId_faces_);
715void Ecrire_CGNS::cgns_write_domaine_deformable_seq(
const Domaine * domaine,
const Nom& nom_dom,
const DoubleTab& les_som,
const IntTab& les_elem,
const Motcle& type_elem)
717 const int ind = TRUST_2_CGNS::get_index_nom_vector(doms_written_, nom_dom);
718 TRUST_2_CGNS& TRUST2CGNS = T2CGNS_[ind];
719 TRUST2CGNS.associer_domaine_TRUST(domaine, domaine_dis_ ? &(domaine_dis_.valeur()) :
nullptr,
720 les_som, les_elem, postraiter_domaine_, discr_type_);
722 CGNS_TYPE cgns_type_elem = TRUST2CGNS.convert_elem_type(type_elem);
723 const bool is_polyedre = (type_elem ==
"POLYEDRE" || type_elem ==
"PRISME" || type_elem ==
"PRISME_HEXAG");
724 const int icelldim = TRUST2CGNS.topo_dim_from_elem(cgns_type_elem, is_polyedre);
727 std::vector<double> xCoords, yCoords, zCoords;
728 TRUST2CGNS.fill_coords(xCoords, yCoords, zCoords);
730 const cgsize_t isize[3] = { (cgsize_t)nb_som, (cgsize_t)nb_elem, 0 };
733 char basename[CGNS_STR_SIZE];
734 strcpy(basename, nom_dom.
getChar());
742 if (cg_grid_write(fileId_, baseId_[ind], zoneId_[ind], grid_name_loc_.c_str(), &G) != CG_OK)
743 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_seq : cg_grid_write !" << finl, TRUST_CGNS_ERROR();
745 if (cg_goto(fileId_, baseId_[ind],
"Zone_t",zoneId_[ind],
"GridCoordinates_t", G,
"end") != CG_OK)
746 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_seq : cg_goto Zone_t !" << finl, TRUST_CGNS_ERROR();
748 const cgsize_t dims[1] = { (cgsize_t)nb_som };
750 if (cg_array_write(
"CoordinateX", CGNS_ENUMV(RealDouble), 1, dims, xCoords.data()) != CG_OK)
751 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_seq : cg_array_write CoordinateX !" << finl, TRUST_CGNS_ERROR();
753 if (cg_array_write(
"CoordinateY", CGNS_ENUMV(RealDouble), 1, dims, yCoords.data()) != CG_OK)
754 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_seq : cg_array_write CoordinateY !" << finl, TRUST_CGNS_ERROR();
757 if (cg_array_write(
"CoordinateZ", CGNS_ENUMV(RealDouble), 1, dims, zCoords.data()) != CG_OK)
758 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_seq : cg_array_write CoordinateZ !" << finl, TRUST_CGNS_ERROR();
767 if (cg_base_write(fileId_, basename, icelldim, iphysdim, &baseId_[ind]) != CG_OK)
768 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_seq : cg_base_write !" << finl, TRUST_CGNS_ERROR();
773 cgns_helper_.cgns_write_zone_grid_coord<TYPE_ECRITURE_CGNS::SEQ>(icelldim, fileId_, baseId_[ind], basename , isize,
774 zoneId_[ind], xCoords, yCoords, zCoords, coordsId, coordsId, coordsId);
778 sizeId_.push_back( { (cgsize_t)nb_som, (cgsize_t)nb_elem } );
781 cgsize_t start = 1, end;
783 if (cgns_type_elem == CGNS_ENUMV(NGON_n))
784 throw std::runtime_error(
"Ecrire_CGNS::cgns_write_domaine_deformable_seq => You should not be here !!! ");
787 std::vector<cgsize_t> elems;
788 const int nsom = TRUST2CGNS.convert_connectivity(cgns_type_elem, elems);
790 end = start +
static_cast<cgsize_t
>(elems.
size()) / nsom - 1;
792 if (cg_section_write(fileId_, baseId_[ind], zoneId_[ind],
"Elem", cgns_type_elem, start, end, 0, elems.
data(), §ionId) != CG_OK)
793 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_seq : cg_section_write !" << finl, TRUST_CGNS_ERROR();
799 std::string linkfile = baseFile_name_ +
".solution." + cgns_helper_.convert_double_to_string(time_post_[0]) +
".cgns";
800 TRUST_2_CGNS::remove_slash_linkfile(linkfile);
801 cgns_helper_.cgns_write_connectivity_deformable_links(fileId_, baseId_[ind], zoneId_[ind], linkfile, baseZone_name_[ind], baseZone_name_[ind],
802 connectname_[ind],
"Ecrire_CGNS::cgns_write_domaine_deformable_seq");
813void Ecrire_CGNS::cgns_write_domaine_par_over_zone(
const Domaine * domaine,
const Nom& nom_dom,
const DoubleTab& les_som,
const IntTab& les_elem,
const Motcle& type_elem)
817 assert (!is_deformable_);
818 doms_written_.push_back(nom_dom);
821 T2CGNS_.push_back(TRUST_2_CGNS());
822 TRUST_2_CGNS& TRUST2CGNS = T2CGNS_.back();
823 TRUST2CGNS.associer_domaine_TRUST(domaine, domaine_dis_ ? &(domaine_dis_.valeur()) :
nullptr,
824 les_som, les_elem, postraiter_domaine_, discr_type_);
828 assert(fs_dual_.size() > 0 && ef_dual_.size() > 0);
829 TRUST2CGNS.associer_connec_pour_dual(fs_dual_, ef_dual_);
831 CGNS_TYPE cgns_type_elem = TRUST2CGNS.convert_elem_type(type_elem);
832 const bool is_polyedre = (type_elem ==
"POLYEDRE" || type_elem ==
"PRISME" || type_elem ==
"PRISME_HEXAG");
833 const int icelldim = TRUST2CGNS.topo_dim_from_elem(cgns_type_elem, is_polyedre);
838 std::vector<double> xCoords, yCoords, zCoords;
839 TRUST2CGNS.fill_coords(xCoords, yCoords, zCoords);
843 baseId_.push_back(-123);
844 char basename[CGNS_STR_SIZE];
845 strcpy(basename, nom_dom.
getChar());
847 if (cg_base_write(fileId_, basename, icelldim, iphysdim, &baseId_.back()) != CG_OK)
848 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_over_zone : cg_base_write !" << finl, TRUST_CGNS_ERROR();
852 cgns_fill_info_grid_link_file(basename, cgns_type_elem, icelldim, nb_som, nb_elem, is_polyedre);
854 TRUST2CGNS.fill_global_infos();
856 if (cgns_type_elem == CGNS_ENUMV(NGON_n))
857 TRUST2CGNS.fill_global_infos_poly(is_polyedre);
864 std::vector<int> coordsIdx, coordsIdy, coordsIdz, sectionId, sectionId2;
865 std::string zonename;
867 const int nb_zones_to_write = TRUST2CGNS.nb_procs_writing();
868 const bool all_write = TRUST2CGNS.all_procs_write();
870 zoneId_.reserve(nb_zones_to_write);
871 coordsIdx.reserve(nb_zones_to_write);
872 coordsIdy.reserve(nb_zones_to_write);
875 coordsIdz.reserve(nb_zones_to_write);
877 sectionId.reserve(nb_zones_to_write);
878 if (cgns_type_elem == CGNS_ENUMV(NGON_n) && is_polyedre)
879 sectionId2.reserve(nb_zones_to_write);
883 const std::vector<int>& global_nb_elem = TRUST2CGNS.get_global_nb_elem(),
884 &global_nb_som = TRUST2CGNS.get_global_nb_som(),
885 &proc_non_zero_elem = TRUST2CGNS.get_proc_non_zero_elem();
887 for (
int i = 0; i != nb_zones_to_write; i++)
889 const int indZ = all_write ? i : proc_non_zero_elem[i];
890 const int ne_loc = global_nb_elem[indZ], ns_loc = global_nb_som[indZ];
893 cgsize_t start = 1, end = ne_loc;
894 const cgsize_t isize[3] = { ns_loc , end , 0 };
896 zoneId_.push_back(-123);
898 zonename.resize(CGNS_STR_SIZE,
' ');
900 coordsIdx.push_back(-123), coordsIdy.push_back(-123);
902 coordsIdz.push_back(-123);
905 cgns_helper_.cgns_write_zone_grid_coord<TYPE_ECRITURE_CGNS::PAR_OVER>(icelldim, fileId_, baseId_.back(), zonename.c_str(), isize,
906 zoneId_.back(), xCoords, yCoords, zCoords,
907 coordsIdx.back(), coordsIdy.back(), coordsIdz.back());
910 sectionId.push_back(-123);
912 if (cgns_type_elem == CGNS_ENUMV(NGON_n))
916 end = start +
static_cast<cgsize_t
>(TRUST2CGNS.get_global_nb_face_som()[indZ]) -1;
917 cgsize_t maxoffset =
static_cast<cgsize_t
>(TRUST2CGNS.get_global_nb_face_som_offset()[indZ]);
919 if (cgp_poly_section_write(fileId_, baseId_.back(), zoneId_.back(),
"NGON_n", CGNS_ENUMV(NGON_n), start, end, maxoffset, 0, §ionId.back()) != CG_OK)
920 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_over_zone : cgp_poly_section_write !" << finl, TRUST_CGNS_ERROR();
922 sectionId2.push_back(-123);
925 end = start +
static_cast<cgsize_t
>(TRUST2CGNS.get_global_nb_elem_face()[indZ]) -1;
926 maxoffset =
static_cast<cgsize_t
>(TRUST2CGNS.get_global_nb_elem_face_offset()[indZ]);
928 if (cgp_poly_section_write(fileId_, baseId_.back(), zoneId_.back(),
"NFACE_n", CGNS_ENUMV(NFACE_n), start, end, maxoffset, 0, §ionId2.back()) != CG_OK)
929 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_over_zone : cgp_poly_section_write !" << finl, TRUST_CGNS_ERROR();
933 end = start +
static_cast<cgsize_t
>(TRUST2CGNS.get_global_nb_elem()[indZ]) -1;
934 cgsize_t maxoffset =
static_cast<cgsize_t
>(TRUST2CGNS.get_global_nb_elem_som_offset()[indZ]);
936 if (cgp_poly_section_write(fileId_, baseId_.back(), zoneId_.back(),
"NGON_n", CGNS_ENUMV(NGON_n), start, end, maxoffset, 0, §ionId.back()) != CG_OK)
937 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_over_zone : cgp_poly_section_write !" << finl, TRUST_CGNS_ERROR();
942 if (cgp_section_write(fileId_, baseId_.back(), zoneId_.back(),
"Elem", cgns_type_elem, start, end, 0, §ionId.back()) != CG_OK)
943 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_over_zone : cgp_section_write !" << finl, TRUST_CGNS_ERROR();
947 zoneId_par_.push_back(zoneId_);
952 cgsize_t min = 1, max = nb_som;
954 if (all_write) indx = proc_me;
956 for (
int i = 0; i < nb_zones_to_write; i++)
957 if (proc_non_zero_elem[i] == proc_me)
964 cgns_helper_.cgns_write_grid_coord_data<TYPE_ECRITURE_CGNS::PAR_OVER>(icelldim, fileId_, baseId_.back(), zoneId_par_.back()[indx],
965 coordsIdx[indx], coordsIdy[indx], coordsIdz.empty() ? -123 : coordsIdz[indx],
966 min, max, xCoords, yCoords, zCoords);
969 if (cgns_type_elem == CGNS_ENUMV(NGON_n))
973 const std::vector<cgsize_t>& fs = TRUST2CGNS.get_local_fs(),
974 &fs_offset = TRUST2CGNS.get_local_fs_offset();
976 max = min + TRUST2CGNS.get_nb_fs() - 1;
978 if (cgp_poly_elements_write_data(fileId_, baseId_.back(), zoneId_par_.back()[indx], sectionId[indx], min, max, fs.data(), fs_offset.data()) != CG_OK)
979 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_over_zone : cgp_poly_elements_write_data !" << finl, TRUST_CGNS_ERROR();
981 const std::vector<cgsize_t>& ef = TRUST2CGNS.get_local_ef(),
982 &ef_offset = TRUST2CGNS.get_local_ef_offset();
984 min = max + 1, max = min + TRUST2CGNS.get_nb_ef() - 1;
986 if (cgp_poly_elements_write_data(fileId_, baseId_.back(), zoneId_par_.back()[indx], sectionId2[indx], min, max, ef.data(), ef_offset.data()) != CG_OK)
987 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_over_zone : cgp_poly_elements_write_data !" << finl, TRUST_CGNS_ERROR();
991 const std::vector<cgsize_t>& es = TRUST2CGNS.get_local_es(),
992 &es_offset = TRUST2CGNS.get_local_es_offset();
994 max = min + TRUST2CGNS.get_nb_es() -1;
996 if (cgp_poly_elements_write_data(fileId_, baseId_.back(), zoneId_par_.back()[indx], sectionId[indx], min, max, es.data(), es_offset.data()) != CG_OK)
997 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_over_zone : cgp_poly_elements_write_data !" << finl, TRUST_CGNS_ERROR();
1002 std::vector<cgsize_t> elems;
1003 TRUST2CGNS.convert_connectivity(cgns_type_elem, elems);
1006 if (cgp_elements_write_data(fileId_, baseId_.back(), zoneId_par_.back()[indx], sectionId[indx], min, max, elems.
data()) != CG_OK)
1007 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_over_zone : cgp_elements_write_data !" << finl, TRUST_CGNS_ERROR();
1010 TRUST2CGNS.clear_vectors();
1014void Ecrire_CGNS::cgns_write_field_par_over_zone(
const int comp,
const double temps,
const Nom& id_du_champ,
const Nom& id_du_domaine,
const Nom& localisation,
const Nom& nom_dom,
const DoubleTab& valeurs)
1018 const std::string LOC = Motcle(localisation).getString();
1019 Motcle id_du_champ_modifie = TRUST_2_CGNS::modify_field_name_for_post(id_du_champ, id_du_domaine, LOC, fieldId_som_, fieldId_elem_, fieldId_faces_);
1020 const Nom& id_champ = id_du_champ_modifie;
1023 int ind_glob = -123, ind_base = -123;
1024 TRUST_2_CGNS::init_glob_base_domain_idx(doms_written_, nom_dom,
true , LOC, ind_glob, ind_base);
1032 const TRUST_2_CGNS& TRUST2CGNS = T2CGNS_[ind_base];
1034 const int nb_zones_to_write = TRUST2CGNS.nb_procs_writing();
1035 const bool all_write = TRUST2CGNS.all_procs_write();
1037 cgns_helper_.cgns_sol_write<TYPE_ECRITURE_CGNS::PAR_OVER>(nb_zones_to_write, fileId_, baseId_[ind_glob], ind_glob,
1038 static_cast<int>(time_post_.size() - 1), zoneId_par_[ind_glob], LOC,
1039 solname_som_, solname_elem_, solname_faces_,
1040 solname_som_written_, solname_elem_written_, solname_faces_written_,
1041 flowId_som_, flowId_elem_, flowId_faces_);
1043 cgns_helper_.cgns_field_write<TYPE_ECRITURE_CGNS::PAR_OVER>(nb_zones_to_write, fileId_, baseId_[ind_glob], ind_glob, zoneId_par_[ind_glob], LOC,
1044 flowId_som_, flowId_elem_, flowId_faces_, id_champ.
getChar(),
1045 fieldId_som_, fieldId_elem_, fieldId_faces_);
1051 cgsize_t min = 1, max = nb_vals;
1053 const std::vector<int>& proc_non_zero_write= TRUST2CGNS.get_proc_non_zero_elem();
1054 if (all_write) indx = proc_me;
1056 for (
int i = 0; i < nb_zones_to_write; i++)
1057 if (proc_non_zero_write[i] == proc_me)
1065 const Domaine_VF& dom_vf = ref_cast(Domaine_VF, domaine_dis_.valeur());
1066 DoubleTrav new_vals;
1067 TRUST_2_CGNS::map_face_values(dom_vf, valeurs, new_vals);
1071 cgns_helper_.cgns_field_write_data<TYPE_ECRITURE_CGNS::PAR_OVER>(fileId_, baseId_[ind_glob], indx , zoneId_par_[ind_glob], LOC,
1072 flowId_som_, flowId_elem_, flowId_faces_,
1073 fieldId_som_, fieldId_elem_, fieldId_faces_,
1074 comp, min, max, new_vals);
1077 cgns_helper_.cgns_field_write_data<TYPE_ECRITURE_CGNS::PAR_OVER>(fileId_, baseId_[ind_glob], indx , zoneId_par_[ind_glob], LOC,
1078 flowId_som_, flowId_elem_, flowId_faces_,
1079 fieldId_som_, fieldId_elem_, fieldId_faces_,
1080 comp, min, max, valeurs);
1090void Ecrire_CGNS::cgns_write_domaine_par_in_zone(
const Domaine * domaine,
const Nom& nom_dom,
const DoubleTab& les_som,
const IntTab& les_elem,
const Motcle& type_elem)
1094 if (is_deformable_ && !first_time_post_)
1096 cgns_write_domaine_deformable_par_in_zone(domaine, nom_dom, les_som, les_elem, type_elem);
1100 doms_written_.push_back(nom_dom);
1103 T2CGNS_.push_back(TRUST_2_CGNS());
1104 TRUST_2_CGNS& TRUST2CGNS = T2CGNS_.back();
1105 TRUST2CGNS.associer_domaine_TRUST(domaine, domaine_dis_ ? &(domaine_dis_.valeur()) :
nullptr,
1106 les_som, les_elem, postraiter_domaine_, discr_type_);
1110 assert(fs_dual_.size() > 0 && ef_dual_.size() > 0);
1111 TRUST2CGNS.associer_connec_pour_dual(fs_dual_, ef_dual_);
1114 CGNS_TYPE cgns_type_elem = TRUST2CGNS.convert_elem_type(type_elem);
1115 const bool is_polyedre = (type_elem ==
"POLYEDRE" || type_elem ==
"PRISME" || type_elem ==
"PRISME_HEXAG");
1116 const int icelldim = TRUST2CGNS.topo_dim_from_elem(cgns_type_elem, is_polyedre);
1120 std::vector<double> xCoords, yCoords, zCoords;
1121 TRUST2CGNS.fill_coords(xCoords, yCoords, zCoords);
1123 TRUST2CGNS.fill_global_infos();
1125 const bool enter_group_comm = is_comm_group_mode();
1127 const int proc_me = enter_group_comm ? TRUST2CGNS.get_proc_me_local_comm() :
Process::me();
1129 if (cgns_type_elem == CGNS_ENUMV(NGON_n))
1130 TRUST2CGNS.fill_global_infos_poly(is_polyedre);
1132 const int ns_tot = TRUST2CGNS.get_ns_tot(), ne_tot = TRUST2CGNS.get_ne_tot();
1134 assert (enter_group_comm || (!enter_group_comm && ns_tot > 0 && ne_tot > 0));
1136 char basename[CGNS_STR_SIZE];
1137 strcpy(basename, nom_dom.
getChar());
1139 cgns_fill_info_grid_link_file(basename, cgns_type_elem, icelldim, ns_tot, ne_tot, is_polyedre);
1148 baseId_.push_back(-123);
1149 zoneId_.push_back(-123);
1152 if (ne_tot == 0 && ns_tot == 0)
1155 if (cg_base_write(fileId_, basename, icelldim, iphysdim, &baseId_.back()) != CG_OK)
1156 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_in_zone : cg_base_write !" << finl, TRUST_CGNS_ERROR();
1159 const cgsize_t isize[3]= { ns_tot, ne_tot, 0 };
1160 int coordsIdx = -123, coordsIdy = -123, coordsIdz = -123, sectionId = -123, sectionId2 = -123;
1162 cgns_helper_.cgns_write_zone_grid_coord<TYPE_ECRITURE_CGNS::PAR_IN>(icelldim, fileId_, baseId_.back(), basename , isize,
1163 zoneId_.back(), xCoords, yCoords, zCoords, coordsIdx, coordsIdy, coordsIdz);
1166 const int ind_base_zone =
static_cast<int>(baseId_.size()) - 1;
1167 assert(ind_base_zone ==
static_cast<int>(zoneId_.size()) - 1);
1168 cgns_build_connectivity_sections_par_in_zone(cgns_type_elem, is_polyedre, TRUST2CGNS, ind_base_zone, ne_tot, sectionId, sectionId2);
1173 const std::vector<int>& incr_max_som = TRUST2CGNS.get_global_incr_max_som(),
1174 &incr_min_som = TRUST2CGNS.get_global_incr_min_som();
1176 cgsize_t min = incr_min_som[proc_me], max = incr_max_som[proc_me];
1177 assert (min <= max);
1180 cgns_helper_.cgns_write_grid_coord_data<TYPE_ECRITURE_CGNS::PAR_IN>(icelldim, fileId_, baseId_.back(), zoneId_.back(),
1181 coordsIdx, coordsIdy, coordsIdz, min, max, xCoords, yCoords, zCoords);
1184 cgns_write_connectivity_par_in_zone(cgns_type_elem, is_polyedre, TRUST2CGNS, ind_base_zone, sectionId, sectionId2);
1187 if (!is_deformable_)
1188 TRUST2CGNS.clear_vectors();
1192void Ecrire_CGNS::cgns_build_connectivity_sections_par_in_zone(
const CGNS_TYPE cgns_type_elem,
const bool is_polyedre,
1193 const TRUST_2_CGNS& TRUST2CGNS,
const int ind_base_zone,
1194 const int ne_tot,
int& sectionId,
int& sectionId2 )
const
1197 cgsize_t start = -123, end = -123;
1198 if (cgns_type_elem == CGNS_ENUMV(NGON_n))
1200 cgsize_t maxoffset = -123;
1204 const int nb_fs = TRUST2CGNS.get_nfs_tot();
1205 const int nb_fs_offset = TRUST2CGNS.get_nfs_offset_tot();
1207 start = 1, end = start + nb_fs - 1;
1208 maxoffset = nb_fs_offset;
1209 assert(start <= end);
1211 if (cgp_poly_section_write(fileId_, baseId_[ind_base_zone], zoneId_[ind_base_zone],
"NGON_n", CGNS_ENUMV(NGON_n), start, end, maxoffset, 0, §ionId) != CG_OK)
1212 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_in_zone : cgp_poly_section_write !" << finl, TRUST_CGNS_ERROR();
1214 const int nb_ef = TRUST2CGNS.get_nef_tot();
1215 const int nb_ef_offset = TRUST2CGNS.get_nef_offset_tot();
1217 start = end + 1, end = start + nb_ef - 1;
1218 maxoffset = nb_ef_offset;
1219 assert(start <= end);
1221 if (cgp_poly_section_write(fileId_, baseId_[ind_base_zone], zoneId_[ind_base_zone],
"NFACE_n", CGNS_ENUMV(NFACE_n), start, end, maxoffset, 0, §ionId2) != CG_OK)
1222 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_in_zone : cgp_poly_section_write !" << finl, TRUST_CGNS_ERROR();
1226 const int nb_es = ne_tot;
1227 const int nb_es_offset = TRUST2CGNS.get_nes_offset_tot();
1229 start = 1, end = start + nb_es - 1;
1230 maxoffset = nb_es_offset;
1232 if (cgp_poly_section_write(fileId_, baseId_[ind_base_zone], zoneId_[ind_base_zone],
"NGON_n", CGNS_ENUMV(NGON_n), start, end, maxoffset, 0, §ionId) != CG_OK)
1233 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_in_zone : cgp_poly_section_write !" << finl, TRUST_CGNS_ERROR();
1238 start = 1, end = ne_tot;
1239 assert(start <= end);
1241 if (cgp_section_write(fileId_, baseId_[ind_base_zone], zoneId_[ind_base_zone],
"Elem", cgns_type_elem, start, end, 0, §ionId) != CG_OK)
1242 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_in_zone : cgp_section_write !" << finl, TRUST_CGNS_ERROR();
1247void Ecrire_CGNS::cgns_write_connectivity_par_in_zone(
const CGNS_TYPE cgns_type_elem,
const bool is_polyedre,
1248 const TRUST_2_CGNS& TRUST2CGNS,
const int ind_base_zone,
1249 const int sectionId,
const int sectionId2)
const
1252 const bool enter_group_comm = is_comm_group_mode();
1254 const int proc_me = enter_group_comm ? TRUST2CGNS.get_proc_me_local_comm() :
Process::me();
1257 if (cgns_type_elem == CGNS_ENUMV(NGON_n))
1261 const std::vector<cgsize_t>& fs = TRUST2CGNS.get_local_fs(),
1262 &fs_offset = TRUST2CGNS.get_local_fs_offset();
1264 const std::vector<int>& incr_min_face_som = TRUST2CGNS.get_global_incr_min_face_som(),
1265 &incr_max_face_som = TRUST2CGNS.get_global_incr_max_face_som();
1267 min = incr_min_face_som[proc_me], max = incr_max_face_som[proc_me];
1268 assert (min <= max);
1270 if (cgp_poly_elements_write_data(fileId_, baseId_[ind_base_zone], zoneId_[ind_base_zone], sectionId, min, max, fs.data(), fs_offset.data()) != CG_OK)
1271 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_in_zone : cgp_poly_elements_write_data !" << finl, TRUST_CGNS_ERROR();
1273 const std::vector<cgsize_t>& ef = TRUST2CGNS.get_local_ef(),
1274 &ef_offset = TRUST2CGNS.get_local_ef_offset();
1276 const std::vector<int>& incr_min_elem_face = TRUST2CGNS.get_global_incr_min_elem_face(),
1277 &incr_max_elem_face = TRUST2CGNS.get_global_incr_max_elem_face();
1279 min = incr_max_face_som.back() + incr_min_elem_face[proc_me];
1280 max = incr_max_face_som.back() + incr_max_elem_face[proc_me];
1281 assert (min <= max);
1283 if (cgp_poly_elements_write_data(fileId_, baseId_[ind_base_zone], zoneId_[ind_base_zone], sectionId2, min, max, ef.data(), ef_offset.data()) != CG_OK)
1284 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_in_zone : cgp_poly_elements_write_data !" << finl, TRUST_CGNS_ERROR();
1288 const std::vector<cgsize_t>& es = TRUST2CGNS.get_local_es(),
1289 &es_offset = TRUST2CGNS.get_local_es_offset();
1291 const std::vector<int>& incr_max_elem = TRUST2CGNS.get_global_incr_max_elem(),
1292 &incr_min_elem = TRUST2CGNS.get_global_incr_min_elem();
1294 min = incr_min_elem[proc_me], max = incr_max_elem[proc_me];
1295 assert (min <= max);
1297 if (cgp_poly_elements_write_data(fileId_, baseId_[ind_base_zone], zoneId_[ind_base_zone], sectionId, min, max, es.data(), es_offset.data()) != CG_OK)
1298 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_in_zone : cgp_poly_elements_write_data !" << finl, TRUST_CGNS_ERROR();
1303 std::vector<cgsize_t> elems;
1304 TRUST2CGNS.convert_connectivity(cgns_type_elem, elems);
1306 const std::vector<int>& incr_max_elem = TRUST2CGNS.get_global_incr_max_elem(),
1307 &incr_min_elem = TRUST2CGNS.get_global_incr_min_elem();
1309 min = incr_min_elem[proc_me], max = incr_max_elem[proc_me];
1310 assert (min <= max);
1312 if (cgp_elements_write_data(fileId_, baseId_[ind_base_zone], zoneId_[ind_base_zone], sectionId, min, max, elems.
data()) != CG_OK)
1313 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_par_in_zone : cgp_elements_write_data !" << finl, TRUST_CGNS_ERROR();
1318void Ecrire_CGNS::cgns_write_field_par_in_zone(
const int comp,
const double temps,
const Nom& id_du_champ,
const Nom& id_du_domaine,
const Nom& localisation,
const Nom& nom_dom,
const DoubleTab& valeurs)
1321 const int nb_vals = valeurs.
dimension(0);
1322 const std::string LOC = Motcle(localisation).getString();
1323 Motcle id_du_champ_modifie = TRUST_2_CGNS::modify_field_name_for_post(id_du_champ, id_du_domaine, LOC, fieldId_som_, fieldId_elem_, fieldId_faces_);
1324 const Nom& id_champ = id_du_champ_modifie;
1327 int ind_glob = -123, ind_base = -123;
1328 TRUST_2_CGNS::init_glob_base_domain_idx(doms_written_, nom_dom,
true , LOC, ind_glob, ind_base);
1336 cgns_helper_.cgns_sol_write<TYPE_ECRITURE_CGNS::PAR_IN>(1 , fileId_, baseId_[ind_glob], ind_glob,
1337 static_cast<int>(time_post_.size() - 1), zoneId_, LOC,
1338 solname_som_, solname_elem_, solname_faces_,
1339 solname_som_written_, solname_elem_written_, solname_faces_written_,
1340 flowId_som_, flowId_elem_, flowId_faces_);
1342 cgns_helper_.cgns_field_write<TYPE_ECRITURE_CGNS::PAR_IN>(1 , fileId_, baseId_[ind_glob], ind_glob, zoneId_, LOC,
1343 flowId_som_, flowId_elem_,flowId_faces_,
1344 id_champ.
getChar(), fieldId_som_, fieldId_elem_, fieldId_faces_);
1349 const TRUST_2_CGNS& TRUST2CGNS = T2CGNS_[ind_base];
1350 const bool enter_group_comm = is_comm_group_mode();
1352 const int proc_me = enter_group_comm ? TRUST2CGNS.get_proc_me_local_comm() :
Process::me();
1354 cgsize_t min = -123, max = -123;
1358 const std::vector<int>& incr_max_som = TRUST2CGNS.get_global_incr_max_som(),
1359 &incr_min_som = TRUST2CGNS.get_global_incr_min_som();
1361 min = incr_min_som[proc_me], max = incr_max_som[proc_me];
1365 const std::vector<int>& incr_max_elem = TRUST2CGNS.get_global_incr_max_elem(),
1366 &incr_min_elem = TRUST2CGNS.get_global_incr_min_elem();
1368 min = incr_min_elem[proc_me], max = incr_max_elem[proc_me];
1373 const Domaine_VF& dom_vf = ref_cast(Domaine_VF, domaine_dis_.valeur());
1374 DoubleTrav new_vals;
1375 TRUST_2_CGNS::map_face_values(dom_vf, valeurs, new_vals);
1377 cgns_helper_.cgns_field_write_data<TYPE_ECRITURE_CGNS::PAR_IN>(fileId_, baseId_[ind_glob], ind_glob, zoneId_, LOC,
1378 flowId_som_, flowId_elem_, flowId_faces_,
1379 fieldId_som_, fieldId_elem_, fieldId_faces_,
1380 comp, min, max, new_vals);
1383 cgns_helper_.cgns_field_write_data<TYPE_ECRITURE_CGNS::PAR_IN>(fileId_, baseId_[ind_glob], ind_glob, zoneId_, LOC,
1384 flowId_som_, flowId_elem_, flowId_faces_,
1385 fieldId_som_, fieldId_elem_, fieldId_faces_,
1386 comp, min, max, valeurs);
1392void Ecrire_CGNS::cgns_write_domaine_deformable_par_in_zone(
const Domaine * domaine,
const Nom& nom_dom,
const DoubleTab& les_som,
const IntTab& les_elem,
const Motcle& type_elem)
1395 const int ind = TRUST_2_CGNS::get_index_nom_vector(doms_written_, nom_dom);
1396 TRUST_2_CGNS& TRUST2CGNS = T2CGNS_[ind];
1397 TRUST2CGNS.associer_domaine_TRUST(domaine, domaine_dis_ ? &(domaine_dis_.valeur()) :
nullptr,
1398 les_som, les_elem, postraiter_domaine_, discr_type_);
1400 CGNS_TYPE cgns_type_elem = TRUST2CGNS.convert_elem_type(type_elem);
1401 const bool is_polyedre = (type_elem ==
"POLYEDRE" || type_elem ==
"PRISME" || type_elem ==
"PRISME_HEXAG");
1402 const int icelldim = TRUST2CGNS.topo_dim_from_elem(cgns_type_elem, is_polyedre);
1405 std::vector<double> xCoords, yCoords, zCoords;
1406 TRUST2CGNS.fill_coords(xCoords, yCoords, zCoords);
1408 char basename[CGNS_STR_SIZE];
1409 strcpy(basename, nom_dom.
getChar());
1413 TRUST2CGNS.fill_global_infos();
1414 if (cgns_type_elem == CGNS_ENUMV(NGON_n))
1415 TRUST2CGNS.fill_global_infos_poly(is_polyedre);
1418 const int ns_tot = TRUST2CGNS.get_ns_tot(), ne_tot = TRUST2CGNS.get_ne_tot();
1419 const bool enter_group_comm = is_comm_group_mode();
1420 const int proc_me = enter_group_comm ? TRUST2CGNS.get_proc_me_local_comm() :
Process::me();
1422 int coordsIdx = -123, coordsIdy = -123, coordsIdz = -123;
1428 if (ne_tot == 0 && ns_tot == 0)
1433 if (cg_grid_write(fileId_, baseId_[ind], zoneId_[ind], grid_name_loc_.c_str(), &G) != CG_OK)
1434 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_par_in_zone : cg_grid_write !" << finl, TRUST_CGNS_ERROR();
1436 if (cg_goto(fileId_, baseId_[ind],
"Zone_t",zoneId_[ind],
"GridCoordinates_t", G,
"end") != CG_OK)
1437 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_par_in_zone : cg_goto Zone_t !" << finl, TRUST_CGNS_ERROR();
1439 const cgsize_t dims[1] = { ns_tot };
1441 if (cgp_array_write(
"CoordinateX", CGNS_ENUMV(RealDouble), 1, dims, &coordsIdx) != CG_OK)
1442 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_par_in_zone : cgp_array_write CoordinateX !" << finl, TRUST_CGNS_ERROR();
1444 if (cgp_array_write(
"CoordinateY", CGNS_ENUMV(RealDouble), 1, dims, &coordsIdy) != CG_OK)
1445 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_par_in_zone : cgp_array_write CoordinateY !" << finl, TRUST_CGNS_ERROR();
1448 if (cgp_array_write(
"CoordinateZ", CGNS_ENUMV(RealDouble), 1, dims, &coordsIdz) != CG_OK)
1449 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_par_in_zone : cgp_array_write CoordinateZ !" << finl, TRUST_CGNS_ERROR();
1453 const std::vector<int>& incr_max_som = TRUST2CGNS.get_global_incr_max_som(),
1454 &incr_min_som = TRUST2CGNS.get_global_incr_min_som();
1456 const cgsize_t min = incr_min_som[proc_me], max = incr_max_som[proc_me];
1457 assert (min <= max);
1459 if (cgp_array_write_data(coordsIdx, &min, &max, xCoords.data()) != CG_OK)
1460 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_par_in_zone : cgp_array_write_data CoordinateX !" << finl, TRUST_CGNS_ERROR();
1462 if (cgp_array_write_data(coordsIdy, &min, &max, yCoords.data()) != CG_OK)
1463 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_par_in_zone : cgp_array_write_data CoordinateY !" << finl, TRUST_CGNS_ERROR();
1466 if (cgp_array_write_data(coordsIdz, &min, &max, zCoords.data()) != CG_OK)
1467 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_par_in_zone : cgp_array_write_data CoordinateZ !" << finl, TRUST_CGNS_ERROR();
1480 if (ne_tot == 0 && ns_tot == 0)
1483 if (cg_base_write(fileId_, basename, icelldim, iphysdim, &baseId_[ind]) != CG_OK)
1484 Cerr <<
"Error Ecrire_CGNS::cgns_write_domaine_deformable_par_in_zone : cg_base_write !" << finl, TRUST_CGNS_ERROR();
1486 const cgsize_t isize[3]= { ns_tot, ne_tot, 0 };
1488 cgns_helper_.cgns_write_zone_grid_coord<TYPE_ECRITURE_CGNS::PAR_IN>(icelldim, fileId_, baseId_[ind], basename , isize,
1489 zoneId_[ind], xCoords, yCoords, zCoords, coordsIdx, coordsIdy, coordsIdz);
1491 int sectionId = -123, sectionId2 = -123;
1493 const bool should_write_conn = (is_lagrangian_ || glob_min_nb_elem <= 0);
1496 sizeId_.push_back( { isize[0], isize[1] } );
1499 if (should_write_conn)
1500 cgns_build_connectivity_sections_par_in_zone(cgns_type_elem, is_polyedre, TRUST2CGNS, ind, ne_tot, sectionId, sectionId2);
1504 const std::vector<int>& incr_max_som = TRUST2CGNS.get_global_incr_max_som(),
1505 &incr_min_som = TRUST2CGNS.get_global_incr_min_som();
1507 cgsize_t min = incr_min_som[proc_me], max = incr_max_som[proc_me];
1508 assert (min <= max);
1511 cgns_helper_.cgns_write_grid_coord_data<TYPE_ECRITURE_CGNS::PAR_IN>(icelldim, fileId_, baseId_[ind], zoneId_[ind],
1512 coordsIdx, coordsIdy, coordsIdz, min, max, xCoords, yCoords, zCoords);
1515 if (should_write_conn)
1516 cgns_write_connectivity_par_in_zone(cgns_type_elem, is_polyedre, TRUST2CGNS, ind, sectionId, sectionId2);
1519 if (!should_write_conn)
1521 std::string linkfile = (enter_group_comm ? Nom(baseFile_name_).nom_me(proc_maitre_local_comm_).getString() : baseFile_name_) +
1522 ".solution." + cgns_helper_.convert_double_to_string(time_post_[0]) +
".cgns";
1524 TRUST_2_CGNS::remove_slash_linkfile(linkfile);
1526 cgns_helper_.cgns_write_connectivity_deformable_links(fileId_, baseId_[ind], zoneId_[ind], linkfile, baseZone_name_[ind], baseZone_name_[ind],
1527 connectname_[ind],
"Ecrire_CGNS::cgns_write_domaine_deformable_par_in_zone");
1538void Ecrire_CGNS::cgns_write_domaine_dual(
const Nom& nom_dom_init,
const int est_le_premier_post,
const Nom& nom_dom_faces)
1540 Cerr <<
"Writing the Dual mesh of " << nom_dom_init <<
" in a CGNS format ..." << finl;
1541 assert(domaine_dis_);
1543 Process::exit(
"Dimension is not defined. Check your data file.");
1544 const Domaine_VF& dom_vf = ref_cast(Domaine_VF, domaine_dis_.valeur());
1545 const auto& dual_m = dom_vf.get_mc_dual_mesh();
1549 dual_m->checkConsistency();
1552 const Nom dom_dual_nom = (nom_dom_faces !=
"??") ? nom_dom_faces : Nom(dual_m->getName());
1554 dom_dual.
nommer(dom_dual_nom);
1559 int nnodes =
static_cast<int>(dual_m->getNumberOfNodes());
1560 const double *coord = dual_m->getCoords()->begin();
1565 int ncells =
static_cast<int>(dual_m->getNumberOfCells());
1567 ArrOfInt conn, connIndex;
1568 int conn_size =
static_cast<int>(dual_m->getNodalConnectivity()->getNbOfElems()),
1569 conn_indx_size=
static_cast<int>(dual_m->getNodalConnectivityIndex()->getNbOfElems());
1571 const auto *c = dual_m->getNodalConnectivity()->
begin(),
1572 *cI = dual_m->getNodalConnectivityIndex()->begin();
1575 std::copy(c, c + conn_size, conn.
addr());
1576 connIndex.
resize(conn_indx_size);
1577 std::copy(cI, cI + conn_indx_size, connIndex.
addr());
1579 int mesh_type_cell =
static_cast<int>(conn[connIndex[0]]);
1582 if (mesh_type_cell == INTERP_KERNEL::NORM_TRI3)
1583 type_cell =
"Triangle";
1584 else if (mesh_type_cell == INTERP_KERNEL::NORM_POLYHED)
1585 type_cell =
"Polyedre";
1588 Cerr <<
"Cell type " << mesh_type_cell <<
" is not supported yet. It should be only triangle (2D) and polyedre (3D). Call the 911 !!" << finl;
1592 Elem_geom type_elem;
1593 type_elem.typer(type_cell);
1597 if (sub_type(Polyedre, type_elem.valeur()))
1600 for (
int i = 0; i < conn_size; i++)
1601 if (conn[i]<0) marker++;
1602 int num_nodes = conn_size - ncells - marker;
1603 int nfaces = ncells + marker;
1604 ArrOfInt nodes(num_nodes), facesIndex(nfaces+1), polyhedronIndex(ncells+1);
1605 int face=0, node = 0;
1606 for (
int i = 0; i < ncells; i++)
1608 polyhedronIndex[i] = face;
1610 const int index = connIndex[i] + 1;
1611 const int nb_som =
static_cast<int>(connIndex[i + 1] - index);
1612 for (
int j = 0; j < nb_som; j++)
1614 if (j==0 || conn[index + j]<0)
1615 facesIndex[face++] = node;
1616 if (conn[index + j]>=0)
1617 nodes[node++] = conn[index + j];
1620 facesIndex[nfaces] = node;
1621 polyhedronIndex[ncells] = face;
1622 ref_cast(Polyedre,type_elem.valeur()).affecte_connectivite_numero_global(nodes, facesIndex, polyhedronIndex, les_elems);
1626 for (
int i = 0; i < ncells; i++)
1628 const int index = connIndex[i] + 1;
1629 const int nb_som =
static_cast<int>(connIndex[i + 1] - index);
1630 if (i==0) les_elems.
resize(ncells, nb_som);
1631 for (
int j = 0; j < nb_som; j++)
1632 les_elems(i, j) = conn[index + j];
1637 conn_trust_to_med(les_elems,type_elem->que_suis_je(),
false);
1640 dom_dual.type_elem() = type_elem;
1642 dom_dual.type_elem()->associer_domaine(dom_dual);
1649 fill_connectivity_from_mc_mesh(dual_m, fs_dual_, ef_dual_);
1651 cgns_write_domaine(&dom_dual, dom_dual_nom, sommets, les_elems, type_cell);
DoubleTab_t & les_sommets()
void nommer(const Nom &nom) override
Donne un nom a l'Objet_U Methode virtuelle a surcharger.
classe Domaine_dis_base Cette classe est la base de la hierarchie des domaines discretisees.
Une chaine de caractere (Nom) en majuscules.
class Nom Une chaine de caractere pour nommer les objets de TRUST
const char * getChar() const
Nom nom_me(int, const char *prefix=0, int without_padding=0) const
Insere _prefix000n (n=me() ou nproc()) dans un nom de fichier (par ex:toto.
const std::string & getString() const
Un tableau de chaine de caracteres (VECT(Nom)).
static bool KEEP_FILES_BEFORE_RESET_TIME
static bool PARALLEL_OVER_ZONE
static const Comm_Group & get_user_defined_group()
Renvoie une reference au groupe sur defini par l'utilisateur.
static double mp_min(double)
static bool is_parallel()
static int me()
renvoie mon rang dans le groupe de communication courant.
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
_SIZE_ size_array() const
void resize(_SIZE_ new_size, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
void resize(_SIZE_ n, RESIZE_OPTIONS opt=RESIZE_OPTIONS::COPY_INIT)
_SIZE_ dimension(int d) const