Пример #1
0
def test_readwrite():
    """Test reading/writing to a file round-trip"""
    tokamak = freegs.machine.MAST_sym()
    eq = freegs.Equilibrium(
        tokamak=tokamak,
        Rmin=0.1,
        Rmax=2.0,
        Zmin=-1.0,
        Zmax=1.0,
        nx=17,
        ny=17,
        boundary=freegs.boundary.freeBoundaryHagenow,
    )
    profiles = freegs.jtor.ConstrainPaxisIp(1e4, 1e6, 2.0)

    # Note here the X-point locations and isoflux locations are not the same.
    # The result will be an unbalanced double null configuration, where the
    # X-points are on different flux surfaces.
    xpoints = [(1.1, -0.6), (1.1, 0.8)]
    isoflux = [(1.1, -0.6, 1.1, 0.6)]
    constrain = freegs.control.constrain(xpoints=xpoints, isoflux=isoflux)

    freegs.solve(eq, profiles, constrain, maxits=25, atol=1e-3, rtol=1e-1)

    memory_file = io.BytesIO()

    with freegs.OutputFile(memory_file, "w") as f:
        f.write_equilibrium(eq)

    with freegs.OutputFile(memory_file, "r") as f:
        read_eq = f.read_equilibrium()

    assert tokamak == read_eq.tokamak
    assert allclose(eq.psi(), read_eq.psi())
Пример #2
0
#!/usr/bin/env python

import freegs

#########################################
# Create the machine, which specifies coil locations
# and equilibrium, specifying the domain to solve over

tokamak = freegs.machine.TestTokamak()

eq = freegs.Equilibrium(tokamak=tokamak,
                        Rmin=0.1, Rmax=2.0,    # Radial domain
                        Zmin=-1.0, Zmax=1.0,   # Height range
                        nx=65, ny=65,          # Number of grid points
                        boundary=freegs.boundary.freeBoundaryHagenow)  # Boundary condition


#########################################
# Plasma profiles

profiles = freegs.jtor.ConstrainPaxisIp(1e3, # Plasma pressure on axis [Pascals]
                                        2e5, # Plasma current [Amps]
                                        2.0) # Vacuum f=R*Bt

#########################################
# Coil current constraints
#
# Specify locations of the X-points
# to use to constrain coil currents

xpoints = [(1.1, -0.6),   # (R,Z) locations of X-points
Пример #3
0
start_resolution = 17
nrefinements = 5  # Number of refinements. Minimum 2
rtol = 1e-10  # Relative tolerance in Picard iteration
location = (1.2, 0.1)  # Location to record values at

############################################
# Generate low resolution solution

tokamak = freegs.machine.TestTokamak()

eq = freegs.Equilibrium(
    tokamak=tokamak,
    Rmin=0.1,
    Rmax=2.0,  # Radial domain
    Zmin=-1.0,
    Zmax=1.0,  # Height range
    nx=start_resolution,
    ny=start_resolution,  # Number of grid points
    boundary=freegs.boundary.freeBoundaryHagenow)

profiles = freegs.jtor.ConstrainPaxisIp(
    1e3,  # Plasma pressure on axis [Pascals]
    2e5,  # Plasma current [Amps]
    2.0)  # Vacuum f=R*Bt

xpoints = [
    (1.1, -0.6),  # (R,Z) locations of X-points
    (1.1, 0.8)
]
Пример #4
0
# Plasma equilibrium (Grad-Shafranov) solver
import freegs

# Boundary conditions
import freegs.boundary as boundary

profiles = freegs.jtor.ConstrainPaxisIp(
    1e4,  # Plasma pressure on axis [Pascals]
    1e6,  # Plasma current [Amps]
    1.0)  # fvac = R*Bt

eq = freegs.Equilibrium(Rmin=0.1,
                        Rmax=2.0,
                        Zmin=-1.0,
                        Zmax=1.0,
                        nx=65,
                        ny=65,
                        boundary=boundary.fixedBoundary)

# Nonlinear solver for Grad-Shafranov equation
freegs.solve(
    eq,  # The equilibrium to adjust
    profiles)  # The toroidal current profile function

print("Done!")

# Plot equilibrium
from freegs.plotting import plotEquilibrium

plotEquilibrium(eq)
Пример #5
0
#!/usr/bin/env python

import freegs

#########################################
# Create the machine, which specifies coil locations
# and equilibrium, specifying the domain to solve over

tokamak = freegs.machine.MAST()

eq = freegs.Equilibrium(
    tokamak=tokamak,
    Rmin=0.1,
    Rmax=2.0,  # Radial domain
    Zmin=-2.0,
    Zmax=2.0,  # Height range
    nx=65,
    ny=65)  # Number of grid points

#########################################
# Plasma profiles

profiles = freegs.jtor.ConstrainPaxisIp(
    3e3,  # Plasma pressure on axis [Pascals]
    7e5,  # Plasma current [Amps]
    0.4)  # vacuum f = R*Bt

#########################################
# Coil current constraints
#
# Specify locations of the X-points
Пример #6
0
#!/usr/bin/env python
#
# Example demonstrating functions for creating and finding X-points

import freegs

# Plotting routines
from freegs.plotting import plotEquilibrium, plotCoils, plotConstraints

import matplotlib.pyplot as plt

tokamak = freegs.machine.TestTokamak()
eq = freegs.Equilibrium(tokamak=tokamak, nx=256,ny=256)

##########################################################
# Calculate currents in coils to create X-points
# in specified locations
# 

xpoints = [(1.1, -0.8),   # (R,Z) locations of X-points
           (1.1, 0.8)]

control = freegs.control.constrain(xpoints=xpoints)
control(eq)  # Apply control to Equilibrium eq

psi = eq.psi()

print("=> Solved coil currents, created X-points")

ax = plotEquilibrium(eq, show=False)
plotCoils(tokamak.coils, axis=ax)
Пример #7
0
profiles = freegs.jtor.ConstrainBetapIp(0.1, 1e6, 1.0)

resolutions = [33, 65, 129, 257, 513]  #, 1025]

boundaries = [("A", 0.1, 2.0, -1.0, 1.0), ("B", 0.5, 1.75, -0.8, 1.1)]

for n in resolutions:
    for bndry_name, Rmin, Rmax, Zmin, Zmax in boundaries:
        # Re-create objects so no state is retained between runs

        tokamak = freegs.machine.TestTokamak()

        eq = freegs.Equilibrium(
            tokamak=tokamak,
            Rmin=Rmin,
            Rmax=Rmax,  # Radial domain
            Zmin=Zmin,
            Zmax=Zmax,  # Height range
            nx=n,
            ny=n)  # Number of grid points

        freegs.solve(
            eq,  # The equilibrium to adjust
            profiles,  # The toroidal current profile function
            constrain,  # Constraint function to set coil currents
            rtol=1e-6,
            show=False)

        # Save solution for later analysis
        with open("test-02-" + bndry_name + "-" + str(n) + ".pkl", "wb") as f:
            pickle.dump(n, f)
            pickle.dump((bndry_name, Rmin, Rmax, Zmin, Zmax), f)