Commit 843be1e4 authored by Zolnierczuk, Piotr's avatar Zolnierczuk, Piotr
Browse files

new flipper work

new flipper field in biot-savart that should bring
the flipper curves closer to "reality"
parent a730983e
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ def rxx13(omega_z, omega_x):

def current_sheet(turns_density):
    "magnetic field of an infinite current sheet per unit current"
    #FIXME: move to Biot-Savart module
    return MU_0/2*turns_density


@@ -123,9 +124,6 @@ def make_flipper(name, params=None):
            params = json.load(file)
            name = params.pop('name', 'unknown')
            return __make_flipper(name, params=params)
    except json.JSONDecodeError:
        print(f"Error: Could not decode JSON from the file '{name}'. Check the file format.")
        return None
    except FileNotFoundError:
        pass

+45 −3
Original line number Diff line number Diff line
@@ -225,6 +225,7 @@ def bsheet_kernel(r, width, height):
            by = by + k*log((rr-zz)/(rr+zz))/2
    return bx/_four_pi, by/_four_pi

#bsheet_kernel_vec = np.vectorize(bsheet_kernel, excluded={1, 'width', 2, 'height'})

def current_sheet_finite(r, s1, s2, s3):
    """
@@ -255,8 +256,8 @@ def current_sheet_finite(r, s1, s2, s3):
    M  = np.vstack((ex,ey,ez))

    r  = r - (s2+s3)/2
    r = np.dot(M,r)

    r  = np.dot(M,r) # FIXME: works only for r(vectors) and not r[...,3] tensors
    #
    bx, by = bsheet_kernel(r,bb,hh)

    # Transformation of the field back into the original coordinate system
@@ -276,6 +277,8 @@ def current_sheet(r, s1, s2, s3, finite=True):
        return current_sheet_finite(r, s1, s2, s3)
    return current_sheet_infinite(r)



# ============================================================================
# Helmholtz pairs and solenoids
# ============================================================================
@@ -314,6 +317,45 @@ def solenoid(r, radius=1, start=-0.5, end=+0.5, nturns=10):
        bfield = bfield + db
    return bfield


# ============================================================================
# Flipper field
# ============================================================================
def flipper_field(r, thickness, width, length):
    """
    r         - obs. point
    thickness - along the beam (x-horizontal)
    width     - perp to beam   (y-horizontal)
    length    - vertical       (z-vertical)
    """
    b = np.zeros_like(r)

    # upstream plane
    xs1 = asarray(( -thickness/2, +width/2, -length/2))
    xs2 = asarray(( -thickness/2, -width/2, -length/2))
    xs3 = asarray(( -thickness/2, +width/2, +length/2))
    b  += current_sheet(r, xs1, xs2, xs3)

    # downstream plane
    xs1 = asarray(( +thickness/2, -width/2, +length/2))
    xs2 = asarray(( +thickness/2, +width/2, +length/2))
    xs3 = asarray(( +thickness/2, -width/2, -length/2))
    b  += current_sheet(r, xs1, xs2, xs3)

    # left (looking downstream)
    xs1 = asarray(( +thickness/2, +width/2, -length/2))
    xs2 = asarray(( -thickness/2, +width/2, -length/2))
    xs3 = asarray(( +thickness/2, +width/2, +length/2))
    b  += current_sheet(r, xs1, xs2, xs3)

    # right (looking downstream)
    xs1 = asarray(( -thickness/2, -width/2, +length/2))
    xs2 = asarray(( +thickness/2, -width/2, +length/2))
    xs3 = asarray(( -thickness/2, -width/2, -length/2))
    b  += current_sheet(r, xs1, xs2, xs3)

    return b

# ============================================================================
# Obsolete/Testing
# ============================================================================
+13 −6
Original line number Diff line number Diff line
@@ -11,7 +11,8 @@ from ..echo.flippers import make_flipper, tof_curve

def plot_flipper_curve(axs, name='fpi', **kwargs):
    "test with plots"
    print(f"{name=}, {kwargs=}")
    log = logging.getLogger()
    log.debug("plot_flipper_curve(%s, %s)", name, kwargs)
    pos     = kwargs.pop('pos', 'p2')
    freq    = kwargs.pop('freq', 60.0)
    points  = kwargs.pop('points', 163)
@@ -24,7 +25,9 @@ def plot_flipper_curve(axs, name='fpi', **kwargs):
    b_z     = kwargs.pop('bfield_z', 0.0) # vertical   external field in Tesla
    fname   = kwargs.pop('file', None)    # flipper definition file

    log = logging.getLogger()
    log.debug("pos=%s freq=%g points=%d shift=%g lmax=%g compare=%s scale=%g b_x=%g b_z=%g fname=%s",
              pos, freq, points, shift, lmax, compare, scale, b_x, b_z, fname)

    L  =  Ltot.get(pos) # [m] source to detector
    L1 =  L - L2 # [m] source to sample
    B_ext = np.asarray([ b_x, 0.0, b_z])  # ext. field
@@ -36,10 +39,14 @@ def plot_flipper_curve(axs, name='fpi', **kwargs):
        except FileNotFoundError as err:
            log.error("cannot load compare file (%s)",err)
            compare_data = None
    try:
        if fname:
            flipper = make_flipper(fname)
        else:
            flipper = make_flipper(name)
    except ValueError as err:
        log.error("cannot create flipper (%s)", err)
        return None, None
    title = rf'{flipper.name} $\lambda_{{max}}$={lmax:g}$\AA$'

    delam = HMN/(freq*L) # wavelengtgh band
+2 −2
Original line number Diff line number Diff line
@@ -2,8 +2,8 @@
PySEN revision module
"""
import sys
__version__  = "2.1.0.dev9"
__date__     = "Mar 12, 2026"
__version__  = "2.1.0.dev10"
__date__     = "Mar 19, 2026"

def version(full=False):
    "get pysen version number"
+7 −0
Original line number Diff line number Diff line
{
    "name": "new_flipper",
    "type": "pi"
    "position": -1.2345678,
    "thickness": 0.314,
    "turns_density": 333.33
}
Loading