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, tol) 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 real(real64), optional, intent(in) :: tol
81 logical :: contained(1:nn)
82 end function box_contains_points
83
85 function box_bounds(this, axes) result(bounds)
86 import :: box_t
87 import :: basis_vectors_t
88 import :: real64
89 class(box_t), intent(in) :: this
90 class(basis_vectors_t), optional, intent(in) :: axes
91 real(real64) :: bounds(2, this%dim)
92 end function box_bounds
93
95 subroutine box_write_info(this, iunit, namespace)
96 import :: box_t
97 import :: namespace_t
98 class(box_t), intent(in) :: this
99 integer, optional, intent(in) :: iunit
100 type(namespace_t), optional, intent(in) :: namespace
101 end subroutine box_write_info
102
104 function box_short_info(this, unit_length)
105 use unit_oct_m
106 import :: box_t
107 import :: box_info_len
108 class(box_t), intent(in) :: this
109 type(unit_t), intent(in) :: unit_length
110 character(len=BOX_INFO_LEN) :: box_short_info
111 end function box_short_info
112 end interface
113
115 type, extends(linked_list_t) :: box_list_t
116 private
117 contains
118 procedure :: add => box_list_add_node
119 end type box_list_t
120
121 type, extends(linked_list_iterator_t) :: box_iterator_t
122 private
123 contains
124 procedure :: get_next => box_iterator_get_next
125 end type box_iterator_t
126
127contains
128
129 !!--------------------------------------------------------------
131 subroutine box_turn_inside_out(this)
132 class(box_t), intent(inout) :: this
133
134 this%inside_out = .not. this%inside_out
135
136 end subroutine box_turn_inside_out
137
138 !!--------------------------------------------------------------
140 logical function box_is_inside_out(this)
141 class(box_t), intent(in) :: this
142
143 box_is_inside_out = this%inside_out
145 end function box_is_inside_out
146
147 !!---------------------------------------------------------------
150 recursive logical function box_contains_point(this, xx, tol) result(contained)
151 class(box_t), intent(in) :: this
152 real(real64), target, intent(in) :: xx(1:this%dim)
153 real(real64), optional, intent(in) :: tol
155 real(real64), pointer, contiguous :: xx_ptr(:,:)
156 logical :: points_contained(1)
158 xx_ptr(1:1, 1:this%dim) => xx(1:this%dim)
159 points_contained = this%contains_points(1, xx_ptr, tol)
160 contained = points_contained(1)
161
162 end function box_contains_point
164 !--------------------------------------------------------------
165 function box_get_surface_points(this, namespace, mesh_spacing, nn, xx, number_of_layers) result(surface_points)
166 class(box_t), intent(in) :: this
167 type(namespace_t), intent(in) :: namespace
168 real(real64), intent(in) :: mesh_spacing(:)
169 integer, intent(in) :: nn
170 real(real64), intent(in) :: xx(:,:)
171 integer, optional, intent(in) :: number_of_layers
172 logical :: surface_points(1:nn)
173
174 surface_points = .false.
175 call messages_not_implemented("get_surface_points for box shape")
176
177 end function box_get_surface_points
179 !--------------------------------------------------------------
180 subroutine box_get_surface_point_info(this, point_coordinates, mesh_spacing, normal_vector, surface_element)
181 class(box_t), intent(in) :: this
182 real(real64), intent(in) :: point_coordinates(:)
183 real(real64), intent(in) :: mesh_spacing(:)
184 real(real64), intent(out) :: normal_vector(:)
185 real(real64), intent(out) :: surface_element
186
189 call messages_not_implemented("get_surface_point_info for box shape")
190
192 end subroutine box_get_surface_point_info
193
194 ! ---------------------------------------------------------
195 subroutine box_list_add_node(this, box)
196 class(box_list_t) :: this
197 class(box_t), target :: box
198
199 select type (box)
200 class is (box_t)
201 call this%add_ptr(box)
202 class default
203 assert(.false.)
204 end select
205
206 end subroutine box_list_add_node
207
208 ! ---------------------------------------------------------
209 function box_iterator_get_next(this) result(box)
210 class(box_iterator_t), intent(inout) :: this
211 class(box_t), pointer :: box
212
213 select type (ptr => this%get_next_ptr())
214 class is (box_t)
215 box => ptr
216 class default
217 assert(.false.)
218 end select
219
220 end function box_iterator_get_next
221
222end module box_oct_m
223
224!! Local Variables:
225!! mode: f90
226!! coding: utf-8
227!! End:
Box bounds along some axes.
Definition: box.F90:178
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:197
Write the complete information about the box to a file.
Definition: box.F90:188
subroutine box_turn_inside_out(this)
Turn a box inside out.
Definition: box.F90:225
subroutine box_get_surface_point_info(this, point_coordinates, mesh_spacing, normal_vector, surface_element)
Definition: box.F90:274
recursive logical function box_contains_point(this, xx, tol)
Convenience function to check if a single point is inside the box when that point is passed as a rank...
Definition: box.F90:244
logical function, dimension(1:nn) box_get_surface_points(this, namespace, mesh_spacing, nn, xx, number_of_layers)
Definition: box.F90:259
class(box_t) function, pointer box_iterator_get_next(this)
Definition: box.F90:303
subroutine box_list_add_node(this, box)
Definition: box.F90:289
logical function box_is_inside_out(this)
Is the box inside out?
Definition: box.F90:234
This module implements fully polymorphic linked lists, and some specializations thereof.
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1113
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:208
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.