hrkz / torchqg

Quasi-geostrophic spectral solver in PyTorch
MIT License
15 stars 2 forks source link

Units for Output Variables of QG Simulation #1

Closed jejjohnson closed 2 years ago

jejjohnson commented 2 years ago

What are the final units for the saved tensor with the u, v, PV and stream function?

The tensor is stored as steps, Nx, Ny but I can’t figure out what the final units should be from the given parameters. Are they in seconds, km? And any idea for how to calculate them from the given parameters?

hrkz commented 2 years ago

Well, in main.py units are first non-dimensionalized (L 32 - 34) in order to be integrated. At the end of the simulation, all the variables are then unitless.

If you want to use the same dimensionalization, you can use t_unit() and l_unit() to transform them back to something relevant. For velocities in m/s, I believe that taking u * l_unit() / t_unit() should do the job.

jejjohnson commented 2 years ago

Makes sense.

btw: Are there any units for q (PV) and p (stream function)? (I don't know if this is a stupid question or not...)


Below is some demo code for how one would do the conversion. Could you check if I'm correct?

Time Domain (steps): We want it in seconds.

time_unit: float = 1.2e6 # time domain conversion
dt: float = 480. / time_unit # time step
steps: np.ndarray = ...  # unit-less
steps *= time_unit       # unit-less -> seconds
time = steps * dt

Spatial Domain (Nx,Ny): we want it in meters.

space_unit: float = 504e4 / math.pi  # spatial domain conversion
Nx: np.ndarray = ...                 # unit-less
Ny: np.ndarray = ...                 # unit-less
Nx *= space_unit                     # meters
Ny *= space_unit                     # meters

U,V (u,v): we want it in meters per second.

time_unit: float = 1.2e6                # time domain conversion
space_unit: float = 504e4 / math.pi     # spatial domain conversion
vel_unit: float = space_unit / time_unit # velocity unit
u: np.ndarray = ...                     # unit-less
v: np.ndarray = ...                     # unit-less
u *= vel_unit                           # meters/second
v *= vel_unit                           # meters/second
hrkz commented 2 years ago

For vorticity q, the unit is often taken to be radians/s (its a rotating rate), which comes directly by taking the curl of the velocity, i.e. units are (m/m)/s. For streamfunction p, since you have grad(p) = (u, v) with velocities in m/s and dx, dy in m, unit of p should be m^2/s, but I did not find anything on the internet confirming that...


Looks fine to me. Be careful, if you want the total temporal window of integration, it should be steps * dt. Also for velocities, vel_unit is space_unit / time_unit.

jejjohnson commented 2 years ago

Code Example: Awesome! Thanks so much!


Units: So to confirm, are the output variables, q and p, variables are dimensionless as well? And so I would need to do the appropriate unit conversions based on your comments?

hrkz commented 2 years ago

Exactly, q and p are dimensionless and require unit conversions as well!