Octopus
mix_tests.F90
Go to the documentation of this file.
1!! Copyright (C) 2024 N. Tancogne-Dejean
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
22module mix_tests_oct_m
24 use global_oct_m
25 use, intrinsic :: iso_fortran_env
27 use mesh_oct_m
28 use mix_oct_m
31 use space_oct_m
32 use types_oct_m
33
34 implicit none
35
36 private
37 public :: &
39
40contains
41
42 subroutine mix_tests_run()
43 integer :: iter, max_iter
44 real(real64), parameter :: tol = 1e-10_real64
45 real(real64), parameter :: solution = 2.0134438978154419300_real64
46 real(real64) :: rhoin(1,1), rhoout(1,1)
47 type(mix_t) :: smix
48 type(mixfield_t), pointer :: mixfield
49 type(derivatives_t) :: der
50 type(mesh_t), target :: mesh
51 type(space_t) :: space
52
53 max_iter = 1000
54
55 ! Fake initializations due to current code design
56 der%dim = 1
57 der%mesh => mesh
58 der%mesh%use_curvilinear = .false.
59 der%mesh%volume_element = m_one
60 der%mesh%parallel_in_domains = .false.
62
63 ! Initialization
64 call mix_init(smix, global_namespace, space, der, 1, 1, func_type_ = type_float)
65 call mix_get_field(smix, mixfield)
66
67 !Starting point
68 rhoin = m_one
69
70 write(message(1),'(a, f20.13)') "Starting point : ", rhoin
71 call messages_info(1)
72
73 do iter = 1, max_iter
74 call mixfield_set_vin(mixfield, rhoin)
75 call test_function(rhoin(1,1), rhoout(1,1))
76
77 write(message(1),'(a, i3, a, f20.13)') "At iter. ", iter, " the value is ", rhoout
78 call messages_info(1)
79
80 ! Check convergence
81 if(abs(rhoout(1,1)-rhoin(1,1)) < tol) exit
82
83 call mixfield_set_vout(mixfield, rhoout)
84 call mixing(global_namespace, smix)
85 call mixfield_get_vnew(mixfield, rhoin)
86 call mixfield_set_vin(mixfield, rhoin)
87 end do
88
89 message(1) = ''
90 if (iter < max_iter) then
91 write(message(2), '(a,f25.15,a,i3,a)') "Computed fixed point ", rhoout, " after ", iter, " iterations."
92 else
93 write(message(2), '(a,f25.15,a,i3,a)') "Failure: fixed point ", rhoout, " after ", max_iter, " iterations."
94 end if
95 write(message(3),'(a, f25.15, a )') "Numerical fixed point should be ", solution, " ."
96 call messages_info(3)
97
98 end subroutine mix_tests_run
99
103 subroutine test_function(x, fx)
104 real(real64), intent(in) :: x
105 real(real64), intent(out) :: fx
106
107 fx = sin(x) + atan(x)
108
109 end subroutine test_function
110
111end module mix_tests_oct_m
112
113!! Local Variables:
114!! mode: f90
115!! coding: utf-8
116!! End:
subroutine test_function(label)
double sin(double __x) __attribute__((__nothrow__
double atan(double __x) __attribute__((__nothrow__
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
real(real64), parameter, public m_one
Definition: global.F90:201
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
subroutine, public mixing(namespace, smix)
Main entry-point to SCF mixer.
Definition: mix.F90:846
subroutine, public mix_get_field(this, mixfield)
Definition: mix.F90:838
subroutine, public mix_init(smix, namespace, space, der, d1, d2, def_, func_type_, prefix_)
Initialise mix_t instance.
Definition: mix.F90:269
This module implements unit tests for the mixing methods.
Definition: mix_tests.F90:117
subroutine, public mix_tests_run()
Definition: mix_tests.F90:138
type(namespace_t), public global_namespace
Definition: namespace.F90:135
type(type_t), parameter, public type_float
Definition: types.F90:135