def make_figs(system, tools): fig = glucifer.Figure(edgecolour="white", quality=2) figTempComponent = fig.Surface(system.mesh, system.temperatureField, colourBar=True) figVelComponent = fig.VectorArrows(system.mesh, system.velocityField) figViscComponent = fig.Contours( system.mesh, fn.math.log10(tools.projections['viscosityProj']), colours="red black", interval=0.5, colourBar=False, ) figMaterialComponent = fig.Points( system.swarm, fn_colour=system.materialVar, fn_mask=system.materialVar, fn_size=4., colours="purple", colourBar=False, ) figs = { 'fig': fig, } return figs
def density(self, figsize=None, title="Density Field", units=u.kilogram / u.metre**3, quality=3, script=None, cullface=False, show=True, store=None, visugrid=None, **kwargs): Fig = glucifer.Figure(store=store, figsize=figsize, quality=quality, min=self._boundingBox[0], max=self._boundingBox[1]) Fig["title"] = title + " " + str(units) Fig["boundingBox"] = self._boundingBox fact = Dimensionalize(1.0, units).magnitude Fig.Points(self.Model.swarm, fn_colour=self.Model._densityFn * fact, cullface=cullface, name=Fig["title"], **kwargs) Fig.script(script) if show and glucifer.lavavu.is_notebook(): Fig.show() return Fig
def plot_temperature(self, figsize=(1200, 400), units=u.degK, **args): Fig = glucifer.Figure(figsize=(1200, 400), title="Temperature Field") Fig.append( glucifer.objects.Surface( self.mesh, sca.Dimensionalize(self.temperature, units))) Fig.show() return Fig
def plot_pressure(self, figsize=(1200, 400), units=u.pascal, **kwargs): Fig = glucifer.Figure(figsize=(1200, 400), title="Pressure Field") Fig.append( glucifer.objects.Surface(self.mesh, sca.Dimensionalize(self.pressure, units), **kwargs)) Fig.show() return Fig
def plot_density(self, figsize=(1200, 400), **args): Fig = glucifer.Figure(figsize=(1200, 400)) Fig.append( glucifer.objects.Points(self.swarm, fn_colour=self.densityFn, fn_size=2.0)) Fig.show() return Fig
def plot_material(self, figsize=(1200, 400), **args): Fig = glucifer.Figure(figsize=(1200, 400), title="Materials") Fig.append( glucifer.objects.Points(self.swarm, fn_colour=self.material, fn_size=2.0)) Fig.show() return Fig
def velocityField(self, figsize=None, title="Velocity Field", units=u.centimeter / u.year, cullface=False, script=None, show=True, quality=3, store=None, colours='diverge', visugrid=None, arrowlength=0.0, arrownorm=1.0, arrowres=(16, 16, 16), **kwargs): Fig = glucifer.Figure(store=store, figsize=figsize, quality=quality, min=self._boundingBox[0], max=self._boundingBox[1]) Fig["title"] = title + " " + str(units) Fig["boundingBox"] = self._boundingBox fact = Dimensionalize(1.0, units).magnitude velmagfield = uw.function.math.sqrt( uw.function.math.dot(self.Model.velocityField, self.Model.velocityField)) Fig.Surface(self.Model.mesh, velmagfield * fact, colours=colours, cullface=cullface, name=Fig["title"], **kwargs) Fig.VectorArrows(self.Model.mesh, self.Model.velocityField, length=arrowlength, normalise=arrownorm, resolution=arrowres, **kwargs) if visugrid: clip_X, clip_Y = _visugrid_drawing_object(self.Model, visugrid) Fig.Mesh(visugrid.mesh, xmin=clip_X[0], xmax=clip_X[1], ymin=clip_Y[0], ymax=clip_Y[1]) Fig.script(script) if show and glucifer.lavavu.is_notebook(): Fig.show() return Fig
def plot_velocity(self, figsize=(1200, 400), **args): Fig = glucifer.Figure(figsize=(1200, 400)) Fig.append(glucifer.objects.Surface(self.mesh, self.velocity[0])) Fig.append( glucifer.objects.VectorArrows(self.mesh, self.velocity, scaling=0.03, arrowHead=10., resolutionI=25, resolutionJ=10)) Fig.show() return Fig
def plot_viscosity(self, figsize=(1200, 400), units=u.pascal * u.second, **args): Fig = glucifer.Figure(figsize=(1200, 400), title="Viscosity Field") Fig.append( glucifer.objects.Points(self.swarm, fn_colour=self.viscosityFn, fn_size=2.0, logScale=True)) Fig.show() return Fig
def materialField(self, figsize=None, title="Material Field", colours=None, script=None, cullface=False, mask=None, visugrid=None, onMesh=False, tracers=[], show=True, store=None, quality=3, **kwargs): Fig = glucifer.Figure(store=store, figsize=figsize, quality=quality, min=self._boundingBox[0], max=self._boundingBox[1]) Fig["title"] = title Fig["boundingBox"] = self._boundingBox if onMesh: Fig.Surface(self.Model.mesh, self.Model.projMaterialField, **kwargs) else: pts = Fig.Points(self.Model.swarm, fn_colour=self.Model.materialField, colours=colours, cullface=cullface, name=Fig["title"], **kwargs) # pts.colourBar["binlabels"] = True # pts.colourBar["align"] = "right" # pts.colourBar["vertical"] = True pts.colourBar.colourMap["discrete"] = True if visugrid: clip_X, clip_Y = _visugrid_drawing_object(self.Model, visugrid) Fig.Mesh(visugrid.mesh, xmin=clip_X[0], xmax=clip_X[1], ymin=clip_Y[0], ymax=clip_Y[1]) Fig.script(script) if show and glucifer.lavavu.is_notebook(): # Fig.viewer().window() Fig.show() return Fig
def make_figs(system, tools): fig = glucifer.Figure(edgecolour="white", quality=2) figTempComponent = fig.Surface(system.mesh, system.temperatureField, colourBar=True) figVelComponent = fig.VectorArrows(system.mesh, system.velocityField) figs = { 'fig': fig, } return figs
def __init__( self, *args, onMesh = True, facecolour = 'black', edgecolour = 'white', colourBar = False, quality = 3., **kwargs ): args = list(args) self.fig = glucifer.Figure( facecolour = facecolour, quality = 3., **kwargs ) self.features = set() self.fittedvars = [] self.updateFuncs = [] self.vars = [] self.planetVars = [] self.inventory = [ self.add_surface, self.add_contours, self.add_stipple, self.add_points, self.add_arrows, self.add_arrows_red, self.add_arrows_blue, ] self.functions_used = [] self.add_vars( *args, # onMesh = onMesh, colourBar = colourBar, **kwargs ) self.objects = self.fig.objects super().__init__(**kwargs)
def make_figs(system, step, modeltime): fig = glucifer.Figure(edgecolour="white", quality=2) figTempComponent = fig.Surface(system.mesh, system.temperatureField, colourBar=True) figVelComponent = fig.VectorArrows(system.mesh, system.velocityField) figViscComponent = fig.Contours(system.mesh, fn.math.log10(system.viscosityFn), colours="red black", interval=0.5, colourBar=False) figs = { 'fig': fig, } return figs
def strainRate(self, figsize=None, title="Strain Rate Field", units=1.0 / u.second, cullface=False, logScale=True, colours="coolwarm", script=None, show=True, quality=3, store=None, visugrid=None, **kwargs): Fig = glucifer.Figure(store=store, figsize=figsize, quality=quality, min=self._boundingBox[0], max=self._boundingBox[1]) Fig["title"] = title + " " + str(units) Fig["boundingBox"] = self._boundingBox fact = Dimensionalize(1.0, units).magnitude Fig.Surface(self.Model.mesh.subMesh, self.Model.strainRateField * fact, cullface=cullface, logScale=logScale, name=Fig["title"], colours=colours, **kwargs) if visugrid: clip_X, clip_Y = _visugrid_drawing_object(self.Model, visugrid) Fig.Mesh(visugrid.mesh, xmin=clip_X[0], xmax=clip_X[1], ymin=clip_Y[0], ymax=clip_Y[1]) Fig.script(script) if show and glucifer.lavavu.is_notebook(): Fig.show() return Fig
def viscosityField(self, figsize=None, title="Viscosity Field", units=u.pascal * u.second, logScale=True, projected=False, cullface=False, script=None, show=True, quality=3, store=None, visugrid=None, **kwargs): Fig = glucifer.Figure(store=store, figsize=figsize, quality=quality, min=self._boundingBox[0], max=self._boundingBox[1]) Fig["title"] = title + " " + str(units) Fig["boundingBox"] = self._boundingBox fact = Dimensionalize(1.0, units).magnitude Fig.Points(self.Model.swarm, self.Model._viscosityFn * fact, logScale=logScale, name=Fig["title"], cullface=cullface, **kwargs) if visugrid: clip_X, clip_Y = _visugrid_drawing_object(self.Model, visugrid) Fig.Mesh(visugrid.mesh, xmin=clip_X[0], xmax=clip_X[1], ymin=clip_Y[0], ymax=clip_Y[1]) Fig.script(script) if show and glucifer.lavavu.is_notebook(): Fig.show() return Fig
def plotFigures(fnSize=2, figSize=(1600, 300)): Model.plot.viscosity( figsize=figSize, colours='spectral', fn_size=fnSize, valueRange=[1e18, 1e23], fn_mask=Model.materialField > stickyAirLayer.index).save( Model.outputDir + '/ViscoSity_ ' + str(Model.time) + '.png') Model.plot.material( figsize=figSize, fn_size=fnSize, fn_mask=Model.materialField > stickyAirLayer.index).save( Model.outputDir + '/Material_ ' + str(Model.time) + '.png') Model.plot.plasticStrain( figsize=figSize, colours='cubelaw2', fn_size=fnSize, fn_mask=Model.materialField > stickyAirLayer.index, valueRange=[ 0, 4 ]).save(Model.outputDir + '/PlasticStrain ' + str(Model.time) + '.png') FigSr = glucifer.Figure( figsize=figSize, quality=3, title="Strain Rate Field 1.0/seconds", boundingBox=((0.0, -0.05), (1.0, 0.075))) fact = GEO.Dimensionalize(1.0, 1. / u.seconds).magnitude FigSr.Points( Model.swarm, Model.strainRateField * fact, logScale=True, figsize=figSize, colours='spectral', valueRange=[1e-18, 1e-13], fn_mask=Model.materialField > stickyAirLayer.index, fn_size=fnSize) FigSr.save(Model.outputDir + '/strainRate ' + str(Model.time) + '.png') return
def melt_fraction(self, figsize=None, title="Melt fraction", cullface=False, script=None, show=True, store=None, visugrid=None, quality=3, **kwargs): self.Model.update_melt_fraction() Fig = glucifer.Figure(store=store, figsize=figsize, quality=quality, min=self._boundingBox[0], max=self._boundingBox[1]) Fig["title"] = title Fig["boundingBox"] = self._boundingBox Fig.Points(self.Model.swarm, fn_colour=self.Model.meltField, cullface=cullface, name=Fig["title"], **kwargs) if visugrid: clip_X, clip_Y = _visugrid_drawing_object(self.Model, visugrid) Fig.Mesh(visugrid.mesh, xmin=clip_X[0], xmax=clip_X[1], ymin=clip_Y[0], ymax=clip_Y[1]) Fig.script(script) if show and glucifer.lavavu.is_notebook(): Fig.show() return Fig
def pressureField(self, figsize=None, title="Pressure Field", units=u.pascal, cullface=False, script=None, show=True, quality=3, store=None, visugrid=None, **kwargs): Fig = glucifer.Figure(store=store, figsize=figsize, quality=quality, min=self._boundingBox[0], max=self._boundingBox[1]) Fig["title"] = title + " " + str(units) Fig["boundingBox"] = self._boundingBox fact = Dimensionalize(1.0, units).magnitude Fig.Surface(self.Model.mesh, self.Model.pressureField * fact, cullface=cullface, **kwargs) if visugrid: clip_X, clip_Y = _visugrid_drawing_object(self.Model, visugrid) Fig.Mesh(visugrid.mesh, xmin=clip_X[0], xmax=clip_X[1], ymin=clip_Y[0], ymax=clip_Y[1]) Fig.script(script) if show and glucifer.lavavu.is_notebook(): Fig.show() return Fig
stokes = uw.systems.Stokes(velocityField=velocityField, pressureField=pressureField, conditions=[ freeslipBC, ], fn_viscosity=fn.misc.constant(1.), fn_bodyforce=buoyancyFn) solver = uw.systems.Solver(stokes) advDiff = uw.systems.AdvectionDiffusion(phiField=temperatureField, phiDotField=temperatureDotField, velocityField=velocityField, fn_diffusivity=fn.misc.constant(1.), conditions=[ tempBC, ]) figtemp = glucifer.Figure() figtemp.append(glucifer.objects.Surface(mesh, temperatureField)) for step in range(int(1e5)): solver.solve(nonLinearIterate=True) dt = advDiff.get_max_dt() advDiff.integrate(dt) if step % 10 == 0: figtemp.save("figtemp.png") meshHandle = mesh.save('mesh256.h5') temperatureField.save('isoviscousRa1e9res256', meshHandle)
# The actual function evaluation. Here the conditional function is evaluated at the location # of each swarm particle. The results are then written to the materialVariable swarm variable. if md.perturb == 0: materialVariable.data[:] = fn.branching.conditional(conditions).evaluate( swarm) else: #in this case just build the asphenosphere materialVariable.data[:] = material1 materialVariable.data[np.where( swarm.particleCoordinates.data[:, 1] < ndp.asthenosphere)] = material2 # In[17]: figMat = glucifer.Figure(figsize=(1200, 400), boundingBox=((-2.0, 0.0, 0.0), (2.0, 1.0, 0.0))) figMat.append(glucifer.objects.Points(swarm, materialVariable, pointSize=2.0)) figMat.append(glucifer.objects.Mesh(mesh)) #figMat.show() # ## Buoyancy forces # # In this example, no buoyancy forces are included in the Stokes system, the Pressures that appear are dynamic (p'). We add the appropriate lithostatic component to the Drucker-Prager yield criterion. # In[18]: lithPressureFn = ndp.rho * (1. - coord[1]) # ## Background Rheology # In[19]:
maskFnVar2.data[:] = plate_id_fn.evaluate(mesh) viscSwarmVar = swarm.add_variable(dataType="double", count=1) viscSwarmVar.data[:] = viscosityMapFn.evaluate(swarm) # In[79]: store1 = glucifer.Store('output/subduction1') store2 = glucifer.Store('output/subduction2') store3 = glucifer.Store('output/subduction3') #these figures are mainly intended for understanding how the interface is controlled, #i.e. through the spatial mask functions #in this figure we'll track the proximity variable figProx = glucifer.Figure(store1, figsize=(960, 300)) figProx.append(glucifer.objects.Points(swarm, proximityVariable)) for f in fCollection: figProx.append(glucifer.objects.Points(f.swarm, pointSize=5)) figVisc = glucifer.Figure(store2, figsize=(960, 300)) figVisc.append(glucifer.objects.Points(swarm, viscSwarmVar, logScale=True)) figMask = glucifer.Figure(store3, figsize=(960, 300)) figMask.append(glucifer.objects.Surface(mesh, maskFnVar1)) figMask.append(glucifer.objects.Surface(mesh, maskFnVar2, valueRange=[0, 3])) #figMask.append( glucifer.objects.Surface(mesh, maskFnVar3) ) for f in fCollection: figMask.append(glucifer.objects.Points(f.swarm, pointSize=5)) # ## Main Loop
#marker.director.data #marker.director.data_shadow #print((allDirector[markerIndexes]).shape) #print(marker.empty) # In[33]: uw.barrier() with mesh.deform_mesh(): mesh.data[nearbyNodesMask] = nodeAdjust # In[47]: fig = glucifer.Figure() #fig= glucifer.Figure(quality=3) fig.append(glucifer.objects.Points(swarm, proximityVariable, pointSize=1.5)) #fig.append( glucifer.objects.Points(fault.swarm, pointSize=3, colourBar=False)) #fig.append( glucifer.objects.Points(marker.swarm, pointSize=3, colourBar=False)) #fig.append( glucifer.objects.Points(markerEvalMantle, pointSize=3, colourBar=False)) #fig.append( glucifer.objects.Points(markerEvalFault, pointSize=3, colourBar=False)) fig.append(glucifer.objects.Mesh(mesh, opacity=0.4)) #fig.append( glucifer.objects.Surface(mesh, fn.math.dot(velocityField, velocityField))) #fig.append( glucifer.objects.Surface(mesh, bcMeshVar)) fig.show() #fig.save_image('proximity.png')
vField.data[top.data] = [-1.0, 0.] vField.data[mySet.data] = [1.0, 0.] # In[6]: vBCs = uw.conditions.DirichletCondition(vField, indexSetsPerDof=(mySet + top, top + base)) # In[7]: store = glucifer.Store('model') # In[8]: fig = glucifer.Figure(store) # In[9]: fig.append(glucifer.objects.VectorArrows(q1_mesh, vField)) # fig.append( glucifer.objects.Mesh(q1_mesh, nodeNumbers=True)) # In[10]: fig.show() # In[11]: stokes = uw.systems.Stokes( vField, pField,
print('finished adding points') # In[15]: #%pylab inline #plt.scatter(testPs[:,0], testPs[:,1]) #plt.scatter(testPs[:,0]*1.1, testPs[:,1]*1.1) # In[16]: print(line.director.data[:, 0]) # In[19]: fig2 = glucifer.Figure() #fig1.append( glucifer.objects.VectorArrows(mesh, velocityField, scaling=.1) ) fig2.append( glucifer.objects.Surface(mesh, 0., colours='red white yellow', colourBar=False)) fig2.append(glucifer.objects.Points(line.swarm, pointsize=5)) #fig1.append( glucifer.objects.Points(refline.swarm, pointsize = 5)) #fig2.append( glucifer.objects.Points(line.swarm, line.director[0], pointsize = 15)) #fig2.show() fig2.save_database('test.gldb') # In[20]:
# In[16]: figPs = Model.plot.plasticStrain( figsize=figSize, colours='cubelaw', fn_size=fnSize, fn_mask=Model.materialField > stickyAirLayer.index, valueRange=[0, 4]) # In[17]: figSr = glucifer.Figure(figsize=figSize, quality=3, title="Strain Rate Field 1.0/seconds", boundingBox=((GEO.nd(Model.minCoord[0]), GEO.nd(Model.minCoord[1])), (GEO.nd(Model.maxCoord[0]), GEO.nd(Model.maxCoord[1])))) figSr.Points(Model.swarm, Model._strainRate_2ndInvariant * GEO.Dimensionalize(1.0, 1. / u.seconds).magnitude, logScale=True, valueRange=[1e-21, 1e-12], fn_mask=Model.materialField > stickyAirLayer.index, fn_size=fnSize) figSr.show() # In[18]:
# Define our perturbation function. Note that it is a function of the x coordinate, # accessed by 'coordinate[0]'. perturbationFn = offset + amplitude*fn.math.cos( k*coordinate[0] ) # Setup the conditions list for the following conditional function. Where the # z coordinate (coordinate[1]) is less than the perturbation, set to lightIndex. conditions = [ ( perturbationFn > coordinate[1] , lightIndex ), ( True , denseIndex ) ] # The actual function evaluation. Here the conditional function is evaluated at the location # of each swarm particle. The results are then written to the materialVariable swarm variable. materialVariable.data[:] = fn.branching.conditional( conditions ).evaluate(swarm) # **Plot the particles by material** fig1 = glucifer.Figure(figsize=(250,250), margin=0) fig1.append( glucifer.objects.Points(swarm, materialVariable, pointSize=2, colourBar=False) ) # Here we set a density of '0.' for the lightMaterial, and '1.' for the heavymaterial. densityMap = { lightIndex:0., denseIndex:1. } densityFn = fn.branching.map( fn_key = materialVariable, mapping = densityMap ) # Here we set a viscosity value of '1.' for both materials. viscosityMap = { lightIndex:eta, denseIndex:1. } viscosityFn = fn.branching.map( fn_key = materialVariable, mapping = viscosityMap ) # Define our vertical unit vector using a python tuple (this will be automatically converted to a function). z_hat = ( 0.0, 1.0 ) # Now create a buoyancy force vector using the density (FEvariable) and the vertical unit vector. buoyancyFn = -densityFn*z_hat
strainrateField = uw.mesh.MeshVariable( mesh=mesh, nodeDofCount=1) srtdata = fn.tensor.second_invariant( fn.tensor.symmetric( velocityField.fn_gradient )) rostfield = srtdata.evaluate(mesh) strainrateField.data[:] = rostfield viscVariable = gSwarm.add_variable( dataType="float", count=1 ) viscVariable.data[:] = viscosityMapFn.evaluate(gSwarm) # In[247]: #Images figEta = glucifer.Figure() figEta.append( glucifer.objects.Points(gSwarm,viscVariable, logScale=True)) figMat = glucifer.Figure() figMat.append( glucifer.objects.Points(gSwarm,materialVariable, colours='brown white blue red')) figMat.append( glucifer.objects.Mesh(mesh)) figStrainRate = glucifer.Figure() figStrainRate.append( glucifer.objects.Surface(mesh, strainRate_2ndInvariant, logScale=True)) figVelocityMag = glucifer.Figure() figVelocityMag.append( glucifer.objects.Surface(mesh, fn.math.dot(velocityField,velocityField)) )
#Checkpoint ################ if step % checkpoint_every == 0: if uw.rank() == 0: checkpoint1(step, checkpointPath, f_o, metric_output) checkpoint2(step, checkpointPath, f_o) f_o = open(os.path.join(outputPath, outputFile), 'a') #is this line supposed to be here? # In[ ]: f_o.close() # In[ ]: figTemp = glucifer.Figure() figTemp.append(glucifer.objects.Surface(mesh, temperatureField)) #figTemp.append( glucifer.objects.Mesh(mesh)) figTemp.append( glucifer.objects.VectorArrows(mesh, velocityField, arrowHead=0.2, scaling=0.05)) #figTemp.save_database('test.gldb') figTemp.show() # In[41]: print(time.clock() - start, realtime)
nodeDs = marker.director[markerIndexes] * signedDists nodeAdjust = mesh.data[nearbyNodesMask] - nodeDs #Hacky test for making sure no node displacements are greater than ds. np.allclose(np.floor(np.linalg.norm(nodeDs / ds, axis=1)), 0.) uw.barrier() with mesh.deform_mesh(): mesh.data[nearbyNodesMask] = nodeAdjust # In[ ]: # In[26]: fig = glucifer.Figure() #fig= glucifer.Figure(quality=3) fig.append(glucifer.objects.Points(swarm, proximityVariable, pointSize=1.5)) #fig.append( glucifer.objects.Points(fault.swarm, pointSize=3, colourBar=False)) #fig.append( glucifer.objects.Points(marker.swarm, pointSize=3, colourBar=False)) #fig.append( glucifer.objects.Points(markerEvalMantle, pointSize=3, colourBar=False)) #fig.append( glucifer.objects.Points(markerEvalFault, pointSize=3, colourBar=False)) fig.append(glucifer.objects.Mesh(mesh, opacity=0.4)) #fig.append( glucifer.objects.Surface(mesh, fn.math.dot(velocityField, velocityField))) #fig.append( glucifer.objects.Surface(mesh, bcMeshVar)) #fig.show() #fig.save_image('proximity.png')
viscField = uw.fevariable.FeVariable(feMesh=linearMesh, nodeDofCount=1) viscdata = viscosityFn2.evaluate(linearMesh) viscField.data[:] = viscdata stressField = uw.fevariable.FeVariable(feMesh=linearMesh, nodeDofCount=1) srtdata = fn.tensor.second_invariant( fn.tensor.symmetric(velocityField.gradientFn)) rostfield = srtdata.evaluate(linearMesh) stressinv = 2 * viscdata * rostfield[:] stressField.data[:] = stressinv ##Gldbs: viscVariable = gSwarm.add_variable(dataType="float", count=1) viscVariable.data[:] = viscosityMapFn.evaluate(gSwarm) figEta = glucifer.Figure() figEta + glucifer.objects.Points( gSwarm, materialVariable, colours='brown white red blue') figEta + glucifer.objects.Points(gSwarm, viscVariable) # Main simulation loop # ======= # # The main time stepping loop begins here. Before this the time and timestep are initialised to zero and the output statistics arrays are set up. Also the frequency of outputting basic statistics to the screen is set in steps_output. # # In[ ]: pics = uw.swarm.PICIntegrationSwarm(gSwarm) # In[ ]: