@@ -7,6 +7,18 @@ import numbers as _numbers
7
7
8
8
_reactor_counts = _defaultdict(int )
9
9
10
+
11
+ def _unique_name (name , class_type ):
12
+ """ Generate a unique name."""
13
+
14
+ if name is not None :
15
+ return name
16
+ else :
17
+ _reactor_counts[class_type] += 1
18
+ n = _reactor_counts[class_type]
19
+ return ' {0}_{1}' .format(class_type, n)
20
+
21
+
10
22
# Need a pure-python class to store weakrefs to
11
23
class _WeakrefProxy :
12
24
pass
@@ -28,12 +40,7 @@ cdef class ReactorBase:
28
40
if isinstance (contents, ThermoPhase):
29
41
self .insert(contents)
30
42
31
- if name is not None :
32
- self .name = name
33
- else :
34
- _reactor_counts[self .reactor_type] += 1
35
- n = _reactor_counts[self .reactor_type]
36
- self .name = ' {0}_{1}' .format(self .reactor_type, n)
43
+ self .name = _unique_name(name, self .type)
37
44
38
45
if volume is not None :
39
46
self .volume = volume
@@ -419,12 +426,7 @@ cdef class ReactorSurface:
419
426
if A is not None :
420
427
self .area = A
421
428
422
- if name is not None :
423
- self .name = name
424
- else :
425
- _reactor_counts[self .__class__.__name__ ] += 1
426
- n = _reactor_counts[self .__class__.__name__ ]
427
- self .name = ' {0}_{1}' .format(self .__class__.__name__ , n)
429
+ self .name = _unique_name(name, self .type)
428
430
429
431
property type :
430
432
""" The type of the reactor."""
@@ -537,12 +539,7 @@ cdef class WallBase:
537
539
538
540
self ._install(left, right)
539
541
540
- if name is not None :
541
- self .name = name
542
- else :
543
- _reactor_counts[self .__class__.__name__ ] += 1
544
- n = _reactor_counts[self .__class__.__name__ ]
545
- self .name = ' {0}_{1}' .format(self .__class__.__name__ , n)
542
+ self .name = _unique_name(name, self .type)
546
543
547
544
if A is not None :
548
545
self .area = A
@@ -720,12 +717,7 @@ cdef class FlowDevice:
720
717
assert self .dev != NULL
721
718
self ._rate_func = None
722
719
723
- if name is not None :
724
- self .name = name
725
- else :
726
- _reactor_counts[self .__class__.__name__ ] += 1
727
- n = _reactor_counts[self .__class__.__name__ ]
728
- self .name = ' {0}_{1}' .format(self .__class__.__name__ , n)
720
+ self .name = _unique_name(name, self .type)
729
721
730
722
self ._install(upstream, downstream)
731
723
@@ -1062,9 +1054,19 @@ cdef class ReactorNet:
1062
1054
self .net.addReactor(deref(r.reactor))
1063
1055
1064
1056
def to_yaml (self ):
1065
- """ Return a YAML representation of the ReactorNet setup."""
1057
+ """
1058
+ Return a YAML representation of the ReactorNet structure. To
1059
+ print the structure to the terminal, simply call the ReactorNet object.
1060
+ The following two statements are equivalent for the sim object::
1061
+
1062
+ >>> sim()
1063
+ >>> print(sim.to_yaml())
1064
+ """
1066
1065
return pystr(self .net.toYAML())
1067
1066
1067
+ def __call__ (self ):
1068
+ print (self .to_yaml())
1069
+
1068
1070
def advance (self , double t , pybool apply_limit = True ):
1069
1071
"""
1070
1072
Advance the state of the reactor network in time from the current time
0 commit comments