Menu

Imposing boundary flags in 3D

2016-11-20
2016-11-20
  • Sander Rhebergen

    Hello,
    I am new to using ngsolve/ngs-py and struggling a little to impose boundary conditions in 3D. I took the 2D ng-spy navierstokes.py demo and want to extend this to 3D. I created a geo file describing a brick and give number to the different planes:

    algebraic3d

    solid wall_t = plane (0, 0, 0; 0, 0, -1) -bc=3000;
    solid wall_b = plane (0, 0, 0; 0, -1, 0) -bc=3000;
    solid inflow = plane (0, 0, 0; -1, 0, 0) -bc=1000;

    solid wall_f = plane (3, 0.5, 0.5; 0, 0, 1) -bc=3000;
    solid wall_ba = plane (3, 0.5, 0.5; 0, 1, 0) -bc=3000;
    solid outflow = plane (3, 0.5, 0.5; 1, 0, 0) -bc=2000;

    solid rec = inflow and outflow and wall_t and wall_b and wall_f and wall_ba;

    tlo rec -maxh=0.08;

    I then create the grid using netgen which then gives me a brick.vol.gz. When I open this file I indeed see the bc imposed on the different planes. I now load this into navierstokes.py and create my velocity space:

    mesh = Mesh("brick.vol.gz")
    V = H1(mesh,order=2,dirichlet=[1000])

    I then want to impose u[0]=2 on boundary with label 1000, which I do as follows:

    uin = CoefficientFunction(2.0)
    u.components[0].Set(uin, definedon=mesh.Boundaries("1000"))

    However, when I run my code, I just get zero everywhere. Does anyone know what I am doing wrong here?
    (Eventually, I would like to impose different bcs on the different planes).

    Thanks,
    Sander

     
  • Joachim Schoeberl

    Hi Sander,

    welcome to NGS-Py !

    You can use either 1-based numbers, or labels (= strings) for bound markers. The recommendation are strings, what are C++11 regex. You use them with:

    solid wall_t = plane (0, 0, 0; 0, 0, -1) -bc="bottom"

    with

    print ("boundary labels: ", mesh.Boundaries())

    you see whether everything went ok.

    Best, Joachim

     
  • Sander Rhebergen

    Hi Joachim,

    Thanks for the response. So I did as you suggested. In my brick.geo file I wrote

    solid wall_t = plane (0, 0, 0; 0, 0, -1) -bc="wall"

    This gave me an error though:

    Load CSG geometry file brick.geo
    caught error Parsing error in line 3:
    token ';' expected

    Problem with input file:
    Parsing error in line 3:
    token ';' expected

    So I changed this to:

    solid wall_t = plane (0, 0, 0; 0, 0, -1) -bc=wall;

    (I had to remove the double quotation mark)

    I added the line

    print ("boundary labels: ", mesh.Boundaries())

    to the navierstokes.py file after I read the mesh, but then get the error

    Import expr.py
    (should) load python file 'navierstokes.py'
    Traceback (most recent call last):
    File "<string>", line 12, in <module>
    TypeError: Boundaries(): incompatible function arguments. The following argument types are supported:
    1. (self: ngsolve.comp.Mesh, pattern: str) -> ngsolve.comp.Region

    Invoked with: <ngsolve.comp.Mesh object="" at="" 0x7fe84d16d518="">
    Finished executing navierstokes.py

    Also, if I just open the brick.vol.gz file, I don't see the labels anywhere. Did I misunderstand something?

    thanks,
    Sander

     
  • Joachim Schoeberl

    Hi Sanders,

    I was to quick:
    in the .geo file you have to write -bcname="label"
    You can also model the csg-geometry within python, see the cmagnet.py example.

    and it is mesh.GetBoundaries() to get the list of labels.

    Joachim

     
  • Sander Rhebergen

    Hi Joachim,
    I think that seems to work now, thanks!
    Sander

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.