preCICE v3.1.2
Loading...
Searching...
No Matches
ScaleActionTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <algorithm>
3#include <list>
4#include <memory>
5#include <string>
6#include "action/Action.hpp"
10#include "logging/Logger.hpp"
11#include "mesh/Data.hpp"
12#include "mesh/Mesh.hpp"
17#include "testing/Testing.hpp"
18#include "xml/XMLTag.hpp"
19
20namespace precice::mesh {
21class Vertex;
22} // namespace precice::mesh
23
24using namespace precice;
25
26BOOST_AUTO_TEST_SUITE(ActionTests)
28
29BOOST_AUTO_TEST_CASE(DivideByArea2D)
30{
31 PRECICE_TEST(1_rank);
32 using namespace mesh;
33 PtrMesh mesh(new Mesh("Mesh", 2, testing::nextMeshID()));
34 PtrData data = mesh->createData("test-data", 1, 0_dataID);
35 int dataID = data->getID();
36 Vertex &v0 = mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
37 Vertex &v1 = mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
38 Vertex &v2 = mesh->createVertex(Eigen::Vector2d(1.0, 1.0));
39 mesh->createEdge(v0, v1);
40 mesh->createEdge(v1, v2);
41 mesh->allocateDataValues();
42 Eigen::VectorXd v(3);
43 v << 2.0, 3.0, 4.0;
44 data->setSampleAtTime(1, time::Sample{1, v});
45
46 const auto &values = data->values();
47 BOOST_TEST(values(0) == 2.0);
48 BOOST_TEST(values(1) == 3.0);
49 BOOST_TEST(values(2) == 4.0);
50
51 // Scale properties
53 action::ScaleByAreaAction::WRITE_MAPPING_POST, dataID, mesh,
55
56 scale.performAction();
57
58 BOOST_TEST(values(0) == 4.0);
59 BOOST_TEST(values(1) == 3.0);
60 BOOST_TEST(values(2) == 8.0);
61}
62
63BOOST_AUTO_TEST_CASE(DivideByArea3D)
64{
65 PRECICE_TEST(1_rank);
66 using namespace mesh;
67 PtrMesh mesh(new Mesh("Mesh", 3, testing::nextMeshID()));
68 PtrData data = mesh->createData("test-data", 1, 0_dataID);
69 int dataID = data->getID();
70 Vertex &v0 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
71 Vertex &v1 = mesh->createVertex(Eigen::Vector3d(6.0, 2.0, 0.0));
72 Vertex &v2 = mesh->createVertex(Eigen::Vector3d(0.0, 2.0, 0.0));
73 Vertex &v3 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 3.0));
74 Vertex &v4 = mesh->createVertex(Eigen::Vector3d(2.0, 0.0, 3.0));
75 Edge & e0 = mesh->createEdge(v0, v1);
76 Edge & e1 = mesh->createEdge(v1, v2);
77 Edge & e2 = mesh->createEdge(v0, v2);
78 Edge & e3 = mesh->createEdge(v2, v3);
79 Edge & e4 = mesh->createEdge(v0, v3);
80 Edge & e5 = mesh->createEdge(v0, v4);
81 Edge & e6 = mesh->createEdge(v3, v4);
82 mesh->createTriangle(e0, e1, e2);
83 mesh->createTriangle(e2, e3, e4);
84 mesh->createTriangle(e4, e5, e6);
85 mesh->allocateDataValues();
86 Eigen::VectorXd v(5);
87 v << 2.0, 3.0, 6.0, 5.0, 6.0;
88 data->setSampleAtTime(1, time::Sample{1, v});
89
90 const auto &values = data->values();
91 BOOST_TEST(values(0) == 2.0);
92 BOOST_TEST(values(1) == 3.0);
93 BOOST_TEST(values(2) == 6.0);
94 BOOST_TEST(values(3) == 5.0);
95 BOOST_TEST(values(4) == 6.0);
96
97 // Scale properties
99 action::ScaleByAreaAction::WRITE_MAPPING_POST, dataID, mesh,
101
102 scale.performAction();
103
104 BOOST_TEST(values(0) == 0.5);
105 BOOST_TEST(values(1) == 1.5);
106 BOOST_TEST(values(2) == 2.0);
107 BOOST_TEST(values(3) == 2.5);
108 BOOST_TEST(values(4) == 6.0);
109}
110
112{
113 PRECICE_TEST(1_rank);
114 {
115 std::string filename = testing::getPathToSources() + "/action/tests/ScaleActionTest-testConfiguration-1.xml";
118 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
119 action::ActionConfiguration config(tag, meshConfig);
121 BOOST_TEST(config.actions().size() == 1);
122 auto &action = config.actions().front();
123 BOOST_TEST(static_cast<bool>(action));
124 }
125 {
126 std::string filename = testing::getPathToSources() + "/action/tests/ScaleActionTest-testConfiguration-2.xml";
129 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
130 action::ActionConfiguration config(tag, meshConfig);
132 BOOST_TEST(config.actions().size() == 1);
133 auto &action = config.actions().front();
134 BOOST_TEST(static_cast<bool>(action));
135 }
136}
137
139BOOST_AUTO_TEST_SUITE_END() // ActionTest
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(DivideByArea2D)
#define PRECICE_TEST(...)
Definition Testing.hpp:27
Configures an Action subclass object.
const std::list< PtrAction > & actions() const
Returns the configured action.
@ SCALING_DIVIDE_BY_AREA
Divides the data by the area of neighboring edges/triangles.
void performAction() final override
Scales data on mesh nodes according to selected scaling type.
Performs and provides configuration for Data objects from XML files.
Vertex of a mesh.
Definition Vertex.hpp:16
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:31
provides Mesh, Data and primitives.
std::string getPathToSources()
Returns the base path to the sources.
Definition Testing.cpp:31
XMLTag getRootTag()
Returns an XMLTag::Listener that does nothing on callbacks.
Definition XMLTag.cpp:389
void configure(XMLTag &tag, const precice::xml::ConfigurationContext &context, std::string_view configurationFilename)
Configures the given configuration from file configurationFilename.
Definition XMLTag.cpp:395
Main namespace of the precice library.
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:24