16#include <Ecrire_MED.h>
19#include <Domaine_VF.h>
22#include <medcoupling++.h>
24#include <TRUST_2_MED.h>
25#include <Sortie_Fichier_base.h>
26#include <Synonyme_info.h>
27#include <Domaine_dis_cache.h>
28#include <Domaine_VF.h>
31#include <MEDLoader.hxx>
32#include <MEDFileMesh.hxx>
33#include <MEDCouplingFieldDouble.hxx>
34#pragma GCC diagnostic ignored "-Wreorder"
35#include <MEDFileField.hxx>
36using namespace MEDCoupling;
40Add_synonym(Ecrire_MED,
"Ecrire_MED");
48template <
typename _SIZE_>
51 int nb_std = domaine.nb_front_Cl() + domaine.nb_groupes_faces();
52 return i<nb_std ? domaine.frontiere(i) : domaine.joint(i-nb_std);
56template <
typename _SIZE_>
62template <
typename _SIZE_>
68template <
typename _SIZE_>
80template <
typename _SIZE_>
94template <
typename _SIZE_>
97 Cerr<<
"syntax : Write_MED [ append ] nom_dom nom_fic "<<finl;
106 Cerr<<
" Adding "<<nom_dom<<finl;
111 Cerr << nom_dom <<
" type is " <<
objet(nom_dom).que_suis_je() << finl;
112 Cerr <<
"Only Domaine type objects can be meshed" << finl;
121template <
typename _SIZE_>
127template <
typename _SIZE_>
133template <
typename _SIZE_>
139template <
typename _SIZE_>
149template <
typename _SIZE_>
152 const Domaine_t& dom = dom_.valeur();
153 int nb_bords = dom.nb_front_Cl(), nb_faces_int = dom.nb_groupes_faces();
156 int nb_jnts = dom.nb_joints();
159 noms_bords_and_jnts.dimensionner(nb_bords+nb_jnts+nb_faces_int);
160 sz_bords_and_jnts.resize_array(nb_bords+nb_jnts+nb_faces_int);
163 for(
int i=0; i<nb_bords + nb_faces_int; i++)
168 noms_bords_and_jnts[i] =
"type_raccord_";
169 noms_bords_and_jnts[i] += front.
le_nom();
173 noms_bords_and_jnts[i] =
"groupes_faces_";
174 noms_bords_and_jnts[i] += front.
le_nom();
177 noms_bords_and_jnts[i] = front.
le_nom();
178 sz_bords_and_jnts[i] = front.
nb_faces();
188template <
typename _SIZE_>
193 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
194 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
195 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
196 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
197 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
198 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
200 Cerr <<
"*** WARNING *** The MED post-processing format will generate " <<
Process::nproc() <<
" files" << finl;
202 Cerr <<
"Use LATA format instead or contact TRUST support team." << finl;
204 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
205 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
206 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
207 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
208 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
209 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
212 ecrire_domaine_dis(append);
223 Process::exit(
"Dimension is not defined. Check your data file.");
230 assert(domaine_dis_);
232 const auto& dual_m = dom_vf.get_mc_dual_mesh();
233 MEDCouplingUMesh *dual_no_const =
const_cast<MEDCouplingUMesh *
>(dual_m);
236 MCAuto<MEDFileUMesh> mfu(MEDFileUMesh::New());
237 mfu->setName(dual_m->getName());
238 mfu->setCoords(dual_no_const->getCoords());
239 mfu->setMeshAtLevel(0, dual_no_const,
false);
243 dual_m->checkConsistency();
247 int option = (append ? 1 : 2);
248 Cerr<<
"Writing file '" << nom_fichier_<<
"' with mesh name '" << dual_m->getName() <<
"' (append=" << (append ?
"true":
"false") <<
") ..."<<finl;
249 mfu->write(nom_fichier_.getString(),
option);
254template <
typename _SIZE_>
269template <
typename _SIZE_>
275 Noms noms_bords_and_jnts;
276 ArrOfInt_t sz_bords_and_jnts;
277 get_bords_infos(noms_bords_and_jnts, sz_bords_and_jnts);
280 bool full_face_mesh = domaine_dis_ && ref_cast(
Domaine_VF, domaine_dis_.valeur()).elem_faces().size()>0;
284 assert((std::is_same<_SIZE_, int>::value));
288 const MEDCouplingUMesh *faces_mesh = dom_vf.get_mc_face_mesh();
289 MCAuto<MEDCouplingUMesh> face_mesh2 = faces_mesh->clone(
false);
290 face_mesh2->setName(mfumesh_->getName());
291 mfumesh_->setMeshAtLevel(-1, face_mesh2,
false);
292 nfaces =
static_cast<int>(faces_mesh->getNumberOfCells());
296 MCAuto<MEDCouplingUMesh> boundary_mesh(MEDCouplingUMesh::New(mcumesh_->getName(), mesh_dimension_ - 1));
297 boundary_mesh->setCoords(mcumesh_->getCoords());
299 for (
int j = 0; j < noms_bords_and_jnts.size(); j++) nfaces += sz_bords_and_jnts(j);
300 boundary_mesh->allocateCells(nfaces);
302 for (
int b=0; b < noms_bords_and_jnts.size(); b++)
304 const Frontiere_t& front = ::mes_faces_fr(dom_.valeur(),b);
305 const IntTab_t& som_fac = front.les_sommets_des_faces();
306 int_t nb_fac = som_fac.dimension(0);
307 int nb_som_fac = som_fac.dimension_int(1);
308 const Nom& typ_f_trust = front.faces().type(front.faces().type_face());
310 int boundary_mesh_dimension = -1;
311 INTERP_KERNEL::NormalizedCellType typ_fac_mc = type_geo_trio_to_type_medcoupling(typ_f_trust, boundary_mesh_dimension);
312 assert(boundary_mesh_dimension == mesh_dimension_ - 1);
315 IntTab_t som_fac_cpy = som_fac;
316 conn_trust_to_med(som_fac_cpy, typ_f_trust,
true);
318 for (int_t face_idx=0; face_idx < nb_fac; face_idx++)
320 int nvertices = nb_som_fac;
321 for (
int k = 0; k < nb_som_fac; k++)
322 if (som_fac_cpy(face_idx, k) < 0) nvertices--;
323 if(std::is_same<_SIZE_, mcIdType>::value)
326 const mcIdType* where = (mcIdType *)(som_fac_cpy.addr() + face_idx*nb_som_fac);
327 boundary_mesh->insertNextCell(typ_fac_mc, nvertices, where);
331 auto ptr = som_fac_cpy.addr() + face_idx*nb_som_fac;
332 std::vector<mcIdType> tmp(ptr, ptr+nvertices);
333 boundary_mesh->insertNextCell(typ_fac_mc, nvertices, tmp.data());
337 mfumesh_->setMeshAtLevel(-1, boundary_mesh,
false);
341 std::vector<const DataArrayIdType *> grps;
342 std::vector<MCAuto<DataArrayIdType>> grps_mem;
344 int_t face_idx = 0, start, end;
345 int nb_bords = dom_->nb_front_Cl() + dom_->nb_groupes_faces();
346 for (
int b=0; b < nb_bords; b++, face_idx=end)
348 MCAuto<DataArrayIdType> g(DataArrayIdType::New());
349 start=face_idx, end=start+sz_bords_and_jnts[b];
350 Cerr <<
" grp " << noms_bords_and_jnts[b] <<
" " << start <<
" " << end << finl;
354 g->setName(noms_bords_and_jnts[b].getChar());
355 grps_mem.push_back(g);
378 mfumesh_->setGroupsAtLevel(-1, grps);
385template <
typename _SIZE_>
389 Process::exit(
"Dimension is not defined. Check your data file.");
395 mcumesh_ = dom_->get_mc_mesh();
396 mesh_dimension_ = mcumesh_->getMeshDimension();
397 MEDCouplingUMesh *mc_no_const =
const_cast<MEDCouplingUMesh *
>(mcumesh_);
400 mfumesh_ = MEDFileUMesh::New();
401 mfumesh_->setName(mcumesh_->getName());
402 mfumesh_->setCoords(mc_no_const->getCoords());
403 mfumesh_->setMeshAtLevel(0, mc_no_const,
false);
407 mcumesh_->checkConsistency();
411 fill_faces_and_boundaries();
414 int option = (append ? 1 : 2);
415 Cerr<<
"Writing file '" << nom_fichier_<<
"' with mesh name '" << mfumesh_->getName() <<
"' (append=" << (append ?
"true":
"false") <<
") ..."<<finl;
416 mfumesh_->write(nom_fichier_.getString(),
option);
424 Process::exit(
"Ecrire_MED_32_64<trustIdType>::ecrire_domaine_dis() -- Not allowed with a 64b object!");
436template <
typename _SIZE_>
438 const Noms& noms_compo,
const Nom& type_elem,
double time)
442 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
443 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
444 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
445 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
446 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
447 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
449 Cerr <<
"*** WARNING *** The MED post-processing format will generate " <<
Process::nproc() <<
" files" << finl;
451 Cerr <<
"Use LATA format instead or contact TRUST support team." << finl;
453 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
454 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
455 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
456 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
457 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
458 Cerr <<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << finl;
464 MEDCoupling::TypeOfField field_type;
465 if (type ==
"CHAMPMAILLE")
466 field_type = MEDCoupling::ON_CELLS;
467 else if (type ==
"CHAMPPOINT")
468 field_type = MEDCoupling::ON_NODES;
469 else if (type ==
"CHAMPFACES")
470 field_type = MEDCoupling::ON_CELLS;
473 Cerr <<
"Field type " << type <<
" is not supported yet." << finl;
477 std::string file_name = nom_fichier_.
getString();
478 std::string field_name = nom_cha1.
getString();
480 if (timestep_.find(field_name)==timestep_.end())
483 std::vector<std::string> field_names = GetAllFieldNames(file_name);
484 if (std::find(field_names.begin(), field_names.end(), field_name) != field_names.end())
486 std::vector<std::pair<std::pair<int, int>,
double> > ts = GetAllFieldIterations(file_name, field_name);
487 timestep = ts[ts.size() - 1].first.first + 1;
489 timestep_.insert({field_name,timestep});
492 timestep_.at(field_name)++;
493 MCAuto<MEDCouplingFieldDouble> field(MEDCouplingFieldDouble::New(field_type, MEDCoupling::ONE_TIME));
494 field->setName(field_name);
495 field->setTime(time, timestep_.at(field_name), -1);
496 field->setTimeUnit(
"s");
499 if (nom_dom ==
"PARTICULES")
501 MEDCoupling::CheckFileForRead(file_name);
502 std::string mesh_name = nom_dom.
getString();
503 MCAuto<MEDFileMesh> mm(MEDFileMesh::New(file_name,mesh_name));
504 MEDFileMesh *mmPtr(mm);
505 MEDFileUMesh *mmuPtr=
dynamic_cast<MEDFileUMesh *
>(mmPtr);
508 std::ostringstream oss;
509 oss <<
"ReadUMeshFromFile : With fileName=\""<< file_name <<
"\", meshName=\""<< mesh_name <<
"\" exists but it is not an unstructured mesh !";
510 throw INTERP_KERNEL::Exception(oss.str());
512 const MCAuto<MEDCouplingUMesh> umesh_particles = mmuPtr->getMeshAtLevel(1);
513 field->setMesh(umesh_particles);
517 if (type ==
"CHAMPFACES")
518 field->setMesh(domaine_dis_->get_mc_face_mesh());
520 field->setMesh(dom_->get_mc_mesh());
528 MCAuto<DataArrayDouble> array(DataArrayDouble::New());
529 array->useArray(val.
addr(),
false, MEDCoupling::DeallocType::CPP_DEALLOC, size, nb_comp);
533 for (
int i = 0; i < nb_comp; i++)
534 array->setInfoOnComponent(i,
"[" + unite[i].getString() +
"]");
536 array->setInfoOnComponent(0,
"[" + unite[0].getString() +
"]");
537 field->setArray(array);
539 MCAuto<MEDFileField1TS> file(MEDFileField1TS::New());
540 file->setFieldNoProfileSBT(field);
541 file->write(file_name, 0);
551 const Noms& noms_compo,
const Nom& type_elem,
double time)
553 Process::exit(
"Ecrire_MED_32_64<trustIdType>::ecrire_champ() -- Not allowed with a 64b object!");
classe Domaine_32_64 un Domaine est un maillage compose d'un ensemble d'elements geometriques de meme...
void build_mc_face_mesh() const
Build the MEDCoupling face mesh. It is always made of polygons (in 3D) for simplicity purposes....
classe Domaine_dis_base Cette classe est la base de la hierarchie des domaines discretisees.
Classe Ecrire_MED Ecrit un fichier MED.
void ecrire_domaine_dis(bool append=true)
void ecrire_champ(const Nom &type, const Nom &nom_cha1, const DoubleTab &val, const Noms &unite, const Noms &noms_compo, const Nom &type_elem, double time)
Nom nom_fichier_
Name of the MED file to write.
Ecrire_MED_32_64(const Nom &file_name, const Domaine_t &dom)
void get_bords_infos(Noms &noms_bords_and_jnts, ArrOfInt_t &sz_bords_and_jnts) const
void ecrire_domaine_dual(bool append=true)
Domaine_32_64< _SIZE_ > Domaine_t
void set_file_name_and_dom(const Nom &file_name, const Domaine_t &dom, const Domaine_dis_base *dom_dis=nullptr)
void fill_faces_and_boundaries()
Entree & interpreter(Entree &) override
void ecrire_domaine(bool append=true)
Class defining operators and methods for all reading operation in an input flow (file,...
const Nom & le_nom() const override
Donne le nom de l'Objet_U Methode a surcharger : renvoie "neant" dans cette implementation.
int_t nb_faces() const
Renvoie le nombre de faces de la frontiere.
Classe Groupe_Face La classe sert a representer une selection de faces lu dans le fichier med.
Classe de base des objets "interprete".
static Objet_U & objet(const Nom &)
Voir Interprete_bloc::objet_global() BM: la classe Interprete n'est pas le meilleur endroit pour cett...
Une chaine de caractere (Nom) en majuscules.
class Nom Une chaine de caractere pour nommer les objets de TRUST
const std::string & getString() const
const Nom & le_nom() const override
Renvoie *this;.
Un tableau de chaine de caracteres (VECT(Nom)).
virtual Entree & readOn(Entree &)
Lecture d'un Objet_U sur un flot d'entree Methode a surcharger.
virtual Sortie & printOn(Sortie &) const
Ecriture de l'objet sur un flot de sortie Methode a surcharger.
static int multiple_files
static int nproc()
renvoie le nombre de processeurs dans le groupe courant Voir Comm_Group::nproc() et PE_Groups::curren...
static void exit(int exit_code=-1)
Routine de sortie de TRUST dans une region Kokkos.
Classe Raccord_base Cette classe est simplement une frontiere, c'est la classe de base de la.
Classe de base des flux de sortie.
_SIZE_ dimension(int d) const