Dirichlet boundary condition in gmsh

Hi all, I want to define dirichlet boundary condition in my mesh file in gmsh and then use it in julia (not defining bc in julia just read them from mesh file). is there anyone who had experience in this field or any tutorials to help me?
thank you

You mark the desired boundaries in Gmsh with a tag, e.g. "DirichletEdges", and then use that to specify the boundary condition in Gridap. See e.g. this example.

2 Likes

thank you. i read this but as you can see they only read tags and it seem that the value of boundary conditions are in mesh file. it is declared in source tag and also periodic boundary conditions. they have mentioned that
“Note that this mesh file already contains periodic boundary information for the left and right side, and that is enough for gridap to realize a periodic boundary condition should be implemented.”

i know how to add physical groups in gmsh but i dont know how to implement value on it for example a displacement on line in mesh file not in gridap.

Periodic boundary conditions are different. As far as Gridap is concerned, there is no boundary condition — in fact, there is no boundary. The mesh simply lives on a torus.

2 Likes

Hello, I am just learning how to use Gridap, but maybe this will answer your question:

To deal with non-homogeneous Dirichlet boundary conditions using GMSH and Gridap in Julia, you can assign physical groups to the desired borders. These tags are used later by Gridap when creating the trial functions.

First, when you create the mesh in Gmsh, assign tags to the boundaries like this:

# Define tags for the boundaries using Gmsh interface in Julia
gmsh.model.addPhysicalGroup(1, [1]) 
gmsh.model.setPhysicalName(1, 1, "bottom")

gmsh.model.addPhysicalGroup(1, [3])
gmsh.model.setPhysicalName(1, 3, "top")

In my example, I created a rectangle where top and bottom borders have nonhomogenous Dirichlet boundary conditions. This .msh file was imported using GridapGmsh.

using Gridap
using GridapGmsh
using GridapMakie, GLMakie
using FileIO

# Step 1: Load the GMSH mesh
mesh_file = "simple_mesh_with_borders.msh"

# Create a DiscreteModel from the GMSH mesh file
model = GmshDiscreteModel(mesh_file)
writevtk(model,"model")

# Step 2: Set up a finite element space for H^1 functions
order = 2 
reffe = ReferenceFE(lagrangian,Float64,order)
V = TestFESpace(
    model,
    reffe;conformity=:H1,
    dirichlet_tags = ["top", "bottom"] 
    )

# Step 3: Define the weak form for the Laplace equation
Ω = Triangulation(model)
dΩ = Measure(Ω,2*order)
# Bilinear form for Laplace operator
a(u, v) = ∫( ∇(v) ⋅ ∇(u) )dΩ
# Right-hand side (homogeneous)
l(v) = ∫( 0.0 * v )dΩ

# Weak form : ∫∇u ⋅ ∇v = ∫f * v
println("Number of cells in Ω: ", num_cells(Ω));

# Step 4: Define the Dirichlet boundary condition values in a verctor
top(x)=1.0
bottom(x)=2.0
U = TrialFESpace(V, [top, bottom])

# Step 5: Solve the system
op = AffineFEOperator(a, l, U, V)
ls = LUSolver()
solver = LinearFESolver(ls)
println("Solving PDE");
uh = solve(solver,op)

# Step 6: Write the solution to a VTK file
println("Writing solutiion to a Paraview vtk file");
writevtk(Ω, "solution", cellfields = ["uh" => uh])


# Step 7: Plot the solution in Julia (optional)

# Plot the values
println("Plotting in Julia");

fig = plot(Ω)
wireframe!(Ω, color=:black, linewidth=2)
scatter!(Ω, marker=:star8, markersize=20, color=:blue)
save("2d_Fig1.png", fig)

fig, _ , plt = plot(Ω, uh)
Colorbar(fig[1,2], plt)
save("2d_Fig2.png", fig)
1 Like