Esempio n. 1
0
void MLC_Config::copy(ConfigTree& dst, const ConfigTree& src, const std::string& path)
{
    if (src.empty()) {
        // remove all existing keys
        ConfigTree::iterator dit = dst.begin();
        while (dit != dst.end()) {
            boost::property_tree::path p(path);
            p /= dit->first;

            if (!dit->second.empty()) {
                copy(dit->second, src, p.dump());
            }

            std::string v = dit->second.data();
            dit = dst.erase(dit);
            notify(p.dump(), v.c_str(), NULL);
        }
    }
    else {
        // remove non-existing keys
        ConfigTree::iterator dit = dst.begin();
        while (dit != dst.end()) {
            if (src.find(dit->first) == src.not_found()) {
                boost::property_tree::path p(path);
                p /= dit->first;

                if (!dit->second.empty()) {
                    copy(dit->second, ConfigTree(), p.dump());
                }

                std::string v = dit->second.data();
                dit = dst.erase(dit);
                notify(p.dump(), v.c_str(), NULL);
            }
            else {
                ++dit;
            }
        }

        // update keys
        ConfigTree::const_iterator sit = src.begin();
        for (; sit != src.end(); ++sit) {
            boost::property_tree::path p(path);
            p /= sit->first;

            optional<ConfigTree&> child = dst.get_child_optional(sit->first);
            if (sit->second.empty() && (!child || child.get().empty())) {
                if (sit->second.data().empty() && !(child)) {
                    // both source & destination are NULL, skip it
                    continue;
                }

                // value node
                std::string v;
                const char* oldval = NULL;
                const char* newval = NULL;

                if (child) {
                    v = child->data();
                    oldval = v.c_str();
                }

                if (sit->second.data().empty()) {
                    dst.erase(sit->first);
                }
                else {
                    newval = sit->second.data().c_str();
                    dst.put(sit->first, sit->second.data());
                }

                notify(p.dump(), oldval, newval);
            }
            else {
                if (!child) {
                    child = dst.put_child(sit->first, ConfigTree());
                    notify(p.dump(), NULL, "");
                }

                copy(child.get(), sit->second, p.dump());
            }
        }
    }
}
Esempio n. 2
0
ProcessVariable::ProcessVariable(
    ConfigTree const& config,
    MeshLib::Mesh const& mesh,
    GeoLib::GEOObjects const& geometries)
    : _name(config.get<std::string>("name")),
      _mesh(mesh)
{
    DBUG("Constructing process variable %s", this->_name.c_str());

    // Initial condition
    {
        auto const& ic_config = config.find("initial_condition");
        if (ic_config == config.not_found())
            INFO("No initial condition found.");


        std::string const type =
            config.get<std::string>("initial_condition.type");
        if (type == "Uniform")
        {
            _initial_condition.reset(new UniformInitialCondition(ic_config->second));
        }
        else
        {
            ERR("Unknown type of the initial condition.");
        }
    }

    // Boundary conditions
    {
        auto const& bcs_config = config.find("boundary_conditions");
        if (bcs_config == config.not_found())
            INFO("No boundary conditions found.");

        for (auto const& bc_iterator : bcs_config->second)
        {
            ConfigTree const& bc_config = bc_iterator.second;

            // Find corresponding GeoObject
            std::string const geometrical_set_name =
                bc_config.get<std::string>("geometrical_set");
            std::string const geometry_name =
                bc_config.get<std::string>("geometry");

            GeoLib::GeoObject const* const geometry = geometries.getGeoObject(
                    geometrical_set_name, geometry_name);
            DBUG("Found geometry type \"%s\"",
                GeoLib::convertGeoTypeToString(geometry->getGeoType()).c_str());

            // Construct type dependent boundary condition
            std::string const type = bc_config.get<std::string>("type");

            if (type == "UniformDirichlet")
            {
                _dirichlet_bcs.emplace_back(
                    new UniformDirichletBoundaryCondition(
                        geometry, bc_config));
            }
            else if (type == "UniformNeumann")
            {
                _neumann_bc_configs.emplace_back(
                    new NeumannBcConfig(geometry, bc_config));
            }
            else
            {
                ERR("Unknown type \'%s\' of the boundary condition.",
                        type.c_str());
            }
        }

    }
}