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_SEG2;
66 throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
69 switch (triofield._nodes_per_elem)
72 elemtype=INTERP_KERNEL::NORM_TRI3;
75 elemtype=INTERP_KERNEL::NORM_QUAD4;
78 throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
82 switch (triofield._nodes_per_elem)
85 elemtype=INTERP_KERNEL::NORM_TETRA4;
88 elemtype=INTERP_KERNEL::NORM_HEXA8;
91 throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
95 throw INTERP_KERNEL::Exception("incompatible Trio field - wrong mesh dimension");
97 //creating a connectivity table that complies to MED (1 indexing)
98 //and passing it to _mesh
99 int* conn=new int[triofield._nodes_per_elem];
100 _mesh->setMeshDimension(triofield._mesh_dim);
101 for (int i=0; i<triofield._nb_elems;i++)
103 for(int j=0;j<triofield._nodes_per_elem;j++)
105 conn[j]=(triofield._connectivity)[i*triofield._nodes_per_elem+j];
107 _mesh->insertNextCell(elemtype,triofield._nodes_per_elem,conn);
111 _mesh->finishInsertingCells();
113 //field on the sending end
114 int nb_case=triofield.nb_values();
115 if (triofield._type==0)
117 _field = ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_CELLS,ParaMEDMEM::ONE_TIME);
121 _field = ParaMEDMEM::MEDCouplingFieldDouble::New(ParaMEDMEM::ON_NODES,ParaMEDMEM::ONE_TIME );
123 _field->setMesh(_mesh);
124 _field->setNature(ParaMEDMEM::ConservativeVolumic);
125 ParaMEDMEM::DataArrayDouble *fieldArr=ParaMEDMEM::DataArrayDouble::New();
126 fieldArr->alloc(_field->getNumberOfTuples(),triofield._nb_field_components);
127 _field->setName(triofield.getName().c_str());
128 std::string meshName("SupportOf_"); meshName+=_field->getName();
129 _mesh->setName(meshName.c_str());
130 _field->setTime(triofield._time1,0,triofield._itnumber);
131 if (triofield._field!=0)
133 for (int i =0; i<nb_case; i++)
134 for (int j=0; j<triofield._nb_field_components; j++)
136 fieldArr->setIJ(i,j,triofield._field[i*triofield._nb_field_components+j]);
139 //field on the receiving end
142 // the trio field points to the pointer inside the MED field
143 triofield._field=const_cast<double*> (fieldArr->getPointer());
144 for (int i=0; i<triofield._nb_field_components*nb_case;i++)
145 triofield._field[i]=0.0;
147 _field->setArray(fieldArr);
151 MEDField::~MEDField()