CASTOR plugin
CASTOR is a restive MHD stability solver.
Castor parser module.
CastorParser
CastorParser(default_namelist)
Bases: Parser
An I/O parser
clean_output_files
clean_output_files(run_dir)
Removes unnecessary files.
Parameters
run_dir : str Path to the run directory.
extract_resistivity
extract_resistivity(
filepath, outputpath, resistivity_type="spitzer"
)
author = "Hampus Nyström"
str
Path to the HELENA output file (fort.20).
outputpath: str Path to the output file. Filename should generally be "fort.14". resistivity_type: str Type of resistivity to extract. Options are "spitzer" and "neoclassical".
Script for writing resistivity data from helena output file to an outputfile that can be read by CASTOR.
read_input_density
read_input_density(run_dir)
The file called "density" is generated by HELENA and can be used as an input (in some version??) to MISHKA as fort.17.
sgrid: sqrt(psi/psi_boundary) ne: electron density
read_input_fort12
read_input_fort12(run_dir)
Read the HELENA output file fort.12 which is used as input by MISHKA.
read_output_fort20
read_output_fort20(run_dir)
The main output file. Looking for line:
INSTABILITY FOUND : -10 9 0.3076E+00 0.2167E-08
If number of iterations reached the maximum limit (usually 20), then the growthrate is assumed to be 0. (Europed)
read_output_fort22
read_output_fort22(run_dir)
Read the output file fort.22 which contains a list of eigenvalues (real, complex). The eigenvalues are listed as [Re(ev1), Re(ev1)+Im(ev1), Re(ev2), Re(ev2)+Im(ev2), ...]
-
gamma: growth rate eigenvalue
-
ng: number of grid points
-
ngl: 2
-
nbg: the number of eigenvalues per harmonic (2 * ngl * manz)
-
manz: number of poloidal harmonics
-
sgrid: flux system coordinate s = sqrt(psi/psi_boundary)
-
rfour: "RFOUR(1) - LOWEST POLOIDAL MODE NUMBER" ?
-
ev: array of eigenvalues [complex(Re(ev1), Im(ev1)), complex(Re(ev2), Im(ev2)), ...]
write_input_file
write_input_file(params, run_dir, vshift=[])
Writes input file.
Parameters
params : dict Dictionary containing input parameters. run_dir : str Path to the run directory. vshift : list[complex] A list of compelx values as starting points for the eigenvalue solver. Writing the namelist will fail if the values are tuples, not complex values.
write_summary
write_summary(run_dir, mpol, params)
Generates a summary file with run directory and parameters, along with success and stability criteria.
Parameters
run_dir : str Path to the run directory. params : dict Dictionary containing input parameters.
Returns
dict Summary dictionary containing run directory, parameters, success status, Mercier criterion presence, and ballooning criterion presence.
Module for running CASTOR code.
Configuration
Mandatory fields in the configuration file for using the CASTOR plugin:
runner:
type: CastorRunner
executable_path: "/path/to/castor/executable"
other_params: {
"namelist_path": "/path/to/fort.10"
}
CastorRunner
CastorRunner(executable_path, other_params, **kwargs)
Bases: Runner
Class for running CASTOR. Requires that pre-compiled CASTOR binary exist for m=(21,31,41,51,71). Adding "_m" at the end of the name of the defined executable path.
For example, if the executable path in the config file is executable_path: "/bin/cas12" and the toroidal mode number is n=20, which according to the europed standards gives the poloidal mode number m=71, then the runner will expect the executable to be found at "/bin/cas12_71".
Attributes:
| Name | Type | Description |
|---|---|---|
executable_path |
str
|
the path to the pre-compiled executable CASTOR binary (without "_m") |
other_params |
dict
|
a dictionary of other parameters defined in the config file |
get_equilibrium_files
get_equilibrium_files(
run_dir, params, resistivity_type="spitzer"
)
Copies the equilibirum files to the run directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_dir
|
str
|
The run directory to where the input file is copied. |
required |
Returns:
| Type | Description |
|---|---|
|
None |
get_mpol
get_mpol(n)
Chooses the maximum poloidal harmonic to use in CASTOR. As this class assumes that the CASTOR verions are pre-compiled, this function chooses which version to use. Implementation following the Europed model set_harmonic(self,n) for europed input parameter 0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The toroidal mode number |
required |
Returns:
| Name | Type | Description |
|---|---|---|
harmonic |
int
|
The poloidal harmonic to use in the CASTOR run. |
pre_run_check
pre_run_check()
Performs pre-run checks to ensure necessary files exist before running the simulation.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the executable path or the namelist path is |
run_castor
run_castor(mpol, run_dir)
Start CASTOR run. Write the CASTOR output to a separate file.
single_code_run
single_code_run(run_dir, params=None, vshift=None)
Logic to run CASTOR
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_dir
|
str
|
The directory in where CASTOR is run. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the results of the CASTOR run. |