Unverified Commit 1063926f authored by Boris Bonev's avatar Boris Bonev Committed by GitHub
Browse files

changing defuault grid to equiangular in all SHT routines for consistency (#59)

parent 663bea1f
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
## Versioning ## Versioning
### v0.7.3
* Changing default grid in all SHT routines to `equiangular`
### v0.7.2 ### v0.7.2
* Added resampling modules for convenience * Added resampling modules for convenience
......
...@@ -53,7 +53,7 @@ class DistributedRealSHT(nn.Module): ...@@ -53,7 +53,7 @@ class DistributedRealSHT(nn.Module):
[2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math. [2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math.
""" """
def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="lobatto", norm="ortho", csphase=True): def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="equiangular", norm="ortho", csphase=True):
""" """
Distribtued SHT layer. Expects the last 3 dimensions of the input tensor to be channels, latitude, longitude. Distribtued SHT layer. Expects the last 3 dimensions of the input tensor to be channels, latitude, longitude.
...@@ -178,7 +178,7 @@ class DistributedInverseRealSHT(nn.Module): ...@@ -178,7 +178,7 @@ class DistributedInverseRealSHT(nn.Module):
[2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math. [2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math.
""" """
def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="lobatto", norm="ortho", csphase=True): def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="equiangular", norm="ortho", csphase=True):
super().__init__() super().__init__()
...@@ -288,7 +288,7 @@ class DistributedRealVectorSHT(nn.Module): ...@@ -288,7 +288,7 @@ class DistributedRealVectorSHT(nn.Module):
[2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math. [2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math.
""" """
def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="lobatto", norm="ortho", csphase=True): def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="equiangular", norm="ortho", csphase=True):
""" """
Initializes the vector SHT Layer, precomputing the necessary quadrature weights Initializes the vector SHT Layer, precomputing the necessary quadrature weights
...@@ -432,7 +432,7 @@ class DistributedInverseRealVectorSHT(nn.Module): ...@@ -432,7 +432,7 @@ class DistributedInverseRealVectorSHT(nn.Module):
[1] Schaeffer, N. Efficient spherical harmonic transforms aimed at pseudospectral numerical simulations, G3: Geochemistry, Geophysics, Geosystems. [1] Schaeffer, N. Efficient spherical harmonic transforms aimed at pseudospectral numerical simulations, G3: Geochemistry, Geophysics, Geosystems.
[2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math. [2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math.
""" """
def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="lobatto", norm="ortho", csphase=True): def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="equiangular", norm="ortho", csphase=True):
super().__init__() super().__init__()
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 The torch-harmonics Authors. All rights reserved. # SPDX-FileCopyrightText: Copyright (c) 2022 The torch-harmonics Authors. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
# #
...@@ -43,7 +43,7 @@ class SphereSolver(nn.Module): ...@@ -43,7 +43,7 @@ class SphereSolver(nn.Module):
- Allen-Cahn eq - Allen-Cahn eq
""" """
def __init__(self, nlat, nlon, dt, lmax=None, mmax=None, grid='legendre-gauss', radius=1.0, coeff=0.001): def __init__(self, nlat, nlon, dt, lmax=None, mmax=None, grid="equiangular", radius=1.0, coeff=0.001):
super().__init__() super().__init__()
# time stepping param # time stepping param
...@@ -96,7 +96,7 @@ class SphereSolver(nn.Module): ...@@ -96,7 +96,7 @@ class SphereSolver(nn.Module):
def grid2spec(self, u): def grid2spec(self, u):
"""spectral coefficients from spatial data""" """spectral coefficients from spatial data"""
return self.sht(u) return self.sht(u)
def spec2grid(self, uspec): def spec2grid(self, uspec):
...@@ -116,7 +116,7 @@ class SphereSolver(nn.Module): ...@@ -116,7 +116,7 @@ class SphereSolver(nn.Module):
dudtspec = uspec + (1. + 2.j)*self.coeff*self.lap*uspec - (1. + 2.j)*u3spec dudtspec = uspec + (1. + 2.j)*self.coeff*self.lap*uspec - (1. + 2.j)*u3spec
else: else:
NotImplementedError NotImplementedError
return dudtspec return dudtspec
def randspec(self): def randspec(self):
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 The torch-harmonics Authors. All rights reserved. # SPDX-FileCopyrightText: Copyright (c) 2022 The torch-harmonics Authors. All rights reserved.
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met: # modification, are permitted provided that the following conditions are met:
# #
...@@ -43,7 +43,7 @@ class ShallowWaterSolver(nn.Module): ...@@ -43,7 +43,7 @@ class ShallowWaterSolver(nn.Module):
SWE solver class. Interface inspired bu pyspharm and SHTns SWE solver class. Interface inspired bu pyspharm and SHTns
""" """
def __init__(self, nlat, nlon, dt, lmax=None, mmax=None, grid='legendre-gauss', radius=6.37122E6, \ def __init__(self, nlat, nlon, dt, lmax=None, mmax=None, grid="equiangular", radius=6.37122E6, \
omega=7.292E-5, gravity=9.80616, havg=10.e3, hamp=120.): omega=7.292E-5, gravity=9.80616, havg=10.e3, hamp=120.):
super().__init__() super().__init__()
...@@ -249,7 +249,7 @@ class ShallowWaterSolver(nn.Module): ...@@ -249,7 +249,7 @@ class ShallowWaterSolver(nn.Module):
# initial geopotential # initial geopotential
uspec = torch.zeros(3, self.lmax, self.mmax, dtype=ctype, device=self.lap.device) uspec = torch.zeros(3, self.lmax, self.mmax, dtype=ctype, device=self.lap.device)
uspec[:, :llimit, :mlimit] = torch.sqrt(torch.tensor(4 * torch.pi / llimit / (llimit+1), device=device, dtype=ctype)) * torch.randn_like(uspec[:, :llimit, :mlimit]) uspec[:, :llimit, :mlimit] = torch.sqrt(torch.tensor(4 * torch.pi / llimit / (llimit+1), device=device, dtype=ctype)) * torch.randn_like(uspec[:, :llimit, :mlimit])
uspec[0] = self.gravity * self.hamp * uspec[0] uspec[0] = self.gravity * self.hamp * uspec[0]
uspec[0, 0, 0] += torch.sqrt(torch.tensor(4 * torch.pi, device=device, dtype=ctype)) * self.havg * self.gravity uspec[0, 0, 0] += torch.sqrt(torch.tensor(4 * torch.pi, device=device, dtype=ctype)) * self.havg * self.gravity
uspec[1:] = mach * uspec[1:] * torch.sqrt(self.gravity * self.havg) / self.radius uspec[1:] = mach * uspec[1:] * torch.sqrt(self.gravity * self.havg) / self.radius
...@@ -276,7 +276,7 @@ class ShallowWaterSolver(nn.Module): ...@@ -276,7 +276,7 @@ class ShallowWaterSolver(nn.Module):
# uspec = torch.zeros(3, self.lmax, self.mmax, dtype=phispec.dtype, device=device) # uspec = torch.zeros(3, self.lmax, self.mmax, dtype=phispec.dtype, device=device)
# uspec[0] = phispec # uspec[0] = phispec
# uspec[1:] = vrtdivspec # uspec[1:] = vrtdivspec
return torch.tril(uspec) return torch.tril(uspec)
def timestep(self, uspec: torch.Tensor, nsteps: int) -> torch.Tensor: def timestep(self, uspec: torch.Tensor, nsteps: int) -> torch.Tensor:
...@@ -293,7 +293,7 @@ class ShallowWaterSolver(nn.Module): ...@@ -293,7 +293,7 @@ class ShallowWaterSolver(nn.Module):
for iter in range(nsteps): for iter in range(nsteps):
dudtspec[inew] = self.dudtspec(uspec) dudtspec[inew] = self.dudtspec(uspec)
# update vort,div,phiv with third-order adams-bashforth. # update vort,div,phiv with third-order adams-bashforth.
# forward euler, then 2nd-order adams-bashforth time steps to start. # forward euler, then 2nd-order adams-bashforth time steps to start.
if iter == 0: if iter == 0:
...@@ -311,11 +311,11 @@ class ShallowWaterSolver(nn.Module): ...@@ -311,11 +311,11 @@ class ShallowWaterSolver(nn.Module):
inew = (inew - 1) % 3 inew = (inew - 1) % 3
inow = (inow - 1) % 3 inow = (inow - 1) % 3
iold = (iold - 1) % 3 iold = (iold - 1) % 3
return uspec return uspec
def integrate_grid(self, ugrid, dimensionless=False, polar_opt=0): def integrate_grid(self, ugrid, dimensionless=False, polar_opt=0):
dlon = 2 * torch.pi / self.nlon dlon = 2 * torch.pi / self.nlon
radius = 1 if dimensionless else self.radius radius = 1 if dimensionless else self.radius
if polar_opt > 0: if polar_opt > 0:
out = torch.sum(ugrid[..., polar_opt:-polar_opt, :] * self.quad_weights[polar_opt:-polar_opt] * dlon * radius**2, dim=(-2, -1)) out = torch.sum(ugrid[..., polar_opt:-polar_opt, :] * self.quad_weights[polar_opt:-polar_opt] * dlon * radius**2, dim=(-2, -1))
......
...@@ -48,7 +48,7 @@ class RealSHT(nn.Module): ...@@ -48,7 +48,7 @@ class RealSHT(nn.Module):
[2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math. [2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math.
""" """
def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="lobatto", norm="ortho", csphase=True): def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="equiangular", norm="ortho", csphase=True):
r""" r"""
Initializes the SHT Layer, precomputing the necessary quadrature weights Initializes the SHT Layer, precomputing the necessary quadrature weights
...@@ -141,7 +141,7 @@ class InverseRealSHT(nn.Module): ...@@ -141,7 +141,7 @@ class InverseRealSHT(nn.Module):
[2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math. [2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math.
""" """
def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="lobatto", norm="ortho", csphase=True): def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="equiangular", norm="ortho", csphase=True):
super().__init__() super().__init__()
...@@ -214,7 +214,7 @@ class RealVectorSHT(nn.Module): ...@@ -214,7 +214,7 @@ class RealVectorSHT(nn.Module):
[2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math. [2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math.
""" """
def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="lobatto", norm="ortho", csphase=True): def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="equiangular", norm="ortho", csphase=True):
r""" r"""
Initializes the vector SHT Layer, precomputing the necessary quadrature weights Initializes the vector SHT Layer, precomputing the necessary quadrature weights
...@@ -321,7 +321,7 @@ class InverseRealVectorSHT(nn.Module): ...@@ -321,7 +321,7 @@ class InverseRealVectorSHT(nn.Module):
[1] Schaeffer, N. Efficient spherical harmonic transforms aimed at pseudospectral numerical simulations, G3: Geochemistry, Geophysics, Geosystems. [1] Schaeffer, N. Efficient spherical harmonic transforms aimed at pseudospectral numerical simulations, G3: Geochemistry, Geophysics, Geosystems.
[2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math. [2] Wang, B., Wang, L., Xie, Z.; Accurate calculation of spherical and vector spherical harmonic expansions via spectral element grids; Adv Comput Math.
""" """
def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="lobatto", norm="ortho", csphase=True): def __init__(self, nlat, nlon, lmax=None, mmax=None, grid="equiangular", norm="ortho", csphase=True):
super().__init__() super().__init__()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment