Octopus
box_user_defined.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!! Copyright (C) 2021 M. Oliveira, K. Lively, A. Obzhirov, I. Albar
3!!
4!! This program is free software; you can redistribute it and/or modify
5!! it under the terms of the GNU General Public License as published by
6!! the Free Software Foundation; either version 2, or (at your option)
7!! any later version.
8!!
9!! This program is distributed in the hope that it will be useful,
10!! but WITHOUT ANY WARRANTY; without even the implied warranty of
11!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12!! GNU General Public License for more details.
13!!
14!! You should have received a copy of the GNU General Public License
15!! along with this program; if not, write to the Free Software
16!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17!! 02110-1301, USA.
18!!
19
20#include "global.h"
21
23 use box_oct_m
26 use debug_oct_m
27 use global_oct_m
30 use parser_oct_m
32 use string_oct_m
33 use unit_oct_m
34
35 implicit none
36
37 private
38 public :: box_user_defined_t
39
45 type, extends(box_shape_t) :: box_user_defined_t
46 private
47 type(box_parallelepiped_t), pointer :: outer_box
48 character(len=1024) :: expression
49 contains
50 procedure :: shape_contains_points => box_user_defined_shape_contains_points
51 procedure :: write_info => box_user_defined_write_info
52 procedure :: short_info => box_user_defined_short_info
54 end type box_user_defined_t
55
56 interface box_user_defined_t
57 procedure box_user_defined_constructor
58 end interface box_user_defined_t
59
60contains
61
62 !--------------------------------------------------------------
63 function box_user_defined_constructor(dim, center, axes, expression, length, namespace) result(box)
64 integer, intent(in) :: dim
65 real(real64), intent(in) :: center(dim)
66 real(real64), intent(in) :: axes(dim, dim)
67 character(len=1024), intent(in) :: expression
68 real(real64), intent(in) :: length(dim)
69 type(namespace_t), intent(in) :: namespace
70 class(box_user_defined_t), pointer :: box
71
73
74 ! Allocate memory
75 safe_allocate(box)
76
77 ! Initialize box
78 call box_shape_init(box, namespace, dim, center, bounding_box_min=-m_half*length, bounding_box_max=m_half*length, axes=axes)
79 box%expression = expression
80 call conv_to_c_string(box%expression)
81 box%outer_box => box_parallelepiped_t(dim, center, axes, length, namespace)
82
83 box%bounding_box_l = m_half*length + abs(center)
84
87
88 !--------------------------------------------------------------
89 subroutine box_user_defined_finalize(this)
90 type(box_user_defined_t), intent(inout) :: this
91
93
94 call box_shape_end(this)
95 safe_deallocate_p(this%outer_box)
96
98 end subroutine box_user_defined_finalize
99
100 !--------------------------------------------------------------
101 function box_user_defined_shape_contains_points(this, nn, xx) result(contained)
102 class(box_user_defined_t), intent(in) :: this
103 integer, intent(in) :: nn
104 real(real64), contiguous, intent(in) :: xx(:,:)
105 logical :: contained(1:nn)
106
107 integer :: ip
108 real(real64) :: re, im, rr, xx_centered(this%dim)
109
110 contained = this%outer_box%contains_points(nn, xx)
111
112 do ip = 1, nn
113 if (.not. contained(ip)) then
114 ! Skip points that are outside the outer box
115 cycle
116 end if
117
118 xx_centered = xx(ip, :) - this%center
119 rr = norm2(xx_centered)
120 call parse_expression(re, im, this%dim, xx_centered, rr, m_zero, this%expression)
121 contained(ip) = abs(re) > m_epsilon .neqv. this%is_inside_out()
122 end do
123
125
126 !--------------------------------------------------------------
127 subroutine box_user_defined_write_info(this, iunit, namespace)
128 class(box_user_defined_t), intent(in) :: this
129 integer, optional, intent(in) :: iunit
130 type(namespace_t), optional, intent(in) :: namespace
131
133
134 write(message(1),'(2x,a)') 'Type = user-defined'
135 call messages_info(1, iunit=iunit, namespace=namespace)
136
139
140 !--------------------------------------------------------------
141 character(len=BOX_INFO_LEN) function box_user_defined_short_info(this, unit_length) result(info)
142 class(box_user_defined_t), intent(in) :: this
143 type(unit_t), intent(in) :: unit_length
147 write(info,'(3a)') 'BoxShape = user_defined; BoxShapeUsDef = "', trim(this%expression), '"'
148
150 end function box_user_defined_short_info
151
152end module box_user_defined_oct_m
153
154!! Local Variables:
155!! mode: f90
156!! coding: utf-8
157!! End:
subroutine info()
Definition: em_resp.F90:1096
subroutine, public box_shape_init(this, namespace, dim, center, bounding_box_min, bounding_box_max, axes)
Definition: box_shape.F90:175
subroutine, public box_shape_end(this)
Definition: box_shape.F90:271
class(box_user_defined_t) function, pointer box_user_defined_constructor(dim, center, axes, expression, length, namespace)
subroutine box_user_defined_finalize(this)
subroutine box_user_defined_write_info(this, iunit, namespace)
logical function, dimension(1:nn) box_user_defined_shape_contains_points(this, nn, xx)
character(len=box_info_len) function box_user_defined_short_info(this, unit_length)
real(real64), parameter, public m_zero
Definition: global.F90:187
real(real64), parameter, public m_epsilon
Definition: global.F90:203
real(real64), parameter, public m_half
Definition: global.F90:193
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
Definition: messages.F90:624
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public conv_to_c_string(str)
converts to c string
Definition: string.F90:252
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 parallelepiped box. Currently this is restricted to a rectangular cuboid (all th...
Base class for more specialized boxes that are defined by a shape and have a center and basis vectors...
Definition: box_shape.F90:134
Class implementing a box defined by a mathematical expression. This box needs to be inside a parallel...