elif getMPISizeWorld() > 1: print("\nWARNING: SEGY files cannot be written with multiple processes\n") t = 0.0 mkDir("tmp") n = 0 while t < t_end: t, u = sw.update(t + sampling_interval) tracerEW_x.addRecord(locEW(u[0])) tracerEW_z.addRecord(locEW(u[DIM - 1])) if DIM == 3: tracerEW_y.addRecord(locEW(u[1])) tracerNS_x.addRecord(locNS(u[0])) tracerNS_y.addRecord(locNS(u[1])) tracerNS_z.addRecord(locNS(u[2])) print(t, locEW(u[DIM - 1])[len(rgEW) // 2 - 4 : len(rgEW) // 2 + 1], wl.getValue(t)) # if n%5 == 0 : saveSilo("tmp/u_%d.silo"%(n/5,), u=u) saveSilo("tmp/u_%d.silo" % (n,), u=u, cycle=n, time=t) n += 1 if tracerEW_x.obspy_available() and getMPISizeWorld() == 1: tracerEW_x.write("lineEW_x.sgy") tracerEW_z.write("lineEW_z.sgy") if DIM == 3: tracerEW_y.write("lineEW_y.sgy") tracerNS_x.write("lineNS_x.sgy") tracerNS_y.write("lineNS_y.sgy") tracerNS_z.write("lineNS_z.sgy") else: # no speckley print("The Speckley module is not available")
# vertical direction. Using this masking means that when q is used it will apply # only to the specified area of the domain. x = Function(mydomain).getX() q=q.subs(theta,(symconstants.pi/4)*whereNonNegative(x[1]-.30)*whereNegative(x[1]-.70)) # epsilon is defined in terms of u and has the rotation applied. epsilon0 = symmetric(grad(u)) epsilon = matrixmult(matrixmult(q,epsilon0),q.transpose(1)) # For the purposes of demonstration, an arbitrary c with isotropic constraints # is chosen here. In order to act as an isotropic material c is chosen such that # c00 = c11 = c01+c1+2*c55 c00 = 10 c01 = 8; c11 = 10 c05 = 0; c15 = 0; c55 = 1 # sigma is defined in terms of epsilon sigma[0,0] = c00*epsilon[0,0]+c01*epsilon[1,1]+c05*2*epsilon[1,0] sigma[1,1] = c01*epsilon[0,0]+c11*epsilon[1,1]+c15*2*epsilon[1,0] sigma[0,1] = c05*epsilon[0,0]+c15*epsilon[1,1]+c55*2*epsilon[1,0] sigma[1,0] = sigma[0,1] sigma0=matrixmult(matrixmult(q.transpose(1),sigma),q) # set up boundary conditions x=mydomain.getX() gammaD=whereZero(x[1])*[1,1] yconstraint = FunctionOnBoundary(mydomain).getX()[1] # The nonlinear PDE is set up, the values are substituted in and the solution is # calculated y represents an external shearing force acting on the domain. # In this case a force of magnitude 50 acting in the x[0] direction. p = NonlinearPDE(mydomain, u, debug=NonlinearPDE.DEBUG0) p.setValue(X=sigma0,q=gammaD,y=[-50,0]*whereZero(yconstraint-1),r=[1,1]) v = p.getSolution(u=[0,0]) saveSilo("solution",solution=v)
def RegionalCalculation(reg_mask): """ Calculates the "regional" from the entire FEILDS model excluding the selected region and outputs gravity at the specified altitude... see above for the "residual" """ # read in a gravity data grid to define data computation space G_DATA = os.path.join(DATADIR,'Final_BouguerTC_UC15K_qrtdeg.nc') FS=ReducedFunction(dom) nValues=[NX, NY, 1] first = [0, 0, cell_at_altitude] multiplier = [1, 1, 1] reverse = [0, 0, 0] byteorder = BYTEORDER_NATIVE gdata = readBinaryGrid(G_DATA, FS, shape=(), fill=-999999, byteOrder=byteorder, dataType=DATATYPE_FLOAT32, first=first, numValues=nValues, multiplier=multiplier, reverse=reverse) print("Grid successfully read") # get the masking and units sorted out for the data-space g_mask = whereNonZero(gdata+999999) gdata=gdata*g_mask * GRAV_UNITS # if people choose to have air in their region we exclude it from the # specified gravity calculation region if h_top < 0.: reg_mask = reg_mask+mask_air live_model = initial_model* whereNonPositive(reg_mask) dead_model = initial_model* wherePositive(reg_mask) if UseMean is True: # calculate the mean density within the selected region BackgroundDensity = integrate(dead_model)/integrate(wherePositive(reg_mask)) print("Density mean for selected region equals = %s"%BackgroundDensity) live_model = live_model + BackgroundDensity * wherePositive(reg_mask) # create mapping rho_mapping = DensityMapping(dom, rho0=live_model) # invert sign of gravity field to account for escript's coordinate system gdata = -GRAV_UNITS * gdata # turn the scalars into vectors (vertical direction) d=kronecker(DIM)[DIM-1] w=safeDiv(1., g_mask) gravity_model=GravityModel(dom, w*d, gdata*d, fixPotentialAtBottom=False, coordinates=COORDINATES) gravity_model.rescaleWeights(rho_scale=rho_mapping.getTypicalDerivative()) phi,_ = gravity_model.getArguments(live_model) g_init = -gravity_model.getCoordinateTransformation().getGradient(phi) g_init = interpolate(g_init, gdata.getFunctionSpace()) print("Computed gravity: %s"%(g_init[2])) fn=os.path.join(OUTPUTDIR,'regional-gravity') if SiloOutput is True: saveSilo(fn, density=live_model, gravity_init=g_init, g_initz=-g_init[2], gravitymask=g_mask, modelmask=reg_mask) print('SILO file written with the following fields: density (kg/m^3), gravity vector (m/s^2), gz (m/s^2), gravitymask, modelmask') # to compare calculated data against input dataset. # Not used by default but should work if the input dataset is correct #gslice = g_init[2]*wherePositive(g_mask) #g_dash = integrate(gslice)/integrate(wherePositive(g_mask)) #gdataslice = gdata*wherePositive(g_mask) #gdata_dash = integrate(gdataslice)/integrate(wherePositive(g_mask)) #misfit=(gdataslice-gdata_dash)-(gslice-g_dash) saveDataCSV(fn+".csv", mask=g_mask, gz=-g_init[2], Long=datacoords[0], Lat=datacoords[1], h=datacoords[2]) print('CSV file written with the following fields: Longitude (degrees) Latitude (degrees), h (100km), gz (m/s^2)')
def saveAndUpload(fn, **args): saveSilo(fn, **args) subprocess.call(["cloud", "upload", fn, fn, "--set-acl=public-read"])
tracer_z=SimpleSEGYWriter(receiver_group=grploc, source=srcloc, sampling_interval=sampling_interval, text='z-displacement') if not tracer_x.obspy_available(): print("\nWARNING: obspy not available, SEGY files will not be written\n") elif getMPISizeWorld() > 1: print("\nWARNING: SEGY files cannot be written with multiple processes\n") t=0. mkDir('output') n=0 k_out=0 print("calculation starts @ %s"%(time.asctime(),)) while t < t_end: t,u = sw.update(t+sampling_interval) tracer_x.addRecord(srclog(u[0])) tracer_z.addRecord(srclog(u[1])) print("t=%s, src=%s: \t %s \t %s \t %s"%(t, wl.getValue(t),srclog(u[1])[0], srclog(u[1])[src_id], srclog(u[1])[-1])) if not n_out is None and n%n_out == 0: print("time step %s written to file %s"%(n_out, "output/u_%d.silo"%(k_out,))) saveSilo("output/u_%d.silo"%(k_out,), u=u) k_out+=1 n+=1 if tracer_x.obspy_available() and getMPISizeWorld() == 1: tracer_x.write('output/lineX.sgy') tracer_z.write('output/lineZ.sgy') print("calculation completed @ %s"%(time.asctime(),)) else: # no speckley print("The Speckley module is not available")
if ReverseSelection: reg_mask = whereNonZero(mask_LONG+mask_LAT+mask_h) else: reg_mask = whereZero(mask_LONG+mask_LAT+mask_h) # prior to any computation, write out the selected region model as CSV # and Silo if requested fn = os.path.join(OUTPUTDIR, "region_%s")%(MODEL_PROPERTY) saveDataCSV(fn+".csv", Long=datacoords[0], Lat=datacoords[1], h=datacoords[2], PROPERTY=initial_model, mask=reg_mask) print("CSV file written with the following fields: Longitude (degrees)" +" Latitude (degrees), h (100km), Property (kg/m^3 or Pa)") if SiloOutput: saveSilo(fn, PROPERTY=initial_model, mask=reg_mask) print('SILO file written with the following fields: Property (kg/m^3 or Pa), mask') def ResidualCalculation(reg_mask): """ Calculates the "residual" from the selected region for the entire FEILDS model region and outputs gravity at the specified altitude... see below for the "regional" """ # read in a gravity data grid to define data computation space G_DATA = os.path.join(DATADIR,'Final_BouguerTC_UC15K_qrtdeg.nc') FS=ReducedFunction(dom) nValues=[NX, NY, 1] first = [0, 0, cell_at_altitude]
elif getMPISizeWorld() > 1: print( "\nWARNING: SEGY files cannot be written with multiple processes\n" ) t = 0. mkDir('output') n = 0 k_out = 0 print("calculation starts @ %s" % (time.asctime(), )) while t < t_end: t, u = sw.update(t + sampling_interval) tracer_x.addRecord(srclog(u[0])) tracer_z.addRecord(srclog(u[1])) print("t=%s, src=%s: \t %s \t %s \t %s" % (t, wl.getValue(t), srclog(u[1])[0], srclog( u[1])[src_id], srclog(u[1])[-1])) if not n_out is None and n % n_out == 0: print("time step %s written to file %s" % (n_out, "output/u_%d.silo" % (k_out, ))) saveSilo("output/u_%d.silo" % (k_out, ), u=u) k_out += 1 n += 1 if tracer_x.obspy_available() and getMPISizeWorld() == 1: tracer_x.write('output/lineX.sgy') tracer_z.write('output/lineZ.sgy') print("calculation completed @ %s" % (time.asctime(), )) else: # no speckley print("The Speckley module is not available")
from esys.weipa import saveVTK, saveSilo from esys.escript.linearPDEs import LinearSinglePDE, SolverOptions from esys.finley import ReadGmsh from esys.escript.pdetools import Locator print("read in mesh") domain = ReadGmsh("simplemesh.msh", 3, optimize=True) pde = LinearSinglePDE(domain, isComplex=False) pde.setSymmetryOn() x = domain.getX() pde.setValue(A=kronecker(3), Y=1, q=whereZero(x[0] - inf(x[0]))) options = pde.getSolverOptions() options.setPackage(SolverOptions.TRILINOS) options.setSolverMethod(SolverOptions.PCG) options.setPreconditioner(SolverOptions.AMG) options.setTrilinosParameter("multigrid algorithm", "sa") options.setTrilinosParameter("sa: damping factor", 1.3) options.setTrilinosParameter("max levels", 10) options.setTrilinosParameter("coarse: max size", 2000) options.setTrilinosParameter("coarse: type", "SuperLU") options.setTrilinosParameter("verbosity", "low") print("solve pde") u = pde.getSolution() saveSilo("asimple", u=u) print("finished")
locEW=Locator(domain,rcvEW_locations) tracerEW=SimpleSEGYWriter(receiver_group=rgEW, source=src_loc_2D, sampling_interval=sampling_interval) if DIM==3: locNS=Locator(domain,rcvNS_locations) tracerNS=SimpleSEGYWriter(receiver_group=rgNS, source=src_loc_2D, sampling_interval=sampling_interval) if not tracerEW.obspy_available(): print("\nWARNING: obspy not available, SEGY files will not be written\n") elif getMPISizeWorld() > 1: print("\nWARNING: SEGY files cannot be written with multiple processes\n") t=0. mkDir('tmp') n=0 while t < t_end: t,p = sw.update(t+sampling_interval) tracerEW.addRecord(locEW(p)) if DIM==3: tracerNS.addRecord(locNS(p)) print(t, locEW(p)[:4], wl.getValue(t)) if n%5 == 0 : saveSilo("tmp/u_%d.silo"%(n//5,), p=p) n+=1 if tracerEW.obspy_available() and getMPISizeWorld() == 1: tracerEW.write('lineEW.sgy') if DIM == 3: tracerNS.write('lineNS.sgy') else: # no speckley print("The Speckley module is not available")
if not config.true_properties is None: outargs['sigma_error']=sigma/sigma_true sigma_true.expand() outargs['sigma_true']=sigma_true if not args.sigmaonly: outargs['gamma']=gamma if not config.true_properties is None: outargs['gamma_error']=gamma/gamma_true gamma_true.expand() outargs['gamma_true']=gamma_true if args.vtk: saveVTK(config.outfile, **outargs) if getMPIRankWorld() == 0: print("result written to %s.vtu"%config.outfile) else: saveSilo(config.outfile, **outargs) if getMPIRankWorld() == 0: print("result written to %s.silo"%config.outfile) if args.xyz: sigmas=interpolate(sigma, ReducedFunction(domain)) X=sigmas.getFunctionSpace().getX() args={ "d0": X[0], "d1": X[1], "d2" :X[2], "sigma" : sigmas} if not args.sigmaonly: args['gamma']=interpolate(gamma, sigmas.getFunctionSpace()) saveDataCSV(config.outfile+".csv", **args) if getMPIRankWorld() == 0: print("result written to %s.csv"%config.outfile) if getMPIRankWorld() == 0: print("All done - Have a nice day!")