From f2616088ca73f60bad1d95612b9fd50b9a02a6ff Mon Sep 17 00:00:00 2001 From: abn Date: Thu, 4 Mar 2021 12:07:43 +0100 Subject: [PATCH] ParaMEDMEM tests can rely on medcoupling module directly. --- src/ParaMEDMEM_Swig/test_InterpKernelDEC.py | 55 +++++++++---------- src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py | 2 +- src/ParaMEDMEM_Swig/test_OverlapDEC.py | 21 ++++--- .../test_StructuredCoincidentDEC.py | 53 +++++++++--------- 4 files changed, 64 insertions(+), 67 deletions(-) diff --git a/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py b/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py index 304b1929e..be4c1346a 100755 --- a/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py +++ b/src/ParaMEDMEM_Swig/test_InterpKernelDEC.py @@ -19,8 +19,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -import ParaMEDMEM as pm -from medcoupling import ReadUMeshFromFile, WriteField, WriteUMesh +from medcoupling import * from ParaMEDMEMTestTools import WriteInTmpDir import sys, os import unittest @@ -36,9 +35,9 @@ class ParaMEDMEM_IK_DEC_Tests(unittest.TestCase): msh = self.generateFullTarget() msh.simplexize(0) msh.setName("src_mesh") - fld = pm.MEDCouplingFieldDouble(pm.ON_CELLS, pm.ONE_TIME) + fld = MEDCouplingFieldDouble(ON_CELLS, ONE_TIME) fld.setMesh(msh); fld.setName("source_F"); - da = pm.DataArrayDouble(msh.getNumberOfCells()) + da = DataArrayDouble(msh.getNumberOfCells()) da.iota() da *= 2 fld.setArray(da) @@ -46,8 +45,8 @@ class ParaMEDMEM_IK_DEC_Tests(unittest.TestCase): def generateFullTarget(self): """ The complete target mesh: 4 squares """ - m1 = pm.MEDCouplingCMesh("tgt_msh") - da = pm.DataArrayDouble([0,1,2]) + m1 = MEDCouplingCMesh("tgt_msh") + da = DataArrayDouble([0,1,2]) m1.setCoords(da, da) msh = m1.buildUnstructured() return msh @@ -76,8 +75,8 @@ class ParaMEDMEM_IK_DEC_Tests(unittest.TestCase): sub_m = msh[[1,3]] sub_m.zipCoords() # Receiving side must prepare an empty field that will be filled by DEC: - fld = pm.MEDCouplingFieldDouble(pm.ON_CELLS, pm.ONE_TIME) - da = pm.DataArrayDouble(sub_m.getNumberOfCells()) + fld = MEDCouplingFieldDouble(ON_CELLS, ONE_TIME) + da = DataArrayDouble(sub_m.getNumberOfCells()) fld.setArray(da) fld.setName("tgt_F") fld.setMesh(sub_m) @@ -99,10 +98,10 @@ class ParaMEDMEM_IK_DEC_Tests(unittest.TestCase): procs_source = list(range(nproc_source)) procs_target = list(range(size - nproc_source, size)) - interface = pm.CommInterface() - source_group = pm.MPIProcessorGroup(interface, procs_source) - target_group = pm.MPIProcessorGroup(interface, procs_target) - idec = pm.InterpKernelDEC(source_group, target_group) + interface = CommInterface() + source_group = MPIProcessorGroup(interface, procs_source) + target_group = MPIProcessorGroup(interface, procs_target) + idec = InterpKernelDEC(source_group, target_group) # Write out full size meshes/fields for inspection if rank == 0: @@ -118,7 +117,7 @@ class ParaMEDMEM_IK_DEC_Tests(unittest.TestCase): # if source_group.containsMyRank(): _, fieldS = self.getPartialSource(rank) - fieldS.setNature(pm.IntensiveMaximum) # The only policy supported for now ... + fieldS.setNature(IntensiveMaximum) # The only policy supported for now ... WriteField("./source_field_part_%d.med" % rank, fieldS, True) idec.attachLocalField(fieldS) idec.synchronize() @@ -126,7 +125,7 @@ class ParaMEDMEM_IK_DEC_Tests(unittest.TestCase): if target_group.containsMyRank(): mshT, fieldT = self.getPartialTarget(rank) - fieldT.setNature(pm.IntensiveMaximum) + fieldT.setNature(IntensiveMaximum) WriteUMesh("./target_mesh_part_%d.med" % rank, mshT, True) idec.attachLocalField(fieldT) idec.synchronize() @@ -158,10 +157,10 @@ class ParaMEDMEM_IK_DEC_Tests(unittest.TestCase): procs_source = list(range(nproc_source)) procs_target = list(range(size - nproc_source + 1, size)) - interface = pm.CommInterface() - target_group = pm.MPIProcessorGroup(interface, procs_target) - source_group = pm.MPIProcessorGroup(interface, procs_source) - dec = pm.InterpKernelDEC(source_group, target_group) + interface = CommInterface() + target_group = MPIProcessorGroup(interface, procs_target) + source_group = MPIProcessorGroup(interface, procs_source) + dec = InterpKernelDEC(source_group, target_group) data_dir = os.path.join(os.environ['MEDCOUPLING_ROOT_DIR'], "share", "resources", "med") if not os.path.isdir(data_dir): @@ -175,28 +174,28 @@ class ParaMEDMEM_IK_DEC_Tests(unittest.TestCase): filename = filename_xml1 + str(rank+1) + ".med" meshname = "Mesh_2_" + str(rank+1) mesh=ReadUMeshFromFile(filename,meshname,0) - paramesh=pm.ParaMESH(mesh,source_group,"source mesh") - comptopo = pm.ComponentTopology() - parafield = pm.ParaFIELD(pm.ON_CELLS,pm.NO_TIME,paramesh, comptopo) - parafield.getField().setNature(pm.IntensiveMaximum) + paramesh=ParaMESH(mesh,source_group,"source mesh") + comptopo = ComponentTopology() + parafield = ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo) + parafield.getField().setNature(IntensiveMaximum) nb_local=mesh.getNumberOfCells() value = [1.0]*nb_local parafield.getField().setValues(value) - icocofield = pm.ICoCoMEDField(parafield.getField()) + icocofield = ICoCoMEDField(parafield.getField()) dec.attachLocalField(icocofield) pass else: filename = filename_xml2 + str(rank - nproc_source + 1) + ".med" meshname = "Mesh_3_" + str(rank - nproc_source + 1) mesh=ReadUMeshFromFile(filename,meshname,0) - paramesh=pm.ParaMESH(mesh,target_group,"target mesh") - comptopo = pm.ComponentTopology() - parafield = pm.ParaFIELD(pm.ON_CELLS,pm.NO_TIME,paramesh, comptopo) - parafield.getField().setNature(pm.IntensiveMaximum) + paramesh=ParaMESH(mesh,target_group,"target mesh") + comptopo = ComponentTopology() + parafield = ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo) + parafield.getField().setNature(IntensiveMaximum) nb_local=mesh.getNumberOfCells() value = [0.0]*nb_local parafield.getField().setValues(value) - icocofield = pm.ICoCoMEDField(parafield.getField()) + icocofield = ICoCoMEDField(parafield.getField()) dec.attachLocalField(icocofield) pass diff --git a/src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py b/src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py index d1aea9e94..a4b0e7da1 100755 --- a/src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py +++ b/src/ParaMEDMEM_Swig/test_NonCoincidentDEC.py @@ -19,7 +19,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -from ParaMEDMEM import * +from medcoupling import * from mpi4py import MPI import unittest import os diff --git a/src/ParaMEDMEM_Swig/test_OverlapDEC.py b/src/ParaMEDMEM_Swig/test_OverlapDEC.py index d3e33775a..eb7d1d610 100644 --- a/src/ParaMEDMEM_Swig/test_OverlapDEC.py +++ b/src/ParaMEDMEM_Swig/test_OverlapDEC.py @@ -1,7 +1,6 @@ #!/usr/bin/env python -import ParaMEDMEM as pm -from medcoupling import WriteField, WriteUMesh +from medcoupling import * from ParaMEDMEMTestTools import WriteInTmpDir import sys, os import unittest @@ -24,9 +23,9 @@ class ParaMEDMEM_O_DEC_Tests(unittest.TestCase): msh = self.generateFullTarget() msh.simplexize(0) msh.setName("src_mesh") - fld = pm.MEDCouplingFieldDouble(pm.ON_CELLS, pm.ONE_TIME) + fld = MEDCouplingFieldDouble(ON_CELLS, ONE_TIME) fld.setMesh(msh); fld.setName("source_F"); - da = pm.DataArrayDouble(msh.getNumberOfCells()) + da = DataArrayDouble(msh.getNumberOfCells()) da.iota() da *= 2 fld.setArray(da) @@ -34,8 +33,8 @@ class ParaMEDMEM_O_DEC_Tests(unittest.TestCase): def generateFullTarget(self): """ The complete target mesh: 4 squares """ - m1 = pm.MEDCouplingCMesh("tgt_msh") - da = pm.DataArrayDouble([0,1,2]) + m1 = MEDCouplingCMesh("tgt_msh") + da = DataArrayDouble([0,1,2]) m1.setCoords(da, da) msh = m1.buildUnstructured() return msh @@ -63,8 +62,8 @@ class ParaMEDMEM_O_DEC_Tests(unittest.TestCase): sub_m = msh[rank] sub_m.zipCoords() # Receiving side must prepare an empty field that will be filled by DEC: - fld = pm.MEDCouplingFieldDouble(pm.ON_CELLS, pm.ONE_TIME) - da = pm.DataArrayDouble(sub_m.getNumberOfCells()) + fld = MEDCouplingFieldDouble(ON_CELLS, ONE_TIME) + da = DataArrayDouble(sub_m.getNumberOfCells()) fld.setArray(da) fld.setName("tgt_F") fld.setMesh(sub_m) @@ -80,7 +79,7 @@ class ParaMEDMEM_O_DEC_Tests(unittest.TestCase): # Define (single) processor group - note the difference with InterpKernelDEC which needs two groups. proc_group = list(range(size)) # No need for ProcessorGroup object here. - odec = pm.OverlapDEC(proc_group) + odec = OverlapDEC(proc_group) # Write out full size meshes/fields for inspection if rank == 0: @@ -95,9 +94,9 @@ class ParaMEDMEM_O_DEC_Tests(unittest.TestCase): # OK, let's go DEC !! # _, fieldS = self.getPartialSource(rank) - fieldS.setNature(pm.IntensiveMaximum) # The only policy supported for now ... + fieldS.setNature(IntensiveMaximum) # The only policy supported for now ... mshT, fieldT = self.getPartialTarget(rank) - fieldT.setNature(pm.IntensiveMaximum) + fieldT.setNature(IntensiveMaximum) if rank not in [2,3]: WriteField("./source_field_part_%d.med" % rank, fieldS, True) WriteUMesh("./target_mesh_part_%d.med" % rank, mshT, True) diff --git a/src/ParaMEDMEM_Swig/test_StructuredCoincidentDEC.py b/src/ParaMEDMEM_Swig/test_StructuredCoincidentDEC.py index 9d85fb905..11c5b7a16 100755 --- a/src/ParaMEDMEM_Swig/test_StructuredCoincidentDEC.py +++ b/src/ParaMEDMEM_Swig/test_StructuredCoincidentDEC.py @@ -19,8 +19,7 @@ # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # -import ParaMEDMEM as pm -from medcoupling import WriteField, WriteUMesh, ReadUMeshFromFile +from medcoupling import * from ParaMEDMEMTestTools import WriteInTmpDir import os import unittest @@ -36,16 +35,16 @@ class ParaMEDMEM_SC_DEC_Tests(unittest.TestCase): """ The complete mesh: 4 squares each divided in 2 diagonaly (so 8 cells in total) Note that in this case, this is the **only** mesh for the whole problem. """ - m1 = pm.MEDCouplingCMesh("tgt_msh") - da = pm.DataArrayDouble([0,1,2]) + m1 = MEDCouplingCMesh("tgt_msh") + da = DataArrayDouble([0,1,2]) m1.setCoords(da, da) msh = m1.buildUnstructured() msh.simplexize(0) msh.setName("src_mesh") - fld = pm.MEDCouplingFieldDouble(pm.ON_CELLS, pm.ONE_TIME) + fld = MEDCouplingFieldDouble(ON_CELLS, ONE_TIME) fld.setMesh(msh); fld.setName("source_F"); - da = pm.DataArrayDouble(msh.getNumberOfCells()) + da = DataArrayDouble(msh.getNumberOfCells()) da.iota() da *= 2 fld.setArray(da) @@ -94,11 +93,11 @@ class ParaMEDMEM_SC_DEC_Tests(unittest.TestCase): procs_source = list(range(nproc_source)) procs_target = list(range(size - nproc_source, size)) - interface = pm.CommInterface() - source_group = pm.MPIProcessorGroup(interface, procs_source) - target_group = pm.MPIProcessorGroup(interface, procs_target) + interface = CommInterface() + source_group = MPIProcessorGroup(interface, procs_source) + target_group = MPIProcessorGroup(interface, procs_target) - scdec = pm.StructuredCoincidentDEC(source_group, target_group) + scdec = StructuredCoincidentDEC(source_group, target_group) # Write out full size meshes/fields for inspection if rank == 0: @@ -110,7 +109,7 @@ class ParaMEDMEM_SC_DEC_Tests(unittest.TestCase): # if source_group.containsMyRank(): _, fieldS = self.getPartialSource(rank) - fieldS.setNature(pm.IntensiveMaximum) # The only policy supported for now ... + fieldS.setNature(IntensiveMaximum) # The only policy supported for now ... WriteField("./source_field_part_%d.med" % rank, fieldS, True) scdec.attachLocalField(fieldS) scdec.synchronize() @@ -118,7 +117,7 @@ class ParaMEDMEM_SC_DEC_Tests(unittest.TestCase): if target_group.containsMyRank(): mshT, fieldT = self.getPartialTarget(rank) - fieldT.setNature(pm.IntensiveMaximum) + fieldT.setNature(IntensiveMaximum) WriteUMesh("./target_mesh_part_%d.med" % rank, mshT, True) scdec.attachLocalField(fieldT) scdec.synchronize() @@ -147,11 +146,11 @@ class ParaMEDMEM_SC_DEC_Tests(unittest.TestCase): print("Should be run on >= 4 procs!") return - interface = pm.CommInterface() + interface = CommInterface() - source_group = pm.MPIProcessorGroup(interface, 0, 2) - target_group = pm.MPIProcessorGroup(interface, 3, size-1) - self_group = pm.MPIProcessorGroup(interface, rank, rank) + source_group = MPIProcessorGroup(interface, 0, 2) + target_group = MPIProcessorGroup(interface, 3, size-1) + self_group = MPIProcessorGroup(interface, rank, rank) data_dir = os.path.join(os.environ['MEDCOUPLING_ROOT_DIR'], "share", "resources", "med") if not os.path.isdir(data_dir): @@ -165,17 +164,17 @@ class ParaMEDMEM_SC_DEC_Tests(unittest.TestCase): filename_seq_wr = "." filename_seq_med = os.path.join(".", "myWrField_seq_pointe221.med") - dec = pm.StructuredCoincidentDEC(source_group, target_group) + dec = StructuredCoincidentDEC(source_group, target_group) MPI.COMM_WORLD.Barrier() if source_group.containsMyRank(): filename = filename_xml1 + str(rank+1) + ".med" meshname = "Mesh_2_" + str(rank+1) mesh = ReadUMeshFromFile(filename,meshname,0) - paramesh=pm.ParaMESH(mesh,source_group,"source mesh") - comptopo=pm.ComponentTopology(6) - parafield=pm.ParaFIELD(pm.ON_CELLS,pm.NO_TIME,paramesh,comptopo) - parafield.getField().setNature(pm.IntensiveMaximum) + paramesh=ParaMESH(mesh,source_group,"source mesh") + comptopo=ComponentTopology(6) + parafield=ParaFIELD(ON_CELLS,NO_TIME,paramesh,comptopo) + parafield.getField().setNature(IntensiveMaximum) nb_local=mesh.getNumberOfCells() global_numbering=paramesh.getGlobalNumberingCell2() value = [] @@ -183,7 +182,7 @@ class ParaMEDMEM_SC_DEC_Tests(unittest.TestCase): for icomp in range(6): value.append(global_numbering[ielem]*6.0+icomp); parafield.getField().setValues(value) - icocofield = pm.ICoCoMEDField(parafield.getField()) + icocofield = ICoCoMEDField(parafield.getField()) dec.setMethod("P0") dec.attachLocalField(parafield) dec.synchronize() @@ -192,14 +191,14 @@ class ParaMEDMEM_SC_DEC_Tests(unittest.TestCase): if target_group.containsMyRank(): meshname2 = "Mesh_2" mesh = ReadUMeshFromFile(filename_2, meshname2,0) - paramesh = pm.ParaMESH(mesh, self_group, "target mesh") - comptopo = pm.ComponentTopology(6,target_group) - parafield = pm.ParaFIELD(pm.ON_CELLS,pm.NO_TIME,paramesh, comptopo) - parafield.getField().setNature(pm.IntensiveMaximum) + paramesh = ParaMESH(mesh, self_group, "target mesh") + comptopo = ComponentTopology(6,target_group) + parafield = ParaFIELD(ON_CELLS,NO_TIME,paramesh, comptopo) + parafield.getField().setNature(IntensiveMaximum) nb_local=mesh.getNumberOfCells() value = [0.0]*(nb_local*comptopo.nbLocalComponents()) parafield.getField().setValues(value) - icocofield = pm.ICoCoMEDField(parafield.getField()) + icocofield = ICoCoMEDField(parafield.getField()) dec.setMethod("P0") dec.attachLocalField(parafield) dec.synchronize() -- 2.39.2