ikarus-project / ikarus

Ikarus is a C++-based library that uses DUNE modules to solve partial differential equations with the finite element method and more.
https://ikarus-project.github.io/
Other
4 stars 2 forks source link

Add AssemblerManipulator to manipulate the assembled quantities #304

Open tarun-mitruka opened 3 weeks ago

tarun-mitruka commented 3 weeks ago

globalIndexFromGlobalPosition can be used along with fixIthDOF to fix Dirichlet DOFs at specific Lagrange nodes. AssemblerManipulator can be used to manipulate assembled quantities, for example to add point forces

Highlights: Introduced the function forEachLagrangeNodePosition that helps traversing over the local coordinates of an element and call a user-desired function. This can then be called via other helper functions like obtainLagrangeGlobalNodePositions to get the global coordinates or via globalIndexFromGlobalPosition to the global index at a given global position. For example,

Dune::FieldVector<double, 2> pos{2.0, 1.0};
const auto globalIndices = utils::globalIndexFromGlobalPosition(basis.flat(), pos);

These helper functions can be further be used with AssemblerManipulator to manipulate assembled quantities. For example, we can define the lambda functions

double springStiffness   = 596482;
double pointF            = 64.23;
auto doubleEnergy        = [&](const auto&, const auto&, auto, double& energyL) -> void { energyL *= 2.0; };
auto pointLoad           = [&](const auto&, const auto&, auto, auto, Eigen::VectorXd& vec) -> void {
        vec[globalIndices[0]] += pointF;
        vec[globalIndices[1]] += pointF;
};
auto addSpringStiffnessDense = [&](const auto&, const auto&, auto, auto, Eigen::MatrixXd& mat) -> void {
        mat.diagonal()[globalIndices[0]] += springStiffness;
        mat.diagonal()[globalIndices[1]] += springStiffness;
};

and bind it to the assemblers via

denseFlatAssembler.bind(doubleEnergy);
denseFlatAssembler.bind(doubleEnergy); // doubled twice
denseFlatAssembler.bind(pointLoad);
denseFlatAssembler.bind(addSpringStiffnessDense);

to manipulate the assembled quantities. Here, the scalar quantity mechanicalPotentialEnergy is doubled twice, point loads and additional spring stiffness are added for the DOFs at the given pos

Python bindings for these functionalities will be added soon.

codecov[bot] commented 3 weeks ago

Codecov Report

Attention: Patch coverage is 84.61538% with 16 lines in your changes missing coverage. Please review.

Project coverage is 91.37%. Comparing base (1f6d41c) to head (26463d8).

Files Patch % Lines
...us/assembler/assemblermanipulatorbuildingblocks.hh 77.27% 10 Missing :warning:
ikarus/assembler/assemblermanipulatorfuser.hh 90.00% 3 Missing :warning:
ikarus/assembler/simpleassemblers.inl 83.33% 3 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #304 +/- ## ========================================== + Coverage 91.24% 91.37% +0.13% ========================================== Files 63 64 +1 Lines 2055 2262 +207 ========================================== + Hits 1875 2067 +192 - Misses 180 195 +15 ``` | [Flag](https://app.codecov.io/gh/ikarus-project/ikarus/pull/304/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ikarus-project) | Coverage Δ | | |---|---|---| | [tests](https://app.codecov.io/gh/ikarus-project/ikarus/pull/304/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ikarus-project) | `91.37% <84.61%> (+0.13%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=ikarus-project#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.