Skip to content

zane-perry/Boundary-Value-ODE-PDE-Solver

Repository files navigation

2D Boundary Integral Visualization (Project)

This repository contains Python and MATLAB code used to explore boundary integral methods for 2D potential problems (Laplace-type problems) and to visualize approximation errors across a 2D domain.

Contents

  • integral2d.py — Main Python script. Builds and solves a boundary integral equation for a parameterized closed curve, computes the boundary density, evaluates the solution inside the domain, and plots a log-scaled error map.
  • integral1d.py — (Related) 1D integral utilities / experiments (not the main runner).
  • deprecated.py — Old/experimental code kept for reference.
  • test.py — Small test/driver file (useful for quick checks).
  • Interior_diriclet.m, main_neuman_star2.m — MATLAB scripts likely used for related experiments (Dirichlet/Neumann problems).

What integral2d.py does (short)

  • Defines a parameterized closed boundary curve via functions x(t), y(t) and their derivatives dx, dy, ddx, ddy. Several example parameterizations are commented in the file (circle, clover, "little guy"); the file currently uses a "blob" parameterization.
  • Uses a Nyström collocation approach to assemble a double-layer operator matrix D and constructs the linear system A = (-1/2 I) + D to match boundary values.
  • Solves for the density sigma on the boundary.
  • Evaluates the resulting potential at interior grid points and computes pointwise absolute errors against the exact solution f (the code uses a known fundamental-solution-like exact f centered at [2,3]).
  • Visualizes the log-scaled error map over a rectangular region, overlaying the boundary curve.

Dependencies

The Python code requires:

  • Python 3.8+ (tested locally with 3.8–3.11)
  • numpy
  • scipy
  • matplotlib

Install with pip in a virtual environment:

# macOS / bash
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install numpy scipy matplotlib

(If you prefer, create a requirements.txt with numpy, scipy, matplotlib.)

How to run

From the project root (/Users/…/Project), with your virtualenv active:

python3 integral2d.py

What to expect:

  • The script will display the boundary shape first (a small plot).
  • Then it will compute the density using a trapezoidal rule discretization (plotDomainTrap) and show an error heatmap.
  • Next it will compute the density using a Gauss–Legendre composite rule (plotDomainGauss) and show a second error heatmap.

Each heatmap is drawn with a logarithmic color scale and the parameterized boundary overplotted in black.

Parameters you may want to tweak

Open integral2d.py and edit these top-level variables:

  • left, right, bottom, top — domain rectangle for the error plot.
  • dA — resolution of interior evaluation grid (default 500). Decrease for faster runs (e.g., 150 or 250) if plotting or memory/time is an issue.
  • dt — number of points used to draw the boundary curve for overlay (default 100).

Discretization / quadrature settings inside the two plot functions:

  • plotDomainTrap() uses N = 1000 (trapezoidal). Lower N to speed things (e.g., 200–500) at cost of accuracy.
  • plotDomainGauss() uses panels = 10 and num = 16 (so N = panels * num). Adjust panels and num to change composite Gauss quadrature accuracy/cost.

Parameterizations of the boundary are present near the top of the file. There are several commented blocks:

  • A circle
  • A clover domain
  • A "little guy" domain
  • A "blob" domain (currently active)

To change the domain: comment or uncomment the block defining x, y, dx, dy, ddx, ddy. Make sure exactly one parameterization block defines these functions.

Common issues & troubleshooting

  • Slow runs / high memory usage: the default dA=500 leads to 250k interior evaluations; each evaluation computes sums over all boundary nodes — this can be expensive. Reduce dA or the quadrature N.
  • Ill-conditioned or singular linear system: if the assembled matrix is near singular, try increasing quadrature resolution or adjusting the geometry (self-intersection can cause issues). Using double precision via NumPy is standard.
  • If Matplotlib windows don’t appear: ensure your environment supports graphical display (running on macOS with a standard desktop session is fine). When running over SSH, use an X server or save figures to files by calling plt.savefig(...) in the code.

Tips for experiments

  • Compare the trapezoidal vs Gauss–Legendre error plots by varying N and panels/num and observing how the log-error maps change.
  • Explore the effect of moving the exact-solution source point inside/outside the domain in f = lambda point: (-1/(2*np.pi))*np.log(np.linalg.norm(point - np.array([2,3]))).
  • Add timing/print statements to measure assembly and solve times (e.g., time.time() around solveDensity and makePlot).

Files of interest

  • integral2d.py — main workhorse. Read top-to-bottom: parameterizations, exact solution f, quadrature node generators makeTrapNodes and makeGaussNodes, matrix assembler solveDensity, evaluator evalSolution, and plotting functions.
  • test.py — quick checks; you can use or extend it for automated/short-run tests.
  • MATLAB files (.m) — related but separate; open them with MATLAB/Octave.

Example quick-run (faster)

If you'd like a faster run for quick visual checks, edit these values near the top of integral2d.py before running:

  • dA = 150 # lower-res interior grid
  • In plotDomainTrap(), set N = 300
  • In plotDomainGauss(), set panels = 6 and num = 8

Then run:

python3 integral2d.py

You should see plots appear faster.

Next steps & suggested improvements

  • Add a requirements.txt or pyproject.toml to pin dependencies.
  • Add a small command-line interface (argparse) to switch parameterizations and numeric parameters without editing the source.
  • Save figures automatically (and optionally export data) for batch experiments.
  • Add unit tests for low-level functions (makeTrapNodes, makeGaussNodes, small solveDensity with a known analytic case).

Contact / Author

This file was generated as documentation for the project code present in this directory. If you have further questions about how a function works or want me to add example runs or tests, let me know and I can update the README or code.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published