Periodic boundary conditions (unknown equivalent)

I am new to NGSolve.

The analysis domain of my problem is two spheres.
I want to impose periodic boundary conditions (unknown equivalent edge element)
to both of the surfaces of the sphere.
I mean the values of those two domains are equal but unknnowns.

Does NGSolve have that feature?

I checked some of the Q&A’s in this forum, but I could not see the similarity to my question although they might be related.

Yes you can do this. Identify the faces of both spheres and generate a periodic mesh (as you would do in other periodic cases, I think there are examples for this) and then use the Periodic fespace-wrapper in the same way.

I reffered the following example,
PeriodicSpace example

The ”Rectangle Example” seems to be working, however, no pair appears with the ”Sphere Example".
I have tested with Identifiy pairs of the faces, but none of them worked out.

Rectangle Example

from ngsolve import *
from netgen.occ import *
from ngsolve.webgui import Draw

shape = Rectangle(1,1).Face()

shape.edges.Max(X).name = "right"
shape.edges.Min(X).name = "left"
shape.edges.Max(Y).name = "top"
shape.edges.Min(Y).name = "bot"

shape.edges.Max(Y).Identify(shape.edges.Min(Y), "bt")
shape.edges.Max(X).Identify(shape.edges.Min(X), "lr")

mesh = Mesh(OCCGeometry(shape, dim=2).GenerateMesh(maxh=0.1))
Draw(mesh, settings={"Objects": {"Edges": False, "Surface": True}}); 

for pair in mesh.ngmesh.GetIdentifications():
    print([mesh.vertices[pair[0]-1].point, mesh.vertices[pair[1]-1].point])

Sphere Example

from ngsolve import *
from netgen.occ import *
from ngsolve.webgui import Draw

sph1 = Sphere(Pnt(0,0,0.0), r=1)
sph2 = Sphere(Pnt(0,0,2.5), r=1)
sph = sph1+sph2

sph.edges[0].name = "e0"
sph.edges[1].name = "e1"
sph.edges[2].name = "e2"
sph.edges[3].name = "e3"

sph.faces[0].Identify(sph.faces[1],"ud0")
#sph.edges[0].Identify(sph.edges[1],"ud0")
#sph.edges[2].Identify(sph.edges[3],"ud1")
#sph.edges[4].Identify(sph.edges[5],"ud2")
#sph.edges[6].Identify(sph.edges[7],"ud3")

mesh = Mesh(OCCGeometry(sph).GenerateMesh(maxh=0.5)).Curve(2)
Draw(mesh, settings={"camera": {"transformations": [{"type": "rotateX", "angle": -90},{"type": "rotateZ", "angle": 90}]}, "Objects": {"Edges": False, "Surface": True}}, clipping={ "x" : 0.1, "y" : 0, "z" : 0, "dist":0, "function":True}); 

for pair in mesh.ngmesh.GetIdentifications():
    print([mesh.vertices[pair[0]-1].point, mesh.vertices[pair[1]-1].point])```

I tried the following example with CSG, but no pairs are generated with Sphere Example and only the bottom surfaces have the periodicity with Brick Example.

Sphere Example

from ngsolve import *
from netgen.csg import *
from ngsolve.webgui import Draw
geo = CSGeometry()
sph1 = Sphere(Pnt(0.0,0.0, 1.1), 1.0)
sph2 = Sphere(Pnt(0.0,0.0,-1.1), 1.0)
geo.Add(sph1+sph2)
geo.PeriodicSurfaces(sph1, sph2)
mesh = Mesh(geo.GenerateMesh (maxh=0.2)).Curve(1)
Draw(mesh)
for pair in mesh.ngmesh.GetIdentifications():
    print([mesh.vertices[pair[0]-1].point, mesh.vertices[pair[1]-1].point])

Brick Example

from ngsolve import *
from netgen.csg import *
from ngsolve.webgui import Draw
geo = CSGeometry()
br1 = OrthoBrick(Pnt(-1,-1,-3),Pnt(1,1,-1)).bc("outer1")
br2 = OrthoBrick(Pnt(-1,-1, 1),Pnt(1,1, 3)).bc("outer2")
geo.Add(br1+br2)
geo.PeriodicSurfaces(br1, br2)
mesh = Mesh(geo.GenerateMesh (maxh=0.2)).Curve(1)
Draw(mesh)
for pair in mesh.ngmesh.GetIdentifications():
    print([mesh.vertices[pair[0]-1].point, mesh.vertices[pair[1]-1].point])

There was a bug in the occ periodic identification for this case. It is fixed on master now and

ph.faces[0].Identify(sph.faces[1],"ud0", IdentificationType.PERIODIC)

should work

I am using NGsolve on Jupyter Hub.
It still says,
NgException: Meshing failed!

from ngsolve import *
from netgen.occ import *
from ngsolve.webgui import Draw

sph1 = Sphere(Pnt(0,0,0.0), r=1)
sph2 = Sphere(Pnt(0,0,2.), r=1)
sph = sph1+sph2
sph.faces[0].Identify(sph.faces[1], "ud0",  IdentificationType.PERIODIC)
mesh = Mesh(OCCGeometry(sph, dim=3).GenerateMesh(maxh=0.5)).Curve(2)