Octopus
derivatives.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
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
27
29 use accel_oct_m
31 use batch_oct_m
34 use debug_oct_m
40 use global_oct_m
41 use iso_c_binding
42 use, intrinsic :: iso_fortran_env
45 use math_oct_m
46 use mesh_oct_m
51 use parser_oct_m
53 use space_oct_m
62 use types_oct_m
63 use utils_oct_m
65
66 implicit none
67
68 private
69 public :: &
106
107
108 integer, parameter :: &
109 DER_BC_ZERO_F = 0, & !< function is zero at the boundaries
110 der_bc_zero_df = 1, &
111 der_bc_period = 2
112
113 integer, parameter, public :: &
114 DER_STAR = 1, &
115 der_variational = 2, &
116 der_cube = 3, &
117 der_starplus = 4, &
119
120 integer, parameter :: &
121 BLOCKING = 1, &
122 non_blocking = 2
123
126 type derivatives_t
127 ! Components are public by default
128 type(boundaries_t) :: boundaries
129 type(mesh_t), pointer :: mesh => null()
130 integer :: dim = 0
131 integer :: periodic_dim = 0
132 integer :: order = 0
133 integer :: stencil_type = 0
134
135
136 logical, private :: stencil_primitive_coordinates
137
138 class(coordinate_system_t), private, pointer :: coord_system
139 logical :: remove_zero_weight_points
140 logical :: symmetrize_grad
141 type(symmetries_t) :: symm
142
143 real(real64), allocatable :: masses(:)
144
147 real(real64), private :: lapl_cutoff = m_zero
148
149 type(nl_operator_t), allocatable, private :: op(:)
151 type(nl_operator_t), pointer :: lapl => null()
152 type(nl_operator_t), pointer :: grad(:) => null()
153
154 integer, allocatable :: n_ghost(:)
155!#if defined(HAVE_MPI)
156 integer, private :: comm_method = 0
157!#endif
158 type(derivatives_t), pointer :: finer => null()
159 type(derivatives_t), pointer :: coarser => null()
160 type(transfer_table_t), pointer :: to_finer => null()
161 type(transfer_table_t), pointer :: to_coarser => null()
162 end type derivatives_t
163
166 private
167!#ifdef HAVE_MPI
168 type(par_vec_handle_batch_t) :: pv_h
169!#endif
170 type(derivatives_t), pointer :: der
171 type(nl_operator_t), pointer :: op
172 type(batch_t), pointer :: ff
173 type(batch_t), pointer :: opff
174 logical :: ghost_update
175 logical :: factor_present
176 real(real64) :: factor
178
179 type(accel_kernel_t) :: kernel_uvw_xyz, kernel_dcurl, kernel_zcurl
181contains
182
183 ! ---------------------------------------------------------
184 subroutine derivatives_init(der, namespace, space, coord_system, symm, order)
185 type(derivatives_t), target, intent(inout) :: der
186 type(namespace_t), intent(in) :: namespace
187 class(space_t), intent(in) :: space
188 class(coordinate_system_t), target, intent(in) :: coord_system
189 type(symmetries_t), intent(in) :: symm
190 integer, optional, intent(in) :: order
191
192 integer :: idir
193 integer :: default_stencil
194 logical :: stencil_primitive_coordinates
195 character(len=128) :: kernel_name
196
197 push_sub(derivatives_init)
199 ! Non-orthogonal curvilinear coordinates are currently not implemented
200 assert(.not. coord_system%local_basis .or. coord_system%orthogonal)
202 ! copy this value to my structure
203 der%dim = space%dim
204 der%periodic_dim = space%periodic_dim
205 der%coord_system => coord_system
206
207 !%Variable DerivativesStencil
208 !%Type integer
209 !%Default stencil_star
210 !%Section Mesh::Derivatives
211 !%Description
212 !% Decides what kind of stencil is used, <i>i.e.</i> which points, around
213 !% each point in the mesh, are the neighboring points used in the
214 !% expression of the differential operator.
215 !%
216 !% If curvilinear coordinates are to be used, then only the <tt>stencil_starplus</tt>
217 !% or the <tt>stencil_cube</tt> may be used. We only recommend the <tt>stencil_starplus</tt>,
218 !% since the cube typically needs far too much memory.
219 !%Option stencil_star 1
220 !% A star around each point (<i>i.e.</i>, only points on the axis).
221 !%Option stencil_variational 2
222 !% Same as the star, but with coefficients built in a different way.
223 !%Option stencil_cube 3
224 !% A cube of points around each point.
225 !%Option stencil_starplus 4
226 !% The star, plus a number of off-axis points.
227 !%Option stencil_stargeneral 5
228 !% The general star. Default for non-orthogonal grids.
229 !%End
230 default_stencil = der_star
231 if (coord_system%local_basis) default_stencil = der_starplus
232 if (.not. coord_system%orthogonal) default_stencil = der_stargeneral
234 call parse_variable(namespace, 'DerivativesStencil', default_stencil, der%stencil_type)
235
236 if (.not. varinfo_valid_option('DerivativesStencil', der%stencil_type)) then
237 call messages_input_error(namespace, 'DerivativesStencil')
238 end if
239 call messages_print_var_option("DerivativesStencil", der%stencil_type, namespace=namespace)
241 if (coord_system%local_basis .and. der%stencil_type < der_cube) call messages_input_error(namespace, 'DerivativesStencil')
242 ! The star stencils have no off-axis points, so they cannot represent the cross derivatives
243 ! of the Laplacian in non-orthogonal coordinates.
244 if (.not. coord_system%orthogonal .and. &
245 (der%stencil_type == der_star .or. der%stencil_type == der_variational)) then
246 call messages_input_error(namespace, 'DerivativesStencil', &
247 'stencil_star and stencil_variational cannot be used for non-orthogonal cells. Use stencil_stargeneral.')
248 end if
249 if (der%stencil_type == der_variational) then
250 !%Variable DerivativesLaplacianFilter
251 !%Type float
252 !%Default 1.0
253 !%Section Mesh::Derivatives
254 !%Description
255 !% Undocumented
256 !%End
257 call parse_variable(namespace, 'DerivativesLaplacianFilter', m_one, der%lapl_cutoff)
258 end if
259
260 !%Variable DerivativesOrder
261 !%Type integer
262 !%Default 4
263 !%Section Mesh::Derivatives
264 !%Description
265 !% This variable gives the discretization order for the approximation of
266 !% the differential operators. This means, basically, that
267 !% <tt>DerivativesOrder</tt> points are used in each positive/negative
268 !% spatial direction, <i>e.g.</i> <tt>DerivativesOrder = 1</tt> would give
269 !% the well-known three-point formula in 1D.
270 !% The number of points actually used for the Laplacian
271 !% depends on the stencil used. Let <math>O</math> = <tt>DerivativesOrder</tt>, and <math>d</math> = <tt>Dimensions</tt>.
272 !% <ul>
273 !% <li> <tt>stencil_star</tt>: <math>2 O d + 1</math>
274 !% <li> <tt>stencil_cube</tt>: <math>(2 O + 1)^d</math>
275 !% <li> <tt>stencil_starplus</tt>: <math>2 O d + 1 + n</math> with <i>n</i> being 8
276 !% in 2D and 24 in 3D.
277 !% </ul>
278 !%End
279 call parse_variable(namespace, 'DerivativesOrder', 4, der%order)
280 ! overwrite order if given as argument
281 if (present(order)) then
282 der%order = order
283 end if
284
285 !%Variable DerivativesRemoveZeroWeightPoints
286 !%Type logical
287 !%Default yes
288 !%Section Mesh::Derivatives
289 !%Description
290 !% By default, Octopus removes the zero-weight points in the stencils.
291 !% This debug variable gives the possibility to deactive this feature.
292 !%End
293 call parse_variable(namespace, 'DerivativesRemoveZeroWeightPoints', .true., der%remove_zero_weight_points)
294
295 !%Variable DerivativesSymmetrizeGradient
296 !%Type logical
297 !%Default yes
298 !%Section Mesh::Derivatives
299 !%Description
300 !% On non-orthogonal grids, the stencils of the gradient are not mapped onto each other
301 !% by the rotations of the lattice, such that the discrete gradient does not have the
302 !% symmetries of the lattice. If set to yes, the gradient operator is averaged over
303 !% the rotations of the space group of the system that map the grid onto itself, which enlarges its stencil.
304 !% This has no effect for orthogonal grids, or if only the identity is found (see <tt>SymmetriesCompute</tt>).
305 !%End
306 call parse_variable(namespace, 'DerivativesSymmetrizeGradient', .true., der%symmetrize_grad)
307 ! Systems without symmetries (e.g. Maxwell) do not have any operation
308 if (allocated(symm%ops)) der%symm = symm
309
310
311#ifdef HAVE_MPI
312 !%Variable ParallelizationOfDerivatives
313 !%Type integer
314 !%Default non_blocking
315 !%Section Execution::Parallelization
316 !%Description
317 !% This option selects how the communication of mesh boundaries is performed.
318 !%Option blocking 1
319 !% Blocking communication.
320 !%Option non_blocking 2
321 !% Communication is based on non-blocking point-to-point communication.
322 !%End
323
324 call parse_variable(namespace, 'ParallelizationOfDerivatives', non_blocking, der%comm_method)
325
326 if (.not. varinfo_valid_option('ParallelizationOfDerivatives', der%comm_method)) then
327 call messages_input_error(namespace, 'ParallelizationOfDerivatives')
328 end if
329
330 call messages_obsolete_variable(namespace, 'OverlapDerivatives', 'ParallelizationOfDerivatives')
331#endif
332
333 !%Variable StencilPrimitiveCoordinates
334 !%Type logical
335 !%Section Mesh::Derivatives
336 !%Description
337 !% This variable controls the method for generating the stencil weights for the Laplacian.
338 !% For the gradient, the weights are always computed for primitive coordinates.
339 !% If set to yes, primitive coordinates are used for the polynomials and the right-hand side
340 !% of the Laplacian is computed using the metric tensor and the trace of the Hessian.
341 !% If set to no, Cartesian coordinates are used for the polynomials and the right-hand side
342 !% of the Laplacian reduces to the Cartesian case.
343 !% For some non-orthogonal grids, using primitive coordinates is necessary because the polynomials
344 !% become linearly dependent, thus the corresponding matrix cannot be inverted. For some curvilinear
345 !% coordinate systems, using Cartesian coordinates is more accurate.
346 !%
347 !% By default, use primitve coordinates except for curvilinear meshes.
348 !%End
349 stencil_primitive_coordinates = .not. coord_system%local_basis
350 call parse_variable(namespace, 'StencilPrimitiveCoordinates', stencil_primitive_coordinates, der%stencil_primitive_coordinates)
351
352 ! if needed, der%masses should be initialized in modelmb_particles_init
353 safe_allocate(der%masses(1:space%dim))
354 der%masses = m_one
355
356 ! construct lapl and grad structures
357 safe_allocate(der%op(1:der%dim + 1))
358 der%grad => der%op
359 der%lapl => der%op(der%dim + 1)
360
361 call derivatives_get_stencil_lapl(der, der%lapl, space, coord_system)
363
364 ! find out how many ghost points we need in each dimension
365 safe_allocate(der%n_ghost(1:der%dim))
366 der%n_ghost(:) = 0
367 do idir = 1, der%dim
368 der%n_ghost(idir) = maxval(abs(der%lapl%stencil%points(idir, :)))
369 end do
370
371 nullify(der%coarser)
372 nullify(der%finer)
373 nullify(der%to_coarser)
374 nullify(der%to_finer)
375
376 if (accel_is_enabled()) then
377 ! Check if we can build the uvw_to_xyz kernel
378 select type (coord_system)
379 type is (cartesian_t)
380 ! In this case one does not need to call the kernel, so all is fine
381 class default
382 if (der%dim > 3) then
383 message(1) = "Calculation of derivatives on the GPU with dimension > 3 are only implemented for Cartesian coordinates."
384 call messages_fatal(1, namespace=namespace)
385 else
386 ! Each dimension adds a (source, ld, dest, ld) argument group
387 write(kernel_name, '(a,i1,a)') 'uvw_to_xyz<double, Dim::D', der%dim, &
388 repeat(', double*, int, double*, int', der%dim)//'>'
389 call accel_kernel_start_call(kernel_uvw_xyz, 'uvw_to_xyz.cu', trim(kernel_name))
390 end if
391 end select
392 call accel_kernel_build(kernel_dcurl, 'curl.cu', 'curl<double>')
393 call accel_kernel_build(kernel_zcurl, 'curl.cu', 'curl<complex<double>>')
394 end if
395
396 pop_sub(derivatives_init)
397 end subroutine derivatives_init
398
399
400 ! ---------------------------------------------------------
401 subroutine derivatives_end(der)
402 type(derivatives_t), intent(inout) :: der
403
404 integer :: idim
405
406 push_sub(derivatives_end)
407
408 assert(allocated(der%op))
409
410 do idim = 1, der%dim+1
411 call nl_operator_end(der%op(idim))
412 end do
413
414 safe_deallocate_a(der%masses)
415
416 safe_deallocate_a(der%n_ghost)
417
418 safe_deallocate_a(der%op)
419 nullify(der%lapl, der%grad)
420
421 nullify(der%coarser)
422 nullify(der%finer)
423 nullify(der%to_coarser)
424 nullify(der%to_finer)
425
426 call boundaries_end(der%boundaries)
427
428 pop_sub(derivatives_end)
429 end subroutine derivatives_end
430
431
432 ! ---------------------------------------------------------
433 subroutine derivatives_get_stencil_lapl(der, lapl, space, coord_system, name, order)
434 type(derivatives_t), intent(in) :: der
435 type(nl_operator_t), intent(inout) :: lapl
436 class(space_t), intent(in) :: space
437 class(coordinate_system_t), intent(in) :: coord_system
438 character(len=80), optional, intent(in) :: name
439 integer, optional, intent(in) :: order
440
441 character(len=80) :: name_
442 integer :: order_
443
445
446 name_ = optional_default(name, "Laplacian")
447 order_ = optional_default(order, der%order)
448
449 ! initialize nl operator
450 call nl_operator_init(lapl, name_, symm=op_symmetric)
451
452 ! create stencil
453 select case (der%stencil_type)
454 case (der_star, der_variational)
455 call stencil_star_get_lapl(lapl%stencil, der%dim, order_)
456 case (der_cube)
457 call stencil_cube_get_lapl(lapl%stencil, der%dim, order_)
458 case (der_starplus)
459 call stencil_starplus_get_lapl(lapl%stencil, der%dim, order_)
460 case (der_stargeneral)
461 call stencil_stargeneral_get_arms(lapl%stencil, space%dim, coord_system)
462 call stencil_stargeneral_get_lapl(lapl%stencil, der%dim, order_)
463 end select
464
466 end subroutine derivatives_get_stencil_lapl
467
468
469 ! ---------------------------------------------------------
471 subroutine derivatives_lapl_diag(der, lapl)
472 type(derivatives_t), intent(in) :: der
473 real(real64), contiguous, intent(out) :: lapl(:)
474
475 push_sub(derivatives_lapl_diag)
476
477 assert(ubound(lapl, dim=1) >= der%mesh%np)
478
479 ! the Laplacian is a real operator
480 call dnl_operator_operate_diag(der%lapl, lapl)
481
483
484 end subroutine derivatives_lapl_diag
485
486
487 ! ---------------------------------------------------------
488 subroutine derivatives_get_stencil_grad(der)
489 type(derivatives_t), intent(inout) :: der
490
491
492 integer :: ii
493 character :: dir_label
494
496
497 assert(associated(der%grad))
498
499 ! initialize nl operator
500 do ii = 1, der%dim
501 dir_label = ' '
502 if (ii < 5) dir_label = index2axis(ii)
503
504 call nl_operator_init(der%grad(ii), "Gradient "//dir_label, symm=op_antisymmetric)
505
506 ! create stencil
507 select case (der%stencil_type)
508 case (der_star, der_variational)
509 call stencil_star_get_grad(der%grad(ii)%stencil, der%dim, ii, der%order)
510 case (der_cube)
511 call stencil_cube_get_grad(der%grad(ii)%stencil, der%dim, der%order)
512 case (der_starplus)
513 call stencil_starplus_get_grad(der%grad(ii)%stencil, der%dim, ii, der%order)
514 case (der_stargeneral)
515 ! use the simple star stencil
516 call stencil_star_get_grad(der%grad(ii)%stencil, der%dim, ii, der%order)
517 end select
518 end do
519
521
522 end subroutine derivatives_get_stencil_grad
523
524 ! ---------------------------------------------------------
570 subroutine derivatives_build(der, namespace, space, mesh, stencil, qvector, regenerate, verbose)
571 type(derivatives_t), intent(inout) :: der
572 type(namespace_t), intent(in) :: namespace
573 class(space_t), intent(in) :: space
574 class(mesh_t), target, intent(in) :: mesh
575 type(stencil_t), intent(in) :: stencil
576 real(real64), contiguous, optional, intent(in) :: qvector(:)
578 logical, optional, intent(in) :: regenerate
579 logical, optional, intent(in) :: verbose
580
581 integer :: i
582 logical :: const_w_
583 integer :: np_zero_bc
584
585 push_sub(derivatives_build)
586
587 if (.not. optional_default(regenerate, .false.)) then
588 call boundaries_init(der%boundaries, namespace, space, mesh, qvector)
589 end if
590
591 assert(allocated(der%op))
592 assert(der%stencil_type >= der_star .and. der%stencil_type <= der_stargeneral)
593 assert(.not.(der%stencil_type == der_variational .and. mesh%use_curvilinear))
594
595 der%mesh => mesh ! make a pointer to the underlying mesh
596
597 const_w_ = .true.
598
599 ! need non-constant weights for curvilinear and scattering meshes
600 if (mesh%use_curvilinear) const_w_ = .false.
601
602 np_zero_bc = 0
603
604 if (optional_default(regenerate, .false.)) then
605 do i = 1, der%dim+1
606 call nl_operator_end(der%op(i))
607 safe_deallocate_a(der%op(i)%w)
608 end do
609 call derivatives_get_stencil_lapl(der, der%lapl, space, der%coord_system)
611 end if
612
613 ! build operators
614 do i = 1, der%dim+1
615 call nl_operator_build(space, mesh, der%op(i), der%mesh%np, const_w = const_w_, &
616 regenerate=regenerate)
617 np_zero_bc = max(np_zero_bc, nl_operator_np_zero_bc(der%op(i)))
618 end do
620 assert(np_zero_bc > mesh%np .and. np_zero_bc <= mesh%np_part)
621
622 select case (der%stencil_type)
623
624 case (der_star, der_starplus, der_stargeneral) ! Laplacian and gradient have different stencils
625 do i = 1, der%dim + 1
626
627 call derivatives_make_discretization(namespace, der, 1, i, der%op(i:i), space, verbose=verbose)
628 end do
629
630 case (der_cube)
631 ! gradients have the same stencils, so use one call to derivatives_make_discretization
632 ! to solve the linear equation once for several right-hand sides
633 call derivatives_make_discretization(namespace, der, der%dim, der%dim, der%op(:), space, verbose=verbose)
634 ! the polynomials are evaluated differently for the Laplacian
635 call derivatives_make_discretization(namespace, der, 1, der%dim+1, der%op(der%dim+1:der%dim+1), space, &
636 verbose=verbose)
637
638 case (der_variational)
639 ! the gradients use the star stencil
640 do i = 1, der%dim
641 call derivatives_make_discretization(namespace, der, 1, i, der%op(i:i), space, verbose=verbose)
642 end do
643 ! we have the explicit coefficients for the Laplacian
644 call stencil_variational_coeff_lapl(der%dim, der%order, mesh%spacing, der%lapl, alpha = der%lapl_cutoff)
645 ! finalize the Laplacian as done in derivatives_make_discretization for the other stencils
646 if (der%lapl%const_w) call nl_operator_build_symmetric_weights(der%lapl)
648 call nl_operator_update_gpu_buffers(der%lapl)
649 end select
650
651 if (der%symmetrize_grad .and. const_w_ .and. .not. mesh%coord_system%orthogonal) then
652 call derivatives_symmetrize_grad(der, space, mesh, stencil)
653 end if
654
655 pop_sub(derivatives_build)
656
657 end subroutine derivatives_build
658
659 ! ---------------------------------------------------------
667 subroutine derivatives_symmetrize_grad(der, space, mesh, stencil)
668 type(derivatives_t), intent(inout) :: der
669 class(space_t), intent(in) :: space
670 class(mesh_t), intent(in) :: mesh
671 type(stencil_t), intent(in) :: stencil
672
673 integer :: dim, nrot, nops, iop, idir, jdir, ip, jp, is, npoints, nsym, nkeep
674 integer :: mat(der%dim, der%dim), pt(der%dim)
675 integer, allocatable :: mm(:,:,:), points(:,:), sym_points(:,:), keep(:)
676 real(real64) :: chi(der%dim), jac(der%dim, der%dim), jac_inv(der%dim, der%dim), tmp(der%dim, der%dim)
677 real(real64) :: wpair(der%dim), max_weight
678 real(real64), allocatable :: rot(:,:,:), wcart(:,:), wsym(:,:), wprim(:)
679 real(real64), parameter :: tol = 1.0e-10_real64
680
682
683 dim = der%dim
684 nrot = 0
685 if (allocated(der%symm%point_group)) nrot = ubound(der%symm%point_group, dim=3)
686 if (dim > 3 .or. nrot <= 1 .or. any(abs(der%masses - m_one) > m_epsilon)) then
688 return
689 end if
690
691 ! The Jacobian is the matrix A of the primitive lattice vectors, and its inverse converts
692 ! the primitive derivatives to the Cartesian gradient
693 chi = m_zero
694 jac = mesh%coord_system%jacobian(chi)
695 jac_inv = mesh%coord_system%jacobian_inverse(chi)
696
697 ! Rotations mapping the grid onto itself. The reduced coordinates are x_i = n_i / ll_i, with n_i the
698 ! index of the point, so the matrix of the rotation for the indices is M_ij = ll_i Mred_ij / ll_j.
699 ! The Cartesian matrix is R = B M B^-1, with B = A diag(h) the vectors joining neighboring grid points.
700 safe_allocate(mm(1:dim, 1:dim, 1:nrot))
701 safe_allocate(rot(1:dim, 1:dim, 1:nrot))
702 nops = 0
703 do iop = 1, nrot
704 do jdir = 1, dim
705 mat(:, jdir) = mesh%idx%ll(1:dim) * der%symm%point_group(1:dim, jdir, iop)
706 end do
707 if (any([(mod(mat(:, jdir), mesh%idx%ll(jdir)) /= 0, jdir = 1, dim)])) cycle
708 do jdir = 1, dim
709 mat(:, jdir) = mat(:, jdir) / mesh%idx%ll(jdir)
710 tmp(:, jdir) = mesh%spacing(1:dim) * mat(:, jdir) / mesh%spacing(jdir)
711 end do
712 tmp = matmul(jac, matmul(tmp, jac_inv))
713 if (any(abs(matmul(transpose(tmp), tmp) - diagonal_matrix(dim, m_one)) > symprec)) cycle
714 nops = nops + 1
715 mm(:, :, nops) = mat
716 rot(:, :, nops) = tmp
717 end do
718
719 ! Union of the stencils of the gradients, and the corresponding Cartesian weights
720 npoints = sum([(der%grad(idir)%stencil%size, idir = 1, dim)])
721 safe_allocate(points(1:dim, 1:npoints))
722 safe_allocate(wcart(1:dim, 1:npoints))
723 npoints = 0
724 wcart = m_zero
725 do idir = 1, dim
726 do ip = 1, der%grad(idir)%stencil%size
727 call add_point(der%grad(idir)%stencil%points(:, ip), points, npoints, jp)
728 wcart(:, jp) = wcart(:, jp) + jac_inv(idir, :) * der%grad(idir)%w(ip, 1)
729 end do
730 end do
731
732 ! Average over the operations. The symmetrized stencil must fit in the stencil used to generate the
733 ! boundary and ghost points.
734 safe_allocate(sym_points(1:dim, 1:npoints*nops))
735 safe_allocate(wsym(1:dim, 1:npoints*nops))
736 nsym = 0
737 wsym = m_zero
738 do iop = 1, nops
739 do ip = 1, npoints
740 pt = matmul(mm(:, :, iop), points(:, ip))
741 if (.not. any([(all(stencil%points(1:dim, is) == pt), is = 1, stencil%size)])) then
742 message(1) = "The symmetrized gradient does not fit in the stencil of the grid."
743 message(2) = "The gradient is not symmetrized."
744 call messages_warning(2)
745 safe_deallocate_a(mm)
746 safe_deallocate_a(rot)
747 safe_deallocate_a(points)
748 safe_deallocate_a(wcart)
749 safe_deallocate_a(sym_points)
750 safe_deallocate_a(wsym)
752 return
753 end if
754 call add_point(pt, sym_points, nsym, jp)
755 wsym(:, jp) = wsym(:, jp) + matmul(rot(:, :, iop), wcart(:, ip)) / nops
756 end do
757 end do
758
759 ! Enforce the exact antisymmetry of the weights
760 do ip = 1, nsym
761 call add_point(-sym_points(:, ip), sym_points, nsym, jp)
762 if (jp > ip) then
763 wpair = m_half * (wsym(:, ip) - wsym(:, jp))
764 wsym(:, ip) = wpair
765 wsym(:, jp) = -wpair
766 else if (jp == ip) then
767 wsym(:, ip) = m_zero
768 end if
769 end do
770
771 ! Rebuild the operators for the primitive derivatives, w_i = a_i . w
772 safe_allocate(wprim(1:nsym))
773 safe_allocate(keep(1:nsym))
774 do idir = 1, dim
775 wprim = matmul(jac(:, idir), wsym(:, 1:nsym))
776 max_weight = maxval(abs(wprim))
777 nkeep = count(abs(wprim) > tol * max_weight)
778 keep(1:nkeep) = pack([(ip, ip = 1, nsym)], abs(wprim) > tol * max_weight)
779
780 call nl_operator_end(der%grad(idir))
781 call stencil_allocate(der%grad(idir)%stencil, dim, nkeep)
782 der%grad(idir)%stencil%points(:, :) = sym_points(:, keep(1:nkeep))
783 call stencil_init_center(der%grad(idir)%stencil)
784
785 call nl_operator_build(space, mesh, der%grad(idir), mesh%np, const_w = .true., regenerate = .true.)
786 der%grad(idir)%w(:, 1) = wprim(keep(1:nkeep))
787
788 call nl_operator_output_weights(der%grad(idir))
789 call nl_operator_build_symmetric_weights(der%grad(idir))
790 call nl_operator_allocate_gpu_buffers(der%grad(idir))
791 call nl_operator_update_gpu_buffers(der%grad(idir))
792 end do
793
794 safe_deallocate_a(mm)
795 safe_deallocate_a(rot)
796 safe_deallocate_a(points)
797 safe_deallocate_a(wcart)
798 safe_deallocate_a(sym_points)
799 safe_deallocate_a(wsym)
800 safe_deallocate_a(wprim)
801 safe_deallocate_a(keep)
802
804
805 contains
806
808 subroutine add_point(pt, list, n, ind)
809 integer, intent(in) :: pt(:)
810 integer, intent(inout) :: list(:,:)
811 integer, intent(inout) :: n
812 integer, intent(out) :: ind
813
814 do ind = 1, n
815 if (all(list(:, ind) == pt)) return
816 end do
817 n = n + 1
818 ind = n
819 list(:, n) = pt
820 end subroutine add_point
821 end subroutine derivatives_symmetrize_grad
822
823 ! ---------------------------------------------------------
824 subroutine stencil_pol_grad(stencil_type, dim, direction, order, polynomials)
825 integer, intent(in) :: stencil_type
826 integer, intent(in) :: dim
827 integer, intent(in) :: direction
828 integer, intent(in) :: order
829 integer, contiguous, intent(inout) :: polynomials(:, :)
830
831 select case (stencil_type)
832 case (der_star, der_stargeneral, der_variational)
833 call stencil_star_polynomials_grad(direction, order, polynomials)
834 case (der_starplus)
835 call stencil_starplus_pol_grad(dim, direction, order, polynomials)
836 case (der_cube)
837 ! same stencil for gradient and Laplacian in this case
838 call stencil_cube_polynomials_lapl(dim, order, polynomials)
839 end select
840 end subroutine stencil_pol_grad
841
842 ! ---------------------------------------------------------
843 subroutine stencil_pol_lapl(stencil_type, stencil, dim, order, polynomials)
844 integer, intent(in) :: stencil_type
845 type(stencil_t), intent(in) :: stencil
846 integer, intent(in) :: dim
847 integer, intent(in) :: order
848 integer, contiguous, intent(inout) :: polynomials(:, :)
849
850 select case (stencil_type)
851 case (der_star, der_variational)
852 ! the variational stencil uses the points of the star; a generic Laplacian (e.g. with a
853 ! different order) is built with the star finite-difference weights
854 call stencil_star_polynomials_lapl(dim, order, polynomials)
855 case (der_starplus)
856 call stencil_starplus_pol_lapl(dim, order, polynomials)
858 call stencil_stargeneral_pol_lapl(stencil, dim, order, polynomials)
859 case (der_cube)
860 call stencil_cube_polynomials_lapl(dim, order, polynomials)
861 end select
862 end subroutine stencil_pol_lapl
863
864 ! ---------------------------------------------------------
865 subroutine get_rhs_lapl(coord_system, polynomials, chi, rhs, stencil_primitive_coordinates)
866 class(coordinate_system_t), intent(in) :: coord_system
867 integer, contiguous, intent(in) :: polynomials(:,:)
868 real(real64), contiguous, intent(in) :: chi(:)
869 real(real64), contiguous, intent(out) :: rhs(:)
870 logical, intent(in) :: stencil_primitive_coordinates
871
872 integer :: i, j, k, dim
873 real(real64) :: metric_inverse(1:size(polynomials, dim=1), 1:size(polynomials, dim=1))
874 real(real64) :: hessian_trace(1:size(polynomials, dim=1))
875 integer :: powers(0:2)
876
877 push_sub(get_rhs_lapl)
878
879 dim = size(polynomials, dim=1)
880
881 if (stencil_primitive_coordinates) then
882 ! inverse metric and trace of Hessian in primitive coordinates
883 metric_inverse = coord_system%metric_inverse(chi)
884 hessian_trace = coord_system%trace_hessian(chi)
885 else
886 ! inverse metric and trace of Hessian in Cartesian coordinates
887 metric_inverse = m_zero
888 do i = 1, dim
889 metric_inverse(i, i) = m_one
890 end do
891 hessian_trace = m_zero
892 end if
893
894 ! find right-hand side for operator
895 rhs(:) = m_zero
896 do j = 1, size(polynomials, dim=2)
897 ! count the powers of the polynomials
898 powers = 0
899 do i = 1, dim
900 if (polynomials(i, j) <= 2) then
901 powers(polynomials(i, j)) = powers(polynomials(i, j)) + 1
902 end if
903 end do
904
905 ! find all polynomials for which exactly one term is quadratic
906 ! for these, the Laplacian on the polynomial is 2*metric_inverse(i, i)
907 if (powers(2) == 1 .and. powers(0) == dim - 1) then
908 do i = 1, dim
909 if (polynomials(i, j) == 2) then
910 rhs(j) = m_two*metric_inverse(i, i)
911 end if
912 end do
913 end if
914 ! find all polynomials for which exactly two terms are linear
915 ! for these, the Laplacian on the polynomial is metric_inverse(i, k) + metric_inverse(k, i)
916 if (powers(1) == 2 .and. powers(0) == dim - 2) then
917 do i = 1, dim
918 if (polynomials(i, j) == 1) then
919 do k = i+1, dim
920 if (polynomials(k, j) == 1) then
921 rhs(j) = metric_inverse(i, k) + metric_inverse(k, i)
922 end if
923 end do
924 end if
925 end do
926 end if
927 ! find all polynomials for which exactly one term is linear
928 ! for these, the Laplacian on the polynomial is hessian_trace(i)
929 ! this term is only non-zero for curvilinear coordinates with a varying metric tensor
930 if (powers(1) == 1 .and. powers(0) == dim - 1) then
931 do i = 1, dim
932 if (polynomials(i, j) == 1) then
933 rhs(j) = hessian_trace(i)
934 end if
935 end do
936 end if
937 end do
938
939 pop_sub(get_rhs_lapl)
940 end subroutine get_rhs_lapl
941
942 ! ---------------------------------------------------------
943 subroutine get_rhs_grad(polynomials, dir, rhs)
944 integer, contiguous, intent(in) :: polynomials(:,:)
945 integer, intent(in) :: dir
946 real(real64), contiguous, intent(out) :: rhs(:)
947
948 integer :: j, k, dim
949 logical :: this_one
950
951 push_sub(get_rhs_grad)
952
953 dim = size(polynomials, dim=1)
954
955 ! find right-hand side for operator
956 rhs(:) = m_zero
957 do j = 1, size(polynomials, dim=2)
958 this_one = .true.
959 do k = 1, dim
960 if (k == dir .and. polynomials(k, j) /= 1) this_one = .false.
961 if (k /= dir .and. polynomials(k, j) /= 0) this_one = .false.
962 end do
963 if (this_one) rhs(j) = m_one
964 end do
965
966 pop_sub(get_rhs_grad)
967 end subroutine get_rhs_grad
968
969
970 ! ---------------------------------------------------------
971 subroutine derivatives_make_discretization(namespace, der, nderiv, ideriv, op, &
972 space, name, verbose, order)
973 type(namespace_t), intent(in) :: namespace
974 type(derivatives_t), intent(in) :: der
975 integer, intent(in) :: nderiv
976 integer, intent(in) :: ideriv
977 type(nl_operator_t), intent(inout) :: op(:)
978 type(space_t), intent(in) :: space
979 character(len=80), optional, intent(in) :: name
980 logical, optional, intent(in) :: verbose
981 integer, optional, intent(in) :: order
982
983 integer :: p, p_max, i, j, k, pow_max, order_
984 real(real64) :: x(der%dim)
985 real(real64), allocatable :: mat(:,:), sol(:,:), powers(:,:)
986 integer, allocatable :: pol(:,:)
987 real(real64), allocatable :: rhs(:,:)
988 character(len=80) :: name_
989
991
992 order_ = optional_default(order, der%order)
993
994 safe_allocate(rhs(1:op(1)%stencil%size, nderiv))
995 safe_allocate(pol(1:der%dim, 1:op(1)%stencil%size))
996 ! get polynomials
997 if (nderiv == 1) then
998 if (ideriv <= der%dim) then ! gradient
999 call stencil_pol_grad(der%stencil_type, der%dim, ideriv, order_, pol)
1000 name_ = index2axis(ideriv) // "-gradient"
1001 else ! Laplacian
1002 call stencil_pol_lapl(der%stencil_type, op(1)%stencil, der%dim, order_, pol)
1003 name_ = "Laplacian"
1004 end if
1005 else if (nderiv == der%dim) then
1006 ! in this case, we compute the weights for the gradients at once
1007 ! because they have the same stencils
1008 ! this is only used for the cube stencil
1009 name_ = "gradients"
1010 call stencil_pol_grad(der%stencil_type, der%dim, 1, order_, pol)
1011 else
1012 message(1) = "Error: derivatives_make_discretization can only be called with nderiv = 1 or der%dim."
1013 call messages_fatal(1)
1014 end if
1015
1016 safe_allocate(mat(1:op(1)%stencil%size, 1:op(1)%stencil%size))
1017 safe_allocate(sol(1:op(1)%stencil%size, 1:nderiv))
1018
1019 if (optional_default(verbose, .true.)) then
1020 name_ = optional_default(name, name_)
1021 message(1) = 'Info: Generating weights for finite-difference discretization of ' // trim(name_)
1022 call messages_info(1, namespace=namespace)
1023 end if
1024
1025 ! use to generate power lookup table
1026 pow_max = maxval(pol)
1027 safe_allocate(powers(1:der%dim, 0:pow_max))
1028 powers(:,:) = m_zero
1029 powers(:,0) = m_one
1030
1031 p_max = op(1)%np
1032 if (op(1)%const_w) p_max = 1
1033
1034 do p = 1, p_max
1035 ! get polynomials and right-hand side
1036 ! we need the current position for the right-hand side for curvilinear coordinates
1037 if (nderiv == 1) then
1038 if (ideriv <= der%dim) then ! gradient
1039 call get_rhs_grad(pol, ideriv, rhs(:,1))
1040 name_ = index2axis(ideriv) // "-gradient"
1041 else ! Laplacian
1042 call get_rhs_lapl(der%mesh%coord_system, pol, der%mesh%chi(:, p), rhs(:,1), der%stencil_primitive_coordinates)
1043 end if
1044 else if (nderiv == der%dim) then
1045 ! in this case, we compute the weights for the gradients at once
1046 ! because they have the same stencils
1047 do i = 1, der%dim
1048 call get_rhs_grad(pol, i, rhs(:,i))
1049 end do
1050 end if
1051
1052 ! first polynomial is just a constant
1053 mat(1,:) = m_one
1054 ! i indexes the point in the stencil
1055 do i = 1, op(1)%stencil%size
1056 if (ideriv <= der%dim) then
1057 ! for gradients, we always need to evaluate the polynomials in primitive coordinates
1058 x = real(op(1)%stencil%points(:, i), real64)*der%mesh%spacing
1059 else
1060 ! for the Laplacian, we can evaluate the polynomials in primitive or Cartesian coordinates
1061 if (der%stencil_primitive_coordinates) then
1062 x = real(op(1)%stencil%points(:, i), real64)*der%mesh%spacing
1063 else
1064 x = der%mesh%x(:, p + op(1)%ri(i, op(1)%rimap(p))) - der%mesh%x(:, p)
1065 end if
1066 end if
1067
1068 ! NB: these masses are applied on the cartesian directions. Should add a check for non-orthogonal axes
1069 x = x*sqrt(der%masses)
1070
1071 ! calculate powers
1072 powers(:, 1) = x
1073 do k = 2, pow_max
1074 powers(:, k) = x*powers(:, k-1)
1075 end do
1076
1077 ! generate the matrix
1078 ! j indexes the polynomial being used
1079 do j = 2, op(1)%stencil%size
1080 mat(j, i) = powers(1, pol(1, j))
1081 do k = 2, der%dim
1082 mat(j, i) = mat(j, i)*powers(k, pol(k, j))
1083 end do
1084 end do
1085 end do ! loop over i = point in stencil
1086
1087 ! linear problem to solve for derivative weights:
1088 ! mat * sol = rhs
1089 call lalg_linsyssolve(op(1)%stencil%size, nderiv, mat, rhs, sol)
1090
1091 ! for the cube stencil, all derivatives are calculated at once, so assign
1092 ! the correct solution to each operator
1093 do i = 1, nderiv
1094 op(i)%w(:, p) = sol(:, i)
1095 ! The central weight of an antisymmetric operator is zero by symmetry
1096 if (op(i)%symmetry == op_antisymmetric .and. op(i)%stencil%center > 0) then
1097 op(i)%w(op(i)%stencil%center, p) = m_zero
1098 endif
1099 end do
1100
1101 end do ! loop over points p
1102
1103 do i = 1, nderiv
1104 if (der%remove_zero_weight_points) then
1105 call nl_operator_remove_zero_weight_points(op(i), space, der%mesh)
1106 end if
1107 call nl_operator_output_weights(op(i))
1108 if (op(i)%const_w) then
1110 end if
1111 end do
1112
1113 ! In case of constant weights, we store the weights of the Laplacian on the GPU, as this
1114 ! saves many unecessary transfers
1115 do i = 1, nderiv
1118 end do
1119
1120
1121 safe_deallocate_a(mat)
1122 safe_deallocate_a(sol)
1123 safe_deallocate_a(powers)
1124 safe_deallocate_a(pol)
1125 safe_deallocate_a(rhs)
1126
1128 end subroutine derivatives_make_discretization
1129
1130#ifdef HAVE_MPI
1131 ! ---------------------------------------------------------
1132 logical function derivatives_overlap(this) result(overlap)
1133 type(derivatives_t), intent(in) :: this
1134
1135 push_sub(derivatives_overlap)
1136
1137 overlap = this%comm_method /= blocking
1138
1139 pop_sub(derivatives_overlap)
1140 end function derivatives_overlap
1141#endif
1142
1143 ! ---------------------------------------------------------
1144 subroutine derivatives_get_lapl(this, namespace, op, space, name, order)
1145 type(derivatives_t), intent(in) :: this
1146 type(namespace_t), intent(in) :: namespace
1147 type(nl_operator_t), contiguous, intent(inout) :: op(:)
1148 class(space_t), intent(in) :: space
1149 character(len=80), intent(in) :: name
1150 integer, intent(in) :: order
1151
1152 push_sub(derivatives_get_lapl)
1153
1154 call derivatives_get_stencil_lapl(this, op(1), space, this%mesh%coord_system, name, order)
1155 call nl_operator_build(space, this%mesh, op(1), this%mesh%np, const_w = .not. this%mesh%use_curvilinear)
1156 call derivatives_make_discretization(namespace, this, 1, this%dim+1, op(1:1), space, name, order=order)
1157
1158 pop_sub(derivatives_get_lapl)
1159 end subroutine derivatives_get_lapl
1160
1161 ! ---------------------------------------------------------
1174 function derivatives_get_inner_boundary_mask(this) result(mask)
1175 type(derivatives_t), intent(in) :: this
1176
1177 logical :: mask(1:this%mesh%np)
1178 integer :: ip, is, index
1179
1180 mask = .false.
1181 ! Loop through all points in the grid
1182 do ip = 1, this%mesh%np
1183 ! For each of them, loop through all points in the stencil
1184 do is = 1, this%lapl%stencil%size
1185 ! Get the index of the point obtained as: grid_point + displament_due_to_stencil
1186 index = nl_operator_get_index(this%lapl, is, ip)
1187 ! Check whether the displaced point if outsude the grid. Is so, it belongs to the mask
1188 if (index > this%mesh%np + this%mesh%pv%np_ghost) then
1189 mask(ip) = .true.
1190 exit
1191 end if
1192 end do
1193 end do
1194
1196
1197 ! ---------------------------------------------------------
1202 real(real64) function derivatives_lapl_get_max_eigenvalue(this)
1203 type(derivatives_t), intent(in) :: this
1204
1205 integer :: i
1206
1208
1210 if ((this%stencil_type == der_star .or. this%stencil_type == der_stargeneral) &
1211 .and. .not. this%mesh%use_curvilinear) then
1212 ! use Fourier transform of stencil evaluated at the maximum phase
1213 do i = 1, this%lapl%stencil%size
1215 (-1)**maxval(abs(this%lapl%stencil%points(:, i)))*this%lapl%w(i, 1)
1216 end do
1218 else
1219 ! use upper bound from continuum for other stencils
1220 do i = 1, this%dim
1222 m_pi**2/this%mesh%spacing(i)**2
1223 end do
1224 end if
1225
1228
1229 subroutine derivates_set_coordinates_system(der, coord_system)
1230 type(derivatives_t), target, intent(inout) :: der
1231 class(coordinate_system_t), target, intent(in) :: coord_system
1232
1233 der%coord_system => coord_system
1235
1236#include "undef.F90"
1237#include "real.F90"
1238#include "derivatives_inc.F90"
1239
1240#include "undef.F90"
1241#include "complex.F90"
1242#include "derivatives_inc.F90"
1243
1244end module derivatives_oct_m
1245
1246!! Local Variables:
1247!! mode: f90
1248!! coding: utf-8
1249!! End:
subroutine add_point(pt, list, n, ind)
Returns in ind the index of point in the list, adding it if needed.
double sqrt(double __x) __attribute__((__nothrow__
subroutine, public accel_kernel_start_call(this, file_name, kernel_name, flags)
Definition: accel.F90:1842
subroutine, public accel_kernel_build(this, file_name, kernel_name, flags)
Compile the program that contains a given kernel.
Definition: accel.F90:1800
pure logical function, public accel_is_enabled()
Definition: accel.F90:391
This module implements batches of mesh functions.
Definition: batch.F90:112
This module implements common operations on batches of mesh functions.
Definition: batch_ops.F90:95
Module implementing boundary conditions in Octopus.
Definition: boundaries.F90:101
subroutine, public boundaries_end(this)
Definition: boundaries.F90:407
subroutine, public boundaries_init(this, namespace, space, mesh, qvector)
initialize the boundary contitions
Definition: boundaries.F90:206
This module implements the curvilinear coordinates given in E.L. Briggs, D.J. Sullivan,...
Definition: curv_briggs.F90:98
This module implements the curvilinear coordinates given in F. Gygi and G. Galli, PRB 52 R2229 (1996)...
Definition: curv_gygi.F90:97
This module implements the curvilinear coordinates given in N. A. Modine, G. Zumbach,...
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
subroutine, public zderivatives_curl(der, ff, op_ff, ghost_update, set_bc)
apply the curl operator to a vector of mesh functions
subroutine, public dderivatives_perform(op, der, ff, op_ff, ghost_update, set_bc, factor)
apply a nl_operator to a mesh function
subroutine, public derivatives_build(der, namespace, space, mesh, stencil, qvector, regenerate, verbose)
build the derivatives object:
subroutine, public derivatives_lapl_diag(der, lapl)
Returns the diagonal elements of the Laplacian, needed for preconditioning.
integer, parameter, public der_cube
subroutine, public dderivatives_batch_curl_from_gradient(der, ffb, gradb)
calculate the curl from a batch and its gradient
subroutine derivatives_make_discretization(namespace, der, nderiv, ideriv, op, space, name, verbose, order)
subroutine, public dderivatives_batch_grad(der, ffb, opffb, ghost_update, set_bc, to_cartesian, factor)
apply the gradient to a batch of mesh functions
subroutine stencil_pol_grad(stencil_type, dim, direction, order, polynomials)
subroutine stencil_pol_lapl(stencil_type, stencil, dim, order, polynomials)
subroutine, public zderivatives_batch_curl_from_gradient(der, ffb, gradb)
calculate the curl from a batch and its gradient
subroutine, public zderivatives_batch_div(der, ffb, opffb, ghost_update, set_bc, to_cartesian)
calculate the divergence of a vector of batches
subroutine, public dderivatives_partial(der, ff, op_ff, dir, ghost_update, set_bc)
apply the partial derivative along dir to a mesh function
subroutine get_rhs_lapl(coord_system, polynomials, chi, rhs, stencil_primitive_coordinates)
subroutine, public dderivatives_batch_perform(op, der, ff, opff, ghost_update, set_bc, factor, async)
apply an operator to a bach of mesh functions
subroutine, public zderivatives_div(der, ff, op_ff, ghost_update, set_bc, to_cartesian)
apply the divergence operator to a vector of mesh functions
integer, parameter der_bc_period
boundary is periodic
subroutine, public dderivatives_batch_finish(handle, async)
apply a non-local operator to a batch (2nd part)
subroutine, public dderivatives_curl(der, ff, op_ff, ghost_update, set_bc)
apply the curl operator to a vector of mesh functions
subroutine derivatives_get_stencil_grad(der)
subroutine derivatives_symmetrize_grad(der, space, mesh, stencil)
Symmetrizes the gradient operators over the point group of the structure.
subroutine, public dderivatives_grad(der, ff, op_ff, ghost_update, set_bc, to_cartesian)
apply the gradient to a mesh function
subroutine derivatives_get_stencil_lapl(der, lapl, space, coord_system, name, order)
subroutine, public derivatives_end(der)
integer, parameter der_bc_zero_df
first derivative of the function is zero
subroutine, public zderivatives_batch_grad(der, ffb, opffb, ghost_update, set_bc, to_cartesian, factor)
apply the gradient to a batch of mesh functions
subroutine, public dderivatives_batch_div(der, ffb, opffb, ghost_update, set_bc, to_cartesian)
calculate the divergence of a vector of batches
subroutine, public derivatives_get_lapl(this, namespace, op, space, name, order)
subroutine, public zderivatives_batch_perform(op, der, ff, opff, ghost_update, set_bc, factor, async)
apply an operator to a bach of mesh functions
subroutine, public dderivatives_batch_start(op, der, ff, opff, handle, ghost_update, set_bc, factor)
apply a non-local operator to a batch (1st part)
subroutine get_rhs_grad(polynomials, dir, rhs)
subroutine, public dderivatives_lapl(der, ff, op_ff, ghost_update, set_bc, factor)
apply the Laplacian to a mesh function
real(real64) function, public derivatives_lapl_get_max_eigenvalue(this)
Get maximum eigenvalue of discrete Laplacian. For the star and star_general stencils,...
subroutine, public dderivatives_batch_curl(der, ffb, ghost_update, set_bc)
apply the curl to a batch of mesh functions
subroutine, public zderivatives_grad(der, ff, op_ff, ghost_update, set_bc, to_cartesian)
apply the gradient to a mesh function
subroutine, public derivatives_init(der, namespace, space, coord_system, symm, order)
subroutine, public zderivatives_partial(der, ff, op_ff, dir, ghost_update, set_bc)
apply the partial derivative along dir to a mesh function
subroutine, public zderivatives_batch_start(op, der, ff, opff, handle, ghost_update, set_bc, factor)
apply a non-local operator to a batch (1st part)
logical function, dimension(1:this%mesh%np), public derivatives_get_inner_boundary_mask(this)
This function tells whether a point in the grid is contained in a layer of the width of the stencil b...
integer, parameter, public der_starplus
subroutine, public zderivatives_perform(op, der, ff, op_ff, ghost_update, set_bc, factor)
apply a nl_operator to a mesh function
subroutine, public zderivatives_batch_curl(der, ffb, ghost_update, set_bc)
apply the curl to a batch of mesh functions
integer, parameter, public der_variational
subroutine, public zderivatives_lapl(der, ff, op_ff, ghost_update, set_bc, factor)
apply the Laplacian to a mesh function
subroutine, public derivates_set_coordinates_system(der, coord_system)
subroutine, public zderivatives_batch_finish(handle, async)
apply a non-local operator to a batch (2nd part)
subroutine, public dderivatives_div(der, ff, op_ff, ghost_update, set_bc, to_cartesian)
apply the divergence operator to a vector of mesh functions
integer, parameter non_blocking
integer, parameter, public der_stargeneral
real(real64), parameter, public m_two
Definition: global.F90:175
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:171
real(real64), parameter, public m_epsilon
Definition: global.F90:189
real(real64), parameter, public m_half
Definition: global.F90:179
real(real64), parameter, public m_one
Definition: global.F90:174
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:97
subroutine, public messages_warning(no_lines, all_nodes, namespace)
Definition: messages.F90:501
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:980
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:671
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
This module defines non-local operators.
Definition: nl_operator.F90:95
subroutine, public dnl_operator_operate_diag(op, fo)
subroutine, public nl_operator_init(op, label, symm)
initialize an instance of a non-local operator by setting the label
subroutine, public nl_operator_build_symmetric_weights(op, max_size)
Builds (or rebuild) the necessary arrays for symmetric and antisymmetric stencils.
subroutine, public nl_operator_update_gpu_buffers(op)
subroutine, public nl_operator_output_weights(this)
subroutine, public nl_operator_end(op)
subroutine, public nl_operator_remove_zero_weight_points(op, space, mesh)
Removes the zero-weight points for constant weight stencils.
integer, parameter, public op_symmetric
subroutine, public nl_operator_build(space, mesh, op, np, const_w, regenerate)
Creates the nonlocal operators for the stencils used for finite differences.
integer pure function, public nl_operator_np_zero_bc(op)
integer, parameter, public op_antisymmetric
integer pure function, public nl_operator_get_index(op, is, ip)
subroutine, public nl_operator_allocate_gpu_buffers(op)
Some general things and nomenclature:
Definition: par_vec.F90:150
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
This module defines routines, generating operators for a cubic stencil.
subroutine, public stencil_cube_get_lapl(this, dim, order)
subroutine, public stencil_cube_polynomials_lapl(dim, order, pol)
subroutine, public stencil_cube_get_grad(this, dim, order)
This module defines stencils used in Octopus.
Definition: stencil.F90:114
subroutine, public stencil_allocate(this, dim, size)
Definition: stencil.F90:158
subroutine, public stencil_init_center(this)
set the index of the central point of the stencil
Definition: stencil.F90:259
This module defines routines, generating operators for a star stencil.
subroutine, public stencil_star_get_grad(this, dim, dir, order)
subroutine, public stencil_star_get_lapl(this, dim, order)
subroutine, public stencil_star_polynomials_grad(dir, order, pol)
subroutine, public stencil_star_polynomials_lapl(dim, order, pol)
This module defines routines, generating operators for a generalized star stencil.
subroutine, public stencil_stargeneral_get_arms(this, dim, coord_system)
Finds the direction of the arms of the star-general stencil as described in Natan et al....
subroutine, public stencil_stargeneral_pol_lapl(this, dim, order, pol)
subroutine, public stencil_stargeneral_get_lapl(this, dim, order)
This module defines routines, generating operators for a stencil consisting of a star and a cross....
subroutine, public stencil_starplus_pol_grad(dim, dir, order, pol)
subroutine, public stencil_starplus_pol_lapl(dim, order, pol)
subroutine, public stencil_starplus_get_lapl(this, dim, order)
subroutine, public stencil_starplus_get_grad(this, dim, dir, order)
Implements the variational discretization of the Laplacian as proposed by P. Maragakis,...
subroutine, public stencil_variational_coeff_lapl(dim, order, h, lapl, alpha)
real(real64), public symprec
Definition: symmetries.F90:154
This module is intended to contain simple general-purpose utility functions and procedures.
Definition: utils.F90:99
character pure function, public index2axis(idir)
Definition: utils.F90:191
abstract class to describe coordinate systems
handle to transfer data from the start() to finish() calls.
class representing derivatives
Describes mesh distribution to nodes.
Definition: mesh.F90:165
data type for non local operators
The class representing the stencil, which is used for non-local mesh operations.
Definition: stencil.F90:142
int true(void)