Skip to content

Files

Latest commit

 

History

History
82 lines (52 loc) · 5.69 KB

README.md

File metadata and controls

82 lines (52 loc) · 5.69 KB

Solving PDEs with Cartesian grids using Gridap without plugins

In this directory the solution of PDEs using Cartesian meshes is described. Cartesian mesh generation is included in Gridap.jl and therefore no extra plugin is required.

How to run scripts

Consider the script poisson.jl that solves the Poisson problem in a unit square using Gridap.jl. Before runing this case, Gridap has to be installed, which can be done instantiating the environment in this directory. The steps are as follows.

  • Enter into the 'NoPlugins' folder and open a Julia REPL. The options --project=. set the current directory as a local environment, equivalent to use activate in the pkg mode (see below).
$ cd NoPlugins
$ julia --project=.
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.11.1 (2024-10-16)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> 
  • Instantiate the environment. This will automatically download all required packages, Gridap.jl in this case. This is done in the pkg mode of the prompt. Learn about prompt modes if you need it.
# Type ] to enter in pkg mode
(NoPlugins) pkg> instantiate
  • Run the script. There are two options
  1. copy the contents of the file into the REPL
  2. include the contents using
# Use the backspace key to return to Julian mode
include("poisson.jl")
  • If you are using Visual Studio Code install the Julia extension. This extension includes an integrated REPL, which can be started from the Command Palette (in the View menu, also activated with the shorcut Ctrl-Shift-p) with the command Jula: start REPL. There are several options to run the code and to debug.

  • After execution the file results.vtu is generated to visualize using Paraview.

Defining loads

In the script poisson.jl, the load term is defined such that the exact solution of the problem is a given function. Feel free to experiment changing it with or without automatic differentiation, see commented code.

Defining boundary conditions

The imposition of boundary conditions is managed by assigning tags to geometric entities, i.e. points, lines and surfaces. These tags are used to identify individual geometric entities, or groups of them, which permit to perform operations like assignning values to the unknown or integrating to assign Neumann conditions.

Tags included in Cartesian models

The mesh geneartor is responsible for creating these tags. When Cartesian meshes are used, Gridap generates the model that already contains a set of tags, assigned to geometric entitites. The geometric entities of a Cartesian mesh in 2D are shown in the following figure.

Each vertex (1 to 4) and line (5 to 8) have assigned a tag whose name is "tag_i" where i is the entity number, e.g., vertex 1 is identified by "tag_1", and so on. The (only) face, entity 9, is identified by the tag "interior" and the last tag generated during model creation by CartesianDiscreteModel is "boundary" which includes entities 1 to 8.

The boundary conditions defined in the script poisson.jl are of Dirichlet type on the whole domain boundary. This is done in the definition of the test FE space and the value is defined when creating the trial FE space (it is given by the exact solution).

The 3D case is similar, with the following numbering of geometric entities.

Tags defined to group entities

It is possible to define new tags to identify parts of the boundary grouping entities. This is done in the script poisson_group_tags.jl at lines 22 to 24 where the tag "dirichlet_boundary" is defined to identify the left boundary of the domain and the tag "neumann_boundary" to identify the rest. Observe that vertices are not included in the latter because Neumann conditions are applied through integration (and points have zero measure).

Tags defined by functions of coordinates

It is finally possible to define new tags to identify small parts of the boundary using functions that consume the coordinates of the nodes and edges of the mesh. This requires the use of lower level functions of Gridap.jl and is illustrated in the script poisson_coord_tags.jl.

Some comments about the code:

  1. Note the use of internal modules of Gridap.jl at lines 2 to 4 that permit access to some lower level functions.
  2. The function is_dirichlet defines which part of the boundary is included in the Dirichlet boundary in terms of the coordinates. Feel free to change with it.
  3. This function is used at line 34 to select nodes of the mesh to include in the new tag "dirichlet_boundary", created at line 38.
  4. In the same way, edges of the mesh are processed in lines 40 to 46 to include them in the new tag "neumann_boundary", created at line 46.