Salome HOME
Initiating medtool
[modules/med.git] / src / ParaMEDMEM / ParaMESH.cxx
1 // Copyright (C) 2007-2015  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 "ParaMESH.hxx"
21 #include "ProcessorGroup.hxx"
22 #include "MPIProcessorGroup.hxx"
23 #include "Topology.hxx"
24 #include "BlockTopology.hxx"
25 #include "MEDCouplingMemArray.hxx"
26
27 #include <fstream>
28 #include <vector>
29
30 //inclusion for the namespaces
31 using namespace std;
32
33 namespace ParaMEDMEM
34 {
35   ParaMESH::ParaMESH( MEDCouplingPointSet *subdomain_mesh, MEDCouplingPointSet *subdomain_face,
36             DataArrayInt *CorrespElt_local2global, DataArrayInt *CorrespFace_local2global,
37             DataArrayInt *CorrespNod_local2global, const ProcessorGroup& proc_group ):
38     _cell_mesh(subdomain_mesh),
39     _face_mesh(subdomain_face),
40     _my_domain_id(proc_group.myRank()),
41     _block_topology (new BlockTopology(proc_group, subdomain_mesh->getNumberOfCells())),
42     _explicit_topology(0),
43     _node_global(CorrespNod_local2global),
44     _face_global(CorrespFace_local2global),
45     _cell_global(CorrespElt_local2global)
46   {
47     if(_cell_mesh)
48       _cell_mesh->incrRef();
49     if(_face_mesh)
50       _face_mesh->incrRef();
51     if(CorrespElt_local2global)
52       CorrespElt_local2global->incrRef();
53     if(CorrespFace_local2global)
54       CorrespFace_local2global->incrRef();
55     if(CorrespNod_local2global)
56       CorrespNod_local2global->incrRef();
57   }
58
59   ParaMESH::ParaMESH( MEDCouplingPointSet *mesh, const ProcessorGroup& proc_group, const std::string& name):
60     _cell_mesh(mesh),
61     _face_mesh(0),
62     _my_domain_id(proc_group.myRank()),
63     _block_topology (new BlockTopology(proc_group, mesh->getNumberOfCells())),
64     _node_global(0),
65     _face_global(0)
66   {
67     if(_cell_mesh)
68       _cell_mesh->incrRef();
69     int nb_elem=mesh->getNumberOfCells();
70     _explicit_topology=new BlockTopology(proc_group,nb_elem);
71     int nbOfCells=mesh->getNumberOfCells();
72     _cell_global = DataArrayInt::New();
73     _cell_global->alloc(nbOfCells,1);
74     int *cellglobal=_cell_global->getPointer();
75     int offset = _block_topology->localToGlobal(make_pair(_my_domain_id,0));
76     for (int i=0; i<nbOfCells; i++)
77       {
78         cellglobal[i]=offset+i;
79       }
80   }
81
82   void ParaMESH::setNodeGlobal(DataArrayInt *nodeGlobal)
83   {
84     if(nodeGlobal!=_node_global)
85       {
86         if(_node_global)
87           _node_global->decrRef();
88         _node_global=nodeGlobal;
89         if(_node_global)
90           _node_global->incrRef();
91       }
92   }
93
94   void ParaMESH::setCellGlobal(DataArrayInt *cellGlobal)
95   {
96     if(cellGlobal!=_cell_global)
97       {
98         if(_cell_global)
99           _cell_global->decrRef();
100         _cell_global=cellGlobal;
101         if(_cell_global)
102           _cell_global->incrRef();
103       }
104   }
105
106   ParaMESH::~ParaMESH()
107   {
108     if(_cell_mesh)
109       _cell_mesh->decrRef();
110     if(_face_mesh)
111       _face_mesh->decrRef();
112     delete _block_topology;
113     if(_node_global)
114       _node_global->decrRef();
115     if(_cell_global)
116       _cell_global->decrRef();
117     if(_face_global)
118       _face_global->decrRef();
119     delete _explicit_topology;
120   }
121
122 }