Salome HOME
Merge from BR_V5_DEV 16Feb09
[modules/med.git] / src / ParaMEDMEM / ParaGRID.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "ParaGRID.hxx"
20 #include "Topology.hxx"
21 #include "BlockTopology.hxx"
22 #include "MemArray.hxx"
23 #include "MEDCouplingSMesh.hxx"
24 #include "InterpKernelUtilities.hxx"
25
26 #include <iostream>
27
28 using namespace std;
29
30 namespace ParaMEDMEM
31 {
32   
33   ParaGRID::ParaGRID(MEDCouplingSMesh* global_grid, Topology* topology) throw(INTERP_KERNEL::Exception)
34   {
35   
36     _block_topology = dynamic_cast<BlockTopology*>(topology);
37     if(_block_topology==0)
38       throw INTERP_KERNEL::Exception(LOCALIZED("ParaGRID::ParaGRID topology must be block topology"));
39     
40     if (!_block_topology->getProcGroup()->containsMyRank())
41       return;
42     
43     int dimension=_block_topology->getDimension() ;
44     if (dimension != global_grid->getSpaceDimension())
45       throw INTERP_KERNEL::Exception(LOCALIZED("ParaGrid::ParaGrid incompatible topology"));
46     _grid=global_grid;
47     _grid->incrRef();
48     /*vector<vector<double> > xyz_array(dimension);
49       vector<pair<int,int> > local_indices = _block_topology->getLocalArrayMinMax();
50       vector <string> coordinates_names;
51       vector <string> coordinates_units;
52       for (int idim=0; idim<dimension ; idim++)
53       {
54       DataArrayDouble *array=global_grid->getCoordsAt(idim);
55       double *arrayC=array->getPointer();
56       cout << " Indices "<< local_indices[idim].first <<" "<<local_indices[idim].second<<endl;
57       for (int i=(local_indices)[idim].first; i<(local_indices)[idim].second; i++)
58       xyz_array[idim].push_back(arrayC[i]);
59       coordinates_names.push_back(array->getName());
60       coordinates_units.push_back(array->getInfoOnComponentAt(0));
61       }
62       _grid=MEDCouplingSMesh::New();
63       _grid->set(xyz_array, coordinates_names,coordinates_units);
64       _grid->setName(global_grid->getName());
65       _grid->setDescription(global_grid->getDescription());*/
66   }
67
68   ParaGRID::~ParaGRID()
69   {
70     if(_grid)
71       _grid->decrRef();
72   }
73 }