Hello everyone,
I am implementing a fiber orientation modeling strategy inspired by the paper "Image-based immersed boundary model of the aortic root", where the valve leaflet fiber direction is derived from the gradient of a scalar potential field u obtained by solving the Poisson equation.
I wrote the C++ code using libMesh (main parts shown below):
and in the main code is :
Problem:
When calling system.solve(), the program hangs or stalls silently — no error, but also no residual or convergence output, as :
EquationSystems
n_systems()=2
System #0, "Poisson_u"
Type "LinearImplicit"
Variables="u"
Finite Element Types="LAGRANGE"
Approximation Orders="FIRST"
n_dofs()=2949
n_local_dofs()=2949
n_constrained_dofs()=244
n_local_constrained_dofs()=244
n_vectors()=1
n_matrices()=1
DofMap Sparsity
Average On-Processor Bandwidth <= 11.9447
Average Off-Processor Bandwidth <= 0
Maximum On-Processor Bandwidth <= 19
Maximum Off-Processor Bandwidth <= 0
DofMap Constraints
Number of DoF Constraints = 244
Number of Heterogenous Constraints= 122
Average DoF Constraint Length= 0
System #1, "Poisson_v"
Type "LinearImplicit"
Variables="v"
Finite Element Types="LAGRANGE"
Approximation Orders="FIRST"
n_dofs()=2949
n_local_dofs()=2949
n_constrained_dofs()=244
n_local_constrained_dofs()=244
n_vectors()=1
n_matrices()=1
DofMap Sparsity
Average On-Processor Bandwidth <= 11.9447
Average Off-Processor Bandwidth <= 0
Maximum On-Processor Bandwidth <= 19
Maximum Off-Processor Bandwidth <= 0
DofMap Constraints
Number of DoF Constraints = 244
Number of Heterogenous Constraints= 122
Average DoF Constraint Length= 0
Total DOFs: 2949
Total constrained DOFs: 244
Global RHS: min=0, max=133028
Converged reason = -11
Iterations = 0, Final residual = inf
Total DOFs: 2949
Total constrained DOFs: 244
Global RHS: min=0, max=133062
Converged reason = -11
Iterations = 0, Final residual = inf
sol_u[0] = inf
sol_u[1] = inf
sol_u[2] = inf
sol_u[3] = inf
sol_u[4] = inf
sol_u[5] = inf
sol_u[6] = inf
sol_u[7] = inf
sol_u[8] = inf
sol_u[9] = inf
I’ve tried using various solvers (CG, GMRES) and preconditioners (AMG, ILU), but nothing helps.
Hi,
I did a quick test of your code and I think I have a rough idea of what’s going wrong. You shouldn't encapsulate the finite element assembly and solve steps entirely inside the solve_poisson function—this disrupts the expected workflow.
Generally, the workflow is: declare the system, assemble it, apply boundary conditions, initialize the system, and then solve. I suggest checking out the Poisson equation example provided by libMesh, which follows this standard computational workflow and should align well with your needs. You can find it at path_to_libMesh_src/examples/introduction/introduction_ex5
As for why MATLAB is able to compute the result, I suspect it's because the equation system in your code is not properly initialized, even if the assembly is done correctly. This is just a hypothesis, but it's likely that libMesh doesn’t solve the system using the raw assembled matrix directly—there may be some internal transformations or setup steps involved.
Thank you so much for your prompt and insightful response!
You're absolutely right, encapsulating the entire assembly and solve process inside the solve_poisson function did break the expected workflow. I refactored the code to follow the standard steps: declaring the system, assembling it, applying boundary conditions, initializing, and then solving, and it now works perfectly.
I also checked the example you mentioned (introduction_ex5), and it really helped clarify the intended structure. I appreciate the pointer.
Thanks again for your help — it was exactly what I needed!