Example #1
0
void Field::read(const H5::CommonFG &loc, const string &entry,
                 const shared_ptr<Project> &project) {
  m_project = project;
  auto group = loc.openGroup(entry);
  assert(H5::readAttribute<string>(group, "type", project->enumtype) ==
         "Field");
  H5::readAttribute(group, "name", m_name);
  assert(H5::readGroupAttribute<string>(group, "project", "name") ==
         project->name());
  // TODO: Read and interpret objects (shallowly) instead of naively only
  // looking at their names
  m_manifold = project->manifolds().at(
      H5::readGroupAttribute<string>(group, "manifold", "name"));
  m_configuration = project->configurations().at(
      H5::readGroupAttribute<string>(group, "configuration", "name"));
  assert(H5::readGroupAttribute<string>(group, "configuration/fields/" + name(),
                                        "name") == name());
  assert(H5::readGroupAttribute<string>(group, "manifold/fields/" + name(),
                                        "name") == name());
  m_tangentspace = project->tangentspaces().at(
      H5::readGroupAttribute<string>(group, "tangentspace", "name"));
  assert(H5::readGroupAttribute<string>(group, "tangentspace/fields/" + name(),
                                        "name") == name());
  m_tensortype = project->tensortypes().at(
      H5::readGroupAttribute<string>(group, "tensortype", "name"));
  H5::readGroup(group, "discretefields",
                [&](const H5::Group &group, const string &name) {
                  readDiscreteField(group, name);
                });
  m_configuration->insert(name(), shared_from_this());
  m_manifold->insert(name(), shared_from_this());
  m_tangentspace->insert(name(), shared_from_this());
  m_tensortype->noinsert(shared_from_this());
}
void SubDiscretization::read(const H5::CommonFG &loc, const string &entry,
                             const shared_ptr<Manifold> &manifold) {
  m_manifold = manifold;
  auto group = loc.openGroup(entry);
  assert(
      H5::readAttribute<string>(group, "type", manifold->project()->enumtype) ==
      "SubDiscretization");
  H5::readAttribute(group, "name", m_name);
  assert(H5::readGroupAttribute<string>(group, "manifold", "name") ==
         manifold->name());
  m_parent_discretization = manifold->discretizations().at(
      H5::readGroupAttribute<string>(group, "parent_discretization", "name"));
  assert(H5::readGroupAttribute<string>(
             group,
             string("parent_discretization/child_discretizations/") + name(),
             "name") == name());
  m_child_discretization = manifold->discretizations().at(
      H5::readGroupAttribute<string>(group, "child_discretization", "name"));
  assert(H5::readGroupAttribute<string>(
             group,
             string("child_discretization/parent_discretizations/") + name(),
             "name") == name());
  H5::readAttribute(group, "factor", m_factor);
  std::reverse(m_factor.begin(), m_factor.end());
  H5::readAttribute(group, "offset", m_offset);
  std::reverse(m_offset.begin(), m_offset.end());
  m_parent_discretization->insertChild(name(), shared_from_this());
  m_child_discretization->insertParent(name(), shared_from_this());
}
Example #3
0
void Manifold::read(const H5::CommonFG &loc, const string &entry,
                    const shared_ptr<Project> &project) {
  this->m_project = project;
  auto group = loc.openGroup(entry);
  assert(H5::readAttribute<string>(group, "type", project->enumtype) ==
         "Manifold");
  H5::readAttribute(group, "name", m_name);
  assert(H5::readGroupAttribute<string>(group, "project", "name") ==
         project->name());
  m_configuration = project->configurations().at(
      H5::readGroupAttribute<string>(group, "configuration", "name"));
  assert(H5::readGroupAttribute<string>(
             group, "configuration/manifolds/" + name(), "name") == name());
  H5::readAttribute(group, "dimension", m_dimension);
  H5::readGroup(group, "discretizations",
                [&](const H5::Group &group, const string &name) {
                  readDiscretization(group, name);
                });
  H5::readGroup(group, "subdiscretizations",
                [&](const H5::Group &group, const string &name) {
                  readSubDiscretization(group, name);
                });
  // Cannot check "fields", "coordinatesystems" since they have not been read
  // yet
  // assert(H5::checkGroupNames(group, "fields", fields));
  // assert(H5::checkGroupNames(group, "coordinatesystems", fields));
  m_configuration->insert(name(), shared_from_this());
}
void DiscretizationBlock::read(
    const H5::CommonFG &loc, const string &entry,
    const shared_ptr<Discretization> &discretization) {
  this->discretization = discretization;
  auto group = loc.openGroup(entry);
  assert(H5::readAttribute<string>(
             group, "type",
             discretization->manifold.lock()->project.lock()->enumtype) ==
         "DiscretizationBlock");
  H5::readAttribute(group, "name", name);
  assert(H5::readGroupAttribute<string>(group, "discretization", "name") ==
         discretization->name);
  if (group.attrExists("offset")) {
    vector<hssize_t> offset, shape;
    H5::readAttribute(group, "offset", offset);
    std::reverse(offset.begin(), offset.end());
    H5::readAttribute(group, "shape", shape);
    std::reverse(shape.begin(), shape.end());
    region = box_t(offset, point_t(offset) + shape);
  }
  if (group.attrExists("active")) {
    // TODO read_active<0>(group, *this, active);
    read_active<1>(group, *this, active);
    read_active<2>(group, *this, active);
    read_active<3>(group, *this, active);
    read_active<4>(group, *this, active);
  }
}
Example #5
0
void Project::read(const H5::CommonFG &loc) {
  auto group = loc.openGroup(".");
  createTypes(); // TODO: read from file instead to ensure integer constants are
                 // consistent
  assert(H5::readAttribute<string>(group, "type", enumtype) == "Project");
  H5::readAttribute(group, "name", m_name);
  H5::readGroup(group, "parameters",
                [&](const H5::Group &group, const string &name) {
                  readParameter(group, name);
                });
  H5::readGroup(group, "configurations",
                [&](const H5::Group &group, const string &name) {
                  readConfiguration(group, name);
                });
  H5::readGroup(group, "tensortypes",
                [&](const H5::Group &group, const string &name) {
                  readTensorType(group, name);
                });
  H5::readGroup(group, "manifolds",
                [&](const H5::Group &group, const string &name) {
                  readManifold(group, name);
                });
  H5::readGroup(group, "tangentspaces",
                [&](const H5::Group &group, const string &name) {
                  readTangentSpace(group, name);
                });
  H5::readGroup(group, "fields",
                [&](const H5::Group &group, const string &name) {
                  readField(group, name);
                });
  H5::readGroup(group, "coordinatesystems",
                [&](const H5::Group &group, const string &name) {
                  readCoordinateSystem(group, name);
                });
}
Example #6
0
void Project::write(const H5::CommonFG &loc,
                    const H5::H5Location &parent) const {
  assert(invariant());
  // auto group = loc.createGroup(name());
  auto group = loc.openGroup(".");
  createTypes();
  auto typegroup = group.createGroup("types");
  enumtype.commit(typegroup, "SimulationIO");
#if 0
  rangetype.commit(typegroup, "Range");
#endif
  for (int d = 0; d < int(pointtypes.size()); ++d)
    pointtypes.at(d).commit(typegroup, "Point[" + itos(d) + "]");
  for (int d = 0; d < int(boxtypes.size()); ++d)
    boxtypes.at(d).commit(typegroup, "Box[" + itos(d) + "]");
  for (int d = 0; d < int(regiontypes.size()); ++d)
    regiontypes.at(d).commit(typegroup, "Region[" + itos(d) + "]");
  H5::createAttribute(group, "type", enumtype, "Project");
  H5::createAttribute(group, "name", name());
  // no link to parent
  H5::createGroup(group, "parameters", parameters());
  H5::createGroup(group, "configurations", configurations());
  H5::createGroup(group, "tensortypes", tensortypes());
  H5::createGroup(group, "manifolds", manifolds());
  H5::createGroup(group, "tangentspaces", tangentspaces());
  H5::createGroup(group, "fields", fields());
  H5::createGroup(group, "coordinatesystems", coordinatesystems());
}
Example #7
0
void TensorComponent::read(const H5::CommonFG &loc, const string &entry,
                           const shared_ptr<TensorType> &tensortype) {
  m_tensortype = tensortype;
  auto group = loc.openGroup(entry);
  assert(H5::readAttribute<string>(group, "type",
                                   tensortype->project()->enumtype) ==
         "TensorComponent");
  H5::readAttribute(group, "name", m_name);
  assert(H5::readGroupAttribute<string>(group, "tensortype", "name") ==
         tensortype->name());
  H5::readAttribute(group, "storage_index", m_storage_index);
  H5::readAttribute(group, "indexvalues", m_indexvalues);
}
Example #8
0
void Parameter::read(const H5::CommonFG &loc, const string &entry,
                     const shared_ptr<Project> &project) {
  this->project = project;
  auto group = loc.openGroup(entry);
  assert(H5::readAttribute<string>(group, "type", project->enumtype) ==
         "Parameter");
  H5::readAttribute(group, "name", name);
  assert(H5::readGroupAttribute<string>(group, "project", "name") ==
         project->name);
  H5::readGroup(group, "parametervalues",
                [&](const H5::Group &group, const string &name) {
                  readParameterValue(group, name);
                });
}
Example #9
0
void TensorType::read(const H5::CommonFG &loc, const string &entry,
                      const shared_ptr<Project> &project) {
  m_project = project;
  auto group = loc.openGroup(entry);
  assert(H5::readAttribute<string>(group, "type", project->enumtype) ==
         "TensorType");
  H5::readAttribute(group, "name", m_name);
  assert(H5::readGroupAttribute<string>(group, "project", "name") ==
         project->name());
  H5::readAttribute(group, "dimension", m_dimension);
  H5::readAttribute(group, "rank", m_rank);
  H5::readGroup(group, "tensorcomponents",
                [&](const H5::Group &group, const string &name) {
                  readTensorComponent(group, name);
                });
  // TODO: check storage_indices
}
Example #10
0
void Basis::read(const H5::CommonFG &loc, const string &entry,
                 const shared_ptr<TangentSpace> &tangentspace) {
  m_tangentspace = tangentspace;
  auto group = loc.openGroup(entry);
  assert(H5::readAttribute<string>(
             group, "type", tangentspace->project()->enumtype) == "Basis");
  H5::readAttribute(group, "name", m_name);
  assert(H5::readGroupAttribute<string>(group, "tangentspace", "name") ==
         tangentspace->name());
  m_configuration = tangentspace->project()->configurations().at(
      H5::readGroupAttribute<string>(group, "configuration", "name"));
  assert(H5::readGroupAttribute<string>(
             group, string("configuration/bases/") + name(), "name") == name());
  H5::readGroup(group, "basisvectors",
                [&](const H5::Group &group, const string &name) {
                  readBasisVector(group, name);
                });
  // TODO: check group directions
  m_configuration->insert(name(), shared_from_this());
}
Example #11
0
void TangentSpace::read(const H5::CommonFG &loc, const string &entry,
                        const shared_ptr<Project> &project) {
  this->project = project;
  auto group = loc.openGroup(entry);
  assert(H5::readAttribute<string>(group, "type", project->enumtype) ==
         "TangentSpace");
  H5::readAttribute(group, "name", name);
  assert(H5::readGroupAttribute<string>(group, "project", "name") ==
         project->name);
  configuration = project->configurations.at(
      H5::readGroupAttribute<string>(group, "configuration", "name"));
  assert(H5::readGroupAttribute<string>(
             group, string("configuration/tangentspaces/") + name, "name") ==
         name);
  H5::readAttribute(group, "dimension", dimension);
  H5::readGroup(group, "bases",
                [&](const H5::Group &group, const string &name) {
                  readBasis(group, name);
                });
  // Cannot check "fields" since fields have not been read yet
  // assert(H5::checkGroupNames(group, "fields", fields));
  configuration->insert(name, shared_from_this());
}
Example #12
0
void ParameterValue::read(const H5::CommonFG &loc, const string &entry,
                          const shared_ptr<Parameter> &parameter) {
  this->parameter = parameter;
  value_type = type_empty;
  auto group = loc.openGroup(entry);
  assert(H5::readAttribute<string>(group, "type",
                                   parameter->project.lock()->enumtype) ==
         "ParameterValue");
  H5::readAttribute(group, "name", name);
  assert(H5::readGroupAttribute<string>(group, "parameter", "name") ==
         parameter->name);
  // TODO: Read and interpret objects (shallowly) instead of naively only
  // looking at their names
  if (group.attrExists("data")) {
    auto attr = group.openAttribute("data");
    auto type = attr.getDataType();
    auto cls = type.getClass();
    switch (cls) {
    case H5T_INTEGER:
      H5::readAttribute(group, "data", value_int);
      value_type = type_int;
      break;
    case H5T_FLOAT:
      H5::readAttribute(group, "data", value_double);
      value_type = type_double;
      break;
    case H5T_STRING:
      H5::readAttribute(group, "data", value_string);
      value_type = type_string;
      break;
    default:
      assert(0);
    }
  }
  // Cannot check "configurations" since configurations have not been read yet
  // assert(H5::checkGroupNames(group, "configurations", configurations));
}