Skip to main content

EnSight 2025 R2

libuserd_interface

Last update: 16.07.2025
Go to the documentation of this file.
1/*
2 *
3 * *************************************************************
4 * Copyright 2024 ANSYS, Inc.
5 * All Rights Reserved.
6 *
7 * Restricted Rights Legend
8 *
9 * Use, duplication, or disclosure of this
10 * software and its documentation by the
11 * Government is subject to restrictions as
12 * set forth in subdivision [(b)(3)(ii)] of
13 * the Rights in Technical Data and Computer
14 * Software clause at 52.227-7013.
15 * *************************************************************
16 */
17
18#ifndef LIBUSERD_INTERFACE_H
19#define LIBUSERD_INTERFACE_H
20
21#ifdef __cplusplus
22
23#include <string>
24#include <vector>
25#include <map>
26#include <array>
27
28#include "libuserd_common.h"
29
47/* TODO
48 * - Add support for structured data
49 */
50
56namespace libuserd {
57
59 std::string name;
60 std::vector<std::string> file_1_extension;
61 std::vector<std::string> file_2_extension;
62 };
63
64 // Forward declaration
65 class ReaderInfo;
66 class LibUserd;
67 class Reader;
68
76 class Query : public IQuery {
77
78 public:
86 size_t num_points() override;
87
99 ErrorCode data(float* x, float* y) override;
100
101 private:
102 Query(const uint32_t id,
103 const uint32_t reader_id,
104 const std::string& name,
105 const std::string& x_title,
106 const std::string& y_title,
107 const std::map<const std::string, std::string>& metadata);
108 friend class Reader;
109 uint32_t m_reader_id;
110 };
111
119 class Variable : public IVariable {
120
121 public:
122
123 private:
124 Variable(const uint32_t _id,
125 const std::string& _name,
126 const std::string& _unit_label,
127 const std::string& _unit_dims,
128 const VariableLocation _location,
129 const VariableType _type,
130 const bool _time_varying,
131 const bool _complex,
132 const bool _interleave_flag,
133 const uint32_t _number_of_components,
134 const std::map<const std::string, std::string>& _metadata);
135
136 friend class Reader;
137 };
138
146 class Part : public IPart {
147
148 public:
158 ErrorCode num_nodes(std::size_t& num_coords, int32_t rank = 0) override;
159
171 ErrorCode nodes(float* xyz, int32_t rank = 0) override;
172
182 ErrorCode num_elements(std::map<ElementType, std::size_t>& elements, int32_t rank = 0) override;
183
200 ErrorCode element_conn(ElementType elem_type, uint32_t* connectivity, int32_t rank = 0) override;
201
215 ErrorCode element_conn_nsided_size(ElementType elem_type,
216 size_t& nodes_per_polygon_size, size_t& nodes_size, int32_t rank = 0) override;
217
229 ErrorCode element_conn_nsided(ElementType elem_type, uint32_t* nodes_per_polygon, uint32_t* nodes, int32_t rank = 0) override;
230
246 ErrorCode element_conn_nfaced_size(ElementType elem_type, size_t& faces_per_element_size,
247 size_t& nodes_per_face_size, size_t& indices_size, int32_t rank = 0) override;
248
261 ErrorCode element_conn_nfaced(ElementType elem_type,
262 uint32_t* faces_per_element, uint32_t* nodes_per_face, uint32_t* nodes, int32_t rank = 0) override;
263
280 ErrorCode variable_values(IVariable* var, ElementType elem_type,
281 bool complex, uint32_t component, float* array, int32_t rank = 0) override;
282
291 ErrorCode rigid_body_transform(struct RigidBodyTransform& transform) override;
292
293 private:
294 Part(const uint32_t index,
295 const uint32_t id,
296 const uint32_t reader_id,
297 const std::string& name,
298 const std::map<const std::string, std::string>& metadata,
299 const PartHints hints);
300
301 friend class Reader;
302 };
303
304
314 class ReaderInfo : public IReaderInfo {
315
316 public:
331 ErrorCode read_dataset(const std::string& file1, const std::string& file2, IReader*& reader) override;
332
343 static bool get_userd_xtra_gui_values(int reader_id, Options& userd_options);
344
345 private:
346 ReaderInfo(const uint32_t id,
347 const std::string name,
348 const std::string description,
349 const std::string file_labels[2],
350 struct Options options);
351 friend class LibUserd;
352 };
353
362 class Reader : public IReader {
363
364 public:
375 ErrorCode parts(std::vector<IPart*>& part_list) override;
376
387 ErrorCode variables(std::vector<IVariable*>& variable_list) override;
388
399 ErrorCode queries(std::vector<IQuery*>& query_list) override;
400
410 ErrorCode get_number_of_time_sets(uint32_t & number_of_time_sets) override;
411
422 ErrorCode timevalues(std::vector<float> & timevalues, uint32_t timeset_number = 0) override;
423
434 ErrorCode set_timevalue(float timevalue, uint32_t timeset_number = 0) override;
435
446 ErrorCode set_timestep(uint32_t timestep, uint32_t timeset_number = 0) override;
447
458 ErrorCode variable_value(const IVariable* var, float& value, int32_t rank = 0) override;
459
477 UpdateHints dynamic_update_check(UpdateHints changes_allowed) override;
478
486 bool is_geometry_changing() override;
487
495 const IReaderInfo* info() override;
496
497 // static helper methods
498 static ErrorCode get_geometry_info(int reader_id, int part_index, std::vector<int>& geoms_vector);
499 static ErrorCode number_of_geometries(int reader_id, int part_index, int& number_of_geoms);
500
501 private:
503 friend class ReaderInfo;
504
505 ReaderInfo m_reader_info;
506
507 // Private helper methods
508 ErrorCode get_meta_data_string();
509 void parse_metatags(std::map<const std::string, std::string>& map, const char* section_name);
510 ErrorCode get_part_hints(int reader_id, int part_index, PartHints& part_hints);
511
512 std::map<const std::string, std::string> m_part_metatags;
513 std::map<const std::string, std::string> m_var_metatags;
514 std::map<const std::string, std::string> m_query_metatags;
515 };
516
517
518
527 class LibUserd : public ILibUserd {
528 public:
529
541
542 /*
543 * These functions need to be called before initialize() is called.
544 */
545
559 ErrorCode set_reader_path(const std::string& path) override;
560
571 ErrorCode set_message_handler(ErrorProc, void* userdata) override;
572
585 ErrorCode initialize(int32_t number_of_ranks = 0) override;
586
594 size_t get_available_reader_count() override;
595
604 ErrorCode get_all_readers(std::vector<IReaderInfo*>& info) override;
605
617 ErrorCode query_format(const std::string& name1, const std::string& name2, std::vector<IReaderInfo*>& reader_info) override;
618
627 ErrorCode shutdown() override;
628
638
639 private:
640 LibUserd();
641 LibUserd(const LibUserd&) = delete;
642 static LibUserd* s_libuserd;
643
644 std::vector<fileExtensions> m_reader_extensions;
645 void initReaderExtensions();
646 std::string processFilename(const std::string &filename);
647
648 friend class ReaderInfo;
649 static void set_active_reader(Reader* reader);
650 static Reader* s_active_reader;
651 };
652}
653
654#endif
655
656#endif
ErrorCode get_all_readers(std::vector< IReaderInfo * > &info) override
get_all_readers
ErrorCode shutdown() override
shutdown
ErrorCode initialize(int32_t number_of_ranks=0) override
initialize
ErrorCode query_format(const std::string &name1, const std::string &name2, std::vector< IReaderInfo * > &reader_info) override
query_format
ErrorCode set_message_handler(ErrorProc, void *userdata) override
set_message_handler
static Reader * get_active_reader()
get_active_reader
static LibUserd * library_interface()
library_interface
ErrorCode set_reader_path(const std::string &path) override
set_reader_path
size_t get_available_reader_count() override
get_available_reader_count
ErrorCode element_conn_nsided(ElementType elem_type, uint32_t *nodes_per_polygon, uint32_t *nodes, int32_t rank=0) override
element_conn_nsided
ErrorCode rigid_body_transform(struct RigidBodyTransform &transform) override
rigid_body_transform
ErrorCode num_nodes(std::size_t &num_coords, int32_t rank=0) override
num_nodes
ErrorCode element_conn_nfaced(ElementType elem_type, uint32_t *faces_per_element, uint32_t *nodes_per_face, uint32_t *nodes, int32_t rank=0) override
element_conn_nfaced
ErrorCode variable_values(IVariable *var, ElementType elem_type, bool complex, uint32_t component, float *array, int32_t rank=0) override
variable_values
ErrorCode num_elements(std::map< ElementType, std::size_t > &elements, int32_t rank=0) override
num_elements
ErrorCode element_conn_nfaced_size(ElementType elem_type, size_t &faces_per_element_size, size_t &nodes_per_face_size, size_t &indices_size, int32_t rank=0) override
element_conn_nfaced_size
ErrorCode nodes(float *xyz, int32_t rank=0) override
nodes
ErrorCode element_conn_nsided_size(ElementType elem_type, size_t &nodes_per_polygon_size, size_t &nodes_size, int32_t rank=0) override
element_conn_nsided_size
ErrorCode element_conn(ElementType elem_type, uint32_t *connectivity, int32_t rank=0) override
element_conn
size_t num_points() override
num_points
ErrorCode data(float *x, float *y) override
data
ErrorCode timevalues(std::vector< float > &timevalues, uint32_t timeset_number=0) override
timevalues
ErrorCode queries(std::vector< IQuery * > &query_list) override
queries
ErrorCode variables(std::vector< IVariable * > &variable_list) override
variables
const IReaderInfo * info() override
info
ErrorCode set_timestep(uint32_t timestep, uint32_t timeset_number=0) override
set_timestep
bool is_geometry_changing() override
is_geometry_changing
ErrorCode variable_value(const IVariable *var, float &value, int32_t rank=0) override
variable_value
ErrorCode parts(std::vector< IPart * > &part_list) override
parts
ErrorCode set_timevalue(float timevalue, uint32_t timeset_number=0) override
timevalue
ErrorCode get_number_of_time_sets(uint32_t &number_of_time_sets) override
timevalues
UpdateHints dynamic_update_check(UpdateHints changes_allowed) override
dynamic_update_check
ErrorCode read_dataset(const std::string &file1, const std::string &file2, IReader *&reader) override
read_dataset
static bool get_userd_xtra_gui_values(int reader_id, Options &userd_options)
Retrieves extra GUI values for a specified reader.

Connect with Ansys