def test2d(): mesh = pg.Mesh("mesh/world2d.bms") print (mesh) xMin = mesh.boundingBox().min()[0] yMax = mesh.boundingBox().max()[0] x = np.arange(xMin, yMax, 1.0) mesh.createNeighbourInfos() rho = pg.RVector(len(mesh.cellAttributes()), 1.0) * 2000.0 rho.setVal(0.0, pg.find(mesh.cellAttributes() == 1.0)) swatch = pg.Stopwatch(True) pnts = [] spnts = pg.stdVectorRVector3() for i in x: pnts.append(pg.RVector3(i, 0.0001)) spnts.append(pg.RVector3(i, 0.0001)) # gzC, GC = calcGCells(pnts, mesh, rho, 1) gzC = pg.calcGCells(spnts, mesh, rho, 1) print ("calcGCells", swatch.duration(True)) # gzB, GB = calcGBounds(pnts, mesh, rho) # gzB = pg.calcGBounds(spnts, mesh, rho) # print("calcGBounds", swatch.duration(True)) gZ_Mesh = gzC ax1, ax2 = getaxes() # sphere analytical solution gAna = analyticalCircle2D(spnts, radius=2.0, pos=pg.RVector3(0.0, -5.0), dDensity=2000) gAna2 = analyticalCircle2D(spnts, radius=2.0, pos=pg.RVector3(5.0, -5.0), dDensity=2000) gAna = gAna + gAna2 ax1.plot(x, gAna, "-x", label="analytical") ax1.plot(x, gZ_Mesh, label="WonBevis1987-mesh") print (gAna / gZ_Mesh) # rho=GB[0]/mesh.cellSizes() drawModel(ax2, mesh, rho) for i in (0, 1): drawSelectedMeshBoundaries(ax2, mesh.findBoundaryByMarker(i), color=(1.0, 1.0, 1.0, 1.0), linewidth=0.3) # sphere polygone radius = 2.0 depth = 5.0 poly1 = pg.stdVectorRVector3() poly2 = pg.stdVectorRVector3() nSegment = 124 for i in range(nSegment): xp = np.sin((i + 1) * (2.0 * np.pi) / nSegment) yp = np.cos((i + 1) * (2.0 * np.pi) / nSegment) poly1.append(pg.RVector3(xp * radius, yp * radius - depth)) poly2.append(pg.RVector3(xp * radius + 5.0, yp * radius - depth)) gZ_Poly = calcPolydgdz(spnts, poly1, 2000) gZ_Poly += calcPolydgdz(spnts, poly2, 2000) ax1.plot(x, gZ_Poly, label="WonBevis1987-Poly") ax2.plot(pg.x(poly1), pg.y(poly1), color="red") ax2.plot(pg.x(poly2), pg.y(poly2), color="red") ax2.plot(pg.x(spnts), pg.y(spnts), marker="x", color="black") # test some special case for i, p in enumerate(poly1): poly1[i] = pg.RVector3(poly1[i] - pg.RVector3(5.0, -6.0)) ax2.plot(pg.x(poly1), pg.y(poly1), color="green") gz = calcPolydgdz(spnts, poly1, 2000) ax1.plot(x, gz, label="Special Case", color="green") ax1.set_ylabel("dg/dz [mGal]") ax2.set_ylabel("Tiefe [m]") ax1.legend() ax2.set_xlim([x[0], x[-1]]) ax2.grid()
# mesh.createQuadrangle(A, B, C, D) mesh.scale(pg.RVector3(3.0, 3.0)) # mesh.createTriangle(A, B, D) print mesh.cellSizes() x = np.arange(-10, 10, 1.0) rho = pg.RVector(len(mesh.cellAttributes()), 1.0) * 2000.0 print (rho) pnts = pg.stdVectorRVector3() for i in x: pnts.append(pg.RVector3(i, 0.0001)) gzNum = [] gzNum.append(pg.calcGCells(pnts, mesh, rho, 0)[0]) # plt.plot(x, gzNum[0], label=str(0)) for i in range(1, 10): gzNum.append(pg.calcGCells(pnts, mesh, rho, i)[0]) err = pg.abs(gzNum[i] / gzNum[0] - 1.0) * 100.0 plt.semilogy(x, err, label=str(i)) plt.plot(x, gzNum[i], label=str(i)) plt.legend() # plt.plot(x, p1 )
def test2d(): mesh = pg.Mesh('mesh/world2d.bms') print(mesh) xMin = mesh.boundingBox().min()[0] yMax = mesh.boundingBox().max()[0] x = np.arange(xMin, yMax, 1.) mesh.createNeighbourInfos() rho = pg.RVector(len(mesh.cellAttributes()), 1.) * 2000.0 rho.setVal(0.0, pg.find(mesh.cellAttributes() == 1.0)) swatch = pg.Stopwatch(True) pnts = [] spnts = pg.stdVectorRVector3() for i in x: pnts.append(pg.RVector3(i, 0.0001)) spnts.append(pg.RVector3(i, 0.0001)) # gzC, GC = calcGCells(pnts, mesh, rho, 1) gzC = pg.calcGCells(spnts, mesh, rho, 1) print("calcGCells", swatch.duration(True)) # gzB, GB = calcGBounds(pnts, mesh, rho) # gzB = pg.calcGBounds(spnts, mesh, rho) # print("calcGBounds", swatch.duration(True)) gZ_Mesh = gzC ax1, ax2 = getaxes() # sphere analytical solution gAna = analyticalCircle2D(spnts, radius=2.0, pos=pg.RVector3(0.0, -5.0), dDensity=2000) gAna2 = analyticalCircle2D(spnts, radius=2.0, pos=pg.RVector3(5.0, -5.0), dDensity=2000) gAna = gAna + gAna2 ax1.plot(x, gAna, '-x', label='analytical') ax1.plot(x, gZ_Mesh, label='WonBevis1987-mesh') print(gAna / gZ_Mesh) # rho=GB[0]/mesh.cellSizes() drawModel(ax2, mesh, rho) for i in (0, 1): drawSelectedMeshBoundaries(ax2, mesh.findBoundaryByMarker(i), color=(1.0, 1.0, 1.0, 1.0), linewidth=0.3) # sphere polygone radius = 2. depth = 5. poly1 = pg.stdVectorRVector3() poly2 = pg.stdVectorRVector3() nSegment = 124 for i in range(nSegment): xp = np.sin((i + 1) * (2. * np.pi) / nSegment) yp = np.cos((i + 1) * (2. * np.pi) / nSegment) poly1.append(pg.RVector3(xp * radius, yp * radius - depth)) poly2.append(pg.RVector3(xp * radius + 5., yp * radius - depth)) gZ_Poly = calcPolydgdz(spnts, poly1, 2000) gZ_Poly += calcPolydgdz(spnts, poly2, 2000) ax1.plot(x, gZ_Poly, label='WonBevis1987-Poly') ax2.plot(pg.x(poly1), pg.y(poly1), color='red') ax2.plot(pg.x(poly2), pg.y(poly2), color='red') ax2.plot(pg.x(spnts), pg.y(spnts), marker='x', color='black') # test some special case for i, p in enumerate(poly1): poly1[i] = pg.RVector3(poly1[i] - pg.RVector3(5.0, -6.)) ax2.plot(pg.x(poly1), pg.y(poly1), color='green') gz = calcPolydgdz(spnts, poly1, 2000) ax1.plot(x, gz, label='Special Case', color='green') ax1.set_ylabel('dg/dz [mGal]') ax2.set_ylabel('Tiefe [m]') ax1.legend() ax2.set_xlim([x[0], x[-1]]) ax2.grid()
def test2d(): mesh = g.Mesh( 'mesh/world2d.bms' ) print mesh xMin = mesh.boundingBox( ).min()[0] yMax = mesh.boundingBox( ).max()[0] x = P.arange( xMin, yMax, 1. ); mesh.createNeighbourInfos() rho = g.RVector( len( mesh.cellAttributes() ), 1. ) * 2000.0 rho.setVal( 0.0, g.find( mesh.cellAttributes() == 1.0 ) ) swatch = g.Stopwatch( True ) pnts = [] spnts = g.stdVectorRVector3() for i in x: pnts.append( g.RVector3( i, 0.0001 ) ) spnts.append( g.RVector3( i, 0.0001 ) ) #gzC, GC = calcGCells( pnts, mesh, rho, 1 ) gzC = g.calcGCells( spnts , mesh, rho, 1 ) print "calcGCells", swatch.duration( True ) #gzB, GB = calcGBounds( pnts, mesh, rho ) gzB = g.calcGBounds( spnts , mesh, rho ) print "calcGBounds", swatch.duration( True ) gZ_Mesh = gzC ax1, ax2 = getaxes() # sphere analytical solution gAna = analyticalCircle2D( spnts, radius = 2.0, pos = g.RVector3( 0.0, -5.0 ), dDensity = 2000 ) gAna2 = analyticalCircle2D( spnts, radius = 2.0, pos = g.RVector3( 5.0, -5.0 ), dDensity = 2000 ) gAna = gAna + gAna2 ax1.plot( x, gAna, '-x', label= 'Analytisch' ) ax1.plot( x, gZ_Mesh, label= 'WonBevis1987-mesh' ) print gAna / gZ_Mesh #rho=GB[0]/mesh.cellSizes() gci = drawModel( ax2, mesh, rho ) drawSelectedMeshBoundaries( ax2, mesh.findBoundaryByMarker( 0 ) , color = ( 1.0, 1.0, 1.0, 1.0 ) , linewidth = 0.3 ) drawSelectedMeshBoundaries( ax2, mesh.findBoundaryByMarker( 1 ) , color = ( 1.0, 1.0, 1.0, 1.0 ) , linewidth = 0.3 ) # sphere polygone radius = 2. depth = 5. poly1 = g.stdVectorRVector3() poly2 = g.stdVectorRVector3() nSegment=124 for i in range( nSegment ): xp = np.sin( (i+1) * ( 2. * np.pi ) / nSegment ) yp = np.cos( (i+1) * ( 2. * np.pi ) / nSegment ) poly1.append( g.RVector3( xp * radius, yp * radius - depth ) ) poly2.append( g.RVector3( xp * radius + 5., yp * radius - depth ) ) gZ_Poly = calcPolydgdz( spnts, poly1, 2000 ) gZ_Poly += calcPolydgdz( spnts, poly2, 2000 ) ax1.plot( x, gZ_Poly, label= 'WonBevis1987-Poly' ) ax2.plot( g.x( poly1 ), g.y( poly1 ), color = 'red' ) ax2.plot( g.x( poly2 ), g.y( poly2 ), color = 'red' ) ax2.plot( g.x( spnts ), g.y( spnts ), marker = 'x', color = 'black' ) # test some special case for i, p in enumerate( poly1 ): poly1[i] = g.RVector3( poly1[i] - g.RVector3( 5.0, -6. ) ) ax2.plot( g.x( poly1 ), g.y( poly1 ), color = 'green' ) gz = calcPolydgdz( spnts, poly1, 2000 ) ax1.plot( x, gz, label= 'Special Case', color = 'green' ) ax1.set_ylabel( 'dg/dz [mGal]' ) ax2.set_ylabel( 'Tiefe [m]' ) ax1.legend() ax2.set_xlim( [ x[0], x[-1] ] ) ax2.grid()
# mesh.createQuadrangle(A, B, C, D) mesh.scale(pg.RVector3(3., 3.)) # mesh.createTriangle(A, B, D) print mesh.cellSizes() x = np.arange(-10, 10, 1.) rho = pg.RVector(len(mesh.cellAttributes()), 1.) * 2000.0 print(rho) pnts = pg.stdVectorRVector3() for i in x: pnts.append(pg.RVector3(i, 0.0001)) gzNum = [] gzNum.append(pg.calcGCells(pnts, mesh, rho, 0)[0]) # plt.plot(x, gzNum[0], label=str(0)) for i in range(1, 10): gzNum.append(pg.calcGCells(pnts, mesh, rho, i)[0]) err = pg.abs(gzNum[i] / gzNum[0] - 1.) * 100. plt.semilogy(x, err, label=str(i)) plt.plot(x, gzNum[i], label=str(i)) plt.legend() # plt.plot(x, p1 ) test2d()