34 #ifndef propagationmatrix_h 35 #define propagationmatrix_h 101 const Index stokes_dim = 1,
102 const Index nr_za = 1,
103 const Index nr_aa = 1,
105 : mfreqs(nr_frequencies),
106 mstokes_dim(stokes_dim),
110 assert(mstokes_dim < 5 and mstokes_dim > 0);
111 mdata =
Tensor4(maa, mza, mfreqs, NumberOfNeededVectors(), v);
120 mstokes_dim(pm.mstokes_dim),
124 mvectortype(pm.mvectortype) {}
131 : mfreqs(std::move(
pm.mfreqs)),
132 mstokes_dim(std::move(
pm.mstokes_dim)),
133 mza(std::move(
pm.mza)),
134 maa(std::move(
pm.maa)),
135 mdata(std::move(
pm.mdata)),
136 mvectortype(std::move(
pm.mvectortype)) {}
162 throw std::runtime_error(
163 "Tensor4 not representative of PropagationMatrix");
173 : mfreqs(1), mstokes_dim(x.ncols()), mza(1), maa(1) {
174 assert(mstokes_dim < 5 and mstokes_dim > 0);
177 if (not assume_fit) {
178 if (not FittingShape(x)) {
179 throw std::runtime_error(
"Matrix not fit as propagation matrix");
183 mdata.resize(1, 1, 1, NumberOfNeededVectors());
185 switch (mstokes_dim) {
187 mdata(0, 0, 0, 5) = x(1, 3);
188 mdata(0, 0, 0, 6) = x(2, 3);
189 mdata(0, 0, 0, 3) = x(0, 3);
191 mdata(0, 0, 0, mstokes_dim) = x(1, 2);
192 mdata(0, 0, 0, 2) = x(0, 2);
194 mdata(0, 0, 0, 1) = x(0, 1);
196 mdata(0, 0, 0, 0) = x(0, 0);
212 bool OK()
const {
return mdata.ncols() == NumberOfNeededVectors() and mdata.nrows() == mfreqs and mdata.npages() == mza and mdata.nbooks() == maa;}
221 bool IsEmpty()
const {
return not mfreqs or not mza or not maa; };
232 const Index ia = 0)
const {
235 for (
auto&
n : mdata(ia, iz, iv,
joker))
236 if (
n not_eq 0)
return false;
249 const Index ia = 0)
const {
250 if (mdata(ia, iz, iv, 0) == 0.0)
258 if (not mvectortype) {
259 switch (mstokes_dim) {
273 throw std::runtime_error(
274 "Cannot understand the input in PropagationMatrix");
286 const Index ia = 0)
const;
300 const Index ia = 0) {
301 mdata(ia, iz, iv, mstokes_dim) += rot;
316 const Index ia = 0) {
317 mdata(ia, iz, iv, mstokes_dim) = rot;
330 const Index ia = 0)
const;
339 mfreqs = std::move(
pm.mfreqs);
340 mstokes_dim = std::move(
pm.mstokes_dim);
341 mza = std::move(
pm.mza);
342 maa = std::move(
pm.maa);
343 mdata = std::move(
pm.mdata);
344 mvectortype = std::move(
pm.mvectortype);
395 const Index ia = 0) {
422 const Index ia = 0) {
423 mdata(ia, iz, iv,
joker) = x;
432 mdata /= other.
mdata;
442 for (
Index i = 0;
i < NumberOfNeededVectors();
i++) {
443 for (
Index j = 0; j < mza; j++) {
444 for (
Index k = 0; k < maa; k++) {
445 mdata(k, j,
joker,
i) /= x;
472 const Index ia = 0) {
498 const Index ia = 0) {
499 mdata(ia, iz, iv,
joker) /= x;
508 mdata *= other.
mdata;
518 for (
Index i = 0;
i < NumberOfNeededVectors();
i++)
519 for (
Index j = 0; j < mza; j++)
520 for (
Index k = 0; k < maa; k++) mdata(k, j,
joker,
i) *= x;
544 const Index ia = 0) {
570 const Index ia = 0) {
571 mdata(ia, iz, iv,
joker) *= x;
580 mdata += other.
mdata;
590 MultiplyAndAdd(lpms.
scale, lpms.
bas);
600 for (
Index i = 0;
i < NumberOfNeededVectors();
i++)
601 for (
Index j = 0; j < mza; j++)
602 for (
Index k = 0; k < maa; k++) mdata(k, j,
joker,
i) += x;
626 const Index ia = 0) {
652 const Index ia = 0) {
653 mdata(ia, iz, iv,
joker) += x;
662 mdata -= other.
mdata;
672 for (
Index i = 0;
i < NumberOfNeededVectors();
i++) {
673 for (
Index j = 0; j < mza; j++) {
674 for (
Index k = 0; k < maa; k++) {
675 mdata(k, j,
joker,
i) -= x;
702 const Index ia = 0) {
728 const Index ia = 0) {
729 mdata(ia, iz, iv,
joker) -= x;
742 const Index ia = 0) {
743 for (
Index i = 0;
i < mstokes_dim;
i++) mdata(ia, iz, iv,
i) += x[
i];
777 const Index ia = 0)
const;
800 return mdata(ia, iz,
joker, 0);
810 return mdata(ia, iz,
joker, 1);
820 return mdata(ia, iz,
joker, 2);
830 return mdata(ia, iz,
joker, 3);
840 return mdata(ia, iz,
joker, mstokes_dim);
850 return mdata(ia, iz,
joker, 5);
860 return mdata(ia, iz,
joker, 6);
870 return mdata(ia, iz,
joker, 0);
880 return mdata(ia, iz,
joker, 1);
890 return mdata(ia, iz,
joker, 2);
900 return mdata(ia, iz,
joker, 3);
910 return mdata(ia, iz,
joker, mstokes_dim);
920 return mdata(ia, iz,
joker, 5);
930 return mdata(ia, iz,
joker, 6);
954 const Index ia = 0)
const;
969 const Index ia = 0)
const;
1002 const Index ia = 0);
1024 const Index ia = 0);
1060 const Index it = -1,
1062 const Index ia = 0);
1068 std::ostream&
operator<<(std::ostream& os,
const ArrayOfPropagationMatrix& apm);
1072 const ArrayOfArrayOfPropagationMatrix& aapm);
1090 const Index stokes_dim = 1,
1091 const Index nr_za = 1,
1092 const Index nr_aa = 1,
1095 mfreqs = nr_frequencies;
1096 mstokes_dim = stokes_dim;
1099 assert(mstokes_dim < 5 and mstokes_dim > 0);
1100 mdata =
Tensor4(maa, mza, mfreqs, mstokes_dim, v);
1109 mstokes_dim = x.
ncols();
1114 if (mstokes_dim > 4 or mstokes_dim < 1)
1115 throw std::runtime_error(
"Tensor4 is bad for StokesVector");
1124 mstokes_dim = x.
nelem();
1127 assert(mstokes_dim < 5 and mstokes_dim > 0);
1129 mdata.resize(1, 1, 1, mstokes_dim);
1130 for (
Index i = 0;
i < mstokes_dim;
i++) mdata(0, 0, 0,
i) = x[
i];
1146 mdata.resize(maa, mza, mfreqs, mstokes_dim);
1150 for (
Index j = 0; j < mza; j++)
1151 for (
Index k = 0; k < mfreqs; k++) {
1152 switch (mstokes_dim) {
1154 mdata(
i, j, k, 3) = (a.
mdata(
i, j, k, 3) + b.
mdata(
i, j, k, 3)) *
1157 mdata(
i, j, k, 2) = (a.
mdata(
i, j, k, 2) + b.
mdata(
i, j, k, 2)) *
1160 mdata(
i, j, k, 1) = (a.
mdata(
i, j, k, 1) + b.
mdata(
i, j, k, 1)) *
1163 mdata(
i, j, k, 0) = (a.
mdata(
i, j, k, 0) + b.
mdata(
i, j, k, 0)) *
1188 MultiplyAndAdd(lpms.
scale, lpms.
bas);
1202 mdata.resize(maa, mza, mfreqs, mstokes_dim);
1203 mdata(
joker,
joker,
joker,
Range(0, mstokes_dim, 1)) = x.
Data()(
joker,
joker,
joker,
Range(0, mstokes_dim, 1));
1213 operator=(lpms.
bas);
1214 mdata *= lpms.
scale;
1242 for (
Index j = 0; j < mza; j++) {
1243 for (
Index k = 0; k < mfreqs; k++) {
1244 switch (mstokes_dim) {
1246 mdata(
i, j, k, 3) += x *
data(
i, j, k, 3);
1248 mdata(
i, j, k, 2) += x *
data(
i, j, k, 2);
1250 mdata(
i, j, k, 1) += x *
data(
i, j, k, 1);
1252 mdata(
i, j, k, 0) += x *
data(
i, j, k, 0);
1268 const Index ia = 0) {
1269 return mdata(ia, iz, iv,
joker);
1281 const Index ia = 0)
const {
1282 return mdata(ia, iz, iv,
joker);
1288 const Index ia = 0) {
1289 mdata(ia, iz, iv,
joker) = x;
1304 const Index ia = 0) {
1305 switch (mstokes_dim) {
1307 mdata(ia, iz, iv, 3) += (vec1[3] + vec2[3]) * 0.5;
1309 mdata(ia, iz, iv, 2) += (vec1[2] + vec2[2]) * 0.5;
1311 mdata(ia, iz, iv, 1) += (vec1[1] + vec2[1]) * 0.5;
1313 mdata(ia, iz, iv, 0) += (vec1[0] + vec2[0]) * 0.5;
1327 const Index ia = 0)
const {
1328 switch (mstokes_dim) {
1330 if (K14(iz, ia)[iv] not_eq 0.0)
return true;
1332 if (K13(iz, ia)[iv] not_eq 0.0)
return true;
1334 if (K12(iz, ia)[iv] not_eq 0.0)
return true;
1349 const Index ia = 0)
const {
1350 return not IsPolarized(iv, iz, ia);
1359 std::ostream&
operator<<(std::ostream& os,
const ArrayOfStokesVector& apm);
1361 const ArrayOfArrayOfStokesVector& aapm);
1385 #endif //propagationmatrix_h INDEX Index
The type to use for all integer numbers and indices.
void compute_transmission_matrix(Tensor3View T, const Numeric &r, const PropagationMatrix &upper_level, const PropagationMatrix &lower_level, const Index iz=0, const Index ia=0)
Compute the matrix exponent as the transmission matrix of this propagation matrix.
ConstVectorView K23(const Index iz=0, const Index ia=0) const
Vector view to K(1, 3) elements.
Array< PropagationMatrix > ArrayOfPropagationMatrix
VectorView VectorAtPosition(const Index iv=0, const Index iz=0, const Index ia=0)
Get a vectorview to the position.
void MultiplyAndAdd(const Numeric x, const PropagationMatrix &y)
Add a scaled version of the input.
PropagationMatrix & operator/=(const PropagationMatrix &other)
Divide operator.
A class implementing complex numbers for ARTS.
Index NumberOfAzimuthAngles() const
The number of azimuth angles of the propagation matrix.
void compute_transmission_matrix_from_averaged_matrix_at_frequency(MatrixView T, const Numeric &r, const PropagationMatrix &averaged_propagation_matrix, const Index iv, const Index iz=0, const Index ia=0)
Compute the matrix exponent as the transmission matrix of this propagation matrix.
void RemoveAtPosition(const Numeric &x, const Index iv=0, const Index iz=0, const Index ia=0)
Subtraction at position.
bool IsRotational(const Index iv=0, const Index iz=0, const Index ia=0) const
False if diagonal element is non-zero in internal Matrix representation.
Index NumberOfNeededVectors() const
The number of required vectors to fill this PropagationMatrix.
void SetAtPosition(const PropagationMatrix &x, const Index iv=0, const Index iz=0, const Index ia=0)
Set the At Position object.
Index NumberOfNeededVectors() const
The number of required vectors to fill this StokesVector.
bool IsZero(const Index iv=0, const Index iz=0, const Index ia=0) const
False if any non-zeroes in internal Matrix representation.
ConstVectorView K12(const Index iz=0, const Index ia=0) const
Vector view to K(0, 1) elements.
void SetFaraday(const Numeric &rot, const Index iv=0, const Index iz=0, const Index ia=0)
Sets the Faraday rotation to the PropagationMatrix at required position.
Array< StokesVector > ArrayOfStokesVector
ConstVectorView Kjj(const Index iz=0, const Index ia=0) const
Vector view to diagonal elements.
Index npages() const
Returns the number of pages.
PropagationMatrix(PropagationMatrix &&pm) noexcept
Construct a new Propagation Matrix object.
PropagationMatrix(ConstTensor4View x)
Construct a new Propagation Matrix object.
bool IsEmpty() const
Asks if the class is empty.
void MultiplyAtPosition(const Numeric &x, const Index iv=0, const Index iz=0, const Index ia=0)
Multiply operator at position.
VectorView K24(const Index iz=0, const Index ia=0)
Vector view to K(1, 3) elements.
PropagationMatrix & operator-=(ConstVectorView x)
Subtraction operator.
std::ostream & operator<<(std::ostream &os, const PropagationMatrix &pm)
output operator
Class to help with hidden temporary variables for operations of type Numeric times Class...
ConstVectorView K13(const Index iz=0, const Index ia=0) const
Vector view to K(0, 2) elements.
void SetAtPosition(const Numeric &x, const Index iv=0, const Index iz=0, const Index ia=0)
Set the At Position object.
Stokes vector is as Propagation matrix but only has 4 possible values.
PropagationMatrix & operator+=(ConstVectorView x)
Addition operator.
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
ConstVectorView K24(const Index iz=0, const Index ia=0) const
Vector view to K(1, 3) elements.
void AddAbsorptionVectorAtPosition(ConstVectorView x, const Index iv=0, const Index iz=0, const Index ia=0)
Adds as a Stokes vector at position.
bool IsUnpolarized(const Index iv=0, const Index iz=0, const Index ia=0) const
Checks if vector is polarized.
Index nrows() const
Returns the number of rows.
PropagationMatrix & operator+=(const PropagationMatrix &other)
Addition operator.
VectorView K23(const Index iz=0, const Index ia=0)
Vector view to K(1, 2) elements.
Index nelem() const
Returns the number of elements.
A constant view of a Tensor4.
VectorView K13(const Index iz=0, const Index ia=0)
Vector view to K(0, 2) elements.
PropagationMatrix & operator/=(const Numeric &x)
Divide operator.
StokesVector & operator=(const LazyScale< PropagationMatrix > &lpms)
Set this lazily.
VectorView K12(const Index iz=0, const Index ia=0)
Vector view to K(0, 1) elements.
void MultiplyAtPosition(const PropagationMatrix &x, const Index iv=0, const Index iz=0, const Index ia=0)
Multiply operator at position.
Array< ArrayOfArrayOfStokesVector > ArrayOfArrayOfArrayOfStokesVector
VectorView K34(const Index iz=0, const Index ia=0)
Vector view to K(2, 3) elements.
LazyScale(const base &t, const Numeric &x)
Construct a new Lazy Scale object.
void RemoveAtPosition(const PropagationMatrix &x, const Index iv=0, const Index iz=0, const Index ia=0)
Subtraction at position.
Index NumberOfZenithAngles() const
The number of zenith angles of the propagation matrix.
PropagationMatrix & operator*=(const PropagationMatrix &other)
Multiply operator.
StokesVector(ConstTensor4View x)
Construct a new Propagation Matrix object.
PropagationMatrix & operator+=(const Numeric &x)
Addition operator.
bool IsPolarized(const Index iv=0, const Index iz=0, const Index ia=0) const
Checks if vector is polarized.
PropagationMatrix & operator+=(const LazyScale< PropagationMatrix > &lpms)
Addition operator.
PropagationMatrix & operator=(const PropagationMatrix &other)
Copy operator.
PropagationMatrix & operator=(const LazyScale< PropagationMatrix > &lpms)
Laze equal to opeartor.
ConstVectorView K34(const Index iz=0, const Index ia=0) const
Vector view to diagonal elements.
void AddAtPosition(const Numeric &x, const Index iv=0, const Index iz=0, const Index ia=0)
Addition at position operator.
PropagationMatrix(const PropagationMatrix &pm)
Construct a new Propagation Matrix object.
PropagationMatrix & operator/=(ConstVectorView x)
Divide operator.
NUMERIC Numeric
The type to use for all floating point numbers.
Index StokesDimensions() const
The stokes dimension of the propagation matrix.
Array< ArrayOfStokesVector > ArrayOfArrayOfStokesVector
LazyScale< PropagationMatrix > operator*(const PropagationMatrix &pm, const Numeric &x)
Returns a lazy multiplier.
Tensor4 & Data()
Get full view to data.
PropagationMatrix & operator-=(const Numeric &x)
Subtraction operator.
StokesVector & operator+=(const LazyScale< PropagationMatrix > &lpms)
Addition operator.
StokesVector(const Index nr_frequencies=0, const Index stokes_dim=1, const Index nr_za=1, const Index nr_aa=1, const Numeric &v=0.0)
Initialize variable sizes.
PropagationMatrix & operator=(PropagationMatrix &&pm) noexcept
Move operator.
PropagationMatrix(const Index nr_frequencies=0, const Index stokes_dim=1, const Index nr_za=1, const Index nr_aa=1, const Numeric v=0.0)
Initialize variable sizes.
Array< ArrayOfPropagationMatrix > ArrayOfArrayOfPropagationMatrix
VectorView K14(const Index iz=0, const Index ia=0)
Vector view to K(0, 3) elements.
Index NumberOfFrequencies() const
The number of frequencies of the propagation matrix.
This can be used to make arrays out of anything.
const base & bas
A const reference to a value.
void DivideAtPosition(const Numeric &x, const Index iv=0, const Index iz=0, const Index ia=0)
Divide at position.
PropagationMatrix & operator-=(const PropagationMatrix &other)
Subtraction operator.
VectorView Kjj(const Index iz=0, const Index ia=0)
Vector view to diagonal elements.
void AddFaraday(const Numeric &rot, const Index iv=0, const Index iz=0, const Index ia=0)
Adds the Faraday rotation to the PropagationMatrix at required position.
void SetVectorType(bool vectortype)
Set the Vector Type object.
A constant view of a Vector.
StokesVector & operator=(const PropagationMatrix &x)
Set *this from a Propagation matrix.
A constant view of a Matrix.
Index nbooks() const
Returns the number of books.
ConstVectorView VectorAtPosition(const Index iv=0, const Index iz=0, const Index ia=0) const
Get a vectorview to the position.
void AddAtPosition(const PropagationMatrix &x, const Index iv=0, const Index iz=0, const Index ia=0)
Addition at position operator.
PropagationMatrix & operator*=(const Numeric &x)
Multiply operator.
void SetZero()
Sets all data to zero.
StokesVector(const StokesVector &a, const StokesVector &b, const Numeric &scale=0.5)
Construct a new Stokes Vector as a scale between two others.
StokesVector & operator+=(const PropagationMatrix &x)
Addition operator.
PropagationMatrix(ConstMatrixView x, const bool &assume_fit=false)
Initialize from single stokes_dim-by-stokes_dim matrix.
void compute_transmission_matrix_and_derivative(Tensor3View T, Tensor4View dT_upper_level, Tensor4View dT_lower_level, const Numeric &r, const PropagationMatrix &upper_level, const PropagationMatrix &lower_level, const Array< PropagationMatrix > &dprop_mat_upper_level, const Array< PropagationMatrix > &dprop_mat_lower_level, const Numeric &dr_dTu=0.0, const Numeric &dr_dTl=0.0, const Index it=-1, const Index iz=0, const Index ia=0)
Index ncols() const
Returns the number of columns.
StokesVector & operator=(const Numeric &x)
Set this to constant value.
void DivideAtPosition(const PropagationMatrix &x, const Index iv=0, const Index iz=0, const Index ia=0)
Divide at position.
void AddAverageAtPosition(ConstVectorView vec1, ConstVectorView vec2, const Index iv=0, const Index iz=0, const Index ia=0)
Add the average of both inputs at position.
const Numeric & scale
A const reference to a Numeric.
PropagationMatrix & operator*=(ConstVectorView x)
Multiply operator.
StokesVector(ConstVectorView x)
Construct a new Stokes Vector object.
PropagationMatrix & operator=(const Numeric &x)
Sets all data to constant.
const Tensor4 & Data() const
Get full const view to data.
ConstVectorView K14(const Index iz=0, const Index ia=0) const
Vector view to K(0, 3) elements.
void SetAtPosition(ConstVectorView x, const Index iv=0, const Index iz=0, const Index ia=0)