|
| 1 | +// SPDX-FileCopyrightText: 2024-present Proxima Fusion GmbH |
| 2 | +// <info@proximafusion.com> |
| 3 | +// |
| 4 | +// SPDX-License-Identifier: MIT |
| 5 | +#include "vmecpp/free_boundary/only_coils/only_coils.h" |
| 6 | + |
| 7 | +namespace vmecpp { |
| 8 | + |
| 9 | +OnlyCoils::OnlyCoils(const Sizes* s, const TangentialPartitioning* tp, |
| 10 | + const MGridProvider* mgrid, std::span<double> bSqVacShare, |
| 11 | + std::span<double> vacuum_b_r_share, |
| 12 | + std::span<double> vacuum_b_phi_share, |
| 13 | + std::span<double> vacuum_b_z_share) |
| 14 | + : FreeBoundaryBase(s, tp, mgrid, bSqVacShare, vacuum_b_r_share, |
| 15 | + vacuum_b_phi_share, vacuum_b_z_share) {} // OnlyCoils |
| 16 | + |
| 17 | +bool OnlyCoils::update( |
| 18 | + const std::span<const double> rCC, const std::span<const double> rSS, |
| 19 | + const std::span<const double> rSC, const std::span<const double> rCS, |
| 20 | + const std::span<const double> zSC, const std::span<const double> zCS, |
| 21 | + const std::span<const double> zCC, const std::span<const double> zSS, |
| 22 | + int signOfJacobian, const std::span<const double> rAxis, |
| 23 | + const std::span<const double> zAxis, double* bSubUVac, double* bSubVVac, |
| 24 | + double netToroidalCurrent, int ivacskip, |
| 25 | + const VmecCheckpoint& vmec_checkpoint, bool at_checkpoint_iteration) { |
| 26 | + // only need surface geometry, not all derived quantities |
| 27 | + bool full_update = false; |
| 28 | + |
| 29 | + sg_.update(rCC, rSS, rSC, rCS, zSC, zCS, zCC, zSS, signOfJacobian, |
| 30 | + full_update); |
| 31 | + |
| 32 | + // blindly assume netToroidalCurrent == 0.0, |
| 33 | + // since checked for that during initialization |
| 34 | + ef_.update(rAxis, zAxis, 0.0); |
| 35 | + |
| 36 | + // compute net covariant magnetic field components on surface |
| 37 | + double local_bsubuvac = 0.0; |
| 38 | + double local_bsubvvac = 0.0; |
| 39 | + for (int kl = tp_.ztMin; kl < tp_.ztMax; ++kl) { |
| 40 | + int l = kl / s_.nZeta; |
| 41 | + local_bsubuvac += ef_.bSubU[kl - tp_.ztMin] * s_.wInt[l]; |
| 42 | + local_bsubvvac += ef_.bSubV[kl - tp_.ztMin] * s_.wInt[l]; |
| 43 | + } |
| 44 | + local_bsubuvac *= signOfJacobian * 2.0 * M_PI; |
| 45 | + |
| 46 | +#ifdef _OPENMP |
| 47 | +#pragma omp single |
| 48 | +#endif // _OPENMP |
| 49 | + { |
| 50 | + *bSubUVac = 0.0; |
| 51 | + *bSubVVac = 0.0; |
| 52 | + } |
| 53 | +#ifdef _OPENMP |
| 54 | +#pragma omp barrier |
| 55 | +#endif // _OPENMP |
| 56 | + |
| 57 | +#ifdef _OPENMP |
| 58 | +#pragma omp critical |
| 59 | +#endif // _OPENMP |
| 60 | + { |
| 61 | + *bSubUVac += local_bsubuvac; |
| 62 | + *bSubVVac += local_bsubvvac; |
| 63 | + } |
| 64 | +#ifdef _OPENMP |
| 65 | +#pragma omp barrier |
| 66 | +#endif // _OPENMP |
| 67 | + |
| 68 | + // compute magnetic pressure from only coils: |B|^2/2 |
| 69 | + for (int kl = tp_.ztMin; kl < tp_.ztMax; ++kl) { |
| 70 | + // cylindrical components of vacuum magnetic field |
| 71 | + vacuum_b_r_share_[kl] = ef_.interpBr[kl - tp_.ztMin]; |
| 72 | + vacuum_b_phi_share_[kl] = ef_.interpBp[kl - tp_.ztMin]; |
| 73 | + vacuum_b_z_share_[kl] = ef_.interpBz[kl - tp_.ztMin]; |
| 74 | + |
| 75 | + // magnetic pressure from vacuum: |B|^2/2 |
| 76 | + bSqVacShare[kl] = 0.5 * (vacuum_b_r_share_[kl] * vacuum_b_r_share_[kl] + |
| 77 | + vacuum_b_phi_share_[kl] * vacuum_b_phi_share_[kl] + |
| 78 | + vacuum_b_z_share_[kl] * vacuum_b_z_share_[kl]); |
| 79 | + } // kl |
| 80 | + |
| 81 | + // ... done ... |
| 82 | + |
| 83 | +#ifdef _OPENMP |
| 84 | +#pragma omp barrier |
| 85 | +#endif // _OPENMP |
| 86 | + |
| 87 | + // TODO(jons): could move bSubUVac, bSubVVac collection here to spare on |
| 88 | + // barrier |
| 89 | + |
| 90 | + return false; |
| 91 | +} // update |
| 92 | + |
| 93 | +} // namespace vmecpp |
0 commit comments