Globals Library 1.0
Loading...
Searching...
No Matches
modNorms.f90
Go to the documentation of this file.
1module norms
2
3 use globals
4
5 implicit none
6
7 private
8
9 !>-----------------------------------------------------------
10 !> @brief Abstract type for the definition of the
11 !> procedure for the evaluation of the norm of a vector
12 !>
13 !> @details General definition of norm of a vector function
14 !>
15 !> **Example:**
16 !> * \f$\| v \| = \sqrt{\sum_{i} v_i^2}\f$
17 !> * \f$\| v \| = \sqrt{\sum_{i \ni D} v_i^2}\f$, where \f$D\f$
18 !> is a set of indices
19 !> * \f$\| v \| = \sqrt{ v^{\top} G v }\f$, for a metric \f$G\f$
20 type, public, abstract :: abs_norm
21 contains
22 !> Abstract procedure for the evaluation of the norm
23 procedure(compute_norm), public, deferred :: eval_norm
24 end type abs_norm
25
26 abstract interface
27 !>-----------------------------------------------------------
28 !> @brief Abstract interface for the computation of the norm
29 !> @param[inout] this: Object calling the function
30 !> @param[in] nvec: Integer, length of the vector
31 !> @param[in] vec: Real, input vector
32 !> @param[inout] scr: optional
33 !> @param[out] result: Norm of the input vector
34 !>----------------------------------------------------------
35 function compute_norm(this, nvec, vec, scr) result(norm)
36 use globals
37 import abs_norm
38 implicit none
39 class(abs_norm), intent(inout) :: this
40 integer, intent(in) :: nvec
41 real(kind=double), intent(in) :: vec(nvec)
42 real(kind=double), optional, intent(inout) :: scr(nvec)
43 ! output result
44 real(kind=double) :: norm
45 end function compute_norm
46 end interface
47
48 !> @brief Euclidean norm
49 type, public, extends(abs_norm) :: euc_norm
50 contains
51 !> Evaluation of the Euclidean norm
52 procedure, public :: eval_norm => eval_euc_norm
53 end type euc_norm
54
55 !> @brief Weighted version of Euclian norm.
56 !> @details The entries on the Dirichlet node are set to zero
57 !> \f$G_{i,j} = \delta_{i,j} (1 - \delta_{i,k})\f$
58 !> for \f$k\f$ in `noddir`.
59 type, public, extends(abs_norm) :: dir_norm
60 !> Number of Dirichlet nodes
61 integer :: ndir
62 !> Indeces of the Dirichlet Nodes
63 integer, allocatable :: noddir(:)
64 contains
65 !> Constructor for type `Norms::dir_norm`
66 procedure, public :: init => init_dir_norm
67 !> Evaluation of the weighted Euclidean norm
68 procedure, public :: eval_norm => eval_dir_norm
69 end type dir_norm
70
71contains
72
73 !> TODO COMMENT
74 function eval_euc_norm(this, nvec, vec, scr) result(resnorm)
75 implicit none
76 class(euc_norm), intent(inout) :: this
77 integer, intent(in) :: nvec
78 real(kind=double), intent(in) :: vec(nvec)
79 real(kind=double), optional, intent(inout) :: scr(nvec)
80 ! output result
81 real(kind=double) :: resnorm
82 !local
83 real(kind=double) :: dnrm2
84
85 resnorm = dnrm2(nvec, vec, 1)
86
87 end function eval_euc_norm
88
89 !> TODO COMMENT
90 subroutine init_dir_norm(this, lun_err, ndir, noddir)
91 implicit none
92 class(dir_norm), intent(inout) :: this
93 integer, intent(in) :: lun_err
94 integer, intent(in) :: ndir
95 integer, intent(in) :: noddir(ndir)
96 !local
97 logical :: rc
98 integer :: res
99
100 this%ndir = ndir
101 if (.not. allocated(this%noddir)) then
102 allocate (this%noddir(ndir), stat=res)
103 rc = ioerr(lun_err, err_alloc, 'init_dirichlet_resnorm', &
104 'type dir_resnorm member noddir ', res)
105 end if
106 this%noddir = noddir
107
108 end subroutine init_dir_norm
109
110 function eval_dir_norm(this, nvec, vec, scr) result(resnorm)
111 use, intrinsic :: iso_fortran_env, only: stderr => error_unit
112 implicit none
113 class(dir_norm), intent(inout) :: this
114 integer, intent(in) :: nvec
115 real(kind=double), intent(in) :: vec(nvec)
116 real(kind=double), optional, intent(inout) :: scr(nvec)
117
118 ! output result
119 real(kind=double) :: resnorm
120 !local
121 logical :: rc
122 integer :: i
123 real(kind=double) :: dnrm2
124
125 resnorm = zero
126 if (.not. present(scr)) then
127 rc = ioerr(stderr, err_val, 'eval_dir_norm', &
128 'scratch array not passed')
129 else
130 scr = vec
131 do i = 1, this%ndir
132 scr(this%noddir(i)) = zero
133 end do
134 resnorm = dnrm2(nvec, scr, 1)
135 end if
136
137 end function eval_dir_norm
138
139end module norms
Abstract interface for the computation of the norm.
Definition modNorms.f90:35
real(kind=double) function eval_euc_norm(this, nvec, vec, scr)
TODO COMMENT.
Definition modNorms.f90:75
real(kind=double) function eval_dir_norm(this, nvec, vec, scr)
Definition modNorms.f90:111
subroutine init_dir_norm(this, lun_err, ndir, noddir)
TODO COMMENT.
Definition modNorms.f90:91
Abstract type for the definition of the procedure for the evaluation of the norm of a vector.
Definition modNorms.f90:20
Weighted version of Euclian norm.
Definition modNorms.f90:59
Euclidean norm.
Definition modNorms.f90:49