29 #ifndef linefunctiondata_h 30 #define linefunctiondata_h 93 os <<
"Type: " << type <<
", is not accepted. " 94 <<
"See documentation for accepted types\n";
95 throw std::runtime_error(os.str());
129 #define VARIABLE2STRINGDEF(X) case Variable::X: return # X 141 #undef VARIABLE2STRINGDEF 146 #define STRING2VARIABLEDEF(X) if(type == # X) return Variable::X 158 os <<
"Type: " << type <<
", is not accepted. " 159 <<
"See documentation for accepted types\n";
160 throw std::runtime_error(os.str());
181 os <<
"Type: " << type <<
", is not accepted. " 182 <<
"See documentation for accepted types\n";
183 throw std::runtime_error(os.str());
195 is >> tmp >> mp.
X0 >> mp.
X1 >> mp.
X2;
206 std::array<ModelParameters, nVars>
X;
207 std::array<Numeric, nmaxInterpModels>
V;
216 return V[i+0] + (T-V[0]) * (V[i+1]-V[i+0]) / (V[1]-V[0]);
218 return V[i+2] + (T-V[2]) * (V[i+3]-V[i+2]) / (V[3]-V[2]);
220 return V[i+1] + (T-V[1]) * (V[i+2]-V[i+1]) / (V[2]-V[1]);
230 return (V[i+1]-V[i+0]) / (V[1]-V[0]);
232 return (V[i+3]-V[i+2]) / (V[3]-V[2]);
234 return (V[i+2]-V[i+1]) / (V[2]-V[1]);
248 std::array<Numeric, nmaxInterpModels>
interp = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) :
252 #define x0 X[Index(var)].X0 253 #define x1 X[Index(var)].X1 254 #define x2 X[Index(var)].X2 271 return x0 +
x1 * (T -
T0);
277 return special_linemixing_aer(T,
var);
301 return pow(
T0/T, 1.5*
x1 + 0.25);
379 return -
x0*
pow(
T0/T,1.5*
x1 + 0.25)*(1.5*
x1 + 0.25)/T;
381 return special_linemixing_aer_dT(T,
var);
417 #define ACCESS_INTERNAL(VARPOS) \ 418 ModelParameters& VARPOS() noexcept {return X[Index(Variable::VARPOS)];} \ 419 ModelParameters VARPOS() const noexcept {return X[Index(Variable::VARPOS)];} 424 #undef ACCESS_INTERNAL 427 std::array<ModelParameters, nVars>&
Data() noexcept {
return X;}
428 const std::array<ModelParameters, nVars>&
Data() const noexcept {
return X;}
429 std::array<Numeric, nmaxInterpModels>&
Interp() noexcept {
return V;}
430 const std::array<Numeric, nmaxInterpModels>&
Interp() const noexcept {
return V;}
433 #define MODELPARAMCASESETTER(X) case Variable::X: X () = x; break 445 #undef MODELPARAMCASESETTER 449 #define MODELPARAMCASEGETTER(X) case Variable::X: return X (); 461 #undef MODELPARAMCASEGETTER 466 std::istream&
read(std::istream& is) {
472 std::ostream&
write(std::ostream& os)
const {
479 for(
const auto& mp: ssm.
Data()) os << mp <<
' ';
480 for(
const auto& num: ssm.
Interp()) os << num <<
' ';
485 for(
auto& mp: ssm.
Data()) is >> mp;
486 for(
auto& num: ssm.
Interp()) is >> num;
517 os <<
"Type: " << type <<
", is not accepted. " 518 <<
"See documentation for accepted types\n";
519 throw std::runtime_error(os.str());
537 return os <<
"G0: " << x.
G0 549 return {x.
G0, -x.D0, x.G2, -x.D2, x.FVC, x.ETA, x.Y, x.G, -x.DV};
554 return {-x.
G0, -x.D0, -x.G2, -x.D2, -x.FVC, -x.ETA, -x.Y, -x.G, -x.DV};
568 return {y.
G0-x.G0, y.D0-x.D0, y.G2-x.G2, y.D2-x.D2,
569 y.FVC-x.FVC, y.ETA-x.ETA, y.Y-x.Y, y.G-x.G, y.DV-x.DV};
573 static constexpr
const char*
const bath_broadening =
"AIR";
574 static constexpr
const char*
const self_broadening =
"SELF";
582 std::vector<SingleSpeciesModel>
mdata;
584 bool OK() const noexcept {
588 bool needs_any = mtype not_eq
Type::DP;
589 if(n not_eq k or m > n or (needs_any and not n))
597 mspecies(0), mdata(0) {}
601 std::array<Numeric, nmaxInterpModels>
interp = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) noexcept :
602 mtype(
Type::VP), mself(
true), mbath(
true), mspecies(2), mdata(2) {
605 mdata.front().Interp() =
interp;
609 mdata.back ().Interp() =
interp;
613 mtype(type), mself(
false), mbath(
true), mspecies(1), mdata(1, bath) {}
616 const std::vector<SingleSpeciesModel>& ssms) :
617 mtype(type), mself(self), mbath(bath), mspecies(species), mdata(ssms) {
619 throw std::runtime_error(
"Bad initialization with different sizes or bad types, see documentation for valid initializations of LineShape::Model");
624 if(mself not_eq other.mself)
626 else if(mbath not_eq other.mbath)
628 else if(mspecies.
nelem() not_eq other.mspecies.nelem())
632 if(mspecies[
i].
Species() not_eq other.mspecies[
i].Species())
642 if(atmospheric_species.
nelem() != atmospheric_vmrs.
nelem())
643 throw std::runtime_error(
"Bad atmospheric inputs");
654 if(mbath and
i == back) {}
657 const auto target = (mself and
i == 0) ?
659 mspecies[i].Species() ;
662 Index this_species_index = -1;
663 for(
Index j=0; j<atmospheric_species.
nelem(); j++)
664 if(atmospheric_species[j][0].
Species() == target)
665 this_species_index = j;
668 if(this_species_index not_eq -1)
669 line_vmrs[i] = atmospheric_vmrs[this_species_index];
675 line_vmrs[back] = 1.0 - line_vmrs.
sum();
677 line_vmrs /= line_vmrs.sum();
680 if(not std::isnormal(line_vmrs.sum()))
681 throw std::runtime_error(
"Bad VMRs, your atmosphere does not support the line of interest");
690 if(self_species == mspecies[
i].
Species())
696 return this_species(
self.
Species());
700 #define LSPC(XVAR, PVAR) \ 701 Numeric XVAR (Numeric T, Numeric T0, Numeric P [[maybe_unused]], const Vector& vmrs) const noexcept { \ 702 return PVAR * std::inner_product(mdata.cbegin(), mdata.cend(), vmrs.begin(), 0.0, \ 703 std::plus<Numeric>(), [=](const SingleSpeciesModel& x, Numeric vmr) -> Numeric \ 704 {return vmr * x.compute(T, T0, Variable::XVAR);}); \ 710 #define LSPC(XVAR, PVAR) \ 711 Numeric d ## XVAR ## _dVMR (Numeric T, Numeric T0, Numeric P [[maybe_unused]], const Index deriv_pos) const noexcept { \ 712 if(deriv_pos not_eq -1) return PVAR * mdata[deriv_pos].compute(T, T0, Variable::XVAR); \ 719 #define LSPC(XVAR, PVAR) \ 720 Numeric d ## XVAR ## _dT (Numeric T, Numeric T0, Numeric P [[maybe_unused]], const Vector& vmrs) const noexcept { \ 721 return PVAR * std::inner_product(mdata.cbegin(), mdata.cend(), vmrs.begin(), 0.0, \ 722 std::plus<Numeric>(), [=](const SingleSpeciesModel& x, Numeric vmr) -> Numeric \ 723 {return vmr * x.compute_dT (T, T0, Variable::XVAR);}); \ 729 #define LSPDC(XVAR, DERIV, PVAR) \ 730 Numeric d ## XVAR ## DERIV (Numeric T, Numeric T0, Numeric P [[maybe_unused]], \ 731 Index deriv_pos, const Vector& vmrs) const noexcept { \ 732 if(deriv_pos not_eq -1) \ 733 return vmrs[deriv_pos] * PVAR * mdata[deriv_pos].compute ## DERIV (T, T0, Variable::XVAR); \ 748 return {
G0(T, T0, P, vmrs),
D0(T, T0, P, vmrs),
749 G2(T, T0, P, vmrs),
D2(T, T0, P, vmrs),
750 FVC(T, T0, P, vmrs),
ETA(T, T0, P, vmrs),
751 Y(T, T0, P, vmrs),
G(T, T0, P, vmrs),
DV(T, T0, P, vmrs)};
755 return {dG0_dT(T, T0, P, vmrs), dD0_dT(T, T0, P, vmrs),
756 dG2_dT(T, T0, P, vmrs), dD2_dT(T, T0, P, vmrs),
757 dFVC_dT(T, T0, P, vmrs), dETA_dT(T, T0, P, vmrs),
758 dY_dT(T, T0, P, vmrs), dG_dT(T, T0, P, vmrs), dDV_dT(T, T0, P, vmrs)};
762 return {dG0_dVMR(T,
T0, P, pos), dD0_dVMR(T,
T0, P, pos),
763 dG2_dVMR(T,
T0, P, pos), dD2_dVMR(T,
T0, P, pos),
764 dFVC_dVMR(T,
T0, P, pos), dETA_dVMR(T,
T0, P, pos),
765 dY_dVMR(T,
T0, P, pos), dG_dVMR(T,
T0, P, pos), dDV_dVMR(T,
T0, P, pos)};
772 #define RETURNINTERNALDERIVATIVE(TYPE) \ 773 case JacPropMatType::LineShape ## TYPE ## X0: return d ## TYPE ## _dX0(T, T0, P, pos, vmrs); \ 774 case JacPropMatType::LineShape ## TYPE ## X1: return d ## TYPE ## _dX1(T, T0, P, pos, vmrs); \ 775 case JacPropMatType::LineShape ## TYPE ## X2: return d ## TYPE ## _dX2(T, T0, P, pos, vmrs) 788 #undef RETURNINTERNALDERIVATIVE 797 friend inline std::ostream&
operator<<(std::ostream& os,
const Model& m);
802 bool Self() const noexcept {
return mself;}
803 bool Bath() const noexcept {
return mbath;}
804 const std::vector<SingleSpeciesModel>&
Data() const noexcept {
return mdata;}
807 std::vector<SingleSpeciesModel>&
Data() noexcept {
return mdata;}
812 bool self = spec == self_broadening;
813 bool bath = spec == bath_broadening;
815 return mdata.front().Get(var);
817 throw std::runtime_error(
"No self species but trying to get self in line shape model");
818 else if(mbath and bath)
819 return mdata.back().Get(var);
821 throw std::runtime_error(
"No bath species but trying to get bath in line shape model");
825 if(sp.
Species() == mspecies[
i].Species())
826 return mdata[
i].Get(var);
828 os <<
"No species of type " << spec <<
" found in line shape model\n";
829 os <<
"Available species are: " << mspecies <<
"\n";
830 throw std::runtime_error(os.str());
835 mspecies.erase(mspecies.begin()+i);
836 mdata.erase(mdata.begin()+i);
837 if(i == 0 and mself) mself=
false;
838 else if(i ==
nelem() and mbath) mbath=
false;
842 for(
auto& ssm: mdata) {
863 if(m.
mself and
i==0) os <<
' ' << self_broadening;
864 else if(m.
mbath and
i==m.
nelem()-1) os <<
' ' << bath_broadening;
865 else os <<
' ' << m.
mspecies[
i].SpeciesNameMain();
867 for(
auto& d: m.
mdata) os <<
' ' << d;
877 m.
mdata.resize(nelem);
884 for(
auto& d: m.
mdata) is >> d;
889 namespace LegacyLineFunctionData {
907 if(type ==
String(
"DP"))
return {};
914 os <<
"Type: " << type <<
", is not accepted. " 915 <<
"See documentation for accepted types\n";
916 throw std::runtime_error(os.str());
922 if(type ==
"#")
return {};
925 else if(type ==
"INT")
return {};
929 os <<
"Type: " << type <<
", is not accepted. " 930 <<
"See documentation for accepted types\n";
931 throw std::runtime_error(os.str());
936 namespace LegacyLineMixingData {
948 return TypeLM::LM_NONE;
949 else if(type ==
"LL")
950 return TypeLM::LM_LBLRTM;
951 else if(type ==
"NR")
952 return TypeLM::LM_LBLRTM_O2NonResonant;
953 else if(type ==
"L2")
954 return TypeLM::LM_2NDORDER;
955 else if(type ==
"L1")
956 return TypeLM::LM_1STORDER;
957 else if(type ==
"BB")
958 return TypeLM::LM_BYBAND;
961 os <<
"Type: " << type <<
", is not accepted. " 962 <<
"See documentation for accepted types\n";
963 throw std::runtime_error(os.str());
969 case TypeLM::LM_NONE:
971 case TypeLM::LM_LBLRTM:
973 case TypeLM::LM_LBLRTM_O2NonResonant:
975 case TypeLM::LM_2NDORDER:
977 case TypeLM::LM_1STORDER:
979 case TypeLM::LM_BYBAND:
988 namespace LegacyPressureBroadeningData {
1003 return TypePB::PB_NONE;
1004 else if(type ==
"N2")
1005 return TypePB::PB_AIR_BROADENING;
1006 else if(type ==
"WA")
1007 return TypePB::PB_AIR_AND_WATER_BROADENING;
1008 else if(type ==
"AP")
1009 return TypePB::PB_PLANETARY_BROADENING;
1012 os <<
"Type: " << type <<
", is not accepted. " 1013 <<
"See documentation for accepted types\n";
1014 throw std::runtime_error(os.str());
1019 if(t == TypePB::PB_PLANETARY_BROADENING and
1027 else if(t == TypePB::PB_AIR_AND_WATER_BROADENING and
1036 case TypePB::PB_NONE:
1038 case TypePB::PB_AIR_BROADENING:
1040 case TypePB::PB_AIR_AND_WATER_BROADENING:
1042 case TypePB::PB_PLANETARY_BROADENING:
1052 #endif // linefunctiondata_h
Model(Type type, bool self, bool bath, const ArrayOfSpeciesTag &species, const std::vector< SingleSpeciesModel > &ssms)
INDEX Index
The type to use for all integer numbers and indices.
bool same_broadening_species(const Model &other) const noexcept
std::istream & operator>>(std::istream &is, ModelParameters &mp)
Input operator for ModelParameters.
constexpr SingleSpeciesModel(ModelParameters G0={TemperatureModel::None, 0, 0, 0}, ModelParameters D0={TemperatureModel::None, 0, 0, 0}, ModelParameters G2={TemperatureModel::None, 0, 0, 0}, ModelParameters D2={TemperatureModel::None, 0, 0, 0}, ModelParameters FVC={TemperatureModel::None, 0, 0, 0}, ModelParameters ETA={TemperatureModel::None, 0, 0, 0}, ModelParameters Y={TemperatureModel::None, 0, 0, 0}, ModelParameters G={TemperatureModel::None, 0, 0, 0}, ModelParameters DV={TemperatureModel::None, 0, 0, 0}, std::array< Numeric, nmaxInterpModels > interp={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
void var(VectorView var, const Vector &y, const ArrayOfVector &ys, const Index start=0, const Index end=-1)
Compute the variance of the ranged ys.
TemperatureModel string2temperaturemodel(const String &type)
Turns predefined strings into a TemperatureModel type.
LegacyLineMixingData::TypeLM string2typelm(String type)
Line mixing types from string.
Vector vmrs(const ConstVectorView &atmospheric_vmrs, const ArrayOfArrayOfSpeciesTag &atmospheric_species, const QuantumIdentifier &self, const ArrayOfSpeciesTag &lineshape_species, bool self_in_list, bool bath_in_list, Type type)
Returns a VMR vector for this model's main calculations.
std::istream & from_linefunctiondata(std::istream &data, Model &lsc)
Index typepb2nelem(LegacyPressureBroadeningData::TypePB type)
Pressure broadening types to number of elements.
const std::array< ModelParameters, nVars > & Data() const noexcept
Index nelem() const
Number of elements.
QuantumIdentifier::QType Index LowerQuantumNumbers Species
std::vector< SingleSpeciesModel > & Data() noexcept
Output GetVMRDerivs(Numeric T, Numeric T0, Numeric P, const Index pos) const noexcept
std::vector< Variable > linemixingtag2variablesvector(String type)
Line mixing models.
Index temperaturemodel2legacynelem(TemperatureModel type) noexcept
Length per variable.
ArrayOfSpeciesTag mspecies
std::vector< SingleSpeciesModel > mdata
Routines for setting up the jacobian.
Model vector2modellm(Vector x, LegacyLineMixingData::TypeLM type)
LineShape::Model from legacy input vector.
ArrayOfString all_coefficientsLineFunctionData()
{"X0", "X1", "X2"}
Index Species() const
Molecular species index.
Numeric interp(ConstVectorView itw, ConstVectorView a, const GridPos &tc)
Red 1D Interpolate.
Constants of physical expressions as constexpr.
Main line shape model class.
Numeric & SingleModelParameter(ModelParameters &mp, const String &type)
Get a coefficient from ModelParameters by name.
Index typelm2nelem(LegacyLineMixingData::TypeLM type)
Line mixing types to number.
Numeric compute_dT(Numeric T, Numeric T0, Variable var) const noexcept
Numeric special_linemixing_aer(Numeric T, Variable var) const noexcept
#define MODELPARAMCASEGETTER(X)
Model vector2modelpb(Vector x, LegacyPressureBroadeningData::TypePB type, bool self_in_list)
ArrayOfString all_variablesLineFunctionData()
{"G0", "D0", "G2", "D2", "ETA", "FVC", "Y", "G", "DV"}
bool Bath() const noexcept
Numeric compute(Numeric T, Numeric T0, Variable var) const noexcept
constexpr Output negativeOutput(Output x) noexcept
Output turned negative.
G0 G2 FVC Y DV Numeric Numeric Numeric Zeeman LowerQuantumNumbers void * data
Numeric compute_dX0(Numeric T, Numeric T0, Variable var) const noexcept
Numeric GetInternalDeriv(Numeric T, Numeric T0, Numeric P, Index pos, const Vector &vmrs, JacPropMatType deriv) const
const std::vector< SingleSpeciesModel > & Data() const noexcept
Index nelem() const
Returns the number of elements.
#define RETURNINTERNALDERIVATIVE(TYPE)
JacPropMatType
List of Jacobian properties for analytical line shape related derivatives.
#define LSPDC(XVAR, DERIV, PVAR)
Computations of line shape derived parameters.
bool self_listed(const QuantumIdentifier &qid, LegacyPressureBroadeningData::TypePB t)
Pressure broadening if self exist.
std::istream & from_artscat4(std::istream &is, Model &lsc, const QuantumIdentifier &qid)
Model(const SingleSpeciesModel &bath, Type type) noexcept
constexpr Index nmaxTempModelParams
Current max number of coefficients.
Numeric sum() const
The sum of all elements of a Vector.
void Species(Index sp)
Set the Species.
constexpr Index nmaxInterpModels
A tag group can consist of the sum of several of these.
Variable
List of possible shape variables.
Coefficients and temperature model for SingleSpeciesModel.
#define ACCESS_INTERNAL(VARPOS)
std::ostream & operator<<(std::ostream &os, Variable v)
Output operator for Variable to be human-readable.
void Set(Variable var, const ModelParameters &x) noexcept
LegacyPressureBroadeningData::TypePB string2typepb(String type)
Pressure broadening types from string.
Class to identify and match lines by their quantum numbers.
std::istream & read(std::istream &is)
Output GetTemperatureDerivs(Numeric T, Numeric T0, Numeric P, const Vector &vmrs) const
#define MODELPARAMCASESETTER(X)
void SetLineMixingModel(SingleSpeciesModel x)
NUMERIC Numeric
The type to use for all floating point numbers.
Index this_species(const QuantumIdentifier &self) const noexcept
std::array< ModelParameters, nVars > X
Numeric special_linemixing_aer_dT(Numeric T, Variable var) const noexcept
const ArrayOfSpeciesTag & Species() const noexcept
String shapetype2string(Type type) noexcept
Turns selected Type into a string.
Numeric pow(const Rational base, Numeric exp)
Power of.
std::istream & from_linemixingdata(std::istream &data, Model &lsc)
Legacy reading of old deprecated LineMixingData class.
std::array< Numeric, nmaxInterpModels > V
basic_ostringstream< char, string_char_traits< char >, alloc > ostringstream
This can be used to make arrays out of anything.
String temperaturemodel2string(TemperatureModel type) noexcept
Turns selected TemperatureModel type into a string.
Numeric compute_dX2(Numeric T, Numeric T0, Variable var) const noexcept
Vector vmrs(const ConstVectorView &atmospheric_vmrs, const ArrayOfArrayOfSpeciesTag &atmospheric_species, const QuantumIdentifier &self) const
constexpr Output differenceOutput(Output y, Output x) noexcept
Diff of two output.
Numeric compute_dT0(Numeric T, Numeric T0, Variable var) const noexcept
std::array< ModelParameters, nVars > & Data() noexcept
constexpr Output si2cgs(Output x) noexcept
Output turned from SI to CGS units.
const std::array< Numeric, nmaxInterpModels > & Interp() const noexcept
A constant view of a Vector.
std::ostream & write(std::ostream &os) const
constexpr Output mirroredOutput(Output x) noexcept
Output to be used by mirroring calls.
constexpr Numeric freq2kaycm(T x)
std::istream & from_pressurebroadeningdata(std::istream &data, Model &lsc, const QuantumIdentifier &qid)
Index nelem(const Lines &l)
Number of lines.
Numeric compute_dX1(Numeric T, Numeric T0, Variable var) const noexcept
TemperatureModel
Temperature models.
#define VARIABLE2STRINGDEF(X)
#define STRING2VARIABLEDEF(X)
JacPropMatType select_derivativeLineShape(const String &var, const String &coeff)
Select the derivative that will be used in Jacobian calculations — also checks validity of var and c...
bool Self() const noexcept
ModelParameters Get(Variable var) const noexcept
Index this_species(const Index &self_species) const noexcept
Compute the line shape parameters for a single broadening species.
Model(Numeric sgam, Numeric nself, Numeric agam, Numeric nair, Numeric psf, std::array< Numeric, nmaxInterpModels > interp={0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) noexcept
std::array< Numeric, nmaxInterpModels > & Interp() noexcept
ModelParameters Get(const String &spec, const Variable var) const
Type string2shapetype(const String &type)
Turns predefined strings into a Type.
constexpr Index nVars
Current max number of line shape variables.
String variable2string(Variable type) noexcept
Turns selected Variable type into a string.
Type ModelType() const noexcept
my_basic_string< char > String
The String type for ARTS.
Variable string2variable(const String &type)
Turns predefined strings into a Variable type.
std::vector< Variable > lineshapetag2variablesvector(String type)
Line shape models.