Octopus
stencil.F90
Go to the documentation of this file.
1!! Copyright (C) 2008 X. Andrade
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
41
42module stencil_oct_m
43 use debug_oct_m
44 use global_oct_m
47
48 implicit none
49
50 private
51 public :: &
52 stencil_t, &
58
60 ! Components are public by default
61 integer :: arms(1:3,1:3) = reshape([0,0,0,0,0,0,0,0,0], (/3, 3/))
62 integer :: narms = 0
63 end type stargeneral_arms_t
64
69
70 type stencil_t
71 ! Components are public by default
72 integer, private :: dim
73 integer :: center
74 ! !! A value of -1 indicates that the central point is not in the stencil.
75 integer :: size
76 integer, allocatable :: points(:, :)
77
78 ! The stargeneral arms
79 type(stargeneral_arms_t) :: stargeneral
80 end type stencil_t
81
82contains
83
84 !-------------------------------------------------------
85 subroutine stencil_allocate(this, dim, size)
86 type(stencil_t), intent(inout) :: this
87 integer, intent(in) :: dim
88 integer, intent(in) :: size
89
90 push_sub(stencil_allocate)
91
92 this%dim = dim
93 this%size = size
94
95 safe_allocate(this%points(1:this%dim, 1:size))
96
97 this%points = 0
98
99 pop_sub(stencil_allocate)
100 end subroutine stencil_allocate
101
102 !-------------------------------------------------------
103 subroutine stencil_copy(input, output)
104 type(stencil_t), intent(in) :: input
105 type(stencil_t), intent(out) :: output
106
107 push_sub(stencil_copy)
108
109 call stencil_allocate(output, input%dim, input%size)
110 output%points = input%points
111 output%center = input%center
112
113 output%stargeneral%narms = input%stargeneral%narms
114 output%stargeneral%arms = input%stargeneral%arms
115
116 pop_sub(stencil_copy)
117 end subroutine stencil_copy
118
119
120 !-------------------------------------------------------
121 subroutine stencil_end(this)
122 type(stencil_t), intent(inout) :: this
123
124 push_sub(stencil_end)
125
126 safe_deallocate_a(this%points)
127
128 pop_sub(stencil_end)
129 end subroutine stencil_end
130
131
132 !-------------------------------------------------------
133 subroutine stencil_union(st1, st2, stu)
134 type(stencil_t), intent(in) :: st1
135 type(stencil_t), intent(in) :: st2
136 type(stencil_t), intent(inout) :: stu
138 integer :: ii, jj, nstu
139 logical :: not_in_st1
140
141 push_sub(stencil_union)
142
143 assert(st1%dim == st2%dim)
144
145 call stencil_allocate(stu, st1%dim, st1%size + st2%size)
146
147 ! copy the first stencil
148 do ii = 1, st1%size
149 stu%points(:, ii) = st1%points(:, ii)
150 end do
151
152 nstu = st1%size
153
154 do ii = 1, st2%size
155
156 not_in_st1 = .true.
158 ! check whether that point was already in the stencil
159 do jj = 1, nstu
160 if (all(stu%points(:, jj) == st2%points(:, ii))) then
161 not_in_st1 = .false.
162 exit
163 end if
164 end do
166 if (not_in_st1) then !add it
167 nstu = nstu + 1
168 stu%points(:, nstu) = st2%points(:, ii)
169 end if
171 end do
172
173 stu%size = nstu
175 call stencil_init_center(stu)
176
177 pop_sub(stencil_union)
178 end subroutine stencil_union
179
181 !-------------------------------------------------------
186 subroutine stencil_init_center(this)
187 type(stencil_t), intent(inout) :: this
188
189 integer :: ii
190
191 push_sub(stencil_init_center)
192
193 this%center = -1
194
195 do ii = 1, this%size
196 if (all(this%points(:, ii) == 0)) this%center = ii
197 end do
199 pop_sub(stencil_init_center)
200 end subroutine stencil_init_center
201
202end module stencil_oct_m
203
204!! Local Variables:
205!! mode: f90
206!! coding: utf-8
207!! End:
This module defines stencils used in Octopus.
Definition: stencil.F90:137
subroutine, public stencil_end(this)
Definition: stencil.F90:217
subroutine, public stencil_union(st1, st2, stu)
Definition: stencil.F90:229
subroutine, public stencil_copy(input, output)
Definition: stencil.F90:199
subroutine, public stencil_allocate(this, dim, size)
Definition: stencil.F90:181
subroutine, public stencil_init_center(this)
set the index of the central point of the stencil
Definition: stencil.F90:282
The class representing the stencil, which is used for non-local mesh operations.
Definition: stencil.F90:165
int true(void)