16#include <Convert_ICoCoTrioField.h>
17#include <ICoCoTrioField.h>
18#include <ICoCoMEDDoubleField.hxx>
20#include <Champ_Generique_base.h>
21#include <Domaine_VF.h>
23#include <Comm_Group.h>
26void affecte_double_avec_doubletab(
double** p,
const ArrOfDouble& trio)
32void affecte_int_avec_inttab(
int** p,
const ArrOfInt& trio)
36 memcpy(*p,trio.
addr(),sz*
sizeof(
int));
44 afield._time1 = afield._time2 = ch.
get_time(), afield._itnumber = 0;
47 afield._has_field_ownership =
true;
50 const DoubleTab& vals = champ_ecriture.
valeurs();
51 afield._nb_field_components = vals.
nb_dim() > 1 ? vals.
dimension(1) : 1;
52 affecte_double_avec_doubletab(&afield._field, vals);
57 build_triomesh(dom_dis, afield, 0, 0);
60 afield._time1 = afield._time2 = 0.0, afield._itnumber = 0;
63 afield._has_field_ownership =
true;
64 const DoubleTab& vals = ch.
valeurs();
65 afield._nb_field_components = vals.
nb_dim() > 1 ? vals.
dimension(1) : 1;
66 affecte_double_avec_doubletab(&afield._field, vals);
69void build_triomesh(
const Domaine_dis_base& dom_dis, ICoCo::TrioField& afield,
int type,
int loc_faces)
72 const Domaine& dom = dom_dis.
domaine();
80 affecte_double_avec_doubletab(&afield._coords, coord);
84 Motcle type_elem(type_elem_);
85 type_elem.prefix(
"_AXI");
86 if (type_elem !=
Motcle(type_elem_))
88 if (type_elem ==
"QUADRILATERE_2D")
89 type_elem =
"SEGMENT_2D";
90 if (type_elem ==
"RECTANGLE_2D")
91 type_elem =
"RECTANGLE";
93 if ((type_elem ==
"RECTANGLE") || (type_elem ==
"QUADRANGLE") || (type_elem ==
"TRIANGLE") || (type_elem ==
"TRIANGLE_3D") || (type_elem ==
"QUADRANGLE_3D") || (type_elem ==
"POLYGONE") || (type_elem ==
"POLYGONE_3D"))
95 else if ((type_elem ==
"HEXAEDRE") || (type_elem ==
"HEXAEDRE_VEF") || (type_elem ==
"POLYEDRE") || (type_elem ==
"PRISME") || (type_elem ==
"TETRAEDRE"))
97 else if ((type_elem ==
"SEGMENT_2D") || (type_elem ==
"SEGMENT"))
101 Cerr <<
"build_triofield: " << type_elem<<
" not coded" <<finl;
106 if (loc_faces) afield._mesh_dim--;
108 if (loc_faces || type_elem !=
"POLYEDRE")
112 afield._nodes_per_elem = std::max(conn.
dimension(1), type_elem ==
"POLYGONE" || type_elem ==
"POLYGONE_3D" || type_elem ==
"POLYEDRE" ? (
int) 5 : 0);
113 afield._connectivity =
new int[afield._nb_elems * afield._nodes_per_elem];
114 for (
int i = 0; i < afield._nb_elems; i++)
115 for (
int j = 0; j < afield._nodes_per_elem; j++)
116 afield._connectivity[afield._nodes_per_elem * i + j] = j < conn.
dimension(1) ? conn(i, j) : -1;
120 const Polyedre& poly = ref_cast(Polyedre, dom.type_elem().valeur());
123 int e, f, s, nef_max = 0, nfs_max = 0;
124 for (e = 0; e + 1 < e_fi.
size_array(); e++) nef_max = std::max(nef_max, e_fi(e + 1) - e_fi(e));
125 for (f = 0; f + 1 < f_si.size_array(); f++) nfs_max = std::max(nfs_max, f_si(f + 1) - f_si(f));
126 afield._nodes_per_elem = std::max(nef_max * (nfs_max + 1), (
int) 9);
127 int *p = afield._connectivity =
new int[afield._nb_elems * afield._nodes_per_elem];
128 for (e = 0; e < afield._nb_elems; e++)
131 for (f = e_fi(e); f < e_fi(e + 1); f++, *p = -1, p++)
132 for (s = f_si(f); s < f_si(f + 1); s++)
133 *p = e_s(e, sl(s)), p++;
135 for ( ; p < afield._connectivity + (e + 1) * afield._nodes_per_elem; p++) *p = -1;
141#include <MEDCouplingUMesh.hxx>
142#include <MEDCouplingFieldDouble.hxx>
148using ICoCo::TrioField;
149using ICoCo::MEDDoubleField;
161MEDDoubleField build_medfield(TrioField& triofield)
163 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingUMesh> mesh(MEDCoupling::MEDCouplingUMesh::New(
"",triofield._mesh_dim));
164 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> coo(MEDCoupling::DataArrayDouble::New());
165 coo->alloc(triofield._nbnodes,triofield._space_dim);
166 mesh->setCoords(coo);
167 double *ptr(coo->getPointer());
168 std::copy(triofield._coords,triofield._coords+triofield._space_dim*triofield._nbnodes,ptr);
169 mesh->allocateCells(triofield._nb_elems);
170 INTERP_KERNEL::NormalizedCellType elemtype;
171 switch(triofield._mesh_dim)
175 switch (triofield._nodes_per_elem)
178 elemtype=INTERP_KERNEL::NORM_SEG2;
181 throw INTERP_KERNEL::Exception(
"incompatible Trio field - wrong nb of nodes per elem");
187 switch (triofield._nodes_per_elem)
190 elemtype=INTERP_KERNEL::NORM_SEG2;
193 throw INTERP_KERNEL::Exception(
"incompatible Trio field - wrong nb of nodes per elem");
199 switch (triofield._nodes_per_elem)
202 elemtype=INTERP_KERNEL::NORM_TRI3;
205 elemtype=INTERP_KERNEL::NORM_QUAD4;
208 elemtype=INTERP_KERNEL::NORM_POLYGON;
214 switch (triofield._nodes_per_elem)
217 elemtype=INTERP_KERNEL::NORM_TETRA4;
220 elemtype=INTERP_KERNEL::NORM_HEXA8;
223 elemtype=INTERP_KERNEL::NORM_POLYHED;
227 throw INTERP_KERNEL::Exception(
"incompatible Trio field - wrong mesh dimension");
232 MEDCoupling::MCAuto<MEDCoupling::MEDCouplingFieldDouble> field;
233 int *conn(
new int[triofield._nodes_per_elem]);
234 for (
int i=0; i<triofield._nb_elems; i++)
237 for(
int j=0; j<triofield._nodes_per_elem; j++)
239 conn[j]=triofield._connectivity[i*triofield._nodes_per_elem+j];
241 if (elemtype==INTERP_KERNEL::NORM_QUAD4)
248 if (elemtype==INTERP_KERNEL::NORM_HEXA8)
258 int size = triofield._nodes_per_elem;
259 while (conn[size - 1] == -1) size--;
262 std::vector<mcIdType> conn_mc(conn, conn+size);
263 mesh->insertNextCell(elemtype,size,conn_mc.data());
265 mesh->insertNextCell(elemtype,size,conn);
269 mesh->finishInsertingCells();
273 std::vector<int> cells;
278 Cerr<<
" cells are butterflyed "<<cells[0]<<finl;
284 int nb_case=triofield.nb_values();
285 if (triofield._type==0)
287 field = MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_CELLS,MEDCoupling::ONE_TIME);
291 field = MEDCoupling::MEDCouplingFieldDouble::New(MEDCoupling::ON_NODES,MEDCoupling::ONE_TIME );
293 field->setMesh(mesh);
294 field->setNature(MEDCoupling::IntensiveMaximum);
295 MEDCoupling::MCAuto<MEDCoupling::DataArrayDouble> fieldArr(MEDCoupling::DataArrayDouble::New());
296 fieldArr->alloc(field->getNumberOfTuplesExpected(),triofield._nb_field_components);
297 field->setName(triofield.getName());
298 std::string meshName(
"SupportOf_");
299 meshName+=triofield.getName();
300 mesh->setName(meshName);
301 field->setTime(triofield._time1,0,triofield._itnumber);
302 if (triofield._field!=0)
304 for (
int i =0; i<nb_case; i++)
305 for (
int j=0; j<triofield._nb_field_components; j++)
307 fieldArr->setIJ(i,j,triofield._field[i*triofield._nb_field_components+j]);
314 triofield._field=fieldArr->getPointer();
315 for (
int i=0; i<triofield._nb_field_components*nb_case; i++)
316 triofield._field[i]=0.0;
318 field->setArray(fieldArr);
319 return MEDDoubleField(field);
324 build_triofield(ch, fl);
325 return build_medfield(fl);
336ICoCo::MEDDoubleField build_medfield(ICoCo::TrioField& ch)
338 Cerr<<
"Version compiled without MEDCoupling"<<finl;
344 Cerr<<
"Version compiled without MEDCoupling"<<finl;
class Champ_Generique_base
virtual const Domaine_dis_base & get_ref_domaine_dis_base() const
Returns a ref to the discretized domain on which the storage space will be evaluated.
virtual const Champ_base & get_champ(OWN_PTR(Champ_base) &espace_stockage) const =0
virtual double get_time() const
Returns the time of the Champ_Generique_base.
virtual Entity get_localisation(const int index=-1) const
Returns the type of geometric entities on which the discrete values are attached (NODE for a P1 field...
virtual DoubleTab & valeurs()=0
class Champ_base This class is the base of the fields hierarchy.
virtual void abort() const =0
virtual void clear()
Reset the Domaine completely except for its name.
DoubleTab_t & les_sommets()
int nb_faces() const
Returns the total number of faces.
class Domaine_dis_base This class is the base of the hierarchy of discretized domains.
virtual IntTab & face_sommets()
const Domaine & domaine() const
const Nom & le_nom() const override
Returns the name of the field.
A character string (Nom) in uppercase.
const std::string & getString() const
const Nom & que_suis_je() const
Returns the string identifying the class.
virtual const Nom & le_nom() const
Returns the name of the Objet_U. Virtual method to override: returns "neant" in this implementation.
static const Comm_Group & groupe_TRUST()
Returns a reference to the group containing all TRUST processors.
const ArrOfInt_t & getPolyhedronIndex() const
const BigArrOfInt_t & getNodes() const
const ArrOfInt_t & getFacesIndex() const
static void abort()
Abort routine for TRUST on a fatal error.
static void exit(int exit_code=-1)
Exit routine for TRUST within a Kokkos region.
_SIZE_ size_array() const
_SIZE_ dimension(int d) const