Memory usage when allocating many H1 spaces on subdomains

Hi everyone,

I have a mesh with over a thousand domains and need to create an H1 space for each. Each space only uses a small sub-mesh, but I run out of memory during allocation, especially with MPI.

What in the allocation of a finite element space consumes significant memory? Any suggestions for handling many such localized spaces more efficiently?

Thanks!

A basic H1 space still reserves one dof per vertex as UNUSED_DOF (for coarse prolongations). you can remove that by Compress on the space:

fes = Compress(H1(mesh, definedon=...))

does this help?

Hi Chistopher,

Thank you for your prompt response. I have tried it already but it doesn’t help.

Cheers,
Vien Che

Hi Christopher,

I observed that when using

Compress()

the DOFs reduces without actually freeing memory.

I will check the memory again and let’s you know.

Cheers,
Vien Che

Can you post some minimal demo example that highlights the problem?

ngsolve_test.py (1.5 KB)
Hi Christopher,

Please find the minimal demo example in the attachment. Without Compress, it is even a bit more efficient.

Cheers,
Vien Che

DOFs 63210
DOFs compressed 54900

in this example most of the dofs are actually used in the space. Ah and your problem is the size of the space itself, not objects (bilinearform, gfs,…) built from it? Then compress doesn’t help you, yes. What are you using the spaces for? and why do you need so many of them?

If you want to solve problems on different subparts you can just build one space and solve using setting freedofs on subdomains:

something like

freedofs = fes.GetDofs(mesh.Materials("box_2")) * fes.FreeDofs()
gfu.vec.datra = a.mat.Inverse(freedofs) * f.vec

Hi Christopher,

I used the spaces to implement the Interface resisitivity with the Robin-like term on the interface

a += alpha * (ui-uo) * (vi-vo) * ds(“interface”)

And I have more than 2000 interfaces (“interface_1_2”, “interface_3_4” and so on).
Later, I also want to compute the solution difference at the interface as well. For example:

fesTMP = FacetFESpace(mesh, order=order, complex=True)
gf1 = GridFunction(fesTMP)
gf2 = GridFunction(fesTMP)
gfu = GridFunction(fes)
gfu_out, gfu_in = gfu.components
gfu_out.Set(1.0)
gfu_cell.Set(2.0)
gf1.Set(gfu_out, definedon=mesh.Boundaries(“interface”))
gf2.Set(gfu_cell, definedon=mesh.Boundaries(“interface”))
TMP = gf2 - gf1

Hi Vien,

if you have thousands of domains, you may try a graph colouring. Then you can use one H1 space per colour, defined on the union of subdomains of that colour.

Joachim

Hi Joachim,

Thank you for your response. I thought about it as well and successfully implemented it. I ran an example.

No. of Color classes: 8
No. of Domains: 52

It reduces from 52 to 8. I will test with more domains.

Best regards,
Vien Che