Пример #1
0
Array GreyBodyDustEmissivity::emissivity(const DustMix* mix, const Array& Jv) const
{
    // get basic information about the wavelength grid
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();
    int Nlambda = lambdagrid->Nlambda();

    // get basic information about the dust mix
    int Npop = mix->Npop();

    // accumulate the emissivities at the equilibrium temperature for all populations in the dust mix
    Array ev(Nlambda);
    for (int c=0; c<Npop; c++)
    {
        double T = mix->equilibrium(Jv,c);
        PlanckFunction B(T);
        for (int ell=0; ell<Nlambda; ell++)
        {
            ev[ell] += mix->sigmaabs(ell,c) * B(lambdagrid->lambda(ell));
        }
    }

    // convert emissivity from "per hydrogen atom" to "per unit mass"
    ev /= mix->mu();
    return ev;
}
Пример #2
0
void InstrumentFrame::calibrateAndWriteDataFrames(int ell, QList<Array*> farrays, QStringList fnames)
{
    PeerToPeerCommunicator* comm = find<PeerToPeerCommunicator>();
    if (!comm->isRoot()) return;

    Units* units = find<Units>();
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();

    // conversion from bolometric luminosities (units W) to monochromatic luminosities (units W/m)
    // --> divide by delta-lambda
    double dlambda = lambdagrid->dlambda(ell);

    // correction for the area of the pixels of the images; the units are now W/m/sr
    // --> divide by area
    double xpresang = 2.0*atan(_xpres/(2.0*_distance));
    double ypresang = 2.0*atan(_ypres/(2.0*_distance));
    double area = xpresang*ypresang;

    // calibration step 3: conversion of the flux per pixel from monochromatic luminosity units (W/m/sr)
    // to flux density units (W/m3/sr) by taking into account the distance
    // --> divide by fourpid2
    double fourpid2 = 4.0*M_PI*_distance*_distance;

    // conversion from program SI units (at this moment W/m3/sr) to the correct output units
    // --> multiply by unit conversion factor
    double unitfactor = units->osurfacebrightness(lambdagrid->lambda(ell), 1.);

    // perform the conversion, in place
    foreach (Array* farr, farrays)
    {
        (*farr) *= (unitfactor / (dlambda * area * fourpid2));
    }

    // write a FITS file for each array
    for (int q = 0; q < farrays.size(); q++)
    {
        QString filename = find<FilePaths>()->output(_instrument->instrumentName()
                                                     + "_" + fnames[q] + "_" + QString::number(ell) + ".fits");
        find<Log>()->info("Writing " + fnames[q] + " flux " + QString::number(ell)
                                                     + " to FITS file " + filename + "...");
        FITSInOut::write(filename, *(farrays[q]), _Nxp, _Nyp, 1,
                       units->olength(_xpres), units->olength(_ypres),
                       units->usurfacebrightness(), units->ulength());
    }
}
Пример #3
0
void SED::write(const QString& filename) const
{
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();
    Units* units = find<Units>();

    ofstream file(filename.toLocal8Bit().constData());
    file << setprecision(8) << scientific;
    for (int ell=0; ell<lambdagrid->Nlambda(); ell++)
    {
        double lambda = lambdagrid->lambda(ell);
        double dlambda = lambdagrid->dlambda(ell);
        file << units->owavelength(lambda)
             << '\t'
             << _Lv[ell]/dlambda*lambda
             << endl;
    }
    file.close();
}
Пример #4
0
void InstrumentFrame::calibrateAndWriteDataFrames(int ell, QList<Array*> farrays, QStringList fnames)
{
    Units* units = find<Units>();
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();

    // conversion from bolometric luminosities (units W) to monochromatic luminosities (units W/m)
    // --> divide by delta-lambda
    double dlambda = lambdagrid->dlambda(ell);

    // correction for the area of the pixels of the images; the units are now W/m/sr
    // --> divide by area
    double xpresang = 2.0*atan(_xpres/(2.0*_distance));
    double ypresang = 2.0*atan(_ypres/(2.0*_distance));
    double area = xpresang*ypresang;

    // calibration step 3: conversion of the flux per pixel from monochromatic luminosity units (W/m/sr)
    // to flux density units (W/m3/sr) by taking into account the distance
    // --> divide by fourpid2
    double fourpid2 = 4.0*M_PI*_distance*_distance;

    // conversion from program SI units (at this moment W/m3/sr) to the correct output units
    // --> multiply by unit conversion factor
    double unitfactor = units->osurfacebrightness(lambdagrid->lambda(ell), 1.);

    // Perform the conversion, in place
    foreach (Array* farr, farrays)
    {
        (*farr) *= (unitfactor / (dlambda * area * fourpid2));
    }

    // Write a FITS file for each array
    for (int q = 0; q < farrays.size(); q++)
    {
        QString filename = _instrument->instrumentName() + "_" + fnames[q] + "_" + QString::number(ell);
        QString description = fnames[q] + " flux " + QString::number(ell);

        // Create the image and save it
        Image image(this, _Nxp, _Nyp, 1, _xpres, _ypres, "surfacebrightness");
        image.saveto(this, *(farrays[q]), filename, description);
    }
}
Пример #5
0
void PerspectiveInstrument::write()
{
    Units* units = find<Units>();
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();
    int Nlambda = find<WavelengthGrid>()->Nlambda();

    // Put the data cube in a list of f-array pointers, as the sumResults function requires
    QList< Array* > farrays;
    farrays << &_ftotv;

    // Sum the flux arrays element-wise across the different processes
    sumResults(farrays);

    // Multiply each sample by lambda/dlamdba and by the constant factor 1/(4 pi s^2)
    // to obtain the surface brightness and convert to output units (such as W/m2/arcsec2)

    double front = 1. / (4.*M_PI*_s*_s);
    for (int ell=0; ell<Nlambda; ell++)
    {
        double lambda = lambdagrid->lambda(ell);
        double dlambda = lambdagrid->dlambda(ell);
        for (int i=0; i<_Nx; i++)
        {
            for (int j=0; j<_Ny; j++)
            {
                int m = i + _Nx*j + _Nx*_Ny*ell;
                _ftotv[m] = units->osurfacebrightness(lambda, _ftotv[m]*front/dlambda);
            }
        }
    }

    // Write a FITS file containing the data cube

    QString filename = _instrumentname + "_total";
    Image image(this, _Nx, _Ny, Nlambda, _s, _s, "surfacebrightness");
    image.saveto(this, _ftotv, filename, "total flux");
}
Пример #6
0
void QuasarSED::setupSelfBefore()
{
    StellarSED::setupSelfBefore();

    WavelengthGrid* lambdagrid = find<WavelengthGrid>();
    double Nlambda = lambdagrid->Nlambda();

    Array jv(Nlambda);
    for (int ell=0; ell<Nlambda; ell++)
    {
        double lambda = lambdagrid->lambda(ell);

        lambda *= 1e6; // conversion from m to micron (the Quasar SED is defined using microns)
        double j = 0.0;
        double a = 1.0;
        double b = 0.003981072;
        double c = 0.001258926;
        double d = 0.070376103;

        if (lambda<0.001)
            j = 0.0;
        else if (lambda<0.01)
            j = a*pow(lambda,0.2);
        else if (lambda<0.1)
            j = b*pow(lambda,-1.0);
        else if (lambda<5.0)
            j = c*pow(lambda,-1.5);
        else if (lambda<1000.0)
            j = d*pow(lambda,-4.0);
        else
            j = 0.0;
        jv[ell] = j;
    }

    setemissivities(jv);
}
Пример #7
0
void SPHStarburstComp::setupSelfBefore()
{
    StellarComp::setupSelfBefore();

    // cache the random generator
    _random = find<Random>();

    // local constant for units
    const double pc = Units::pc();

    // vectors storing the particle attributes (r and h are data members since we need those after setup)
    std::vector<double> SFRv;
    std::vector<double> Zv;
    std::vector<double> logCv;
    std::vector<double> Pv;
    std::vector<double> fPDRv;

    // load the SPH star particles
    QString filepath = find<FilePaths>()->input(_filename);
    QFile infile(filepath);
    if (!infile.open(QIODevice::ReadOnly|QIODevice::Text))
        throw FATALERROR("Could not open the SPH HII region data file " + filepath);
    find<Log>()->info("Reading SPH HII region particles from file " + filepath + "...");
    int Nparts = 0;
    double SFRtot = 0;
    while (!infile.atEnd())
    {
        // read a line, split it in columns, and skip empty and comment lines
        QList<QByteArray> columns = infile.readLine().simplified().split(' ');
        if (!columns.isEmpty() && !columns[0].startsWith('#'))
        {
            // get the column values; missing or illegal values default to zero
            _rv.push_back(Vec(columns.value(0).toDouble()*pc,
                              columns.value(1).toDouble()*pc,
                              columns.value(2).toDouble()*pc));
            _hv.push_back(columns.value(3).toDouble()*pc);
            SFRv.push_back(columns.value(4).toDouble());  // star formation rate in Msun / yr
            Zv.push_back(columns.value(5).toDouble());    // metallicity as dimensionless fraction
            logCv.push_back(columns.value(6).toDouble()); // log compactness (Groves 2008) as dimensionless value
            Pv.push_back(columns.value(7).toDouble());    // ISM pressure in Pa
            fPDRv.push_back(columns.value(8).toDouble()); // dimensionless photo-dissociation region covering fraction

            Nparts++;
            SFRtot += columns.value(4).toDouble();
        }
    }
    infile.close();

    double Mtot = SFRtot * 1.e7;  // total stellar mass from total sfr over the last 10 Myr

    find<Log>()->info("  Total number of SPH HII region particles: " + QString::number(Nparts));
    find<Log>()->info("  Total stellar mass: " + QString::number(Mtot) + " Msun");

    find<Log>()->info("Filling the vectors with the SEDs of the particles... ");

    // construct the library of SED models
    MappingsSEDFamily map(this);

    // construct a temporary matrix Lvv with the luminosity of each particle at each wavelength
    // and also the permanent vector _Ltotv with the total luminosity for every wavelength bin
    int Nlambda = find<WavelengthGrid>()->Nlambda();
    ArrayTable<2> Lvv(Nlambda,Nparts);
    _Ltotv.resize(Nlambda);
    double Ltot = 0;
    for (int i=0; i<Nparts; i++)
    {
        const Array& Lv = map.luminosities(SFRv[i], Zv[i], logCv[i], Pv[i], fPDRv[i]);
        for (int ell=0; ell<Nlambda; ell++)
        {
            Lvv[ell][i] = Lv[ell];
            _Ltotv[ell] += Lv[ell];
            Ltot += Lv[ell];
        }
    }
    find<Log>()->info("  HII luminosity: " + QString::number(Ltot/Units::Lsun()) + " Lsun");

    // construct the permanent vectors _Xvv with the normalized cumulative luminosities (per wavelength bin)
    _Xvv.resize(Nlambda,0);
    for (int ell=0; ell<Nlambda; ell++)
    {
        NR::cdf(_Xvv[ell], Lvv[ell]);
    }

    // if requested, write a data file with the luminosities per wavelength
    if (_writeLuminosities)
    {
        Units* units = find<Units>();
        WavelengthGrid* lambdagrid = find<WavelengthGrid>();

        // Create a text file
        TextOutFile file(this, "HII_luminosities", "HII luminosities");

        // Write the header
        file.addColumn("lambda (" + units->uwavelength() + ")");
        file.addColumn("luminosity (" + units->ubolluminosity() + ")");

        // Write the body
        for (int ell=0; ell<Nlambda; ell++)
        {
            file.writeRow(QList<double>() << units->owavelength(lambdagrid->lambda(ell))
                                          << units->obolluminosity(_Ltotv[ell]));
        }
    }
}
Пример #8
0
void PanDustSystem::write() const
{
    DustSystem::write();

    // If requested, output the interstellar radiation field in every dust cell to a data file
    if (_writeISRF)
    {
        WavelengthGrid* lambdagrid = find<WavelengthGrid>();
        Units* units = find<Units>();

        // Create a text file
        TextOutFile file(this, "ds_isrf", "ISRF");

        // Write the header
        file.writeLine("# Mean field intensities for all dust cells with nonzero absorption");
        file.addColumn("dust cell index", 'd');
        file.addColumn("x coordinate of cell center (" + units->ulength() + ")", 'g');
        file.addColumn("y coordinate of cell center (" + units->ulength() + ")", 'g');
        file.addColumn("z coordinate of cell center (" + units->ulength() + ")", 'g');
        for (int ell=0; ell<_Nlambda; ell++)
            file.addColumn("J_lambda (W/m3/sr) for lambda = "
                           + QString::number(units->owavelength(lambdagrid->lambda(ell)))
                           + " " + units->uwavelength(), 'g');

        // Write one line for each dust cell with nonzero absorption
        for (int m=0; m<_Ncells; m++)
        {
            double Ltotm = Labs(m);
            if (Ltotm>0.0)
            {
                QList<double> values;
                Position bfr = _grid->centralPositionInCell(m);
                values << m << units->olength(bfr.x()) << units->olength(bfr.y()) << units->olength(bfr.z());
                for (auto J : meanintensityv(m)) values << J;
                file.writeRow(values);
            }
        }
    }

    // If requested, output temperate map(s) along coordiate axes cuts
    if (_writeTemp)
    {
        // construct a private class instance to do the work (parallelized)
        WriteTemp wt(this);
        Parallel* parallel = find<ParallelFactory>()->parallel();

        // get the dimension of the dust grid
        int dimDust = _grid->dimension();

        // Create an assigner that assigns all the work to the root process
        RootAssigner* assigner = new RootAssigner(0);
        assigner->assign(Np);

        // For the xy plane (always)
        {
            wt.setup(1,1,0);
            parallel->call(&wt, assigner);
            wt.write();
        }

        // For the xz plane (only if dimension is at least 2)
        if (dimDust >= 2)
        {
            wt.setup(1,0,1);
            parallel->call(&wt, assigner);
            wt.write();
        }

        // For the yz plane (only if dimension is 3)
        if (dimDust == 3)
        {
            wt.setup(0,1,1);
            parallel->call(&wt, assigner);
            wt.write();
        }
    }
}
Пример #9
0
void PanDustSystem::write() const
{
    DustSystem::write();

    PeerToPeerCommunicator* comm = find<PeerToPeerCommunicator>();
    bool dataParallel = comm->dataParallel();

    // If requested, output the interstellar radiation field in every dust cell to a data file
    if (_writeISRF)
    {
        WavelengthGrid* lambdagrid = find<WavelengthGrid>();
        Units* units = find<Units>();

        // Create a text file
        TextOutFile file(this, "ds_isrf", "ISRF");

        // Write the header
        file.writeLine("# Mean field intensities for all dust cells with nonzero absorption");
        file.addColumn("dust cell index", 'd');
        file.addColumn("x coordinate of cell center (" + units->ulength() + ")", 'g');
        file.addColumn("y coordinate of cell center (" + units->ulength() + ")", 'g');
        file.addColumn("z coordinate of cell center (" + units->ulength() + ")", 'g');
        for (int ell=0; ell<_Nlambda; ell++)
            file.addColumn("J_lambda (W/m3/sr) for lambda = "
                           + QString::number(units->owavelength(lambdagrid->lambda(ell)))
                           + " " + units->uwavelength(), 'g');

        // Write one line for each dust cell with nonzero absorption
        for (int m=0; m<_Ncells; m++)
        {
            if (!dataParallel)
            {
                double Ltotm = Labs(m);
                if (Ltotm>0.0)
                {
                    QList<double> values;
                    Position bfr = _grid->centralPositionInCell(m);
                    values << m << units->olength(bfr.x()) << units->olength(bfr.y()) << units->olength(bfr.z());

                    for (auto J : meanintensityv(m)) values << J;
                    file.writeRow(values);
                }
            }
            else // for distributed mode
            {
                QList<double> values;
                Position bfr = _grid->centralPositionInCell(m);
                values << m << units->olength(bfr.x()) << units->olength(bfr.y()) << units->olength(bfr.z());

                // the correct process gets Jv
                Array Jv(_Nlambda);
                if (_assigner->validIndex(m)) Jv = meanintensityv(m);

                // and broadcasts it
                int sender = _assigner->rankForIndex(m);
                comm->broadcast(Jv,sender);

                if (Jv.sum()>0)
                {
                    for (auto J : Jv) values << J;
                    file.writeRow(values);
                }
            }
        }
    }

    // If requested, output temperature map(s) along coordinate axes and temperature data for each dust cell
    if (_writeTemp)
    {
        // Parallelize the calculation over the threads
        Parallel* parallel = find<ParallelFactory>()->parallel();
        // If the necessary data is distributed over the processes, do the calculation on all processes.
        // Else, let the root do everything.
        bool isRoot = comm->isRoot();

        // Output temperature map(s) along coordinate axes
        {
            // Construct a private class instance to do the work (parallelized)
            WriteTempCut wt(this);

            // Get the dimension of the dust grid
            int dimDust = _grid->dimension();

            // For the xy plane (always)
            {
                wt.setup(1,1,0);
                if (dataParallel) parallel->call(&wt, Np);
                else if (isRoot) parallel->call(&wt, Np);
                wt.write();
            }

            // For the xz plane (only if dimension is at least 2)
            if (dimDust >= 2)
            {
                wt.setup(1,0,1);
                if (dataParallel) parallel->call(&wt, Np);
                else if (isRoot) parallel->call(&wt, Np);
                wt.write();
            }

            // For the yz plane (only if dimension is 3)
            if (dimDust == 3)
            {
                wt.setup(0,1,1);
                if (dataParallel) parallel->call(&wt, Np);
                else if (isRoot) parallel->call(&wt, Np);
                wt.write();
            }
        }

        // Output a text file with temperature data for each dust cell
        {
            find<Log>()->info("Calculating indicative dust temperatures for each cell...");

            // Construct a private class instance to do the work (parallelized)
            WriteTempData wt(this);

            // Call the body on the right cells. If everything is available, no unnecessary communication will be done.
            if (dataParallel)
            {
                // Calculate the temperature for the cells owned by this process
                parallel->call(&wt, _assigner);
            }
            else if (isRoot)
            {
                // Let root calculate it for everything
                parallel->call(&wt, _Ncells);
            }
            wt.write();
        }
    }
}
Пример #10
0
void SingleFrameInstrument::calibrateAndWriteDataCubes(QList< Array*> farrays, QStringList fnames)
{
    WavelengthGrid* lambdagrid = find<WavelengthGrid>();
    int Nlambda = lambdagrid->Nlambda();

    // calibration step 1: conversion from bolometric luminosities (units W) to monochromatic luminosities (units W/m)

    for (int ell=0; ell<Nlambda; ell++)
    {
        double dlambda = lambdagrid->dlambda(ell);
        for (int i=0; i<_Nxp; i++)
        {
            for (int j=0; j<_Nyp; j++)
            {
                int m = i + _Nxp*j + _Nxp*_Nyp*ell;
                foreach (Array* farr, farrays)
                {
                    (*farr)[m] /= dlambda;
                }
            }
        }
    }

    // calibration step 2: correction for the area of the pixels of the images; the units are now W/m/sr

    double xpresang = 2.0*atan(_xpres/(2.0*_distance));
    double ypresang = 2.0*atan(_ypres/(2.0*_distance));
    double area = xpresang*ypresang;
    foreach (Array* farr, farrays)
    {
        (*farr) /= area;
    }

    // calibration step 3: conversion of the flux per pixel from monochromatic luminosity units (W/m/sr)
    // to flux density units (W/m3/sr) by taking into account the distance

    double fourpid2 = 4.0*M_PI*_distance*_distance;
    foreach (Array* farr, farrays)
    {
        (*farr) /= fourpid2;
    }

    // conversion from program SI units (at this moment W/m3/sr) to the correct output units;
    // we use lambda*flambda for the surface brightness (in units like W/m2/arcsec2)

    Units* units = find<Units>();
    for (int ell=0; ell<Nlambda; ell++)
    {
        double lambda = lambdagrid->lambda(ell);
        for (int i=0; i<_Nxp; i++)
        {
            for (int j=0; j<_Nyp; j++)
            {
                int m = i + _Nxp*j + _Nxp*_Nyp*ell;
                foreach (Array* farr, farrays)
                {
                    (*farr)[m] = units->obolsurfacebrightness(lambda*(*farr)[m]);
                }
            }
        }
    }