Skip to content

Commit 2917b1b

Browse files
authored
Merge branch 'master' into indices_debug
2 parents ba135ee + 1a4251c commit 2917b1b

18 files changed

Lines changed: 286 additions & 251 deletions

parcels/codegenerator.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
from parcels.field import Field, VectorField
2-
from parcels.fieldset import FieldList, VectorFieldList
3-
from parcels.loggers import logger
1+
from parcels.field import Field, VectorField, SummedField, SummedVectorField
2+
from parcels.tools.loggers import logger
43
import ast
54
import cgen as c
65
from collections import OrderedDict
@@ -20,12 +19,12 @@ def __getattr__(self, attr):
2019
if isinstance(getattr(self.obj, attr), Field):
2120
return FieldNode(getattr(self.obj, attr),
2221
ccode="%s->%s" % (self.ccode, attr))
23-
elif isinstance(getattr(self.obj, attr), VectorFieldList):
24-
return VectorFieldListNode(getattr(self.obj, attr),
25-
ccode="%s->%s" % (self.ccode, attr))
26-
elif isinstance(getattr(self.obj, attr), FieldList) or isinstance(getattr(self.obj, attr), list):
27-
return FieldListNode(getattr(self.obj, attr),
28-
ccode="%s->%s" % (self.ccode, attr))
22+
elif isinstance(getattr(self.obj, attr), SummedVectorField):
23+
return SummedVectorFieldNode(getattr(self.obj, attr),
24+
ccode="%s->%s" % (self.ccode, attr))
25+
elif isinstance(getattr(self.obj, attr), SummedField) or isinstance(getattr(self.obj, attr), list):
26+
return SummedFieldNode(getattr(self.obj, attr),
27+
ccode="%s->%s" % (self.ccode, attr))
2928
elif isinstance(getattr(self.obj, attr), VectorField):
3029
return VectorFieldNode(getattr(self.obj, attr),
3130
ccode="%s->%s" % (self.ccode, attr))
@@ -60,24 +59,24 @@ def __init__(self, field, args, var, var2, var3):
6059
self.var3 = var3 # third variable for UVW interpolation
6160

6261

63-
class FieldListNode(IntrinsicNode):
62+
class SummedFieldNode(IntrinsicNode):
6463
def __getitem__(self, attr):
65-
return FieldListEvalNode(self.obj, attr)
64+
return SummedFieldEvalNode(self.obj, attr)
6665

6766

68-
class FieldListEvalNode(IntrinsicNode):
67+
class SummedFieldEvalNode(IntrinsicNode):
6968
def __init__(self, fields, args, var):
7069
self.fields = fields
7170
self.args = args
7271
self.var = var # the variable in which the interpolated field is written
7372

7473

75-
class VectorFieldListNode(IntrinsicNode):
74+
class SummedVectorFieldNode(IntrinsicNode):
7675
def __getitem__(self, attr):
77-
return VectorFieldListEvalNode(self.obj, attr)
76+
return SummedVectorFieldEvalNode(self.obj, attr)
7877

7978

80-
class VectorFieldListEvalNode(IntrinsicNode):
79+
class SummedVectorFieldEvalNode(IntrinsicNode):
8180
def __init__(self, field, args, var, var2, var3):
8281
self.field = field
8382
self.args = args
@@ -210,18 +209,18 @@ def visit_Subscript(self, node):
210209

211210
# If we encounter field evaluation we replace it with a
212211
# temporary variable and put the evaluation call on the stack.
213-
if isinstance(node.value, FieldListNode):
212+
if isinstance(node.value, SummedFieldNode):
214213
tmp = [self.get_tmp() for _ in node.value.obj]
215214
# Insert placeholder node for field eval ...
216-
self.stmt_stack += [FieldListEvalNode(node.value, node.slice, tmp)]
215+
self.stmt_stack += [SummedFieldEvalNode(node.value, node.slice, tmp)]
217216
# .. and return the name of the temporary that will be populated
218217
return ast.Name(id='+'.join(tmp))
219-
elif isinstance(node.value, VectorFieldListNode):
218+
elif isinstance(node.value, SummedVectorFieldNode):
220219
tmp = [self.get_tmp() for _ in node.value.obj.U]
221220
tmp2 = [self.get_tmp() for _ in node.value.obj.U]
222221
tmp3 = [self.get_tmp() if node.value.obj.W else None for _ in node.value.obj.U]
223222
# Insert placeholder node for field eval ...
224-
self.stmt_stack += [VectorFieldListEvalNode(node.value, node.slice, tmp, tmp2, tmp3)]
223+
self.stmt_stack += [SummedVectorFieldEvalNode(node.value, node.slice, tmp, tmp2, tmp3)]
225224
# .. and return the name of the temporary that will be populated
226225
if all(tmp3):
227226
return ast.Tuple([ast.Name(id='+'.join(tmp)), ast.Name(id='+'.join(tmp2)), ast.Name(id='+'.join(tmp3))], ast.Load())
@@ -621,7 +620,7 @@ def visit_FieldNode(self, node):
621620
"""Record intrinsic fields used in kernel"""
622621
self.field_args[node.obj.name] = node.obj
623622

624-
def visit_FieldListNode(self, node):
623+
def visit_SummedFieldNode(self, node):
625624
"""Record intrinsic fields used in kernel"""
626625
for fld in node.obj:
627626
self.field_args[fld.name] = fld
@@ -630,7 +629,7 @@ def visit_VectorFieldNode(self, node):
630629
"""Record intrinsic fields used in kernel"""
631630
self.vector_field_args[node.obj.name] = node.obj
632631

633-
def visit_VectorFieldListNode(self, node):
632+
def visit_SummedVectorFieldNode(self, node):
634633
"""Record intrinsic fields used in kernel"""
635634
for fld in node.obj.U:
636635
self.field_args[fld.name] = fld
@@ -672,7 +671,7 @@ def visit_VectorFieldEvalNode(self, node):
672671
node.ccode = c.Block([c.Assign("err", ccode_eval),
673672
conv_stat, c.Statement("CHECKERROR(err)")])
674673

675-
def visit_FieldListEvalNode(self, node):
674+
def visit_SummedFieldEvalNode(self, node):
676675
self.visit(node.fields)
677676
self.visit(node.args)
678677
cstat = []
@@ -683,7 +682,7 @@ def visit_FieldListEvalNode(self, node):
683682
cstat += [c.Assign("err", ccode_eval), conv_stat, c.Statement("CHECKERROR(err)")]
684683
node.ccode = c.Block(cstat)
685684

686-
def visit_VectorFieldListEvalNode(self, node):
685+
def visit_SummedVectorFieldEvalNode(self, node):
687686
self.visit(node.field)
688687
self.visit(node.args)
689688
cstat = []

parcels/examples/tutorial_FieldLists.ipynb renamed to parcels/examples/tutorial_SummedFields.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"cell_type": "markdown",
55
"metadata": {},
66
"source": [
7-
"## Tutorial on how to combine different Fields for advection into a `FieldList` object"
7+
"## Tutorial on how to combine different Fields for advection into a `SummedField` object"
88
]
99
},
1010
{
@@ -13,9 +13,9 @@
1313
"source": [
1414
"In some oceanographic applications, you may want to advect particles using a combination of different velocity data sets. For example, particles at the surface are transported by a combination of geostrophic, Ekman and Stokes flow. And often, these flows are not even on the same grid.\n",
1515
"\n",
16-
"One option would be to write a `Kernel` that computes the movement of particles due to each of these flows. However, in Parcels it is possible to directly combine different flows (without interpolation) and feed them into the built-in `AdvectionRK4` kernel. For that, we use so-called `FieldList` objects.\n",
16+
"One option would be to write a `Kernel` that computes the movement of particles due to each of these flows. However, in Parcels it is possible to directly combine different flows (without interpolation) and feed them into the built-in `AdvectionRK4` kernel. For that, we use so-called `SummedField` objects.\n",
1717
"\n",
18-
"This tutorial shows how to use these `FieldLists` with a very idealised example. We start by importing the relevant modules."
18+
"This tutorial shows how to use these `SummedField` with a very idealised example. We start by importing the relevant modules."
1919
]
2020
},
2121
{
@@ -123,7 +123,7 @@
123123
"cell_type": "markdown",
124124
"metadata": {},
125125
"source": [
126-
"Now comes the trick of the `FieldLists`. We can simply define a new `FieldSet` with a list of different `Fields`, as in `U=[U, Ustokes]`."
126+
"Now comes the trick of the `SummedFields`. We can simply define a new `FieldSet` with a summation of different `Fields`, as in `U=U+Ustokes`."
127127
]
128128
},
129129
{
@@ -132,7 +132,7 @@
132132
"metadata": {},
133133
"outputs": [],
134134
"source": [
135-
"fieldset = FieldSet(U=[U, Ustokes], V=[V, Vstokes])"
135+
"fieldset = FieldSet(U=U+Ustokes, V=V+Vstokes)"
136136
]
137137
},
138138
{
@@ -177,9 +177,9 @@
177177
"cell_type": "markdown",
178178
"metadata": {},
179179
"source": [
180-
"What happens under the hood is that each `Field` in the `FieldList` is interpolated separately to the particle location, and that the different velocities are added in each step of the RK4 advection. So `FieldLists` are effortless to users\n",
180+
"What happens under the hood is that each `Field` in the `SummedField` is interpolated separately to the particle location, and that the different velocities are added in each step of the RK4 advection. So `SummedFields` are effortless to users\n",
181181
"\n",
182-
"Note that `FieldLists` work for any type of `Field`, not only for velocities. Any call to a `Field` interpolation (`fieldset.fld[time, lon, lat, depth]`) will return the sum of all `Fields` in the list if `fld` is a `FieldList`."
182+
"Note that `SummedFields` work for any type of `Field`, not only for velocities. Any call to a `Field` interpolation (`fieldset.fld[time, lon, lat, depth]`) will return the sum of all `Fields` in the list if `fld` is a `SummedField`."
183183
]
184184
},
185185
{
@@ -206,7 +206,7 @@
206206
"name": "python",
207207
"nbconvert_exporter": "python",
208208
"pygments_lexer": "ipython2",
209-
"version": "2.7.15"
209+
"version": "2.7.14"
210210
}
211211
},
212212
"nbformat": 4,

0 commit comments

Comments
 (0)