1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "ICoCoMEDField.hxx"
21 #include "ICoCoTrioField.hxx"
22 #include "ProcessorGroup.hxx"
23 #include "MEDCouplingUMesh.hxx"
24 #include "MEDCouplingFieldDouble.hxx"
25 #include "NormalizedUnstructuredMesh.hxx"
30 /*! Constructor directly attaching a MEDCouplingUMesh and a MEDCouplingFieldDouble
31 the object does not take the control the objects pointed by
35 MEDField::MEDField(ParaMEDMEM::MEDCouplingUMesh* mesh, ParaMEDMEM::MEDCouplingFieldDouble* field):
45 MEDField::MEDField(TrioField& triofield)
47 _mesh = ParaMEDMEM::MEDCouplingUMesh::New();
48 _mesh->setMeshDimension(triofield._space_dim);
49 ParaMEDMEM::DataArrayDouble *myCoords=ParaMEDMEM::DataArrayDouble::New();
50 myCoords->alloc(triofield._nbnodes,triofield._space_dim);
51 _mesh->setCoords(myCoords);
53 double *ptr=myCoords->getPointer();
54 std::copy(triofield._coords,triofield._coords+triofield._space_dim*triofield._nbnodes,ptr);
55 _mesh->allocateCells(triofield._nb_elems);
56 INTERP_KERNEL::NormalizedCellType elemtype;
57 switch (triofield._mesh_dim)
60 switch (triofield._nodes_per_elem)
63 elemtype=INTERP_KERNEL::NORM_TRI3;
66 elemtype=INTERP_KERNEL::NORM_QUAD4;
69 throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
73 switch (triofield._nodes_per_elem)
76 elemtype=INTERP_KERNEL::NORM_TETRA4;
79 elemtype=INTERP_KERNEL::NORM_HEXA8;
82 throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
86 throw INTERP_KERNEL::Exception("incompatible Trio field - wrong mesh dimension");
88 //creating a connectivity table that complies to MED (1 indexing)
89 //and passing it to _mesh
90 int* conn=new int[triofield._nodes_per_elem];
91 _mesh->setMeshDimension(triofield._mesh_dim);
92 for (int i=0; i<triofield._nb_elems;i++)
94 for(int j=0;j<triofield._nodes_per_elem;j++)
96 conn[j]=(triofield._connectivity)[i*triofield._nodes_per_elem+j];
98 _mesh->insertNextCell(elemtype,triofield._nodes_per_elem,conn);
102 _mesh->finishInsertingCells();
104 //field on the sending end
105 int nb_case=triofield.nb_values();
106 if (triofield._type==0)
108 _field = ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
112 _field = ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::ONE_TIME );
114 _field->setMesh(_mesh);
115 _field->setNature(ParaMEDMEM::ConservativeVolumic);
116 ParaMEDMEM::DataArrayDouble *fieldArr=ParaMEDMEM::DataArrayDouble::New();
117 fieldArr->alloc(_field->getNumberOfTuples(),triofield._nb_field_components);
118 _field->setName(triofield.getName().c_str());
119 std::string meshName("SupportOf_"); meshName+=_field->getName();
120 _mesh->setName(meshName.c_str());
121 _field->setTime(triofield._time1,0,triofield._itnumber);
122 if (triofield._field!=0)
124 for (int i =0; i<nb_case; i++)
125 for (int j=0; j<triofield._nb_field_components; j++)
127 fieldArr->setIJ(i,j,triofield._field[i*triofield._nb_field_components+j]);
130 //field on the receiving end
133 // the trio field points to the pointer inside the MED field
134 triofield._field=const_cast<double*> (fieldArr->getPointer());
135 for (int i=0; i<triofield._nb_field_components*nb_case;i++)
136 triofield._field[i]=0.0;
138 _field->setArray(fieldArr);
142 MEDField::~MEDField()