ARTS 2.5.9 (git: 825fa5f2)
gui_propmat.cc
Go to the documentation of this file.
1#include <atomic>
2#include <chrono>
3#include <cstdlib>
4#include <functional>
5#include <future>
6#include <iterator>
7#include <mutex>
8#include <stdexcept>
9#include <thread>
10
11#include "agenda_class.h"
12#include "artstime.h"
13#include "auto_md.h"
14#include "debug.h"
15#include "energylevelmap.h"
16#include "jacobian.h"
17#include "messages.h"
18#include "propagationmatrix.h"
19#include "species_tags.h"
20#include "transmissionmatrix.h"
21#include "workspace_ng.h"
22
23#ifdef ARTS_GUI_ENABLED
24#include <gui/propmat.h>
25
26namespace PropmatClearskyAgendaGUI {
27void compute(Workspace& ws,
28 ARTSGUI::PropmatClearsky::ComputeValues& v,
29 const Agenda& propmat_clearsky_agenda) {
31 v.pm,
32 v.sv,
33 v.aopm,
34 v.aosv,
35 v.jacobian_quantities,
36 v.select_abs_species,
37 v.f_grid,
38 v.rtp_mag,
39 v.rtp_los,
40 v.rtp_pressure,
41 v.rtp_temperature,
42 v.rtp_nlte,
43 v.rtp_vmr,
44 propmat_clearsky_agenda);
45}
46
47bool run(ARTSGUI::PropmatClearsky::ResultsArray& ret,
48 ARTSGUI::PropmatClearsky::Control& ctrl,
49 Workspace& ws,
50 const Agenda& propmat_clearsky_agenda,
51 ArrayOfRetrievalQuantity& jacobian_quantities,
52 ArrayOfSpeciesTag& select_abs_species,
53 Vector& f_grid,
54 Vector& rtp_mag,
55 Vector& rtp_los,
56 Numeric& rtp_pressure,
57 Numeric& rtp_temperature,
58 EnergyLevelMap& rtp_nlte,
59 Vector& rtp_vmr,
60 Numeric& transmission_distance) {
61 for (auto& v : ret) v.ok.store(false);
62 ARTSGUI::PropmatClearsky::ComputeValues v;
63
64 while (true) {
65 std::this_thread::sleep_for(10ms);
66
67 try {
68 if (ctrl.exit.load()) return true;
69
70 if (ctrl.error.load()) continue;
71
72 if (ctrl.run.load()) {
73 std::lock_guard allow_copy{ctrl.copy};
74
75 v.jacobian_quantities = jacobian_quantities;
76 v.select_abs_species = select_abs_species;
77 v.f_grid = f_grid;
78 v.rtp_mag = rtp_mag;
79 v.rtp_los = rtp_los;
80 v.rtp_pressure = rtp_pressure;
81 v.rtp_temperature = rtp_temperature;
82 v.rtp_nlte = rtp_nlte;
83 v.rtp_vmr = rtp_vmr;
84 v.transmission_distance = transmission_distance;
85 } else {
86 continue;
87 }
88
89 compute(ws, v, propmat_clearsky_agenda);
90
91 v.tm = TransmissionMatrix(v.pm.NumberOfFrequencies(), v.pm.StokesDimensions());
92 v.aotm = ArrayOfTransmissionMatrix(v.jacobian_quantities.nelem(), v.tm);
93 auto local_aotm = v.aotm;
95 v.aotm,
96 local_aotm,
97 v.pm,
98 v.pm,
99 v.aopm,
100 v.aopm,
101 v.transmission_distance,
102 0,
103 0,
104 -1);
105
106 // Lock after the compute to copy values
107 std::lock_guard allow_copy{ctrl.copy};
108
109 // Copy over values
110 ret.at(ctrl.pos).value = v;
111 ret.at(ctrl.pos).ok.store(true);
112
113 ctrl.run.store(false);
114 } catch (std::runtime_error& e) {
115 ctrl.errmsg = e.what();
116 ctrl.error.store(true);
117 ctrl.run.store(false);
118 }
119 }
120
121 return false;
122}
123} // namespace PropmatClearskyAgendaGUI
124#endif // ARTS_GUI_ENABLED
125
126void propmat_clearsky_agendaGUI(Workspace& ws [[maybe_unused]],
127 const Agenda& propmat_clearsky_agenda [[maybe_unused]],
128 const ArrayOfArrayOfSpeciesTag& abs_species [[maybe_unused]],
129 const Index& load [[maybe_unused]],
130 const Verbosity& verbosity [[maybe_unused]]) {
131#ifdef ARTS_GUI_ENABLED
132 ARTSGUI::PropmatClearsky::ResultsArray res;
133 ARTSGUI::PropmatClearsky::Control ctrl;
134
135 // Initialize values to something
136 ArrayOfRetrievalQuantity jacobian_quantities{};
137 ArrayOfSpeciesTag select_abs_species{};
138 Vector f_grid(1e9, 1000, 1e9);
139 Vector rtp_mag(3, 0);
140 Vector rtp_los(2, 0);
141 Numeric rtp_pressure{1000};
142 Numeric rtp_temperature(300);
143 EnergyLevelMap rtp_nlte{};
144 Vector rtp_vmr(abs_species.nelem(), 1.0/Numeric(abs_species.nelem()));
145 Numeric transmission_distance{1'000};
146
147 // Set some defaults
148 if (load) {
149 if (auto* val = ws.get<Vector>("f_grid")) f_grid = *val;
150 if (auto* val = ws.get<Vector>("rtp_mag")) rtp_mag = *val;
151 if (auto* val = ws.get<Vector>("rtp_los")) rtp_los = *val;
152 if (auto* val = ws.get<Vector>("rtp_vmr")) rtp_vmr = *val;
153 if (auto* val = ws.get<Numeric>("rtp_pressure")) rtp_pressure = *val;
154 if (auto* val = ws.get<Numeric>("rtp_temperature")) rtp_temperature = *val;
155 if (auto* val = ws.get<EnergyLevelMap>("rtp_nlte")) rtp_nlte = *val;
156 }
157
158 auto success = std::async(std::launch::async,
159 &PropmatClearskyAgendaGUI::run,
160 std::ref(res),
161 std::ref(ctrl),
162 std::ref(ws),
163 std::cref(propmat_clearsky_agenda),
164 std::ref(jacobian_quantities),
165 std::ref(select_abs_species),
166 std::ref(f_grid),
167 std::ref(rtp_mag),
168 std::ref(rtp_los),
169 std::ref(rtp_pressure),
170 std::ref(rtp_temperature),
171 std::ref(rtp_nlte),
172 std::ref(rtp_vmr),
173 std::ref(transmission_distance));
174
175 if (std::getenv("ARTS_HEADLESS")) {
177 out1 << "Omitting GUI because ARTS_HEADLESS is set.\n";
178
179 ctrl.run.store(true);
180 while (not(res[0].ok.load() or ctrl.exit.load())) {
181 std::this_thread::sleep_for(10ms);
182 }
183 ctrl.exit.store(true);
184 } else {
185 ARTSGUI::propmat(res,
186 ctrl,
187 jacobian_quantities,
188 select_abs_species,
189 f_grid,
190 rtp_mag,
191 rtp_los,
192 rtp_pressure,
193 rtp_temperature,
194 rtp_nlte,
195 rtp_vmr,
196 transmission_distance,
197 ArrayOfArrayOfSpeciesTag{abs_species});
198 }
199
200 bool invalid_state = not success.get();
201 ARTS_USER_ERROR_IF(invalid_state, '\n', ctrl.error)
202
203#else // ARTS_GUI_ENABLED not defined
204 ARTS_USER_ERROR("Did not compile with GUI")
205#endif // ARTS_GUI_ENABLED
206}
Declarations for agendas.
Stuff related to time in ARTS.
void propmat_clearsky_agendaExecute(Workspace &ws, PropagationMatrix &propmat_clearsky, StokesVector &nlte_source, ArrayOfPropagationMatrix &dpropmat_clearsky_dx, ArrayOfStokesVector &dnlte_source_dx, const ArrayOfRetrievalQuantity &jacobian_quantities, const ArrayOfSpeciesTag &select_abs_species, const Vector &f_grid, const Vector &rtp_mag, const Vector &rtp_los, const Numeric rtp_pressure, const Numeric rtp_temperature, const EnergyLevelMap &rtp_nlte, const Vector &rtp_vmr, const Agenda &input_agenda)
Definition: auto_md.cc:25665
The Agenda class.
Definition: agenda_class.h:69
This can be used to make arrays out of anything.
Definition: array.h:48
The Vector class.
Definition: matpackI.h:910
Workspace class.
Definition: workspace_ng.h:53
T * get(const char *name)
Retrieve a value ptr if it exist (FIXME: C++20 allows const char* as template argument)
Definition: workspace_ng.h:188
Helper macros for debugging.
#define ARTS_USER_ERROR(...)
Definition: debug.h:150
#define ARTS_USER_ERROR_IF(condition,...)
Definition: debug.h:134
Class to map energy levels.
void propmat_clearsky_agendaGUI(Workspace &ws, const Agenda &propmat_clearsky_agenda, const ArrayOfArrayOfSpeciesTag &abs_species, const Index &load, const Verbosity &verbosity)
WORKSPACE METHOD: propmat_clearsky_agendaGUI.
Definition: gui_propmat.cc:126
Routines for setting up the jacobian.
NUMERIC Numeric
The type to use for all floating point numbers.
Definition: matpack.h:33
INDEX Index
The type to use for all integer numbers and indices.
Definition: matpack.h:39
Declarations having to do with the four output streams.
#define CREATE_OUT1
Definition: messages.h:204
constexpr Numeric e
Elementary charge convenience name [C].
MagneticField compute(const Tensor3 &z_field, const Vector &lat_grid, const Vector &lon_grid, const Time &time, const Vector &ell)
Computes the magnetic field based on IGRF13 coefficients.
Definition: igrf13.cc:283
Stuff related to the propagation matrix.
Class to keep track of Transmission Matrices for Stokes Dim 1-4.
void stepwise_transmission(TransmissionMatrix &T, ArrayOfTransmissionMatrix &dT1, ArrayOfTransmissionMatrix &dT2, const PropagationMatrix &K1, const PropagationMatrix &K2, const ArrayOfPropagationMatrix &dK1, const ArrayOfPropagationMatrix &dK2, const Numeric &r, const Numeric &dr_dtemp1, const Numeric &dr_dtemp2, const Index temp_deriv_pos)
Set the stepwise transmission matrix.
Stuff related to the transmission matrix.
#define v
Array< TransmissionMatrix > ArrayOfTransmissionMatrix
This file contains the Workspace class.