Skip to content

Commit

Permalink
Cleanup WaveEquation2D
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed May 24, 2024
1 parent 59f76d3 commit 7f76308
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
31 changes: 24 additions & 7 deletions src/ra/acoustic/WaveEquation2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,36 @@ auto WaveEquation2D::operator()(Callback const& callback) -> void
auto uNext = uNextBuf.to_mdspan();

// Source location and initial condition
u(Nx / 2, Ny / 2) = 1.0;
u(Nx / 4, Ny / 4) = 1.0;
u(Nx / 4 * 3, Ny / 4) = -1.0;

// Update equation function with Neumann boundary conditions
auto const delta = std::pow(c * dt / dx, 2.0);

fmt::println("Wave: {}x{} Nt={} dx={} fs={} fmax={}", Nx, Ny, Nt, dx, fs, _spec.fmax.numerical_value_in(si::hertz));

for (auto t{1U}; t < Nt - 1U; ++t) {
fmt::println(
"Wave: {}x{} Nt={} dx={:.1f}mm fs={:.0f}Hz fmax={:.0f}Hz",
Nx,
Ny,
Nt,
dx * 1'000.0,
fs,
_spec.fmax.numerical_value_in(si::hertz)
);

for (auto t{0U}; t < Nt; ++t) {
for (auto x{1U}; x < Nx - 1U; ++x) {
for (auto y{1U}; y < Ny - 1U; ++y) {
uNext(x, y)
= (2 * u(x, y) - uPrev(x, y) + delta * (u(x + 1, y) - 2 * u(x, y) + u(x - 1, y))
+ delta * (u(x, y + 1) - 2 * u(x, y) + u(x, y - 1)));
auto const prev = uPrev(x, y);
auto const now = u(x, y);
auto const right = u(x + 1, y);
auto const left = u(x - 1, y);
auto const top = u(x, y + 1);
auto const bottom = u(x, y - 1);

uNext(x, y) = (2 * now - prev + delta * (right - 2 * now + left) + delta * (top - 2 * now + bottom));

// u0 = in_mask * (0.5*(right + left + top + bottom) - prev);
// uNext(x, y) = 0.5 * (right + left + top + bottom) - prev;
}
}

Expand Down
2 changes: 1 addition & 1 deletion tool/RaumAkustik/tabs/WaveEquation2DEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ auto WaveEquation2DEditor::paint(juce::Graphics& g) -> void
}
}

g.drawImage(_frameImage, area.toFloat(), juce::RectanglePlacement::centred);
g.drawImage(_frameImage, area.toFloat().reduced(8.0F), juce::RectanglePlacement::centred);
}

auto WaveEquation2DEditor::resized() -> void
Expand Down

0 comments on commit 7f76308

Please sign in to comment.