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

TRI-AMDD / mpet / 8476080312

29 Mar 2024 01:46AM UTC coverage: 55.461% (-7.2%) from 62.648%
8476080312

Pull #126

github

d-cogswell
Adds a benchmark section to docs.
Pull Request #126: v1.0.0

2351 of 4239 relevant lines covered (55.46%)

2.22 hits per line

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

52.63
/mpet/extern_funcs.py
1
"""Functions used in the simulation which cannot be represented by simple analytical functions.
2

3
These functions are handled here because they cannot be written in a form that DAE Tools knows how
4
to automatically differentiate. For example, they may contain `if` statements or a function from an
5
external library that the DAE Tools library doesn't know about.
6
"""
7
import scipy.interpolate as sintrp
4✔
8

9
from daetools.pyDAE import daeScalarExternalFunction, adouble
4✔
10

11

12
class InterpTimeScalar(daeScalarExternalFunction):
4✔
13
    def __init__(self, Name, Model, units, time, tvec, yvec):
4✔
14
        arguments = {}
4✔
15
        arguments["time"] = time
4✔
16
        self.cache = None
4✔
17
        self.interp = sintrp.interp1d(tvec, yvec, bounds_error=False,
4✔
18
                                      fill_value=yvec[-1])
19
        daeScalarExternalFunction.__init__(self, Name, Model, units, arguments)
4✔
20

21
    def Calculate(self, values):
4✔
22
        time = values["time"]
×
23
        # A derivative for Jacobian is requested - always return 0.0
24
        if time.Derivative != 0:
×
25
            return adouble(0)
×
26
        # Store the previous time value to prevent excessive
27
        # interpolation.
28
        if self.cache:
×
29
            if self.cache[0] == time.Value:
×
30
                return adouble(float(self.cache[1]))
×
31
        yval = float(self.interp(time.Value))
×
32
        self.cache = (time.Value, yval)
×
33
        return adouble(yval)
×
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