preCICE v3.1.1
Loading...
Searching...
No Matches
PythonActionTest.cpp
Go to the documentation of this file.
1#ifndef PRECICE_NO_PYTHON
2
3#include <Eigen/Core>
4#include <algorithm>
5#include <memory>
6#include <string>
7#include "action/Action.hpp"
9#include "logging/Logger.hpp"
10#include "mesh/Data.hpp"
11#include "mesh/Mesh.hpp"
14#include "testing/Testing.hpp"
15
16using namespace precice;
17using namespace precice::action;
18
19BOOST_AUTO_TEST_SUITE(ActionTests)
21
22BOOST_AUTO_TEST_CASE(PerformActionWithGlobalIterationsCounter)
23{
24 PRECICE_TEST(1_rank);
25 mesh::PtrMesh mesh(new mesh::Mesh("Mesh", 3, testing::nextMeshID()));
26 mesh->createVertex(Eigen::Vector3d::Constant(1.0));
27 mesh->createVertex(Eigen::Vector3d::Constant(2.0));
28 mesh->createVertex(Eigen::Vector3d::Constant(3.0));
29 int targetID = mesh->createData("TargetData", 1, 0_dataID)->getID();
30 int sourceID = mesh->createData("SourceData", 1, 1_dataID)->getID();
31 mesh->allocateDataValues();
32 std::string path = testing::getPathToSources() + "/action/tests/";
33 PythonAction action(PythonAction::WRITE_MAPPING_POST, path, "TestAction", mesh, targetID, sourceID);
34
35 Eigen::VectorXd v(3);
36 v << 0.1, 0.2, 0.3;
37 mesh->data(sourceID)->setSampleAtTime(1, time::Sample{1, v});
38 mesh->data(targetID)->setSampleAtTime(1, time::Sample{1, Eigen::VectorXd::Zero(mesh->nVertices())});
39
40 action.performAction();
41
42 Eigen::VectorXd result(3);
43 result << 1.1, 1.2, 1.3;
44 BOOST_TEST(testing::equals(mesh->data(targetID)->values(), result));
45 mesh->data(sourceID)->setSampleAtTime(1, time::Sample{1, Eigen::VectorXd::Zero(mesh->nVertices())});
46
47 action.performAction();
48
49 result << 2.0, 2.0, 2.0;
50 BOOST_TEST(testing::equals(mesh->data(targetID)->values(), result));
51}
52
54BOOST_AUTO_TEST_SUITE_END() // ActionTest
55
56#endif // not PRECICE_NO_PYTHON
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(PerformActionWithGlobalIterationsCounter)
#define PRECICE_TEST(...)
Definition Testing.hpp:27
Container and creator for meshes.
Definition Mesh.hpp:39
contains actions to modify exchanged data.
Definition Action.hpp:6
boost::test_tools::predicate_result equals(const std::vector< float > &VectorA, const std::vector< float > &VectorB, float tolerance)
equals to be used in tests. Compares two std::vectors using a given tolerance. Prints both operands o...
Definition Testing.cpp:65
std::string getPathToSources()
Returns the base path to the sources.
Definition Testing.cpp:31
Main namespace of the precice library.