87 bool rejected =
false;
90 }
catch (
const std::invalid_argument &) {
94 return fail(errorMessage,
"invalid spatial step was not rejected");
98 if (potential.
width() != 8 || potential.
height() != 4 ||
99 potential.
size() != 32 || potential.
empty()) {
100 return fail(errorMessage,
"potential dimensions are incorrect");
103 return fail(errorMessage,
"new potential is not zero initialized");
106 const std::uint64_t revision0 = potential.
revision();
107 potential.
set(2, 1, 4.5f);
108 if (std::abs(potential(2, 1) - 4.5f) > 1.0e-6f ||
109 potential.
revision() == revision0) {
110 return fail(errorMessage,
"set/revision failed");
112 if (potential.
maximum() != 4.5f) {
113 return fail(errorMessage,
"potential maximum is incorrect");
116 potential.
fill(-2.0f);
117 if (potential.
minimum() != -2.0f || potential.
maximum() != -2.0f) {
118 return fail(errorMessage,
"fill/minimum/maximum failed");
123 return fail(errorMessage,
"clear failed");
126 bool boundsRejected =
false;
128 potential.
setAt(99, 0, 1.0f);
129 }
catch (
const std::out_of_range &) {
130 boundsRejected =
true;
132 if (!boundsRejected) {
133 return fail(errorMessage,
"out-of-range access was not rejected");
139 return fail(errorMessage,
"grid compatibility check failed");
144 const std::size_t cx = nearestIndexX(g, 0.0);
145 const std::size_t cy = nearestIndexY(g, 0.0);
147 return fail(errorMessage,
"physical coordinate mapping is incorrect");
152 if (g.
revision() != r + 1 || !sampleIs(g, 0.0, 0.0, 3.0f) ||
153 !sampleIs(g, 0.9, 0.4, 3.0f) || !sampleIs(g, 1.4, 0.0, 0.0f)) {
154 return fail(errorMessage,
"rectangle primitive failed");
160 if (g.
revision() != r + 1 || !sampleIs(g, 0.0, 0.0, 4.0f) ||
161 !sampleIs(g, 0.7, 0.7, 4.0f) || !sampleIs(g, 1.2, 0.0, 0.0f)) {
162 return fail(errorMessage,
"circle primitive failed");
166 g.
addBarrier(-2.0f, -2.0f, 2.0f, 2.0f, 0.4f, 5.0f);
167 if (!sampleIs(g, 0.0, 0.0, 5.0f) || !sampleIs(g, 0.0, 1.0, 0.0f)) {
168 return fail(errorMessage,
"barrier primitive failed");
172 const std::vector<PotentialPoint2D> triangle = {
173 {-1.0f, -1.0f}, {1.0f, -1.0f}, {0.0f, 1.0f}
176 if (!sampleIs(g, 0.0, 0.0, 6.0f) || !sampleIs(g, 1.5, 0.0, 0.0f)) {
177 return fail(errorMessage,
"polygon primitive failed");
182 if (!sampleIs(g, 0.0, 0.0, 0.0f) || !sampleIs(g, 0.0, 1.0, 7.0f) ||
183 !sampleIs(g, 1.0, 1.0, 0.0f)) {
184 return fail(errorMessage,
"single slit primitive failed");
189 if (!sampleIs(g, 0.0, -1.0, 0.0f) || !sampleIs(g, 0.0, 1.0, 0.0f) ||
190 !sampleIs(g, 0.0, 0.0, 8.0f) || !sampleIs(g, 0.0, 2.0, 8.0f)) {
191 return fail(errorMessage,
"double slit primitive failed");
196 if (!sampleIs(g, 0.0, 0.0, -4.0f) ||
197 std::abs(g(nearestIndexX(g, 1.0), nearestIndexY(g, 0.0)) -
198 static_cast<float>(-4.0 * std::exp(-0.5))) > 2.0e-3f) {
199 return fail(errorMessage,
"Gaussian potential failed");
204 if (!sampleIs(g, 0.0, 0.0, 1.0f) ||
205 std::abs(g(nearestIndexX(g, 1.0), nearestIndexY(g, 0.0)) - 2.0f) > 1.0e-5f ||
206 std::abs(g(nearestIndexX(g, 0.0), nearestIndexY(g, 1.0)) - 3.0f) > 1.0e-5f) {
207 return fail(errorMessage,
"harmonic potential failed");
211 g.
addLinear(0.0f, 0.0f, 0.5f, 2.0f, -1.0f);
212 if (!sampleIs(g, 0.0, 0.0, 0.5f) ||
213 std::abs(g(nearestIndexX(g, 1.0), nearestIndexY(g, 1.0)) - 1.5f) > 1.0e-5f) {
214 return fail(errorMessage,
"linear potential failed");
219 if (std::abs(g(nearestIndexX(g, 0.0), nearestIndexY(g, 0.0)) + 6.0f) > 1.0e-5f ||
220 !(g(nearestIndexX(g, 2.0), nearestIndexY(g, 0.0)) > -2.0f)) {
221 return fail(errorMessage,
"softened radial potential failed");
224 bool smoothRejected =
false;
227 }
catch (
const std::invalid_argument &) {
228 smoothRejected =
true;
230 if (!smoothRejected) {
231 return fail(errorMessage,
"invalid smooth-potential dimensions were not rejected");
234 bool geometryRejected =
false;
237 }
catch (
const std::invalid_argument &) {
238 geometryRejected =
true;
240 if (!geometryRejected) {
241 return fail(errorMessage,
"invalid geometry dimensions were not rejected");
243 }
catch (
const std::exception &e) {
244 errorMessage = e.what();