preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
30BOOST_AUTO_TEST_CASE(DivideByArea2D)
31{
33 using namespace mesh;
34 PtrMesh mesh(new Mesh("Mesh", 2, testing::nextMeshID()));
35 PtrData data = mesh->createData("test-data", 1, 0_dataID);
36 int dataID = data->getID();
37 Vertex &v0 = mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
38 Vertex &v1 = mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
39 Vertex &v2 = mesh->createVertex(Eigen::Vector2d(1.0, 1.0));
40 mesh->createEdge(v0, v1);
41 mesh->createEdge(v1, v2);
42 mesh->allocateDataValues();
43 Eigen::VectorXd v(3);
44 v << 2.0, 3.0, 4.0;
45 data->setSampleAtTime(1, time::Sample{1, v});
46
47 const auto &values = data->values();
48 BOOST_TEST(values(0) == 2.0);
49 BOOST_TEST(values(1) == 3.0);
50 BOOST_TEST(values(2) == 4.0);
51
52 // Scale properties
54 action::ScaleByAreaAction::WRITE_MAPPING_POST, dataID, mesh,
56
57 scale.performAction();
58
59 BOOST_TEST(values(0) == 4.0);
60 BOOST_TEST(values(1) == 3.0);
61 BOOST_TEST(values(2) == 8.0);
62}
63
65BOOST_AUTO_TEST_CASE(DivideByArea3D)
66{
68 using namespace mesh;
69 PtrMesh mesh(new Mesh("Mesh", 3, testing::nextMeshID()));
70 PtrData data = mesh->createData("test-data", 1, 0_dataID);
71 int dataID = data->getID();
72 Vertex &v0 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
73 Vertex &v1 = mesh->createVertex(Eigen::Vector3d(6.0, 2.0, 0.0));
74 Vertex &v2 = mesh->createVertex(Eigen::Vector3d(0.0, 2.0, 0.0));
75 Vertex &v3 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 3.0));
76 Vertex &v4 = mesh->createVertex(Eigen::Vector3d(2.0, 0.0, 3.0));
77 Edge &e0 = mesh->createEdge(v0, v1);
78 Edge &e1 = mesh->createEdge(v1, v2);
79 Edge &e2 = mesh->createEdge(v0, v2);
80 Edge &e3 = mesh->createEdge(v2, v3);
81 Edge &e4 = mesh->createEdge(v0, v3);
82 Edge &e5 = mesh->createEdge(v0, v4);
83 Edge &e6 = mesh->createEdge(v3, v4);
84 mesh->createTriangle(e0, e1, e2);
85 mesh->createTriangle(e2, e3, e4);
86 mesh->createTriangle(e4, e5, e6);
87 mesh->allocateDataValues();
88 Eigen::VectorXd v(5);
89 v << 2.0, 3.0, 6.0, 5.0, 6.0;
90 data->setSampleAtTime(1, time::Sample{1, v});
91
92 const auto &values = data->values();
93 BOOST_TEST(values(0) == 2.0);
94 BOOST_TEST(values(1) == 3.0);
95 BOOST_TEST(values(2) == 6.0);
96 BOOST_TEST(values(3) == 5.0);
97 BOOST_TEST(values(4) == 6.0);
98
99 // Scale properties
101 action::ScaleByAreaAction::WRITE_MAPPING_POST, dataID, mesh,
103
104 scale.performAction();
105
106 BOOST_TEST(values(0) == 0.5);
107 BOOST_TEST(values(1) == 1.5);
108 BOOST_TEST(values(2) == 2.0);
109 BOOST_TEST(values(3) == 2.5);
110 BOOST_TEST(values(4) == 6.0);
111}
112
113PRECICE_TEST_SETUP(1_rank)
115{
116 PRECICE_TEST();
117 {
118 std::string filename = testing::getPathToSources() + "/action/tests/ScaleActionTest-testConfiguration-1.xml";
121 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
122 action::ActionConfiguration config(tag, meshConfig);
124 BOOST_TEST(config.actions().size() == 1);
125 auto &action = config.actions().front();
126 BOOST_TEST(static_cast<bool>(action));
127 }
128 {
129 std::string filename = testing::getPathToSources() + "/action/tests/ScaleActionTest-testConfiguration-2.xml";
132 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
133 action::ActionConfiguration config(tag, meshConfig);
135 BOOST_TEST(config.actions().size() == 1);
136 auto &action = config.actions().front();
137 BOOST_TEST(static_cast<bool>(action));
138 }
139}
140
142BOOST_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:39
#define PRECICE_TEST_SETUP(...)
Creates and attaches a TestSetup to a Boost test case.
Definition Testing.hpp:29
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:28
provides Mesh, Data and primitives.
std::string getPathToSources()
Returns the base path to the sources.
Definition Testing.cpp:33
XMLTag getRootTag()
Returns an empty root tag with name "configuration".
Definition XMLTag.cpp:278
std::string configure(XMLTag &tag, const precice::xml::ConfigurationContext &context, std::string_view configurationFilename)
Configures the given configuration from file configurationFilename.
Definition XMLTag.cpp:284
Main namespace of the precice library.
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:21