| 1952 | } |
| 1953 | |
| 1954 | vtkSmartPointer<vtkAbstractArray> vtkIOSSReaderInternal::GetField(const std::string& fieldname, |
| 1955 | Ioss::Region* region, const Ioss::GroupingEntity* group_entity, const DatabaseHandle& handle, |
| 1956 | int timestep, vtkIdTypeArray* ids_to_extract, const std::string& cache_key_suffix) |
| 1957 | { |
| 1958 | const auto get_field = [&fieldname, ®ion, ×tep, &handle, this]( |
| 1959 | const Ioss::GroupingEntity* entity) -> vtkSmartPointer<vtkAbstractArray> |
| 1960 | { |
| 1961 | if (!entity->field_exists(fieldname)) |
| 1962 | { |
| 1963 | return nullptr; |
| 1964 | } |
| 1965 | |
| 1966 | if (!vtkIOSSUtilities::IsFieldTransient(entity, fieldname)) |
| 1967 | { |
| 1968 | // non-time dependent field. |
| 1969 | return vtkIOSSUtilities::GetData(entity, fieldname, /*transform=*/nullptr, &this->Cache); |
| 1970 | } |
| 1971 | |
| 1972 | // determine state for transient data. |
| 1973 | const auto& stateVector = this->DatabaseTimes[handle.first]; |
| 1974 | if (stateVector.empty()) |
| 1975 | { |
| 1976 | // see paraview/paraview#20658 for why this is needed. |
| 1977 | return nullptr; |
| 1978 | } |
| 1979 | |
| 1980 | auto iter = std::find_if(stateVector.begin(), stateVector.end(), |
| 1981 | [&](const std::pair<int, double>& pair) |
| 1982 | { return pair.second == this->TimestepValues[timestep]; }); |
| 1983 | |
| 1984 | if (iter == stateVector.end()) |
| 1985 | { |
| 1986 | throw std::runtime_error("Invalid timestep chosen: " + vtk::to_string(timestep)); |
| 1987 | } |
| 1988 | const int state = iter->first; |
| 1989 | region->begin_state(state); |
| 1990 | try |
| 1991 | { |
| 1992 | const std::string key = "__vtk_transient_" + fieldname + "_" + vtk::to_string(state) + "__"; |
| 1993 | auto f = |
| 1994 | vtkIOSSUtilities::GetData(entity, fieldname, /*transform=*/nullptr, &this->Cache, key); |
| 1995 | region->end_state(state); |
| 1996 | return f; |
| 1997 | } |
| 1998 | catch (...) |
| 1999 | { |
| 2000 | region->end_state(state); |
| 2001 | std::rethrow_exception(std::current_exception()); |
| 2002 | } |
| 2003 | }; |
| 2004 | |
| 2005 | const auto get_field_for_entity = [&]() |
| 2006 | { |
| 2007 | if (group_entity->type() == Ioss::EntityType::SIDESET) |
| 2008 | { |
| 2009 | // sidesets need to be handled specially. For sidesets, the fields are |
| 2010 | // available on nested sideblocks. |
| 2011 | std::vector<vtkSmartPointer<vtkAbstractArray>> arrays; |