Skip to content

Commit

Permalink
#709 some more test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Jan 31, 2020
1 parent 824283f commit a19a389
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 275 deletions.
32 changes: 9 additions & 23 deletions examples/notebooks/compare-comsol-discharge-curve.ipynb

Large diffs are not rendered by default.

152 changes: 52 additions & 100 deletions examples/notebooks/models/compare-lithium-ion.ipynb

Large diffs are not rendered by default.

107 changes: 45 additions & 62 deletions examples/notebooks/parameter-values.ipynb

Large diffs are not rendered by default.

131 changes: 43 additions & 88 deletions examples/notebooks/spatial_methods/finite-volumes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -615,19 +615,7 @@
" ├── @\n",
" │ ├── Sparse Matrix (42, 40)\n",
" │ └── y[0:40]\n",
" └── numpy concatenation\n",
" ├── Column vector of length 0\n",
" ├── *\n",
" │ ├── *\n",
" │ │ ├── 2.0\n",
" │ │ └── 1.0\n",
" │ └── Column vector of length 1\n",
" ├── Column vector of length 40\n",
" └── *\n",
" ├── *\n",
" │ ├── 2.0\n",
" │ └── 2.0\n",
" └── Column vector of length 1\n",
" └── Column vector of length 42\n",
"The value of u on the left-hand boundary is [1.]\n",
"The value of u on the right-hand boundary is [2.]\n"
]
Expand Down Expand Up @@ -663,25 +651,13 @@
"output_type": "stream",
"text": [
"The gradient object is:\n",
"@\n",
"├── Sparse Matrix (41, 42)\n",
"└── +\n",
" ├── @\n",
" │ ├── Sparse Matrix (42, 40)\n",
" │ └── y[0:40]\n",
" └── numpy concatenation\n",
" ├── Column vector of length 0\n",
" ├── *\n",
" │ ├── *\n",
" │ │ ├── -0.024999999999999998\n",
" │ │ └── 3.0\n",
" │ └── Column vector of length 1\n",
" ├── Column vector of length 40\n",
" └── *\n",
" ├── *\n",
" │ ├── 0.02499999999999991\n",
" │ └── 4.0\n",
" └── Column vector of length 1\n",
"+\n",
"├── @\n",
"│ ├── Sparse Matrix (41, 39)\n",
"│ └── @\n",
"│ ├── Sparse Matrix (39, 40)\n",
"│ └── y[0:40]\n",
"└── Column vector of length 41\n",
"The gradient on the left-hand boundary is [3.]\n",
"The gradient of u on the right-hand boundary is [4.]\n"
]
Expand Down Expand Up @@ -714,26 +690,18 @@
"output_type": "stream",
"text": [
"The gradient object is:\n",
"@\n",
"├── Sparse Matrix (41, 42)\n",
"└── +\n",
" ├── @\n",
" │ ├── Sparse Matrix (42, 40)\n",
" │ └── y[0:40]\n",
" └── numpy concatenation\n",
" ├── Column vector of length 0\n",
" ├── *\n",
" │ ├── *\n",
" │ │ ├── 2.0\n",
" │ │ └── 5.0\n",
" │ └── Column vector of length 1\n",
" ├── Column vector of length 40\n",
" └── *\n",
" ├── *\n",
" │ ├── 0.02499999999999991\n",
" │ └── 6.0\n",
" └── Column vector of length 1\n",
"The value of u on the left-hand boundary is [5.]\n",
"+\n",
"├── @\n",
"│ ├── Sparse Matrix (41, 40)\n",
"│ └── @\n",
"│ ├── Sparse Matrix (40, 41)\n",
"│ └── +\n",
"│ ├── @\n",
"│ │ ├── Sparse Matrix (41, 40)\n",
"│ │ └── y[0:40]\n",
"│ └── Column vector of length 41\n",
"└── Column vector of length 41\n",
"The value of u on the left-hand boundary is [0.]\n",
"The gradient on the right-hand boundary is [6.]\n"
]
}
Expand Down Expand Up @@ -797,25 +765,13 @@
"text": [
"@\n",
"├── Sparse Matrix (40, 41)\n",
"└── @\n",
" ├── Sparse Matrix (41, 42)\n",
" └── +\n",
" ├── @\n",
" │ ├── Sparse Matrix (42, 40)\n",
" │ └── y[0:40]\n",
" └── numpy concatenation\n",
" ├── Column vector of length 0\n",
" ├── *\n",
" │ ├── *\n",
" │ │ ├── -0.024999999999999998\n",
" │ │ └── -1.0\n",
" │ └── Column vector of length 1\n",
" ├── Column vector of length 40\n",
" └── *\n",
" ├── *\n",
" │ ├── 0.02499999999999991\n",
" │ └── 1.0\n",
" └── Column vector of length 1\n"
"└── +\n",
" ├── @\n",
" │ ├── Sparse Matrix (41, 39)\n",
" │ └── @\n",
" │ ├── Sparse Matrix (39, 40)\n",
" │ └── y[0:40]\n",
" └── Column vector of length 41\n"
]
}
],
Expand Down Expand Up @@ -878,11 +834,11 @@
"output_type": "stream",
"text": [
"@\n",
"├── Sparse Matrix (40, 42)\n",
"├── Sparse Matrix (40, 41)\n",
"└── +\n",
" ├── Column vector of length 42\n",
" ├── Column vector of length 41\n",
" └── @\n",
" ├── Sparse Matrix (42, 40)\n",
" ├── Sparse Matrix (41, 40)\n",
" └── y[0:40]\n"
]
}
Expand All @@ -904,13 +860,13 @@
"laplacian matrix is:\n",
"\n",
"1/dx^2 *\n",
"[[ 1. -2. 1. ... 0. 0. 0.]\n",
" [ 0. 1. -2. ... 0. 0. 0.]\n",
" [ 0. 0. 1. ... 0. 0. 0.]\n",
"[[-0.025 0.025 0. ... 0. 0. 0. ]\n",
" [ 0. -0.025 0.025 ... 0. 0. 0. ]\n",
" [ 0. 0. -0.025 ... 0. 0. 0. ]\n",
" ...\n",
" [ 0. 0. 0. ... 1. 0. 0.]\n",
" [ 0. 0. 0. ... -2. 1. 0.]\n",
" [ 0. 0. 0. ... 1. -2. 1.]]\n"
" [ 0. 0. 0. ... 0.025 0. 0. ]\n",
" [ 0. 0. 0. ... -0.025 0.025 0. ]\n",
" [ 0. 0. 0. ... 0. -0.025 0.025]]\n"
]
}
],
Expand All @@ -936,7 +892,7 @@
{
"data": {
"text/plain": [
"0.5950588420091663"
"0.4124502999475226"
]
},
"execution_count": 25,
Expand All @@ -957,7 +913,7 @@
{
"data": {
"text/plain": [
"0.3470027389994357"
"0.2925413999473676"
]
},
"execution_count": 26,
Expand Down Expand Up @@ -1035,9 +991,7 @@
"int(v):\n",
"\n",
"@\n",
"├── *\n",
"│ ├── 39.47841760435743\n",
"│ └── Sparse Matrix (1, 10)\n",
"├── Sparse Matrix (1, 10)\n",
"└── *\n",
" ├── /\n",
" │ ├── y[40:50]\n",
Expand Down Expand Up @@ -1083,7 +1037,8 @@
{
"data": {
"text/plain": [
"matrix([[1., 1., 1., 1., 1., 1., 1., 1., 1., 1.]])"
"matrix([[39.4784176, 39.4784176, 39.4784176, 39.4784176, 39.4784176,\n",
" 39.4784176, 39.4784176, 39.4784176, 39.4784176, 39.4784176]])"
]
},
"execution_count": 30,
Expand All @@ -1092,7 +1047,7 @@
}
],
"source": [
"int_v_over_r_disc.children[0].children[1].evaluate() / micro_mesh.d_edges"
"int_v_over_r_disc.children[0].evaluate() / micro_mesh.d_edges"
]
},
{
Expand Down Expand Up @@ -1282,7 +1237,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.6.9"
}
},
"nbformat": 4,
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/test_expression_tree/test_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def test_matrix_evaluate(self):

def test_matrix_operations(self):
np.testing.assert_array_equal((self.mat + self.mat).evaluate(), 2 * self.A)
np.testing.assert_array_equal((self.mat - self.mat).evaluate(), 0 * self.A)
np.testing.assert_array_equal(
(self.mat - self.mat).evaluate().toarray(), 0 * self.A
)
np.testing.assert_array_equal(
(self.mat @ self.vect).evaluate(), np.array([[5], [2], [3]])
)
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_expression_tree/test_unary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def test_unary_operator(self):

# with number
log = pybamm.log(10)
self.assertIsInstance(log.children[0], pybamm.Scalar)
self.assertEqual(log.evaluate(), np.log(10))

def test_negation(self):
Expand Down

0 comments on commit a19a389

Please sign in to comment.