preCICE
Loading...
Searching...
No Matches
TimeGridsTest.cpp
Go to the documentation of this file.
1#ifndef PRECICE_NO_MPI
2
3#include <Eigen/Core>
4#include <Eigen/Dense>
5
10#include "mesh/Mesh.hpp"
11
13#include "testing/Testing.hpp"
14#include "time/TimeGrids.hpp"
15
16BOOST_AUTO_TEST_SUITE(TimeTests)
17
18using namespace precice;
19using namespace precice::time;
20
22
24 using DataMap = std::map<int, cplscheme::PtrCouplingData>;
25};
26
27BOOST_FIXTURE_TEST_SUITE(TimeGridsTest, TimeGridsTestsFixture)
28
30BOOST_AUTO_TEST_CASE(TestMoveAndScaleTimeGrids)
31{
33 std::vector<int> dataIDs;
34 dataIDs.push_back(0);
35 mesh::PtrMesh dummyMesh(new mesh::Mesh("DummyMesh", 3, testing::nextMeshID()));
36
37 mesh::PtrData displacements(new mesh::Data("dvalues", -1, 1));
38
39 // init displacements and waveform
40
41 double timeWindowStart = 0.0;
42 double dt = 1.0;
43 double timeWindowEnd = timeWindowStart + dt;
44
45 displacements->values().resize(4);
46 displacements->values() << 1.0, 1.0, 1.0, 1.0;
47 displacements->setSampleAtTime(timeWindowStart, displacements->sample());
48 displacements->setSampleAtTime(timeWindowStart + 0.5 * dt, displacements->sample());
49 displacements->setSampleAtTime(timeWindowEnd, displacements->sample());
50
51 cplscheme::PtrCouplingData dpcd = makeCouplingData(displacements, dummyMesh, true);
52
53 DataMap data;
54 data.insert(std::pair<int, cplscheme::PtrCouplingData>(0, dpcd));
55
56 time::TimeGrids fullTimeGrid(data, dataIDs, false);
57 time::TimeGrids reducedTimeGrid(data, dataIDs, true);
58
59 Eigen::VectorXd storedFullTimeGrid = fullTimeGrid.getTimeGridAfter(dataIDs[0], timeWindowStart);
60 Eigen::VectorXd storedReducedTimeGrid = reducedTimeGrid.getTimeGridAfter(dataIDs[0], timeWindowStart);
61
63 BOOST_TEST(storedFullTimeGrid.size() == 2);
64 BOOST_TEST(testing::equals(storedFullTimeGrid(0), 0.5));
65 BOOST_TEST(testing::equals(storedFullTimeGrid(1), 1.0));
66
67 BOOST_TEST(storedReducedTimeGrid.size() == 1);
68 BOOST_TEST(testing::equals(storedReducedTimeGrid(0), 1.0));
69
70 // Create a second data pointer with the contentes of the second time window
71 mesh::PtrData newdisplacements(new mesh::Data("dvalues", -1, 1));
72
73 // move to next window
74 timeWindowStart = timeWindowEnd;
75 dt = 2 * dt;
76 timeWindowEnd = timeWindowStart + dt;
77
78 // init newdisplacements
79 newdisplacements->values().resize(4);
80 newdisplacements->values() << 1.0, 1.0, 1.0, 1.0;
81 newdisplacements->setSampleAtTime(timeWindowStart, newdisplacements->sample());
82 newdisplacements->setSampleAtTime(timeWindowEnd, newdisplacements->sample());
83
84 cplscheme::PtrCouplingData newdpcd = makeCouplingData(newdisplacements, dummyMesh, true);
85
86 DataMap newdata;
87 newdata.insert(std::pair<int, cplscheme::PtrCouplingData>(0, newdpcd));
88
89 // move the time grid to the new time window
90 fullTimeGrid.moveTimeGridToNewWindow(newdata);
91 reducedTimeGrid.moveTimeGridToNewWindow(newdata);
92
93 storedFullTimeGrid = fullTimeGrid.getTimeGridAfter(dataIDs[0], timeWindowStart);
94 storedReducedTimeGrid = reducedTimeGrid.getTimeGridAfter(dataIDs[0], timeWindowStart);
95
97 BOOST_TEST(storedFullTimeGrid.size() == 2);
98 BOOST_TEST(testing::equals(storedFullTimeGrid(0), 2.0));
99 BOOST_TEST(testing::equals(storedFullTimeGrid(1), 3.0));
100
101 BOOST_TEST(storedReducedTimeGrid.size() == 1);
102 BOOST_TEST(testing::equals(storedReducedTimeGrid(0), 3.0));
103}
104
107#endif
std::map< int, PtrCouplingData > DataMap
BOOST_AUTO_TEST_CASE(testIQNIMVJPPWithSubsteps)
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
cplscheme::PtrCouplingData makeCouplingData(mesh::PtrData data, mesh::PtrMesh mesh, bool exchangeSubsteps)
Definition helper.hpp:10
Describes a set of data values belonging to the vertices of a mesh.
Definition Data.hpp:26
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
std::shared_ptr< CouplingData > PtrCouplingData
std::shared_ptr< Data > PtrData
std::shared_ptr< Mesh > PtrMesh
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.
std::map< int, cplscheme::PtrCouplingData > DataMap