Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IN REVIEW] Refactor EAS to handle NonLinearElastic #325

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

tarun-mitruka
Copy link
Collaborator

@tarun-mitruka tarun-mitruka commented Sep 19, 2024

This PR focuses on refactoring enhancedassumedstrains.hh such that it is compatible also with nonlinearelastic.hh.

See CHANGELOG.md for more details.

See also Issue #331.

DONE

  • Include updateState(/*...*/) in mixin.hh
  • Get rid of noAssembler() argument for nonlinop construcor
  • Does updateStateImpl() need to be a template of scalartype?
  • Incorporate the call of the updateState() function in nonlinear solvers. (see below the call by FEGenericObserver as an example)
  • Check if AutoDiff tests could be refactored even further
  • Can we make a default implementation for updateState() or does every element need to implement this - Every element has to implement as it can then also be used for instance to update history variables while working with plasticity.
  • Add tests performing a nonlinear analysis along with the EAS method.
  • Fix/Add Python bindings accordingly
// In newtonraphson.hh
this->notify(NonLinearSolverMessages::SOLUTION_UPDATED, correction_);

// In main.cpp
auto updateStateObserver = std::make_shared<Ikarus::FEGenericObserver<Ikarus::NonLinearSolverMessages>>(
    Ikarus::NonLinearSolverMessages::SOLUTION_UPDATED, [&](const Eigen::VectorXd& correction_) {
      for (auto& fe : fes) {
        req.insertGlobalSolution(Ikarus::FESolutions::displacement, D_Glob)
            .insertParameter(Ikarus::FEParameter::loadfactor, lambda);
        fe.updateState(req, correction_);
      }
});

nr->subscribeAll({updateStateObserver });

OTHER PR

@tarun-mitruka tarun-mitruka added enhancement New request to enhance existing features feature New feature labels Sep 19, 2024
@tarun-mitruka tarun-mitruka mentioned this pull request Sep 19, 2024
9 tasks
@tarun-mitruka tarun-mitruka force-pushed the NonlinearEAS branch 3 times, most recently from 3f72a67 to 5761ccd Compare September 27, 2024 13:42
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 96.66667% with 6 lines in your changes missing coverage. Please review.

Project coverage is 80.72%. Comparing base (13b6e50) to head (acb6da3).

Files with missing lines Patch % Lines
...finiteelements/mechanics/enhancedassumedstrains.hh 93.33% 5 Missing ⚠️
...olver/newtonraphsonwithscalarsubsidiaryfunction.hh 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #325      +/-   ##
==========================================
+ Coverage   78.99%   80.72%   +1.72%     
==========================================
  Files          69       70       +1     
  Lines        2238     2309      +71     
==========================================
+ Hits         1768     1864      +96     
+ Misses        470      445      -25     
Flag Coverage Δ
tests 80.72% <96.66%> (+1.72%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@tarun-mitruka tarun-mitruka force-pushed the NonlinearEAS branch 2 times, most recently from 3cbc683 to 572e568 Compare October 10, 2024 12:57
@tarun-mitruka tarun-mitruka marked this pull request as ready for review October 10, 2024 13:02
@tarun-mitruka tarun-mitruka requested a review from rath3t October 10, 2024 13:02
@tarun-mitruka
Copy link
Collaborator Author

@rath3t The C++ side of this PR is ready for the first review, the Python bindings side will be updated after the C++ side is converged in either this PR or via a separate PR by @henrij22

const auto controlInfo = lc.run();

double expectedLambda = 1.0;
double expectedMaxDisp = 4.459851990227056; // abs(maxDisp) in ANSYS APDL = 4.48777
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am not sure if this minor difference is acceptable here as ANSYS APDL is used more like a black box, where the control routine and nonlinear solver algorithms are not fully clear. Since the easAutoDiffTest passes, I think the solution should be correct here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Shall I remove the APDL comment here or leave it?
@rath3t You didn't comment anything in the tests during your review process. Can it be assumed that no major changes are necessary there?

@tarun-mitruka tarun-mitruka changed the title [DRAFT] Refactor EAS to handle NonLinearElastic [IN REVIEW] Refactor EAS to handle NonLinearElastic Oct 10, 2024
@tarun-mitruka tarun-mitruka force-pushed the NonlinearEAS branch 4 times, most recently from b2c03d4 to 022022c Compare October 21, 2024 15:08
@tarun-mitruka tarun-mitruka force-pushed the NonlinearEAS branch 2 times, most recently from 7437c55 to ffa7248 Compare October 29, 2024 15:53
@tarun-mitruka tarun-mitruka marked this pull request as draft October 30, 2024 08:04
- A `helperfunctions.hh` file is added that contains the helper functions used by the nonlinear solvers.
- This contains the function `updateStates()` that calls the `updateState()` function for every finite element.
- `updateStates()` is called by nonlinear solvers during every iteration, whenever the correction vector is updated.
- `NonLinearOperator` now has an additional template argument, `Assembler`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

IN my view the Nonlinear operator is by design only a collection of a function and its derivative.
There should be no template or object of an assembler. What should this be doing if all functions are just lambdas without any underlying assembler? But somehow I also dont see a nice solution to this we should chat about different posibilities of design choices. I think it can be already done with observers but this might be to indirect. E.g. all EAS element observe the non-linear solver and as soon as the solvers signals that the iteration or load step is finished the elements get notified and can update what they want. This seems nicer, since we dont have to refactor the design of nonlinearoperator.

Another thing would be a new class that contains a nonlinearoperator and the assembler.
Something similar I have done already in python branch for the solvers but Im not srue if we want that.

@@ -230,29 +232,34 @@ private:
return mat_;
}

protected:
bool usesEASSkill() const {
if constexpr (hasEAS)
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can also disable all the linear elastic functionality if eas is present and the eas method always deals with everything. Like calculateMatrix(...) requires not hasEAS which would disable the function alltogether and we would not have the runtime switch with usesEASSkill().

}
updateStates(nonLinearOperator().assembler(), correction_);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont like that introduction of states inside the innocent Newton-Raphson function.
This entangels unrelated functionality and might drop on our feet later, sicne extensibility is compromised since a local change somewhere else might affect this here.

@@ -377,6 +378,7 @@ public:

info_.randomPredictionString = "";

updateStates(nonLinearOperator().assembler(), eta_);
Copy link
Collaborator

Choose a reason for hiding this comment

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

same

*/
template <typename TypeListOne, typename TypeListTwo>
template <typename TypeListOne, typename TypeListTwo, typename Assembler = Impl::NoAssembler>
Copy link
Collaborator

Choose a reason for hiding this comment

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

As i said before this is not so nice

Copy link
Collaborator

@rath3t rath3t left a comment

Choose a reason for hiding this comment

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

See comment. But we should discuss this in person.

@tarun-mitruka
Copy link
Collaborator Author

tarun-mitruka commented Jan 10, 2025

To- Dos (New)

  • Remove/Modify Code related to displacement-based stuffs in EAS such that 'usesEASSkill' is not needed @tarun-mitruka
  • Remove notion of assembler from nonlinear operator and the notion of update state from nonlinear solver. Add a factory for control routine which takes in the assembler and subscribes a message for the solver. The finite elements should then inherit from an observer itself. @henrij22
  • It was recently discovered that somewhere in the code, either a copy of the assembler or the finite element container occurs and the current updateState function called by the nonlinear solvers updates the state variables of the "wrong" finite element container. This is apparently fixed by the broadcaster-listener design in [WIP] Observer Pattern for UpdateState #346. This also has to be merged first before this PR is merged.

@tarun-mitruka tarun-mitruka force-pushed the NonlinearEAS branch 2 times, most recently from b733c54 to a5ed1c9 Compare January 13, 2025 16:25
@@ -100,29 +113,24 @@ public:
* \tparam RT The type representing the requested result.
*/
template <template <typename, int, int> class RT>
requires(EnhancedAssumedStrains::template supportsResultType<RT>())
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is neccesary 1) gcc won't compile otherwise and 2) that the correct function is chosen (idk why but if that is not here, then the function in nonlinear "wins" and nans are returned)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is it due to the priority tags? For a similar reason, I added a default in feresulttypes.hh to get zeros instead of nans, which I think is removed now

Copy link
Collaborator

Choose a reason for hiding this comment

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

My comment was in constrast to just requires(supportsResultType<RT>())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New request to enhance existing features feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants