How to compose a region using a gfu (or cf)?

More
4 years 7 months ago - 4 years 7 months ago #2583 by creativeworker
Hello,

I don't understand how i could compose a ngsolve.comp.Region using a given gfu (or cf). Using that region i'd like to separate two groups of dofs (using the definedon=region).

Here the concrete goal:
- sort every dof of fes into a second fes where the gfu value is higher than tol. All the other dofs should go into a third fes.

Perhaps its easy and I just didn't go the correct way of solving the problem.
Thanks for your help!
Last edit: 4 years 7 months ago by creativeworker.
More
4 years 7 months ago #2584 by mneunteufel
Hi creativeworker,

you can use a BitArray to sort dofs. This works only for lowest order H1 elements where every dof is associated with the vertex value.

For example
Code:
fes = H1(mesh, order=1) gfu = GridFunction(fes) gfu.Set(x*y+2*y) limit = 1.5 dofs = BitArray(fes.ndof) dofs[:] = False for i in range(fes.ndof): if gfu.vec[i] > limit: dofs[i] = True
saves all dofs where gfu is greater than 1.5.

Defining a second space which lives only on these dofs can be done only with
Code:
fes2 = H1(mesh, order=1, dirichlet="left|top|bottom|right") for i in range(fes.ndof): if dofs[i] == False: fes2.SetCouplingType(i,COUPLING_TYPE.UNUSED_DOF) fes2 = Compress(fes2)

Best,
Michael

File Attachment:

File Name: sortdof_20...-22-2.py
File Size:1 KB
More
4 years 7 months ago #2585 by schruste
Hi,

Short addition. Compress has an argument "active_dofs" exactly for replacing the last loop:
Code:
fes2 = H1(mesh, order=1, dirichlet="left|top|bottom|right") fes2 = Compress(fes2, active_dofs=dofs)

Best,
Christoph
The following user(s) said Thank You: creativeworker
More
4 years 7 months ago #2586 by creativeworker
Thank you very much. The Compress function helps me also in another place!
More
4 years 7 months ago - 4 years 7 months ago #2587 by creativeworker
May i ask two further things on that topic:

Is there a possibility to find the boundary dofs of such a bit mask? Or to define a region with the bit mask and find the boundary dofs there?

Secondly, is there a chance to bring this idea to HCurl space?
Last edit: 4 years 7 months ago by creativeworker.
More
4 years 7 months ago #2591 by mneunteufel
Hi creativeworker,

you can get the dofs of a boundary as a BitArray with
Code:
fes.GetDofs(mesh.Boundaries("left"))
which then can be combined with other BitArrays, see attached file.

Best
Michael

File Attachment:

File Name: sortdof_bnd.py
File Size:0 KB
Attachments:
Time to create page: 0.129 seconds