Error with setting the boundary condition
- omar
-
Topic Author
- New Member
-
Less
More
2 years 3 months ago #4378
by omar
Error with setting the boundary condition was created 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
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
- mneunteufel
-
- Offline
- Premium Member
-
Less
More
- Thank you received: 59
2 years 3 months ago #4379
by mneunteufel
Replied by mneunteufel on topic Error with setting the boundary condition
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
-
Topic Author
- New Member
-
Less
More
2 years 3 months ago #4380
by omar
Replied by omar on topic Error with setting the boundary condition
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
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
- mneunteufel
-
- Offline
- Premium Member
-
Less
More
- Thank you received: 59
2 years 3 months ago #4394
by mneunteufel
Replied by mneunteufel on topic Error with setting the boundary condition
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
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
-
Topic Author
- New Member
-
Less
More
2 years 3 months ago #4397
by omar
Replied by omar on topic Error with setting the boundary condition
Thank you so mush
That solved the issue
That solved the issue
Time to create page: 0.108 seconds