Salome HOME
MED33 porting
[tools/medcoupling.git] / src / ParaMEDMEM / ParaMESH.cxx
1 //
2 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 //
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include "ParaMESH.hxx"
22 #include "ProcessorGroup.hxx"
23 #include "MPIProcessorGroup.hxx"
24 #include "Topology.hxx"
25 #include "BlockTopology.hxx"
26 #include "MEDCouplingMemArray.hxx"
27
28 #include <fstream>
29 #include <vector>
30
31 //inclusion for the namespaces
32 using namespace std;
33
34 namespace MEDCoupling
35 {
36   ParaMESH::ParaMESH( MEDCouplingPointSet *subdomain_mesh, MEDCouplingPointSet *subdomain_face,
37             DataArrayInt *CorrespElt_local2global, DataArrayInt *CorrespFace_local2global,
38             DataArrayInt *CorrespNod_local2global, const ProcessorGroup& proc_group ):
39     _cell_mesh(subdomain_mesh),
40     _face_mesh(subdomain_face),
41     _my_domain_id(proc_group.myRank()),
42     _block_topology (new BlockTopology(proc_group, subdomain_mesh->getNumberOfCells())),
43     _explicit_topology(0),
44     _node_global(CorrespNod_local2global),
45     _face_global(CorrespFace_local2global),
46     _cell_global(CorrespElt_local2global)
47   {
48     if(_cell_mesh)
49       _cell_mesh->incrRef();
50     if(_face_mesh)
51       _face_mesh->incrRef();
52     if(CorrespElt_local2global)
53       CorrespElt_local2global->incrRef();
54     if(CorrespFace_local2global)
55       CorrespFace_local2global->incrRef();
56     if(CorrespNod_local2global)
57       CorrespNod_local2global->incrRef();
58   }
59
60   ParaMESH::ParaMESH( MEDCouplingPointSet *mesh, const ProcessorGroup& proc_group, const std::string& name):
61     _cell_mesh(mesh),
62     _face_mesh(0),
63     _my_domain_id(proc_group.myRank()),
64     _block_topology (new BlockTopology(proc_group, mesh->getNumberOfCells())),
65     _node_global(0),
66     _face_global(0)
67   {
68     if(_cell_mesh)
69       _cell_mesh->incrRef();
70     int nb_elem=mesh->getNumberOfCells();
71     _explicit_topology=new BlockTopology(proc_group,nb_elem);
72     int nbOfCells=mesh->getNumberOfCells();
73     _cell_global = DataArrayInt::New();
74     _cell_global->alloc(nbOfCells,1);
75     int *cellglobal=_cell_global->getPointer();
76     int offset = _block_topology->localToGlobal(make_pair(_my_domain_id,0));
77     for (int i=0; i<nbOfCells; i++)
78       {
79         cellglobal[i]=offset+i;
80       }
81   }
82
83   void ParaMESH::setNodeGlobal(DataArrayInt *nodeGlobal)
84   {
85     if(nodeGlobal!=_node_global)
86       {
87         if(_node_global)
88           _node_global->decrRef();
89         _node_global=nodeGlobal;
90         if(_node_global)
91           _node_global->incrRef();
92       }
93   }
94
95   void ParaMESH::setCellGlobal(DataArrayInt *cellGlobal)
96   {
97     if(cellGlobal!=_cell_global)
98       {
99         if(_cell_global)
100           _cell_global->decrRef();
101         _cell_global=cellGlobal;
102         if(_cell_global)
103           _cell_global->incrRef();
104       }
105   }
106
107   ParaMESH::~ParaMESH()
108   {
109     if(_cell_mesh)
110       _cell_mesh->decrRef();
111     if(_face_mesh)
112       _face_mesh->decrRef();
113     delete _block_topology;
114     if(_node_global)
115       _node_global->decrRef();
116     if(_cell_global)
117       _cell_global->decrRef();
118     if(_face_global)
119       _face_global->decrRef();
120     delete _explicit_topology;
121   }
122
123 }