Skip to content

Conversation

@arnoldkk13
Copy link
Contributor

Pull Request Checklist. Please read and check each box with an X. Delete any part not applicable. Ask on the forum if you need help with any step.

Refactored the Newton line search functionality in do_one_defect_correction_Stokes_step into a new function in helper_functions.cc.

Before your first pull request:

For all pull requests:

For new features/models or changes of existing features:

  • [X ] I have tested my new feature locally to ensure it is correct.

* Performs a Newton line search for the do_one_defect_correction_Stokes_step function
*/
template <int dim>
void Simulator<dim>::perform_line_search(const DefectCorrectionResiduals &dcr, const bool use_picard, LinearAlgebra::BlockVector &search_direction)
Copy link
Contributor

Choose a reason for hiding this comment

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

same here:

  • return step length
  • one argument per line


/**
* Perform a newton line search to determine the optimal step length
* along the search direction.
Copy link
Contributor

Choose a reason for hiding this comment

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

Also say that the result of the function is that current_linearization_point is set to the old current_linearization_point plus a suitable update in direction of search_direction.

Copy link
Contributor

Choose a reason for hiding this comment

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

You'll still want to address this point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, document what the function returns.

@arnoldkk13 arnoldkk13 force-pushed the defect_correction_stokes_refactor branch from 8a53156 to 90b1500 Compare November 14, 2025 00:57
Copy link
Contributor

@bangerth bangerth left a comment

Choose a reason for hiding this comment

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

Only the two comments I'm leaving below.


/**
* Perform a newton line search to determine the optimal step length
* along the search direction.
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll still want to address this point.


/**
* Perform a newton line search to determine the optimal step length
* along the search direction.
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, document what the function returns.

@arnoldkk13 arnoldkk13 force-pushed the defect_correction_stokes_refactor branch from 0de2e51 to c537189 Compare November 18, 2025 05:19
Copy link
Contributor

@bangerth bangerth left a comment

Choose a reason for hiding this comment

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

This looks good to me. @arnoldkk13 is one of my undergraduate research students, so I would like someone else to take a second look and approve/disapprove.

We have some follow-ups in the pipeline. For example, the search_direction argument to the refactored function should really be const, but the original code modified it so the current code does too. We'll work on that next, once this patch is in.

Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

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

Looks all correct to me, I just have some code style suggestion, and a question about a change in the screen output. Let me know when you want me to take another look, and thanks @arnoldkk13!

Comment on lines 1343 to 1346
* is set to the old current_linearlization_point plus a suitable update.
*
* @return This function returns the updated residual after the line
* search is performed.
Copy link
Member

Choose a reason for hiding this comment

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

Could you indent this comment like the other lines? Unfortunately make indent does not affect doxygen comments so you will have to do it manually.

Also please add documentation for the other input parameters before @return in this format: * @param use_picard Whether a Picard iteration was used to ... and the same for the other parameters.

Comment on lines 2632 to 2634
/**
* Performs a Newton line search for the do_one_defect_correction_Stokes_step function
*/
Copy link
Member

Choose a reason for hiding this comment

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

Remove this comment here. The place to put these comments is the declaration of this function in the header file. And please add two more empty lines, we have a stylistic convention of having 3 empty lines between functions in all source files, and following this convention makes it easier to read the code.

Comment on lines 2653 to 2655
// Do the loop for the line search at least once with the full step length.
// If line search is disabled we will exit the loop in the first iteration.

Copy link
Member

Choose a reason for hiding this comment

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

I think the code would be easier to read if you had an empty line before the comment and no empty line between comment and the loop. It is just a quesiton of coding style, but code is typically read much more often than (re-)written and this is closer to our usual style.

pcout << " The linear solver tolerance is set to " << parameters.linear_stokes_solver_tolerance << std::endl;
pcout << " The linear solver tolerance is set to "
<< parameters.linear_stokes_solver_tolerance
<< ". ";
Copy link
Member

Choose a reason for hiding this comment

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

You removed an std::endl at the end of this line. Was this on purpose? If it was: Can you post how the output looked like before and now? I just want to check if it makes sense to remove the newline in this context.

@arnoldkk13 arnoldkk13 force-pushed the defect_correction_stokes_refactor branch from 12ce145 to c637833 Compare November 21, 2025 22:53
@arnoldkk13
Copy link
Contributor Author

@gassmoeller Thank you for the comments and changes! I’ve finished adding your comments, so please take a look when you have the chance.

Comment on lines 1340 to 1356
/**
* Perform a Newton line search to determine the optimal step length
* along the search direction. After the update, the current_linearization_point
* is set to the old current_linearlization_point plus a suitable update.
*
* @param dcr The defect correction residuals associated with the current nonlinear
* iteration.
* @param use_picard Whether a Picard iteration was used to update the nonlinear
* iteration (true) or a Newton update (false).
* @param search_direction The proposed update direction for the solution vector.
*
* @return This function returns the updated residual after the line
* search is performed.
*
* This function is implemented in
* <code>source/simulator/helper_functions.cc</code>
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll still want to align the stars at the beginning of each line.

@arnoldkk13 arnoldkk13 force-pushed the defect_correction_stokes_refactor branch from 0604575 to 0528889 Compare November 23, 2025 19:52
Copy link
Member

@gassmoeller gassmoeller left a comment

Choose a reason for hiding this comment

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

Yes, looks all good now. Thanks!

@gassmoeller
Copy link
Member

Ah this PR has acquired a conflict because I merged #6782. Could you update your main branch and then rebase this PR to resolve the conflict? Let us know if you need instructions for how that works.

@bangerth
Copy link
Contributor

@arnoldkk13 Let me know if you need help with resolving the merge conflict!

@arnoldkk13 arnoldkk13 force-pushed the defect_correction_stokes_refactor branch from 9416939 to 679066c Compare December 5, 2025 00:05
@arnoldkk13
Copy link
Contributor Author

I believe that the merge conflict should be resolved. Please let me know if any changes are needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants