| 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_Scale.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 Scale_Factory *Scale_Factory::factory() |
| 19 |
{ |
| 20 |
static Scale_Factory registerThis; |
| 21 |
return ®isterThis; |
| 22 |
} |
| 23 |
|
| 24 |
Scale_Factory::Scale_Factory() : Ioss::TransformFactory("scale") |
| 25 |
{ |
| 26 |
Ioss::TransformFactory::alias("scale", "multiply"); |
| 27 |
} |
| 28 |
|
| 29 |
Ioss::Transform *Scale_Factory::make(const std::string & /*unused*/) const { return new Scale(); } |
| 30 |
|
| 31 |
Scale::Scale() = default; |
| 32 |
|
| 33 |
void Scale::set_property(const std::string & /*name*/, int value) { intMultiplier = value; } |
| 34 |
|
| 35 |
void Scale::set_property(const std::string & /*name*/, double value) { realMultiplier = value; } |
| 36 |
|
| 37 |
const Ioss::VariableType *Scale::output_storage(const Ioss::VariableType *in) const { return in; } |
| 38 |
|
| 39 |
size_t Scale::output_count(size_t in) const |
| 40 |
{ |
| 41 |
// Does not modify the entity count... |
| 42 |
return in; |
| 43 |
} |
| 44 |
|
| 45 |
bool Scale::internal_execute(const Ioss::Field &field, void *data) |
| 46 |
{ |
| 47 |
size_t count = field.transformed_count(); |
| 48 |
int components = field.transformed_storage()->component_count(); |
| 49 |
|
| 50 |
if (field.get_type() == Ioss::Field::REAL) { |
| 51 |
auto *rdata = static_cast<double *>(data); |
| 52 |
|
| 53 |
for (size_t i = 0; i < count * components; i++) { |
| 54 |
rdata[i] *= realMultiplier; |
| 55 |
} |
| 56 |
} |
| 57 |
else if (field.get_type() == Ioss::Field::INTEGER) { |
| 58 |
auto *idata = static_cast<int *>(data); |
| 59 |
|
| 60 |
for (size_t i = 0; i < count * components; i++) { |
| 61 |
idata[i] *= intMultiplier; |
| 62 |
} |
| 63 |
} |
| 64 |
else if (field.get_type() == Ioss::Field::INT64) { |
| 65 |
auto *idata = static_cast<int64_t *>(data); |
| 66 |
|
| 67 |
for (size_t i = 0; i < count * components; i++) { |
| 68 |
idata[i] *= intMultiplier; |
| 69 |
} |
| 70 |
} |
| 71 |
else { |
| 72 |
} |
| 73 |
return true; |
| 74 |
} |
| 75 |
} // namespace Iotr |