# Macro ThN2O for mixed vectorial and scalar finite element space

**URL:** <https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731>\
**Category:** General Discussion\
**Created:** [May 10, 2022, 9:55pm UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731 "2022-05-10T21:55:44Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![stergopilot](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@stergopilot](https://community.freefem.org/u/stergopilot)\
**Post date:** [April 12, 2024, 8:33am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/21 "2024-04-12T08:33:47Z")

</div>

OK.  
[example.edp](https://community.freefem.org/uploads/short-url/aCDsDuELBvvudfy29TJEtvokN9c.edp) (3.0 KB)

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 12, 2024, 8:34am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/22 "2024-04-12T08:34:36Z")

</div>

Why are you removing the brackets?

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 12, 2024, 8:35am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/23 "2024-04-12T08:35:43Z")

</div>

Why are you commenting lines 95 and 96? Why are you _still_ defining `A` and `B` inside the brackets?

---

<div class="post-metadata">

**Author:** ![stergopilot](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@stergopilot](https://community.freefem.org/u/stergopilot)\
**Post date:** [April 12, 2024, 8:47am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/24 "2024-04-12T08:47:01Z")

</div>

It seems like that I need to uncomment lines 95 and 96.  
[example.edp](https://community.freefem.org/uploads/short-url/mYrQj7ZHusI1ALkouqv506zj1NY.edp) (3.0 KB)  
But I need to find a solution to avoid the duplicate definition of

> macro def(i)[i, i#B, i#C]//  
> macro init(i)[i, i, i]//

to avoid errors

> Compile error : The macro already exists, sorry

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 12, 2024, 8:51am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/25 "2024-04-12T08:51:06Z")

</div>

Again, why did you remove the brackets?

---

<div class="post-metadata">

**Author:** ![stergopilot](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@stergopilot](https://community.freefem.org/u/stergopilot)\
**Post date:** [April 12, 2024, 9:02am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/26 "2024-04-12T09:02:14Z")

</div>

If I keep the brackets, A is invisible in the for loop.  
[example.edp](https://community.freefem.org/uploads/short-url/8U1QivmamTlvqXk7mx2ddsO1nJL.edp) (3.0 KB)

> 106 : u1=A The Identifier A does not exist  
> Error line number 106, in file example.edp, before token A

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 12, 2024, 9:03am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/27 "2024-04-12T09:03:48Z")

</div>

Yes, now, back to square one: [Macro ThN2O for mixed vectorial and scalar finite element space - #12 by prj](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/12)  
Do not declare `A` and `B` inside the brackets, but leave all the rest the same.

---

<div class="post-metadata">

**Author:** ![stergopilot](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@stergopilot](https://community.freefem.org/u/stergopilot)\
**Post date:** [April 12, 2024, 9:09am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/28 "2024-04-12T09:09:59Z")

</div>

Then I obtained `The macro already exists` error again.  
[example\_new.edp](https://community.freefem.org/uploads/short-url/ohh5aIw6TIt86jKyexNaW1kXEBD.edp) (3.4 KB)

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 12, 2024, 9:18am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/29 "2024-04-12T09:18:07Z")

</div>

OK, I ask you to move `A` and `B` definitions outside of the brackets and leave the rest of the code the same, but you insist on modifying the rest of the code (by removing the brackets). Why?

---

<div class="post-metadata">

**Author:** ![stergopilot](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@stergopilot](https://community.freefem.org/u/stergopilot)\
**Post date:** [April 12, 2024, 9:54am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/30 "2024-04-12T09:54:51Z")

</div>

Now it runs without errors with the following revision.

> Mat A;  
> {  
> macro def(i)[i, i#B, i#C, i#D, i#E, i#F, i#G]//  
> macro init(i)[i, i, i, i, i, i, i]//  
> createMat(Th,A,Pk)  
> set(A, sparams = “-pc\_type lu”);  
> A = vSt(Wh, Wh);  
> }  
> Mat B;  
> {  
> macro def(i)[i, i#B, i#C]//  
> macro init(i)[i, i, i]//  
> createMat(Th,B,Ps)  
> set(B, sparams = “-pc\_type lu”);  
> }

Another question is that whether I include the `A = vSt(Wh, Wh);` in the brackets.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [April 12, 2024, 10:10am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/31 "2024-04-12T10:10:13Z")

</div>

You can leave it in the brackets or not, it does not really matters. What matters is that you leave the `macro` definitions _inside_ the brackets, and the `Mat` definitions _outside_ the brackets.

---

<div class="post-metadata">

**Author:** ![stergopilot](https://avatars.discourse-cdn.com/v4/letter/s/e36b37/32.png) [@stergopilot](https://community.freefem.org/u/stergopilot)\
**Post date:** [April 12, 2024, 10:24am UTC](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731/32 "2024-04-12T10:24:52Z")

</div>

I see. Thank you so much!

[Previous page](https://community.freefem.org/t/macro-thn2o-for-mixed-vectorial-and-scalar-finite-element-space/1731.md?page=1)
