Nektar++
TestMovement.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestMovement.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
40#include <boost/test/tools/floating_point_comparison.hpp>
41#include <boost/test/unit_test.hpp>
42
44{
45
47{
48 char arg = ' ';
49 char *args[] = {&arg};
51}
52
53const std::string angVelStr = "0.1*t", xEqnStr = "0.1*x - 0.1*t",
54 yEqnStr = "0.1*y^2 - x", zEqnStr = "sqrt(t)";
55std::vector<std::string> velocityStr = {"1.0", "2.0", "3.0"};
56std::vector<std::string> displacementStr = {"1.0", "2.0", "3.0"};
57const NekPoint<NekDouble> origin = {1., 2., 3.};
58const DNekVec axis = {1., 2., 3.};
59
60/// Produce dummy Zone objects, containing empty domain pointers
62 SpatialDomains::MovementType type, int zoneID, int domainID,
64{
66 switch (type)
67 {
69 {
72 zoneID, domainID, domain, 3));
73 }
74 break;
76 {
78 std::make_shared<LibUtilities::Equation>(interpreter,
79 angVelStr);
82 zoneID, domainID, domain, 3, origin, axis, angularVelEqn));
83 }
84 break;
86 {
89 for (int i = 0; i < 3; ++i)
90 {
91 velocityEqns[i] = std::make_shared<LibUtilities::Equation>(
92 interpreter, velocityStr[i]);
93 displacementEqns[i] = std::make_shared<LibUtilities::Equation>(
94 interpreter, displacementStr[i]);
95 }
96
99 zoneID, domainID, domain, 3, velocityEqns,
100 displacementEqns));
101 }
102 break;
103 default:
104 {
105 }
106 break;
107 }
108 return nullptr;
109}
110
111/// Produce dummy Interface objects, containing empty domain pointers
113 std::vector<int> compositeIDs)
114{
116 for (auto &id : compositeIDs)
117 {
118 edge[id] =
120 }
123 interfaceID, edge, false));
124}
125
126BOOST_AUTO_TEST_CASE(TestAddGetZones)
127{
133 0, interpreter),
134 zone2 = CreateZone(
136 2, interpreter);
137 m.AddZone(zone1);
138 m.AddZone(zone2);
139 std::map<int, SpatialDomains::ZoneBaseShPtr> zones = m.GetZones();
140 BOOST_TEST(zones.size() == 2);
141 BOOST_TEST(zones.at(0).get() == zone1.get());
142 BOOST_TEST(zones.at(2).get() == zone2.get());
143 BOOST_TEST(zones.at(0) == zone1);
144 BOOST_TEST(zones.at(2) == zone2);
145}
146
147BOOST_AUTO_TEST_CASE(TestAddGetInterfaces)
148{
151 interface2 = CreateInterface(1, {1, 2, 3}),
152 interface3 = CreateInterface(3, {4});
153 m.AddInterface("north", interface1, interface2);
154 m.AddInterface("east", interface2, interface3);
155 m.AddInterface("south", interface3, interface1);
157 BOOST_TEST(interfaces.size() == 3);
158 SpatialDomains::InterfacePairShPtr north = interfaces.at(
159 std::make_pair(0, "north")),
160 east = interfaces.at(
161 std::make_pair(1, "east")),
162 south = interfaces.at(
163 std::make_pair(2, "south"));
164 BOOST_TEST(north->m_leftInterface == interface1);
165 BOOST_TEST(north->m_rightInterface == interface2);
166 BOOST_TEST(east->m_leftInterface == interface2);
167 BOOST_TEST(east->m_rightInterface == interface3);
168 BOOST_TEST(south->m_leftInterface == interface3);
169 BOOST_TEST(south->m_rightInterface == interface1);
170}
171
172BOOST_AUTO_TEST_CASE(TestWriteMovement)
173{
177 m.AddZone(
180 interpreter));
181 m.AddZone(
183 m.AddInterface("north", CreateInterface(0, {0}),
184 CreateInterface(1, {1, 2, 3, 4}));
185 m.AddInterface("south", CreateInterface(2, {5, 6, 7, 8, 9, 11}),
186 CreateInterface(3, {12}));
187
189 std::map<int, SpatialDomains::ZoneBaseShPtr> zones = m.GetZones();
190 TiXmlElement *nektar = new TiXmlElement("NEKTAR");
191 m.WriteMovement(nektar);
192 TiXmlElement *movement = nektar->FirstChildElement("MOVEMENT");
193 BOOST_TEST(movement);
194 TiXmlElement *xmlZones = movement->FirstChildElement("ZONES"),
195 *xmlInterfaces = movement->FirstChildElement("INTERFACES");
196 BOOST_TEST(xmlZones);
197 BOOST_TEST(xmlInterfaces);
198
199 int id, err;
200 std::string attr;
201 std::vector<NekDouble> vec;
202
203 // Check the fixed zone
204 TiXmlElement *zone = xmlZones->FirstChildElement();
205 BOOST_TEST(zone->Value() == "F");
206 err = zone->QueryIntAttribute("ID", &id);
207 BOOST_TEST(err == TIXML_SUCCESS);
208 BOOST_TEST(id == 0);
209 err = zone->QueryStringAttribute("DOMAIN", &attr);
210 BOOST_TEST(err == TIXML_SUCCESS);
211 BOOST_TEST(attr == "D[10]");
212
213 // Check the rotating zone
214 zone = xmlZones->IterateChildren(zone)->ToElement();
215 BOOST_TEST(zone->Value() == "R");
216 err = zone->QueryIntAttribute("ID", &id);
217 BOOST_TEST(err == TIXML_SUCCESS);
218 BOOST_TEST(id == 1);
219 err = zone->QueryStringAttribute("DOMAIN", &attr);
220 BOOST_TEST(err == TIXML_SUCCESS);
221 BOOST_TEST(attr == "D[11]");
222 err = zone->QueryStringAttribute("ORIGIN", &attr);
223 BOOST_TEST(err == TIXML_SUCCESS);
225 BOOST_TEST(NekPoint<NekDouble>(vec.at(0), vec.at(1), vec.at(2)) == origin);
226 err = zone->QueryStringAttribute("AXIS", &attr);
227 BOOST_TEST(err == TIXML_SUCCESS);
228 DNekVec xmlAxis(attr);
229 BOOST_TEST(xmlAxis.GetDimension() == 3);
230 for (int i = 0; i < 3; i++)
231 {
232 BOOST_TEST(xmlAxis[i] == axis[i]);
233 }
234 err = zone->QueryStringAttribute("ANGVEL", &attr);
235 BOOST_TEST(err == TIXML_SUCCESS);
236 BOOST_TEST(attr == angVelStr);
237
238 // Check the translating zone
239 zone = xmlZones->IterateChildren(zone)->ToElement();
240 BOOST_TEST(zone->Value() == "T");
241 err = zone->QueryIntAttribute("ID", &id);
242 BOOST_TEST(err == TIXML_SUCCESS);
243 BOOST_TEST(id == 3);
244 err = zone->QueryStringAttribute("DOMAIN", &attr);
245 BOOST_TEST(err == TIXML_SUCCESS);
246 BOOST_TEST(attr == "D[13]");
247 err = zone->QueryStringAttribute("XVELOCITY", &attr);
248 BOOST_TEST(err == TIXML_SUCCESS);
249 BOOST_TEST(attr == velocityStr[0]);
250 err = zone->QueryStringAttribute("YVELOCITY", &attr);
251 BOOST_TEST(err == TIXML_SUCCESS);
252 BOOST_TEST(attr == velocityStr[1]);
253 err = zone->QueryStringAttribute("ZVELOCITY", &attr);
254 BOOST_TEST(err == TIXML_SUCCESS);
255 BOOST_TEST(attr == velocityStr[2]);
256 err = zone->QueryStringAttribute("XDISPLACEMENT", &attr);
257 BOOST_TEST(err == TIXML_SUCCESS);
258 BOOST_TEST(attr == displacementStr[0]);
259 err = zone->QueryStringAttribute("YDISPLACEMENT", &attr);
260 BOOST_TEST(err == TIXML_SUCCESS);
261 BOOST_TEST(attr == displacementStr[1]);
262 err = zone->QueryStringAttribute("ZDISPLACEMENT", &attr);
263 BOOST_TEST(err == TIXML_SUCCESS);
264 BOOST_TEST(attr == displacementStr[2]);
265
266 BOOST_TEST(xmlZones->LastChild() == zone);
267
268 TiXmlElement *intr;
269
270 // Check the north interface
271 TiXmlElement *interface = xmlInterfaces->FirstChildElement();
272 BOOST_TEST(interface->Value() == "INTERFACE");
273 err = interface->QueryStringAttribute("NAME", &attr);
274 BOOST_TEST(err == TIXML_SUCCESS);
275 BOOST_TEST(attr == "north");
276 intr = interface->FirstChildElement();
277 BOOST_TEST(intr->Value() == "L");
278 err = intr->QueryIntAttribute("ID", &id);
279 BOOST_TEST(err == TIXML_SUCCESS);
280 BOOST_TEST(id == 0);
281 err = intr->QueryStringAttribute("BOUNDARY", &attr);
282 BOOST_TEST(err == TIXML_SUCCESS);
283 BOOST_TEST(attr == "C[0]");
284 intr = interface->IterateChildren(intr)->ToElement();
285 BOOST_TEST(intr->Value() == "R");
286 err = intr->QueryIntAttribute("ID", &id);
287 BOOST_TEST(err == TIXML_SUCCESS);
288 BOOST_TEST(id == 1);
289 err = intr->QueryStringAttribute("BOUNDARY", &attr);
290 BOOST_TEST(err == TIXML_SUCCESS);
291 BOOST_TEST(attr == "C[1-4]");
292
293 // Check the south interface
294 interface = xmlInterfaces->IterateChildren(interface)->ToElement();
295 BOOST_TEST(interface->Value() == "INTERFACE");
296 err = interface->QueryStringAttribute("NAME", &attr);
297 BOOST_TEST(err == TIXML_SUCCESS);
298 BOOST_TEST(attr == "south");
299 intr = interface->FirstChildElement();
300 BOOST_TEST(intr->Value() == "L");
301 err = intr->QueryIntAttribute("ID", &id);
302 BOOST_TEST(err == TIXML_SUCCESS);
303 BOOST_TEST(id == 2);
304 err = intr->QueryStringAttribute("BOUNDARY", &attr);
305 BOOST_TEST(err == TIXML_SUCCESS);
306 BOOST_TEST(attr == "C[5-9,11]");
307 intr = interface->IterateChildren(intr)->ToElement();
308 BOOST_TEST(intr->Value() == "R");
309 err = intr->QueryIntAttribute("ID", &id);
310 BOOST_TEST(err == TIXML_SUCCESS);
311 BOOST_TEST(id == 3);
312 err = intr->QueryStringAttribute("BOUNDARY", &attr);
313 BOOST_TEST(err == TIXML_SUCCESS);
314 BOOST_TEST(attr == "C[12]");
315
316 BOOST_TEST(xmlInterfaces->LastChild() == interface);
317
318 delete nektar;
319}
320} // namespace Nektar::MovementTests
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
General purpose memory allocation routines with the ability to allocate from thread specific memory p...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
unsigned int GetDimension() const
Returns the number of dimensions for the point.
Definition: NekVector.cpp:201
static bool GenerateVector(const std::string &str, std::vector< T > &out)
Takes a comma-separated string and converts it to entries in a vector.
Definition: ParseUtils.cpp:130
const std::map< int, ZoneBaseShPtr > & GetZones() const
Definition: Movement.h:73
const InterfaceCollection & GetInterfaces() const
Definition: Movement.h:68
void AddInterface(std::string name, InterfaceShPtr left, InterfaceShPtr right)
Add pair of interfaces to this data.
void AddZone(ZoneBaseShPtr zone)
Add a zone object to this Movement data.
void WriteMovement(TiXmlElement *root)
Write the MOVEMENT section of the XML file.
std::shared_ptr< Interpreter > InterpreterSharedPtr
Definition: Interpreter.h:322
std::shared_ptr< SessionReader > SessionReaderSharedPtr
std::shared_ptr< Equation > EquationSharedPtr
Definition: Equation.h:125
LibUtilities::SessionReaderSharedPtr CreateSession()
const std::string xEqnStr
SpatialDomains::ZoneBaseShPtr CreateZone(SpatialDomains::MovementType type, int zoneID, int domainID, LibUtilities::InterpreterSharedPtr interpreter)
Produce dummy Zone objects, containing empty domain pointers.
std::vector< std::string > velocityStr
const NekPoint< NekDouble > origin
const std::string yEqnStr
SpatialDomains::InterfaceShPtr CreateInterface(int interfaceID, std::vector< int > compositeIDs)
Produce dummy Interface objects, containing empty domain pointers.
BOOST_AUTO_TEST_CASE(TestAddGetZones)
const std::string zEqnStr
const std::string angVelStr
std::vector< std::string > displacementStr
std::shared_ptr< ZoneBase > ZoneBaseShPtr
Definition: Zones.h:170
std::shared_ptr< ZoneTranslate > ZoneTranslateShPtr
Definition: Zones.h:313
std::shared_ptr< InterfacePair > InterfacePairShPtr
std::shared_ptr< ZoneRotate > ZoneRotateShPtr
Definition: Zones.h:312
std::shared_ptr< Interface > InterfaceShPtr
MovementType
Enum of zone movement type.
Definition: Zones.h:47
std::map< std::pair< int, std::string >, InterfacePairShPtr > InterfaceCollection
Definition: Movement.h:49
std::shared_ptr< ZoneFixed > ZoneFixedShPtr
Definition: Zones.h:314
std::map< int, CompositeSharedPtr > CompositeMap
Definition: MeshGraph.h:136