helper module

Define helper function to load CST data.

get_id(folderpath)[source]

Get the ID of the simulation stored in folderpath.

Parameters:

folderpath (Path) – A mmdd-xxxxxxx folder.

Return type:

int

mmdd_xxxxxxx_folder_to_dict(folderpath, delimiter='\\t')[source]

Put all results from a CST mmdd-xxxxxxx folder to a dict.

The expected structure should look like:

mmdd-xxxxxxx
├── 'Adimensional e.txt'
├── 'Adimensional h.txt'
├── 'E_acc in MV per m.txt'
├──  Parameters.txt
├── 'ParticleInfo [PIC]'
│   ├── 'Emitted Secondaries.txt'
│   └── 'Particle vs. Time.txt'
├── 'TD Number of mesh cells.txt'
└── 'TD Total solver time.txt'

Corresponding output will look like:

dic = {
    'Adimensional e': 4.2,
    'Adimensional h': 2.0,
    'E_acc in MV per m': 4.9,
    'Parameters': {'f': 1e9, 'Period': '1 / f'},
    'Emitted Secondaries': np.array([0, 2, 3]),
    'Particle vs. Time': np.array([100, 102, 105]),
    'TD Number of mesh cells': 4.2,
    'TD Total solver time': 4.2,
}

Note

We skip hidden files, as well as all files in a folder containing the keyword "3d".

Parameters:
  • folderpath (Path) – Path to a mmdd-xxxxxxx folder, holding the results of a single simulation among a parametric simulation export.

  • delimiter (str, optional) – Delimiter between two columns. The default is a tab character.

Returns:

dic – Holds the data of the folder. The keys are the name of the files. It will look like:

Return type:

dict[str, Any]

_parameters_file_to_dict(filepath)[source]

Put the Parameters.txt content in a dictionary.

Todo

Detect integer values.

Todo

Evaluate simple expressions. A parameter defined as ‘1/2’ will be a string instead of 0.5 (float)…

Parameters:

filepath (Path) – Path to the file.

Returns:

parameters – Holds the name of the Parameter as a key, and the corresponding value as a value.

Return type:

dict[str, float | str]

no_extension(filename)[source]

Remove extension from string corresponding to filename.

Parameters:

filename (str)

Return type:

str