2Test plugin for the ICON Community Interface (ComIn)
4The point_source plugin shows an example for
5- Requesting a tracer that participates in ICON's turbulence and convection scheme
6- Adding point source emissions to this tracer
7- Using KDTree of scipy to locate the point source
8- Use decomp_domain to check if the point source is local to the PE
9- Updating the tracer with tendencies received from ICON's turbulence and convection scheme
11@authors 12/2023 :: ICON Community Interface <comin@icon-model.org>
13SPDX-License-Identifier: BSD-3-Clause
15Please see the file LICENSE in the root of the source tree for this code.
16Where software is supplied by third parties, it is indicated in the
17headers of the routines.
23from scipy.spatial
import KDTree
26comin.var_request_add((
"pntsrc", -1),
False)
37 """Short helper function to print a message on one PE"""
38 if comin.parallel_get_host_mpi_rank() == rank:
39 print(f
"ComIn point_source.py: {message_string}", file=sys.stderr)
44 return clat * np.cos(lon), clat * np.sin(lon), np.sin(lat)
47@comin.register_callback(comin.EP_SECONDARY_CONSTRUCTOR)
49 """Constructor: Get pointers to tracers and descriptive data"""
50 global pntsrc, ddt_pntsrc_turb, ddt_pntsrc_conv
52 entry_points = [comin.EP_ATM_ADVECTION_BEFORE, comin.EP_ATM_PHYSICS_BEFORE]
54 entry_points, (
"pntsrc", jg), comin.COMIN_FLAG_READ | comin.COMIN_FLAG_WRITE
57 entry_points = [comin.EP_ATM_PHYSICS_BEFORE]
59 entry_points, (
"ddt_pntsrc_turb", jg), comin.COMIN_FLAG_READ
62 entry_points, (
"ddt_pntsrc_conv", jg), comin.COMIN_FLAG_READ
65 message(
"pntsrc_constructor successful", msgrank)
68@comin.register_callback(comin.EP_ATM_INIT_FINALIZE)
70 global lcontain_pntsrc, jc_loc, jb_loc
75 clon = np.asarray(domain.cells.clon)
76 clat = np.asarray(domain.cells.clat)
77 xyz = np.c_[
lonlat2xyz(clon.ravel(), clat.ravel())]
78 decomp_domain = np.asarray(domain.cells.decomp_domain)
82 [
lonlat2xyz(np.deg2rad(pntsrc_lon), np.deg2rad(pntsrc_lat))], k=1
85 lcontain_pntsrc =
False
86 if decomp_domain.ravel()[ii] == 0:
89 jc_loc, jb_loc = np.unravel_index(ii, clon.shape)
91 f
"Min at PE {comin.parallel_get_host_mpi_rank()}, clon={np.rad2deg(clon[jc_loc,jb_loc])}, clat={np.rad2deg(clat[jc_loc,jb_loc])}",
92 comin.parallel_get_host_mpi_rank(),
94 lcontain_pntsrc =
True
97@comin.register_callback(comin.EP_ATM_ADVECTION_BEFORE)
99 """Emission for pntsrc on domain 1"""
100 if comin.current_get_domain_id() == jg
and lcontain_pntsrc:
101 pntsrc_np = np.asarray(pntsrc)
102 pntsrc_np[jc_loc, :, jb_loc, 0, 0] = pntsrc_np[jc_loc, :, jb_loc, 0, 0] + 1.0
105@comin.register_callback(comin.EP_ATM_PHYSICS_BEFORE)
107 """Update tracer from turb and conv tendencies for domain 1"""
108 if comin.current_get_domain_id() == jg:
109 pntsrc_np = np.asarray(pntsrc)
110 ddt_pntsrc_turb_np = np.asarray(ddt_pntsrc_turb)
111 ddt_pntsrc_conv_np = np.asarray(ddt_pntsrc_conv)
113 dtime = comin.descrdata_get_timesteplength(jg)
114 pntsrc_np[:, :, :, 0, 0] = np.maximum(
116 pntsrc_np[:, :, :, 0, 0]
119 ddt_pntsrc_turb_np[:, :, :, 0, 0]
120 + ddt_pntsrc_conv_np[:, :, :, 0, 0]
127@comin.register_callback(comin.EP_DESTRUCTOR)
129 message(
"pntsrc_destructor called!", msgrank)
var_get(context, var_descriptor, flag)
get variable object, arguments: [entry point], (name string, domain id), access flag)
metadata_set(var_descriptor, **kwargs)
sets metadata for a requested field, arguments: name string, domain id, metadata key,...
descrdata_get_domain(jg)
returns descriptive data for a given domain, arguments: jg
pntsrc_updatePhysTends()
Update tracer from turb and conv tendencies for domain 1.
pntsrc_constructor()
Constructor: Get pointers to tracers and descriptive data.
pntsrc_emission()
Emission for pntsrc on domain 1.
message(message_string, rank)
Short helper function to print a message on one PE.