preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TimeGridsTest.cpp
Go to the documentation of this file.
1#ifndef PRECICE_NO_MPI
2
3#include <Eigen/Core>
4#include <Eigen/Dense>
5#include <Eigen/src/Core/Matrix.h>
6
11#include "mesh/Mesh.hpp"
12
14#include "testing/Testing.hpp"
15#include "time/TimeGrids.hpp"
16
17BOOST_AUTO_TEST_SUITE(TimeTests)
18
19using namespace precice;
20using namespace precice::time;
21
23
27
28BOOST_FIXTURE_TEST_SUITE(TimeGridsTest, TimeGridsTestsFixture)
29
31BOOST_AUTO_TEST_CASE(TestMoveAndScaleTimeGrids)
32{
34 std::vector<int> dataIDs;
35 dataIDs.push_back(0);
36 mesh::PtrMesh dummyMesh(new mesh::Mesh("DummyMesh", 3, testing::nextMeshID()));
37
38 mesh::PtrData displacements(new mesh::Data("dvalues", -1, 1));
39
40 // init displacements and waveform
41
42 double timeWindowStart = 0.0;
43 double dt = 1.0;
44 double timeWindowEnd = timeWindowStart + dt;
45
46 displacements->values().resize(4);
47 displacements->values() << 1.0, 1.0, 1.0, 1.0;
48 displacements->setSampleAtTime(timeWindowStart, displacements->sample());
49 displacements->setSampleAtTime(timeWindowStart + 0.5 * dt, displacements->sample());
50 displacements->setSampleAtTime(timeWindowEnd, displacements->sample());
51
52 cplscheme::PtrCouplingData dpcd = makeCouplingData(displacements, dummyMesh, true);
53
54 DataMap data;
56
57 time::TimeGrids fullTimeGrid(data, dataIDs, false);
58 time::TimeGrids reducedTimeGrid(data, dataIDs, true);
59
60 Eigen::VectorXd storedFullTimeGrid = fullTimeGrid.getTimeGridAfter(dataIDs[0], timeWindowStart);
61 Eigen::VectorXd storedReducedTimeGrid = reducedTimeGrid.getTimeGridAfter(dataIDs[0], timeWindowStart);
62
64 BOOST_TEST(storedFullTimeGrid.size() == 2);
65 BOOST_TEST(testing::equals(storedFullTimeGrid(0), 0.5));
66 BOOST_TEST(testing::equals(storedFullTimeGrid(1), 1.0));
67
68 BOOST_TEST(storedReducedTimeGrid.size() == 1);
69 BOOST_TEST(testing::equals(storedReducedTimeGrid(0), 1.0));
70
71 // Create a second data pointer with the contentes of the second time window
72 mesh::PtrData newdisplacements(new mesh::Data("dvalues", -1, 1));
73
74 // move to next window
75 timeWindowStart = timeWindowEnd;
76 dt = 2 * dt;
77 timeWindowEnd = timeWindowStart + dt;
78
79 // init newdisplacements
80 newdisplacements->values().resize(4);
81 newdisplacements->values() << 1.0, 1.0, 1.0, 1.0;
82 newdisplacements->setSampleAtTime(timeWindowStart, newdisplacements->sample());
83 newdisplacements->setSampleAtTime(timeWindowEnd, newdisplacements->sample());
84
85 cplscheme::PtrCouplingData newdpcd = makeCouplingData(newdisplacements, dummyMesh, true);
86
87 DataMap newdata;
89
90 // move the time grid to the new time window
91 fullTimeGrid.moveTimeGridToNewWindow(newdata);
92 reducedTimeGrid.moveTimeGridToNewWindow(newdata);
93
94 storedFullTimeGrid = fullTimeGrid.getTimeGridAfter(dataIDs[0], timeWindowStart);
95 storedReducedTimeGrid = reducedTimeGrid.getTimeGridAfter(dataIDs[0], timeWindowStart);
96
98 BOOST_TEST(storedFullTimeGrid.size() == 2);
99 BOOST_TEST(testing::equals(storedFullTimeGrid(0), 2.0));
100 BOOST_TEST(testing::equals(storedFullTimeGrid(1), 3.0));
101
102 BOOST_TEST(storedReducedTimeGrid.size() == 1);
103 BOOST_TEST(testing::equals(storedReducedTimeGrid(0), 3.0));
104}
105
108#endif
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#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
BOOST_AUTO_TEST_CASE(TestMoveAndScaleTimeGrids)
Describes a set of data values belonging to the vertices of a mesh.
Definition Data.hpp:27
Container and creator for meshes.
Definition Mesh.hpp:38
Interface for storing the time grids in the Quasi-Newton and Aitken methods. A time grid is a ordered...
Definition TimeGrids.hpp:21
Eigen::VectorXd getTimeGridAfter(int dataID, double time) const
Definition TimeGrids.cpp:23
void moveTimeGridToNewWindow(const DataMap &cplData)
Definition TimeGrids.cpp:37
T insert(T... args)
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
cplscheme::PtrCouplingData makeCouplingData(mesh::PtrData data, mesh::PtrMesh mesh, bool exchangeSubsteps)
Definition helper.hpp:10
contains the time interpolation logic.
Definition Sample.hpp:8
Main namespace of the precice library.
T push_back(T... args)