Skip to content

Added initialization of the variables after allocation #162

Merged
mnottoli merged 5 commits into
ddsolvation:mainfrom
robin-dahl:Source-fix
Nov 5, 2025
Merged

Added initialization of the variables after allocation #162
mnottoli merged 5 commits into
ddsolvation:mainfrom
robin-dahl:Source-fix

Conversation

@robin-dahl

@robin-dahl robin-dahl commented Mar 27, 2025

Copy link
Copy Markdown
Contributor

This PR addresses two minor issues encountered during the self-consistent implementation of ddX.

Initialization in allocate_state
While working on the self-consistent implementation of ddX, we noticed that the initial guesses for the direct and adjoint solutions can be problematic. This was traced back to the allocate_state routine, where variables are allocated but not initialized to zero. This PR adds zero-initialization to the variables.
This change should not affect the behavior of ddX.

Jacobi Solver Convergence in ddLPB
During the implementation of ddLPB, we observed that one of the Jacobi solvers in the lpb_guess_adjoint routine fails to converge after the first SCF iteration. We resolved this by explicitly resetting hsp_guess to zero within the prec_tstarx routine.
This change is not expected to affect ddX, as the hsp_guess is already set to zero in the beginning, which explains why the first iteration works correctly but not the subsequent ones.

@mnottoli

mnottoli commented Aug 8, 2025

Copy link
Copy Markdown
Collaborator

I changed a bit how the guess for the adjoint screened Poisson equation is done.
Can you try again the case that was causing problems?
If it works, we can close this PR.

@robin-dahl

Copy link
Copy Markdown
Contributor Author

I changed a bit how the guess for the adjoint screened Poisson equation is done. Can you try again the case that was causing problems? If it works, we can close this PR.

Unfortunately, it is not working. However, the error message is a new one. Before the Jacobi solver did not converge but now we get "In fill_guess, the RHS is not initialized"

@mnottoli

mnottoli commented Aug 8, 2025

Copy link
Copy Markdown
Collaborator

I think the problem is here: https://github.com/robin-dahl/tblite/blob/d4b819c17af6f4748d1fa690718ee5759da1ea67/src/tblite/solvation/ddx.f90#L324C20-L324C23

You are calling fill_guess and fill_guess_adjoint without first calling setup first. The two guesses require the RHS and the adjoint RHS saved in the state.

@robin-dahl

Copy link
Copy Markdown
Contributor Author

Isn't that done by allocate_state?

@mnottoli

mnottoli commented Aug 8, 2025

Copy link
Copy Markdown
Collaborator

No, allocate_state simply allocates the various vectors. The two guesses are constructed by applying the diagonal of the matrices to the two RHSs. If the RHS has not been loaded by setup, the error is expected.

@robin-dahl

Copy link
Copy Markdown
Contributor Author

Alright, calling the setup however also requires calling multipole_electrostatics and multipole_psi, which I just do now with arbitrary point charges that are equal to zero. Seems to work though!

@mnottoli mnottoli merged commit a8d4f10 into ddsolvation:main Nov 5, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants