2 # -*- coding: iso-8859-1 -*-
3 # Copyright (C) 2007-2013 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.
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 *
27 class ParaMEDMEMBasicsTest(unittest.TestCase):
28 def testInterpKernelDEC_2D(self):
30 size = MPI_Comm_size(MPI_COMM_WORLD)
31 rank = MPI_Comm_rank(MPI_COMM_WORLD)
33 raise RuntimeError, "Expect MPI_COMM_WORLD size == 5"
36 procs_source = range( nproc_source )
37 procs_target = range( size - nproc_source + 1, size)
39 interface = CommInterface()
40 target_group = MPIProcessorGroup(interface, procs_target)
41 source_group = MPIProcessorGroup(interface, procs_source)
42 dec = InterpKernelDEC(source_group, target_group)
49 data_dir = os.environ['MED_ROOT_DIR']
50 tmp_dir = os.environ['TMP']
52 if not tmp_dir or len(tmp_dir)==0:
56 filename_xml1 = os.path.join(data_dir, "share/salome/resources/med/square1_split")
57 filename_xml2 = os.path.join(data_dir, "share/salome/resources/med/square2_split")
59 MPI_Barrier(MPI_COMM_WORLD)
60 if source_group.containsMyRank():
61 filename = filename_xml1 + str(rank+1) + ".med"
62 meshname = "Mesh_2_" + str(rank+1)
63 mesh=MEDLoader.ReadUMeshFromFile(filename,meshname,0)
64 paramesh=ParaMESH(mesh,source_group,"source mesh")
65 comptopo = ComponentTopology()
66 parafield = ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo)
67 parafield.getField().setNature(ConservativeVolumic)
68 nb_local=mesh.getNumberOfCells()
69 value = [1.0]*nb_local
70 parafield.getField().setValues(value)
71 icocofield = ICoCoMEDField(mesh,parafield.getField())
73 dec.attachLocalField(icocofield)
76 filename = filename_xml2 + str(rank - nproc_source + 1) + ".med"
77 meshname = "Mesh_3_" + str(rank - nproc_source + 1)
78 mesh=MEDLoader.ReadUMeshFromFile(filename,meshname,0)
79 paramesh=ParaMESH(mesh,target_group,"target mesh")
80 comptopo = ComponentTopology()
81 parafield = ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo)
82 parafield.getField().setNature(ConservativeVolumic)
83 nb_local=mesh.getNumberOfCells()
84 value = [0.0]*nb_local
85 parafield.getField().setValues(value)
86 icocofield = ICoCoMEDField(mesh,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.failUnless(math.fabs(field_after_int-field_before_int)<1e-8)
102 dec.setForcedRenormalization(False)
116 MPI_Barrier(MPI_COMM_WORLD)