VTK  9.6.1
vtkIOSSUtilities.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3#ifndef vtkIOSSUtilities_h
4#define vtkIOSSUtilities_h
19
21#include "vtkDoubleArray.h"
22#include "vtkIOSSReader.h"
23#include "vtkLogger.h"
24#include "vtkObject.h"
25#include "vtkSmartPointer.h"
26#include "vtkTypeInt32Array.h"
27#include "vtkTypeInt64Array.h"
28#include "vtkTypeList.h" // Needed for ArrayList definition
29
30// Ioss includes
31#include <vtk_ioss.h>
32// clang-format off
33#include VTK_IOSS(Ioss_Region.h)
34#include VTK_IOSS(Ioss_Transform.h)
35#include VTK_IOSS(Ioss_StructuredBlock.h)
36#include VTK_IOSS(Ioss_SideSet.h)
37// clang-format on
38
39#include <cassert>
40#include <set>
41
42VTK_ABI_NAMESPACE_BEGIN
43class vtkCellArray;
44class vtkDataSet;
45VTK_ABI_NAMESPACE_END
46
47namespace vtkIOSSUtilities
48{
49VTK_ABI_NAMESPACE_BEGIN
50
58
62class Cache
63{
64public:
67
72
78
82 void Clear();
83
84 vtkObject* Find(const Ioss::GroupingEntity* entity, const std::string& cachekey) const;
85 void Insert(const Ioss::GroupingEntity* entity, const std::string& cachekey, vtkObject* array);
86
87private:
88 Cache(const Cache&) = delete;
89 void operator=(const Cache&) = delete;
90
91 class CacheInternals;
92 CacheInternals* Internals;
93};
94
100{
101public:
104
108 std::string GetMessages() const;
109
110private:
111 std::ostringstream Stream;
112 std::ostream* DebugStream;
113 std::ostream* WarningStream;
114};
115
116using EntityNameType = std::pair<vtkTypeUInt64, std::string>;
117
125 vtkTypeList::Create<vtkDoubleArray, vtkTypeInt32Array, vtkTypeInt64Array>>::Result;
126
131std::vector<std::pair<int, double>> GetTime(const Ioss::Region* region);
132
140std::string GetSanitizedBlockName(const Ioss::Region* region, const std::string& name);
141
147template <typename EntityType>
148void GetEntityAndFieldNames(const Ioss::Region* region, const std::vector<EntityType*>& entities,
149 std::set<EntityNameType>& entity_names, std::set<std::string>& field_names)
150{
151 for (const auto& entity : entities)
152 {
153 const int64_t id = entity->property_exists("id") ? entity->get_property("id").get_int() : 0;
154 auto name = vtkIOSSUtilities::GetSanitizedBlockName(region, entity->name());
155 entity_names.insert(EntityNameType{ static_cast<vtkTypeUInt64>(id), name });
156
157 Ioss::NameList attributeNames;
158 entity->field_describe(Ioss::Field::TRANSIENT, &attributeNames);
159 entity->field_describe(Ioss::Field::ATTRIBUTE, &attributeNames);
160 std::copy(
161 attributeNames.begin(), attributeNames.end(), std::inserter(field_names, field_names.end()));
162 }
163}
164
168void GetGlobalFieldNames(const Ioss::Region* region, std::set<std::string>& field_names);
169
173template <>
174void GetEntityAndFieldNames<Ioss::SideSet>(const Ioss::Region* region,
175 const std::vector<Ioss::SideSet*>& entities, std::set<EntityNameType>& entity_names,
176 std::set<std::string>& field_names);
177
185
194
201vtkSmartPointer<vtkDataArray> GetData(const Ioss::GroupingEntity* entity,
202 const std::string& fieldname, Ioss::Transform* transform = nullptr, Cache* cache = nullptr,
203 const std::string& cachekey = std::string());
204
213int GetCellType(const Ioss::ElementTopology* topology);
214
222const Ioss::ElementTopology* GetElementTopology(int vtk_cell_type);
223
235 Ioss::GroupingEntity* group_entity, int& vtk_topology_type, Cache* cache = nullptr);
236
243 const Ioss::GroupingEntity* group_entity, Cache* cache = nullptr);
244
251bool IsFieldTransient(const Ioss::GroupingEntity* entity, const std::string& fieldname);
252
254
257std::string GetDisplacementFieldName(Ioss::GroupingEntity* nodeblock);
260
266
271DatabaseFormatType DetectType(const std::string& dbaseName);
272
278DatabaseFormatType GetFormat(const Ioss::GroupingEntity* entity);
279
286std::vector<Ioss::StructuredBlock*> GetMatchingStructuredBlocks(
287 Ioss::Region* region, const std::string& blockname);
288
289VTK_ABI_NAMESPACE_END
290}
291
292#endif
293// VTK-HeaderTest-Exclude: vtkIOSSUtilities.h
object to represent cell connectivity
abstract class to specify dataset behavior
Definition vtkDataSet.h:57
void Clear()
Clears the cache.
void ClearUnused()
Removes all cached entries not accessed since most recent call to ResetAccessCounts.
void ResetAccessCounts()
Call this to clear internal count for hits.
vtkObject * Find(const Ioss::GroupingEntity *entity, const std::string &cachekey) const
void Insert(const Ioss::GroupingEntity *entity, const std::string &cachekey, vtkObject *array)
std::string GetMessages() const
Provides access to the accumulated messages.
abstract base class for most VTK objects
Definition vtkObject.h:53
Hold a reference to a vtkObjectBase instance.
internal utilities for vtkIOSSReader
typename vtkTypeList::Unique< vtkTypeList::Create< vtkDoubleArray, vtkTypeInt32Array, vtkTypeInt64Array > >::Result ArrayList
List of possible ArrayTypes that are produced by vtkIOSSUtilities.
void GetEntityAndFieldNames< Ioss::SideSet >(const Ioss::Region *region, const std::vector< Ioss::SideSet * > &entities, std::set< EntityNameType > &entity_names, std::set< std::string > &field_names)
Specialization for Ioss::SideSet (see paraview/paraview#21231).
void InitializeEnvironmentForIOSS()
Must be called before using any Ioss library functions.
std::vector< std::pair< int, double > > GetTime(const Ioss::Region *region)
Reads time / timestep information from a region.
std::vector< Ioss::StructuredBlock * > GetMatchingStructuredBlocks(Ioss::Region *region, const std::string &blockname)
Returns collection of StructuredBlock's matching the selected blockname.
void GetEntityAndFieldNames(const Ioss::Region *region, const std::vector< EntityType * > &entities, std::set< EntityNameType > &entity_names, std::set< std::string > &field_names)
Populates entitySelection with available entity block (or set) names and populates fieldSelection wit...
DatabaseFormatType GetFormat(const Ioss::GroupingEntity *entity)
Given any GroupingEntity pointer, returns the format that the associated database is in.
void GetGlobalFieldNames(const Ioss::Region *region, std::set< std::string > &field_names)
Reads global fields from the region and populates field_names.
bool IsFieldTransient(const Ioss::GroupingEntity *entity, const std::string &fieldname)
Returns true if the field is transient.
vtkSmartPointer< vtkPoints > GetMeshModelCoordinates(const Ioss::GroupingEntity *group_entity, Cache *cache=nullptr)
Read points from the group_entity.
Ioss::EntityType GetIOSSEntityType(vtkIOSSReader::EntityType vtk_type)
For the given vtkIOSSReader::EntityType return the corresponding Ioss::EntityType.
const Ioss::ElementTopology * GetElementTopology(int vtk_cell_type)
Returns an Ioss topology element, if possible, given a VTK cell type.
vtkSmartPointer< vtkDataArray > CreateArray(const Ioss::Field &field)
Create an array for the given field.
vtkSmartPointer< vtkCellArray > GetConnectivity(Ioss::GroupingEntity *group_entity, int &vtk_topology_type, Cache *cache=nullptr)
Read connectivity information from the group_entity.
std::string GetSanitizedBlockName(const Ioss::Region *region, const std::string &name)
This is primarily intended for CGNS.
std::string GetDisplacementFieldName(Ioss::GroupingEntity *nodeblock)
Finds a displacement field name.
vtkSmartPointer< vtkDataArray > GetData(const Ioss::GroupingEntity *entity, const std::string &fieldname, Ioss::Transform *transform=nullptr, Cache *cache=nullptr, const std::string &cachekey=std::string())
Returns a VTK array for a given field (fieldname) on the chosen block (or set) entity.
std::pair< vtkTypeUInt64, std::string > EntityNameType
DatabaseFormatType DetectType(const std::string &dbaseName)
Given a filename determines and returns the database type.
Remove all duplicate types from TypeList TList, storing the new list in Result.
int GetCellType() override
Implement the vtkCell API.