Solution   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
c 7
b 0
f 0
dl 0
loc 35
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 20 1
A evaluate_solution() 0 2 2
A normalize_residuals() 0 5 2
A evaluate_residual() 0 2 1
1
"""
2
Classes for representing solutions to boundary value problems.
3
4
@author : davidrpugh
5
6
"""
7
8
9
class SolutionLike(object):
10
11
    @property
12
    def basis_kwargs(self):
13
        return self._basis_kwargs
14
15
    @property
16
    def functions(self):
17
        return self._functions
18
19
    @property
20
    def nodes(self):
21
        return self._nodes
22
23
    @property
24
    def problem(self):
25
        return self._problem
26
27
    @property
28
    def residual_function(self):
29
        return self._residual_function
30
31
    @property
32
    def result(self):
33
        return self._result
34
35
36
class Solution(SolutionLike):
37
    """Class representing the solution to a Boundary Value Problem (BVP)."""
38
39
    def __init__(self, basis_kwargs, functions, nodes, problem, residual_function, result):
40
        """
41
        Initialize an instance of the Solution class.
42
43
        Parameters
44
        ----------
45
        basis_kwargs : dict
46
        functions : list
47
        nodes : numpy.ndarray
48
        problem : TwoPointBVPLike
49
        residual_function : callable
50
        result : OptimizeResult
51
52
        """
53
        self._basis_kwargs = basis_kwargs
54
        self._functions = functions
55
        self._nodes = nodes
56
        self._problem = problem
57
        self._residual_function = residual_function
58
        self._result = result
59
60
    def evaluate_residual(self, points):
61
        return self.residual_function(points)
62
63
    def evaluate_solution(self, points):
64
        return [f(points) for f in self.functions]
65
66
    def normalize_residuals(self, points):
67
        """Normalize residuals by the level of the variable."""
68
        residuals = self.evaluate_residual(points)
69
        solutions = self.evaluate_solution(points)
70
        return [resid / soln for resid, soln in zip(residuals, solutions)]
71