2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2020 CEA/DEN, EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 from ParaMEDMEM import *
23 from MEDLoader import ReadUMeshFromFile
27 from mpi4py import MPI
30 class ParaMEDMEMBasicsTest(unittest.TestCase):
31 def testInterpKernelDEC_2D(self):
32 size = MPI.COMM_WORLD.size
33 rank = MPI.COMM_WORLD.rank
35 raise RuntimeError("Expect MPI_COMM_WORLD size == 5")
38 procs_source = list(range(nproc_source))
39 procs_target = list(range(size - nproc_source + 1, size))
41 interface = CommInterface()
42 target_group = MPIProcessorGroup(interface, procs_target)
43 source_group = MPIProcessorGroup(interface, procs_source)
44 dec = InterpKernelDEC(source_group, target_group)
51 data_dir = os.environ['MEDCOUPLING_ROOT_DIR']
52 tmp_dir = os.environ['TMP']
54 if not tmp_dir or len(tmp_dir)==0:
58 filename_xml1 = os.path.join(data_dir, "share/resources/med/square1_split")
59 filename_xml2 = os.path.join(data_dir, "share/resources/med/square2_split")
61 MPI.COMM_WORLD.Barrier()
62 if source_group.containsMyRank():
63 filename = filename_xml1 + str(rank+1) + ".med"
64 meshname = "Mesh_2_" + str(rank+1)
65 mesh=ReadUMeshFromFile(filename,meshname,0)
66 paramesh=ParaMESH(mesh,source_group,"source mesh")
67 comptopo = ComponentTopology()
68 parafield = ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo)
69 parafield.getField().setNature(IntensiveMaximum)
70 nb_local=mesh.getNumberOfCells()
71 value = [1.0]*nb_local
72 parafield.getField().setValues(value)
73 icocofield = ICoCoMEDField(parafield.getField())
74 dec.attachLocalField(icocofield)
77 filename = filename_xml2 + str(rank - nproc_source + 1) + ".med"
78 meshname = "Mesh_3_" + str(rank - nproc_source + 1)
79 mesh=ReadUMeshFromFile(filename,meshname,0)
80 paramesh=ParaMESH(mesh,target_group,"target mesh")
81 comptopo = ComponentTopology()
82 parafield = ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo)
83 parafield.getField().setNature(IntensiveMaximum)
84 nb_local=mesh.getNumberOfCells()
85 value = [0.0]*nb_local
86 parafield.getField().setValues(value)
87 icocofield = ICoCoMEDField(parafield.getField())
88 dec.attachLocalField(icocofield)
91 if source_group.containsMyRank():
92 field_before_int = parafield.getVolumeIntegral(0,True)
94 dec.setForcedRenormalization(False)
97 field_after_int=parafield.getVolumeIntegral(0,True);
98 self.assertTrue(math.fabs(field_after_int-field_before_int)<1e-8)
102 dec.setForcedRenormalization(False)
116 MPI.COMM_WORLD.Barrier()