Giter Site home page Giter Site logo

Comments (4)

danshapero avatar danshapero commented on September 25, 2024

Hi Bryan! The code in that notebook to compute u_shear isn't evaluating the basal velocity as such, but rather the projection of the velocity field onto the 1st-degree Legendre polynomial, which is orthogonal to the constant functions. So it is to be expected that the basal velocity (or the surface - basal difference) is not the same as this projection.

The code that you've written certainly ought to work to compute the basal velocity. If you want something that will make a Function defined on the base mesh instead of a grid of values, you can also do this by a clever weighted depth-average. Let me know if that's what you need and I'll send some more complete code for it.

from icepack.

bryanvriel avatar bryanvriel commented on September 25, 2024

Ah, thanks Daniel for clearing that up! The projection makes sense. Indeed, I think I could make use of a few examples of clever depth-average weighting. I was originally thinking of constructing delta functions centered at arbitrary depths, but I'm pretty sure I would've done that wrong!

from icepack.

danshapero avatar danshapero commented on September 25, 2024

I made a branch with some demonstrations in the hybrid XZ notebook here. The important part is right before the conclusion section. In case you don't want to go digging through all that, here's the code to calculate the basal and surface velocities and plot them:

import sympy

ξ = sympy.symbols("ξ", real=True)
legendre_polynomials = [sympy.legendre(n, 2 * ξ - 1) for n in range(3)]
basis_functions = [p / sympy.sqrt(sympy.integrate(p**2, (ξ, 0, 1))) for p in legendre_polynomials]
basal_values = [p.subs({ξ: 0}) for p in basis_functions]
surface_values = [p.subs({ξ: 1}) for p in basis_functions]
basal_polynomial = sum(w * p for w, p in zip(basal_values, basis_functions))
surface_polynomial = sum(w * p for w, p in zip(surface_values, basis_functions))
basal_weight = sympy.lambdify(ξ, basal_polynomial.simplify())(ζ)
surface_weight = sympy.lambdify(ξ, surface_polynomial.simplify())(ζ)
u_basal = icepack.depth_average(u, weight=basal_weight)
u_surface = icepack.depth_average(u, weight=surface_weight)

fig, axes = plt.subplots()
axes.set_title("Surface & basal velocities")
firedrake.plot(u_basal, edgecolor="tab:blue", label="basal", axes=axes)
firedrake.plot(u_surface, edgecolor="tab:red", label="surface", axes=axes)
axes.legend();

Does all the sympy + Legendre polynomial hackery here make sense? You mentioned constructing delta functions at arbitrary depths. This code is doing that by instead looking at the action of a delta function on something that we know has an expansion in Legendre polynomials. So it does what a delta function would do without having to actually form the delta function as such. In any case this should be probably either be in a tutorial or in icepack itself. The attached figure shows the result.

surface-basal-velocities

I am a little disturbed by the fact that you can evaluate things at negative values of the vertical coordinate -- arguably those should be giving a "point not in domain" error. That's more of a Firedrake issue than an icepack issue.

Closing this for now, feel free to reopen if anything else is unclear.

from icepack.

bryanvriel avatar bryanvriel commented on September 25, 2024

Many thanks Daniel, I think I understand now how the weights are interpreted with respect to a Legendre polynomial expansion. That's quite clever!

Yeah, I'm not too worried now about the out-of-domain evaluations. Perhaps firedrake is assuming that the user knows the vertical mesh is represented by a polynomial expansion and can thus technically be evaluated out of the domain. I'll just make sure never to do that.

from icepack.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.