Conversation
…moother integration of new spline in VACUUM, renaming of matrices (grad_green, green_fourier, green_temp) for clarity, simplifying isgn, adding populate_greenfunction parameter
|
@claude review this PR |
|
Claude finished @jhalpern30's task in 1m 50s —— View job Code Review Complete ✓SummaryThis PR improves the Vacuum module code by:
Overall, these changes significantly improve code readability and maintainability. The refactoring is well-executed with only minor issues noted below. Detailed Findings✅ Strengths
|
Verification that I didn't break anythingNote that my changes are slightly more memory efficient (Solovev ideal example) Tests on developDIIID-like Ideal Example Solovev Ideal Example Solovev Ideal Example (equal_arc_wall = false) Tests on this branchDIIID-like Ideal Example Solovev Ideal Example Solovev Ideal Example (equal_arc_wall = false) |
|
@logan-nc might have a problem here, both my unit tests and docs test are failing and I think its due to FastInterpolations |
|
How bad of a problem? like the tests weren't properly undated and try to use Fortran that isn't there? or like the tests have caught a serious and mysterious bug in the spline implementation somewhere in the source code? |
1 similar comment
|
How bad of a problem? like the tests weren't properly undated and try to use Fortran that isn't there? or like the tests have caught a serious and mysterious bug in the spline implementation somewhere in the source code? |
I think the former but I'm not 100% sure. It looks like it makes the unit tests fail due to some equilibrium issues, and the docs fail because there are spline docstrings that don't exist? |
|
@copilot fix the unit test and doc issues that are causing the checks on this PR to fail |
|
@jhalpern30 I've opened a new pull request, #150, to work on those changes. Once the pull request is ready, I'll request review from you. |
…astInterpolations, all interpolation (except for Gaussian quadrature) now using a consistent package
UPDATEI made Tests stay the same with this update: |
…, fixing equal_arc_grid tests
…nto jmh/2D_vacuum_part2
…nto jmh/2D_vacuum_part2
… periodic data without endpoints and some with. Updating compute_greensfunctions_only
…and replacing it with a flag in compute_vacuum_response
…Free.jl and SingularCoupling.jl to use the same interface
…functions, refactoring some functions as constructors
|
Claude finished @jhalpern30's task in 2m 6s —— View job Summary of Changes After Commit 376271cTodo List:
After commit Commits Summary (in chronological order)1. 162e2f8 - VACUUM - BUGFIX - fixing interp_to_new_gridFixed handling of periodic data that may or may not include endpoint duplication. Updated Files changed: 2. 550f04f - VACUUM - IMPROVEMENT - removing compute_green_only functionalityEliminated the separate Impact: Removed ~97 lines of duplicate logic Files changed:
3. bc61e08 - VACUUM - IMPROVEMENT - consolidating vacuum input generationUnified the vacuum input generation interface between Key changes:
Impact: Removed 176 lines of duplicate code Files changed:
4. 3ebfa96 - bugfixMinor kernel bugfix (1 line change) Files changed: 5. d6971a7 - VACUUM - IMPROVEMENT - ruthless removal of unnecessary parameters and functionsThis is the largest cleanup commit, refactoring geometry initialization functions as constructors and removing unused parameters. Major changes:
Impact: Net removal of 159 lines, major simplification Files changed (9 files):
6. b0c07b8 - TEST - BUGFIX - fixing unit testing exception throw errorFixed error handling in DataTypes.jl for unit tests. Files changed: Overall ImpactLines changed: +277 insertions, -704 deletions across 10 files Key improvements:
These changes maintain numerical correctness (as verified by your tests showing identical results) while significantly improving code clarity and maintainability. |
|
@logan-nc ok this is now ready for review again. Its a bit bigger than originally, but I think its worth it due to the significant cleanups I found from the perturbed equilibrium PR. Claude's summary above gives a decent idea, I think the most notable are that I got rid of the interp_to_new_grid and periodic_deriv functions, incorporated @mgyoo86's new periodic exclusive endpoint BCs from #148 into the VACUUM code (which clean things up very well), removed a lot of unnecessary parameters from the VacuumInput struct, and renamed I think one of the bigger things that remain here is more file organization, reserved for a later commit. |
|
Results from this branch: Solovev example |
Code ReviewThis PR successfully implements a useful architectural improvement by passing geometry structs to kernel! instead of raw arrays. The changes eliminate confusing index logic and make the code more maintainable. However, there are several critical issues that must be addressed before merge. Critical Issues - Must Fix Before Merge1. Missing dx_dtheta and dz_dtheta fields in geometry structs The PR description states the code now uses precomputed derivatives stored in the structs. However, DataTypes.jl:103-136 shows PlasmaGeometry and WallGeometry only contain x, z, and ν fields. Yet Kernel2D.jl:128 references source.dx_dtheta[isrc] and source.dz_dtheta[isrc], which will cause a field-not-found error at runtime. The structs must be updated to include dx_dtheta and dz_dtheta arrays. 2. Missing is_closed_toroidal field in WallGeometry Kernel2D.jl:210 uses is_closed_toroidal = true as a hardcoded variable, but Vacuum.jl:310 references wall.is_closed_toroidal. Either add this field to WallGeometry or use a consistent approach. 3. Broken pickup code references non-existent fields MathUtils.jl:156 in _calculate_potential_chi references plasma_surf.dx_dtheta and plasma_surf.dz_dtheta, but these fields don't exist. If this code is unused (per PR description), either fix it or clearly mark it as deprecated/broken. Design Issues4. Inconsistent offset naming Vacuum.jl:279-282 defines PLASMA_ROW_OFFSET = 0, WALL_ROW_OFFSET = mtheta, etc. The zero-valued offsets add no clarity. Either use all offsets consistently or eliminate redundant ones. 5. FourierTransforms documentation uses old terminology The module docstring and several function docstrings still reference qa*delta phase shifts, but the implementation now uses ν (toroidal angle offset). Update all documentation to match the new API. 6. Removed compute_vacuum_inputs is a breaking change Free.jl removes the compute_vacuum_inputs function. This is a breaking API change for any external callers. Either keep a deprecated wrapper or document the migration path. Code Quality7. Spline derivatives still recreated on each kernel! call Kernel2D.jl:112-115 creates spline derivative functors on every kernel! invocation. If dx_dtheta and dz_dtheta are precomputed in the geometry structs (per PR goals), these spline setups should only be needed for off-grid Gaussian quadrature points. Consider whether this can be optimized further. 8. Test coverage reduced significantly runtests_vacuum_julia.jl has 60 deletions. Verify that removed tests were truly redundant and that remaining coverage is adequate for the new struct-based interface. 9. Comment in Kernel2D.jl:127 could be clearer The comment says derivatives are "needed for off-grid points during Gaussian interpolation" but doesn't specify which integration method uses off-grid vs on-grid points. Be more explicit. Minor Issues
Positive Aspects
Recommendations
The architectural direction is sound and will benefit 3D vacuum development. However, the missing struct fields will cause runtime failures and must be fixed before merge. |
This is part of a series of PRs for 3D vacuum that I am breaking up to be more manageable. This PR is entirely aesthetic - there are no modifications to the outputs, but mainly focuses on simplifications/renaming that will carry over to 3D.
TL;DR:
kernel!now accepts either aPlasmaGeometryorWallGeometrystruct and this led to a VERY nice cleanup, we now actually use thedx_dthetaanddz_dthetastores in the structs instead of recomputing them, removed theisgnvariable, and made some cosmetic renaming of variables. Note that Claude's concerns only relate to the untestedpickupcode so I am just going to leave itIn approximate order of impact:
kernel!now acceptsPlasmaGeometryandWallGeometrystructs!Gone are the days of passing in
j1andj2tokernel!and then going through some confusing logic to figure out which block of the gradient green's matrix you're in and how that affect the singularities. In Julia, we now pass in the struct,and can use type checking on the observer and source positional argument to obtain everything else out such as
grad_greenfunctionwe're ingreenfunctioneven needs to be filled. This is a new feature for both clarify and (possibly) some computational improvement, but not criticalgreenfunctionsingularity correction term if its the plasma-plasma blockisgnlater)Cleaning up spline interface
I simplified some of the existing logic in the
interp_to_new_gridfunctions andperiodic_derivfunctions now that we have the Julia splines. The main improvement here comes from the use of the dx_dthetaanddz_dtheta` arrays in the geometry structs. Previously, these arrays were being filled but never touched, since we just rebuilt the splines and derivatives at the beginning of the kernel callNow, we still create the d1 splines since they're needed for the off-grid points during Gaussian interpolation, but since we doing everything on-grid during Simpson integration we can just use the precomputed derivatives here
Subnote for equal_arc_grid (previously mentioned in #141)
Note that this means that almost this entire section was unused since we were recomputing the derivatives
and essentially all that's happening here is we're redefining the theta angle to be the equal arc theta angle. So we can use the same derivative calculation for both
Removal of the
isgnparameterThis closes #133 and adds a nice clarification. As discussed in that issue, this parameter is a sign flip on the direction of the normal to account for it being the outward unit normal. In the clockwise theta convention of VACUUM, this points toward increasing psi, which ends up pointing out of the vacuum region for the wall and into the vacuum region for the plasma surface. This is why there is a factor of -1 multiplying the
grad_greenfunctionmatrix. I added a much more clear comment on where this comes from, and also condensed it into a single broadcasted matrix multiply, instead of multiplying every single term that gets added during integration.Renaming/clarifications
These are truly cosmetic.
COS_COL_OFFSETand the like + better comments on thisgrri->green_fouriergreenfunction_temp->green_tempgrad_greenfunction_mat->grad_greenfunction