43 const bool bad_stokes = sd not_eq
var.StokesDimensions();
44 const bool bad_freq = nf not_eq
var.NumberOfFrequencies();
45 if (bad_freq or bad_stokes)
return true;
53 if (species.nelem()) {
54 for (
auto& spec : species)
55 if (species[0].
Species() not_eq spec.Species() or
56 species[0].Isotopologue() not_eq spec.Isotopologue() or
57 species[0].Type() not_eq spec.Type())
103 const Index& manual_tag,
113 const Index nq = jacobian_quantities_positions.
nelem();
119 const bool do_jac = not jacobian_quantities_positions.
nelem();
121 throw "*abs_species* sub-arrays must have the same species, isotopologue, and type as first sub-array.";
122 if ((
rtp_mag.nelem() not_eq 3) and (not manual_tag))
123 throw "Only for 3D *rtp_mag* or a manual magnetic field";
125 throw "*rtp_vmr* must match *abs_species*";
127 throw "*abs_species* must match *propmat_clearsky*";
129 throw "*propmat_clearsky* must have *stokes_dim* 4 and frequency dim same as *f_grid*";
131 throw "*abs_species* must match *nlte_source* when non-LTE is on";
133 throw "*nlte_source* must have *stokes_dim* 4 and frequency dim same as *f_grid* when non-LTE is on";
135 throw "*dpropmat_clearsky_dx* must match derived form of *jacobian_quantities*";
137 throw "*dpropmat_clearsky_dx* must have Stokes dim 4 and frequency dim same as *f_grid*";
139 throw "*dnlte_dx_source* must match derived form of *jacobian_quantities* when non-LTE is on";
141 throw "*dnlte_dx_source* must have Stokes dim 4 and frequency dim same as *f_grid* when non-LTE is on";
143 throw "*nlte_dsource_dx* must match derived form of *jacobian_quantities* when non-LTE is on";
145 throw "*nlte_dsource_dx* must have Stokes dim 4 and frequency dim same as *f_grid* when non-LTE is on";
151 if (manual_tag and H0 < 0)
throw "Negative manual magnetic field strength";
155 const Numeric dnumdens_dt_dmvr =
174 const auto polarization_scale_dtheta_data =
176 const auto polarization_scale_deta_data =
189 for (
auto polar : {Zeeman::Polarization::SigmaMinus,
190 Zeeman::Polarization::Pi,
198 for (
Index ispecies = 0; ispecies <
ns; ispecies++) {
228 jacobian_quantities_positions,
244 auto pol_real = pol.attenuation();
245 auto pol_imag = pol.dispersion();
249 MapToEigen(
abs).leftCols<4>().noalias() += numdens * sum.
F.real() * pol_real;
250 MapToEigen(
abs).rightCols<3>().noalias() += numdens * sum.
F.imag() * pol_imag;
253 for (
Index j = 0; j < nq; j++) {
256 Eigen::Matrix<Numeric, Eigen::Dynamic, 7, Eigen::RowMajor>>
260 if (deriv == JacPropMatType::Temperature) {
261 dabs.leftCols<4>().noalias() +=
262 numdens * sum.
dF.col(j).real() * pol_real +
263 dnumdens_dT * sum.
F.real() * pol_real;
264 dabs.rightCols<3>().noalias() +=
265 numdens * sum.
dF.col(j).imag() * pol_imag +
266 dnumdens_dT * sum.
F.imag() * pol_imag;
267 }
else if (deriv == JacPropMatType::MagneticU) {
268 dabs.leftCols<4>().noalias() +=
269 numdens * X.dH_du * sum.
dF.col(j).real() * pol_real +
270 numdens * X.deta_du * sum.
F.real() *
271 dpol_deta.attenuation() +
272 numdens * X.dtheta_du * sum.
F.real() *
273 dpol_dtheta.attenuation();
274 dabs.rightCols<3>().noalias() +=
275 numdens * X.dH_du * sum.
dF.col(j).imag() * pol_imag +
276 numdens * X.deta_du * sum.
F.imag() *
277 dpol_deta.dispersion() +
278 numdens * X.dtheta_du * sum.
F.imag() *
279 dpol_dtheta.dispersion();
280 }
else if (deriv == JacPropMatType::MagneticV) {
281 dabs.leftCols<4>().noalias() +=
282 numdens * X.dH_dv * sum.
dF.col(j).real() * pol_real +
283 numdens * X.deta_dv * sum.
F.real() *
284 dpol_deta.attenuation() +
285 numdens * X.dtheta_dv * sum.
F.real() *
286 dpol_dtheta.attenuation();
287 dabs.rightCols<3>().noalias() +=
288 numdens * X.dH_dv * sum.
dF.col(j).imag() * pol_imag +
289 numdens * X.deta_dv * sum.
F.imag() *
290 dpol_deta.dispersion() +
291 numdens * X.dtheta_dv * sum.
F.imag() *
292 dpol_dtheta.dispersion();
293 }
else if (deriv == JacPropMatType::MagneticW) {
294 dabs.leftCols<4>().noalias() +=
295 numdens * X.dH_dw * sum.
dF.col(j).real() * pol_real +
296 numdens * X.deta_dw * sum.
F.real() *
297 dpol_deta.attenuation() +
298 numdens * X.dtheta_dw * sum.
F.real() *
299 dpol_dtheta.attenuation();
300 dabs.rightCols<3>().noalias() +=
301 numdens * X.dH_dw * sum.
dF.col(j).imag() * pol_imag +
302 numdens * X.deta_dw * sum.
F.imag() *
303 dpol_deta.dispersion() +
304 numdens * X.dtheta_dw * sum.
F.imag() *
305 dpol_dtheta.dispersion();
306 }
else if (deriv == JacPropMatType::VMR and
307 deriv.QuantumIdentity().In(band.QuantumIdentity())) {
308 dabs.leftCols<4>().noalias() +=
309 numdens * sum.
dF.col(j).real() * pol_real +
310 dnumdens_dmvr * sum.
F.real() * pol_real;
311 dabs.rightCols<3>().noalias() +=
312 numdens * sum.
dF.col(j).imag() * pol_imag +
313 dnumdens_dmvr * sum.
F.imag() * pol_imag;
315 dabs.leftCols<4>().noalias() +=
316 numdens * sum.
dF.col(j).real() * pol_real;
317 dabs.rightCols<3>().noalias() +=
318 numdens * sum.
dF.col(j).imag() * pol_imag;
330 .noalias() += numdens * eB.cwiseProduct(sum.
N.real()) * pol_real;
332 for (
Index j = 0; j < nq; j++) {
337 Eigen::Matrix<Numeric, Eigen::Dynamic, 4, Eigen::RowMajor>>
343 if (deriv == JacPropMatType::Temperature) {
344 dnlte_dx_src.noalias() +=
345 dnumdens_dT * eB.cwiseProduct(sum.
N.real()) * pol_real +
346 numdens * eB.cwiseProduct(sum.
dN.col(j).real()) * pol_real;
348 nlte_dsrc_dx.noalias() +=
349 numdens * edBdT.cwiseProduct(sum.
N.real()) * pol_real;
350 }
else if (deriv == JacPropMatType::MagneticU)
351 dnlte_dx_src.noalias() +=
352 numdens * X.dH_du * eB.cwiseProduct(sum.
dN.col(j).real()) * pol_real +
353 numdens * X.deta_du * eB.cwiseProduct(sum.
N.real()) *
354 dpol_deta.attenuation() +
355 numdens * X.dtheta_du * eB.cwiseProduct(sum.
N.real()) *
356 dpol_dtheta.attenuation();
357 else if (deriv == JacPropMatType::MagneticV)
358 dnlte_dx_src.noalias() +=
359 numdens * X.dH_dv * eB.cwiseProduct(sum.
dN.col(j).real()) * pol_real +
360 numdens * X.deta_dv * eB.cwiseProduct(sum.
N.real()) *
361 dpol_deta.attenuation() +
362 numdens * X.dtheta_dv * eB.cwiseProduct(sum.
N.real()) *
363 dpol_dtheta.attenuation();
364 else if (deriv == JacPropMatType::MagneticW)
365 dnlte_dx_src.noalias() +=
366 numdens * X.dH_dw * eB.cwiseProduct(sum.
dN.col(j).real()) * pol_real +
367 numdens * X.deta_dw * eB.cwiseProduct(sum.
N.real()) *
368 dpol_deta.attenuation() +
369 numdens * X.dtheta_dw * eB.cwiseProduct(sum.
N.real()) *
370 dpol_dtheta.attenuation();
371 else if (deriv == JacPropMatType::VMR and
372 deriv.QuantumIdentity().In(band.QuantumIdentity()))
373 dnlte_dx_src.noalias() +=
374 dnumdens_dmvr * eB.cwiseProduct(sum.
N.real()) * pol_real +
375 numdens * eB.cwiseProduct(sum.
dN.col(j).real()) * pol_real;
377 dnlte_dx_src.noalias() +=
378 numdens * eB.cwiseProduct(sum.
dN.col(j).real()) * pol_real;
384 }
catch (
const char* e) {
385 std::ostringstream os;
386 os <<
"Errors raised by *zeeman_on_the_fly* internal function:\n";
387 os <<
"\tError: " << e <<
'\n';
388 throw std::runtime_error(os.str());
389 }
catch (
const std::exception& e) {
391 std::ostringstream os;
392 os <<
"Errors in calls by *zeeman_on_the_fly* internal function:\n";
394 throw std::runtime_error(os.str());