Ask Your Question

Revision history [back]

Consider the definition

phi = M.scalar_field(function('phi')(*coord), name='phi')

There are three layers here:

  • phi itself,
  • inside it is the expression function('phi')(*coord),
  • and inside that is the function function('phi').

If you want to call substitute_function on an expression, you should pass two functions.

To access the function inside phi you need to peel off the layers: phi.expr().operator().

So, you can do what you want as follows:

E[0,0].expr().substitute_function(phi.expr().operator(), F1.expr().operator())

You can also assign the function inside phi to a variable (before defining phi), so you can use that instead.

Consider the definition

phi = M.scalar_field(function('phi')(*coord), name='phi')

There are three layers here:

  • the scalar field phi itself,
  • inside it is the expression function('phi')(*coord),
  • and inside that is the function function('phi').

If you want to call substitute_function on an expression, you should pass two functions.

To access the function inside phi you need to peel off the layers: phi.expr().operator().

So, you can do what you want as follows:

E[0,0].expr().substitute_function(phi.expr().operator(), F1.expr().operator())

You can also assign the function inside phi to a variable (before defining phi), so you can use that instead.