Octopus
box.F90
Go to the documentation of this file.
1!! Copyright (C) 2021 M. Oliveira, K. Lively, A. Obzhirov, I. Albar
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
21module box_oct_m
23 use debug_oct_m
24 use global_oct_m
25 use, intrinsic :: iso_fortran_env
29
30 implicit none
31
32 private
33 public :: &
34 box_t, &
35 box_list_t, &
37
38 integer, parameter, public :: BOX_INFO_LEN=200
39 real(real64), parameter, public :: BOX_BOUNDARY_DELTA = 1e-12_real64
40
48 type, abstract :: box_t
49 private
50 integer, public :: dim
51 logical :: inside_out = .false.
52 real(real64), allocatable, public :: bounding_box_l(:)
55 contains
56 procedure(box_contains_points), deferred :: contains_points
57 procedure(box_bounds), deferred :: bounds
58 procedure(box_write_info), deferred :: write_info
59 procedure(box_short_info), deferred :: short_info
60 procedure :: get_surface_points => box_get_surface_points
61 procedure :: get_surface_point_info => box_get_surface_point_info
62 procedure, non_overridable :: contains_point => box_contains_point
63 procedure, non_overridable :: is_inside_out => box_is_inside_out
64 procedure, non_overridable :: turn_inside_out => box_turn_inside_out
65 end type box_t
66
67 abstract interface
68
70 recursive function box_contains_points(this, nn, xx) result(contained)
71 import :: box_t
72 import :: real64
73 class(box_t), intent(in) :: this
74 integer, intent(in) :: nn
75 real(real64), contiguous, intent(in) :: xx(:,:)
80 logical :: contained(1:nn)
81 end function box_contains_points
82
84 function box_bounds(this, axes) result(bounds)
85 import :: box_t
86 import :: basis_vectors_t
87 import :: real64
88 class(box_t), intent(in) :: this
89 class(basis_vectors_t), optional, intent(in) :: axes
90 real(real64) :: bounds(2, this%dim)
91 end function box_bounds
92
94 subroutine box_write_info(this, iunit, namespace)
95 import :: box_t
96 import :: namespace_t
97 class(box_t), intent(in) :: this
98 integer, optional, intent(in) :: iunit
99 type(namespace_t), optional, intent(in) :: namespace
100 end subroutine box_write_info
101
103 function box_short_info(this, unit_length)
104 use unit_oct_m
105 import :: box_t
106 import :: box_info_len
107 class(box_t), intent(in) :: this
108 type(unit_t), intent(in) :: unit_length
109 character(len=BOX_INFO_LEN) :: box_short_info
110 end function box_short_info
111 end interface
112
114 type, extends(linked_list_t) :: box_list_t
115 private
116 contains
117 procedure :: add => box_list_add_node
118 end type box_list_t
119
120 type, extends(linked_list_iterator_t) :: box_iterator_t
121 private
122 contains
123 procedure :: get_next => box_iterator_get_next
124 end type box_iterator_t
125
126contains
127
128 !!--------------------------------------------------------------
130 subroutine box_turn_inside_out(this)
131 class(box_t), intent(inout) :: this
133 this%inside_out = .not. this%inside_out
134
135 end subroutine box_turn_inside_out
136
137 !!--------------------------------------------------------------
139 logical function box_is_inside_out(this)
140 class(box_t), intent(in) :: this
142 box_is_inside_out = this%inside_out
144 end function box_is_inside_out
146 !!---------------------------------------------------------------
149 recursive logical function box_contains_point(this, xx) result(contained)
150 class(box_t), intent(in) :: this
151 real(real64), target, intent(in) :: xx(1:this%dim)
153 real(real64), pointer, contiguous :: xx_ptr(:,:)
154 logical :: points_contained(1)
156 xx_ptr(1:1, 1:this%dim) => xx(1:this%dim)
157 points_contained = this%contains_points(1, xx_ptr)
158 contained = points_contained(1)
159
160 end function box_contains_point
161
162 !--------------------------------------------------------------
163 function box_get_surface_points(this, namespace, mesh_spacing, nn, xx, number_of_layers) result(surface_points)
164 class(box_t), intent(in) :: this
165 type(namespace_t), intent(in) :: namespace
166 real(real64), intent(in) :: mesh_spacing(:)
167 integer, intent(in) :: nn
168 real(real64), intent(in) :: xx(:,:)
169 integer, optional, intent(in) :: number_of_layers
170 logical :: surface_points(1:nn)
171
172 surface_points = .false.
173 call messages_not_implemented("get_surface_points for box shape")
174
175 end function box_get_surface_points
176
177 !--------------------------------------------------------------
178 subroutine box_get_surface_point_info(this, point_coordinates, mesh_spacing, normal_vector, surface_element)
179 class(box_t), intent(in) :: this
180 real(real64), intent(in) :: point_coordinates(:)
181 real(real64), intent(in) :: mesh_spacing(:)
182 real(real64), intent(out) :: normal_vector(:)
183 real(real64), intent(out) :: surface_element
184
186
187 call messages_not_implemented("get_surface_point_info for box shape")
188
190 end subroutine box_get_surface_point_info
191
192 ! ---------------------------------------------------------
193 subroutine box_list_add_node(this, box)
194 class(box_list_t) :: this
195 class(box_t), target :: box
197 select type (box)
198 class is (box_t)
199 call this%add_ptr(box)
200 class default
201 assert(.false.)
202 end select
203
204 end subroutine box_list_add_node
205
206 ! ---------------------------------------------------------
207 function box_iterator_get_next(this) result(box)
208 class(box_iterator_t), intent(inout) :: this
209 class(box_t), pointer :: box
211 select type (ptr => this%get_next_ptr())
212 class is (box_t)
213 box => ptr
214 class default
215 assert(.false.)
216 end select
217
218 end function box_iterator_get_next
219
220end module box_oct_m
221
222!! Local Variables:
223!! mode: f90
224!! coding: utf-8
225!! End:
Box bounds along some axes.
Definition: box.F90:177
Given a list of points, this function should return an array indicating for each point if it is insid...
Definition: box.F90:163
Return a string containing a short description of the box.
Definition: box.F90:196
Write the complete information about the box to a file.
Definition: box.F90:187
subroutine box_turn_inside_out(this)
Turn a box inside out.
Definition: box.F90:224
subroutine box_get_surface_point_info(this, point_coordinates, mesh_spacing, normal_vector, surface_element)
Definition: box.F90:272
logical function, dimension(1:nn) box_get_surface_points(this, namespace, mesh_spacing, nn, xx, number_of_layers)
Definition: box.F90:257
recursive logical function box_contains_point(this, xx)
Convenience function to check if a single point is inside the box when that point is passed as a rank...
Definition: box.F90:243
class(box_t) function, pointer box_iterator_get_next(this)
Definition: box.F90:301
subroutine box_list_add_node(this, box)
Definition: box.F90:287
logical function box_is_inside_out(this)
Is the box inside out?
Definition: box.F90:233
This module implements fully polymorphic linked lists, and some specializations thereof.
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1125
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:132
Vectors defining a basis in a vector space. This class provides methods to convert vector coordinates...
These classes extends the list and list iterator to create a box list.
Definition: box.F90:207
class to tell whether a point is inside or outside
Definition: box.F90:141
This class implements an iterator for the polymorphic linked list.
This class implements a linked list of unlimited polymorphic values.