Nektar++
Loading...
Searching...
No Matches
TestBoundaryNormals.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: TestBoundaryNormals.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: Unit tests for boundary normal interpolation.
32//
33///////////////////////////////////////////////////////////////////////////////
34
39
40#include <boost/test/unit_test.hpp>
41
42#include <cmath>
43#include <fstream>
44#include <string>
45
47{
48namespace
49{
50const std::string sessionFile = R"END(<?xml version="1.0" encoding="UTF-8"?>
51<NEKTAR>
52 <GEOMETRY DIM="3" SPACE="3">
53 <VERTEX>
54 <V ID="0"> 0 0 0 </V><V ID="1"> 1 0 0 </V>
55 <V ID="2"> 1 1 0 </V><V ID="3"> 0 1 0 </V>
56 <V ID="4"> 0 0 1 </V><V ID="5"> 0 1 1 </V>
57 </VERTEX>
58 <EDGE>
59 <E ID="0">0 1</E><E ID="1">1 2</E><E ID="2">2 3</E>
60 <E ID="3">3 0</E><E ID="4">0 4</E><E ID="5">1 4</E>
61 <E ID="6">2 5</E><E ID="7">3 5</E><E ID="8">4 5</E>
62 </EDGE>
63 <FACE>
64 <Q ID="0">3 0 1 2</Q><T ID="1">0 5 4</T>
65 <Q ID="2">1 6 8 5</Q><T ID="3">2 6 7</T>
66 <Q ID="4">3 7 8 4</Q>
67 </FACE>
68 <ELEMENT><R ID="0">0 1 2 3 4</R></ELEMENT>
69 <COMPOSITE>
70 <C ID="0">R[0]</C><C ID="1">F[0-4]</C>
71 </COMPOSITE>
72 <DOMAIN>C[0]</DOMAIN>
73 </GEOMETRY>
74 <EXPANSIONS>
75 <E COMPOSITE="C[0]" NUMMODES="4" TYPE="MODIFIED" FIELDS="u" />
76 </EXPANSIONS>
77 <CONDITIONS>
78 <VARIABLES><V ID="0">u</V></VARIABLES>
79 <BOUNDARYREGIONS><B ID="0">C[1]</B></BOUNDARYREGIONS>
80 <BOUNDARYCONDITIONS>
81 <REGION REF="0"><D VAR="u" VALUE="0" /></REGION>
82 </BOUNDARYCONDITIONS>
83 </CONDITIONS>
84</NEKTAR>
85)END";
86}
87
88BOOST_AUTO_TEST_CASE(TestBoundaryNormalsUseLocalTraceExpansion)
89{
90 fs::path path =
91 fs::temp_directory_path() / LibUtilities::UniquePath("bndnormals");
92 fs::create_directories(path);
93 path /= "TestBoundaryNormals.xml";
94
95 std::ofstream stream(path);
96 stream << sessionFile;
97 stream.close();
98
99 std::string pathString = path.string();
100 char executable[] = "MultiRegionsUnitTests";
101 char *argv[] = {executable, pathString.data(), nullptr};
105 session, graph, session->GetVariable(0));
106
107 Array<OneD, int> elmtId, faceId;
108 field->GetBoundaryToElmtMap(elmtId, faceId);
109
110 // Guard the fixture: using the parent volume expansion as the source of
111 // PhysInterp must require values beyond at least one trace-normal array.
112 bool exercisesMismatchedTrace = false;
113 for (int n = 0; n < field->GetBndCondExpansions()[0]->GetExpSize(); ++n)
114 {
115 auto elmt = field->GetExp(elmtId[n]);
116 auto localNormals = elmt->GetTraceNormal(faceId[n]);
117 int volume01 = elmt->GetBasis(0)->GetNumPoints() *
118 elmt->GetBasis(1)->GetNumPoints();
119 exercisesMismatchedTrace |= localNormals[0].size() != volume01;
120 }
121 BOOST_REQUIRE(exercisesMismatchedTrace);
122
124 field->GetBoundaryNormals(0, normals);
125
126 int npoints = field->GetBndCondExpansions()[0]->GetTotPoints();
128 for (int d = 0; d < 3; ++d)
129 {
130 expected[d] = Array<OneD, NekDouble>(npoints, 0.0);
131 }
132
133 for (int n = 0; n < field->GetBndCondExpansions()[0]->GetExpSize(); ++n)
134 {
135 auto elmt = field->GetExp(elmtId[n]);
136 auto localNormals = elmt->GetTraceNormal(faceId[n]);
137 // The boundary expansion lives in the shared-trace frame, which is
138 // what the aligned variant carries.
139 auto localTrace = elmt->GetAlignedTraceExp(faceId[n]);
140 int offset = field->GetBndCondExpansions()[0]->GetPhys_Offset(n);
142
143 for (int d = 0; d < 3; ++d)
144 {
145 field->GetBndCondExpansions()[0]->GetExp(n)->PhysInterp(
146 localTrace, localNormals[d], tmp = expected[d] + offset);
147 }
148 }
149
150 BOOST_REQUIRE_EQUAL(normals.size(), 3);
151 for (int d = 0; d < 3; ++d)
152 {
153 BOOST_REQUIRE_EQUAL(normals[d].size(), npoints);
154 }
155
156 for (int i = 0; i < npoints; ++i)
157 {
158 NekDouble magnitude = 0.0;
159 for (int d = 0; d < 3; ++d)
160 {
161 BOOST_REQUIRE(std::isfinite(normals[d][i]));
162 BOOST_CHECK_SMALL(normals[d][i] - expected[d][i], 1.0e-12);
163 magnitude += normals[d][i] * normals[d][i];
164 }
165 BOOST_CHECK_SMALL(std::sqrt(magnitude) - 1.0, 1.0e-12);
166 }
167
168 fs::remove_all(path.parent_path());
169}
170} // namespace Nektar::BoundaryNormalsTest
LibUtilities::SessionReaderSharedPtr session
SpatialDomains::MeshGraphSharedPtr graph
static SessionReaderSharedPtr CreateInstance(int argc, char *argv[])
Creates an instance of the SessionReader class.
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static MeshGraphSharedPtr Read(const LibUtilities::SessionReaderSharedPtr pSession, LibUtilities::DomainRangeShPtr rng=LibUtilities::NullDomainRangeShPtr, bool fillGraph=true, SpatialDomains::MeshGraphSharedPtr partitionedGraph=nullptr)
BOOST_AUTO_TEST_CASE(TestBoundaryNormalsUseLocalTraceExpansion)
static fs::path UniquePath(std::string specFileStem)
Create a unique (random) path, based on an input stem string. The returned string is a filename or di...