Debian Codegraph @

packages/seacas/libraries/ioss/src/transform/Iotr_Offset.C

raw
1 // Copyright(C) 1999-2021, 2023, 2024 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "Ioss_Field.h"
8 #include "Ioss_VariableType.h"
9 #include "transform/Iotr_Offset.h"
10 #include <cstddef>
11 #include <stdint.h>
12
13 #include "Ioss_Transform.h"
14 #include "Ioss_TransformFactory.h"
15
16 namespace Iotr {
17
18 const Offset_Factory *Offset_Factory::factory()
19 {
20 static Offset_Factory registerThis;
21 return &registerThis;
22 }
23
24 Offset_Factory::Offset_Factory() : Ioss::TransformFactory("offset")
25 {
26 Ioss::TransformFactory::alias("offset", "add");
27 }
28
29 Ioss::Transform *Offset_Factory::make(const std::string & /*unused*/) const
30 {
31 return new Offset();
32 }
33
34 Offset::Offset() = default;
35
36 void Offset::set_property(const std::string & /*name*/, int value) { intOffset = value; }
37
38 void Offset::set_property(const std::string & /*name*/, double value) { realOffset = value; }
39
40 const Ioss::VariableType *Offset::output_storage(const Ioss::VariableType *in) const
41 {
42 return in;
43 }
44
45 size_t Offset::output_count(size_t in) const
46 {
47 // Does not modify the entity count...
48 return in;
49 }
50
51 bool Offset::internal_execute(const Ioss::Field &field, void *data)
52 {
53 size_t count = field.transformed_count();
54 int components = field.transformed_storage()->component_count();
55
56 if (field.get_type() == Ioss::Field::REAL) {
57 auto *rdata = static_cast<double *>(data);
58
59 for (size_t i = 0; i < count * components; i++) {
60 rdata[i] += realOffset;
61 }
62 }
63 else if (field.get_type() == Ioss::Field::INTEGER) {
64 auto *idata = static_cast<int *>(data);
65
66 for (size_t i = 0; i < count * components; i++) {
67 idata[i] += intOffset;
68 }
69 }
70 else if (field.get_type() == Ioss::Field::INT64) {
71 auto *idata = static_cast<int64_t *>(data);
72
73 for (size_t i = 0; i < count * components; i++) {
74 idata[i] += intOffset;
75 }
76 }
77 else {
78 }
79 return true;
80 }
81 } // namespace Iotr