Salome HOME
debug: forget of TRI6
[tools/medcoupling.git] / src / ParaMEDMEM / ParaMESH.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 "ParaMESH.hxx"
20 #include "ProcessorGroup.hxx"
21 #include "MPIProcessorGroup.hxx"
22 #include "Topology.hxx"
23 #include "BlockTopology.hxx"
24 #include "MemArray.hxx"
25
26 #include <fstream>
27 #include <vector>
28
29 //inclusion for the namespaces
30 using namespace std;
31
32 namespace ParaMEDMEM
33 {
34   ParaMESH::ParaMESH( MEDCouplingUMesh *subdomain_mesh, MEDCouplingUMesh *subdomain_face,
35             DataArrayInt *CorrespElt_local2global, DataArrayInt *CorrespFace_local2global,
36             DataArrayInt *CorrespNod_local2global, const ProcessorGroup& proc_group ):
37     _cell_mesh(subdomain_mesh),
38     _face_mesh(subdomain_face),
39     _my_domain_id(proc_group.myRank()),
40     _block_topology (new BlockTopology(proc_group, subdomain_mesh->getNumberOfCells())),
41     _explicit_topology(0),
42     _node_global(CorrespNod_local2global),
43     _face_global(CorrespFace_local2global),
44     _cell_global(CorrespElt_local2global)
45   {
46     if(_cell_mesh)
47       _cell_mesh->incrRef();
48     if(_face_mesh)
49       _face_mesh->incrRef();
50     if(CorrespElt_local2global)
51       CorrespElt_local2global->incrRef();
52     if(CorrespFace_local2global)
53       CorrespFace_local2global->incrRef();
54     if(CorrespNod_local2global)
55       CorrespNod_local2global->incrRef();
56   }
57
58   ParaMESH::ParaMESH( MEDCouplingUMesh *mesh, const ProcessorGroup& proc_group, const std::string& name):
59     _cell_mesh(mesh),
60     _face_mesh(0),
61     _my_domain_id(proc_group.myRank()),
62     _block_topology (new BlockTopology(proc_group, mesh->getNumberOfCells())),
63     _node_global(0),
64     _face_global(0)
65   {
66     if(_cell_mesh)
67       _cell_mesh->incrRef();
68     int nb_elem=mesh->getNumberOfCells();
69     _explicit_topology=new BlockTopology(proc_group,nb_elem);
70     int nbOfCells=mesh->getNumberOfCells();
71     _cell_global = DataArrayInt::New();
72     _cell_global->alloc(nbOfCells,1);
73     int *cellglobal=_cell_global->getPointer();
74     int offset = _block_topology->localToGlobal(make_pair(_my_domain_id,0));
75     for (int i=0; i<nbOfCells; i++)
76       {
77         cellglobal[i]=offset+i;
78       }
79   }
80
81   ParaMESH::~ParaMESH()
82   {
83     if(_cell_mesh)
84       _cell_mesh->decrRef();
85     if(_face_mesh)
86       _face_mesh->decrRef();
87     delete _block_topology;
88     if(_node_global)
89       _node_global->decrRef();
90     if(_cell_global)
91       _cell_global->decrRef();
92     if(_face_global)
93       _face_global->decrRef();
94     if(_node_global)
95       _node_global->decrRef();
96     delete _explicit_topology;
97   }
98
99 }