User-facing guide. For contributors, see README.md + docs/code-map.md + docs/vectorization-guide.md.
🇧🇷 Versao em portugues:
docs/como-usar.md
- MATLAB R2019b or later (tested with R2024a on Windows via WSL)
- Gmsh (system install:
apt install gmshon Linux,choco install gmshon Windows) — used only for editing mesh files, not required to RUN the simulator
-
Clone the repo (release lives on
master):git clone https://github.com/Feraul/FlowSim.git cd FlowSim # master = current v2.0.1-vectorized release # for the pre-vectorization backup, use: git checkout v1.0.0-pre-vectorization
-
Edit
Start.dat— the runtime config file. Every line marked>>> EDITE AQUI <<<is a user parameter. Most important:- Output path (line 33) — where results go. Use forward slashes on Linux/WSL, backslashes on Windows.
- Mesh path (line 218) — folder containing
.mshfiles. All meshes now live undermeshes/{hermeline,kozdon,other}/— point Start.dat at the right subdir. - Mesh filename (line 224) — e.g.
M8.msh. numcase— which benchmark case (seefactories/createBenchmark.mfor the full list).pmethod— one of:tpfa/mpfad/mpfah/nlfvpp/mpfaql.phasekey— physics family:1= single-phase pressure/saturation4= groundwater hydraulic head5= contaminant + hydraulic head6= Richards (partially saturated)
-
Confirm SPE10 permeability data (optional — only for SPE10 cases). By default they've been relocated out of the repo (
spe10.mat,spe_perm.dat~90 MB total). If a benchmark needs them:- Symlink from the location
fs.data.paths('spe10')reports, OR - Set the environment variable
FS_DATA_DIRto where you keep them.
- Symlink from the location
cd /path/to/FlowSim
flowsim_init % sets up all paths (only needed once per session)
main % reads Start.dat, runs the configured casecd /path/to/FlowSim
# One-shot run of main.m:
tools/mrun -c $(pwd) main.m
# Or a specific script:
tools/mrun -c $(pwd) /path/to/myscript.m
# One-liner:
tools/mrun -e "disp('hi'); disp(version)"
# With timeout (default 30 min):
tools/mrun -t 3600 -c $(pwd) main.m
# With auto-log to /tmp/mrun-logs/:
tools/mrun -L -c $(pwd) main.mmrun wraps matlab.exe -batch and:
- Filters harmless UNC change-notification warnings
- Auto-cd's into the script's directory (or a
-coverride) - Propagates the exit code (0 = ok, non-0 = MATLAB error, 124 = timeout)
# Full smoke pass (fast, ~30s):
tools/mrun -c $(pwd) tests/smoke/smoke_env.m
# All smoke + unit (~5 min):
tools/mrun -c $(pwd) tests/run_all.m
# One specific test (with verbose progress):
tools/mrun -c $(pwd) tests/unit/unit_baseline_reproduces.mAll tests use tests/helpers/fs_test_env.m which isolates
Start.dat into a temp dir — your real Start.dat is never mutated by tests.
-
Create
benchmarks/CasoNNN.m— inherit fromSimulacaoBase, implement the abstract methods (seebase/SimulacaoBase.mfor the contract). Model after the existingbenchmarks/Caso439.m— it's the only fully implemented one. -
Register in
factories/createBenchmark.m:case NNN, bench = CasoNNN();
-
Update
Start.dat: setnumcase = NNN. -
Optionally add a smoke test in
tests/smoke/that verifies the class loads (meta.class.fromName('CasoNNN')).
-
Create
solvers/MetodoXXX.m— inherit fromMetodoBase, implement:preprocessar(env, parms)— precompute mesh-invariant quantitiesatualizarPremethod(env, parms)— refresh on new kmap (Richards)montarSistema(env, parms, dt)— return[M, I]resolver(M, I, parms, env, tempo, dt, source_wells)— solve (linear or Picard)calcularFlowrate(p, env, parms)— postprocess
-
Register in
factories/createMetodo.m:case 'xxx', metodo = MetodoXXX();
-
Update
Start.dat:pmethod = xxx. -
If you want the vectorized package structure: create
+fs/+assembly/+xxx/build.m(delegate to legacy at first; incrementally port to triplet form).
- "Undefined function or variable" on some
Caso...orMetodo...— the factory expects a class file that doesn't exist. OnlyCaso439+ the 5MetodoXXXclasses are wired in this branch. - "mkdir Access is denied" during preprocessormod — Start.dat's output path is Windows-style but MATLAB can't create it (path doesn't exist or no write permission). Fix the output path.
- "Cannot open file: ...\some_mesh.msh" — Start.dat's mesh dir + mesh
filename don't match a real file. Meshes now live under
meshes/{hermeline,kozdon,other}/— update Start.dat's mesh path. - Baseline test failing — probably a numerical change slipped in. Compare
norm(M_new - M_leg, 'fro') / norm(M_leg, 'fro'). If < 1e-12, adjust tolerance; if > 1e-12, there's a real bug.
| Symptom | Look at |
|---|---|
| MATLAB can't find a function | flowsim_init.m — is legacy tree on path? |
| Wrong pressures / flowrates | Golden baseline test + tests/golden/*.mat |
| Class won't instantiate | tests/smoke/smoke_class_hierarchy.m |
| Path setup issues | Run flowsim_init('verbose', true) to see the addpath order |
| WSL path issues | Add -v to mrun to see the actual MATLAB_CMD |
- Test scratch files live in
/tmp/flowsim_test_env/(recreated per test). - Auto-logs from
mrun -Llive in/tmp/mrun-logs/. - MATLAB
.asvautosaves — gitignored, safe to delete.
manual/manual.pdf— original scientific reference (numerical methods theory)CHANGELOG.md— what changed and whendocs/vectorization-guide.md— recipe for extending the+fs/treedocs/code-map.md— where every function lives + who calls whomtests/README.md— test harness details