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