1 // Copyright (C) 2007-2008 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
19 #include "ICoCoMEDField.hxx"
20 #include "ICoCoTrioField.hxx"
21 #include "ProcessorGroup.hxx"
22 #include "ParaMESH.hxx"
23 #include "ParaFIELD.hxx"
24 #include "NormalizedUnstructuredMesh.hxx"
29 /*! Constructor directly attaching a ParaMESH and a ParaFIELD
30 the object does not take the control the objects pointed by
34 MEDField::MEDField(ParaMEDMEM::ParaMESH* mesh, ParaMEDMEM::ParaFIELD* field):
37 _has_field_ownership(false),
44 MEDField::MEDField(TrioField& triofield, const ParaMEDMEM::ProcessorGroup& group):
45 _has_field_ownership(true)
47 _local_mesh = ParaMEDMEM::MEDCouplingUMesh::New();
48 _local_mesh->setMeshDimension(triofield._space_dim);
49 ParaMEDMEM::DataArrayDouble *myCoords=ParaMEDMEM::DataArrayDouble::New();
50 myCoords->alloc(triofield._nbnodes,triofield._space_dim);
51 _local_mesh->setCoords(myCoords);
52 double *ptr=myCoords->getPointer();
53 std::copy(triofield._coords,triofield._coords+triofield._space_dim*triofield._nbnodes,ptr);
54 _local_mesh->allocateCells(triofield._nb_elems);
55 INTERP_KERNEL::NormalizedCellType elemtype;
56 switch (triofield._mesh_dim)
59 switch (triofield._nodes_per_elem)
62 elemtype=INTERP_KERNEL::NORM_TRI3;
65 elemtype=INTERP_KERNEL::NORM_QUAD4;
68 throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
72 switch (triofield._nodes_per_elem)
75 elemtype=INTERP_KERNEL::NORM_TETRA4;
78 elemtype=INTERP_KERNEL::NORM_HEXA8;
81 throw INTERP_KERNEL::Exception("incompatible Trio field - wrong nb of nodes per elem");
85 throw INTERP_KERNEL::Exception("incompatible Trio field - wrong mesh dimension");
87 //creating a connectivity table that complies to MED (1 indexing)
88 //and passing it to _local_mesh
89 int* conn=new int[triofield._nb_elems*triofield._nodes_per_elem];
90 for (int i=0; i<triofield._nb_elems;i++)
91 for(int j=0;j<triofield._nodes_per_elem;j++)
93 conn[j]=(triofield._connectivity)[i*triofield._nb_elems+j];
94 _local_mesh->insertNextCell(elemtype,triofield._nodes_per_elem,conn);
98 _local_mesh->setMeshDimension(triofield._mesh_dim);
100 _mesh=new ParaMEDMEM::ParaMESH(_local_mesh, group, "support for trio field");
101 _comp_topology=new ParaMEDMEM::ComponentTopology(triofield._nb_field_components);
103 //field on the sending end
104 if (triofield._field!=0)
106 _field = new ParaMEDMEM::ParaFIELD(ParaMEDMEM::ON_CELLS,_mesh, *_comp_topology );
107 ParaMEDMEM::DataArrayDouble *fieldArr=_field->getField()->getArray();
108 _field->getField()->setName(triofield.getName().c_str());
109 _field->getField()->setTime(triofield._time1);
110 _field->getField()->setDtIt(0,triofield._itnumber);
111 for (int i =0; i<triofield._nb_elems; i++)
112 for (int j=0; j<triofield._nb_field_components; j++)
114 fieldArr->setIJ(i,j,triofield._field[i*triofield._nb_field_components+j]);
117 //field on the receiving end
120 _field = new ParaMEDMEM::ParaFIELD(ParaMEDMEM::ON_CELLS,_support, *_comp_topology );
121 _field->getField()->setName(triofield.getName().c_str());
122 _field->getField()->setTime(triofield._time1);
123 _field->getField()->setDtIt(0,triofield._itnumber);
124 // the trio field points to the pointer inside the MED field
125 triofield._field=const_cast<double*> (_field->getField()->getArray()->getPointer());
126 for (int i=0; i<triofield._nb_field_components*triofield._nb_elems;i++)
127 triofield._field[i]=0.0;
131 MEDField::~MEDField()
133 delete _comp_topology;
136 if (_has_field_ownership)