Salome HOME
cd89efe8275cdcd660856041f8746883967b0f31
[tools/medcoupling.git] / src / ParaMEDMEM / ParaGRID.cxx
1 // Copyright (C) 2007-2019  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, or (at your option) any later version.
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
20 #include "ParaGRID.hxx"
21 #include "Topology.hxx"
22 #include "BlockTopology.hxx"
23 #include "MEDCouplingMemArray.hxx"
24 #include "MEDCouplingCMesh.hxx"
25 #include "InterpKernelUtilities.hxx"
26
27 #include <iostream>
28
29 using namespace std;
30
31 namespace MEDCoupling
32 {
33   
34   ParaGRID::ParaGRID(MEDCouplingCMesh* global_grid, Topology* topology) : 
35     _global_axis(), _my_domain_id(0)
36   {
37     _block_topology = dynamic_cast<BlockTopology*>(topology);
38     if(_block_topology==0)
39       throw INTERP_KERNEL::Exception(LOCALIZED("ParaGRID::ParaGRID topology must be block topology"));
40     
41     if (!_block_topology->getProcGroup()->containsMyRank())
42       return;
43     
44     int dimension=_block_topology->getDimension() ;
45     if (dimension != global_grid->getSpaceDimension())
46       throw INTERP_KERNEL::Exception(LOCALIZED("ParaGrid::ParaGrid incompatible topology"));
47     _grid=global_grid;
48     _grid->incrRef();
49     /*vector<vector<double> > xyz_array(dimension);
50       vector<pair<int,int> > local_indices = _block_topology->getLocalArrayMinMax();
51       vector <string> coordinates_names;
52       vector <string> coordinates_units;
53       for (int idim=0; idim<dimension ; idim++)
54       {
55       DataArrayDouble *array=global_grid->getCoordsAt(idim);
56       double *arrayC=array->getPointer();
57       cout << " Indices "<< local_indices[idim].first <<" "<<local_indices[idim].second<<endl;
58       for (int i=(local_indices)[idim].first; i<(local_indices)[idim].second; i++)
59       xyz_array[idim].push_back(arrayC[i]);
60       coordinates_names.push_back(array->getName());
61       coordinates_units.push_back(array->getInfoOnComponentAt(0));
62       }
63       _grid=MEDCouplingCMesh::New();
64       _grid->set(xyz_array, coordinates_names,coordinates_units);
65       _grid->setName(global_grid->getName());
66       _grid->setDescription(global_grid->getDescription());*/
67   }
68
69   ParaGRID::~ParaGRID()
70   {
71     if(_grid)
72       _grid->decrRef();
73   }
74 }