Exemplo n.º 1
0
def numerical():
    des = Dynearthsol('result')
    displacement = numpy.zeros(51, dtype=float)
    Sxx = numpy.zeros(51, dtype=float)
    for i in range(51):
        des.read_header(i)
        x = des.read_field(i, 'coordinate')
        displacement[i] = 1 - x[3, 0]
        s = des.read_field(i, 'stress')
        Sxx[i] = abs(s[1, 0])

    return displacement, Sxx
Exemplo n.º 2
0
def main():
    mopen = Dynearthsol(modelname)
    rho = mopen.read_field(nframe, 'density')
    conn = mopen.read_field(nframe, 'connectivity')
    coord = mopen.read_field(nframe, 'coordinate')
    bcflag = mopen.read_field(nframe, 'bcflag').astype(np.int16)
    node32 = coord[(bcflag & 32).astype(bool)]

    ###### create new vertice #######
    ## extend two walls
    xbtm = coord[bcflag == 17]
    xbtm2 = [[xbtm[0, 0] - 10000, xbtm[0, 1]]]
    xtop = coord[bcflag == 33]
    xtop2 = [[xtop[0, 0] - 10000, xtop[0, 1]]]
    x0 = np.vstack([xbtm, xbtm2, xtop, xtop2])
    tridict = dict(vertices=x0)
    B = tr.triangulate(tridict, 'qa1000000')
    n0 = coord.shape[0]
    coord = np.vstack([coord, B['vertices']])
    conn = np.vstack([conn, B['triangles'] + n0])
    rho = np.hstack([rho, np.ones(shape=B['triangles'].shape[0]) * 1750])
    bcflag = np.hstack([bcflag, np.zeros(shape=B['vertices'].shape[0])
                        ]).astype(np.int16)

    xbtm = coord[bcflag == 66]
    xbtm2 = [[xbtm[0, 0] + 10000, xbtm[0, 1]]]
    xtop = coord[bcflag == 34]
    xtop2 = [[xtop[0, 0] + 10000, xtop[0, 1]]]
    x0 = np.vstack([xbtm, xbtm2, xtop, xtop2])
    tridict = dict(vertices=x0)
    B = tr.triangulate(tridict, 'qa1000000')
    n0 = coord.shape[0]
    coord = np.vstack([coord, B['vertices']])
    conn = np.vstack([conn, B['triangles'] + n0])
    rho = np.hstack([rho, np.ones(shape=B['triangles'].shape[0]) * 1750])

    ################################

    measureX = np.arange(left, right, 500)
    measureY = np.ones(shape=measureX.shape) * height

    result = bouguer(measureX, measureY, coord, conn, rho) * 1e5

    ##### figure #####
    fig, ax = plt.subplots(figsize=(10, 2.5))
    ax.set_title(modelname)
    ax.plot(measureX, result)
    ax.set_ylabel('Bouguer gravity anomaly (mgal)(blue)')
    ax2 = ax.twinx()
    ax2.plot(node32[:, 0], node32[:, 1], 'r')
    ax2.set_ylabel('topography (m)(red)')
    # ax2.set_aspect('equal', adjustable="datalim")
    plt.show()
Exemplo n.º 3
0
def main(modelname, start, end, delta):
    prefix = modelname
    if output_in_cwd:
        output_prefix = os.path.basename(modelname)
    else:
        output_prefix = modelname

    des = Dynearthsol(modelname)

    if start == -1:
        vtulist = sorted(glob.glob(modelname + '.*.vtu'))
        lastframe = int(vtulist[-1][(len(modelname) +
                                     1):-4]) if vtulist else des.frames[0]
        start = des.frames.index(lastframe) + 1

    if end == -1:
        end = len(des.frames)

    for i in range(start, end, delta):
        frame = des.frames[i]
        nnode = des.nnode_list[i]
        nelem = des.nelem_list[i]
        step = des.steps[i]
        time_in_yr = des.time[i] / (365.2425 * 86400)

        des.read_header(frame)
        suffix = '{0:0=6}'.format(frame)
        print('Converting frame #{0}'.format(suffix),
              end='\r',
              file=sys.stderr)

        filename = '{0}.{1}.vtu'.format(output_prefix, suffix)
        fvtu = open(filename, 'w')

        try:
            vtu_header(fvtu, nnode, nelem, time_in_yr, step)

            #
            # node-based field
            #
            fvtu.write('  <PointData>\n')

            # averaged velocity is more stable and is preferred
            try:
                convert_field(des, frame, 'velocity averaged', fvtu)
            except KeyError:
                convert_field(des, frame, 'velocity', fvtu)

            convert_field(des, frame, 'force', fvtu)
            coord0 = des.read_field(frame, 'coord0')
            coord = des.read_field(frame, 'coordinate')
            disp = np.zeros((nnode, 3), dtype=coord.dtype)
            disp[:, 0:des.ndims] = coord - coord0
            vtk_dataarray(fvtu, disp, 'total displacement', 3)

            convert_field(des, frame, 'temperature', fvtu)
            convert_field(des, frame, 'bcflag', fvtu)
            #convert_field(des, frame, 'mass', fvtu)
            #convert_field(des, frame, 'tmass', fvtu)
            #convert_field(des, frame, 'volume_n', fvtu)

            # node number for debugging
            vtk_dataarray(fvtu, np.arange(nnode, dtype=np.int32),
                          'node number')

            fvtu.write('  </PointData>\n')
            #
            # element-based field
            #
            fvtu.write('  <CellData>\n')

            #convert_field(des, frame, 'volume', fvtu)
            #convert_field(des, frame, 'edvoldt', fvtu)

            convert_field(des, frame, 'mesh quality', fvtu)
            convert_field(des, frame, 'plastic strain', fvtu)
            convert_field(des, frame, 'plastic strain-rate', fvtu)

            strain_rate = des.read_field(frame, 'strain-rate')
            srII = second_invariant(strain_rate)
            vtk_dataarray(fvtu, np.log10(srII + 1e-45), 'strain-rate II log10')
            if output_tensor_components:
                for d in range(des.nstr):
                    vtk_dataarray(fvtu, strain_rate[:, d],
                                  'strain-rate ' + des.component_names[d])

            strain = des.read_field(frame, 'strain')
            sI = first_invariant(strain)
            sII = second_invariant(strain)
            vtk_dataarray(fvtu, sI, 'strain I')
            vtk_dataarray(fvtu, sII, 'strain II')
            if output_tensor_components:
                for d in range(des.nstr):
                    vtk_dataarray(fvtu, strain[:, d],
                                  'strain ' + des.component_names[d])

            # averaged stress is more stable and is preferred
            try:
                stress = des.read_field(frame, 'stress averaged')
            except KeyError:
                stress = des.read_field(frame, 'stress')
            tI = first_invariant(stress)
            tII = second_invariant(stress)
            vtk_dataarray(fvtu, tI, 'stress I')
            vtk_dataarray(fvtu, tII, 'stress II')
            if output_tensor_components:
                for d in range(des.ndims):
                    vtk_dataarray(fvtu, stress[:, d] - tI,
                                  'stress ' + des.component_names[d] + ' dev.')
                for d in range(des.ndims, des.nstr):
                    vtk_dataarray(fvtu, stress[:, d],
                                  'stress ' + des.component_names[d])
            if output_principal_stress:
                s1, s3 = compute_principal_stress(stress)
                vtk_dataarray(fvtu, s1, 's1', 3)
                vtk_dataarray(fvtu, s3, 's3', 3)

            convert_field(des, frame, 'density', fvtu)
            convert_field(des, frame, 'material', fvtu)
            convert_field(des, frame, 'viscosity', fvtu)
            effvisc = tII / (srII + 1e-45)
            vtk_dataarray(fvtu, effvisc, 'effective viscosity')

            # element number for debugging
            vtk_dataarray(fvtu, np.arange(nelem, dtype=np.int32),
                          'elem number')

            fvtu.write('  </CellData>\n')

            #
            # node coordinate
            #
            fvtu.write('  <Points>\n')
            convert_field(des, frame, 'coordinate', fvtu)
            fvtu.write('  </Points>\n')

            #
            # element connectivity & types
            #
            fvtu.write('  <Cells>\n')
            convert_field(des, frame, 'connectivity', fvtu)
            vtk_dataarray(fvtu, (des.ndims + 1) *
                          np.array(range(1, nelem + 1), dtype=np.int32),
                          'offsets')
            if des.ndims == 2:
                # VTK_ TRIANGLE == 5
                celltype = 5
            else:
                # VTK_ TETRA == 10
                celltype = 10
            vtk_dataarray(fvtu, celltype * np.ones((nelem, ), dtype=np.int32),
                          'types')
            fvtu.write('  </Cells>\n')

            vtu_footer(fvtu)
            fvtu.close()

        except:
            # delete partial vtu file
            fvtu.close()
            os.remove(filename)
            raise

        #
        # Converting marker
        #
        if output_markers:
            # ordinary markerset
            filename = '{0}.{1}.vtp'.format(output_prefix, suffix)
            output_vtp_file(des, frame, filename, 'markerset', time_in_yr,
                            step)

            # hydrous markerset
            if 'hydrous-markerset size' in des.field_pos:
                filename = '{0}.hyd-ms.{1}.vtp'.format(output_prefix, suffix)
                output_vtp_file(des, frame, filename, 'hydrous-markerset',
                                time_in_yr, step)

    print()
    return
Exemplo n.º 4
0
def main(): 
	mopen=Dynearthsol(modelname)
	rho=mopen.read_field(nframe,'density')
	conn=mopen.read_field(nframe,'connectivity')
	coord=mopen.read_field(nframe,'coordinate')
	bcflag=mopen.read_field(nframe,'bcflag').astype(np.int16)
Exemplo n.º 5
0
def main(modelname, start, end, delta):
    prefix = modelname
    if output_in_cwd:
        output_prefix = os.path.basename(modelname)
    else:
        output_prefix = modelname

    des = Dynearthsol(modelname)

    if end == -1:
        end = len(des.frames)

    for i in range(start, end, delta):
        frame = des.frames[i]
        nnode = des.nnode_list[i]
        nelem = des.nelem_list[i]
        step = des.steps[i]
        time_in_yr = des.time[i] / (365.2425 * 86400)

        des.read_header(frame)
        suffix = '{0:0=6}'.format(frame)
        print('Converting frame #{0}'.format(suffix),
              end='\r',
              file=sys.stderr)

        filename = '{0}.{1}.vtu'.format(output_prefix, suffix)
        fvtu = open(filename, 'wb')

        try:
            vtu_header(fvtu, nnode, nelem, time_in_yr, step)

            #
            # node-based field
            #
            fvtu.write(b'  <PointData>\n')

            convert_field(des, frame, 'temperature', fvtu)
            #convert_field(des, frame, 'z0', fvtu)
            #convert_field(des, frame, 'bcflag', fvtu)
            #convert_field(des, frame, 'mass', fvtu)
            #convert_field(des, frame, 'tmass', fvtu)
            #convert_field(des, frame, 'volume_n', fvtu)

            # node number for debugging
            vtk_dataarray(fvtu, np.arange(nnode, dtype=np.int32),
                          'node number')

            fvtu.write(b'  </PointData>\n')

            #
            # node coordinate
            #
            fvtu.write(b'  <Points>\n')
            convert_field(des, frame, 'coordinate', fvtu)
            fvtu.write(b'  </Points>\n')

            #
            # element connectivity & types
            #
            fvtu.write(b'  <Cells>\n')
            convert_field(des, frame, 'connectivity', fvtu)
            vtk_dataarray(fvtu, (des.ndims + 1) *
                          np.array(range(1, nelem + 1), dtype=np.int32),
                          'offsets')
            if des.ndims == 2:
                # VTK_ TRIANGLE == 5
                celltype = 5
            else:
                # VTK_ TETRA == 10
                celltype = 10
            vtk_dataarray(fvtu, celltype * np.ones((nelem, ), dtype=np.int32),
                          'types')
            fvtu.write(b'  </Cells>\n')

            vtu_footer(fvtu)
            fvtu.close()

        except:
            # delete partial vtu file
            fvtu.close()
            os.remove(filename)
            raise

    print()
    return
Exemplo n.º 6
0
def main(modelname, start, end, delta):
    prefix = modelname
    if output_in_cwd:
        output_prefix = os.path.basename(modelname)
    else:
        output_prefix = modelname

    des = Dynearthsol(modelname)

    if end == -1:
        end = len(des.frames)

    for i in range(start, end, delta):
        frame = des.frames[i]
        nnode = des.nnode_list[i]
        nelem = des.nelem_list[i]
        step = des.steps[i]
        time_in_yr = des.time[i] / (365.2425 * 86400)

        des.read_header(frame)
        suffix = '{0:0=6}'.format(frame)
        print('Converting frame #{0}'.format(suffix), end='\r', file=sys.stderr)

        filename = '{0}.{1}.vtu'.format(output_prefix, suffix)
        fvtu = open(filename, 'wb')

        try:
            vtu_header(fvtu, nnode, nelem, time_in_yr, step)

            #
            # node-based field
            #
            fvtu.write(b'  <PointData>\n')

            convert_field(des, frame, 'temperature', fvtu)
            #convert_field(des, frame, 'z0', fvtu)
            #convert_field(des, frame, 'bcflag', fvtu)
            #convert_field(des, frame, 'mass', fvtu)
            #convert_field(des, frame, 'tmass', fvtu)
            #convert_field(des, frame, 'volume_n', fvtu)

            # node number for debugging
            vtk_dataarray(fvtu, np.arange(nnode, dtype=np.int32), 'node number')

            fvtu.write(b'  </PointData>\n')

            #
            # node coordinate
            #
            fvtu.write(b'  <Points>\n')
            convert_field(des, frame, 'coordinate', fvtu)
            fvtu.write(b'  </Points>\n')

            #
            # element connectivity & types
            #
            fvtu.write(b'  <Cells>\n')
            convert_field(des, frame, 'connectivity', fvtu)
            vtk_dataarray(fvtu, (des.ndims+1)*np.array(range(1, nelem+1), dtype=np.int32), 'offsets')
            if des.ndims == 2:
                # VTK_ TRIANGLE == 5
                celltype = 5
            else:
                # VTK_ TETRA == 10
                celltype = 10
            vtk_dataarray(fvtu, celltype*np.ones((nelem,), dtype=np.int32), 'types')
            fvtu.write(b'  </Cells>\n')

            vtu_footer(fvtu)
            fvtu.close()

        except:
            # delete partial vtu file
            fvtu.close()
            os.remove(filename)
            raise

    print()
    return