Choral
quadMesh_integral.f90
Go to the documentation of this file.
1 
18 
20 
21  use choral
23 
24  implicit none
25 
26  !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27  !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28  !!
29  !! VARAIBLE DEFINITION : BEGIN
30  !!
31  !!
32 
33  !! verb = verbosity level
34  !!
35  integer, parameter :: verb = 2
36 
37  !! msh_file = mesh file name
38  !! msh = mesh
39  !! qdm = integration method on the mesh
40  !!
41  character(len=150) :: msh_file
42  type(mesh) :: msh
43  type(quadmesh) :: qdm
44 
45  !! integral result
46  real(RP) :: int
47 
48  !!
49  !! VARAIBLE DEFINITION : END
50  !!
51  !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
52  !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
53 
54  call choral_init(verb=verb)
55 
56  write(*,*)
57  write(*,*)'quadMesh_integral: start'
58  write(*,*)""
59  write(*,*)" INTEGRAL COMPITATION ON A MESH OF [0,1]x[0,1]"
60  write(*,*)" - \Omega = [0,1]x[0,1] "
61  write(*,*)" - \Gamma = \partial \Omega \cap {x=1} "
62  write(*,*)" - \Gamma_r = \Gamma \cap {x=1} "
63  write(*,*)""
64 
65  !!
66  !! mesh file
67  !!
68  msh_file = trim(gmsh_dir)//"square/square_3.msh"
69 
70 
71  write(*,*) ""
72  write(*,*)"================================== ASSEMBLING THE MESH "
73  msh = mesh(trim(msh_file), "gmsh")
74  if (verb>1) call print(msh)
75 
76  write(*,*) ""
77  write(*,*)"================================== INTEGRAL 1"
78  write(*,*)"= "
79  write(*,*)"= integration domain = \Omega "
80  write(*,*)"= "
81  !!
82  !! link 'qdm' to the mesh 'msh'
83  !!
84  qdm = quadmesh(msh)
85  !!
86  !! set all triangle cells to the
87  !! 6 point Gaussian quadrature rule on triangles
88  !!
89  call set(qdm, quad_gauss_trg_6)
90  !!
91  !! ends up the construction and display a short description
92  !!
93  call assemble(qdm)
94  if (verb>1) call print(qdm)
95  !!
96  !! integral computation
97  !!
98  int = integ(func, qdm)
99  print*, " COMPUTED INTEGRAL = ", int
100  print*, " NUMERICAL ERROR = ", &
101  & abs(int - 2._rp/3._rp)
102 
103 
104 
105  write(*,*) ""
106  write(*,*)"================================== INTEGRAL 2"
107  write(*,*)"= "
108  write(*,*)"= integration domain = \Gamma "
109  write(*,*)"= "
110  !!
111  !! re-initialise 'qdm'
112  !!
113  qdm = quadmesh(msh)
114  !!
115  !! set all edge cells to the
116  !! 3 point Gaussian quadrature rule on edges
117  !!
118  call set(qdm, quad_gauss_edg_3)
119  !!
120  !! ends up the construction and display a short description
121  !!
122  call assemble(qdm)
123  if (verb>1) call print(qdm)
124  !!
125  !! integral computation
126  !!
127  int = integ(func, qdm)
128  print*, " COMPUTED INTEGRAL = ", int
129  print*, " NUMERICAL ERROR = ", &
130  & abs(int - 10._rp/3._rp)
131 
132 
133  write(*,*) ""
134  write(*,*)"================================== INTEGRAL 3"
135  write(*,*)"= "
136  write(*,*)"= integration domain = \Gamma_r = \Gamma \ cap {x >= 1} "
137  write(*,*)"= "
138  !!
139  !! re-initialise 'qdm'
140  !!
141  qdm = quadmesh(msh)
142  !!
143  !! set all edge cells where ' x >= 1' to the
144  !! 3 point Gaussian quadrature rule on edges
145  !!
146  call set(qdm, quad_gauss_edg_3, x_ge_1)
147  !!
148  !! ends up the construction and display a short description
149  !!
150  call assemble(qdm)
151  if (verb>1) call print(qdm)
152  !!
153  !! integral computation
154  !!
155  int = integ(func, qdm)
156  print*, " COMPUTED INTEGRAL = ", int
157  print*, " NUMERICAL ERROR = ", &
158  & abs(int - 4._rp/3._rp)
159 
160 
161  write(*,*) ""
162  write(*,*)"================================== INTEGRAL 4"
163  write(*,*)"= "
164  write(*,*)"= integration domain = \Gamma_r \cup \Omega "
165  write(*,*)"= (composite integration domain)"
166  write(*,*)"= "
167  !!
168  !! re-initialise 'qdm'
169  !!
170  qdm = quadmesh(msh)
171  !!
172  !! set all edge cells where ' x >= 1' to the
173  !! 3 point Gaussian quadrature rule on edges
174  !!
175  call set(qdm, quad_gauss_edg_3, x_ge_1)
176  !!
177  !! set all triangle cells to the
178  !! 6 point Gaussian quadrature rule on triangles
179  !!
180  call set(qdm, quad_gauss_trg_6)
181  !!
182  !! ends up the construction and display a short description
183  !!
184  call assemble(qdm)
185  if (verb>1) call print(qdm)
186  !!
187  !! integral computation
188  !!
189  int = integ(func, qdm)
190  print*, " COMPUTED INTEGRAL =", int
191  print*, " NUMERICAL ERROR = ", &
192  & abs(int - 2._rp)
193 
194 
195 
196 contains
197 
198  !! The function to be integrated
199  !!
200  function func(x)
201  real(RP) :: func
202  real(RP), dimension(3), intent(in) :: x
203 
204  func = x(1)**2 + x(2)**2
205 
206  end function func
207 
210  function x_ge_1(x) result(r)
211  real(RP) :: r
212  real(RP), dimension(3), intent(in) :: x
213 
214  r = x(1) - 1.0_rp
215 
216  end function x_ge_1
217 
218 
219 end program quadmesh_integral
real(rp) function x_ge_1(x)
To characterise {x=1}.
subroutine, public choral_init(verb)
Initialisation for the CHORAL library
Definition: choral.F90:166
TOP-LEVEL MODULE FOR THE LIBRARY CHORAL
Definition: choral.F90:27
real(rp) function func(x)
integer, parameter quad_gauss_edg_3
CHORAL CONSTANTS
integer, parameter quad_gauss_trg_6
program quadmesh_integral
Integration methods on meshes quadMesh: