Skip to content

Commit e765b31

Browse files
committed
#28: More options for test case
1 parent 80d1f23 commit e765b31

File tree

4 files changed

+73
-50
lines changed

4 files changed

+73
-50
lines changed

cmf/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from .stopwatch import StopWatch
2323

2424

25-
__version__ = '1.3.1b'
25+
__version__ = '1.3.1b.i28_numperf_reaches_tracer'
2626

2727
from .cmf_core import connect_cells_with_flux as __ccwf
2828

cmf/cmf_core.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,6 @@ def __len__(self, *args, **kwargs):
15091509
return _cmf_core.timeseries___len__(self, *args, **kwargs)
15101510

15111511

1512-
15131512
def __repr__(self):
15141513
return "cmf.timeseries(%s:%s:%s,count=%i)" % (self.begin,self.end,self.step,self.size())
15151514

@@ -1572,8 +1571,8 @@ def __rdiv__(self,other):
15721571
return res
15731572

15741573
def iter_time(self):
1575-
"""Returns an iterator to iterate over each timestep
1576-
as_float if True, the timesteps will returned as floating point numbers representing the days after 1.1.0001 00:00
1574+
"""
1575+
Returns an iterator to iterate over each timestep
15771576
"""
15781577
for i in range(len(self)):
15791578
yield self.begin + self.step * i
@@ -1607,7 +1606,6 @@ def __setstate__(self, data):
16071606
self.__init__(begin, step, data['interpolationpower'])
16081607
self.extend(data['values'])
16091608

1610-
16111609
def to_pandas(self):
16121610
"""
16131611
Returns the timeseries as a pandas Series object

cmf/cmf_core_src/cmf_wrap.cpp

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,27 +3183,28 @@ SWIG_Python_NonDynamicSetAttr(PyObject *obj, PyObject *name, PyObject *value) {
31833183
#define SWIGTYPE_p_std__shared_ptrT_cmf__river__OpenWaterStorage_t swig_types[171]
31843184
#define SWIGTYPE_p_std__shared_ptrT_cmf__river__Reach_t swig_types[172]
31853185
#define SWIGTYPE_p_std__shared_ptrT_cmf__upslope__ET__ShuttleworthWallace_t swig_types[173]
3186-
#define SWIGTYPE_p_std__shared_ptrT_cmf__upslope__MacroPore_t swig_types[174]
3187-
#define SWIGTYPE_p_std__shared_ptrT_cmf__upslope__SoilLayer_t swig_types[175]
3188-
#define SWIGTYPE_p_std__shared_ptrT_cmf__upslope__SurfaceWater_t swig_types[176]
3189-
#define SWIGTYPE_p_std__shared_ptrT_cmf__upslope__aquifer_t swig_types[177]
3190-
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__DirichletBoundary_t swig_types[178]
3191-
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__NeumannBoundary_t swig_types[179]
3192-
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__SoluteStorage_t swig_types[180]
3193-
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__SystemBridge_t swig_types[181]
3194-
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__WaterStorage_t swig_types[182]
3195-
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__flux_connection_t swig_types[183]
3196-
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__flux_integrator_t swig_types[184]
3197-
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__flux_node_t swig_types[185]
3198-
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__waterbalance_integrator_t swig_types[186]
3199-
#define SWIGTYPE_p_std__shared_ptrT_std__shared_ptrT_cmf__atmosphere__ConstantRainSource_t_t swig_types[187]
3200-
#define SWIGTYPE_p_std__shared_ptrT_std__shared_ptrT_cmf__atmosphere__RainfallStationReference_t_t swig_types[188]
3201-
#define SWIGTYPE_p_std__string swig_types[189]
3202-
#define SWIGTYPE_p_std__vectorT_std__shared_ptrT_cmf__water__WaterStorage_t_t swig_types[190]
3203-
#define SWIGTYPE_p_std__vectorT_std__shared_ptrT_cmf__water__flux_connection_t_t__const_iterator swig_types[191]
3204-
#define SWIGTYPE_p_std__vectorT_std__shared_ptrT_cmf__water__flux_connection_t_t__iterator swig_types[192]
3205-
static swig_type_info *swig_types[194];
3206-
static swig_module_info swig_module = {swig_types, 193, 0, 0, 0, 0};
3186+
#define SWIGTYPE_p_std__shared_ptrT_cmf__upslope__ET__aerodynamic_resistance_t swig_types[174]
3187+
#define SWIGTYPE_p_std__shared_ptrT_cmf__upslope__MacroPore_t swig_types[175]
3188+
#define SWIGTYPE_p_std__shared_ptrT_cmf__upslope__SoilLayer_t swig_types[176]
3189+
#define SWIGTYPE_p_std__shared_ptrT_cmf__upslope__SurfaceWater_t swig_types[177]
3190+
#define SWIGTYPE_p_std__shared_ptrT_cmf__upslope__aquifer_t swig_types[178]
3191+
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__DirichletBoundary_t swig_types[179]
3192+
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__NeumannBoundary_t swig_types[180]
3193+
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__SoluteStorage_t swig_types[181]
3194+
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__SystemBridge_t swig_types[182]
3195+
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__WaterStorage_t swig_types[183]
3196+
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__flux_connection_t swig_types[184]
3197+
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__flux_integrator_t swig_types[185]
3198+
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__flux_node_t swig_types[186]
3199+
#define SWIGTYPE_p_std__shared_ptrT_cmf__water__waterbalance_integrator_t swig_types[187]
3200+
#define SWIGTYPE_p_std__shared_ptrT_std__shared_ptrT_cmf__atmosphere__ConstantRainSource_t_t swig_types[188]
3201+
#define SWIGTYPE_p_std__shared_ptrT_std__shared_ptrT_cmf__atmosphere__RainfallStationReference_t_t swig_types[189]
3202+
#define SWIGTYPE_p_std__string swig_types[190]
3203+
#define SWIGTYPE_p_std__vectorT_std__shared_ptrT_cmf__water__WaterStorage_t_t swig_types[191]
3204+
#define SWIGTYPE_p_std__vectorT_std__shared_ptrT_cmf__water__flux_connection_t_t__const_iterator swig_types[192]
3205+
#define SWIGTYPE_p_std__vectorT_std__shared_ptrT_cmf__water__flux_connection_t_t__iterator swig_types[193]
3206+
static swig_type_info *swig_types[195];
3207+
static swig_module_info swig_module = {swig_types, 194, 0, 0, 0, 0};
32073208
#define SWIG_TypeQuery(name) SWIG_TypeQueryModule(&swig_module, &swig_module, name)
32083209
#define SWIG_MangledTypeQuery(name) SWIG_MangledTypeQueryModule(&swig_module, &swig_module, name)
32093210

@@ -83069,6 +83070,7 @@ static swig_type_info _swigt__p_std__shared_ptrT_cmf__math__integratable_t = {"_
8306983070
static swig_type_info _swigt__p_std__shared_ptrT_cmf__river__OpenWaterStorage_t = {"_p_std__shared_ptrT_cmf__river__OpenWaterStorage_t", "std::shared_ptr< cmf::river::OpenWaterStorage > *", 0, 0, (void*)0, 0};
8307083071
static swig_type_info _swigt__p_std__shared_ptrT_cmf__river__Reach_t = {"_p_std__shared_ptrT_cmf__river__Reach_t", "std::shared_ptr< cmf::river::Reach > *", 0, 0, (void*)0, 0};
8307183072
static swig_type_info _swigt__p_std__shared_ptrT_cmf__upslope__ET__ShuttleworthWallace_t = {"_p_std__shared_ptrT_cmf__upslope__ET__ShuttleworthWallace_t", "std::shared_ptr< cmf::upslope::ET::ShuttleworthWallace > *", 0, 0, (void*)0, 0};
83073+
static swig_type_info _swigt__p_std__shared_ptrT_cmf__upslope__ET__aerodynamic_resistance_t = {"_p_std__shared_ptrT_cmf__upslope__ET__aerodynamic_resistance_t", "std::shared_ptr< cmf::upslope::ET::aerodynamic_resistance > *", 0, 0, (void*)0, 0};
8307283074
static swig_type_info _swigt__p_std__shared_ptrT_cmf__upslope__MacroPore_t = {"_p_std__shared_ptrT_cmf__upslope__MacroPore_t", "std::shared_ptr< cmf::upslope::MacroPore > *", 0, 0, (void*)0, 0};
8307383075
static swig_type_info _swigt__p_std__shared_ptrT_cmf__upslope__SoilLayer_t = {"_p_std__shared_ptrT_cmf__upslope__SoilLayer_t", "cmf::upslope::SoilLayer::ptr *|std::shared_ptr< cmf::upslope::SoilLayer > *", 0, 0, (void*)0, 0};
8307483076
static swig_type_info _swigt__p_std__shared_ptrT_cmf__upslope__SurfaceWater_t = {"_p_std__shared_ptrT_cmf__upslope__SurfaceWater_t", "std::shared_ptr< cmf::upslope::SurfaceWater > *|cmf::upslope::surfacewater_ptr *", 0, 0, (void*)0, 0};
@@ -83264,6 +83266,7 @@ static swig_type_info *swig_type_initial[] = {
8326483266
&_swigt__p_std__shared_ptrT_cmf__river__OpenWaterStorage_t,
8326583267
&_swigt__p_std__shared_ptrT_cmf__river__Reach_t,
8326683268
&_swigt__p_std__shared_ptrT_cmf__upslope__ET__ShuttleworthWallace_t,
83269+
&_swigt__p_std__shared_ptrT_cmf__upslope__ET__aerodynamic_resistance_t,
8326783270
&_swigt__p_std__shared_ptrT_cmf__upslope__MacroPore_t,
8326883271
&_swigt__p_std__shared_ptrT_cmf__upslope__SoilLayer_t,
8326983272
&_swigt__p_std__shared_ptrT_cmf__upslope__SurfaceWater_t,
@@ -83459,6 +83462,7 @@ static swig_cast_info _swigc__p_std__shared_ptrT_cmf__math__integratable_t[] = {
8345983462
static swig_cast_info _swigc__p_std__shared_ptrT_cmf__river__OpenWaterStorage_t[] = { {&_swigt__p_std__shared_ptrT_cmf__river__OpenWaterStorage_t, 0, 0, 0}, {&_swigt__p_std__shared_ptrT_cmf__upslope__SurfaceWater_t, _p_std__shared_ptrT_cmf__upslope__SurfaceWater_tTo_p_std__shared_ptrT_cmf__river__OpenWaterStorage_t, 0, 0}, {&_swigt__p_std__shared_ptrT_cmf__river__Reach_t, _p_std__shared_ptrT_cmf__river__Reach_tTo_p_std__shared_ptrT_cmf__river__OpenWaterStorage_t, 0, 0},{0, 0, 0, 0}};
8346083463
static swig_cast_info _swigc__p_std__shared_ptrT_cmf__river__Reach_t[] = { {&_swigt__p_std__shared_ptrT_cmf__river__Reach_t, 0, 0, 0},{0, 0, 0, 0}};
8346183464
static swig_cast_info _swigc__p_std__shared_ptrT_cmf__upslope__ET__ShuttleworthWallace_t[] = { {&_swigt__p_std__shared_ptrT_cmf__upslope__ET__ShuttleworthWallace_t, 0, 0, 0},{0, 0, 0, 0}};
83465+
static swig_cast_info _swigc__p_std__shared_ptrT_cmf__upslope__ET__aerodynamic_resistance_t[] = { {&_swigt__p_std__shared_ptrT_cmf__upslope__ET__aerodynamic_resistance_t, 0, 0, 0},{0, 0, 0, 0}};
8346283466
static swig_cast_info _swigc__p_std__shared_ptrT_cmf__upslope__MacroPore_t[] = { {&_swigt__p_std__shared_ptrT_cmf__upslope__MacroPore_t, 0, 0, 0},{0, 0, 0, 0}};
8346383467
static swig_cast_info _swigc__p_std__shared_ptrT_cmf__upslope__SoilLayer_t[] = { {&_swigt__p_std__shared_ptrT_cmf__upslope__SoilLayer_t, 0, 0, 0},{0, 0, 0, 0}};
8346483468
static swig_cast_info _swigc__p_std__shared_ptrT_cmf__upslope__SurfaceWater_t[] = { {&_swigt__p_std__shared_ptrT_cmf__upslope__SurfaceWater_t, 0, 0, 0},{0, 0, 0, 0}};
@@ -83654,6 +83658,7 @@ static swig_cast_info *swig_cast_initial[] = {
8365483658
_swigc__p_std__shared_ptrT_cmf__river__OpenWaterStorage_t,
8365583659
_swigc__p_std__shared_ptrT_cmf__river__Reach_t,
8365683660
_swigc__p_std__shared_ptrT_cmf__upslope__ET__ShuttleworthWallace_t,
83661+
_swigc__p_std__shared_ptrT_cmf__upslope__ET__aerodynamic_resistance_t,
8365783662
_swigc__p_std__shared_ptrT_cmf__upslope__MacroPore_t,
8365883663
_swigc__p_std__shared_ptrT_cmf__upslope__SoilLayer_t,
8365983664
_swigc__p_std__shared_ptrT_cmf__upslope__SurfaceWater_t,

demo/runtime_river_substance.py

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
import timeit
88
import argparse
99

10-
def test(d, withsubstance=False, threads=1):
10+
def test(args):
1111
"""
1212
creates a set of river segments with and without substance. the solver
1313
can be set up with a varying nu,ber of threads as well as separated for
1414
water and substance fluxes.
1515
"""
16-
cmf.set_parallel_threads(threads)
17-
18-
if withsubstance:
16+
cmf.set_parallel_threads(args.threads)
17+
d = args.segment_length
18+
if args.tracer:
1919
p = cmf.project("X")
2020
X, = p.solutes
2121
else:
@@ -24,24 +24,41 @@ def test(d, withsubstance=False, threads=1):
2424
# Create a triangular reach crosssection for 10 m long reaches with a bankslope of 2
2525
shape = cmf.TriangularReach(10.,2.)
2626
# Create a 1km river with 100 reaches along the x axis and a constant slope of 1%
27-
reaches = [p.NewReach(i,0,i*.01,shape,False) for i in range(0,1000,d)]
28-
for r_lower, r_upper in zip(reaches[:-1],reaches[1:]):
27+
reaches = [p.NewReach(i, 0, i*.01, shape, False) for i in range(0, 1000, d)]
28+
if args.adsorption:
29+
for r in reaches:
30+
r[X].set_adsorption(cmf.LinearAdsorption(1e-2, 1e-2))
31+
for r_lower, r_upper in zip(reaches[:-1], reaches[1:]):
2932
r_upper.set_downstream(r_lower)
3033
for i, r in enumerate(reaches):
3134
r.Name = 'R{}'.format(i+1)
3235

3336
# Initial condition: 10 cmf of water in the most upper reach
3437
for r in reaches:
3538
r.depth=0.1
36-
if withsubstance:
39+
if args.tracer:
3740
r.conc(X, 1.0)
38-
39-
# Template for the water solver
40-
wsolver = cmf.CVodeIntegrator(1e-9)
41-
# Template for the solute solver
42-
ssolver = cmf.HeunIntegrator()
43-
# Creating the SWI, the storage objects of the project are internally assigned to the correct solver
44-
solver = cmf.SoluteWaterIntegrator(p.solutes, wsolver, ssolver, p)
41+
if args.solver and args.solver != 'c':
42+
# Template for the water solver
43+
wsolver = cmf.CVodeIntegrator(1e-9)
44+
# Template for the solute solver
45+
if args.solver == 'ch':
46+
ssolver = cmf.HeunIntegrator()
47+
print('Heun')
48+
elif args.solver == 'ce':
49+
ssolver = cmf.ExplicitEuler_fixed()
50+
print('Explicit Euler')
51+
elif args.solver == 'ci':
52+
ssolver = cmf.ImplicitEuler(1e-9)
53+
print('Implicit Euler')
54+
else:
55+
ssolver = cmf.CVodeIntegrator(1e-9)
56+
print('CVode')
57+
# Creating the SWI, the storage objects of the project are internally assigned to the correct solver
58+
solver = cmf.SoluteWaterIntegrator(p.solutes, wsolver, ssolver, p)
59+
else:
60+
solver = cmf.CVodeIntegrator(p, 1e-9)
61+
print('Joint CVode solver')
4562
# solver = cmf.CVodeIntegrator(p,1e-6)
4663
assert solver.size() == len(reaches) * (len(p.solutes) + 1)
4764

@@ -50,13 +67,11 @@ def test(d, withsubstance=False, threads=1):
5067

5168
start = time.time()
5269
c = Counter()
53-
for t in solver.run(datetime(2012,1,1),datetime(2012,1,2), cmf.min * 10):
70+
for t in solver.run(datetime(2012, 1, 1),datetime(2012, 1, 2), cmf.min):
5471
# c.update([solver.get_error().argmax()])
55-
print('{:10.3} sec, {}, {}, {}, {:0.4g}'
56-
.format(time.time()-start, t,
57-
solver.dt,0,0 #solver.get_rhsevals(),
58-
#np.abs(solver.get_error()).max()
59-
))
72+
print('{:10.3} sec, {}, {}, {:0.4g}'
73+
.format(time.time()-start, t, solver.dt,
74+
reaches[1][X].conc if X else 0))
6075
depth.append([r.depth for r in reaches])
6176

6277
time_elapsed = time.time() - start
@@ -79,12 +94,17 @@ def test(d, withsubstance=False, threads=1):
7994

8095
parser = argparse.ArgumentParser()
8196
parser.add_argument('segment_length', type=int, help='Length of river segments in m')
82-
parser.add_argument('-X','--tracer', action='store_true', help='Use -x to create a tracer')
83-
parser.add_argument('-t','--threads', action='store', default=1, type=int, help='Number of threads')
97+
parser.add_argument('-X', '--tracer', action='store_true', help='Use -x to create a tracer')
98+
parser.add_argument('-t', '--threads', action='store', default=1, type=int, help='Number of threads')
99+
parser.add_argument('-s', '--solver', choices=['c', 'cc', 'ch', 'ci', 'ce'],
100+
help='Sets the solver: c: Joint CVode, cc: CVode for water and solute, ' + ' ' * 18 +
101+
'ch: CVode / Heun, ci: CVode/Implicit, ce: CVode/Explicit')
102+
parser.add_argument('-e', '--errortolerance', type=float, default=1e-9)
103+
parser.add_argument('-a', '--adsorption', action='store_true', help='Use -a to use linear adsorption')
84104
args = parser.parse_args()
85-
105+
print('cmf', cmf.__version__)
86106
def run():
87-
return test(args.segment_length, args.tracer, args.threads)
107+
return test(args)
88108

89109
t = timeit.Timer(run)
90110

0 commit comments

Comments
 (0)