| 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_Scale3D.h" |
| 10 |
#include <cassert> |
| 11 |
#include <cstddef> |
| 12 |
#include <stdint.h> |
| 13 |
#include <vector> |
| 14 |
|
| 15 |
#include "Ioss_Transform.h" |
| 16 |
#include "Ioss_TransformFactory.h" |
| 17 |
|
| 18 |
namespace Iotr { |
| 19 |
|
| 20 |
const Scale3D_Factory *Scale3D_Factory::factory() |
| 21 |
{ |
| 22 |
static Scale3D_Factory registerThis; |
| 23 |
return ®isterThis; |
| 24 |
} |
| 25 |
|
| 26 |
Scale3D_Factory::Scale3D_Factory() : Ioss::TransformFactory("scale3D") |
| 27 |
{ |
| 28 |
Ioss::TransformFactory::alias("scale3D", "multiply3D"); |
| 29 |
} |
| 30 |
|
| 31 |
Ioss::Transform *Scale3D_Factory::make(const std::string & /*unused*/) const |
| 32 |
{ |
| 33 |
return new Scale3D(); |
| 34 |
} |
| 35 |
|
| 36 |
Scale3D::Scale3D() |
| 37 |
{ |
| 38 |
intScale[0] = intScale[1] = intScale[2] = 1; |
| 39 |
realScale[0] = realScale[1] = realScale[2] = 1.0; |
| 40 |
} |
| 41 |
|
| 42 |
void Scale3D::set_properties(const std::string & /*name*/, const std::vector<int> &values) |
| 43 |
{ |
| 44 |
assert(values.size() == 3); |
| 45 |
intScale[0] = values[0]; |
| 46 |
intScale[1] = values[1]; |
| 47 |
intScale[2] = values[2]; |
| 48 |
} |
| 49 |
|
| 50 |
void Scale3D::set_properties(const std::string & /*name*/, const std::vector<double> &values) |
| 51 |
{ |
| 52 |
assert(values.size() == 3); |
| 53 |
realScale[0] = values[0]; |
| 54 |
realScale[1] = values[1]; |
| 55 |
realScale[2] = values[2]; |
| 56 |
} |
| 57 |
|
| 58 |
const Ioss::VariableType *Scale3D::output_storage(const Ioss::VariableType *in) const |
| 59 |
{ |
| 60 |
return in; |
| 61 |
} |
| 62 |
|
| 63 |
size_t Scale3D::output_count(size_t in) const |
| 64 |
{ |
| 65 |
// Does not modify the entity count... |
| 66 |
return in; |
| 67 |
} |
| 68 |
|
| 69 |
bool Scale3D::internal_execute(const Ioss::Field &field, void *data) |
| 70 |
{ |
| 71 |
size_t count = field.transformed_count(); |
| 72 |
assert(field.transformed_storage()->component_count() == 3); |
| 73 |
|
| 74 |
if (field.get_type() == Ioss::Field::REAL) { |
| 75 |
auto *rdata = static_cast<double *>(data); |
| 76 |
|
| 77 |
for (size_t i = 0; i < count * 3; i += 3) { |
| 78 |
rdata[i + 0] *= realScale[0]; |
| 79 |
rdata[i + 1] *= realScale[1]; |
| 80 |
rdata[i + 2] *= realScale[2]; |
| 81 |
} |
| 82 |
} |
| 83 |
else if (field.get_type() == Ioss::Field::INTEGER) { |
| 84 |
auto *idata = static_cast<int *>(data); |
| 85 |
|
| 86 |
for (size_t i = 0; i < count * 3; i += 3) { |
| 87 |
idata[i + 0] *= intScale[0]; |
| 88 |
idata[i + 1] *= intScale[1]; |
| 89 |
idata[i + 2] *= intScale[2]; |
| 90 |
} |
| 91 |
} |
| 92 |
else if (field.get_type() == Ioss::Field::INT64) { |
| 93 |
auto *idata = static_cast<int64_t *>(data); |
| 94 |
|
| 95 |
for (size_t i = 0; i < count * 3; i += 3) { |
| 96 |
idata[i + 0] *= intScale[0]; |
| 97 |
idata[i + 1] *= intScale[1]; |
| 98 |
idata[i + 2] *= intScale[2]; |
| 99 |
} |
| 100 |
} |
| 101 |
else { |
| 102 |
} |
| 103 |
return true; |
| 104 |
} |
| 105 |
} // namespace Iotr |