Skip to content

Commit 5535f03

Browse files
Using JIT croco_from_z_to_sigma() in VectorField too
1 parent 0acf52b commit 5535f03

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

docs/examples/tutorial_croco_3D.ipynb

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

parcels/compilation/codegenerator.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -857,16 +857,18 @@ def visit_VectorFieldEvalNode(self, node):
857857
self.visit(node.field)
858858
self.visit(node.args)
859859
args = self._check_FieldSamplingArguments(node.args.ccode)
860-
statements_croco = []
861860
if "3DSigma" in node.field.obj.vector_type:
862-
statements_croco.append(
863-
c.Assign(
864-
"parcels_interp_state",
865-
f"temporal_interpolation({args[3]}, {args[2]}, 0, time, H, &particles->xi[pnum*ngrid], &particles->yi[pnum*ngrid], &particles->zi[pnum*ngrid], &particles->ti[pnum*ngrid], &{node.var}, LINEAR, {node.field.obj.U.gridindexingtype.upper()})",
866-
)
867-
)
868-
statements_croco.append(c.Statement(f"{node.var4} = {args[1]}/{node.var}"))
861+
# Get Cs_w values directly from fieldset (since they are 1D in vertical only)
862+
Cs_w = [self.fieldset.Cs_w.data[0][zi][0][0] for zi in range(self.fieldset.Cs_w.data.shape[1])]
863+
statements_croco = [
864+
c.Statement(f"float cs_w[] = {*Cs_w, }".replace("(", "{").replace(")", "}")),
865+
c.Statement(
866+
f"{node.var4} = croco_from_z_to_sigma(U, H, Zeta, {args[3]}, {args[2]}, {args[1]}, time, &particles->xi[pnum*ngrid], &particles->yi[pnum*ngrid], &particles->zi[pnum*ngrid], &particles->ti[pnum*ngrid], hc, &cs_w)"
867+
),
868+
]
869869
args = (args[0], node.var4, args[2], args[3])
870+
else:
871+
statements_croco = []
870872
ccode_eval = node.field.obj._ccode_eval(
871873
node.var, node.var2, node.var3, node.field.obj.U, node.field.obj.V, node.field.obj.W, *args
872874
)

0 commit comments

Comments
 (0)