Skip to content

Commit 3408904

Browse files
authored
Merge pull request #40 from vsnever/enhancement/old_fort44_parser
Fort44 parser for pre 2007 Eirene fort.44 file versions
2 parents 6999c77 + e6430a3 commit 3408904

2 files changed

Lines changed: 123 additions & 2 deletions

File tree

cherab/solps/eirene/parser/fort44.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from cherab.solps.eirene.parser.fort44_2017 import load_fort44_2017
2020
from cherab.solps.eirene.parser.fort44_2013 import load_fort44_2013
21+
from cherab.solps.eirene.parser.fort44_pre_2007 import load_fort44_pre_2007
2122

2223

2324
def load_fort44_file(file_path, debug=False):
@@ -58,9 +59,24 @@ def assign_fort44_parser(file_version):
5859
:return: Parsing function object
5960
"""
6061

62+
# TODO write universal fort44 parser
63+
64+
# Parser load_fort44_pre_2007 is used also for 20071209, 20080706 and 20081111
65+
# versions as a temporary solution. Parameter 'eneutrad' is not parsed from these file versions.
6166
fort44_parser_library = {
62-
20170328: load_fort44_2017,
63-
20130210: load_fort44_2013
67+
960511: load_fort44_pre_2007,
68+
960513: load_fort44_pre_2007,
69+
960623: load_fort44_pre_2007,
70+
960727: load_fort44_pre_2007,
71+
961228: load_fort44_pre_2007,
72+
20000727: load_fort44_pre_2007,
73+
20051115: load_fort44_pre_2007,
74+
20060206: load_fort44_pre_2007,
75+
20071209: load_fort44_pre_2007,
76+
20080706: load_fort44_pre_2007,
77+
20081111: load_fort44_pre_2007,
78+
20130210: load_fort44_2013,
79+
20170328: load_fort44_2017
6480
}
6581

6682
if file_version in fort44_parser_library.keys():
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Copyright 2016-2018 Euratom
2+
# Copyright 2016-2018 United Kingdom Atomic Energy Authority
3+
# Copyright 2016-2018 Centro de Investigaciones Energéticas, Medioambientales y Tecnológicas
4+
#
5+
# Licensed under the EUPL, Version 1.1 or – as soon they will be approved by the
6+
# European Commission - subsequent versions of the EUPL (the "Licence");
7+
# You may not use this work except in compliance with the Licence.
8+
# You may obtain a copy of the Licence at:
9+
#
10+
# https://joinup.ec.europa.eu/software/page/eupl5
11+
#
12+
# Unless required by applicable law or agreed to in writing, software distributed
13+
# under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR
14+
# CONDITIONS OF ANY KIND, either express or implied.
15+
#
16+
# See the Licence for the specific language governing permissions and limitations
17+
# under the Licence.
18+
19+
from cherab.solps.eirene import Eirene
20+
from cherab.solps.eirene.parser.utility import read_block44
21+
22+
23+
def load_fort44_pre_2007(file_path, debug=False):
24+
""" Read neutral species and wall flux information from fort.44
25+
26+
Template for reading is ngread.F in b2plot of B2.5 source.
27+
This is for fort.44 files with format ID < 20071209.
28+
29+
:param str file_path: path to the fort.44 file
30+
:param bool debug: status flag for printing debugging output
31+
:rtype:
32+
"""
33+
34+
with open(file_path, 'r') as file_handle:
35+
# Read sizes
36+
line = file_handle.readline().split()
37+
nx = int(line[0])
38+
ny = int(line[1])
39+
version = int(line[2])
40+
if debug:
41+
print('Geometry & Version : nx {}, ny {}, version {}'
42+
.format(nx, ny, version))
43+
44+
# Read Species numbers
45+
line = file_handle.readline().split()
46+
na = int(line[0]) # number of atoms
47+
nm = int(line[1]) # number of molecules
48+
ni = int(line[2]) # number of ions
49+
ns = na + nm + ni # total number of species
50+
if debug:
51+
print('Species # : {} atoms, {} molecules, {} ions, {} total species'
52+
.format(na, nm, ni, ns))
53+
54+
# Read Species labels
55+
species_labels = []
56+
for _ in range(ns):
57+
line = file_handle.readline()
58+
species_labels.append(line.strip())
59+
if debug:
60+
print("Species labels => {}".format(species_labels))
61+
62+
# create eirene object
63+
eirene = Eirene(nx, ny, na, nm, ni, ns, species_labels, version)
64+
65+
# Read atomic species (da, ta)
66+
eirene.da = read_block44(file_handle, eirene.na, nx, ny) # Atomic Neutral Density
67+
eirene.ta = read_block44(file_handle, eirene.na, nx, ny) # Atomic Neutral Temperature
68+
if debug:
69+
print('Atomic Neutral Density nD0: ', eirene.da[0, :, 0])
70+
print('Atomic Neutral Temperature TD0: ', eirene.ta[0, :, 0])
71+
72+
# Read molecular species (dm, tm)
73+
eirene.dm = read_block44(file_handle, eirene.nm, nx, ny) # Molecular Neutral Density
74+
eirene.tm = read_block44(file_handle, eirene.nm, nx, ny) # Molecular Neutral Temperature
75+
76+
# Read ion species (di, ti)
77+
eirene.di = read_block44(file_handle, eirene.ni, nx, ny) # Test Ion Density
78+
eirene.ti = read_block44(file_handle, eirene.ni, nx, ny) # Test Ion Temperature
79+
80+
# Read radial particle flux (rpa, rpm)
81+
eirene.rpa = read_block44(file_handle, eirene.na, nx, ny) # Atomic Radial Particle Flux
82+
eirene.rpm = read_block44(file_handle, eirene.nm, nx, ny) # Molecular Radial Particle Flux
83+
84+
# Read poloidal particle flux (ppa, ppm)
85+
eirene.ppa = read_block44(file_handle, eirene.na, nx, ny) # Atomic Poloidal Particle Flux
86+
eirene.ppm = read_block44(file_handle, eirene.nm, nx, ny) # Molecular Poloidal Particle Flux
87+
88+
# Read radial energy flux (rea, rem)
89+
eirene.rea = read_block44(file_handle, eirene.na, nx, ny) # Atomic Radial Energy Flux
90+
eirene.rem = read_block44(file_handle, eirene.nm, nx, ny) # Molecular Radial Energy Flux
91+
92+
# Read poloidal energy flux (pea, pem)
93+
eirene.pea = read_block44(file_handle, eirene.na, nx, ny) # Atomic Poloidal Energy Flux
94+
eirene.pem = read_block44(file_handle, eirene.nm, nx, ny) # Molecular Poloidal Energy Flux
95+
96+
# Halpha total & molecules (emist, emism)
97+
eirene.emist = read_block44(file_handle, 1, nx, ny) # Total Halpha Emission (including molecules)
98+
eirene.emism = read_block44(file_handle, 1, nx, ny) # Molecular Halpha Emission
99+
100+
if version >= 960511:
101+
# Radiated power (elosm, edism)
102+
eirene.elosm = read_block44(file_handle, nm, nx, ny) # Power loss due to molecules (including dissociation)
103+
eirene.edism = read_block44(file_handle, nm, nx, ny) # Power loss due to molecule dissociation
104+
105+
return eirene

0 commit comments

Comments
 (0)