Example #1
0
std::pair<std::pair<ParticleID, Voxel>, bool>
SpatiocyteWorld::new_voxel_structure(const Voxel& v)
{
    const bool is_succeeded((*space_).update_voxel_private(ParticleID(), v));
    const coordinate_type coord(private2coord(v.coordinate()));
    return std::make_pair(std::make_pair(ParticleID(),
                Voxel(v.species(), coord, v.radius(), v.D(), v.loc())),
        is_succeeded);
}
Example #2
0
    virtual void add_voxel_without_checking(const particle_info& info)
    {
        if (info.second != ParticleID())
        {
            throw NotSupported("No ParticleID is allowed.");
        }

        ; // do nothing
    }
void load_particle_space(const H5::Group& root, Tspace_* space)
{
    typedef ParticleSpaceHDF5Traits traits_type;
    typedef typename traits_type::h5_species_struct h5_species_struct;
    typedef typename traits_type::h5_particle_struct h5_particle_struct;

    Real3 edge_lengths;
    const hsize_t dims[] = {3};
    const H5::ArrayType lengths_type(H5::PredType::NATIVE_DOUBLE, 1, dims);
    root.openAttribute("edge_lengths").read(lengths_type, &edge_lengths);
    space->reset(edge_lengths);

    double t;
    root.openAttribute("t").read(H5::PredType::IEEE_F64LE, &t);
    space->set_t(t);

    {
        H5::DataSet species_dset(root.openDataSet("species"));
        const unsigned int num_species(
            species_dset.getSpace().getSimpleExtentNpoints());
        boost::scoped_array<h5_species_struct> h5_species_table(
            new h5_species_struct[num_species]);
        species_dset.read(
            h5_species_table.get(), traits_type::get_species_comp_type());
        species_dset.close();

        H5::DataSet particle_dset(root.openDataSet("particles"));
        const unsigned int num_particles(
            particle_dset.getSpace().getSimpleExtentNpoints());
        boost::scoped_array<h5_particle_struct> h5_particle_table(
            new h5_particle_struct[num_particles]);
        particle_dset.read(
            h5_particle_table.get(), traits_type::get_particle_comp_type());
        particle_dset.close();

        typedef utils::get_mapper_mf<unsigned int, Species::serial_type>::type
            species_id_map_type;
        species_id_map_type species_id_map;
        for (unsigned int i(0); i < num_species; ++i)
        {
            species_id_map[h5_species_table[i].id] = h5_species_table[i].serial;
        }

        for (unsigned int i(0); i < num_particles; ++i)
        {
            space->update_particle(ParticleID(std::make_pair(h5_particle_table[i].lot, h5_particle_table[i].serial)), Particle(Species(species_id_map[h5_particle_table[i].sid]), Real3(h5_particle_table[i].posx, h5_particle_table[i].posy, h5_particle_table[i].posz), h5_particle_table[i].radius, h5_particle_table[i].D));
        }

        // boost::scoped_array<h5_particle_struct>
        //     h5_particle_table(new h5_particle_struct[num_particles]);
        // for (unsigned int i(0); i < num_particles; ++i)
        // {
        //     species_id_map_type::const_iterator
        //         it(species_id_map.find(particles[i].second.species_serial()));
        //     if (it == species_id_map.end())
        //     {
        //         species.push_back(particles[i].second.species());
        //         it = species_id_map.insert(
        //             std::make_pair(particles[i].second.species_serial(),
        //                            species.size())).first;
        //     }

        //     h5_particle_table[i].lot = particles[i].first.lot();
        //     h5_particle_table[i].serial = particles[i].first.serial();
        //     h5_particle_table[i].sid = (*it).second;
        //     h5_particle_table[i].posx = particles[i].second.position()[0];
        //     h5_particle_table[i].posy = particles[i].second.position()[1];
        //     h5_particle_table[i].posz = particles[i].second.position()[2];
        //     h5_particle_table[i].radius = particles[i].second.radius();
        //     h5_particle_table[i].D = particles[i].second.D();
        // }

        // boost::scoped_array<h5_species_struct>
        //     h5_species_table(new h5_species_struct[species.size()]);
        // for (unsigned int i(0); i < species.size(); ++i)
        // {
        //     h5_species_table[i].id = i + 1;
        //     std::strcpy(h5_species_table[i].serial,
        //                 species[i].serial().c_str());
        // }
    }
}
Example #4
0
void load_lattice_space(const H5::Group& root, Tspace_* space)
{
    typedef LatticeSpaceHDF5Traits traits_type;

    uint32_t space_type; // not use
    double t;
    double voxel_radius;
    Real3 edge_lengths;
    const hsize_t dims[] = {3};
    uint32_t is_periodic;

#define OPEN_ATTRIBUTE(attribute, type) \
    root.openAttribute(#attribute).read(type, &attribute)

    OPEN_ATTRIBUTE(space_type, H5::PredType::STD_I32LE);
    OPEN_ATTRIBUTE(t, H5::PredType::IEEE_F64LE);
    OPEN_ATTRIBUTE(voxel_radius, H5::PredType::IEEE_F64LE);
    OPEN_ATTRIBUTE(edge_lengths, H5::ArrayType(H5::PredType::NATIVE_DOUBLE, 1, dims));
    OPEN_ATTRIBUTE(is_periodic, H5::PredType::STD_I32LE);

#undef OPEN_ATTRIBUTE

    space->set_t(t);
    space->reset(edge_lengths, voxel_radius, (is_periodic != 0));

    std::map<Species, traits_type::h5_species_struct> struct_map;
    std::map<Species, std::vector<std::pair<ParticleID, Integer> > > voxels_map;
    std::multimap<std::string, Species> location_map;

    std::map<Species, std::pair<traits_type::h5_species_struct,
            std::vector<std::pair<ParticleID, Integer> > > > tmp_map;

    H5::Group spgroup(root.openGroup("species"));
    char name_C[32 + 1];
    for (hsize_t idx(0); idx < spgroup.getNumObjs(); ++idx)
    {
        memset(name_C, 0, 32 + 1);  // clear buffer
        const ssize_t name_len = H5Lget_name_by_idx(spgroup.getLocId(), ".", H5_INDEX_NAME, H5_ITER_INC, idx, name_C, 32, H5P_DEFAULT);
        H5::Group group(spgroup.openGroup(name_C));
        const std::string name_S(name_C);
        Species species(name_S);

        // const H5std_string serial = spgroup.getObjnameByIdx(idx);
        // H5::Group group(spgroup.openGroup(serial.c_str()));
        // Species species(std::string(serial.c_str()));

        traits_type::h5_species_struct property;
        group.openAttribute("property").read(
                traits_type::get_property_comp(), &property);
        struct_map.insert(std::make_pair(species, property));
        location_map.insert(std::make_pair(property.location, species));

        H5::DataSet voxel_dset(group.openDataSet("voxels"));
        const unsigned int num_voxels(
            voxel_dset.getSpace().getSimpleExtentNpoints());
        boost::scoped_array<traits_type::h5_voxel_struct> h5_voxel_array(
                new traits_type::h5_voxel_struct[num_voxels]);
        voxel_dset.read(
                h5_voxel_array.get(), traits_type::get_voxel_comp());
        voxel_dset.close();
        group.close();

        std::vector<std::pair<ParticleID, Integer> > voxels;
        for (unsigned int idx(0); idx < num_voxels; ++idx)
        {
            voxels.push_back(std::make_pair(
                        ParticleID(std::make_pair(h5_voxel_array[idx].lot, h5_voxel_array[idx].serial)),
                        h5_voxel_array[idx].coordinate));
        }
        voxels_map.insert(std::make_pair(species, voxels));
    }
    spgroup.close();

    std::vector<Species> sp_list;
    traits_type::sort_by_location(location_map, sp_list);
    for (std::vector<Species>::iterator itr(sp_list.begin());
            itr != sp_list.end(); ++itr)
    {
        Species species(*itr);
        traits_type::h5_species_struct property((*struct_map.find(species)).second);
        std::vector<std::pair<ParticleID, Integer> > voxels((*voxels_map.find(species)).second);
        if (property.is_structure == 0)
            space->make_molecular_type(species, property.radius, property.D, property.location);
        else
            space->make_structure_type(species, static_cast<Shape::dimension_kind>(property.dimension), property.location);
        space->add_voxels(species, voxels);
    }
}
Example #5
0
 virtual particle_info pop(const private_coordinate_type& coord)
 {
     return particle_info(coord, ParticleID());
 }