# Sparsity pattern of Hdiv mass matrix

Hi all,

at the moment i try to familiarize myself with the implementation of the HDiv basis functions.
I took a look at the sparsity pattern of the mass matrix by

``````mesh = Mesh(unit_square.GenerateMesh(maxh=0.2))
fes = HDiv(mesh, order=25, dirichlet="top|bottom|right|left")
u = fes.TrialFunction()
v = fes.TestFunction()
SetTestoutFile ("test.out")
a = BilinearForm(fes,printelmat=True)
a += u*v*dx
#And so on..``````

and then importing it into matlab.

It looks for the most parts as expected, but there are some dense blocks at both ends of the matrix (far away from machine precision, i.e. 10^-6). Where do these blocks come from?

Best
Tim

Hi Tim,

you can compute and process element-matrices directly within Python, without going over the testout file:

``````from netgen.geom2d import unit_square
from ngsolve import *

mesh = Mesh(unit_square.GenerateMesh(maxh=2))

fes = HDiv(mesh, order=5)
u,v = fes.TnT()

a = BilinearForm(fes)
a += u*v*dx

igt = a.integrators

ei = ElementId(0)
el = fes.GetFE(ei)
trafo = mesh.GetTrafo(ei)

mat = igt.CalcElementMatrix(el, trafo)
print (mat)

import scipy.linalg
ev,evec = scipy.linalg.eigh(a=mat) ``````

You have to look into the H(div) basis functions, in the file fem/hdivhofe_impl.hpp, starting line 89:

We are using something like Dubiner, multiplied by RT0 functions. This gives us exactly the RT space.

We could use a construction like the Dubiner, but with different Jacobi weights to improve non-zero entries. If it improves conditioning (after diagonal scaling) it is another good argument to change.

The last block should better be a scaled Legendre, maybe this is what you have observed.

Joachim

Hi Joachim,

thanks for the tipp.

I forgot the attachment in the previous post. It’s not just one block, but some dense columns and rows. Is that the scaled Legendre? Looks kinda weird.

(There are no such blocks for example in Beuchler, Pillwein Zaglmayer (2010))

Tim

Attachment: SparsityPattern.pdf
{"ft_lang_label":"__label__en","ft_lang_prob":0.80618215,"math_prob":0.9453977,"size":2382,"snap":"2023-40-2023-50","text_gpt3_token_len":621,"char_repetition_ratio":0.076534905,"word_repetition_ratio":0.0,"special_character_ratio":0.23551637,"punctuation_ratio":0.14225942,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.98917633,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-09-24T13:15:57Z\",\"WARC-Record-ID\":\"<urn:uuid:4453083f-06e9-4fc7-a35d-1606858b16ca>\",\"Content-Length\":\"22888\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:62aedb84-d475-4fec-b59c-559158405226>\",\"WARC-Concurrent-To\":\"<urn:uuid:bbe20aa7-e948-4d7e-bb3e-d68bd0f028e5>\",\"WARC-IP-Address\":\"188.34.187.168\",\"WARC-Target-URI\":\"https://forum.ngsolve.org/t/sparsity-pattern-of-hdiv-mass-matrix/1580\",\"WARC-Payload-Digest\":\"sha1:D3W7HAXY6BXSR2YD2BCFF5SZDXVRHC3Z\",\"WARC-Block-Digest\":\"sha1:YFDBQESJCHJ4JUYOBBOREVTI5OFKUTIH\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-40/CC-MAIN-2023-40_segments_1695233506646.94_warc_CC-MAIN-20230924123403-20230924153403-00501.warc.gz\"}"}