File: steam_model.py

package info (click to toggle)
lightyears 1.4-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 1,324 kB
  • ctags: 454
  • sloc: python: 3,499; makefile: 2
file content (72 lines) | stat: -rw-r--r-- 1,870 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 
# 20,000 Light Years Into Space
# This game is licensed under GPL v2, and copyright (C) Jack Whitham 2006-07.
# 

# A model for the movement of steam within the system.


from primitives import *


class Voltage_Model:
    # Don't understand steam? Confused by the thought of
    # boiling water being used as a source of energy?
    # Why not just assume that it's electricity.
    
    def __init__(self):
        # Invariant:
        self.capacitance = 1.0
        # May change:
        self.charge = 0.0
        self.voltage = 0.0
        # Changed by upgrades
        self.capacity = INITIAL_NODE_CAPACITY

    TIME_CONSTANT = 0.1
    NEGLIGIBLE = 0.01

    def Source(self, current):
        dq = current * self.TIME_CONSTANT
        self.charge += dq
        self.__Bound()

    def Think(self, neighbour_list):
        self.voltage = self.charge / self.capacitance
        currents = []

        for (neighbour, resist) in neighbour_list:
            dir = 0
            # Potential difference:
            dv = self.voltage - neighbour.voltage
            if ( dv >= self.NEGLIGIBLE ):
                # Current flow:
                i = dv / resist
                # Charge flow:
                dq = i * self.TIME_CONSTANT
                self.charge -= dq
                neighbour.charge += dq
                currents.append(i)
            else:
                currents.append(0.0)
        self.__Bound()
        return currents
        
    def __Bound(self):    
        if ( self.charge < 0 ):
            self.charge = 0
        elif ( self.charge > self.capacity ):
            self.charge = self.capacity # vent

    def Get_Pressure(self):
        return self.charge

    def Get_Capacity(self):
        return self.capacity

    def Capacity_Upgrade(self):
        self.capacity += CAPACITY_UPGRADE

class Steam_Model(Voltage_Model):
    pass