Debian Codegraph @

src/atlas/mesh/actions/Reorder.h

raw
1 /*
2 * (C) Copyright 2013 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include <string>
14 #include <vector>
15
16 #include "atlas/library/config.h"
17 #include "atlas/util/Config.h"
18 #include "atlas/util/Factory.h"
19 #include "atlas/util/Object.h"
20 #include "atlas/util/ObjectHandle.h"
21
22 namespace atlas {
23 class Mesh;
24
25 namespace mesh {
26 namespace actions {
27
28 // ------------------------------------------------------------------
29
30 /// Base class for reordering the mesh nodes and elements
31 class ReorderImpl : public util::Object {
32 public:
33 ReorderImpl() = default;
34
35 public: // -- static functions --
36 /// Reorder the nodes in the given mesh using a given order
37 /// - All fields in mesh.nodes() are reordered.
38 /// - mesh.cells().node_connectivity() gets updated
39 /// - mesh.edges().node_connectivity() gets updated
40 static void reorderNodes(Mesh& mesh, const std::vector<idx_t>& order);
41
42 /// Reorder the cells by lowest node local index within each cell
43 static void reorderCellsUsingNodes(Mesh& mesh);
44
45 /// Reorder the edges by lowest node local index within each edge
46 static void reorderEdgesUsingNodes(Mesh& mesh);
47
48 public: // -- member functions --
49 /// Reorder the nodes in the given mesh using the order computed with the computeNodesOrder function
50 /// Then apply reorderCellsUsingNodes and reorderEdgesUsingNodes
51 virtual void operator()(Mesh&);
52
53 virtual std::vector<idx_t> computeNodesOrder(Mesh&) = 0;
54 };
55
56 //----------------------------------------------------------------------------------------------------------------------
57
58 class ReorderFactory : public util::Factory<ReorderFactory> {
59 public:
60 static std::string className() { return "ReorderFactory"; }
61 static const ReorderImpl* build(const eckit::Parametrisation&);
62 using Factory::Factory;
63
64 private:
65 virtual const ReorderImpl* make(const eckit::Parametrisation&) = 0;
66 };
67
68 //----------------------------------------------------------------------------------------------------------------------
69
70 template <class T>
71 class ReorderBuilder : public ReorderFactory {
72 private:
73 virtual const ReorderImpl* make(const eckit::Parametrisation& param) { return new T(param); }
74
75 public:
76 using ReorderFactory::ReorderFactory;
77 };
78
79 //----------------------------------------------------------------------------------------------------------------------
80
81 class Reorder : DOXYGEN_HIDE(public util::ObjectHandle<ReorderImpl>) {
82 public:
83 using Parameters = atlas::util::Config;
84
85 public:
86 using Handle::Handle;
87 Reorder(const eckit::Parametrisation& config): Handle(ReorderFactory::build(config)) {}
88
89 /// Reorder the nodes in the given mesh using the order computed with the ReorderImpl::computeNodesOrder function
90 /// Then apply ReorderImpl::reorderCellsUsingNodes and ReorderImpl::reorderEdgesUsingNodes
91 void operator()(Mesh& mesh) { get()->operator()(mesh); }
92 };
93
94 //----------------------------------------------------------------------------------------------------------------------
95
96 /// Dummy implemenation of ReorderImpl which does nothing
97 class NoReorder : public ReorderImpl {
98 public:
99 NoReorder(const eckit::Parametrisation&) {}
100 void operator()(Mesh&) override {}
101 std::vector<idx_t> computeNodesOrder(Mesh&) override { return {}; }
102 };
103
104 //----------------------------------------------------------------------------------------------------------------------
105
106 } // namespace actions
107 } // namespace mesh
108 } // namespace atlas