Esempio n. 1
0
def main(path='./'):

    if len(sys.argv) == 2:
        path = sys.argv[1]

    interpOrders = [1, 2, 3, 4]

    gl = gridlayout.GridLayout()

    directions = gl.directions
    quantities = gl.hybridQuantities

    nbrCellXList = [40, 40, 40]
    nbrCellYList = [0, 12, 12]
    nbrCellZList = [0, 0, 12]

    nbDimsList = [1, 2, 3]

    dxList = [0.1, 0.1, 0.1]  # 1D, 2D and 3D cases
    dyList = [0., 0.1, 0.1]
    dzList = [0., 0., 0.1]

    maxNbrDim = 3

    baseName = 'gridIndexing'

    outFilenameBase = os.path.join(path, baseName)
    outFiles = []

    for interpOrder in interpOrders:
        filenames = [
            outFilenameBase + '_' + str(dim) + 'd_O' + str(interpOrder) +
            '.txt' for dim in nbDimsList
        ]
        outFiles.append([open(f, 'w') for f in filenames])

    for interpOrder, outFilesDim in zip(interpOrders, outFiles):
        for dim, outFile, nbrCellX, nbrCellY, nbrCellZ, dx, dy, dz in zip(
                nbDimsList, outFilesDim, nbrCellXList, nbrCellYList,
                nbrCellZList, dxList, dyList, dzList):

            params = IndexingParams(dim, interpOrder)

            params.setNbrCell(nbrCellX, nbrCellY, nbrCellZ)
            params.setDl(dx, dy, dz)

            for quantity in quantities:

                params.setIndexes(quantity, gl)

                outString = "{} {} {} {} {} {} {}\n".format(
                    quantities.index(quantity), params.nbrCell, params.dl,
                    params.physicalStart, params.physicalEnd,
                    params.ghostStart, params.ghostEnd)

                outFile.write(utilities.removeTupleFormat(outString))

    for files in outFiles:
        for f in files:
            f.close()
Esempio n. 2
0
def test_faraday_yee1D(path):

    layout = gridlayout.GridLayout()  # yee layout

    tv = TestVariables()

    By = np.zeros(layout.allocSize(tv.interpOrder, tv.ByCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)
    Bz = np.zeros(layout.allocSize(tv.interpOrder, tv.BzCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)

    Ey = np.zeros(layout.allocSize(tv.interpOrder, tv.EyCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)
    Ez = np.zeros(layout.allocSize(tv.interpOrder, tv.EzCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)

    ByNew = np.zeros(layout.allocSize(tv.interpOrder, tv.ByCentering[0],
                                      tv.nbrCells[0]),
                     dtype=np.float64)
    BzNew = np.zeros(layout.allocSize(tv.interpOrder, tv.BzCentering[0],
                                      tv.nbrCells[0]),
                     dtype=np.float64)

    psi_p_X = layout.physicalStartIndex(tv.interpOrder, 'primal')
    pei_p_X = layout.physicalEndIndex(tv.interpOrder, 'primal', tv.nbrCells[0])

    psi_d_X = layout.physicalStartIndex(tv.interpOrder, 'dual')
    pei_d_X = layout.physicalEndIndex(tv.interpOrder, 'dual', tv.nbrCells[0])

    nbrGhost_p = layout.nbrGhosts(tv.interpOrder, 'primal')
    nbrGhost_d = layout.nbrGhosts(tv.interpOrder, 'dual')

    x_primal = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'primal',
                         tv.nbrCells[0])) - tv.meshSize[0] * nbrGhost_p
    x_dual = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'dual', tv.nbrCells[0])
    ) - tv.meshSize[0] * nbrGhost_d + tv.meshSize[0] * 0.5

    Ey = np.cos(2 * np.pi / tv.domainSize[0] * x_primal)
    Ez = np.sin(2 * np.pi / tv.domainSize[0] * x_primal)
    By = np.tanh(x_dual - 0.5 * tv.domainSize[0])
    Bz = np.tanh(x_dual - 0.5 * tv.domainSize[0])

    ByNew[psi_d_X:pei_d_X + 1] = By[psi_d_X:pei_d_X + 1] + tv.dt * (
        Ez[psi_p_X + 1:pei_p_X + 1] - Ez[psi_p_X:pei_p_X]) / tv.meshSize[0]
    BzNew[psi_d_X:pei_d_X + 1] = Bz[psi_d_X:pei_d_X + 1] - tv.dt * (
        Ey[psi_p_X + 1:pei_p_X + 1] - Ey[psi_p_X:pei_p_X]) / tv.meshSize[0]

    filename_dbydt = "dbydt_yee_1D_order1.txt"
    filename_dbzdt = "dbzdt_yee_1D_order1.txt"

    np.savetxt(os.path.join(path, filename_dbydt), ByNew, delimiter=" ")
    np.savetxt(os.path.join(path, filename_dbzdt), BzNew, delimiter=" ")
def fieldCoords(primalIndex, startIndex, quantity, direction, dl, origin):
    halfCell = 0.
    gl = gridlayout.GridLayout()

    if gl.qtyCentering(quantity, direction) == 'dual':
        halfCell = 0.5

    x = ((primalIndex - startIndex) + halfCell) * dl + origin

    return x
Esempio n. 4
0
def test_deriv1D(path):
    # derivative along X:
    # By is dual in X, and derived along X it should lie on Ez
    # Ez is primal in X, and derived along X it should lie on By

    layout = gridlayout.GridLayout()  # yee layout

    tv = TestVariables()

    for interpOrder in tv.interpOrders:

        filename_dxBy = 'dxBy_interpOrder_{}_1d.txt'.format(interpOrder)
        filename_dxEz = 'dxEz_interpOrder_{}_1d.txt'.format(interpOrder)

        By = np.zeros(
            layout.allocSize(interpOrder, tv.ByCentering[0], tv.nbrCells[0]))
        Ez = np.zeros(
            layout.allocSize(interpOrder, tv.EzCentering[0], tv.nbrCells[0]))

        dxBy = np.zeros(layout.allocSizeDerived(interpOrder, tv.ByCentering[0],
                                                tv.nbrCells[0]),
                        dtype=np.float64)
        dxEz = np.zeros(layout.allocSizeDerived(interpOrder, tv.EzCentering[0],
                                                tv.nbrCells[0]),
                        dtype=np.float64)

        nbrGhost_p = layout.nbrGhosts(interpOrder, 'primal')
        nbrGhost_d = layout.nbrGhosts(interpOrder, 'dual')

        x_dual = tv.meshSize[0] * np.arange(
            layout.allocSize(interpOrder, 'dual', tv.nbrCells[0])
        ) - tv.meshSize[0] * nbrGhost_d + tv.meshSize[0] * 0.5
        x_primal = tv.meshSize[0] * np.arange(
            layout.allocSize(interpOrder, 'primal',
                             tv.nbrCells[0])) - tv.meshSize[0] * nbrGhost_p

        By = np.cos(2 * np.pi / tv.domainSize[0] * x_dual)
        Ez = np.cos(2 * np.pi / tv.domainSize[0] * x_primal)

        psi_d_X = layout.physicalStartIndex(interpOrder, 'dual')
        pei_d_X = layout.physicalEndIndex(interpOrder, 'dual', tv.nbrCells[0])
        psi_p_X = layout.physicalStartIndex(interpOrder, 'primal')
        pei_p_X = layout.physicalEndIndex(interpOrder, 'primal',
                                          tv.nbrCells[0])

        dxBy[psi_p_X:pei_p_X +
             1] = (By[psi_d_X:pei_d_X + 2] -
                   By[psi_d_X - 1:pei_d_X + 1]) / tv.meshSize[0]
        dxEz[psi_d_X:pei_d_X + 1] = (Ez[psi_p_X + 1:pei_p_X + 1] -
                                     Ez[psi_p_X:pei_p_X]) / tv.meshSize[0]

        np.savetxt(os.path.join(path, filename_dxBy), dxBy, delimiter=" ")
        np.savetxt(os.path.join(path, filename_dxEz), dxEz, delimiter=" ")
Esempio n. 5
0
def test_ampere_yee1D(path):

    layout = gridlayout.GridLayout()  # yee layout

    tv = TestVariables()

    By = np.zeros(layout.allocSize(tv.interpOrder, tv.ByCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)
    Bz = np.zeros(layout.allocSize(tv.interpOrder, tv.BzCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)
    Jy = np.zeros(layout.allocSize(tv.interpOrder, tv.JyCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)
    Jz = np.zeros(layout.allocSize(tv.interpOrder, tv.JzCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)

    psi_p_X = layout.physicalStartIndex(tv.interpOrder, 'primal')
    pei_p_X = layout.physicalEndIndex(tv.interpOrder, 'primal', tv.nbrCells[0])

    psi_d_X = layout.physicalStartIndex(tv.interpOrder, 'dual')
    pei_d_X = layout.physicalEndIndex(tv.interpOrder, 'dual', tv.nbrCells[0])

    nbrGhost_p = layout.nbrGhosts(tv.interpOrder, 'primal')
    nbrGhost_d = layout.nbrGhosts(tv.interpOrder, 'dual')

    x_dual = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'dual', tv.nbrCells[0])
    ) - tv.meshSize[0] * nbrGhost_d + tv.meshSize[0] * 0.5
    x_primal = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'primal',
                         tv.nbrCells[0])) - tv.meshSize[0] * nbrGhost_p

    By = np.cos(2 * np.pi / tv.domainSize[0] * x_dual)
    Bz = np.sin(2 * np.pi / tv.domainSize[0] * x_dual)

    # Jy = -dxBz
    # Jz =  dxBy
    Jy[psi_p_X:pei_p_X + 1] = -(Bz[psi_d_X:pei_d_X + 2] -
                                Bz[psi_d_X - 1:pei_d_X + 1]) / tv.meshSize[0]
    Jz[psi_p_X:pei_p_X + 1] = (By[psi_d_X:pei_d_X + 2] -
                               By[psi_d_X - 1:pei_d_X + 1]) / tv.meshSize[0]

    filename_jy = "jy_yee_1D_order1.txt"
    filename_jz = "jz_yee_1D_order1.txt"

    np.savetxt(os.path.join(path, filename_jy), Jy, delimiter=" ")
    np.savetxt(os.path.join(path, filename_jz), Jz, delimiter=" ")
def main(path='./'):

    if len(sys.argv) == 2:
        path = sys.argv[1]

    # TODO: refactor this for all python since they are the same

    interpOrders = [1, 2, 3, 4]

    nbDimsList = [1, 2, 3]

    nbrCellXList = [40, 40, 40]
    nbrCellYList = [0, 12, 12]
    nbrCellZList = [0, 0, 12]

    dxList = [0.01, 0.01, 0.01]
    dyList = [0., 0.01, 0.01]
    dzList = [0., 0., 0.01]

    originPosition = [0., 0., 0.]

    gl = gridlayout.GridLayout()

    # TODO : end Todo

    # TODO: FieldCoords and CenteredCoords share a common base, refactor this

    baseNameSummary = "fieldCoords_summary"
    baseNameValues = "fieldCoords_values"

    outFilenameBaseSummary = os.path.join(path, baseNameSummary)
    outFilenameBaseValues = os.path.join(path, baseNameValues)
    outSummaries = []
    outValues = []

    for interpOrder in interpOrders:
        filenamesSum = [
            outFilenameBaseSummary + '_' + str(dim) + 'd_O' +
            str(interpOrder) + '.txt' for dim in nbDimsList
        ]
        filenamesVal = [
            outFilenameBaseValues + '_' + str(dim) + 'd_O' + str(interpOrder) +
            '.txt' for dim in nbDimsList
        ]
        outSummaries.append([open(f, 'w') for f in filenamesSum])
        outValues.append([open(f, 'w') for f in filenamesVal])

    for interpOrder, outFilesSumDim, outFilesValDim in zip(
            interpOrders, outSummaries, outValues):
        for dimension,outFileS, outFileV,nbrCellX,nbrCellY,\
            nbrCellZ,dx,dy,dz in zip(nbDimsList, outFilesSumDim, outFilesValDim,
                                     nbrCellXList,nbrCellYList,
                                     nbrCellZList,dxList,dyList,
                                     dzList):

            for quantity in gl.hybridQuantities:

                params = FieldNodeCoordParams(dimension, interpOrder)
                params.setNbrCell(nbrCellX, nbrCellY, nbrCellZ)
                params.setDl(dx, dy, dz)

                centering = getQtyCentering(gl, quantity, dimension)

                params.setCoord(gl, originPosition, centering)

                summaryBasePart = "{} {} {} ".format(quantity, params.nbrCell,
                                                     params.dl)

                summaryGridLayoutPart = "{} {} {}\n".format(
                    params.iStart, params.iEnd, params.origin)

                outSummaryString = summaryBasePart + summaryGridLayoutPart

                outSummaryString = utilities.removeTupleFormat(
                    outSummaryString)

                outFileS.write(outSummaryString)

                if dimension == 1:
                    for position in np.arange(params.iStart, params.iEnd + 1):
                        outValuesString = "{} {} {}\n".format(
                            quantity, position,
                            fieldCoords(position, params.iStart, quantity, 'X',
                                        params.dl, params.origin))

                        outFileV.write(
                            utilities.removeTupleFormat(outValuesString))

                elif dimension == 2:
                    for positionX in np.arange(params.iStart[0],
                                               params.iEnd[0] + 1):
                        for positionY in np.arange(params.iStart[1],
                                                   params.iEnd[1] + 1):
                            position = (positionX, positionY)
                            centered = (fieldCoords(positionX,
                                                    params.iStart[0], quantity,
                                                    'X', params.dl[0],
                                                    params.origin[0]),
                                        fieldCoords(positionY,
                                                    params.iStart[1], quantity,
                                                    'Y', params.dl[1],
                                                    params.origin[1]))

                            outValuesString = "{} {} {}\n".format(
                                quantity, position, centered)

                            outFileV.write(
                                utilities.removeTupleFormat(outValuesString))

                elif dimension == 3:
                    for positionX in np.arange(params.iStart[0],
                                               params.iEnd[0] + 1):
                        for positionY in np.arange(params.iStart[1],
                                                   params.iEnd[1] + 1):
                            for positionZ in np.arange(params.iStart[2],
                                                       params.iEnd[2] + 1):

                                position = (positionX, positionY, positionZ)
                                centered = (fieldCoords(
                                    positionX, params.iStart[0], quantity, 'X',
                                    params.dl[0], params.origin[0]),
                                            fieldCoords(
                                                positionY, params.iStart[1],
                                                quantity, 'Y', params.dl[1],
                                                params.origin[1]),
                                            fieldCoords(
                                                positionZ, params.iStart[2],
                                                quantity, 'Z', params.dl[2],
                                                params.origin[2]))

                                outValuesString = "{} {} {}\n".format(
                                    quantity, position, centered)

                                outFileV.write(
                                    utilities.removeTupleFormat(
                                        outValuesString))

    for outFilesSumDim, outFilesValDim in zip(outSummaries, outValues):
        for f1, f2 in zip(outFilesSumDim, outFilesValDim):
            f1.close()
            f2.close()
Esempio n. 7
0
def main(path='./'):

    if len(sys.argv) == 2:
        path = sys.argv[1]

    # TODO: refactor this for all python since they are the same

    interpOrders = [1,2,3]

    nbDimsList= [1]#, 2, 3]


    nbrCellXList=[40, 40, 40]
    nbrCellYList=[ 0, 12, 12]
    nbrCellZList=[ 0,  0, 12]

    dxList=[0.01, 0.01, 0.01]
    dyList=[0. ,  0.01, 0.01]
    dzList=[0. ,  0.  , 0.01]


    originPosition = [0., 0., 0.]

    gl = gridlayout.GridLayout()


    # TODO : end Todo

    # TODO: FieldCoords and CenteredCoords share a common base, refactor this


    outSummary1D = open(os.path.join(path,"deriv_summary_1d.txt"), "w")
    outSummary2D = open(os.path.join(path,"deriv_summary_2d.txt"), "w")
    outSummary3D = open(os.path.join(path,"deriv_summary_3d.txt"), "w")

    outSummaries =[outSummary1D, outSummary2D, outSummary3D]

    outActualValues1D = open(os.path.join(path,"deriv_values_1d.txt"), "w")
    outActualValues2D = open(os.path.join(path,"deriv_values_2d.txt"), "w")
    outActualValues3D = open(os.path.join(path,"deriv_values_3d.txt"), "w")


    outActualValuesFiles = [outActualValues1D, outActualValues2D, outActualValues3D]


    outDerivedValues1D = open(os.path.join(path, "deriv_derived_values_1d.txt"),"w")


    for interpOrder in interpOrders:
        for dimension,outSummary, outValues,nbrCellX,nbrCellY,\
            nbrCellZ,dx,dy,dz in zip(nbDimsList, outSummaries,
                                     outActualValuesFiles,
                                     nbrCellXList,nbrCellYList,
                                     nbrCellZList,dxList,dyList,
                                     dzList):

            # TODO : the association depend on the direction
            #        Here we derive in the direction X
            quantities = ('Ex','Ey')
            derivedQuantities = ('rho','Bz')

            for quantity,derivQuantity in zip(quantities, derivedQuantities):

                params = DerivParams(dimension,interpOrder);
                params.setNbrCell(nbrCellX,nbrCellY,nbrCellZ)
                params.setDl(dx,dy,dz)

                centering = fieldNodeCoordinates.getQtyCentering(gl,quantity,dimension)
                derivedCentering = fieldNodeCoordinates.getQtyCentering(gl, derivQuantity, dimension)

                params.setCoord(gl, originPosition, centering, derivedCentering)


                summaryBasePart = "{} {} {} {} {} ".format(
                    params.interpOrder,
                    quantity,
                    derivQuantity,
                    params.nbrCell,
                    params.dl)

                summaryGridLayoutPart = " {} {} {} {} {}\n".format(
                    params.iGhostStart,
                    params.iGhostEnd,
                    params.iStart,
                    params.iEnd,
                    params.origin)

                outSummaryString = summaryBasePart + summaryGridLayoutPart

                outSummaryString = utilities.removeTupleFormat(outSummaryString)


                outSummary.write(outSummaryString)

                if dimension == 1:
                    for position in np.arange(params.iGhostStart, params.iGhostEnd ):
                        coord = fieldNodeCoordinates.fieldCoords(position, params.iStart,quantity,'X',params.dl, params.origin)
                        functionValue = primitive(coord)

                        outValuesString = "{} {} {} {}\n".format(
                            params.interpOrder,
                            quantity,
                            position,
                            functionValue,
                        )

                        outValues.write(utilities.removeTupleFormat(outValuesString))

                    for position in np.arange(params.iStart, params.iEnd + 1 ):
                        coord = fieldNodeCoordinates.fieldCoords(position, params.iStart,derivQuantity,'X',params.dl, params.origin)

                        derivedValue = scipy.misc.derivative(primitive,coord,dx,order=3)

                        outDerivedValuesString = "{} {} {} {}\n".format(
                            params.interpOrder,
                            derivQuantity,
                            position,
                            derivedValue
                        )

                        outDerivedValues1D.write(utilities.removeTupleFormat(outDerivedValuesString))


    for outSummary,outValues in zip(outSummaries, outActualValuesFiles):
        outSummary.close()
        outValues.close()

    outDerivedValues1D.close()
Esempio n. 8
0
def test_faraday_yee3D(path):

    layout = gridlayout.GridLayout()  # yee layout

    tv = TestVariables()

    Bx = np.zeros([
        layout.allocSize(tv.interpOrder, tv.BxCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.BxCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.BxCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)
    By = np.zeros([
        layout.allocSize(tv.interpOrder, tv.ByCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.ByCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.ByCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)
    Bz = np.zeros([
        layout.allocSize(tv.interpOrder, tv.BzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.BzCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.BzCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)

    Ex = np.zeros([
        layout.allocSize(tv.interpOrder, tv.ExCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)
    Ey = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EyCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)
    Ez = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)

    BxNew = np.zeros([
        layout.allocSize(tv.interpOrder, tv.BxCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.BxCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.BxCentering[2], tv.nbrCells[2])
    ],
                     dtype=np.float64)
    ByNew = np.zeros([
        layout.allocSize(tv.interpOrder, tv.ByCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.ByCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.ByCentering[2], tv.nbrCells[2])
    ],
                     dtype=np.float64)
    BzNew = np.zeros([
        layout.allocSize(tv.interpOrder, tv.BzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.BzCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.BzCentering[2], tv.nbrCells[2])
    ],
                     dtype=np.float64)

    u1 = np.zeros_like(BxNew)
    u2 = np.zeros_like(BxNew)
    v1 = np.zeros_like(ByNew)
    v2 = np.zeros_like(ByNew)
    w1 = np.zeros_like(BzNew)
    w2 = np.zeros_like(BzNew)

    psi_p_X = layout.physicalStartIndex(tv.interpOrder, 'primal')
    pei_p_X = layout.physicalEndIndex(tv.interpOrder, 'primal', tv.nbrCells[0])
    psi_p_Y = layout.physicalStartIndex(tv.interpOrder, 'primal')
    pei_p_Y = layout.physicalEndIndex(tv.interpOrder, 'primal', tv.nbrCells[1])
    psi_p_Z = layout.physicalStartIndex(tv.interpOrder, 'primal')
    pei_p_Z = layout.physicalEndIndex(tv.interpOrder, 'primal', tv.nbrCells[2])

    psi_d_X = layout.physicalStartIndex(tv.interpOrder, 'dual')
    pei_d_X = layout.physicalEndIndex(tv.interpOrder, 'dual', tv.nbrCells[0])
    psi_d_Y = layout.physicalStartIndex(tv.interpOrder, 'dual')
    pei_d_Y = layout.physicalEndIndex(tv.interpOrder, 'dual', tv.nbrCells[1])
    psi_d_Z = layout.physicalStartIndex(tv.interpOrder, 'dual')
    pei_d_Z = layout.physicalEndIndex(tv.interpOrder, 'dual', tv.nbrCells[2])

    nbrGhost_p = layout.nbrGhosts(tv.interpOrder, 'primal')
    nbrGhost_d = layout.nbrGhosts(tv.interpOrder, 'dual')

    x_primal = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'primal',
                         tv.nbrCells[0])) - tv.meshSize[0] * nbrGhost_p
    y_primal = tv.meshSize[1] * np.arange(
        layout.allocSize(tv.interpOrder, 'primal',
                         tv.nbrCells[1])) - tv.meshSize[1] * nbrGhost_p
    z_primal = tv.meshSize[2] * np.arange(
        layout.allocSize(tv.interpOrder, 'primal',
                         tv.nbrCells[2])) - tv.meshSize[2] * nbrGhost_p
    x_dual = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'dual', tv.nbrCells[0])
    ) - tv.meshSize[0] * nbrGhost_d + tv.meshSize[0] * 0.5
    y_dual = tv.meshSize[1] * np.arange(
        layout.allocSize(tv.interpOrder, 'dual', tv.nbrCells[1])
    ) - tv.meshSize[1] * nbrGhost_d + tv.meshSize[1] * 0.5
    z_dual = tv.meshSize[2] * np.arange(
        layout.allocSize(tv.interpOrder, 'dual', tv.nbrCells[2])
    ) - tv.meshSize[2] * nbrGhost_d + tv.meshSize[2] * 0.5

    Ex = np.tensordot(np.sin(2 * np.pi / tv.domainSize[0] * x_dual),
                      np.tensordot(
                          np.cos(2 * np.pi / tv.domainSize[1] * y_primal),
                          np.tanh(2 * np.pi / tv.domainSize[2] * z_primal),
                          axes=0),
                      axes=0)
    Ey = np.tensordot(np.tanh(2 * np.pi / tv.domainSize[0] * x_primal),
                      np.tensordot(
                          np.sin(2 * np.pi / tv.domainSize[1] * y_dual),
                          np.cos(2 * np.pi / tv.domainSize[2] * z_primal),
                          axes=0),
                      axes=0)
    Ez = np.tensordot(np.cos(2 * np.pi / tv.domainSize[0] * x_primal),
                      np.tensordot(
                          np.tanh(2 * np.pi / tv.domainSize[1] * y_primal),
                          np.sin(2 * np.pi / tv.domainSize[2] * z_dual),
                          axes=0),
                      axes=0)

    Bx = np.tensordot(np.tanh(x_primal - 0.5 * tv.domainSize[0]),
                      np.tensordot(np.tanh(y_dual - 0.5 * tv.domainSize[1]),
                                   np.tanh(z_dual - 0.5 * tv.domainSize[2]),
                                   axes=0),
                      axes=0)
    By = np.tensordot(np.tanh(x_dual - 0.5 * tv.domainSize[0]),
                      np.tensordot(np.tanh(y_primal - 0.5 * tv.domainSize[1]),
                                   np.tanh(z_dual - 0.5 * tv.domainSize[2]),
                                   axes=0),
                      axes=0)
    Bz = np.tensordot(np.tanh(x_dual - 0.5 * tv.domainSize[0]),
                      np.tensordot(np.tanh(y_dual - 0.5 * tv.domainSize[1]),
                                   np.tanh(z_primal - 0.5 * tv.domainSize[2]),
                                   axes=0),
                      axes=0)

    u1[:, psi_d_Y:pei_d_Y +
       1, :] = -tv.dt * (Ez[:, psi_p_Y + 1:pei_p_Y + 1, :] -
                         Ez[:, psi_p_Y:pei_p_Y, :]) / tv.meshSize[1]
    u2[:, :, psi_d_Z:pei_d_Z +
       1] = +tv.dt * (Ey[:, :, psi_p_Z + 1:pei_p_Z + 1] -
                      Ey[:, :, psi_p_Z:pei_p_Z]) / tv.meshSize[2]
    BxNew = Bx + u1 + u2

    v1[:, :, psi_d_Z:pei_d_Z +
       1] = -tv.dt * (Ex[:, :, psi_p_Z + 1:pei_p_Z + 1] -
                      Ex[:, :, psi_p_Z:pei_p_Z]) / tv.meshSize[2]
    v2[psi_d_X:pei_d_X +
       1, :, :] = +tv.dt * (Ez[psi_p_X + 1:pei_p_X + 1, :, :] -
                            Ez[psi_p_X:pei_p_X, :, :]) / tv.meshSize[0]
    ByNew = By + v1 + v2

    w1[psi_d_X:pei_d_X +
       1, :, :] = -tv.dt * (Ey[psi_p_X + 1:pei_p_X + 1, :, :] -
                            Ey[psi_p_X:pei_p_X, :, :]) / tv.meshSize[0]
    w2[:, psi_d_Y:pei_d_Y +
       1, :] = +tv.dt * (Ex[:, psi_p_Y + 1:pei_p_Y + 1, :] -
                         Ex[:, psi_p_Y:pei_p_Y, :]) / tv.meshSize[1]
    BzNew = Bz + w1 + w2

    filename_dbxdt = "dbxdt_yee_3D_order1.txt"
    filename_dbydt = "dbydt_yee_3D_order1.txt"
    filename_dbzdt = "dbzdt_yee_3D_order1.txt"

    np.savetxt(os.path.join(path, filename_dbxdt),
               BxNew.flatten('C'),
               delimiter=" ")
    np.savetxt(os.path.join(path, filename_dbydt),
               ByNew.flatten('C'),
               delimiter=" ")
    np.savetxt(os.path.join(path, filename_dbzdt),
               BzNew.flatten('C'),
               delimiter=" ")
Esempio n. 9
0
def test_laplacian_yee1D(path):

    layout = gridlayout.GridLayout()  # yee layout

    tv = TestVariables()

    for interpOrder in tv.interpOrders:

        Jx = np.zeros(layout.allocSize(interpOrder, tv.JxCentering[0],
                                       tv.nbrCells[0]),
                      dtype=np.float64)
        Jy = np.zeros(layout.allocSize(interpOrder, tv.JyCentering[0],
                                       tv.nbrCells[0]),
                      dtype=np.float64)
        Jz = np.zeros(layout.allocSize(interpOrder, tv.JzCentering[0],
                                       tv.nbrCells[0]),
                      dtype=np.float64)

        lapJx = np.zeros(layout.allocSize(interpOrder, tv.JxCentering[0],
                                          tv.nbrCells[0]),
                         dtype=np.float64)
        lapJy = np.zeros(layout.allocSize(interpOrder, tv.JyCentering[0],
                                          tv.nbrCells[0]),
                         dtype=np.float64)
        lapJz = np.zeros(layout.allocSize(interpOrder, tv.JzCentering[0],
                                          tv.nbrCells[0]),
                         dtype=np.float64)

        psi_p_X = layout.physicalStartIndex(interpOrder, 'primal')
        pei_p_X = layout.physicalEndIndex(interpOrder, 'primal',
                                          tv.nbrCells[0])

        psi_d_X = layout.physicalStartIndex(interpOrder, 'dual')
        pei_d_X = layout.physicalEndIndex(interpOrder, 'dual', tv.nbrCells[0])

        nbrGhost_p = layout.nbrGhosts(interpOrder, 'primal')
        nbrGhost_d = layout.nbrGhosts(interpOrder, 'dual')

        x_primal = tv.meshSize[0] * np.arange(
            layout.allocSize(interpOrder, 'primal',
                             tv.nbrCells[0])) - tv.meshSize[0] * nbrGhost_p
        x_dual = tv.meshSize[0] * np.arange(
            layout.allocSize(interpOrder, 'dual', tv.nbrCells[0])
        ) - tv.meshSize[0] * nbrGhost_d + tv.meshSize[0] * 0.5

        Jx = np.sinh(0.1 * x_dual)
        Jy = np.sinh(0.3 * x_primal)
        Jz = np.sinh(0.2 * x_primal)

        lapJx[psi_d_X:pei_d_X + 1] = (
            Jx[psi_d_X + 1:pei_d_X + 2] - 2.0 * Jx[psi_d_X:pei_d_X + 1] +
            Jx[psi_d_X - 1:pei_d_X]) / (tv.meshSize[0] * tv.meshSize[0])
        lapJy[psi_p_X:pei_p_X + 1] = (
            Jy[psi_p_X + 1:pei_p_X + 2] - 2.0 * Jy[psi_p_X:pei_p_X + 1] +
            Jy[psi_p_X - 1:pei_p_X]) / (tv.meshSize[0] * tv.meshSize[0])
        lapJz[psi_p_X:pei_p_X + 1] = (
            Jz[psi_p_X + 1:pei_p_X + 2] - 2.0 * Jz[psi_p_X:pei_p_X + 1] +
            Jz[psi_p_X - 1:pei_p_X]) / (tv.meshSize[0] * tv.meshSize[0])

        filename_lapJx = 'lapJx_interpOrder_{}_1d.txt'.format(interpOrder)
        filename_lapJy = 'lapJy_interpOrder_{}_1d.txt'.format(interpOrder)
        filename_lapJz = 'lapJz_interpOrder_{}_1d.txt'.format(interpOrder)

        np.savetxt(os.path.join(path, filename_lapJx), lapJx, delimiter=" ")
        np.savetxt(os.path.join(path, filename_lapJy), lapJy, delimiter=" ")
        np.savetxt(os.path.join(path, filename_lapJz), lapJz, delimiter=" ")
Esempio n. 10
0
def test_laplacian_yee3D(path):

    layout = gridlayout.GridLayout()  # yee layout

    tv = TestVariables()

    for interpOrder in tv.interpOrders:

        Jx = np.zeros([
            layout.allocSize(interpOrder, tv.JxCentering[0], tv.nbrCells[0]),
            layout.allocSize(interpOrder, tv.JxCentering[1], tv.nbrCells[1]),
            layout.allocSize(interpOrder, tv.JxCentering[2], tv.nbrCells[2])
        ],
                      dtype=np.float64)
        Jy = np.zeros([
            layout.allocSize(interpOrder, tv.JyCentering[0], tv.nbrCells[0]),
            layout.allocSize(interpOrder, tv.JyCentering[1], tv.nbrCells[1]),
            layout.allocSize(interpOrder, tv.JyCentering[2], tv.nbrCells[2])
        ],
                      dtype=np.float64)
        Jz = np.zeros([
            layout.allocSize(interpOrder, tv.JzCentering[0], tv.nbrCells[0]),
            layout.allocSize(interpOrder, tv.JzCentering[1], tv.nbrCells[1]),
            layout.allocSize(interpOrder, tv.JzCentering[2], tv.nbrCells[2])
        ],
                      dtype=np.float64)
        Jx_x = np.zeros_like(Jx)
        Jx_y = np.zeros_like(Jx)
        Jx_z = np.zeros_like(Jx)
        Jy_x = np.zeros_like(Jy)
        Jy_y = np.zeros_like(Jy)
        Jy_z = np.zeros_like(Jy)
        Jz_x = np.zeros_like(Jz)
        Jz_y = np.zeros_like(Jz)
        Jz_z = np.zeros_like(Jz)

        lapJx = np.zeros([
            layout.allocSize(interpOrder, tv.JxCentering[0], tv.nbrCells[0]),
            layout.allocSize(interpOrder, tv.JxCentering[1], tv.nbrCells[1]),
            layout.allocSize(interpOrder, tv.JxCentering[2], tv.nbrCells[2])
        ],
                         dtype=np.float64)
        lapJy = np.zeros([
            layout.allocSize(interpOrder, tv.JyCentering[0], tv.nbrCells[0]),
            layout.allocSize(interpOrder, tv.JyCentering[1], tv.nbrCells[1]),
            layout.allocSize(interpOrder, tv.JyCentering[2], tv.nbrCells[2])
        ],
                         dtype=np.float64)
        lapJz = np.zeros([
            layout.allocSize(interpOrder, tv.JzCentering[0], tv.nbrCells[0]),
            layout.allocSize(interpOrder, tv.JzCentering[1], tv.nbrCells[1]),
            layout.allocSize(interpOrder, tv.JzCentering[2], tv.nbrCells[2])
        ],
                         dtype=np.float64)

        psi_p_X = layout.physicalStartIndex(interpOrder, 'primal')
        pei_p_X = layout.physicalEndIndex(interpOrder, 'primal',
                                          tv.nbrCells[0])
        psi_p_Y = layout.physicalStartIndex(interpOrder, 'primal')
        pei_p_Y = layout.physicalEndIndex(interpOrder, 'primal',
                                          tv.nbrCells[1])
        psi_p_Z = layout.physicalStartIndex(interpOrder, 'primal')
        pei_p_Z = layout.physicalEndIndex(interpOrder, 'primal',
                                          tv.nbrCells[2])

        psi_d_X = layout.physicalStartIndex(interpOrder, 'dual')
        pei_d_X = layout.physicalEndIndex(interpOrder, 'dual', tv.nbrCells[0])
        psi_d_Y = layout.physicalStartIndex(interpOrder, 'dual')
        pei_d_Y = layout.physicalEndIndex(interpOrder, 'dual', tv.nbrCells[1])
        psi_d_Z = layout.physicalStartIndex(interpOrder, 'dual')
        pei_d_Z = layout.physicalEndIndex(interpOrder, 'dual', tv.nbrCells[2])

        nbrGhost_p = layout.nbrGhosts(interpOrder, 'primal')
        nbrGhost_d = layout.nbrGhosts(interpOrder, 'dual')

        x_primal = tv.meshSize[0] * np.arange(
            layout.allocSize(interpOrder, 'primal',
                             tv.nbrCells[0])) - tv.meshSize[0] * nbrGhost_p
        x_dual = tv.meshSize[0] * np.arange(
            layout.allocSize(interpOrder, 'dual', tv.nbrCells[0])
        ) - tv.meshSize[0] * nbrGhost_d + tv.meshSize[0] * 0.5
        y_primal = tv.meshSize[1] * np.arange(
            layout.allocSize(interpOrder, 'primal',
                             tv.nbrCells[1])) - tv.meshSize[1] * nbrGhost_p
        y_dual = tv.meshSize[1] * np.arange(
            layout.allocSize(interpOrder, 'dual', tv.nbrCells[1])
        ) - tv.meshSize[1] * nbrGhost_d + tv.meshSize[1] * 0.5
        z_primal = tv.meshSize[2] * np.arange(
            layout.allocSize(interpOrder, 'primal',
                             tv.nbrCells[2])) - tv.meshSize[2] * nbrGhost_p
        z_dual = tv.meshSize[2] * np.arange(
            layout.allocSize(interpOrder, 'dual', tv.nbrCells[2])
        ) - tv.meshSize[2] * nbrGhost_d + tv.meshSize[2] * 0.5

        Jx = np.tensordot(np.sinh(0.1 * x_dual),
                          np.tensordot(np.cosh(0.1 * y_primal),
                                       np.tanh(0.1 * z_primal),
                                       axes=0),
                          axes=0)
        Jy = np.tensordot(np.sinh(0.3 * x_primal),
                          np.tensordot(np.cosh(0.3 * y_dual),
                                       np.tanh(0.3 * z_primal),
                                       axes=0),
                          axes=0)
        Jz = np.tensordot(np.sinh(0.2 * x_primal),
                          np.tensordot(np.cosh(0.2 * y_primal),
                                       np.tanh(0.2 * z_dual),
                                       axes=0),
                          axes=0)

        Jx_x[psi_d_X:pei_d_X +
             1, :, :] = (Jx[psi_d_X + 1:pei_d_X + 2, :, :] -
                         2.0 * Jx[psi_d_X:pei_d_X + 1, :, :] +
                         Jx[psi_d_X - 1:pei_d_X, :, :]) / (tv.meshSize[0] *
                                                           tv.meshSize[0])
        Jx_y[:, psi_p_Y:pei_p_Y +
             1, :] = (Jx[:, psi_p_Y + 1:pei_p_Y + 2, :] -
                      2.0 * Jx[:, psi_p_Y:pei_p_Y + 1, :] +
                      Jx[:, psi_p_Y - 1:pei_p_Y, :]) / (tv.meshSize[1] *
                                                        tv.meshSize[1])
        Jx_z[:, :, psi_p_Z:pei_p_Z +
             1] = (Jx[:, :, psi_p_Z + 1:pei_p_Z + 2] -
                   2.0 * Jx[:, :, psi_p_Z:pei_p_Z + 1] +
                   Jx[:, :, psi_p_Z - 1:pei_p_Z]) / (tv.meshSize[2] *
                                                     tv.meshSize[2])

        Jy_x[psi_p_X:pei_p_X +
             1, :, :] = (Jy[psi_p_X + 1:pei_p_X + 2, :, :] -
                         2.0 * Jy[psi_p_X:pei_p_X + 1, :, :] +
                         Jy[psi_p_X - 1:pei_p_X, :, :]) / (tv.meshSize[0] *
                                                           tv.meshSize[0])
        Jy_y[:, psi_d_Y:pei_d_Y +
             1, :] = (Jy[:, psi_d_Y + 1:pei_d_Y + 2, :] -
                      2.0 * Jy[:, psi_d_Y:pei_d_Y + 1, :] +
                      Jy[:, psi_d_Y - 1:pei_d_Y, :]) / (tv.meshSize[1] *
                                                        tv.meshSize[1])
        Jy_z[:, :, psi_p_Z:pei_p_Z +
             1] = (Jy[:, :, psi_p_Z + 1:pei_p_Z + 2] -
                   2.0 * Jy[:, :, psi_p_Z:pei_p_Z + 1] +
                   Jy[:, :, psi_p_Z - 1:pei_p_Z]) / (tv.meshSize[2] *
                                                     tv.meshSize[2])

        Jz_x[psi_p_X:pei_p_X +
             1, :, :] = (Jz[psi_p_X + 1:pei_p_X + 2, :, :] -
                         2.0 * Jz[psi_p_X:pei_p_X + 1, :, :] +
                         Jz[psi_p_X - 1:pei_p_X, :, :]) / (tv.meshSize[0] *
                                                           tv.meshSize[0])
        Jz_y[:, psi_p_Y:pei_p_Y +
             1, :] = (Jz[:, psi_p_Y + 1:pei_p_Y + 2, :] -
                      2.0 * Jz[:, psi_p_Y:pei_p_Y + 1, :] +
                      Jz[:, psi_p_Y - 1:pei_p_Y, :]) / (tv.meshSize[1] *
                                                        tv.meshSize[1])
        Jz_z[:, :, psi_d_Z:pei_d_Z +
             1] = (Jz[:, :, psi_d_Z + 1:pei_d_Z + 2] -
                   2.0 * Jz[:, :, psi_d_Z:pei_d_Z + 1] +
                   Jz[:, :, psi_d_Z - 1:pei_d_Z]) / (tv.meshSize[2] *
                                                     tv.meshSize[2])

        lapJx = Jx_x + Jx_y + Jx_z
        lapJy = Jy_x + Jy_y + Jy_z
        lapJz = Jz_x + Jz_y + Jz_z

        filename_lapJx = 'lapJx_interpOrder_{}_3d.txt'.format(interpOrder)
        filename_lapJy = 'lapJy_interpOrder_{}_3d.txt'.format(interpOrder)
        filename_lapJz = 'lapJz_interpOrder_{}_3d.txt'.format(interpOrder)

        np.savetxt(os.path.join(path, filename_lapJx),
                   lapJx.flatten('C'),
                   delimiter=" ")
        np.savetxt(os.path.join(path, filename_lapJy),
                   lapJy.flatten('C'),
                   delimiter=" ")
        np.savetxt(os.path.join(path, filename_lapJz),
                   lapJz.flatten('C'),
                   delimiter=" ")
def main(path='./'):

    if len(sys.argv) == 2:
        path = sys.argv[1]

    interpOrders = [1, 2, 3, 4]

    nbDimsList = [1, 2, 3]

    nbrCellXList = [40, 40, 40]
    nbrCellYList = [0, 12, 12]
    nbrCellZList = [0, 0, 12]

    dxList = [0.1, 0.1, 0.1]
    dyList = [0., 0.1, 0.1]
    dzList = [0., 0., 0.1]

    originPosition = [0., 0., 0.]

    gl = gridlayout.GridLayout()

    # ------- Debug commands -------
    # for icase in icase_l:
    #     idim = dim_l[icase]
    #     order = interpOrder_l[icase]
    #     print( "Interpolation order = %d" % order )
    #     print( "Nbr of cells = %d" %  nbrCells[Direction_l[idim][1]][icase])
    #     print( "Nbr of ghost cells on the primal mesh = %d on each side" %
    #             gl.nbrGhostsPrimal(order) )

    # ------------------------------

    baseNameSummary = "centeredCoords_summary"
    baseNameValues = "centeredCoords_values"

    outFilenameBaseSummary = os.path.join(path, baseNameSummary)
    outFilenameBaseValues = os.path.join(path, baseNameValues)
    outSummaries = []
    outValues = []

    for interpOrder in interpOrders:
        filenamesSum = [
            outFilenameBaseSummary + '_' + str(dim) + 'd_O' +
            str(interpOrder) + '.txt' for dim in nbDimsList
        ]
        filenamesVal = [
            outFilenameBaseValues + '_' + str(dim) + 'd_O' + str(interpOrder) +
            '.txt' for dim in nbDimsList
        ]
        outSummaries.append([open(f, 'w') for f in filenamesSum])
        outValues.append([open(f, 'w') for f in filenamesVal])

    for interpOrder, outFilesSumDim, outFilesValDim in zip(
            interpOrders, outSummaries, outValues):
        for dimension,outFileS, outFileV,nbrCellX,nbrCellY,\
            nbrCellZ,dx,dy,dz in zip(nbDimsList, outFilesSumDim, outFilesValDim,
                                     nbrCellXList,nbrCellYList,
                                     nbrCellZList,dxList,dyList,
                                     dzList):

            params = CenteredCoordParams(dimension, interpOrder)
            params.setNbrCell(nbrCellX, nbrCellY, nbrCellZ)
            params.setDl(dx, dy, dz)

            centering = getCellCentered(dimension)

            params.setCoord(gl, originPosition, centering)

            summaryBasePart = "{} {} ".format(params.nbrCell, params.dl)

            summaryGridLayoutPart = "{} {} {}\n".format(
                params.iStart, params.iEnd, params.origin)

            outSummaryString = summaryBasePart + summaryGridLayoutPart

            outSummaryString = utilities.removeTupleFormat(outSummaryString)

            outFileS.write(outSummaryString)

            if dimension == 1:
                for position in np.arange(params.iStart, params.iEnd + 1):
                    outValuesString = "{} {}\n".format(
                        position,
                        centeredCoords(position, params.iStart, params.dl,
                                       params.origin))

                    outFileV.write(
                        utilities.removeTupleFormat(outValuesString))

            elif dimension == 2:
                for positionX in np.arange(params.iStart[0],
                                           params.iEnd[0] + 1):
                    for positionY in np.arange(params.iStart[1],
                                               params.iEnd[1] + 1):
                        position = (positionX, positionY)
                        centered = (centeredCoords(positionX, params.iStart[0],
                                                   params.dl[0],
                                                   params.origin[0]),
                                    centeredCoords(positionY, params.iStart[1],
                                                   params.dl[1],
                                                   params.origin[1]))

                        outValuesString = "{} {}\n".format(position, centered)

                        outFileV.write(
                            utilities.removeTupleFormat(outValuesString))

            elif dimension == 3:
                for positionX in np.arange(params.iStart[0],
                                           params.iEnd[0] + 1):
                    for positionY in np.arange(params.iStart[1],
                                               params.iEnd[1] + 1):
                        for positionZ in np.arange(params.iStart[2],
                                                   params.iEnd[2] + 1):

                            position = (positionX, positionY, positionZ)
                            centered = (centeredCoords(positionX,
                                                       params.iStart[0],
                                                       params.dl[0],
                                                       params.origin[0]),
                                        centeredCoords(positionY,
                                                       params.iStart[1],
                                                       params.dl[1],
                                                       params.origin[1]),
                                        centeredCoords(positionZ,
                                                       params.iStart[2],
                                                       params.dl[2],
                                                       params.origin[2]))

                            outValuesString = "{} {}\n".format(
                                position, centered)

                            outFileV.write(
                                utilities.removeTupleFormat(outValuesString))

    for outFilesSumDim, outFilesValDim in zip(outSummaries, outValues):
        for f1, f2 in zip(outFilesSumDim, outFilesValDim):
            f1.close()
            f2.close()
Esempio n. 12
0
def test_deriv2D(path):

    layout = gridlayout.GridLayout()  # yee layout

    tv = TestVariables()

    for interpOrder in tv.interpOrders:

        filename_dxBy = 'dxBy_interpOrder_{}_2d.txt'.format(interpOrder)
        filename_dyBy = 'dyBy_interpOrder_{}_2d.txt'.format(interpOrder)
        filename_dxEz = 'dxEz_interpOrder_{}_2d.txt'.format(interpOrder)
        filename_dyEz = 'dyEz_interpOrder_{}_2d.txt'.format(interpOrder)

        By = np.zeros([
            layout.allocSize(interpOrder, tv.ByCentering[0], tv.nbrCells[0]),
            layout.allocSize(interpOrder, tv.ByCentering[1], tv.nbrCells[1])
        ],
                      dtype=np.float64)
        Ez = np.zeros([
            layout.allocSize(interpOrder, tv.EzCentering[0], tv.nbrCells[0]),
            layout.allocSize(interpOrder, tv.EzCentering[1], tv.nbrCells[1])
        ],
                      dtype=np.float64)

        dxBy = np.zeros([
            layout.allocSizeDerived(interpOrder, tv.ByCentering[0],
                                    tv.nbrCells[0]),
            layout.allocSize(interpOrder, tv.ByCentering[1], tv.nbrCells[1])
        ],
                        dtype=np.float64)
        dyBy = np.zeros([
            layout.allocSize(interpOrder, tv.ByCentering[0], tv.nbrCells[0]),
            layout.allocSizeDerived(interpOrder, tv.ByCentering[1],
                                    tv.nbrCells[1])
        ],
                        dtype=np.float64)
        dxEz = np.zeros([
            layout.allocSizeDerived(interpOrder, tv.EzCentering[0],
                                    tv.nbrCells[0]),
            layout.allocSize(interpOrder, tv.EzCentering[1], tv.nbrCells[1])
        ],
                        dtype=np.float64)
        dyEz = np.zeros([
            layout.allocSize(interpOrder, tv.EzCentering[0], tv.nbrCells[0]),
            layout.allocSizeDerived(interpOrder, tv.EzCentering[1],
                                    tv.nbrCells[1])
        ],
                        dtype=np.float64)

        nbrGhost_p = layout.nbrGhosts(interpOrder, 'primal')
        nbrGhost_d = layout.nbrGhosts(interpOrder, 'dual')

        x_dual = tv.meshSize[0] * np.arange(
            layout.allocSize(interpOrder, 'dual', tv.nbrCells[0])
        ) - tv.meshSize[0] * nbrGhost_d + tv.meshSize[0] * 0.5
        y_dual = tv.meshSize[1] * np.arange(
            layout.allocSize(interpOrder, 'dual', tv.nbrCells[1])
        ) - tv.meshSize[1] * nbrGhost_d + tv.meshSize[1] * 0.5
        x_primal = tv.meshSize[0] * np.arange(
            layout.allocSize(interpOrder, 'primal',
                             tv.nbrCells[0])) - tv.meshSize[0] * nbrGhost_p
        y_primal = tv.meshSize[1] * np.arange(
            layout.allocSize(interpOrder, 'primal',
                             tv.nbrCells[1])) - tv.meshSize[1] * nbrGhost_p

        By = np.tensordot(np.cos(2 * np.pi / tv.domainSize[0] * x_dual),
                          np.sin(2 * np.pi / tv.domainSize[1] * y_primal),
                          axes=0)

        Ez = np.tensordot(np.cos(2 * np.pi / tv.domainSize[0] * x_primal),
                          np.sin(2 * np.pi / tv.domainSize[1] * y_primal),
                          axes=0)

        psi_d_X = layout.physicalStartIndex(interpOrder, 'dual')
        pei_d_X = layout.physicalEndIndex(interpOrder, 'dual', tv.nbrCells[0])
        psi_d_Y = layout.physicalStartIndex(interpOrder, 'dual')
        pei_d_Y = layout.physicalEndIndex(interpOrder, 'dual', tv.nbrCells[1])
        psi_p_X = layout.physicalStartIndex(interpOrder, 'primal')
        pei_p_X = layout.physicalEndIndex(interpOrder, 'primal',
                                          tv.nbrCells[0])
        psi_p_Y = layout.physicalStartIndex(interpOrder, 'primal')
        pei_p_Y = layout.physicalEndIndex(interpOrder, 'primal',
                                          tv.nbrCells[1])

        dxBy[psi_p_X:pei_p_X +
             1, :] = (By[psi_d_X:pei_d_X + 2, :] -
                      By[psi_d_X - 1:pei_d_X + 1, :]) / tv.meshSize[0]
        dxEz[psi_d_X:pei_d_X +
             1, :] = (Ez[psi_p_X + 1:pei_p_X + 1, :] -
                      Ez[psi_p_X:pei_p_X, :]) / tv.meshSize[0]
        dyBy[:,
             psi_d_Y:pei_d_Y + 1] = (By[:, psi_p_Y + 1:pei_p_Y + 1] -
                                     By[:, psi_p_Y:pei_p_Y]) / tv.meshSize[1]
        dyEz[:,
             psi_d_Y:pei_d_Y + 1] = (Ez[:, psi_p_Y + 1:pei_p_Y + 1] -
                                     Ez[:, psi_p_Y:pei_p_Y]) / tv.meshSize[1]

        np.savetxt(os.path.join(path, filename_dxBy),
                   dxBy.flatten('C'),
                   delimiter=" ")
        np.savetxt(os.path.join(path, filename_dyBy),
                   dyBy.flatten('C'),
                   delimiter=" ")
        np.savetxt(os.path.join(path, filename_dxEz),
                   dxEz.flatten('C'),
                   delimiter=" ")
        np.savetxt(os.path.join(path, filename_dyEz),
                   dyEz.flatten('C'),
                   delimiter=" ")
Esempio n. 13
0
def test_ohm_yee3D(path):

    layout = gridlayout.GridLayout()  # yee layout

    tv = TestVariables()
    eta = 1.0
    nu = 0.001

    Vx = np.zeros([
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[0],
                         tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[1],
                         tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[2],
                         tv.nbrCells[2])
    ],
                  dtype=np.float64)
    Vy = np.zeros([
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[0],
                         tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[1],
                         tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[2],
                         tv.nbrCells[2])
    ],
                  dtype=np.float64)
    Vz = np.zeros([
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[0],
                         tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[1],
                         tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[2],
                         tv.nbrCells[2])
    ],
                  dtype=np.float64)

    Bx = np.zeros([
        layout.allocSize(tv.interpOrder, tv.BxCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.BxCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.BxCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)
    By = np.zeros([
        layout.allocSize(tv.interpOrder, tv.ByCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.ByCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.ByCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)
    Bz = np.zeros([
        layout.allocSize(tv.interpOrder, tv.BzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.BzCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.BzCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)

    n = np.zeros([
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[0],
                         tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[1],
                         tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[2],
                         tv.nbrCells[2])
    ],
                 dtype=np.float64)
    P = np.zeros([
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[0],
                         tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[1],
                         tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.MomentsCentering[2],
                         tv.nbrCells[2])
    ],
                 dtype=np.float64)

    Jx = np.zeros([
        layout.allocSize(tv.interpOrder, tv.JxCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.JxCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.JxCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)
    Jy = np.zeros([
        layout.allocSize(tv.interpOrder, tv.JyCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.JyCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.JyCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)
    Jz = np.zeros([
        layout.allocSize(tv.interpOrder, tv.JzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.JzCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.JzCentering[2], tv.nbrCells[2])
    ],
                  dtype=np.float64)

    idealx = np.zeros([
        layout.allocSize(tv.interpOrder, tv.ExCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[2], tv.nbrCells[2])
    ],
                      dtype=np.float64)
    idealy = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EyCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[2], tv.nbrCells[2])
    ],
                      dtype=np.float64)
    idealz = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[2], tv.nbrCells[2])
    ],
                      dtype=np.float64)

    pressx = np.zeros([
        layout.allocSize(tv.interpOrder, tv.ExCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[2], tv.nbrCells[2])
    ],
                      dtype=np.float64)
    pressy = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EyCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[2], tv.nbrCells[2])
    ],
                      dtype=np.float64)
    pressz = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[2], tv.nbrCells[2])
    ],
                      dtype=np.float64)

    resistx = np.zeros([
        layout.allocSize(tv.interpOrder, tv.ExCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[2], tv.nbrCells[2])
    ],
                       dtype=np.float64)
    resisty = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EyCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[2], tv.nbrCells[2])
    ],
                       dtype=np.float64)
    resistz = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[2], tv.nbrCells[2])
    ],
                       dtype=np.float64)

    viscousx = np.zeros([
        layout.allocSize(tv.interpOrder, tv.ExCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[2], tv.nbrCells[2])
    ],
                        dtype=np.float64)
    viscousy = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EyCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[2], tv.nbrCells[2])
    ],
                        dtype=np.float64)
    viscousz = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[2], tv.nbrCells[2])
    ],
                        dtype=np.float64)

    ExNew = np.zeros([
        layout.allocSize(tv.interpOrder, tv.ExCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.ExCentering[2], tv.nbrCells[2])
    ],
                     dtype=np.float64)
    EyNew = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EyCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EyCentering[2], tv.nbrCells[2])
    ],
                     dtype=np.float64)
    EzNew = np.zeros([
        layout.allocSize(tv.interpOrder, tv.EzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[1], tv.nbrCells[1]),
        layout.allocSize(tv.interpOrder, tv.EzCentering[2], tv.nbrCells[2])
    ],
                     dtype=np.float64)

    psi_p_X = layout.physicalStartIndex(tv.interpOrder, 'primal')
    pei_p_X = layout.physicalEndIndex(tv.interpOrder, 'primal', tv.nbrCells[0])
    psi_p_Y = layout.physicalStartIndex(tv.interpOrder, 'primal')
    pei_p_Y = layout.physicalEndIndex(tv.interpOrder, 'primal', tv.nbrCells[1])
    psi_p_Z = layout.physicalStartIndex(tv.interpOrder, 'primal')
    pei_p_Z = layout.physicalEndIndex(tv.interpOrder, 'primal', tv.nbrCells[2])

    psi_d_X = layout.physicalStartIndex(tv.interpOrder, 'dual')
    pei_d_X = layout.physicalEndIndex(tv.interpOrder, 'dual', tv.nbrCells[0])
    psi_d_Y = layout.physicalStartIndex(tv.interpOrder, 'dual')
    pei_d_Y = layout.physicalEndIndex(tv.interpOrder, 'dual', tv.nbrCells[1])
    psi_d_Z = layout.physicalStartIndex(tv.interpOrder, 'dual')
    pei_d_Z = layout.physicalEndIndex(tv.interpOrder, 'dual', tv.nbrCells[2])

    nbrGhost_p = layout.nbrGhosts(tv.interpOrder, 'primal')
    nbrGhost_d = layout.nbrGhosts(tv.interpOrder, 'dual')

    x_primal = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'primal',
                         tv.nbrCells[0])) - tv.meshSize[0] * nbrGhost_p
    y_primal = tv.meshSize[1] * np.arange(
        layout.allocSize(tv.interpOrder, 'primal',
                         tv.nbrCells[1])) - tv.meshSize[1] * nbrGhost_p
    z_primal = tv.meshSize[2] * np.arange(
        layout.allocSize(tv.interpOrder, 'primal',
                         tv.nbrCells[2])) - tv.meshSize[2] * nbrGhost_p
    x_dual = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'dual', tv.nbrCells[0])
    ) - tv.meshSize[0] * nbrGhost_d + tv.meshSize[0] * 0.5
    y_dual = tv.meshSize[1] * np.arange(
        layout.allocSize(tv.interpOrder, 'dual', tv.nbrCells[1])
    ) - tv.meshSize[1] * nbrGhost_d + tv.meshSize[1] * 0.5
    z_dual = tv.meshSize[2] * np.arange(
        layout.allocSize(tv.interpOrder, 'dual', tv.nbrCells[2])
    ) - tv.meshSize[2] * nbrGhost_d + tv.meshSize[2] * 0.5

    # analytical profiles of density, velocity...
    Vx = np.tensordot(np.cosh(0.2 * x_primal),
                      np.tensordot(np.sinh(0.2 * y_primal),
                                   np.tanh(0.2 * z_primal),
                                   axes=0),
                      axes=0)
    Vy = np.tensordot(np.cosh(0.4 * x_primal),
                      np.tensordot(np.sinh(0.4 * y_primal),
                                   np.tanh(0.4 * z_primal),
                                   axes=0),
                      axes=0)
    Vz = np.tensordot(np.cosh(0.3 * x_primal),
                      np.tensordot(np.sinh(0.3 * y_primal),
                                   np.tanh(0.3 * z_primal),
                                   axes=0),
                      axes=0)
    Bx = np.tensordot(np.tanh(0.2 * x_primal),
                      np.tensordot(np.sinh(0.2 * y_dual),
                                   np.cosh(0.2 * z_dual),
                                   axes=0),
                      axes=0)
    By = np.tensordot(np.tanh(0.4 * x_dual),
                      np.tensordot(np.sinh(0.4 * y_primal),
                                   np.cosh(0.4 * z_dual),
                                   axes=0),
                      axes=0)
    Bz = np.tensordot(np.tanh(0.3 * x_dual),
                      np.tensordot(np.sinh(0.3 * y_dual),
                                   np.cosh(0.3 * z_primal),
                                   axes=0),
                      axes=0)
    n = np.tensordot(np.exp(-0.1 * x_primal),
                     np.tensordot(np.exp(-0.1 * y_primal),
                                  np.exp(-0.1 * z_primal),
                                  axes=0),
                     axes=0)
    P = np.tensordot(np.exp(-0.2 * x_primal),
                     np.tensordot(np.exp(-0.2 * y_primal),
                                  np.exp(-0.2 * z_primal),
                                  axes=0),
                     axes=0)
    Jx = np.tensordot(np.sinh(0.1 * x_dual),
                      np.tensordot(np.sinh(0.1 * y_primal),
                                   np.tanh(0.1 * z_primal),
                                   axes=0),
                      axes=0)
    Jy = np.tensordot(np.sinh(0.3 * x_primal),
                      np.tensordot(np.sinh(0.3 * y_dual),
                                   np.tanh(0.3 * z_primal),
                                   axes=0),
                      axes=0)
    Jz = np.tensordot(np.sinh(0.2 * x_primal),
                      np.tensordot(np.sinh(0.2 * y_primal),
                                   np.tanh(0.2 * z_dual),
                                   axes=0),
                      axes=0)

    # ideal term
    idealx[psi_d_X  :pei_d_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1] = \
 -0.25*(Vy[psi_p_X  :pei_p_X  , psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1]\
       +Vy[psi_p_X+1:pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1])\
      *(Bz[psi_d_X  :pei_d_X+1, psi_d_Y-1:pei_d_Y+1, psi_p_Z  :pei_p_Z+1]\
       +Bz[psi_d_X  :pei_d_X+1, psi_d_Y  :pei_d_Y+2, psi_p_Z  :pei_p_Z+1])\
 +0.25*(Vz[psi_p_X  :pei_p_X  , psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1]\
       +Vz[psi_p_X+1:pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1])\
      *(By[psi_d_X  :pei_d_X+1, psi_p_Y  :pei_p_Y+1, psi_d_Z-1:pei_d_Z+1]\
       +By[psi_d_X  :pei_d_X+1, psi_p_Y  :pei_p_Y+1, psi_d_Z  :pei_d_Z+2])

    idealy[psi_p_X  :pei_p_X+1, psi_d_Y  :pei_d_Y+1, psi_p_Z  :pei_p_Z+1] = \
 -0.25*(Vz[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y  , psi_p_Z  :pei_p_Z+1]\
       +Vz[psi_p_X  :pei_p_X+1, psi_p_Y+1:pei_p_Y+1, psi_p_Z  :pei_p_Z+1])\
      *(Bx[psi_p_X  :pei_p_X+1, psi_d_Y  :pei_d_Y+1, psi_d_Z-1:pei_d_Z+1]\
       +Bx[psi_p_X  :pei_p_X+1, psi_d_Y  :pei_d_Y+1, psi_d_Z  :pei_d_Z+2])\
 +0.25*(Vx[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y  , psi_p_Z  :pei_p_Z+1]\
       +Vx[psi_p_X  :pei_p_X+1, psi_p_Y+1:pei_p_Y+1, psi_p_Z  :pei_p_Z+1])\
      *(Bz[psi_d_X-1:pei_d_X+1, psi_d_Y  :pei_d_Y+1, psi_p_Z  :pei_p_Z+1]\
       +Bz[psi_d_X  :pei_d_X+2, psi_d_Y  :pei_d_Y+1, psi_p_Z  :pei_p_Z+1])

    idealz[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_d_Z  :pei_d_Z+1] = \
 -0.25*(Vx[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z  ]\
       +Vx[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z+1:pei_p_Z+1])\
      *(By[psi_d_X-1:pei_d_X+1, psi_p_Y  :pei_p_Y+1, psi_d_Z  :pei_d_Z+1]\
       +By[psi_d_X  :pei_d_X+2, psi_p_Y  :pei_p_Y+1, psi_d_Z  :pei_d_Z+1])\
 +0.25*(Vy[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z  ]\
       +Vy[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z+1:pei_p_Z+1])\
      *(Bx[psi_p_X  :pei_p_X+1, psi_d_Y-1:pei_d_Y+1, psi_d_Z  :pei_d_Z+1]\
       +Bx[psi_p_X  :pei_p_X+1, psi_d_Y  :pei_d_Y+2, psi_d_Z  :pei_d_Z+1])

    # pressure term
    pressx[psi_d_X  :pei_d_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1] = \
       ((P[psi_p_X+1:pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1]\
        -P[psi_p_X  :pei_p_X  , psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1])/tv.meshSize[0])\
  /(0.5*(n[psi_p_X  :pei_p_X  , psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1]\
        +n[psi_p_X+1:pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1]))

    pressy[psi_p_X  :pei_p_X+1, psi_d_Y  :pei_d_Y+1, psi_p_Z  :pei_p_Z+1] = \
       ((P[psi_p_X  :pei_p_X+1, psi_p_Y+1:pei_p_Y+1, psi_p_Z  :pei_p_Z+1]\
        -P[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y  , psi_p_Z  :pei_p_Z+1])/tv.meshSize[1])\
  /(0.5*(n[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y  , psi_p_Z  :pei_p_Z+1]\
        +n[psi_p_X  :pei_p_X+1, psi_p_Y+1:pei_p_Y+1, psi_p_Z  :pei_p_Z+1]))

    pressz[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_d_Z  :pei_d_Z+1] = \
       ((P[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z+1:pei_p_Z+1]\
        -P[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z  ])/tv.meshSize[2])\
  /(0.5*(n[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z  ]\
        +n[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z+1:pei_p_Z+1]))

    # resistive term
    resistx[psi_d_X:pei_d_X+1, psi_p_Y:pei_p_Y+1, psi_p_Z  :pei_p_Z+1] = \
     eta*Jx[psi_d_X:pei_d_X+1, psi_p_Y:pei_p_Y+1, psi_p_Z  :pei_p_Z+1]

    resisty[psi_p_X:pei_p_X+1, psi_d_Y:pei_d_Y+1, psi_p_Z  :pei_p_Z+1] = \
     eta*Jy[psi_p_X:pei_p_X+1, psi_d_Y:pei_d_Y+1, psi_p_Z  :pei_p_Z+1]

    resistz[psi_p_X:pei_p_X+1, psi_p_Y:pei_p_Y+1, psi_d_Z  :pei_d_Z+1] = \
     eta*Jz[psi_p_X:pei_p_X+1, psi_p_Y:pei_p_Y+1, psi_d_Z  :pei_d_Z+1]

    # viscous term
    viscousx[psi_d_X  :pei_d_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1] = \
     -nu*(Jx[psi_d_X-1:pei_d_X  , psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1]\
     -2.0*Jx[psi_d_X  :pei_d_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1]\
         +Jx[psi_d_X+1:pei_d_X+2, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1])\
        /(tv.meshSize[0]*tv.meshSize[0])\
     -nu*(Jx[psi_d_X  :pei_d_X+1, psi_p_Y-1:pei_p_Y  , psi_p_Z  :pei_p_Z+1]\
     -2.0*Jx[psi_d_X  :pei_d_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1]\
         +Jx[psi_d_X  :pei_d_X+1, psi_p_Y+1:pei_p_Y+2, psi_p_Z  :pei_p_Z+1])\
        /(tv.meshSize[1]*tv.meshSize[1])\
     -nu*(Jx[psi_d_X  :pei_d_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z-1:pei_p_Z  ]\
     -2.0*Jx[psi_d_X  :pei_d_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z  :pei_p_Z+1]\
         +Jx[psi_d_X  :pei_d_X+1, psi_p_Y  :pei_p_Y+1, psi_p_Z+1:pei_p_Z+2])\
        /(tv.meshSize[2]*tv.meshSize[2])

    viscousy[psi_p_X  :pei_p_X+1, psi_d_Y  :pei_d_Y+1, psi_p_Z  :pei_p_Z+1] = \
     -nu*(Jy[psi_p_X-1:pei_p_X  , psi_d_Y  :pei_d_Y+1, psi_p_Z  :pei_p_Z+1]\
     -2.0*Jy[psi_p_X  :pei_p_X+1, psi_d_Y  :pei_d_Y+1, psi_p_Z  :pei_p_Z+1]\
         +Jy[psi_p_X+1:pei_p_X+2, psi_d_Y  :pei_d_Y+1, psi_p_Z  :pei_p_Z+1])\
        /(tv.meshSize[0]*tv.meshSize[0])\
     -nu*(Jy[psi_p_X  :pei_p_X+1, psi_d_Y-1:pei_d_Y  , psi_p_Z  :pei_p_Z+1]\
     -2.0*Jy[psi_p_X  :pei_p_X+1, psi_d_Y  :pei_d_Y+1, psi_p_Z  :pei_p_Z+1]\
         +Jy[psi_p_X  :pei_p_X+1, psi_d_Y+1:pei_d_Y+2, psi_p_Z  :pei_p_Z+1])\
        /(tv.meshSize[1]*tv.meshSize[1])\
     -nu*(Jy[psi_p_X  :pei_p_X+1, psi_d_Y  :pei_d_Y+1, psi_p_Z-1:pei_p_Z  ]\
     -2.0*Jy[psi_p_X  :pei_p_X+1, psi_d_Y  :pei_d_Y+1, psi_p_Z  :pei_p_Z+1]\
         +Jy[psi_p_X  :pei_p_X+1, psi_d_Y  :pei_d_Y+1, psi_p_Z+1:pei_p_Z+2])\
        /(tv.meshSize[2]*tv.meshSize[2])

    viscousz[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_d_Z  :pei_d_Z+1] = \
     -nu*(Jz[psi_p_X-1:pei_p_X  , psi_p_Y  :pei_p_Y+1, psi_d_Z  :pei_d_Z+1]\
     -2.0*Jz[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_d_Z  :pei_d_Z+1]\
         +Jz[psi_p_X+1:pei_p_X+2, psi_p_Y  :pei_p_Y+1, psi_d_Z  :pei_d_Z+1])\
        /(tv.meshSize[0]*tv.meshSize[0])\
     -nu*(Jz[psi_p_X  :pei_p_X+1, psi_p_Y-1:pei_p_Y  , psi_d_Z  :pei_d_Z+1]\
     -2.0*Jz[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_d_Z  :pei_d_Z+1]\
         +Jz[psi_p_X  :pei_p_X+1, psi_p_Y+1:pei_p_Y+2, psi_d_Z  :pei_d_Z+1])\
        /(tv.meshSize[1]*tv.meshSize[1])\
     -nu*(Jz[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_d_Z-1:pei_d_Z  ]\
     -2.0*Jz[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_d_Z  :pei_d_Z+1]\
         +Jz[psi_p_X  :pei_p_X+1, psi_p_Y  :pei_p_Y+1, psi_d_Z+1:pei_d_Z+2])\
        /(tv.meshSize[2]*tv.meshSize[2])

    ExNew = idealx + pressx + resistx + viscousx
    EyNew = idealy + pressy + resisty + viscousy
    EzNew = idealz + pressz + resistz + viscousz

    filename_ohmx = "ohmx_yee_3D_order1.txt"
    filename_ohmy = "ohmy_yee_3D_order1.txt"
    filename_ohmz = "ohmz_yee_3D_order1.txt"

    np.savetxt(os.path.join(path, filename_ohmx),
               ExNew.flatten('C'),
               delimiter=" ")
    np.savetxt(os.path.join(path, filename_ohmy),
               EyNew.flatten('C'),
               delimiter=" ")
    np.savetxt(os.path.join(path, filename_ohmz),
               EzNew.flatten('C'),
               delimiter=" ")
Esempio n. 14
0
def test_ohm_yee1D(path):

    layout = gridlayout.GridLayout()  # yee layout

    tv = TestVariables()
    eta = 1.0
    nu = 0.001

    Vx = np.zeros(layout.allocSize(tv.interpOrder, tv.MomentsCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)
    Vy = np.zeros(layout.allocSize(tv.interpOrder, tv.MomentsCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)
    Vz = np.zeros(layout.allocSize(tv.interpOrder, tv.MomentsCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)

    Bx = np.zeros(layout.allocSize(tv.interpOrder, tv.BxCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)
    By = np.zeros(layout.allocSize(tv.interpOrder, tv.ByCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)
    Bz = np.zeros(layout.allocSize(tv.interpOrder, tv.BzCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)

    n = np.zeros(layout.allocSize(tv.interpOrder, tv.MomentsCentering[0],
                                  tv.nbrCells[0]),
                 dtype=np.float64)
    P = np.zeros(layout.allocSize(tv.interpOrder, tv.MomentsCentering[0],
                                  tv.nbrCells[0]),
                 dtype=np.float64)

    Jx = np.zeros(layout.allocSize(tv.interpOrder, tv.JxCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)
    Jy = np.zeros(layout.allocSize(tv.interpOrder, tv.JyCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)
    Jz = np.zeros(layout.allocSize(tv.interpOrder, tv.JzCentering[0],
                                   tv.nbrCells[0]),
                  dtype=np.float64)

    idealx = np.zeros(layout.allocSize(tv.interpOrder, tv.ExCentering[0],
                                       tv.nbrCells[0]),
                      dtype=np.float64)
    idealy = np.zeros(layout.allocSize(tv.interpOrder, tv.EyCentering[0],
                                       tv.nbrCells[0]),
                      dtype=np.float64)
    idealz = np.zeros(layout.allocSize(tv.interpOrder, tv.EzCentering[0],
                                       tv.nbrCells[0]),
                      dtype=np.float64)

    pressx = np.zeros(layout.allocSize(tv.interpOrder, tv.ExCentering[0],
                                       tv.nbrCells[0]),
                      dtype=np.float64)
    pressy = np.zeros(layout.allocSize(tv.interpOrder, tv.EyCentering[0],
                                       tv.nbrCells[0]),
                      dtype=np.float64)
    pressz = np.zeros(layout.allocSize(tv.interpOrder, tv.EzCentering[0],
                                       tv.nbrCells[0]),
                      dtype=np.float64)

    resistx = np.zeros(layout.allocSize(tv.interpOrder, tv.ExCentering[0],
                                        tv.nbrCells[0]),
                       dtype=np.float64)
    resisty = np.zeros(layout.allocSize(tv.interpOrder, tv.EyCentering[0],
                                        tv.nbrCells[0]),
                       dtype=np.float64)
    resistz = np.zeros(layout.allocSize(tv.interpOrder, tv.EzCentering[0],
                                        tv.nbrCells[0]),
                       dtype=np.float64)

    viscousx = np.zeros(layout.allocSize(tv.interpOrder, tv.ExCentering[0],
                                         tv.nbrCells[0]),
                        dtype=np.float64)
    viscousy = np.zeros(layout.allocSize(tv.interpOrder, tv.EyCentering[0],
                                         tv.nbrCells[0]),
                        dtype=np.float64)
    viscousz = np.zeros(layout.allocSize(tv.interpOrder, tv.EzCentering[0],
                                         tv.nbrCells[0]),
                        dtype=np.float64)

    ExNew = np.zeros(layout.allocSize(tv.interpOrder, tv.ExCentering[0],
                                      tv.nbrCells[0]),
                     dtype=np.float64)
    EyNew = np.zeros(layout.allocSize(tv.interpOrder, tv.EyCentering[0],
                                      tv.nbrCells[0]),
                     dtype=np.float64)
    EzNew = np.zeros(layout.allocSize(tv.interpOrder, tv.EzCentering[0],
                                      tv.nbrCells[0]),
                     dtype=np.float64)

    psi_p_X = layout.physicalStartIndex(tv.interpOrder, 'primal')
    pei_p_X = layout.physicalEndIndex(tv.interpOrder, 'primal', tv.nbrCells[0])

    psi_d_X = layout.physicalStartIndex(tv.interpOrder, 'dual')
    pei_d_X = layout.physicalEndIndex(tv.interpOrder, 'dual', tv.nbrCells[0])

    nbrGhost_p = layout.nbrGhosts(tv.interpOrder, 'primal')
    nbrGhost_d = layout.nbrGhosts(tv.interpOrder, 'dual')

    x_primal = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'primal',
                         tv.nbrCells[0])) - tv.meshSize[0] * nbrGhost_p
    x_dual = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'dual', tv.nbrCells[0])
    ) - tv.meshSize[0] * nbrGhost_d + tv.meshSize[0] * 0.5

    # analytical profiles ov density, velocity...
    Vx = np.cosh(0.2 * x_primal)
    Vy = np.cosh(0.4 * x_primal)
    Vz = np.cosh(0.3 * x_primal)
    Bx = np.tanh(0.2 * x_primal)
    By = np.tanh(3.0 * x_dual)
    Bz = np.tanh(1.2 * x_dual)
    n = np.sinh(0.5 * x_primal)
    P = np.sinh(0.8 * x_primal)
    Jx = np.sinh(0.1 * x_dual)
    Jy = np.sinh(0.3 * x_primal)
    Jz = np.sinh(0.2 * x_primal)

    # ideal term
    idealx[psi_d_X:pei_d_X+1] = 0.5*(Vz[psi_p_X:pei_p_X]+Vz[psi_p_X+1:pei_p_X+1])*By[psi_d_X:pei_d_X+1]\
                              - 0.5*(Vy[psi_p_X:pei_p_X]+Vy[psi_p_X+1:pei_p_X+1])*Bz[psi_d_X:pei_d_X+1]

    idealy[psi_p_X:pei_p_X+1] = 0.5*Vx[psi_p_X:pei_p_X+1]*(Bz[psi_d_X-1:pei_d_X+1]+Bz[psi_d_X:pei_d_X+2])\
                              - Vz[psi_p_X:pei_p_X+1]*Bx[psi_p_X:pei_p_X+1]

    idealz[psi_p_X:pei_p_X+1] = Vy[psi_p_X:pei_p_X+1]*Bx[psi_p_X:pei_p_X+1]\
                              - 0.5*Vx[psi_p_X:pei_p_X+1]*(By[psi_d_X-1:pei_d_X+1]+By[psi_d_X:pei_d_X+2])

    # pressure term
    pressx[psi_d_X:pei_d_X+1] = ((P[psi_p_X+1:pei_p_X+1]-P[psi_p_X:pei_p_X])/tv.meshSize[0])\
                                /(0.5*(n[psi_p_X:pei_p_X]+n[psi_p_X+1:pei_p_X+1]))
    pressy[psi_p_X:pei_p_X + 1] = 0
    pressz[psi_p_X:pei_p_X + 1] = 0

    # resistive term
    resistx[psi_d_X:pei_d_X + 1] = eta * Jx[psi_d_X:pei_d_X + 1]
    resisty[psi_p_X:pei_p_X + 1] = eta * Jy[psi_p_X:pei_p_X + 1]
    resistz[psi_p_X:pei_p_X + 1] = eta * Jz[psi_p_X:pei_p_X + 1]

    # viscous term
    viscousx[psi_d_X:pei_d_X + 1] = -nu * (
        Jx[psi_d_X - 1:pei_d_X] - 2.0 * Jx[psi_d_X:pei_d_X + 1] +
        Jx[psi_d_X + 1:pei_d_X + 2]) / (tv.meshSize[0] * tv.meshSize[0])
    viscousy[psi_p_X:pei_p_X + 1] = -nu * (
        Jy[psi_p_X - 1:pei_p_X] - 2.0 * Jy[psi_p_X:pei_p_X + 1] +
        Jy[psi_p_X + 1:pei_p_X + 2]) / (tv.meshSize[0] * tv.meshSize[0])
    viscousz[psi_p_X:pei_p_X + 1] = -nu * (
        Jz[psi_p_X - 1:pei_p_X] - 2.0 * Jz[psi_p_X:pei_p_X + 1] +
        Jz[psi_p_X + 1:pei_p_X + 2]) / (tv.meshSize[0] * tv.meshSize[0])

    ExNew = idealx + pressx + resistx + viscousx
    EyNew = idealy + pressy + resisty + viscousy
    EzNew = idealz + pressz + resistz + viscousz

    filename_ohmx = "ohmx_yee_1D_order1.txt"
    filename_ohmy = "ohmy_yee_1D_order1.txt"
    filename_ohmz = "ohmz_yee_1D_order1.txt"

    np.savetxt(os.path.join(path, filename_ohmx), ExNew, delimiter=" ")
    np.savetxt(os.path.join(path, filename_ohmy), EyNew, delimiter=" ")
    np.savetxt(os.path.join(path, filename_ohmz), EzNew, delimiter=" ")
Esempio n. 15
0
def test_ampere_yee2D(path):

    layout = gridlayout.GridLayout()  # yee layout

    tv = TestVariables()

    Bx = np.zeros([
        layout.allocSize(tv.interpOrder, tv.BxCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.BxCentering[1], tv.nbrCells[1])
    ],
                  dtype=np.float64)
    By = np.zeros([
        layout.allocSize(tv.interpOrder, tv.ByCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.ByCentering[1], tv.nbrCells[1])
    ],
                  dtype=np.float64)
    Bz = np.zeros([
        layout.allocSize(tv.interpOrder, tv.BzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.BzCentering[1], tv.nbrCells[1])
    ],
                  dtype=np.float64)

    Jx = np.zeros([
        layout.allocSize(tv.interpOrder, tv.JxCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.JxCentering[1], tv.nbrCells[1])
    ],
                  dtype=np.float64)
    Jy = np.zeros([
        layout.allocSize(tv.interpOrder, tv.JyCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.JyCentering[1], tv.nbrCells[1])
    ],
                  dtype=np.float64)
    Jz = np.zeros([
        layout.allocSize(tv.interpOrder, tv.JzCentering[0], tv.nbrCells[0]),
        layout.allocSize(tv.interpOrder, tv.JzCentering[1], tv.nbrCells[1])
    ],
                  dtype=np.float64)
    w1 = np.zeros_like(Jz)
    w2 = np.zeros_like(Jz)

    psi_p_X = layout.physicalStartIndex(tv.interpOrder, 'primal')
    pei_p_X = layout.physicalEndIndex(tv.interpOrder, 'primal', tv.nbrCells[0])
    psi_p_Y = layout.physicalStartIndex(tv.interpOrder, 'primal')
    pei_p_Y = layout.physicalEndIndex(tv.interpOrder, 'primal', tv.nbrCells[1])

    psi_d_X = layout.physicalStartIndex(tv.interpOrder, 'dual')
    pei_d_X = layout.physicalEndIndex(tv.interpOrder, 'dual', tv.nbrCells[0])
    psi_d_Y = layout.physicalStartIndex(tv.interpOrder, 'dual')
    pei_d_Y = layout.physicalEndIndex(tv.interpOrder, 'dual', tv.nbrCells[1])

    nbrGhost_p = layout.nbrGhosts(tv.interpOrder, 'primal')
    nbrGhost_d = layout.nbrGhosts(tv.interpOrder, 'dual')

    x_dual = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'dual', tv.nbrCells[0])
    ) - tv.meshSize[0] * nbrGhost_d + tv.meshSize[0] * 0.5
    y_dual = tv.meshSize[1] * np.arange(
        layout.allocSize(tv.interpOrder, 'dual', tv.nbrCells[1])
    ) - tv.meshSize[1] * nbrGhost_d + tv.meshSize[1] * 0.5
    x_primal = tv.meshSize[0] * np.arange(
        layout.allocSize(tv.interpOrder, 'primal',
                         tv.nbrCells[0])) - tv.meshSize[0] * nbrGhost_p
    y_primal = tv.meshSize[1] * np.arange(
        layout.allocSize(tv.interpOrder, 'primal',
                         tv.nbrCells[1])) - tv.meshSize[1] * nbrGhost_p

    Bx = np.tensordot(np.cos(2 * np.pi / tv.domainSize[0] * x_primal),
                      np.sin(2 * np.pi / tv.domainSize[1] * y_dual),
                      axes=0)
    By = np.tensordot(np.cos(2 * np.pi / tv.domainSize[0] * x_dual),
                      np.tanh(2 * np.pi / tv.domainSize[1] * y_primal),
                      axes=0)
    Bz = np.tensordot(np.sin(2 * np.pi / tv.domainSize[0] * x_dual),
                      np.tanh(2 * np.pi / tv.domainSize[1] * y_dual),
                      axes=0)

    # Jx =  dyBz
    # Jy = -dxBz
    # Jz =  dxBy - dyBx
    Jx[:,
       psi_p_Y:pei_p_Y + 1] = (Bz[:, psi_d_Y:pei_d_Y + 2] -
                               Bz[:, psi_d_Y - 1:pei_d_Y + 1]) / tv.meshSize[1]
    Jy[psi_p_X:pei_p_X +
       1, :] = -(Bz[psi_d_X:pei_d_X + 2, :] -
                 Bz[psi_d_X - 1:pei_d_X + 1, :]) / tv.meshSize[0]
    w1[psi_p_X:pei_p_X +
       1, :] = (By[psi_d_X:pei_d_X + 2, :] -
                By[psi_d_X - 1:pei_d_X + 1, :]) / tv.meshSize[0]
    w2[:, psi_p_Y:pei_p_Y +
       1] = -(Bx[:, psi_d_Y:pei_d_Y + 2] -
              Bx[:, psi_d_Y - 1:pei_d_Y + 1]) / tv.meshSize[1]
    Jz = w1 + w2

    filename_jx = "jx_yee_2D_order1.txt"
    filename_jy = "jy_yee_2D_order1.txt"
    filename_jz = "jz_yee_2D_order1.txt"

    np.savetxt(os.path.join(path, filename_jx), Jx.flatten('C'), delimiter=" ")
    np.savetxt(os.path.join(path, filename_jy), Jy.flatten('C'), delimiter=" ")
    np.savetxt(os.path.join(path, filename_jz), Jz.flatten('C'), delimiter=" ")