Octopus
box_union.F90
Go to the documentation of this file.
1!! Copyright (C) 2021 M. Oliveira
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_union_oct_m
22 use box_oct_m
23 use debug_oct_m
24 use global_oct_m
30 use unit_oct_m
31
32 implicit none
33
34 private
35 public :: &
37
39 type, extends(multibox_t) :: box_union_t
40 private
41 contains
42 procedure :: contains_points => box_union_contains_points
43 procedure :: write_info => box_union_write_info
44 procedure :: short_info => box_union_short_info
45 final :: box_union_finalize
46 end type box_union_t
47
48 interface box_union_t
49 procedure box_union_constructor
50 end interface box_union_t
51
52contains
53
54 !--------------------------------------------------------------
55 function box_union_constructor(dim) result(box)
56 integer, intent(in) :: dim
57 class(box_union_t), pointer :: box
58
59 push_sub(box_union_constructor)
60
61 ! Allocate memory
62 safe_allocate(box)
63 safe_allocate(box%bounding_box_l(1:dim))
64
65 ! Initialize box
66 box%dim = dim
67 box%bounding_box_l = m_zero
68
70 end function box_union_constructor
71
72 !--------------------------------------------------------------
73 subroutine box_union_finalize(this)
74 type(box_union_t), intent(inout) :: this
75
76 push_sub(box_union_finalize)
77
78 call multibox_end(this)
79
80 pop_sub(box_union_finalize)
81 end subroutine box_union_finalize
82
83 !--------------------------------------------------------------
84 recursive function box_union_contains_points(this, nn, xx, tol) result(contained)
85 class(box_union_t), intent(in) :: this
86 integer, intent(in) :: nn
87 real(real64), contiguous, intent(in) :: xx(:,:)
88 real(real64), optional, intent(in) :: tol
89 logical :: contained(nn)
90
91 integer :: ip
92 real(real64) :: point(1:this%dim)
93 type(box_iterator_t) :: iter
94 class(box_t), pointer :: box
95
96 ! A point must be inside at least one box to be considered inside an union of boxes
97 do ip = 1, nn
98 point(1:this%dim) = xx(ip, 1:this%dim)
99 contained(ip) = .false.
100
101 call iter%start(this%list)
102 do while (iter%has_next())
103 box => iter%get_next()
104 contained(ip) = box%contains_point(point, tol)
105 if (contained(ip)) exit
106 end do
107
108 contained(ip) = contained(ip) .neqv. this%is_inside_out()
109 end do
110
111 end function box_union_contains_points
112
113 !--------------------------------------------------------------
114 subroutine box_union_write_info(this, iunit, namespace)
115 class(box_union_t), intent(in) :: this
116 integer, optional, intent(in) :: iunit
117 type(namespace_t), optional, intent(in) :: namespace
118
119 push_sub(box_union_write_info)
120
121 ! Todo: need to decide how best to display the information of the boxes that make the union
122
123 pop_sub(box_union_write_info)
124 end subroutine box_union_write_info
125
126 !--------------------------------------------------------------
127 character(len=BOX_INFO_LEN) function box_union_short_info(this, unit_length) result(info)
128 class(box_union_t), intent(in) :: this
129 type(unit_t), intent(in) :: unit_length
130
131 push_sub(box_union_short_info)
133 ! Todo: need to decide how best to display the information of the boxes that make the union
134 info = ''
139end module box_union_oct_m
140
141!! Local Variables:
142!! mode: f90
143!! coding: utf-8
144!! End:
subroutine info()
Definition: em_resp.F90:1096
subroutine box_union_write_info(this, iunit, namespace)
Definition: box_union.F90:208
subroutine box_union_finalize(this)
Definition: box_union.F90:167
class(box_union_t) function, pointer box_union_constructor(dim)
Definition: box_union.F90:149
character(len=box_info_len) function box_union_short_info(this, unit_length)
Definition: box_union.F90:221
recursive logical function, dimension(nn) box_union_contains_points(this, nn, xx, tol)
Definition: box_union.F90:178
real(real64), parameter, public m_zero
Definition: global.F90:188
This module implements fully polymorphic linked lists, and some specializations thereof.
subroutine, public multibox_end(this)
Definition: multibox.F90:143
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:132
Class implementing a box that is an union other boxes.
Definition: box_union.F90:132
Abstract class for boxes that are made up of a list of boxes.
Definition: multibox.F90:131