Salome HOME
c9a251916588ed5d186754ea548667dc5a8d20f5
[tools/medcoupling.git] / src / ParaMEDMEM / ParaMESH.cxx
1 //
2 // Copyright (C) 2007-2020  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             DataArrayIdType *CorrespElt_local2global, DataArrayIdType *CorrespFace_local2global,
38             DataArrayIdType *CorrespNod_local2global, const ProcessorGroup& proc_group ):
39     _my_domain_id(proc_group.myRank()),
40     _block_topology(new BlockTopology(proc_group, subdomain_mesh->getNumberOfCells())),
41     _explicit_topology(nullptr)
42   {
43     _cell_mesh.takeRef(subdomain_mesh);
44     _face_mesh.takeRef(subdomain_face);
45     _node_global.takeRef(CorrespNod_local2global);
46     _face_global.takeRef(CorrespFace_local2global);
47     _cell_global.takeRef(CorrespElt_local2global);
48   }
49
50   ParaMESH::ParaMESH( MEDCouplingPointSet *mesh, const ProcessorGroup& proc_group, const std::string& name):
51     _my_domain_id(proc_group.myRank()),
52     _block_topology(new BlockTopology(proc_group, mesh->getNumberOfCells()))
53   {
54     _cell_mesh.takeRef(mesh);
55     mcIdType nb_elem=mesh->getNumberOfCells();
56     _explicit_topology=new BlockTopology(proc_group,nb_elem);
57     mcIdType nbOfCells=mesh->getNumberOfCells();
58     _cell_global = DataArrayIdType::New();
59     _cell_global->alloc(nbOfCells,1);
60     mcIdType *cellglobal=_cell_global->getPointer();
61     mcIdType offset = _block_topology->localToGlobal(make_pair(_my_domain_id,0));
62     for (mcIdType i=0; i<nbOfCells; i++)
63       {
64         cellglobal[i]=offset+i;
65       }
66   }
67
68   void ParaMESH::setNodeGlobal(DataArrayIdType *nodeGlobal)
69   {
70     _node_global.takeRef(nodeGlobal);
71   }
72
73   void ParaMESH::setCellGlobal(DataArrayIdType *cellGlobal)
74   {
75     _cell_global.takeRef(cellGlobal);
76   }
77
78   ParaMESH::~ParaMESH()
79   {
80     release();
81   }
82
83   /** Destructor involves MPI operations: make sure this is accessible from a proper
84    * method for Python wrapping.
85    */
86   void ParaMESH::release()
87   {
88     delete _block_topology;
89     delete _explicit_topology;
90     _block_topology = nullptr;
91     _explicit_topology = nullptr;
92   }
93
94 }