|
| 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