# Split Function/Accessing components

**URL:** <https://community.freefem.org/t/split-function-accessing-components/4124>\
**Category:** General Discussion\
**Created:** [November 4, 2025, 10:59pm UTC](https://community.freefem.org/t/split-function-accessing-components/4124 "2025-11-04T22:59:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gart1542](https://avatars.discourse-cdn.com/v4/letter/g/c89c15/32.png) [@gart1542](https://community.freefem.org/u/gart1542)\
**Post date:** [November 4, 2025, 10:59pm UTC](https://community.freefem.org/t/split-function-accessing-components/4124/1 "2025-11-04T22:59:15Z")

</div>

Hi all,

I am working on a code to solve the Cahn-Hilliard equation, and I am having trouble trying to split the solution function u into its phi and mu components for updating the Newton loop.

I have the mesh and functions declared as this:

> // Mesh and function space
> 
> int h = 64;
> 
> mesh Th = square(h, h);
> 
> fespace Vh(Th, P1);
> 
> fespace ME = Vh\*Vh;
> 
> // Define functions
> 
> Vh c, c0, dc, dmu;
> 
> Vh psi, v;

And the inside of the Newton loop as this:

> // Assemble
> 
> ```auto
> matrix A = Lhs(ME, ME);
> 
> real[int] b = Rhs(0, ME);
> 
> real[int] sol = A^-1 * b;
> 
> dc[] = sol(0:Vh.ndof - 1);
> 
> dmu[] = sol(Vh.ndof:2*Vh.ndof - 1);
> 
> c[] -= dc[];
> 
> mu[] -= dmu[];
> 
> ```

I have also tried:

> //Extract solution blocks: ucur = [dmu; dc]
> 
> int nd = Vh.ndof;
> 
> for (int i=0; i\<nd; ++i) dmu[i] = ucur[i];
> 
> for (int i=0; i\<nd; ++i) dc[i] = ucur[nd+i];
> 
> c = c - dc;
> 
> mu = mu - dmu;

However, something seems to go wrong with the updates in subsequent Newton Iterations. Particularly, c (phi) does not appear to be updating at all. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [November 5, 2025, 6:15pm UTC](https://community.freefem.org/t/split-function-accessing-components/4124/2 "2025-11-05T18:15:31Z")

</div>

To get the correct components you have to declare an unknown in the space ME

```auto
ME [csol,musol];
csol[]=sol;// csol[] represents all the components of the solution [csol,musol]
dc=csol;
dmu=musol;

```
