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) result(contained)
86 class(box_union_t), intent(in) :: this
87 integer, intent(in) :: nn
88 real(real64), contiguous, intent(in) :: xx(:,:)
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)
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)
132
133 ! Todo: need to decide how best to display the information of the boxes that make the union
134 info = ''
135
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: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:221
recursive logical function, dimension(nn) box_union_contains_points(this, nn, xx)
Definition: box_union.F90:179
real(real64), parameter, public m_zero
Definition: global.F90:187
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