|
15 | 15 | it under the terms of the GNU Lesser General Public License as published by |
16 | 16 | the Free Software Foundation, either version 3 of the License, or |
17 | 17 | (at your option) any later version. |
18 | | - |
| 18 | +
|
19 | 19 | You should have received a copy of the GNU Lesser General Public License |
20 | | -along with FreeGSNKE. If not, see <http://www.gnu.org/licenses/>. |
| 20 | +along with FreeGSNKE. If not, see <http://www.gnu.org/licenses/>. |
21 | 21 | """ |
22 | 22 |
|
23 | | -import warnings |
24 | 23 | from copy import deepcopy |
25 | 24 |
|
26 | 25 | import freegs4e |
27 | | -import matplotlib.pyplot as plt |
28 | 26 | import numpy as np |
29 | | -import scipy as sp |
30 | 27 | from freegs4e.gradshafranov import Greens |
31 | 28 |
|
32 | 29 | from . import nk_solver_H as nk_solver |
@@ -168,7 +165,10 @@ def freeboundary(self, plasma_psi, tokamak_psi, profiles): |
168 | 165 |
|
169 | 166 | # calculates and imposes the boundary conditions |
170 | 167 | self.psi_boundary = np.zeros_like(self.R) |
171 | | - psi_bnd = np.sum(self.greenfunc * self.jtor[np.newaxis, :, :], axis=(-1, -2)) |
| 168 | + # weighted sum over the last two axes. |
| 169 | + # "contract" axis 1 of greenfunc with axis 0 of jtor |
| 170 | + # contract axis 2 of greenfunc with axis 1 of jtor |
| 171 | + psi_bnd = np.tensordot(self.greenfunc, self.jtor, axes=([1, 2], [0, 1])) |
172 | 172 |
|
173 | 173 | self.psi_boundary[:, 0] = psi_bnd[: self.nx] |
174 | 174 | self.psi_boundary[:, -1] = psi_bnd[self.nx : 2 * self.nx] |
@@ -418,7 +418,6 @@ def forward_solve( |
418 | 418 | while (rel_change > target_relative_tolerance) * ( |
419 | 419 | iterations < max_solving_iterations |
420 | 420 | ): |
421 | | - |
422 | 421 | if rel_change > Picard_handover: |
423 | 422 | log.append("Picard iteration: " + str(iterations)) |
424 | 423 | # using Picard instead of NK |
@@ -762,10 +761,9 @@ def optimize_currents( |
762 | 761 | # print(delta_current) |
763 | 762 |
|
764 | 763 | for i in range(constrain.n_control_coils): |
765 | | - |
766 | 764 | if verbose: |
767 | 765 | print( |
768 | | - f" - calculating derivatives for coil {i+1}/{constrain.n_control_coils}" |
| 766 | + f" - calculating derivatives for coil {i + 1}/{constrain.n_control_coils}" |
769 | 767 | ) |
770 | 768 |
|
771 | 769 | currents = np.copy(self.dummy_current) |
@@ -963,12 +961,10 @@ def inverse_solve( |
963 | 961 | (rel_change_full > target_relative_tolerance) |
964 | 962 | + (previous_rel_delta_psit > target_relative_psit_update) |
965 | 963 | ) * (iterations < max_solving_iterations): |
966 | | - |
967 | 964 | if verbose: |
968 | 965 | print("Iteration: " + str(iterations)) |
969 | 966 |
|
970 | 967 | if check_equilibrium: |
971 | | - |
972 | 968 | # this_max_rel_psit = min(max_rel_psit, np.mean(self.rel_psit_updates[-6:])) |
973 | 969 | this_max_rel_psit = np.mean(self.rel_psit_updates[-6:]) |
974 | 970 | this_max_rel_update_size = 1.0 * max_rel_update_size |
|
0 commit comments