PrincetonUniversity / FOCUS

Flexible Optimized Coils Using Space curves
https://princetonuniversity.github.io/FOCUS/
GNU General Public License v3.0
16 stars 3 forks source link

Harmonic normalization seems faulty #28

Closed logan-nc closed 5 years ago

logan-nc commented 5 years ago

When running FOCUS to optimize RMP coil currents, it is normalizing my input currents by hug numbers ~1e9.

The huge normalizer comes from the solvers.h lines that read,

     if ( weight_bharm >= machprec ) then 
        modBn = sqrt(sum(Bmnc**2 + Bmns**2))
        modtBn = sqrt(sum(tBmnc**2 + tBmns**2))
        do icoil = 1, Ncoils
           coil(icoil)%I = coil(icoil)%I * modtBn / modBn
        enddo
        if(myid .eq. 0) write(ounit,'(8X,": rescale coil currents with a factor of "ES12.5)') &
             modtBn / modBn
        call bnormal(0)
        if (abs(bharm) > machprec) weight_bharm = weight_bharm / bharm
        if( myid == 0 ) write(ounit, 1000) "weight_bharm", weight_bharm
        if( myid .eq. 0 .and. weight_bharm < machprec) write(ounit, '("warning : weight_bharm < machine_precision, bharm will not be used.")')
     endif

However, I think the problem is with the Bmn terms being fed into this (i.e. the logic in these lines is sound). I suspect that the either a) Bmnc and Bmns values have not been properly set prior to this line or b) the tBmnc and tBmns are already normalized to a unity modtBn. I kind of suspect some funny harmonic normalization elsewhere, since the Bn field outputs are correctly huge but the final Bmnc/Bmns are small (order 1e-4, similar to the target harmonics).

Note, if I print sqrt(sum( bnc**2 + bns**2)) from my target.harmonics file it is 0.001 and matches the sqrt(sum( initial_Bmns**2 + intial_Bmnc**2)) from the h5 output.

zhucaoxiang commented 5 years ago

I have a case in which the initial coils is close enough. Coil current scaling factor seems normal. Here is the output.

        : Overlap of the realized Bn harmonics is:  99.998 %
        : Average relative absolute Bn error is  :  5.707379279974547E+00
        : The most and least important coils are :    30.134% at coil   1 ;    9.933% at coil    3
        : rescale coil currents with a factor of  3.99971E+00
        : weight_bharm is normalized to  3.55731E+11
logan-nc commented 5 years ago

What's the order of magnitude for your target harmonics and input coil currents?

zhucaoxiang commented 5 years ago

I am using __d3d_rmp__ in the "examples" directory. The coil currents are optimized, but shape are fixed. The currents are something like 4kA, 2kA.

logan-nc commented 5 years ago

Let me phrase this a different way: My realized b_n and realized harmonics do not match:

image

(note the difference better shows the size of the realized b_n since its color limits are not constrained to the initial b_n clims)

zhucaoxiang commented 5 years ago

@logan-nc Do you have the input files that can be used to reproduce the problem? I checked with the d3d_RMPexample, and it looks normal. I will try to solve this.

zhucaoxiang commented 5 years ago

This is caused by bad initial coils, leading to unrealistic auto-normalization in coil currents. The auto-normalization is now turned off and will be printing out as a suggestion.

I will close this issue @logan-nc .