Skip to content

Enable integrating a function of fields - #1401

Draft
jijn wants to merge 4 commits into
prisms-center:masterfrom
jijn:galvanostatic
Draft

jijn wants to merge 4 commits into
prisms-center:masterfrom
jijn:galvanostatic

Conversation

@jijn

@jijn jijn commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Currently we can only integrate a field, say u
$$\displaystyle \int_V u(x) ~dV$$

Here I provide function integrate_function to integrate any function of scalar fields
$$\displaystyle \int_V f(u_1(x),u_2(x),\cdots,u_n(x)) ~dV$$

For example, one field:
$$\displaystyle \int_V f(u(x)) ~dV$$

number I = Integrator<dim, degree, number>::integrate_function(
  solve_context.get_dof_manager().get_field_dof_handler(0),
  [](const number u_q) -> number {
    return std::exp(u_q);
  },
  solve_context.get_solution_indexer().get_solution_vector(0)
);

Two fields:
$$\displaystyle \int_V f(u(x),v(x)) ~dV$$

number I = Integrator<dim, degree, number>::integrate_function(
  dof_handler,
  [](const number u_q, const number v_q) -> number {
    return u_q * v_q;
  },
  solve_context.get_solution_indexer().get_solution_vector(0),
  solve_context.get_solution_indexer().get_solution_vector(1)
);

And more fields...

You can pass a scalar to the function, for example

number I = Integrator<dim, degree, number>::integrate_function(
  dof_handler,
  [V](const number mu_q) -> number {
    return 2.0*std::sinh(0.5*(mu_q + V));
  },
  solve_context.get_solution_indexer().get_solution_vector(0) // mu
);

You can define the function as lambda expression, traditional function, ....
We could, in principle, implement this function for any number of fields, but I think the current one should cover most use cases. This is done using variadic templates.
This PR prepares to implement galvanostatic conditions (Beck's approach).

Comment thread include/prismspf/utilities/integrator.h
*/
template <int rank>
static dealii::Vector<number>
integrate(const dealii::DoFHandler<dim> &dof_handler, const auto &solution_vector)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason why the auto is here @fractalsbyx ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no

Comment thread include/prismspf/utilities/integrator.h Outdated
Comment thread include/prismspf/utilities/integrator.h Outdated

This branch has not been deployed

No deployments
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.

3 participants