Add native biquadratic RKKY interlayer coupling (ext_RKKYBiquadratic)#407
Open
SanthoshSivasubramani wants to merge 2 commits into
Open
Add native biquadratic RKKY interlayer coupling (ext_RKKYBiquadratic)#407SanthoshSivasubramani wants to merge 2 commits into
SanthoshSivasubramani wants to merge 2 commits into
Conversation
Adds bilinear+biquadratic interlayer exchange E = -J1(m1.m2) - J2(m1.m2)^2 as an effective-field term B = (J1 + 2*J2*(m.mp))/(Msat*dz)*mp. J2<0 favours the 90-degree SAF state that bilinear coupling cannot represent; J2=0 reduces to bilinear RKKY. Uses 1/Msat convention (no mu0), z-column partner scan spans a spacer gap, self-guards in SetEffectiveField. L4-validated: parallel B=-4.44444T, perpendicular B=-2.22222T match analytic to 6 sig figs. cuda2go wrapper for the full CC set; gofmt-clean.
There was a problem hiding this comment.
Pull request overview
This PR introduces a native bilinear + biquadratic RKKY interlayer coupling effective-field term (ext_RKKYBiquadratic) with a CUDA implementation, integrates it into the main effective-field pipeline, and adds a regression test validating the analytic field for parallel/perpendicular configurations.
Changes:
- Added
ext_RKKYBiquadraticengine API and aB_rkkybiquadoutput field term. - Implemented the CUDA kernel (
addbiquadrkky) and wired a cuda2go-generated wrapper for execution. - Added a regression test (
test/biquad.mx3) that checks the expected field values.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
test/biquad.mx3 |
Adds regression coverage validating the new field term against analytic expectations. |
engine/effectivefield.go |
Includes the new RKKY-biquadratic term in SetEffectiveField. |
engine/biquad.go |
Defines the scripting API, stores coupled region pairs, and computes B_rkkybiquad. |
cuda/biquad.go |
Host-side Go wrapper that launches the CUDA kernel with mesh/region inputs. |
cuda/biquad.cu |
CUDA kernel computing the coupling field by locating partner cells along z. |
cuda/biquad_wrapper.go |
Auto-generated cuda2go wrapper/embedded PTX for the kernel across compute capabilities. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+57
to
+61
| // locate the nearest partner-region cell in the same (x,y) column along z, | ||
| // scanning outward from iz and stopping at the first hit (checking the | ||
| // lower side first for a deterministic tie-break). | ||
| int P = -1; | ||
| for (int d = 1; d < Nz; d++) { |
Comment on lines
+44
to
+46
| func RKKYBiquadratic(region1, region2 int, J1, J2 float64) { | ||
| biquadPairs = append(biquadPairs, biquadPair{region1, region2, J1, J2}) | ||
| } |
Comment on lines
+31
to
+38
| var ( | ||
| biquadPairs []biquadPair | ||
| B_rkkybiquad = NewVectorField("B_rkkybiquad", "T", "Biquadratic RKKY interlayer coupling field", AddBiquadraticRKKYField) | ||
| ) | ||
|
|
||
| func init() { | ||
| DeclFunc("ext_RKKYBiquadratic", RKKYBiquadratic, "Adds native bilinear+biquadratic RKKY coupling J1,J2 (J/m2) between region1 and region2 (J2<0 favours 90 deg; spans a spacer gap).") | ||
| } |
…, correct quartic energy Addresses Copilot review: apply coupling only at the interface cell (thickness-independent), validate region ids, overwrite duplicate pairs, and register the energy. Because the biquadratic term is quartic in m, a dedicated energy-density kernel (biquadenergy.cu) is used instead of the generic -1/2 M.B density (which would double-count the J2 term). Added test/biquad_thick.mx3 verifying E = -(J1+J2)A (not the doubled value). VM-validated on L4: all tests OK.
Author
|
Thanks for the review — pushed
Validated on an NVIDIA L4 (CUDA 12.3): all tests pass. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add native biquadratic RKKY interlayer coupling (
ext_RKKYBiquadratic)This adds bilinear + biquadratic interlayer exchange (RKKY) coupling as an
effective-field term. The biquadratic term is the standard mechanism behind the
90° interlayer state in synthetic antiferromagnets, which purely bilinear
coupling cannot represent, and which mumax3 currently has no native term for.
Physics
For two magnetic regions coupled across a (possibly nonmagnetic) spacer, the
areal energy is
whose exact variational-derivative effective field is
with
J1the bilinear andJ2the biquadratic areal coupling (J/m²) anddzthe cell size along z.
J1 < 0is antiferromagnetic;J2 < 0favours the 90°(perpendicular) state. With
J2 = 0this reduces exactly to bilinear RKKY. Thekernel uses the
1/Msatconvention (no explicit µ0) and locates the partnercell by scanning the z-column, so the coupling spans a spacer gap rather
than only coupling immediately-adjacent cells.
API
May be called multiple times to couple several region pairs. Exposes a
B_rkkybiquadvector output and self-guards to a no-op inSetEffectiveFieldwhen no pair is defined.
Validation (NVIDIA L4, CUDA 12.3)
test/biquad.mx3passes, matching the analytic field to 6 significant figures.With
J1 = −2e−3,J2 = −1e−3 J/m²,Msat = 1e6 A/m,dz = 0.9e−9 m:(J1+2J2)/(Msat·dz) = −4.44444 Talong partnerJ1/(Msat·dz) = −2.22222 Talong partnerThe perpendicular case confirms the biquadratic term correctly drops out at 90°,
isolating the bilinear contribution.
The CUDA wrapper is generated with
cuda2gofor the full compute-capability set(
50 52 53 60 61 62 70 72 75 80 86 87 89 90). Code isgofmt-clean.Files
cuda/biquad.cu— kernel (addbiquadrkky)cuda/biquad.go,cuda/biquad_wrapper.go— host wrapper (cuda2go-generated)engine/biquad.go—ext_RKKYBiquadraticAPI +B_rkkybiquadfield termengine/effectivefield.go— one line:AddBiquadraticRKKYField(dst)test/biquad.mx3— regression testFollows the same structure as the
ext_RKKYPR (this is its biquadraticgeneralization). Happy to adapt to your conventions.