Tutorial on 3D geometries

Dear all,

Does anybody know about any tutorial/examples in 3D problems?
I am especially interested in learning how to impose the boundary conditions when the problem is 3D.

Thanks in advance!

I have made a tutorial for DOLFINx, which includes 3D problems such as: Hyperelasticity — FEniCSx tutorial
and
Using the GMSH Python API to generate complex meshes | Jørgen S. Dokken
If you are interested in old dolfin, the documentation features some 3D examples as well:
https://fenicsproject.org/olddocs/dolfin/latest/python/demos/hyperelasticity/demo_hyperelasticity.py.html

There is no fundamental difference between enforcing boundary conditions on a 2D or 3D geometry in DOLFIN/DOLFINx

1 Like

That’s great. Thank you very much for the speedy response!

Hi there,

@dokken yet old dolfin can make geometries per the tutorial ? I’ve tried to make a simple 3D domain, though no success so far.

import dolfinx
box = Box(0, 0, 0, 9, 9, 3)
g3d = box
info(g3d, True)
print(g3d, ‘3D geometry’)

it gets “name Box is not defined”, so no such key words are available for dolfinx that were valid for dolfin?

Thanks,

First of all, by not using a wildcard import (from somemodule import *) you need to call somemodule.Mesh to access the Mesh class from that module.

Secondly, the api in DOLFINx is quite different than DOLFIN. See:
https://docs.fenicsproject.org/dolfinx/v0.5.1/python/demos.html#demos
and
https://jsdokken.com/dolfinx-tutorial/
for an introduction to the new API

Many thanks.

msh = mesh.create_rectangle(
comm = MPI.COMM_WORLD,
points = ((0,0), (2,1)),
n = (31, 16),
cell_type = mesh.CellType.triangle,)

When I want to plot(msh), then it gets object is not callable.
Is this because under WSL there is no apt to show it up?

Thanks,

As you have not supplied what script you are running, (i.e. where you have gotten the plot command from), I cannot really help you. For WSL plotting issues see for instance: Problem about pyvista - #2 by dokken

from dolfinx import fem, io, mesh, plot
from mpi4py import MPI

import numpy as np

msh = mesh.create_rectangle(comm = MPI.COMM_WORLD,
points = ((0,0), (2,1)),
n = (31, 16),
cell_type = mesh.CellType.triangle,)
plot(msh)

I saw that some users get the pictures with no X-server help, even under WSL, which seems to be convenient, I’m recalling all things about to set up X-server under WSL, and it’s some sort of magic.

Do you mean there should be no plot command there above?

Thanks,

Please read the tutorials, as they show you how to plot meshes and functions.

Dr. @dokken many thanks, yes, reviewed the tutorial and came up with the following:

msh = mesh.create_box (comm = MPI.COMM_WORLD,
points = ((0,0,0), (9,9,3),
n = (36,36,18),
cell_type = mesh.CellType.tetrahedron,)

with io.XDMFFile (msh.comm, ‘text.xdmf’, ‘w’) as file:
file.write_mesh(msh)

this way I get the file in home directory of Ubuntu 22.04.1 LTS under WSL (Windows 10), while having ParaView on Windows 10, and there I can see the file.

Also one more question - what if I would do some manipulations with the box, for instance, to make some series of holes there, then how can I do so ?

Thanks,

You should use external software for such, for instance the gmsh python api, as used in the tutorials
https://jsdokken.com/dolfinx-tutorial/chapter2/ns_code2.html#mesh-generation
or

@dokken many thanks. As I wrote above, I got the simplest domain - need to upload the picture to visualize my words hereto. For my task this would be a channel where compressible gas flows (one inlet boundary and four outlet boundaries); when I see my domain, my understanding – the entire volume is the domain where I want to simulate compressible gas, and the only thing - is to formulate inlet boundary and outlet boundaries, they might be circle form, for instance.


Should be it done prior to in the channel geometry stage - for instance, by making a circle shaped hole on the surface and then applying sufficient boundary conditions afterwards?

or perhaps I can formulate such boundary conditions on this channel (already consisting of n amount of tetrahedrons)? and no need to make holes at the geometry stage?

Thanks,

You should probably resolve the inlets and outlets in the mesh/geometry creation, as the boundaries between inlet/outlet and walls will not be smooth otherwise.

@dokken many thanks. I thought that outlets / inlets could be determined via nodes of those finite elements that are belong to corresponding boundary (outlets / inlets) ? And probably what you mentioned above - is to determine those regions at the geometry (to explicitly specify those regions) or at mesh stage (when again to determine required nodes)? Thanks,

You could do that, but it will not be a smooth representation of the inlet/outlet.

You can look at this in 2D by trying to mark a circle on a unit square mesh.
See for instance Plotting subdomains/internal boundaries - #2 by dokken
or
https://github.com/FEniCS/dolfinx/blob/main/python/demo/demo_pyvista.py#L95
or
Defining subdomains for different materials — FEniCSx tutorial

@dokken thanks a lot. One more thing needs your attention:

import gmsh
gmsh.initialize()
channel = gmsh.model.occ.addBox(0,0,0,9,3,3)
inlet = gmsh.model.occ.addCircle(1.5,1.5,0,0.75)
domain = gmsh.model.occ.cut( [ (3, channel) ], [ (2, inlet) ] )
gmsh.model.occ.synchronize()
gmsh.write(‘domain.msh’)

It gets Unknown OpenCASCADE entity of dimension 2 with tag 13
It looks like I formulated Circle in wrong way, though the idea was to create a channel, then to make inlet (Circle shaped only in plane meaning gdim = 2).

Please advise what’s wrong. Thanks,

You do not want to cut out the circle, you want it to be meshed as part of the boundary. Probably you need to use the fragment command. See for instance Mesh, Submesh , Torus, Boundary - #5 by dokken
or
https://bthierry.pages.math.cnrs.fr/tutorial/gmsh/occ/basics/#boolean-operations-cad-like-a-boss-_
or the Gmsh documentation.

I don’t want to cut out the circle, I want it to be meshed in a special way (as a boundary) :wink: though would you provide me more, let me say, explicit guide ? Thanks,