Skip to content

Implement Darcy Physics - #620

Open
mmegally wants to merge 33 commits into
SimVascular:mainfrom
mmegally:darcy-solver
Open

Implement Darcy Physics#620
mmegally wants to merge 33 commits into
SimVascular:mainfrom
mmegally:darcy-solver

Conversation

@mmegally

@mmegally mmegally commented Aug 26, 2026

Copy link
Copy Markdown

Current situation

See issue #616 on introducing darcy physics.

Release Notes

  • Adding new equation type "darcy" to solve for pressure/flows in porous domains
  • Test cases added (referenced in issue)

Code of Conduct & Contributing Guidelines

@ktbolt

ktbolt commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

@mmegally You've changed 47 files for this PR. It would be helpful to describe at a high level in #616 the implementation, how this is used (XML) and any related issues for data files, linear solver, etc.

@zasexton

Copy link
Copy Markdown
Collaborator

@ktbolt i think the majority of these file changes have to do with adding any new physics into the current procedural framework. Unfortunate but expected at this point in my opinion. @mmegally I'll do my review in a few hours when I have some time. From my first glance id say that you should remove the sbatch slurm scripts from the commits. These shouldn't be in the testing infrastructure. I'll give a more formal review in a bit though

@mmegally

Copy link
Copy Markdown
Author

@ktbolt I went ahead and added a new comment to issue #616 with some details on the file change split, implementation, and XML usage. Let me know if there is anything else I can clarify. To reiterate my comment from there, 31/47 of the file changes are related to the test cases. I will also go ahead and remove the SLURMs from the test folder as zack mentioned right now

@ktbolt

ktbolt commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

@mmegally Got it, thanks for adding the Issue comments !

@ktbolt

ktbolt commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

@mmegally The darcy_convergence tests are not part of the CI tests so shouldn't they be stored somewhere else ?

Also rename the svFSI.xml files to solver.xml.

@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 52.01699% with 226 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.11%. Comparing base (00f5c92) to head (c159793).

Files with missing lines Patch % Lines
Code/Source/solver/darcy.cpp 0.00% 142 Missing ⚠️
Code/Source/solver/set_equation_props.h 85.34% 17 Missing ⚠️
Code/Source/solver/post.cpp 26.31% 14 Missing ⚠️
Code/Source/solver/read_files.cpp 67.74% 10 Missing ⚠️
Code/Source/solver/stokes.cpp 41.66% 7 Missing ⚠️
Code/Source/solver/eq_assem.cpp 0.00% 5 Missing ⚠️
Code/Source/solver/l_elas.cpp 54.54% 5 Missing ⚠️
Code/Source/solver/shells.cpp 66.66% 5 Missing ⚠️
Code/Source/solver/ustruct.cpp 54.54% 5 Missing ⚠️
Code/Source/solver/heats.cpp 50.00% 3 Missing ⚠️
... and 6 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #620      +/-   ##
==========================================
- Coverage   73.45%   73.11%   -0.35%     
==========================================
  Files         267      268       +1     
  Lines       40041    40241     +200     
  Branches     6706     6729      +23     
==========================================
+ Hits        29413    29423      +10     
- Misses      10385    10575     +190     
  Partials      243      243              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zasexton zasexton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested changes for Darcy equation initialization and fiber-flux reconstruction.

Comment thread Code/Source/solver/consts.h
Comment thread Code/Source/solver/post.cpp Outdated
Comment thread Code/Source/solver/darcy.cpp Outdated
Comment thread Code/Source/solver/set_equation_props.h Outdated
Comment thread Code/Source/solver/set_equation_props.h Outdated
@mmegally
mmegally requested a review from zasexton August 27, 2026 22:26

@michelebucelli michelebucelli left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @mmegally! I left a few comments.

Comment thread Code/Source/solver/CMakeLists.txt Outdated
Comment thread Code/Source/solver/consts.h Outdated
Comment thread Code/Source/solver/consts.h Outdated
Comment thread Code/Source/solver/consts.h
Comment thread Code/Source/solver/consts.h Outdated
Comment thread Code/Source/solver/darcy.cpp Outdated
Comment thread Code/Source/solver/darcy.cpp Outdated
Comment thread Code/Source/solver/darcy.cpp Outdated
Comment thread Code/Source/solver/darcy.cpp Outdated
Comment on lines +142 to +181
void darcy_1d(ComMod& com_mod, const int eNoN, const double w, const Vector<double>& N, const Array<double>& Nx,
const Array<double>& al, const Array<double>& yl, Array<double>& lR, Array3<double>& lK)
{
using namespace consts;

const int cEq = com_mod.cEq;
auto& eq = com_mod.eq[cEq];
const int cDmn = com_mod.cDmn;
auto& dmn = eq.dmn[cDmn];
const double dt = com_mod.dt;
const int i = eq.s;

double k = dmn.prop.at(PhysicalProperyType::permeability);
double source = dmn.prop.at(PhysicalProperyType::source_term);
double beta_0 = dmn.prop.at(PhysicalProperyType::media_compressibility);
double rho_0 = dmn.prop.at(PhysicalProperyType::fluid_density);
double mu = dmn.prop.at(PhysicalProperyType::darcy_fluid_viscosity);

double T1 = eq.af * eq.gam * dt;
double amd = eq.am / T1;
double wl = w * T1;

double p_dot = 0.0;
double Px = 0.0;

for (int a = 0; a < eNoN; a++) {
p_dot = p_dot + N(a) * al(i, a);
Px = Px + Nx(0, a) * yl(i, a);
}

for (int a = 0; a < eNoN; a++) {
lR(0, a) = lR(0, a) +
w * (rho_0 * N(a) * (beta_0 * p_dot - source) +
((k * rho_0) / mu) * Nx(0, a) * Px);
for (int b = 0; b < eNoN; b++) {
lK(0, a, b) = lK(0, a, b) + wl * (rho_0 * beta_0 * N(a) * N(b) * amd +
((((rho_0 * k) / mu) * (Nx(0, a) * Nx(0, b)))));
}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am reading this code right, the problem assembled here does not match the one stated in the documentation at the top of this file. The differences I can notice are the following.

  1. The terms assembled here do not have anything that corresponds to the sink term $\beta_1 (p - p_{sink})$.
  2. The term multiplied by $\beta_0$ is not $\beta_0 (p - p_{source})$, but rather $\beta_0 \rho_0 \frac{\partial p}{\partial t}$
  3. There's a couple of coefficients ($\rho_0$ and $\mu$) that rescale the permeability $K$.

It seems to me that the strong form of the problem assembled here is

$$ \rho_0\beta_0\frac{\partial p}{\partial t} - \nabla \cdot\left(\frac{K\rho_0} {\mu}\nabla p\right) = \rho_0 p_{source} $$

Is this right?

If so, I would suggest confirming that this is indeed the problem that is meant to be solved, and update the documentation accordingly.

Additionally, in the above equation $\rho_0$ can be simplified out (assuming it is homogeneous and constant, which seems to be the case), so I suggest to consider whether it makes sense to remove it altogether. Similarly, $\mu$ only acts as a rescaling term on $K$, so just asking the user to provide a rescaled permemability might make for a simpler parameterization.

The same comments apply to darcy_2d and darcy_3d below.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opting to keep the viscosity and permeability separate at this time since there will likely be some ongoing discussions with the wet-lab experimentalists that will likely want some 1:1 correspondence for their measurements to input parameters. Also keeping the 2d and 3d assembly kernels separate at this time to mirror the other physics files; although I agree that future refactoring should cleanup these to have better concision of code.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also yes the equation that we should be solving for this model is:

$$\rho\beta\frac{\partial p}{\partial t}-\nabla\cdot\left(\frac{\rho K}{\mu}\nabla p\right)=\rho s$$.

$\beta$ should be the storage/compressibility and $s$ is the prescribed volumetric source. You are correct that we do not implement the $p_{source}$ and $p_{sink}$ exchange terms from the original documentation that was written. That documentation has been updated to reflect the current assembly implementation.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying! I assume that you opted to keep the density separate for the same reason as viscosity and compressibility, right?

Comment thread Code/Source/solver/darcy.cpp
@zasexton

zasexton commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

About to push some commits to this fork then we can elevate this draft to a full PR. in the meantime @mmegally can you resolve the active comments that you have addressed along with their appropriate commit tags? you've been doing a great job at fixing up the code so far :)

Resolve remaining Darcy review comments
@zasexton

zasexton commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

@mmegally let's mark this as "Ready to review"

@mmegally
mmegally marked this pull request as ready for review September 3, 2026 20:36

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@zasexton zasexton added the enhancement New feature or request label Sep 3, 2026
@mmegally mmegally mentioned this pull request Sep 8, 2026
Comment thread Code/Source/solver/initialize.cpp

@zasexton zasexton left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion we only piece requiring a bit more review is the zero initialization for the 2D cases to make sure that we are not getting heap error allocations and out-of-bounds. I'll fork this branch and double-check now to make any appropriate changes, if necessary.

@zasexton
zasexton self-requested a review September 10, 2026 18:30

@michelebucelli michelebucelli left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I did a second pass, I only have a few minor suggestions left.

Comment thread Code/Source/solver/darcy.cpp Outdated
Comment thread Code/Source/solver/darcy.cpp Outdated
Comment thread Code/Source/solver/darcy.h
Comment thread Code/Source/solver/darcy.cpp Outdated
Comment on lines +142 to +181
void darcy_1d(ComMod& com_mod, const int eNoN, const double w, const Vector<double>& N, const Array<double>& Nx,
const Array<double>& al, const Array<double>& yl, Array<double>& lR, Array3<double>& lK)
{
using namespace consts;

const int cEq = com_mod.cEq;
auto& eq = com_mod.eq[cEq];
const int cDmn = com_mod.cDmn;
auto& dmn = eq.dmn[cDmn];
const double dt = com_mod.dt;
const int i = eq.s;

double k = dmn.prop.at(PhysicalProperyType::permeability);
double source = dmn.prop.at(PhysicalProperyType::source_term);
double beta_0 = dmn.prop.at(PhysicalProperyType::media_compressibility);
double rho_0 = dmn.prop.at(PhysicalProperyType::fluid_density);
double mu = dmn.prop.at(PhysicalProperyType::darcy_fluid_viscosity);

double T1 = eq.af * eq.gam * dt;
double amd = eq.am / T1;
double wl = w * T1;

double p_dot = 0.0;
double Px = 0.0;

for (int a = 0; a < eNoN; a++) {
p_dot = p_dot + N(a) * al(i, a);
Px = Px + Nx(0, a) * yl(i, a);
}

for (int a = 0; a < eNoN; a++) {
lR(0, a) = lR(0, a) +
w * (rho_0 * N(a) * (beta_0 * p_dot - source) +
((k * rho_0) / mu) * Nx(0, a) * Px);
for (int b = 0; b < eNoN; b++) {
lK(0, a, b) = lK(0, a, b) + wl * (rho_0 * beta_0 * N(a) * N(b) * amd +
((((rho_0 * k) / mu) * (Nx(0, a) * Nx(0, b)))));
}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying! I assume that you opted to keep the density separate for the same reason as viscosity and compressibility, right?

Comment thread Code/Source/solver/Parameters.cpp Outdated
Comment thread Code/Source/solver/post.cpp Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants