# Assemble finite element matrix without varf

**URL:** <https://community.freefem.org/t/assemble-finite-element-matrix-without-varf/82>\
**Category:** General Discussion\
**Created:** [June 25, 2019, 11:46am UTC](https://community.freefem.org/t/assemble-finite-element-matrix-without-varf/82 "2019-06-25T11:46:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandre](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@Alexandre](https://community.freefem.org/u/Alexandre)\
**Post date:** [June 25, 2019, 11:46am UTC](https://community.freefem.org/t/assemble-finite-element-matrix-without-varf/82/1 "2019-06-25T11:46:11Z")

</div>

Dear all,

I am trying to assemble a finite element matrix with “custom” local submatrices.  
The pseudo-code is the following:

```
// For each element
for (int i=0;i<Th.nt;i++){
	// Calculate elemental submatrix
	m_e = ...;

	// Global Assembly
	Assemble(M, m_e, i);
}

```

My question is then the following: What is the function “Assemble” (in the pseudocode)?

I am sure that this function is already present in the source code, but I can’t find it. And also, can I call it in a user script?

Thank you in advance for your help.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [June 25, 2019, 11:59am UTC](https://community.freefem.org/t/assemble-finite-element-matrix-without-varf/82/2 "2019-06-25T11:59:38Z")

</div>

Yes this function existe but this fonction is not interface in the language.

Question why you need to do this …

---

<div class="post-metadata">

**Author:** ![Alexandre](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@Alexandre](https://community.freefem.org/u/Alexandre)\
**Post date:** [June 25, 2019, 12:57pm UTC](https://community.freefem.org/t/assemble-finite-element-matrix-without-varf/82/3 "2019-06-25T12:57:06Z")

</div>

I am trying to implement an upwind scheme based on the residual (or fluctuation) splitting method. The details of the method can be found in this article by H. Deconinck, “Multidimensional upwind schemes based on fluctuation-splitting for systems of conservation laws” (1993).

The main idea is to improve the contribution of the nodes upwind the gradient of a certain quantity.  
In order to do that, I calculate an average “advection” speed over the element and calculate the coefficients k\_i which are one half of the scalar product of the average advection speed and n\_i.  
Where n\_i are the inward normal vector to the face opposed to the node i. Then, depending on the coefficients k\_i, I can choose how to improve the contribution of the nodes upwind the flow.

Depending on the method used for this last step, the resulting scheme is a Low Diffusion A Scheme, a N-scheme or a PSI-scheme.

Maybe these schemes are very close to the upwind method already implemented in Freefem and I can try to use this one.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [June 28, 2019, 8:37am UTC](https://community.freefem.org/t/assemble-finite-element-matrix-without-varf/82/4 "2019-06-28T08:37:00Z")

</div>

You have in plugin example c++ code [https://github.com/FreeFem/FreeFem-sources/blob/master/plugin/seq/mat\_psi.cpp](https://github.com/FreeFem/FreeFem-sources/blob/master/plugin/seq/mat_psi.cpp) very close to you problem.
