VTK  9.2.6
vtkIOSSUtilities.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkIOSSUtilities.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
30#ifndef vtkIOSSUtilities_h
31#define vtkIOSSUtilities_h
32
34#include "vtkDoubleArray.h"
35#include "vtkIOSSReader.h"
36#include "vtkLogger.h"
37#include "vtkObject.h"
38#include "vtkSmartPointer.h"
39#include "vtkTypeInt32Array.h"
40#include "vtkTypeInt64Array.h"
41#include "vtkTypeList.h" // Needed for ArrayList definition
42
43// Ioss includes
44#include <vtk_ioss.h>
45// clang-format off
46#include VTK_IOSS(Ioss_Region.h)
47#include VTK_IOSS(Ioss_Transform.h)
48#include VTK_IOSS(Ioss_StructuredBlock.h)
49#include VTK_IOSS(Ioss_SideSet.h)
50#include VTK_IOSS(Ioss_SideBlock.h)
51// clang-format on
52
53#include <cassert>
54#include <set>
55
56class vtkCellArray;
57class vtkDataSet;
58
59namespace vtkIOSSUtilities
60{
61
63{
68};
69
73class Cache
74{
75public:
78
83
89
93 void Clear();
94
95 vtkObject* Find(const Ioss::GroupingEntity* entity, const std::string& cachekey) const;
96 void Insert(const Ioss::GroupingEntity* entity, const std::string& cachekey, vtkObject* array);
97
98private:
99 Cache(const Cache&) = delete;
100 void operator=(const Cache&) = delete;
101
102 class CacheInternals;
103 CacheInternals* Internals;
104};
105
111{
112public:
115
120
121private:
122 std::ostringstream Stream;
123 std::ostream* DebugStream;
124 std::ostream* WarningStream;
125};
126
127using EntityNameType = std::pair<vtkTypeUInt64, std::string>;
128
136 vtkTypeList::Create<vtkDoubleArray, vtkTypeInt32Array, vtkTypeInt64Array>>::Result;
137
142std::vector<std::pair<int, double>> GetTime(const Ioss::Region* region);
143
151std::string GetSanitizedBlockName(const Ioss::Region* region, const std::string& name);
152
158template <typename EntityType>
159void GetEntityAndFieldNames(const Ioss::Region* region, const std::vector<EntityType*>& entities,
160 std::set<EntityNameType>& entity_names, std::set<std::string>& field_names)
161{
162 for (const auto& entity : entities)
163 {
164 const int64_t id = entity->property_exists("id") ? entity->get_property("id").get_int() : 0;
165 auto name = vtkIOSSUtilities::GetSanitizedBlockName(region, entity->name());
166 entity_names.insert(EntityNameType{ static_cast<vtkTypeUInt64>(id), name });
167
168 Ioss::NameList attributeNames;
169 entity->field_describe(Ioss::Field::TRANSIENT, &attributeNames);
170 entity->field_describe(Ioss::Field::ATTRIBUTE, &attributeNames);
171 std::copy(
172 attributeNames.begin(), attributeNames.end(), std::inserter(field_names, field_names.end()));
173 }
174}
178template <>
179void GetEntityAndFieldNames<Ioss::SideSet>(const Ioss::Region* region,
180 const std::vector<Ioss::SideSet*>& entities, std::set<EntityNameType>& entity_names,
181 std::set<std::string>& field_names);
182
190
199
206vtkSmartPointer<vtkDataArray> GetData(const Ioss::GroupingEntity* entity,
207 const std::string& fieldname, Ioss::Transform* transform = nullptr, Cache* cache = nullptr,
208 const std::string& cachekey = std::string());
209
218int GetCellType(const Ioss::ElementTopology* topology);
219
227const Ioss::ElementTopology* GetElementTopology(int vtk_cell_type);
228
240 Ioss::GroupingEntity* group_entity, int& vtk_topology_type, Cache* cache = nullptr);
241
248 const Ioss::GroupingEntity* group_entity, Cache* cache = nullptr);
249
256bool IsFieldTransient(Ioss::GroupingEntity* entity, const std::string& fieldname);
257
259
262std::string GetDisplacementFieldName(Ioss::GroupingEntity* nodeblock);
265
271
277
283DatabaseFormatType GetFormat(const Ioss::GroupingEntity* entity);
284
291std::vector<Ioss::StructuredBlock*> GetMatchingStructuredBlocks(
292 Ioss::Region* region, const std::string& blockname);
293};
294
295#endif
296// VTK-HeaderTest-Exclude: vtkIOSSUtilities.h
object to represent cell connectivity
Definition: vtkCellArray.h:296
abstract class to specify dataset behavior
Definition: vtkDataSet.h:172
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)
A helper to instantiate on stack to temporarily redirect non-critical messsages emanating from IOSS.
std::string GetMessages() const
Provides access to the accumulated messages.
abstract base class for most VTK objects
Definition: vtkObject.h:79
internal utilities for vtkIOSSReader
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.
std::pair< vtkTypeUInt64, std::string > EntityNameType
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.
int GetCellType(const Ioss::ElementTopology *topology)
Returns VTK celltype for a Ioss topology element.
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.
bool IsFieldTransient(Ioss::GroupingEntity *entity, const std::string &fieldname)
Returns true if the field is transient.
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.
DatabaseFormatType DetectType(const std::string &dbaseName)
Given a filename determines and returns the database type.
@ field
Definition: vtkX3D.h:183
@ Transform
Definition: vtkX3D.h:47
@ name
Definition: vtkX3D.h:225
@ string
Definition: vtkX3D.h:496
Remove all duplicate types from TypeList TList, storing the new list in Result.
Definition: vtkTypeList.h:126