Program Listing for File InverseLinearLconvEvolution.h

Return to documentation for file (/home/kpenev/projects/git/poet/poet_src/unit_tests/testEvolve/InverseLinearLconvEvolution.h)

#ifndef __INVERSE_LINEAR_LCONV_EVOLUTION_H
#define __INVERSE_LINEAR_LCONV_EVOLUTION_H

#include "InverseFunction.h"

template<class LINEAR_QUANTITY_TYPE>
class InverseLinearLconvEvolution : public Core::OneArgumentDiffFunction {
private:
    double
        __disk_lifetime,

        __evolution_rate;

    LINEAR_QUANTITY_TYPE __linear_quantity;

    InverseFunction __find_lconv;

public:
    InverseLinearLconvEvolution(
        double disk_lifetime,

        double total_angmom,

        double orbital_angmom,

        double initial_conv_angmom,

        double evolution_rate
    ) :
        __disk_lifetime(disk_lifetime),
        __evolution_rate(evolution_rate),
        __linear_quantity(total_angmom, orbital_angmom, initial_conv_angmom),
        __find_lconv(__linear_quantity,
                     (
                         (total_angmom - orbital_angmom)
                         *
                         (1.0 + 100.0 * std::numeric_limits<double>::epsilon())
                     ),
                     initial_conv_angmom)
    {}

    double operator()(double age) const
    {
        return __find_lconv(
            std::min(0.0, -(age - __disk_lifetime) * __evolution_rate)
        );
    }

    double disk_lifetime() const {return __disk_lifetime;}

    double range_high() const
    {return __find_lconv.range_high() / __evolution_rate;}

    double range_low() const
    {return -Core::Inf;}

    Core::InterpSolutionIterator crossings(double = 0) const
    {
        throw Core::Error::Runtime(
            "Finding all solutinos of ConservedLELconvEvolution not supported!"
        );
    };

    const Core::FunctionDerivatives *deriv(double age) const
    {
        if(age <= __disk_lifetime)
            return new Core::CubicSplineDerivatives(__find_lconv(0.0),
                                                    0.0,
                                                    0.0);
        const Core::FunctionDerivatives *scaled_deriv = __find_lconv.deriv(
            -(age - __disk_lifetime) * __evolution_rate
        );
        double value = scaled_deriv->order(0),
               order1 = -scaled_deriv->order(1) * __evolution_rate,
               order2 = scaled_deriv->order(2) * std::pow(__evolution_rate, 2);
        delete scaled_deriv;
        return new Core::CubicSplineDerivatives(value, order1, order2);
    }
};


#endif