vector<float> DiscreteJacobianField::DomainSize(const Array<Matrix> & jacobian_array, const float cell_size)
{
    vector<float> domain_size(jacobian_array.Dimension());

    for(unsigned int i = 0; i < domain_size.size(); i++)
    {
        domain_size[i] = jacobian_array.Size(i)*cell_size;
    }

    return domain_size;
}
Example #2
0
void ToolsSplashParallel::convertToText()
{
    if (m_options.data.size() == 0)
        throw std::runtime_error("No datasets requested");

    ColTypeInt ctInt;
    ColTypeDouble ctDouble;

    // read data
    //

    std::vector<ExDataContainer> file_data;

    // identify reference data class (poly, grid), reference domain size and number of elements
    //

    DomainCollector::DomDataClass ref_data_class = DomainCollector::UndefinedType;
    try
    {
        dc.readAttribute(m_options.step, m_options.data[0].c_str(), DOMCOL_ATTR_CLASS,
                &ref_data_class, NULL);
    } catch (const DCException&)
    {
        errorStream << "Error: No domain information for dataset '" << m_options.data[0] << "' available." << std::endl;
        errorStream << "This might not be a valid libSplash domain." << std::endl;
        return;
    }

    switch (ref_data_class)
    {
        case DomainCollector::GridType:
            if (m_options.verbose)
                errorStream << "Converting GRID data" << std::endl;
            break;
        case DomainCollector::PolyType:
            if (m_options.verbose)
                errorStream << "Converting POLY data" << std::endl;
            break;
        default:
            throw std::runtime_error("Could not identify data class for requested dataset");
    }

    Domain ref_total_domain;
    ref_total_domain = dc.getGlobalDomain(m_options.step, m_options.data[0].c_str());

    for (std::vector<std::string>::const_iterator iter = m_options.data.begin();
            iter != m_options.data.end(); ++iter)
    {
        // check that all datasets match to each other
        //

        DomainCollector::DomDataClass data_class = DomainCollector::UndefinedType;
        dc.readAttribute(m_options.step, iter->c_str(), DOMCOL_ATTR_CLASS,
                &data_class, NULL);
        if (data_class != ref_data_class)
            throw std::runtime_error("All requested datasets must be of the same data class");

        Domain total_domain = dc.getGlobalDomain(m_options.step, iter->c_str());
        if (total_domain != ref_total_domain)
            throw std::runtime_error("All requested datasets must map to the same domain");

        // create an extended container for each dataset
        ExDataContainer excontainer;

        if (ref_data_class == DomainCollector::PolyType)
        {
            // poly type

            excontainer.container = dc.readDomain(m_options.step, iter->c_str(),
                    Domain(total_domain.getOffset(), total_domain.getSize()), NULL, true);
        } else
        {
            // grid type

            Dimensions offset(total_domain.getOffset());
            Dimensions domain_size(total_domain.getSize());

            for (int i = 0; i < 3; ++i)
                if (m_options.fieldDims[i] == 0)
                {
                    offset[i] = m_options.sliceOffset;
                    if (offset[i] > total_domain.getBack()[i])
                        throw DCException("Requested offset outside of domain");

                    domain_size[i] = 1;
                    break;
                }

            excontainer.container = dc.readDomain(m_options.step, iter->c_str(),
                    Domain(offset, domain_size), NULL);
        }

        // read unit
        //
        if (m_options.applyUnits)
        {
            try
            {
                dc.readAttribute(m_options.step, iter->c_str(), "unitSI",
                        &(excontainer.unit), NULL);
            } catch (const DCException&)
            {
                if (m_options.verbose)
                    errorStream << "no unit for '" << iter->c_str() << "', defaulting to 1.0" << std::endl;
                excontainer.unit = 1.0;
            }

            if (m_options.verbose)
                errorStream << "Loaded dataset '" << iter->c_str() << "' with unit '" <<
                excontainer.unit << "'" << std::endl;
        } else
        {
            excontainer.unit = 1.0;
            if (m_options.verbose)
                errorStream << "Loaded dataset '" << iter->c_str() << "'" << std::endl;
        }

        file_data.push_back(excontainer);
    }

    assert(file_data[0].container->get(0)->getData() != NULL);

    // write to file
    //
    if (ref_data_class == DomainCollector::PolyType)
        printParticles(file_data);
    else
        printFields(file_data);

    for (std::vector<ExDataContainer>::iterator iter = file_data.begin();
            iter != file_data.end(); ++iter)
    {
        delete iter->container;
    }
}