preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
23BOOST_AUTO_TEST_CASE(PerformActionWithGlobalIterationsCounter)
24{
26 mesh::PtrMesh mesh(new mesh::Mesh("Mesh", 3, testing::nextMeshID()));
27 mesh->createVertex(Eigen::Vector3d::Constant(1.0));
28 mesh->createVertex(Eigen::Vector3d::Constant(2.0));
29 mesh->createVertex(Eigen::Vector3d::Constant(3.0));
30 int targetID = mesh->createData("TargetData", 1, 0_dataID)->getID();
31 int sourceID = mesh->createData("SourceData", 1, 1_dataID)->getID();
32 mesh->allocateDataValues();
33 std::string path = testing::getPathToSources() + "/action/tests/";
34 PythonAction action(PythonAction::WRITE_MAPPING_POST, path, "TestAction", mesh, targetID, sourceID);
35
36 mesh->data(sourceID)->emplaceSampleAtTime(1, {0.1, 0.2, 0.3});
37 mesh->data(targetID)->emplaceSampleAtTime(1, {0.0, 0.0, 0.0});
38
39 action.performAction();
40
41 Eigen::VectorXd result(3);
42 result << 1.1, 1.2, 1.3;
43 BOOST_TEST(testing::equals(mesh->data(targetID)->stamples().back().sample.values, result));
44 mesh->data(sourceID)->emplaceSampleAtTime(1, {0.0, 0.0, 0.0});
45
46 action.performAction();
47
48 result << 2.0, 2.0, 2.0;
49 BOOST_TEST(testing::equals(mesh->data(targetID)->stamples().back().sample.values, result));
50}
51
53BOOST_AUTO_TEST_SUITE_END() // ActionTest
54
55#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:39
#define PRECICE_TEST_SETUP(...)
Creates and attaches a TestSetup to a Boost test case.
Definition Testing.hpp:29
Container and creator for meshes.
Definition Mesh.hpp:38
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:93
std::string getPathToSources()
Returns the base path to the sources.
Definition Testing.cpp:33
Main namespace of the precice library.