Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOSS: Move transform factory from Iotr to Ioss #434

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/seacas/applications/ejoin/EJoin.C
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include <Ioss_SmartAssert.h>
#include <Ioss_SubSystem.h>
#include <Ioss_Transform.h>
#include <transform/Iotr_Factory.h>

#include "EJ_CodeTypes.h"
#include "EJ_SystemInterface.h"
Expand Down Expand Up @@ -228,7 +227,7 @@ int main(int argc, char *argv[])
if (p > 0 && (offset.x != 0.0 || offset.y != 0.0 || offset.z != 0.0)) {
Ioss::NodeBlock *nb = part_mesh[p]->get_node_blocks()[0];
Ioss::Field coord = nb->get_field("mesh_model_coordinates");
Ioss::Transform *transform = Iotr::Factory::create("offset3D");
auto *transform = Ioss::Transform::create("offset3D");
assert(transform != nullptr);
std::vector<double> values(3);
values[0] = offset.x * p;
Expand Down
8 changes: 7 additions & 1 deletion packages/seacas/libraries/ioss/src/Ioss_Transform.C
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// Copyright(C) 1999-2020 National Technology & Engineering Solutions
// Copyright(C) 1999-2020, 2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
// See packages/seacas/LICENSE for details

#include "Ioss_Transform.h"
#include "Ioss_TransformFactory.h"
#include <vector>

namespace Ioss {

class Field;

Transform *Transform::create(const std::string &transform)
{
return TransformFactory::create(transform);
}

bool Transform::execute(const Ioss::Field &field, void *data)
{
return internal_execute(field, data);
Expand Down
2 changes: 2 additions & 0 deletions packages/seacas/libraries/ioss/src/Ioss_Transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace Ioss {
virtual void set_properties(const std::string &name, const std::vector<int> &values);
virtual void set_properties(const std::string &name, const std::vector<double> &values);

static Transform *create(const std::string &transform);

protected:
Transform() = default;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright(C) 1999-2021 National Technology & Engineering Solutions
// Copyright(C) 1999-2021, 2024, 2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
// See packages/seacas/LICENSE for details

#include "Ioss_TransformFactory.h"
#include "Ioss_Utils.h"
#include "transform/Iotr_Factory.h"
#include <map>
#include <ostream>
#include <string>
Expand All @@ -14,11 +14,8 @@

namespace Ioss {
class Transform;
} // namespace Ioss

namespace Iotr {

Ioss::Transform *Factory::create(const std::string &type)
Ioss::Transform *TransformFactory::create(const std::string &type)
{
Ioss::Transform *transform = nullptr;
auto iter = registry().find(type);
Expand All @@ -36,20 +33,20 @@ namespace Iotr {
}
}
else {
Factory *factory = (*iter).second;
transform = factory->make(type);
TransformFactory *factory = (*iter).second;
transform = factory->make(type);
}
return transform;
}

Ioss::NameList Factory::describe()
Ioss::NameList TransformFactory::describe()
{
Ioss::NameList names;
describe(&names);
return names;
}

int Factory::describe(Ioss::NameList *names)
int TransformFactory::describe(Ioss::NameList *names)
{
int count = 0;
for (const auto &entry : registry()) {
Expand All @@ -59,18 +56,21 @@ namespace Iotr {
return count;
}

Factory::Factory(const std::string &type) { registry().insert(std::make_pair(type, this)); }
TransformFactory::TransformFactory(const std::string &type)
{
registry().insert(std::make_pair(type, this));
}

void Factory::alias(const std::string &base, const std::string &syn)
void TransformFactory::alias(const std::string &base, const std::string &syn)
{
Factory *factory = (*registry().find(base)).second;
TransformFactory *factory = (*registry().find(base)).second;
registry().insert(std::make_pair(syn, factory));
}

FactoryMap &Factory::registry()
TransformFactoryMap &TransformFactory::registry()
{
static FactoryMap registry_;
static TransformFactoryMap registry_;
return registry_;
}

} // namespace Iotr
} // namespace Ioss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 2022, 2023 National Technology & Engineering Solutions
// Copyright(C) 2022, 2023, 2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand All @@ -11,32 +11,30 @@
#include <map>
#include <string>

#include "iotr_export.h"
#include "ioss_export.h"

namespace Ioss {
class Transform;
} // namespace Ioss

namespace Iotr {
class Factory;
class TransformFactory;

using FactoryMap = std::map<std::string, Factory *, std::less<>>;
using TransformFactoryMap = std::map<std::string, TransformFactory *, std::less<>>;

class IOTR_EXPORT Factory
class IOSS_EXPORT TransformFactory
{
public:
virtual ~Factory() = default;
virtual ~TransformFactory() = default;
static Ioss::Transform *create(const std::string &type);

static int describe(Ioss::NameList *names);
static Ioss::NameList describe();

protected:
explicit Factory(const std::string &type);
explicit TransformFactory(const std::string &type);
virtual Ioss::Transform *make(const std::string &) const = 0;
static void alias(const std::string &base, const std::string &syn);

private:
static FactoryMap &registry();
static TransformFactoryMap &registry();
};
} // namespace Iotr
} // namespace Ioss
7 changes: 3 additions & 4 deletions packages/seacas/libraries/ioss/src/main/io_shell_ts.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand All @@ -17,7 +17,6 @@
#include "Ioss_SurfaceSplit.h"
#include "Ioss_Transform.h"
#include "Ioss_Utils.h"
#include "transform/Iotr_Factory.h"
#include <fmt/format.h>

#include <algorithm>
Expand Down Expand Up @@ -949,11 +948,11 @@ namespace {
Ioss::Field tr_field(out_field_name, field.get_type(), field.raw_storage(),
field.get_role(), field.raw_count());

Ioss::Transform *transform = Iotr::Factory::create("vector magnitude");
auto *transform = Ioss::Transform::create("vector magnitude");
assert(transform != nullptr);
tr_field.add_transform(transform);

Ioss::Transform *max_transform = Iotr::Factory::create("absolute_maximum");
auto *max_transform = Ioss::Transform::create("absolute_maximum");
assert(max_transform != nullptr);
tr_field.add_transform(max_transform);

Expand Down
14 changes: 7 additions & 7 deletions packages/seacas/libraries/ioss/src/transform/Iotr_MinMax.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2021, 2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2021, 2023, 2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand All @@ -13,7 +13,7 @@
#include <string> // for operator==, string

#include "Ioss_Transform.h" // for Factory, Transform
#include "Iotr_Factory.h"
#include "Ioss_TransformFactory.h"

namespace Iotr {

Expand All @@ -23,12 +23,12 @@ namespace Iotr {
return &registerThis;
}

MinMax_Factory::MinMax_Factory() : Factory("generic_minmax")
MinMax_Factory::MinMax_Factory() : Ioss::TransformFactory("generic_minmax")
{
Factory::alias("generic_minmax", "minimum");
Factory::alias("generic_minmax", "maximum");
Factory::alias("generic_minmax", "absolute_minimum");
Factory::alias("generic_minmax", "absolute_maximum");
Ioss::TransformFactory::alias("generic_minmax", "minimum");
Ioss::TransformFactory::alias("generic_minmax", "maximum");
Ioss::TransformFactory::alias("generic_minmax", "absolute_minimum");
Ioss::TransformFactory::alias("generic_minmax", "absolute_maximum");
}

Ioss::Transform *MinMax_Factory::make(const std::string &type) const { return new MinMax(type); }
Expand Down
8 changes: 4 additions & 4 deletions packages/seacas/libraries/ioss/src/transform/Iotr_MinMax.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright(C) 1999-2022 National Technology & Engineering Solutions
// Copyright(C) 1999-2022, 2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
// See packages/seacas/LICENSE for details

#pragma once

#include "Ioss_Transform.h" // for Transform, Factory
#include "Ioss_Transform.h" // for Transform, Factory
#include "Ioss_TransformFactory.h"
#include "Ioss_VariableType.h" // for VariableType
#include "transform/Iotr_Factory.h"
#include <stddef.h>
#include <string> // for string

Expand All @@ -20,7 +20,7 @@ namespace Ioss {

namespace Iotr {

class IOTR_EXPORT MinMax_Factory : public Factory
class IOTR_EXPORT MinMax_Factory : public Ioss::TransformFactory
{
public:
static const MinMax_Factory *factory();
Expand Down
9 changes: 6 additions & 3 deletions packages/seacas/libraries/ioss/src/transform/Iotr_Offset.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2021, 2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2021, 2023, 2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand All @@ -11,7 +11,7 @@
#include <stdint.h>

#include "Ioss_Transform.h"
#include "Iotr_Factory.h"
#include "Ioss_TransformFactory.h"

namespace Iotr {

Expand All @@ -21,7 +21,10 @@ namespace Iotr {
return &registerThis;
}

Offset_Factory::Offset_Factory() : Factory("offset") { Factory::alias("offset", "add"); }
Offset_Factory::Offset_Factory() : Ioss::TransformFactory("offset")
{
Ioss::TransformFactory::alias("offset", "add");
}

Ioss::Transform *Offset_Factory::make(const std::string & /*unused*/) const
{
Expand Down
4 changes: 2 additions & 2 deletions packages/seacas/libraries/ioss/src/transform/Iotr_Offset.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#pragma once

#include "Ioss_Transform.h" // for Transform, Factory
#include "transform/Iotr_Factory.h"
#include "Ioss_TransformFactory.h"
#include <stddef.h>
#include <string> // for string

Expand All @@ -20,7 +20,7 @@ namespace Ioss {

namespace Iotr {

class IOTR_EXPORT Offset_Factory : public Factory
class IOTR_EXPORT Offset_Factory : public Ioss::TransformFactory
{
public:
static const Offset_Factory *factory();
Expand Down
8 changes: 4 additions & 4 deletions packages/seacas/libraries/ioss/src/transform/Iotr_Offset3D.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2021, 2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2021, 2023, 2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand All @@ -13,7 +13,7 @@
#include <vector>

#include "Ioss_Transform.h"
#include "Iotr_Factory.h"
#include "Ioss_TransformFactory.h"

namespace Iotr {

Expand All @@ -23,9 +23,9 @@ namespace Iotr {
return &registerThis;
}

Offset3D_Factory::Offset3D_Factory() : Factory("offset3D")
Offset3D_Factory::Offset3D_Factory() : Ioss::TransformFactory("offset3D")
{
Factory::alias("offset3D", "add3D");
Ioss::TransformFactory::alias("offset3D", "add3D");
}

Ioss::Transform *Offset3D_Factory::make(const std::string & /*unused*/) const
Expand Down
6 changes: 3 additions & 3 deletions packages/seacas/libraries/ioss/src/transform/Iotr_Offset3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#pragma once

#include "Ioss_Transform.h" // for Transform, Factory
#include "Ioss_Transform.h" // for Transform, Factory
#include "Ioss_TransformFactory.h"
#include "Ioss_VariableType.h" // for VariableType
#include "transform/Iotr_Factory.h"
#include <stddef.h>
#include <string> // for string
#include <vector> // for vector
Expand All @@ -21,7 +21,7 @@ namespace Ioss {

namespace Iotr {

class IOTR_EXPORT Offset3D_Factory : public Factory
class IOTR_EXPORT Offset3D_Factory : public Ioss::TransformFactory
{
public:
static const Offset3D_Factory *factory();
Expand Down
9 changes: 6 additions & 3 deletions packages/seacas/libraries/ioss/src/transform/Iotr_Scale.C
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright(C) 1999-2021, 2023 National Technology & Engineering Solutions
// Copyright(C) 1999-2021, 2023, 2024 National Technology & Engineering Solutions
// of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
// NTESS, the U.S. Government retains certain rights in this software.
//
Expand All @@ -11,7 +11,7 @@
#include <stdint.h>

#include "Ioss_Transform.h"
#include "Iotr_Factory.h"
#include "Ioss_TransformFactory.h"

namespace Iotr {

Expand All @@ -21,7 +21,10 @@ namespace Iotr {
return &registerThis;
}

Scale_Factory::Scale_Factory() : Factory("scale") { Factory::alias("scale", "multiply"); }
Scale_Factory::Scale_Factory() : Ioss::TransformFactory("scale")
{
Ioss::TransformFactory::alias("scale", "multiply");
}

Ioss::Transform *Scale_Factory::make(const std::string & /*unused*/) const { return new Scale(); }

Expand Down
Loading
Loading