• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mbakker7 / ttim / 12312733157

13 Dec 2024 09:08AM UTC coverage: 77.784% (+2.4%) from 75.342%
12312733157

Pull #81

github

web-flow
Merge fcd788ee4 into f9283bd02
Pull Request #81: Add cross-section models

503 of 632 new or added lines in 12 files covered. (79.59%)

42 existing lines in 3 files now uncovered.

3011 of 3871 relevant lines covered (77.78%)

2.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.58
/ttim/stripareasink.py
1
import matplotlib.pyplot as plt
3✔
2
import numpy as np
3✔
3

4
from ttim.element import Element
3✔
5

6

7
class AreaSinkXsection(Element):
3✔
8
    def __init__(
3✔
9
        self,
10
        model,
11
        x1,
12
        x2,
13
        tsandN=[(0.0, 1.0)],
14
        layers=0,
15
        name="StripAreaSinkInhom",
16
        label=None,
17
    ):
18
        super().__init__(
3✔
19
            model,
20
            nparam=1,
21
            nunknowns=0,
22
            layers=layers,
23
            tsandbc=tsandN,
24
            type="g",
25
            name=name,
26
            label=label,
27
            inhomelement=True,
28
        )
29
        self.x1 = float(x1)
3✔
30
        self.x2 = float(x2)
3✔
31
        self.model.addelement(self)
3✔
32

33
    def __repr__(self):
3✔
NEW
34
        return f"{self.__class__.__name__}: " + str([self.x1, self.x2])
×
35

36
    def initialize(self):
3✔
37
        self.xc = (self.x1 + self.x2) / 2.0
3✔
38
        self.L = np.abs(self.x2 - self.x1)
3✔
39
        self.aq = self.model.aq.find_aquifer_data(self.xc, 0.0)
3✔
40
        self.setbc()
3✔
41
        self.setflowcoef()
3✔
42
        self.term = self.flowcoef * self.aq.lab**2 * self.aq.coef[self.layers]
3✔
43
        self.dischargeinf = self.aq.coef[0, :] * self.flowcoef
3✔
44
        self.dischargeinflayers = np.sum(
3✔
45
            self.dischargeinf * self.aq.eigvec[self.layers, :, :], 1
46
        )
47

48
    def setflowcoef(self):
3✔
49
        """Separate function so that this can be overloaded for other types."""
50
        self.flowcoef = 1.0 / self.model.p  # Step function
3✔
51

52
    def potinf(self, x, _, aq=None):
3✔
53
        if aq is None:
3✔
NEW
54
            aq = self.model.aq.find_aquifer_data(x, 0.0)
×
55
        rv = np.zeros((self.nparam, aq.naq, self.model.npval), dtype=complex)
3✔
56
        if aq == self.aq:
3✔
57
            rv[:] = self.term
3✔
58
        return rv
3✔
59

60
    def disvecinf(self, x, _, aq=None):
3✔
61
        if aq is None:
3✔
NEW
62
            aq = self.model.aq.find_aquifer_data(x, 0.0)
×
63
        qx = np.zeros((self.nparam, aq.naq, self.model.npval), dtype=complex)
3✔
64
        qy = np.zeros((self.nparam, aq.naq, self.model.npval), dtype=complex)
3✔
65
        return qx, qy
3✔
66

67
    def plot(self, ax, n_arrows=10, **kwargs):
3✔
NEW
68
        Ly = self.model.aq.z[0] - self.model.aq.z[-1]
×
NEW
69
        Lx = self.x2 - self.x1
×
70

NEW
71
        for i in np.linspace(self.x1, self.x2, n_arrows):
×
NEW
72
            xtail = i
×
NEW
73
            ytail = self.model.aq.z[0] + Ly / 20.0
×
NEW
74
            dx = 0
×
NEW
75
            dy = -0.9 * Ly / 20.0
×
NEW
76
            ax.arrow(
×
77
                xtail,
78
                ytail,
79
                dx,
80
                dy,
81
                width=kwargs.pop("width", Lx / 300.0),
82
                length_includes_head=kwargs.pop("length_includes_head", True),
83
                head_width=kwargs.pop("head_width", 4 * Lx / 300.0),
84
                head_length=kwargs.pop("head_length", 0.4 * Ly / 20.0),
85
                color=kwargs.pop("color", "k"),
86
                joinstyle=kwargs.pop("joinstyle", "miter"),
87
                capstyle=kwargs.pop("capstyle", "projecting"),
88
            )
89

90

91
class HstarXsection(Element):
3✔
92
    def __init__(
3✔
93
        self,
94
        model,
95
        x1,
96
        x2,
97
        tsandhstar=[(0.0, 1.0)],
98
        layers=0,
99
        name="StripHstarInhom",
100
        label=None,
101
    ):
102
        super().__init__(
3✔
103
            model,
104
            nparam=1,
105
            nunknowns=0,
106
            layers=layers,
107
            tsandbc=tsandhstar,
108
            type="g",
109
            name=name,
110
            label=label,
111
            inhomelement=True,
112
        )
113
        self.x1 = float(x1)
3✔
114
        self.x2 = float(x2)
3✔
115
        self.model.addelement(self)
3✔
116

117
    def __repr__(self):
3✔
NEW
118
        return f"{self.__class__.__name__}: " + str([self.x1, self.x2])
×
119

120
    def initialize(self):
3✔
121
        if not np.isfinite(self.x1):
3✔
122
            self.xc = self.x2 - 1e-5
3✔
123
        elif not np.isfinite(self.x2):
3✔
124
            self.xc = self.x1 + 1e-5
3✔
125
        else:
126
            self.xc = (self.x1 + self.x2) / 2.0
3✔
127
        self.L = np.abs(self.x2 - self.x1)
3✔
128
        self.aq = self.model.aq.find_aquifer_data(self.xc, 0.0)
3✔
129
        self.setbc()
3✔
130
        self.setflowcoef()
3✔
131
        self.resfac = 1.0 / self.aq.c[0]
3✔
132
        self.term = (
3✔
133
            self.resfac * self.flowcoef * self.aq.lab**2 * self.aq.coef[self.layers]
134
        )
135
        self.dischargeinf = self.aq.coef[0, :] * self.flowcoef * self.resfac
3✔
136
        self.dischargeinflayers = np.sum(
3✔
137
            self.dischargeinf * self.aq.eigvec[self.layers, :, :], 1
138
        )
139

140
    def setflowcoef(self):
3✔
141
        self.flowcoef = 1.0 / self.model.p
3✔
142

143
    def potinf(self, x, _, aq=None):
3✔
144
        if aq is None:
3✔
NEW
145
            aq = self.model.aq.find_aquifer_data(x, 0.0)
×
146
        rv = np.zeros((self.nparam, aq.naq, self.model.npval), dtype=complex)
3✔
147
        if aq == self.aq:
3✔
148
            rv[:] = self.term
3✔
149
        return rv
3✔
150

151
    def disvecinf(self, x, _, aq=None):
3✔
152
        if aq is None:
3✔
NEW
153
            aq = self.model.aq.find_aquifer_data(x, 0.0)
×
154
        qx = np.zeros((self.nparam, aq.naq, self.model.npval), dtype=complex)
3✔
155
        qy = np.zeros((self.nparam, aq.naq, self.model.npval), dtype=complex)
3✔
156
        return qx, qy
3✔
157

158
    def plot(self, ax=None, hstar=None, **kwargs):
3✔
159
        if ax is None:
3✔
NEW
160
            _, ax = plt.subplots()
×
161
        aq = self.model.aq.find_aquifer_data(self.xc, 0.0)
3✔
162
        ztop = aq.z[0]
3✔
163
        Ly = aq.z[0] - aq.z[-1]
3✔
164
        if hstar is None:
3✔
165
            dy = Ly / 20.0
3✔
166
            zdivider = ztop + 1.1 * dy
3✔
167
        else:
NEW
168
            dy = hstar - ztop
×
NEW
169
            zdivider = hstar + 1
×
170

171
        if np.isfinite(self.x1):
3✔
NEW
172
            x1 = self.x1
×
NEW
173
            ax.plot(
×
174
                [x1, x1],
175
                [ztop, ztop + 1.5 * dy],
176
                color="k",
177
                lw=1.0,
178
                ls="dotted",
179
            )
180
        else:
181
            x1 = ax.get_xlim()[0]
3✔
182

183
        if np.isfinite(self.x2):
3✔
184
            x2 = self.x2
3✔
185
            ax.plot(
3✔
186
                [x2, x2],
187
                [zdivider, aq.z[-1]],
188
                color="k",
189
                lw=1.0,
190
                ls="dotted",
191
            )
192
        else:
NEW
193
            x2 = ax.get_xlim()[1]
×
194

195
        # water level
196
        c = kwargs.pop("color", "b")
3✔
197
        lw = kwargs.pop("lw", 1.0)
3✔
198
        ax.plot([x1, x2], [ztop + dy, ztop + dy], lw=lw, color=c, **kwargs)
3✔
199
        # plot water level symbol: difficult to get consistent, comment out for now
200
        # Lx = x2 - x1
201
        # dx = max(Lx / 200.0, 1)
202
        # xc = (x1 + x2) / 2.0
203
        # ax.plot(
204
        #     [xc - 1.75 * dx, xc + 1.75 * dx],
205
        #     [ztop + dy - 0.5] * 2,
206
        #     lw=0.75 * lw,
207
        #     color=c,
208
        # )
209
        # ax.plot(
210
        #     [xc - dx, xc + dx],
211
        #     [ztop + dy - 1.0] * 2,
212
        #     lw=0.75 * lw,
213
        #     color=c,
214
        # )
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc