Forum Message

 

 

We have moved the forum to https://forum.ngsolve.org . This is an archived version of the topics until 05/05/23. All the topics were moved to the new forum and conversations can be continued there. This forum is just kept as legacy to not invalidate old links. If you want to continue a conversation just look for the topic in the new forum.

Notice

The forum is in read only mode.

Error with setting the boundary condition

  • omar
  • New Member
  • New Member
More
1 year 11 months ago #4378 by omar
I am trying to solve Poisson equation on a contraction step problem. I get an error to set dirichlet boundary condition at different boundaries.

Here is the part of the code:  
######################################################################################################

from ngsolve import *
from netgen.geom2d import SplineGeometry
import netgen.gui
import matplotlib.pyplot as plt
import netgen.geom2d  as  geom2d
import numpy as np
from netgen.meshing import Element0D, Element1D, Element2D, MeshPoint, FaceDescriptor, Mesh
from netgen.csg import Pnt
ngsglobals.msg_level =2

# %% Geometry generation  (points definition)
geo = geom2d.SplineGeometry()
p1 = geo.AppendPoint (0,0)
p2 = geo.AppendPoint (3,0)
p3 = geo.AppendPoint (3,0.1)
p4 = geo.AppendPoint (2,0.1)
p5 = geo.AppendPoint (2,1)
p6 = geo.AppendPoint (0,1)

# (Boundaries definition)
geo.Append (["line", p1, p2],bc=1)  # bottom 
geo.Append (["line", p2, p3],bc=2)  # outlet 
geo.Append (["line", p3, p4],bc=3)  # horizontal 
geo.Append (["line", p4, p5],bc=4)  # vertical 
geo.Append (["line", p5, p6],bc=5)  # top
geo.Append (["line", p6, p1],bc=6)  # Inlet 

fes = H1(mesh, order=2, dirichlet=[1,2])
########################################################################################

The error happens for the last line:

TypeError: __init__(): incompatible constructor arguments. The following argument types are supported:
    1. ngsolve.comp.H1(mesh: ngsolve.comp.Mesh, **kwargs)

Invoked with: <netgen.libngpy._meshing.Mesh object at 0x000002303900E530>; kwargs: order=2, dirichlet=[1, 2]



Thanks in advance  
 
More
1 year 11 months ago #4379 by mneunteufel
Hi omar, there are two types of Mesh object, one from NGSolve one from Netgen. Due to from netgen.meshing import Element0D, Element1D, Element2D, MeshPoint, FaceDescriptor, Mesh the Netgen mesh will be used, but you need the NGSolve mesh.Removing the import of the Netgen Mesh should fix it. Best,Michael
  • omar
  • New Member
  • New Member
More
1 year 11 months ago #4380 by omar
Unfortinately I still have the same error.

Here is my updated code:


from ngsolve import *
import matplotlib.pyplot as plt
import numpy as np
from netgen.geom2d import SplineGeometry
ngsglobals.msg_level =2


# %% Geometry generation (points definition)
geo = SplineGeometry()
p1 = geo.AppendPoint (0,0)
p2 = geo.AppendPoint (3,0)
p3 = geo.AppendPoint (3,0.1)
p4 = geo.AppendPoint (2,0.1)
p5 = geo.AppendPoint (2,1)
p6 = geo.AppendPoint (0,1)

geo.Append (["line", p1, p2],bc=1) # bottom
geo.Append (["line", p2, p3],bc=2) # outlet
geo.Append (["line", p3, p4],bc=3) # horizontal
geo.Append (["line", p4, p5],bc=4) # vertical
geo.Append (["line", p5, p6],bc=5) # top
geo.Append (["line", p6, p1],bc=6) # Inlet

mesh = geo.GenerateMesh (maxh=0.1)

fes = H1(mesh, order=2, dirichlet=[1,2])

###################################

And this is the error message:

__init__(): incompatible constructor arguments. The following argument types are supported:
1. ngsolve.comp.H1(mesh: ngsolve.comp.Mesh, **kwargs)

Invoked with: <netgen.libngpy._meshing.Mesh object at 0x000001722D060BF0>; kwargs: order=2, dirichlet=[1, 2
More
1 year 11 months ago #4394 by mneunteufel
The netgen mesh needs to be converted into the NGSolve mesh.

Replace
mesh = geo.GenerateMesh (maxh=0.1)
by
mesh = Mesh(geo.GenerateMesh (maxh=0.1))

Best,
Michael
The following user(s) said Thank You: omar
  • omar
  • New Member
  • New Member
More
1 year 11 months ago #4397 by omar
Thank you so mush

That solved the issue
Time to create page: 0.169 seconds