radiasoft / Radia-Examples

Apache License 2.0
4 stars 3 forks source link

radia.FldEnrTrq doesn't work or not included in the function library #6

Open loveinthebone opened 4 years ago

loveinthebone commented 4 years ago

Hi All,

First of all, thank you for offering the Jupyter version of Radia for free. I am trying to use it to simulate the force and torque applied by a electromagnet to a permanent magnet. Now I can already get the force component, but find that when I try to use radia.FldEnrTrq function for calculating the torque, it always reports an error:

Incorrect function arguments: FldEnrTrq

While if I run

import radia as rad
?rad.FldEnrTrq

I can get a proper explanation of this function.

I checked the file radiasoft/Radia/cpp/src/clients/python/radpy.cpp, didn't find function FldEnrTrq. However, I did find it in this repository: https://github.com/ochubar/Radia/blob/master/cpp/src/clients/python/radpy.cpp.

Could you help me to solve this problem? For your reference, here is the code I used to test in the Jupyter server:

from __future__ import absolute_import, division, print_function #Py 2.*/3.* compatibility
import radia as rad
from math import *
from uti_plot import *
import numpy as np
import matplotlib.pyplot as plt

def Cylindercoil():
    r_out = 25.0/2 #Outer radius of the coil, unit is mm
    r_in = 12.5/2 #Inner radius
    length = 30 #Length of the coil
    d_wire = 0.402 #coil wire diameter in mm
    I = 2 #current through the coil in A
    j = I/((np.pi*d_wire**2)/4) #current density
    nseg = 6
    coil = rad.ObjRaceTrk([0.,0.,21.], [r_in,r_out], [  0.,0.], length, nseg, j,'man','z')
    return coil

def CylinderVolume():
    D_mag=37.5 # diamter of the LM in mm
    _r = D_mag/2.0
    T_mag=12.5 # Thickness of the LM
    _n_phi=15 #segmentation number of the circle
    dPhi = 2.*np.pi/_n_phi
    phi = dPhi
    slicePgn = [[_r, 0.]]
    for k in range(1, _n_phi):
        slicePgn.append([_r*cos(phi), _r*sin(phi)])
        phi += dPhi
    LM = rad.ObjThckPgn(T_mag/2, T_mag, slicePgn, 'z', [0,0,Br]) #radObjThckPgn[x, lx, {{y1,z1}, {y2,z2},...}, {mx,my,mz} :{0,0,0}]
    return LM

#*********************************Entry Point
if __name__=="__main__":

    #Build the Geometry 
    aCylinderMag = CylinderVolume() 

    aCoil=Cylindercoil()

    # assemble into a group
    grp = rad.ObjCnt([aCylinderMag, aCoil])

    test=rad.FldEnrTrq(aCylinderMag,aCoil,'tx',[0,0,0])

Thanks, Kingson

dtabell commented 4 years ago

Thanks, Kingson, for reporting this issue, and for including your test code. Oleg updated the Radia Python wrappers, and it appears we have not synced the underlying Radia Engine on our Jupyter server. We'll look into this and get back to you.

In the meantime, I just tried running your Python code and several errors arose. For example,

from future import absolute_import, division, print_function

should read

from __future__ import absolute_import, division, print_function

and

slicePgn.append([_rcos(phi), _r*sin(phi)])

should read

slicePgn.append([_r*cos(phi), _r*sin(phi)])

Also, the indentation of your Python code was mangled. It would be great if you could edit the above to make it easier us to help you.

Thanks again for reporting this issue, Dan

loveinthebone commented 4 years ago

Hi Dan,

Thank you for your fast reply. Sorry, I don't know how to easily paste code in the Github comment, but I uploaded the code (a clearer version) to here: https://github.com/loveinthebone/Radia-Examples/blob/master/test_Magnet_VS_Coil.ipynb You can access and test it.

Thank you, Kingson

dtabell commented 4 years ago

Thanks, Kingson. I edited your original comment.

The comments here are parsed by Markdown. This means that to post a block of code, you simply put it between “fences”, which are denoted by a triplet of backticks: ```. Thus

```python
def pick(l, c):
    return [e for idx, e in enumerate(l) if c[idx]]
```

yields

def pick(l, c):
    return [e for idx, e in enumerate(l) if c[idx]]

This will prevent Markdown from converting, for example, your code __future__ into the bold "future".

For more information, see the GitHub Markdown page or the useful Markdown Cheatsheet.

loveinthebone commented 4 years ago

Thank you for the mentoring, Dan.

loveinthebone commented 4 years ago

@dtabell Hi Dan, any progress on solving the issue? From my side, the error is still there when I use the rad.FldEnrTrq function.

bnash commented 4 years ago

Hello Kingson, I have confirmed that I get the same error as you when running Radia on the RadiaSoft Jupyter server. Our version of Radia there comes from O. Chubar's repository. We are in the process of rebuilding it, to take advantage of the recent parallel processing abilities. It may be that when we compile and install the most recent version, this problem will be resolved. In the meantime, I have emailed Oleg requesting assistance.

ochubar commented 4 years ago

Hi, radia_FldEnrTrq is in radpy.cpp, but there is a bug in it. Here is a fix (I'll include it to next update), in line ~#2612 (https://github.com/ochubar/Radia/blob/master/cpp/src/clients/python/radpy.cpp#L2612):

if((indDst <= 0) || (indSrc <= 0) || (oCmpnId == 0) || (oP == 0)) throw CombErStr(strEr_BadFuncArg, ": FldEnrTrq"); //OC14042020 //if((indDst <= 0) || (indSrc <= 0) || (oCmpnId == 0) || (oP)) throw CombErStr(strEr_BadFuncArg, ": FldEnrTrq");

bnash commented 4 years ago

Thanks for the reply and explanation, @ochubar!

loveinthebone commented 4 years ago

Great!. Thank you, Oleg! @bnash Could you send me a message when this bug is fixed in the Jupyter server?

bnash commented 4 years ago

I will make a good effort to do so, Kingson. We may want to consider some sort of mailing list for updates so that Radia users can keep up to date on the developments in the code and interfaces and share experience.