# Different spaces for different variables

**URL:** <https://community.freefem.org/t/different-spaces-for-different-variables/3321>\
**Category:** General Discussion\
**Created:** [June 19, 2024, 1:25am UTC](https://community.freefem.org/t/different-spaces-for-different-variables/3321 "2024-06-19T01:25:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luanusp](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@Luanusp](https://community.freefem.org/u/Luanusp)\
**Post date:** [June 19, 2024, 1:25am UTC](https://community.freefem.org/t/different-spaces-for-different-variables/3321/1 "2024-06-19T01:25:58Z")

</div>

Dear, i’m a beginner to this program and I was trying to implement a problem linked to the 1D heat equation. According to the author, I need to use P1 to approximate the time variable and P3 for the space variable. However, when I define fespace I cannot indicate this information.

For example, if I write fespace Vh(QT, P1); Vh u, v, I understand that in both variables the approximation is being done by P1.

---

<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:** [June 19, 2024, 10:20am UTC](https://community.freefem.org/t/different-spaces-for-different-variables/3321/2 "2024-06-19T10:20:43Z")

</div>

You can separate the spaces and variables, as

```auto
fespace Vh(QT,P1);
fespace Wh(QT,P2);
Vh u;
Wh v,b;

```

In this case u is P1, v and b are in P2

---

<div class="post-metadata">

**Author:** ![Luanusp](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@Luanusp](https://community.freefem.org/u/Luanusp)\
**Post date:** [June 19, 2024, 1:02pm UTC](https://community.freefem.org/t/different-spaces-for-different-variables/3321/3 "2024-06-19T13:02:38Z")

</div>

I’m trying to get the solution for the following problem:

problem heateq(u, v, solver = Cholesky)  
= int2d(QT)( (A1 \* u + A2 \* dy(u) + A3 \* dx(u) + A4 \* dxx(u)) \* (A1 \* v + A2 \* dy(v) + A3 \* dx(v) + A4 \* dxx(v)))  
+ int2d(QT)((.5 - t)^(2 \* alpha) \* u \* v \* ((x \>= .3) \* (x \<= .6))\*one)  
- int1d(QT, 1)((.5^alpha) \* t0 \* rho0 \* v);

The author mentions that he used polynomials of the type P(K) = (P3,x ⊗ P1,t)(K).

However, if I write as you suggested, I understand that I would have to define two “u”, however, I don’t know how to adapt the problem, if this is the correct idea,

---

<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:** [June 19, 2024, 1:07pm UTC](https://community.freefem.org/t/different-spaces-for-different-variables/3321/4 "2024-06-19T13:07:46Z")

</div>

Probably you have only two variables t (real) and x (real 1d).

I think that you should understand the statement “P(K) = (P3,x ⊗ P1,t)(K)” by  
u(t,x)=\frac{t^{n+1}-t}{t^{n+1}-t^n}u^n(x)+\frac{t-t^n}{t^{n+1}-t^n}u^{n+1}(x), for t^n\<t\<t^{n+1}  
Then you need only to resolve u^n(x) for n=0,1... and x in an interval. Thus it is a 1d problem, and known u^n(x) you need to solve a 1d equation to get u^{n+1}(x) that needs to be P3.

---

<div class="post-metadata">

**Author:** ![Luanusp](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@Luanusp](https://community.freefem.org/u/Luanusp)\
**Post date:** [June 19, 2024, 1:38pm UTC](https://community.freefem.org/t/different-spaces-for-different-variables/3321/5 "2024-06-19T13:38:42Z")

</div>

Interesting. If I follow this suggestion, how should I consider the terms “dy(u)” and “dy(v)”, since these terms I used to indicate the derivative at t?

---

<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:** [June 19, 2024, 1:41pm UTC](https://community.freefem.org/t/different-spaces-for-different-variables/3321/6 "2024-06-19T13:41:31Z")

</div>

You replace the time derivative by a finite difference  
\frac{du}{dt}\simeq \frac{u^{n+1}-u^n}{dt}  
This is coherent with the above approximation of u(t,x).  
If your equation is A\_1u+A\_2\partial\_t u+A\_3\partial\_x u-A\_4\partial^2\_{xx}u=0, you should set

```auto
problem heateq(u,v)=
  int1d(Q)((A1*u+A2*u/dt+A3*dx(u))*v+A4*dx(u)*dx(v))
 -int1d(Q)(A2*uold/dt*v)
;

```

Here `u` stands for u^{n+1} and `uold` stands for u^n.

---

<div class="post-metadata">

**Author:** ![Luanusp](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@Luanusp](https://community.freefem.org/u/Luanusp)\
**Post date:** [June 19, 2024, 1:46pm UTC](https://community.freefem.org/t/different-spaces-for-different-variables/3321/7 "2024-06-19T13:46:32Z")

</div>

The problem I am solving is fourth order in space and second order in time. This problem is related to the null controllability property of the heat equation. I’m not directly solving the heat equation.

---

<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:** [June 19, 2024, 2:12pm UTC](https://community.freefem.org/t/different-spaces-for-different-variables/3321/8 "2024-06-19T14:12:55Z")

</div>

Ok then for second-order in time you need two unknowns u and z, and set \frac{u^{n+1}-u^n}{dt}=z^{n+1}, \frac{z^{n+1}-z^n}{dt}=...

---

<div class="post-metadata">

**Author:** ![Luanusp](https://avatars.discourse-cdn.com/v4/letter/l/e19b73/32.png) [@Luanusp](https://community.freefem.org/u/Luanusp)\
**Post date:** [June 19, 2024, 2:15pm UTC](https://community.freefem.org/t/different-spaces-for-different-variables/3321/9 "2024-06-19T14:15:11Z")

</div>

Thank you very much. I will apply the suggestions.

---

<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:** [June 19, 2024, 2:21pm UTC](https://community.freefem.org/t/different-spaces-for-different-variables/3321/10 "2024-06-19T14:21:57Z")

</div>

Or, if it is more adapted to your problem  
A\_1u^{n+1}+A\_2\frac{u^{n+1}-u^n}{dt}+A\_3\partial\_x u^{n+1}+A\_4\partial^2\_{xx}u^{n+1}=z^{n+1},  
A\_1z^{n+1}+A\_2\frac{z^{n+1}-z^n}{dt}+A\_3\partial\_x z^{n+1}+A\_4\partial^2\_{xx}z^{n+1}=0,
