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.
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).
- 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
sigmaon 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
fcentered at [2,3]). - Visualizes the log-scaled error map over a rectangular region, overlaying the boundary curve.
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.)
From the project root (/Users/…/Project), with your virtualenv active:
python3 integral2d.pyWhat 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.
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()usesN = 1000(trapezoidal). LowerNto speed things (e.g., 200–500) at cost of accuracy.plotDomainGauss()usespanels = 10andnum = 16(soN = panels * num). Adjustpanelsandnumto 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.
- Slow runs / high memory usage: the default
dA=500leads to 250k interior evaluations; each evaluation computes sums over all boundary nodes — this can be expensive. ReducedAor the quadratureN. - 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.
- Compare the trapezoidal vs Gauss–Legendre error plots by varying
Nandpanels/numand 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()aroundsolveDensityandmakePlot).
integral2d.py— main workhorse. Read top-to-bottom: parameterizations, exact solutionf, quadrature node generatorsmakeTrapNodesandmakeGaussNodes, matrix assemblersolveDensity, evaluatorevalSolution, 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.
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(), setN = 300 - In
plotDomainGauss(), setpanels = 6andnum = 8
Then run:
python3 integral2d.pyYou should see plots appear faster.
- Add a
requirements.txtorpyproject.tomlto 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, smallsolveDensitywith a known analytic case).
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.