|
| 1 | +/*! |
| 2 | + * \file CGeometry_tests.cpp |
| 3 | + * \brief Unit tests for CGeometry. |
| 4 | + * \author T. Albring |
| 5 | + * \version 7.0.5 "Blackbird" |
| 6 | + * |
| 7 | + * SU2 Project Website: https://su2code.github.io |
| 8 | + * |
| 9 | + * The SU2 Project is maintained by the SU2 Foundation |
| 10 | + * (http://su2foundation.org) |
| 11 | + * |
| 12 | + * Copyright 2012-2020, SU2 Contributors (cf. AUTHORS.md) |
| 13 | + * |
| 14 | + * SU2 is free software; you can redistribute it and/or |
| 15 | + * modify it under the terms of the GNU Lesser General Public |
| 16 | + * License as published by the Free Software Foundation; either |
| 17 | + * version 2.1 of the License, or (at your option) any later version. |
| 18 | + * |
| 19 | + * SU2 is distributed in the hope that it will be useful, |
| 20 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | + * Lesser General Public License for more details. |
| 23 | + * |
| 24 | + * You should have received a copy of the GNU Lesser General Public |
| 25 | + * License along with SU2. If not, see <http://www.gnu.org/licenses/>. |
| 26 | + */ |
| 27 | + |
| 28 | +#include "catch.hpp" |
| 29 | +#include "../../UnitQuadTestCase.hpp" |
| 30 | + |
| 31 | +std::unique_ptr<UnitQuadTestCase> TestCase; |
| 32 | + |
| 33 | +TEST_CASE("Geometry constructor", "[Geometry]"){ |
| 34 | + |
| 35 | + cout.rdbuf(nullptr); |
| 36 | + |
| 37 | + TestCase = std::unique_ptr<UnitQuadTestCase>(new UnitQuadTestCase()); |
| 38 | + |
| 39 | + TestCase->InitConfig(); |
| 40 | + |
| 41 | + auto aux_geometry = std::unique_ptr<CGeometry>(new CPhysicalGeometry(TestCase->config.get(), 0, 1)); |
| 42 | + |
| 43 | + CHECK(aux_geometry->GetnPoint() == 125); |
| 44 | + CHECK(aux_geometry->GetnElem() == 64); |
| 45 | + CHECK(aux_geometry->GetnElemHexa() == 64); |
| 46 | + CHECK(aux_geometry->GetnEdge() == 0); |
| 47 | + CHECK(aux_geometry->GetnElem_Bound(0) == 16); |
| 48 | + CHECK(aux_geometry->GetnElem_Bound(5) == 16); |
| 49 | + |
| 50 | + TestCase->geometry = std::unique_ptr<CGeometry>(new CPhysicalGeometry(aux_geometry.get(), TestCase->config.get())); |
| 51 | + |
| 52 | + CHECK(TestCase->geometry->GetnPoint() == 125); |
| 53 | + CHECK(TestCase->geometry->GetnElem() == 64); |
| 54 | + CHECK(TestCase->geometry->GetnElemHexa() == 64); |
| 55 | + CHECK(TestCase->geometry->GetnEdge() == 0); |
| 56 | + CHECK(TestCase->geometry->GetnElem_Bound(0) == 16); |
| 57 | + CHECK(TestCase->geometry->GetnElem_Bound(5) == 16); |
| 58 | + |
| 59 | + cout.rdbuf(TestCase->orig_buf); |
| 60 | + |
| 61 | +} |
| 62 | + |
| 63 | +TEST_CASE("Set Send/Recv", "[Geometry]"){ |
| 64 | + TestCase->geometry->SetSendReceive(TestCase->config.get()); |
| 65 | + |
| 66 | + /*---- No check yet, since unit tests run in serial at the moment ---*/ |
| 67 | +} |
| 68 | + |
| 69 | +TEST_CASE("Set Boundaries", "[Geometry]"){ |
| 70 | + |
| 71 | + TestCase->geometry->SetBoundaries(TestCase->config.get()); |
| 72 | + |
| 73 | + CHECK(TestCase->config->GetMarker_All_KindBC(0) == CUSTOM_BOUNDARY); |
| 74 | + CHECK(TestCase->config->GetMarker_All_KindBC(2) == HEAT_FLUX); |
| 75 | + CHECK(TestCase->config->GetSolid_Wall(2)); |
| 76 | + CHECK(TestCase->config->GetSolid_Wall(3)); |
| 77 | +} |
| 78 | + |
| 79 | +TEST_CASE("Set Point Connectivity", "[Geometry]"){ |
| 80 | + |
| 81 | + TestCase->geometry->SetPoint_Connectivity(); |
| 82 | + |
| 83 | + CHECK(TestCase->geometry->nodes->GetnElem(55) == 4); |
| 84 | + CHECK(TestCase->geometry->nodes->GetElem(30, 2) == 16); |
| 85 | + CHECK(TestCase->geometry->nodes->GetnNeighbor(3) == 4); |
| 86 | + CHECK(TestCase->geometry->nodes->GetPoint(99, 2) == 98); |
| 87 | +} |
| 88 | + |
| 89 | +TEST_CASE("Set elem connectivity", "[Geometry]"){ |
| 90 | + |
| 91 | + TestCase->geometry->SetElement_Connectivity(); |
| 92 | + |
| 93 | + CHECK(TestCase->geometry->elem[14]->GetnNeighbor_Elements() == 6); |
| 94 | + CHECK(TestCase->geometry->elem[14]->GetNeighbor_Elements(1) == 15); |
| 95 | + |
| 96 | +} |
| 97 | + |
| 98 | +TEST_CASE("Set bound volume", "[Geometry]"){ |
| 99 | + |
| 100 | + TestCase->geometry->SetBoundVolume(); |
| 101 | + |
| 102 | + CHECK(TestCase->geometry->bound[0][10]->GetDomainElement() == 40); |
| 103 | + CHECK(TestCase->geometry->bound[4][10]->GetDomainElement() == 10); |
| 104 | + |
| 105 | +} |
| 106 | + |
| 107 | +TEST_CASE("Set Edges", "[Geometry]"){ |
| 108 | + |
| 109 | + TestCase->geometry->SetEdges(); |
| 110 | + |
| 111 | + CHECK(TestCase->geometry->edges->GetnNodes() == 2); |
| 112 | + CHECK(TestCase->geometry->edges->GetNode(42,0) == 15); |
| 113 | + CHECK(TestCase->geometry->edges->GetNode(87,1) == 57); |
| 114 | + |
| 115 | +} |
| 116 | + |
| 117 | +TEST_CASE("Set vertex", "[Geometry]"){ |
| 118 | + |
| 119 | + TestCase->geometry->SetVertex(TestCase->config.get()); |
| 120 | + |
| 121 | + CHECK(TestCase->geometry->GetnVertex(0) == 25); |
| 122 | + CHECK(TestCase->geometry->vertex[0][20]->GetNode() == 100); |
| 123 | + CHECK(TestCase->geometry->nodes->GetVertex(100, 0) == 20); |
| 124 | + CHECK(TestCase->geometry->nodes->GetVertex(1, 0) == -1); |
| 125 | + |
| 126 | +} |
| 127 | + |
| 128 | +TEST_CASE("Set center of gravity", "[Geometry]"){ |
| 129 | + |
| 130 | + TestCase->geometry->SetCoord_CG(); |
| 131 | + |
| 132 | + CHECK(TestCase->geometry->elem[42]->GetCG(0) == 0.625); |
| 133 | + CHECK(TestCase->geometry->elem[3]->GetCG(1) == 0.125); |
| 134 | + CHECK(TestCase->geometry->elem[25]->GetCG(2) == 0.375); |
| 135 | + |
| 136 | + CHECK(TestCase->geometry->bound[1][4]->GetCG(0) == 1.0); |
| 137 | + CHECK(TestCase->geometry->bound[3][2]->GetCG(1) == 1.0); |
| 138 | + CHECK(TestCase->geometry->bound[4][3]->GetCG(2) == 0.0); |
| 139 | + |
| 140 | + CHECK(TestCase->geometry->edges->GetCG(10, 0) == 0.75); |
| 141 | + CHECK(TestCase->geometry->edges->GetCG(3, 1) == 0.125); |
| 142 | + CHECK(TestCase->geometry->edges->GetCG(22, 2) == 0.0); |
| 143 | +} |
| 144 | + |
| 145 | +TEST_CASE("Set control volume", "[Geometry]"){ |
| 146 | + |
| 147 | + TestCase->geometry->SetControlVolume(TestCase->config.get(), ALLOCATE); |
| 148 | + |
| 149 | + CHECK(TestCase->geometry->nodes->GetVolume(42) == Approx(0.015625)); |
| 150 | + |
| 151 | + CHECK(TestCase->geometry->edges->GetNormal(32)[0] == 0.03125); |
| 152 | + CHECK(TestCase->geometry->edges->GetNormal(5)[1] == 0.0); |
| 153 | + CHECK(TestCase->geometry->edges->GetNormal(10)[2] == 0.03125); |
| 154 | + |
| 155 | + CHECK(TestCase->config->GetDomainVolume() == Approx(1.0)); |
| 156 | + |
| 157 | +} |
| 158 | + |
| 159 | +TEST_CASE("Set bound control volume", "[Geometry]"){ |
| 160 | + |
| 161 | + TestCase->geometry->SetBoundControlVolume(TestCase->config.get(), ALLOCATE); |
| 162 | + |
| 163 | + CHECK(TestCase->geometry->vertex[0][4]->GetNormal()[0] == -0.0625); |
| 164 | + CHECK(TestCase->geometry->vertex[3][2]->GetNormal()[1] == -0.0625); |
| 165 | + CHECK(TestCase->geometry->vertex[5][3]->GetNormal()[2] == 0.03125); |
| 166 | + |
| 167 | +} |
0 commit comments