Octopus
linear_medium_to_em_field.F90
Go to the documentation of this file.
1!! Copyright (C) 2021 F. Bonafé
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#include "global.h"
19
21 use debug_oct_m
22 use global_oct_m
23 use grid_oct_m
31
32 implicit none
33
34 private
35 public :: &
40
42 real(real64), allocatable :: ep(:)
43 real(real64), allocatable :: mu(:)
44 real(real64), allocatable :: c(:)
45 real(real64), allocatable :: sigma_e(:)
46 real(real64), allocatable :: sigma_m(:)
47 integer :: points_number
48 integer :: global_points_number
49 integer, allocatable :: points_map(:)
50 logical :: has_mapping = .true.
51 integer :: bdry_number
52 integer, allocatable :: bdry_map(:)
53 real(real64), allocatable :: aux_ep(:,:)
54 real(real64), allocatable :: aux_mu(:,:)
55 integer :: box_shape
56 real(real64) :: center(3)
57 real(real64) :: lsize(3)
58 character(len=256) :: filename
59 logical :: check_medium_points = .false.
60 contains
61 procedure :: to_grid => single_medium_box_to_grid
62 end type single_medium_box_t
63
65 private
66
67 type(grid_t), pointer, public :: system_gr => null()
68 type(single_medium_box_t), public :: partner_medium_box
69 type(single_medium_box_t), public :: medium_box
70
71 contains
72 procedure :: init => linear_medium_to_em_field_init
73 procedure :: calculate => linear_medium_to_em_field_calculate
74 procedure :: calculate_energy => linear_medium_to_em_field_calculate_energy
77
78
81 end interface linear_medium_to_em_field_t
82
83contains
84
85 ! ---------------------------------------------------------
86 function linear_medium_to_em_field_constructor(partner) result(this)
87 class(interaction_partner_t), target, intent(inout) :: partner
88 class(linear_medium_to_em_field_t), pointer :: this
89
91
92 allocate(this)
93
94 this%label = "linear_medium_to_em_field"
95 this%partner => partner
96
97 this%couplings_from_partner = [permittivity, permeability, e_conductivity, m_conductivity]
98 this%intra_interaction = .false. ! This interaction does not support intra-interactions
99
102
103
104 subroutine linear_medium_to_em_field_init(this, gr)
105 class(linear_medium_to_em_field_t), intent(inout) :: this
106 type(grid_t), target, intent(in) :: gr
107
109
110 this%system_gr => gr
111 ! allocate medium box
112 call single_medium_box_allocate(this%medium_box, gr%np)
113 this%medium_box%has_mapping = .false.
114
116 end subroutine linear_medium_to_em_field_init
117
118 ! ---------------------------------------------------------
120 type(linear_medium_to_em_field_t), intent(inout) :: this
121
123
125
127
128
129 ! ---------------------------------------------------------
131 class(linear_medium_to_em_field_t), intent(inout) :: this
132
138 ! ---------------------------------------------------------
140 class(linear_medium_to_em_field_t), intent(inout) :: this
144 this%energy = m_zero
150 ! ---------------------------------------------------------
152 subroutine single_medium_box_allocate(medium_box, n_points)
153 type(single_medium_box_t), intent(inout) :: medium_box
154 integer, intent(in) :: n_points
155
156
157 push_sub_with_profile(medium_box_allocate)
158 safe_allocate(medium_box%aux_ep(1:n_points,1:3))
159 safe_allocate(medium_box%aux_mu(1:n_points,1:3))
160 safe_allocate(medium_box%c(1:n_points))
161 safe_allocate(medium_box%ep(1:n_points))
162 safe_allocate(medium_box%mu(1:n_points))
163 safe_allocate(medium_box%sigma_e(1:n_points))
164 safe_allocate(medium_box%sigma_m(1:n_points))
165 safe_allocate(medium_box%points_map(1:n_points))
166 medium_box%points_map = 0
167 medium_box%aux_ep(:,1:3) = m_zero
168 medium_box%aux_mu(:,1:3) = m_zero
169 medium_box%ep(:) = m_zero
170 medium_box%mu(:) = m_zero
171 medium_box%c(:) = m_zero
172 medium_box%sigma_e(:) = m_zero
173 medium_box%sigma_m(:) = m_zero
174 medium_box%points_number = n_points
175 pop_sub_with_profile(medium_box_allocate)
176
177 end subroutine single_medium_box_allocate
178
179 ! ---------------------------------------------------------
181 subroutine single_medium_box_end(medium_box)
182 type(single_medium_box_t), intent(inout) :: medium_box
183
184
185 push_sub_with_profile(medium_box_end)
186
187 safe_deallocate_a(medium_box%points_map)
188 safe_deallocate_a(medium_box%bdry_map)
189 safe_deallocate_a(medium_box%aux_ep)
190 safe_deallocate_a(medium_box%aux_mu)
191 safe_deallocate_a(medium_box%c)
192 safe_deallocate_a(medium_box%ep)
193 safe_deallocate_a(medium_box%mu)
194 safe_deallocate_a(medium_box%sigma_e)
195 safe_deallocate_a(medium_box%sigma_m)
196
197 pop_sub_with_profile(medium_box_end)
198
199 end subroutine single_medium_box_end
200
201 ! ---------------------------------------------------------
202 ! return a medium box with all functions mapped to the parent grid
203 function single_medium_box_to_grid(medium_box, grid_out) result(medium_box_out)
204 class(single_medium_box_t), intent(in) :: medium_box
205 type(grid_t), intent(in) :: grid_out
206 class(single_medium_box_t), pointer :: medium_box_out
207
208 integer :: ip, ip_out
209
210 push_sub_with_profile(medium_box_to_grid)
211
212 safe_allocate(medium_box_out)
213 call single_medium_box_allocate(medium_box_out, grid_out%np)
214 medium_box_out%has_mapping = .false.
215
216 do ip = 1, medium_box%points_number
217 ip_out = medium_box%points_map(ip)
218 medium_box_out%aux_ep(ip_out,1:3) = medium_box%aux_ep(ip,1:3)
219 medium_box_out%aux_mu(ip_out,1:3) = medium_box%aux_mu(ip,1:3)
220 medium_box_out%ep(ip_out) = medium_box%ep(ip)
221 medium_box_out%mu(ip_out) = medium_box%mu(ip)
222 medium_box_out%c(ip_out) = medium_box%c(ip)
223 medium_box_out%sigma_e(ip_out) = medium_box%sigma_e(ip)
224 medium_box_out%sigma_m(ip_out) = medium_box%sigma_m(ip)
225 end do
226
227 pop_sub_with_profile(medium_box_to_grid)
228 end function single_medium_box_to_grid
229
231
232!! Local Variables:
233!! mode: f90
234!! coding: utf-8
235!! End:
real(real64), parameter, public m_zero
Definition: global.F90:187
This module implements the underlying real-space grid.
Definition: grid.F90:117
This module defines the abstract interaction_t class, and some auxiliary classes for interactions.
This module defines classes and functions for interaction partners.
subroutine, public single_medium_box_allocate(medium_box, n_points)
Allocation of medium_box components.
subroutine, public single_medium_box_end(medium_box)
Deallocation of medium_box components.
class(linear_medium_to_em_field_t) function, pointer linear_medium_to_em_field_constructor(partner)
class(single_medium_box_t) function, pointer single_medium_box_to_grid(medium_box, grid_out)
This module defines the quantity_t class and the IDs for quantities, which can be exposed by a system...
Definition: quantity.F90:137
integer, parameter, public e_conductivity
Definition: quantity.F90:146
integer, parameter, public m_conductivity
Definition: quantity.F90:146
integer, parameter, public permittivity
Definition: quantity.F90:146
integer, parameter, public permeability
Definition: quantity.F90:146
Description of the grid, containing information on derivatives, stencil, and symmetries.
Definition: grid.F90:168
abstract interaction class
int true(void)