Example #1
0
 def testMultiMeshTypeWrite0(self):
     fname = "Pyfile73.med"
     m = MEDLoader.MEDCoupling1SGTUMesh("mesh", MEDLoader.NORM_QUAD4)
     m.allocateCells()
     m.insertNextCell([0, 2, 1, 3])
     m.setCoords(
         MEDLoader.DataArrayDouble([0., 0., 1., 1., 1., 0., 0., 1.], 4, 2))
     #
     ms = [m.deepCpy() for i in xrange(4)]
     for i, elt in enumerate(ms):
         elt.translate([float(i) * 1.5, 0.])
         pass
     #
     m0 = MEDLoader.MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms)
     f = m0.getMeasureField(False)
     f.getArray().setInfoOnComponents(["ABC [defg]"])
     MEDLoader.MEDLoader.WriteField(fname, f, True)
     #
     fRead = MEDLoader.MEDLoader.ReadFieldCell(fname, "merge", 0,
                                               f.getName(), -1, -1)
     fRead.setMesh(MEDLoader.MEDCoupling1SGTUMesh(fRead.getMesh()))
     self.assertTrue(f.isEqual(fRead, 1e-12, 1e-12))
     #
     m0 = m0.buildUnstructured()
     m0.convertAllToPoly()
     m0 = MEDLoader.MEDCoupling1DGTUMesh(m0)
     f = m0.getMeasureField(False)
     f.getArray().setInfoOnComponents(["ABC [defg]"])
     MEDLoader.MEDLoader.WriteField(fname, f, True)
     #
     fRead = MEDLoader.MEDLoader.ReadFieldCell(fname, "merge", 0,
                                               f.getName(), -1, -1)
     fRead.setMesh(MEDLoader.MEDCoupling1DGTUMesh(fRead.getMesh()))
     self.assertTrue(f.isEqual(fRead, 1e-12, 1e-12))
     #
     m0 = MEDLoader.MEDCouplingCMesh()
     arr = MEDLoader.DataArrayDouble(4)
     arr.iota()
     m0.setCoords(arr, arr)
     m0.setName("mesh")
     f = m0.getMeasureField(False)
     f.getArray().setInfoOnComponents(["ABC [defg]"])
     MEDLoader.MEDLoader.WriteField(fname, f, True)
     #
     fRead = MEDLoader.MEDLoader.ReadFieldCell(fname, "mesh", 0,
                                               f.getName(), -1, -1)
     self.assertTrue(f.isEqual(fRead, 1e-12, 1e-12))
     #
     c = m0.buildUnstructured().getCoords()
     m0 = MEDLoader.MEDCouplingCurveLinearMesh("mesh")
     m0.setNodeGridStructure([4, 4])
     m0.setCoords(c)
     f = m0.getMeasureField(False)
     f.getArray().setInfoOnComponents(["ABC [defg]"])
     MEDLoader.MEDLoader.WriteField(fname, f, True)
     #
     fRead = MEDLoader.MEDLoader.ReadFieldCell(fname, "mesh", 0,
                                               f.getName(), -1, -1)
     self.assertTrue(f.isEqual(fRead, 1e-12, 1e-12))
     pass
Example #2
0
 def testMultiMeshTypeWrite1(self):
     fname = "Pyfile74.med"
     m = MEDLoader.MEDCoupling1SGTUMesh("mesh", MEDLoader.NORM_QUAD4)
     m.allocateCells()
     m.insertNextCell([0, 2, 1, 3])
     m.setCoords(
         MEDLoader.DataArrayDouble([0., 0., 1., 1., 1., 0., 0., 1.], 4, 2))
     #
     ms = [m.deepCopy() for i in range(4)]
     for i, elt in enumerate(ms):
         elt.translate([float(i) * 1.5, 0.])
         pass
     m0 = MEDLoader.MEDCoupling1SGTUMesh.Merge1SGTUMeshes(ms)
     MEDLoader.WriteMesh(fname, m0, True)
     #
     mRead = MEDLoader.ReadMeshFromFile(fname, "merge", 0)
     self.assertTrue(isinstance(mRead, MEDLoader.MEDCouplingUMesh))
     mRead = MEDLoader.MEDCoupling1SGTUMesh(mRead)
     self.assertTrue(m0.isEqual(mRead, 1e-12))
     #
     m0 = m0.buildUnstructured()
     m0.convertAllToPoly()
     m0 = MEDLoader.MEDCoupling1DGTUMesh(m0)
     MEDLoader.WriteMesh(fname, m0, True)
     #
     mRead = MEDLoader.ReadMeshFromFile(fname, "merge", 0)
     mRead = MEDLoader.MEDCoupling1DGTUMesh(mRead)
     self.assertTrue(m0.isEqual(mRead, 1e-12))
     #
     m0 = MEDLoader.MEDCouplingCMesh()
     arr = MEDLoader.DataArrayDouble(4)
     arr.iota()
     m0.setCoords(arr, arr)
     m0.setName("mesh")
     MEDLoader.WriteMesh(fname, m0, True)
     #
     mRead = MEDLoader.ReadMeshFromFile(fname, 0)
     self.assertTrue(isinstance(mRead, MEDLoader.MEDCouplingCMesh))
     self.assertTrue(m0.isEqual(mRead, 1e-12))
     #
     c = m0.buildUnstructured().getCoords()
     m0 = MEDLoader.MEDCouplingCurveLinearMesh("mesh")
     m0.setNodeGridStructure([4, 4])
     m0.setCoords(c)
     MEDLoader.WriteMesh(fname, m0, True)
     #
     mRead = MEDLoader.ReadMeshFromFile(fname, 0)
     self.assertTrue(isinstance(mRead,
                                MEDLoader.MEDCouplingCurveLinearMesh))
     self.assertTrue(m0.isEqual(mRead, 1e-12))
     pass
Example #3
0
 def testUsingAlreadyWrittenMesh2(self):
     """ This test focuses on MEDLoader.WriteFieldUsingAlreadyWrittenMesh with mesh different from UMesh.
     """
     fname = "Pyfile76.med"
     mesh = MEDLoader.MEDCouplingCMesh("mesh")
     arrX = MEDLoader.DataArrayDouble([0, 1, 2, 3])
     arrY = MEDLoader.DataArrayDouble([0, 2, 3, 5, 7])
     arrZ = MEDLoader.DataArrayDouble([7])
     mesh.setCoords(arrX, arrY, arrZ)
     #
     f1 = MEDLoader.MEDCouplingFieldDouble(MEDLoader.ON_NODES)
     f1.setName("f1")
     f1.setMesh(mesh)
     arr = MEDLoader.DataArrayDouble(20)
     arr.iota()
     f1.setArray(arr)
     f1.checkConsistencyLight()
     #
     f2 = MEDLoader.MEDCouplingFieldDouble(MEDLoader.ON_NODES)
     f2.setName("f2")
     f2.setMesh(mesh)
     arr = MEDLoader.DataArrayDouble(20)
     arr.iota()
     arr *= 3
     f2.setArray(arr)
     f2.checkConsistencyLight()
     #
     f11 = f1.deepCopy()
     (f11.getArray())[:] *= 4
     f11.setTime(1.1, 5, 6)
     #
     MEDLoader.WriteMesh(fname, f1.getMesh(), True)
     MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname, f1)
     MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname, f2)
     MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname, f11)
     ##
     f1r = MEDLoader.ReadFieldNode(fname, "mesh", 0, "f1", -1, -1)
     self.assertTrue(f1.isEqual(f1r, 1e-12, 1e-12))
     self.assertTrue(f1r.getArray().isEqual(
         MEDLoader.DataArrayDouble([
             0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13.,
             14., 15., 16., 17., 18., 19.
         ]), 1e-12))
     f2r = MEDLoader.ReadFieldNode(fname, "mesh", 0, "f2", -1, -1)
     self.assertTrue(f2.isEqual(f2r, 1e-12, 1e-12))
     self.assertTrue(f2r.getArray().isEqual(
         MEDLoader.DataArrayDouble([
             0., 3., 6., 9., 12., 15., 18., 21., 24., 27., 30., 33., 36.,
             39., 42., 45., 48., 51., 54., 57.
         ]), 1e-12))
     f3r = MEDLoader.ReadFieldNode(fname, "mesh", 0, "f1", 5, 6)
     self.assertTrue(f11.isEqual(f3r, 1e-12, 1e-12))
     self.assertTrue(f3r.getArray().isEqual(
         MEDLoader.DataArrayDouble([
             0., 4., 8., 12., 16., 20., 24., 28., 32., 36., 40., 44., 48.,
             52., 56., 60., 64., 68., 72., 76.
         ]), 1e-12))
     pass
Example #4
0
def read_typ3(fichier, nom_med):
    with open(fichier, "r") as fic:
        lines = fic.readlines()
    nb_som = int(lines[9].strip())
    nb_cel = int(lines[11].strip())
    nb_fac = int(lines[13].strip())

    som = [map(float, line.split()) for line in lines[17:17 + nb_som]]

    # les connectivites ne partent pas de 0...
    s = read_between(fichier, ["Volumes->Faces"], ["Volumes->Vertices"])
    tmp_cel = connectivity_from_string(s)
    # tmp_cel = [map(int, line.split()[1:]) for line in lines[18 + nb_som:18 + nb_som + nb_cel]]
    cel = [[p - 1 for p in c] for c in tmp_cel]

    s = read_between(fichier, ["Faces->Vertices"],
                     ["Faces->Control volumes", "Faces->volumes"])
    tmp_fac = connectivity_from_string(s)
    # tmp_fac = [map(int, line.split()[1:]) for line in lines[21 + nb_som + 2 * nb_cel + nb_fac:21 + nb_som + 2 * nb_cel + 2 * nb_fac]]
    fac = [[p - 1 for p in c] for c in tmp_fac]

    mesh = ml.MEDCouplingUMesh("mesh", 3)
    mesh.allocateCells(len(cel))

    for e in range(len(cel)):
        con = []
        for face in cel[e]:
            con.extend(fac[face])
            con.append(-1)
        mesh.insertNextCell(ml.NORM_POLYHED, con[:-1])
    mesh.finishInsertingCells()

    pts = []
    for p in som:
        pts.extend(p)
    co = ml.DataArrayDouble(pts, len(pts) / 3, 3)
    mesh.setCoords(co)

    mf, d, di, r, ri = mesh.buildDescendingConnectivity()
    mf.setName("mesh")
    mm = ml.MEDFileUMesh.New()
    mm.setMeshAtLevel(0, mesh)
    mm.setMeshAtLevel(-1, mf)

    g = []
    nb_vois = ri.deltaShiftIndex()
    for i in range(mf.getNumberOfCells()):
        if nb_vois[i] == 1: g.append(i)
    grp = ml.DataArrayInt.New(g)
    grp.setName("boundary")
    mm.addGroup(-1, grp)

    mm.write("{}/mesh.med".format(nom_med), 2)
Example #5
0
 def testMultiWriteFieldOnMergeableNodesMeshes(self):
     fname = "Pyfile120.med"
     arr = MEDLoader.DataArrayDouble([(0, 0), (1, 0), (0, 1), (0, 0),
                                      (1, 0), (0, 1)])
     m = MEDLoader.MEDCouplingUMesh("mesh", 2)
     m.setCoords(arr)
     m.allocateCells()
     m.insertNextCell(MEDLoader.NORM_TRI3, [0, 4, 2])
     m.insertNextCell(MEDLoader.NORM_TRI3, [3, 1, 5])
     m.setName("mesh")
     #
     f = MEDLoader.MEDCouplingFieldDouble(MEDLoader.ON_CELLS)
     f.setMesh(m)
     f.setArray(MEDLoader.DataArrayDouble([5, 6]))
     f.setName("field")
     #
     f.setTime(0., 0, 0)
     MEDLoader.WriteField(fname, f, True)
     f.setTime(1., 1, 0)
     MEDLoader.WriteField(fname, f, False)
     pass
Example #6
0
 def testBigNbOfCompoNonReg(self):
     fileName = "Pyfile57.med"
     m = MEDLoader.MEDCouplingCMesh()
     m.setCoords(MEDLoader.DataArrayDouble([0, 1, 2, 3]),
                 MEDLoader.DataArrayDouble([0, 1]),
                 MEDLoader.DataArrayDouble([0, 1]))
     m = m.buildUnstructured()
     m.setName("TinyMesh")
     f = MEDLoader.MEDCouplingFieldDouble(MEDLoader.ON_CELLS)
     f.setMesh(m)
     nbOfCompo = 4100
     arr = MEDLoader.DataArrayDouble(nbOfCompo * 3)
     arr.iota()
     arr.rearrange(nbOfCompo)
     arr.setInfoOnComponents(["c%i" % (i) for i in range(nbOfCompo)])
     f.setArray(arr)
     f.setName("FieldBigCompo")
     MEDLoader.WriteField(fileName, f, True)
     f2 = MEDLoader.ReadFieldCell(fileName, m.getName(), 0, f.getName(), -1,
                                  -1)
     self.assertTrue(f.isEqual(f2, 1e-12, 1e-12))
     pass
Example #7
0
def read_typ2(fichier, nom_med):
    with open(fichier, "r") as fic:
        lines = fic.readlines()
    nb_som = int(lines[1].strip())
    nb_cel = int(lines[3 + nb_som].strip())

    som = [map(float, line.split()) for line in lines[2:2 + nb_som]]

    # les connectivites ne partent pas de 0...
    tmp_cel = [map(int, line.split()[1:]) for line in lines[4 + nb_som:]]
    cel = [[p - 1 for p in c] for c in tmp_cel]

    mesh = ml.MEDCouplingUMesh("mesh", 2)
    mesh.allocateCells(len(cel))
    for p in cel:
        mesh.insertNextCell(ml.NORM_POLYGON, len(p), p)
    mesh.finishInsertingCells()

    pts = []
    for p in som:
        pts.extend(p)
    co = ml.DataArrayDouble(pts, len(pts) / 2, 2)
    mesh.setCoords(co)

    mf, d, di, r, ri = mesh.buildDescendingConnectivity()
    mf.setName("mesh")
    mm = ml.MEDFileUMesh.New()
    mm.setMeshAtLevel(0, mesh)
    mm.setMeshAtLevel(-1, mf)

    g = []
    nb_vois = ri.deltaShiftIndex()
    for i in range(mf.getNumberOfCells()):
        if nb_vois[i] == 1: g.append(i)
    grp = ml.DataArrayInt.New(g)
    grp.setName("boundary")
    mm.addGroup(-1, grp)

    mm.write("{}/mesh.med".format(nom_med), 2)
Example #8
0
def getWeirdMesh(xmin,
                 xmax,
                 ymin,
                 ymax,
                 lx,
                 ly,
                 str,
                 func=None,
                 extr=-1,
                 unpo=False):
    polys = []
    ic = 0
    for iy, y in enumerate(ly[:-1]):
        for ix, x in enumerate(lx[:-1]):
            ic += 1
            dx = lx[ix + 1] - x
            dy = ly[iy + 1] - y
            c = str[ic % len(str)] if func is None else str[int(
                min(
                    max(
                        func(
                            xmin + (xmax - xmin) * (x + dx / 2 - lx[0]) /
                            (lx[-1] - lx[0]), ymin + (ymax - ymin) *
                            (y + dy / 2 - ly[0]) / (ly[-1] - ly[0])), 0),
                    len(str) - 1))]
            if c == "-":  # deux rectangles (horizontale)
                polys.extend([[[x + dx * i, y + dy * (j + k) / 2]
                               for (i, j) in [(0, 0), (0, 1), (1, 1), (1, 0)]]
                              for k in range(2)])
            elif c == "|":  # deux rectangles (verticale)
                polys.extend([[[x + dx * (i + k) / 2, y + j]
                               for (i, j) in [(0, 0), (0, 1), (1, 1), (1, 0)]]
                              for k in range(2)])
            elif c == "+" or c == "#" or c.isdigit():  # petits carres
                n = 2 if c == "+" else 3 if c == "#" else int(c)
                polys.extend([[[x + dx * (i + k) / n, y + dy * (j + l) / n]
                               for (i, j) in [(0, 0), (0, 1), (1, 1), (1, 0)]]
                              for k in range(int(n)) for l in range(int(n))])
            elif c == "x" or c == "*":  # triangles en croix
                f = 2 * pi / 8
                l = [[
                    x + dx / 2 *
                    (1 + cos(f * k) / max(abs(cos(f * k)), abs(sin(f * k)))),
                    y + dy / 2 *
                    (1 + sin(f * k) / max(abs(cos(f * k)), abs(sin(f * k))))
                ] for k in range(-1, 8, 1 + (c == "x"))]
                polys.extend([[l[i], [x + dx / 2, y + dy / 2], l[i + 1]]
                              for i in range(len(l) - 1)])
            elif c == "/" or c == "\\":
                polys.extend(
                    [[[x + dx * i, y + dy * (1 - j if c == "/" else j)]
                      for (i, j) in [(0, 1), (1, 0), p]]
                     for p in [(0, 0), (1, 1)]])
            else:  # par defaut -> carre vide
                polys.append([[x + dx * i, y + dy * j]
                              for (i, j) in [(0, 0), (0, 1), (1, 1), (1, 0)]])

    polys = [[[
        xmin + (x - lx[0]) * (xmax - xmin) / (lx[-1] - lx[0]),
        ymin + (y - ly[0]) * (ymax - ymin) / (ly[-1] - ly[0])
    ] for [x, y] in p] for p in polys]

    mesh = ml.MEDCouplingUMesh("mesh", 2)
    mesh.allocateCells(len(polys))
    off = 0
    for p in polys:
        mesh.insertNextCell(ml.NORM_POLYGON, len(p),
                            [off + i for i in range(len(p))])
        off += len(p)
    mesh.finishInsertingCells()

    pts = [p for i in xange(len(polys)) for p in polys[i]]
    co = ml.DataArrayDouble(pts, len(pts), 2)
    mesh.setCoords(co)

    mesh.changeSpaceDimension(3)
    mesh.orientCorrectly2DCells([0., 0., -1.], False)
    mesh.changeSpaceDimension(2)
    mesh.mergeNodes(1e-8)
    mesh.conformize2D(1e-8)
    if unpo: mesh.unPolyze()

    if extr > 0:
        mesh.changeSpaceDimension(3)
        mesh1d = ml.MEDCouplingUMesh("ex", 1)
        mesh1d.allocateCells(extr)
        coo = [0., 0., 0.]
        for i in range(extr):
            mesh1d.insertNextCell(ml.NORM_SEG2, 2, [i, i + 1])
            coo.extend([0., 0., float(i + 1) / float(extr)])
        coo_arr = ml.DataArrayDouble(coo, extr + 1, 3)
        mesh1d.setCoords(coo_arr)
        mesh = mesh.buildExtrudedMesh(mesh1d, 0)
        mesh.setName("mesh")

    mf, desc, descIndx, revDesc, revDescIndx = mesh.buildDescendingConnectivity(
    )
    mf.setName("mesh")
    mm = ml.MEDFileUMesh.New()
    mm.setMeshAtLevel(0, mesh)
    mm.setMeshAtLevel(-1, mf)

    bf = mf.computeCellCenterOfMass()
    noms_cl = [["left", "right"]]
    if extr > 0: noms_cl.append(["front", "back"])
    noms_cl.append(["down", "up"])
    for i in range(2 +
                   (extr > 0)):  # frontieres en x puis y (puis en z si extr)
        for j in range(2):  # min puis max
            g = []
            for idx, b in enumerate(bf):
                if abs(b[i] -
                       [[xmin, xmax], [ymin, ymax], [0., 1.]][i][j]) < 1e-5:
                    g.append(idx)
            grp = ml.DataArrayInt.New(g)
            grp.setName(noms_cl[i][j])
            mm.addGroup(-1, grp)

    return mm
import MEDLoader as ml
# Mesh creation
targetCoords = [
    -0.3, -0.3, 0.2, -0.3, 0.7, -0.3, -0.3, 0.2, 0.2, 0.2, 0.7, 0.2, -0.3, 0.7,
    0.2, 0.7, 0.7, 0.7
]
targetConn = [0, 3, 4, 1, 1, 4, 2, 4, 5, 2, 6, 7, 4, 3, 7, 8, 5, 4]
targetMesh = ml.MEDCouplingUMesh("MyMesh", 2)
targetMesh.allocateCells(5)
targetMesh.insertNextCell(ml.NORM_TRI3, 3, targetConn[4:7])
targetMesh.insertNextCell(ml.NORM_TRI3, 3, targetConn[7:10])
targetMesh.insertNextCell(ml.NORM_QUAD4, 4, targetConn[0:4])
targetMesh.insertNextCell(ml.NORM_QUAD4, 4, targetConn[10:14])
targetMesh.insertNextCell(ml.NORM_QUAD4, 4, targetConn[14:18])
myCoords = ml.DataArrayDouble(targetCoords, 9, 2)
myCoords.setInfoOnComponents(["X [km]", "YY [mm]"])
targetMesh.setCoords(myCoords)
# Writing mesh only
ml.WriteUMesh("TargetMesh.med", targetMesh, True)  # True means 'from scratch'
# Re-read it and test equality
meshRead = ml.ReadUMeshFromFile("TargetMesh.med", targetMesh.getName(), 0)
print "Is the read mesh equal to 'targetMesh' ?", meshRead.isEqual(
    targetMesh, 1e-12)
# Writing a field and its support mesh in one go
f = ml.MEDCouplingFieldDouble.New(ml.ON_CELLS, ml.ONE_TIME)
f.setTime(5.6, 7, 8)  # Declare the timestep associated to the field
f.setArray(targetMesh.computeCellCenterOfMass())
f.setMesh(targetMesh)
f.setName("AFieldName")
ml.WriteField("MyFirstField.med", f, True)
Example #10
0
 def testEasyFieldRead1(self):
     fname = "Pyfile111.med"
     arr = MEDLoader.DataArrayDouble(4)
     arr.iota()
     m = MEDLoader.MEDCouplingCMesh()
     m.setCoords(arr, arr)
     m = m.buildUnstructured()
     m.setName("mesh")
     f = MEDLoader.MEDCouplingFieldDouble(MEDLoader.ON_CELLS)
     f.setName("field")
     f.setTime(3., 1, 2)
     da = MEDLoader.DataArrayDouble([2, 3, 4, 5, 6, 7, 8, 9, 10])
     f.setArray(da)
     f.setMesh(m)
     MEDLoader.WriteField(fname, f, True)
     #
     self.assertTrue(f.isEqual(MEDLoader.ReadField(fname), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field"), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 1, 2), 1e-12, 1e-12))
     #
     f3 = f.deepCopy()
     f3.setArray(f.getArray() + 30)
     f3.setName("field2")
     f3.setTime(5., 4, 5)
     MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname, f3)
     #
     self.assertRaises(Exception, MEDLoader.ReadField,
                       fname)  # because several fields in fname now
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field"), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f3.isEqual(MEDLoader.ReadField(fname, "field2"), 1e-12, 1e-12))
     self.assertTrue(
         f3.isEqual(MEDLoader.ReadField(fname, "field2", 4, 5), 1e-12,
                    1e-12))
     self.assertTrue(
         f3.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field2", 4, 5), 1e-12, 1e-12))
     #
     f2 = f.deepCopy()
     f2.setTime(4., 3, 4)
     f2.setArray(f2.getArray() + 10)
     MEDLoader.WriteFieldUsingAlreadyWrittenMesh(fname, f2)
     #
     self.assertRaises(
         Exception, MEDLoader.ReadField,
         fname)  # because unique field "field" has more than one time step
     self.assertRaises(
         Exception, MEDLoader.ReadField, fname, "field"
     )  # because unique field "field" has more than one time step
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f2.isEqual(MEDLoader.ReadField(fname, "field", 3, 4), 1e-12,
                    1e-12))
     self.assertTrue(
         f2.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 3, 4), 1e-12, 1e-12))
     #
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f2.isEqual(MEDLoader.ReadField(fname, "field", 3, 4), 1e-12,
                    1e-12))
     self.assertTrue(
         f2.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 3, 4), 1e-12, 1e-12))
     #
     self.assertTrue(
         f3.isEqual(MEDLoader.ReadField(fname, "field2"), 1e-12, 1e-12))
     self.assertTrue(
         f3.isEqual(MEDLoader.ReadField(fname, "field2", 4, 5), 1e-12,
                    1e-12))
     self.assertRaises(Exception, MEDLoader.ReadField, fname, "field2", 5,
                       5)  # invalid time step
     self.assertTrue(
         f3.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field2", 4, 5), 1e-12, 1e-12))
     self.assertRaises(Exception, MEDLoader.ReadField, MEDLoader.ON_CELLS,
                       fname, "mesh", 0, "field2", 5,
                       5)  # invalid time step
     # Test on profile - restart from scratch
     mm = MEDLoader.MEDFileUMesh()
     mm[0] = m
     mm.write(fname, 2)
     #
     pfl = MEDLoader.DataArrayInt(list(range(8)))
     pfl.setName("PFL")
     #
     f = MEDLoader.MEDCouplingFieldDouble(MEDLoader.ON_CELLS)
     f.setName("field")
     f.setTime(3., 1, 2)
     da = MEDLoader.DataArrayDouble([2, 3, 4, 5, 6, 7, 8, 9])
     f.setArray(da)
     f.setMesh(m[pfl])
     f.checkConsistencyLight()
     #
     f1ts = MEDLoader.MEDFileField1TS()
     f1ts.setFieldProfile(f, mm, 0, pfl)
     f1ts.write(fname, 0)
     #
     self.assertTrue(f.isEqual(MEDLoader.ReadField(fname), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field"), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 1, 2), 1e-12, 1e-12))
     #
     f3 = f.deepCopy()
     f3.setArray(f.getArray() + 30)
     f3.setName("field2")
     f3.setTime(5., 4, 5)
     f1ts = MEDLoader.MEDFileField1TS()
     f1ts.setFieldProfile(f3, mm, 0, pfl)
     f1ts.write(fname, 0)
     #
     self.assertRaises(Exception, MEDLoader.ReadField,
                       fname)  # because several fields in fname now
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field"), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f3.isEqual(MEDLoader.ReadField(fname, "field2"), 1e-12, 1e-12))
     self.assertTrue(
         f3.isEqual(MEDLoader.ReadField(fname, "field2", 4, 5), 1e-12,
                    1e-12))
     self.assertTrue(
         f3.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field2", 4, 5), 1e-12, 1e-12))
     #
     f2 = f.deepCopy()
     f2.setTime(4., 3, 4)
     f2.setArray(f2.getArray() + 10)
     f1ts = MEDLoader.MEDFileField1TS()
     f1ts.setFieldProfile(f2, mm, 0, pfl)
     f1ts.write(fname, 0)
     #
     self.assertRaises(
         Exception, MEDLoader.ReadField,
         fname)  # because unique field "field" has more than one time step
     self.assertRaises(
         Exception, MEDLoader.ReadField, fname, "field"
     )  # because unique field "field" has more than one time step
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f2.isEqual(MEDLoader.ReadField(fname, "field", 3, 4), 1e-12,
                    1e-12))
     self.assertTrue(
         f2.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 3, 4), 1e-12, 1e-12))
     #
     self.assertTrue(
         f.isEqual(MEDLoader.ReadField(fname, "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 1, 2), 1e-12, 1e-12))
     self.assertTrue(
         f2.isEqual(MEDLoader.ReadField(fname, "field", 3, 4), 1e-12,
                    1e-12))
     self.assertTrue(
         f2.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field", 3, 4), 1e-12, 1e-12))
     #
     self.assertTrue(
         f3.isEqual(MEDLoader.ReadField(fname, "field2"), 1e-12, 1e-12))
     self.assertTrue(
         f3.isEqual(MEDLoader.ReadField(fname, "field2", 4, 5), 1e-12,
                    1e-12))
     self.assertRaises(Exception, MEDLoader.ReadField, fname, "field2", 5,
                       5)  # invalid time step
     self.assertTrue(
         f3.isEqual(
             MEDLoader.ReadField(MEDLoader.ON_CELLS, fname, "mesh", 0,
                                 "field2", 4, 5), 1e-12, 1e-12))
     self.assertRaises(Exception, MEDLoader.ReadField, MEDLoader.ON_CELLS,
                       fname, "mesh", 0, "field2", 5,
                       5)  # invalid time step
     pass