Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FieldSet checking and kernel compatability #1925

Open
VeckoTheGecko opened this issue Mar 10, 2025 · 1 comment
Open

FieldSet checking and kernel compatability #1925

VeckoTheGecko opened this issue Mar 10, 2025 · 1 comment
Labels

Comments

@VeckoTheGecko
Copy link
Contributor

In main we have check_fieldsets_in_kernels which defines restrictions on the FieldSet. I think that these can be implemented a different way directly via the kernel API in v4.

I propose that we remove check_fieldsets_in_kernels for now and implement this down the line in v4 - using this issue to track discussion.

Code

Parcels/parcels/kernel.py

Lines 320 to 381 in c42ca55

def check_fieldsets_in_kernels(self, pyfunc):
"""
Checks the integrity of the fieldset with the kernels.
This function is to be called from the derived class when setting up the 'pyfunc'.
"""
if self.fieldset is not None:
if pyfunc is AdvectionRK4_3D:
warning = False
if (
isinstance(self._fieldset.W, Field)
and self._fieldset.W._creation_log != "from_nemo"
and self._fieldset.W._scaling_factor is not None
and self._fieldset.W._scaling_factor > 0
):
warning = True
if isinstance(self._fieldset.W, NestedField):
for f in self._fieldset.W:
if f._creation_log != "from_nemo" and f._scaling_factor is not None and f._scaling_factor > 0:
warning = True
if warning:
warnings.warn(
"Note that in AdvectionRK4_3D, vertical velocity is assumed positive towards increasing z. "
"If z increases downward and w is positive upward you can re-orient it downwards by setting fieldset.W.set_scaling_factor(-1.)",
KernelWarning,
stacklevel=2,
)
elif pyfunc is AdvectionAnalytical:
if self.fieldset.particlefile is not None:
self.fieldset.particlefile._is_analytical = True
if self._ptype.uses_jit:
raise NotImplementedError("Analytical Advection only works in Scipy mode")
if self._fieldset.U.interp_method != "cgrid_velocity":
raise NotImplementedError("Analytical Advection only works with C-grids")
if self._fieldset.U.grid._gtype not in [GridType.CurvilinearZGrid, GridType.RectilinearZGrid]:
raise NotImplementedError("Analytical Advection only works with Z-grids in the vertical")
elif pyfunc is AdvectionRK45:
if not hasattr(self.fieldset, "RK45_tol"):
warnings.warn(
"Setting RK45 tolerance to 10 m. Use fieldset.add_constant('RK45_tol', [distance]) to change.",
KernelWarning,
stacklevel=2,
)
self.fieldset.add_constant("RK45_tol", 10)
if self.fieldset.U.grid.mesh == "spherical":
self.fieldset.RK45_tol /= (
1852 * 60
) # TODO does not account for zonal variation in meter -> degree conversion
if not hasattr(self.fieldset, "RK45_min_dt"):
warnings.warn(
"Setting RK45 minimum timestep to 1 s. Use fieldset.add_constant('RK45_min_dt', [timestep]) to change.",
KernelWarning,
stacklevel=2,
)
self.fieldset.add_constant("RK45_min_dt", 1)
if not hasattr(self.fieldset, "RK45_max_dt"):
warnings.warn(
"Setting RK45 maximum timestep to 1 day. Use fieldset.add_constant('RK45_max_dt', [timestep]) to change.",
KernelWarning,
stacklevel=2,
)
self.fieldset.add_constant("RK45_max_dt", 60 * 60 * 24)

@VeckoTheGecko
Copy link
Contributor Author

Hmm, actually this can't really be removed at the moment since it patches the FieldSet. Let's still keep this open so that we can reconsider how its done in v4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Backlog
Status: Backlog
Development

No branches or pull requests

1 participant