https://www.cdslab.org/paramonte/fortran/2
Current view: top level - main - pm_mathRootTest.F90 (source / functions) Hit Total Coverage
Test: ParaMonte 2.0.0 :: Serial Fortran - Code Coverage Report Lines: 0 1 0.0 %
Date: 2024-04-08 03:18:57 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       2             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       3             : !!!!                                                                                                                            !!!!
       4             : !!!!    ParaMonte: Parallel Monte Carlo and Machine Learning Library.                                                           !!!!
       5             : !!!!                                                                                                                            !!!!
       6             : !!!!    Copyright (C) 2012-present, The Computational Data Science Lab                                                          !!!!
       7             : !!!!                                                                                                                            !!!!
       8             : !!!!    This file is part of the ParaMonte library.                                                                             !!!!
       9             : !!!!                                                                                                                            !!!!
      10             : !!!!    LICENSE                                                                                                                 !!!!
      11             : !!!!                                                                                                                            !!!!
      12             : !!!!       https://github.com/cdslaborg/paramonte/blob/main/LICENSE.md                                                          !!!!
      13             : !!!!                                                                                                                            !!!!
      14             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      15             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      16             : 
      17             : !>  \brief
      18             : !>  This module contains a collection of example functions
      19             : !>  for testing or examining the root-finding routines of the ParaMonte library.
      20             : !>
      21             : !>  \see
      22             : !>  [pm_mathRoot](@ref pm_mathRoot)<br>
      23             : !>  [pm_mathRoot](@ref pm_mathRoot)<br>
      24             : !>  [pm_mathRoot](@ref pm_mathRoot)<br>
      25             : !>
      26             : !>  \todo
      27             : !>  \pvhigh
      28             : !>  Unfortunately, gfortran 12 and older versions do not properly support the parameterized derived types (PDTs).<br>
      29             : !>  As such, the example generic-real-kind PDT types could not be used here.<br>
      30             : !>  This creates significant complexities when using the examples of these modules,<br>
      31             : !>  because all `real` kinds in this module are set to the highest precision available.<br>
      32             : !>  The onus is then on the end user to write wrappers that convert the relevant components and function-returns to the desired `real` kinds.<br>
      33             : !>  In addition to being ugly, error-prone and verbose, this usage of the highest-precision `real` kind is also highly inefficient computationally.<br>
      34             : !>  Fortunately, once PDTs are supported in gfortran, the conversion of the example types of this module to PDTs is straightforward and non-breaking.<br>
      35             : !>  The migration to PDTs must be done as soon as gfortran supports for PDTs is complete.<br>
      36             : !>  Note that other compilers have full support of PDTs.<br>
      37             : !>
      38             : !>  \finmain
      39             : !>
      40             : !>  \author
      41             : !>  \AmirShahmoradi, Oct 16, 2009, 11:14 AM, Michigan
      42             : 
      43             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      44             : 
      45             : module pm_mathRootTest
      46             : 
      47             :     use pm_val2str, only: getStr
      48             :     use pm_option, only: getOption
      49             :     use pm_kind, only: SK, IK, LK, RKH
      50             :     use pm_str, only: getTTZ => getTrimmedTZ
      51             : 
      52             :     implicit none
      53             : 
      54             :     character(*, SK), parameter :: MODULE_NAME = "@pm_mathRootTest"
      55             : 
      56             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      57             : 
      58             :     !>  \brief
      59             :     !>  This is the base type `func_type` standing `abstract` function type to generate a variety of function test functions.<br>
      60             :     !>
      61             :     !>  \details
      62             :     !>  The abstract type minimally contains the function limits and deferred type-bound procedure `get()`.<br>
      63             :     !>  It is primarily meant to be used internally within the ParaMonte library for testing and illustration purposes.<br>
      64             :     !>  In particular, the implementations may not be ideal for benchmarks and performance tests of the library integrators.<br>
      65             :     !>  Nevertheless, all relevant types and function test objects are `public` in this repository and available to the end user.<br>
      66             :     !>
      67             :     !>  \interface{func_type}
      68             :     !>  \code{.F90}
      69             :     !>
      70             :     !>      use pm_mathRootTest, only: func_type
      71             :     !>
      72             :     !>      type, extends(func_type) :: Func_type
      73             :     !>          ...
      74             :     !>      end type
      75             :     !>
      76             :     !>  \endcode
      77             :     !>
      78             :     !>  \see
      79             :     !>  [getQuadErr](@ref pm_quadPack::getQuadErr)<br>
      80             :     !>
      81             :     !>  \finmain{func_type}
      82             :     !>
      83             :     !>  \author
      84             :     !>  \AmirShahmoradi, September 1, 2017, 12:00 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin
      85             :     type, abstract :: func_type
      86             :         real(RKH)                       :: lb       !<  \public The scalar of type `real` of the highest kind supported by the processor \RKH, containing the lower limit of function.
      87             :         real(RKH)                       :: ub       !<  \public The scalar of type `real` of the highest kind supported by the processor \RKH, containing the upper limit of function.
      88             :         real(RKH)       , allocatable   :: root(:)  !<  \public The scalar of type `real` of the highest kind supported by the processor \RKH, containing the true roots of function.
      89             :         character(:, SK), allocatable   :: desc     !<  \public The scalar `allocatable` character of default kind \SK containing a description of the function and function limits and difficulties.
      90             :     contains
      91             :         procedure(get_proc) , deferred  :: get
      92             :     end type
      93             : 
      94             :     !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      95             : 
      96             :     !>  \brief
      97             :     !>  This is the abstract interface of the `get()` type-bound procedure of [func_type](@ref pm_mathRootTest::func_type)
      98             :     !>  class whose arguments of type `real` are of the highest precision kind \RKH, made available by the processor.
      99             :     !>
     100             :     !>  \see
     101             :     !>  [func_type](@ref pm_mathRootTest::func_type)<br>
     102             :     !>
     103             :     !>  \finmain{get_proc}
     104             :     !>
     105             :     !>  \author
     106             :     !>  \AmirShahmoradi, Oct 16, 2009, 11:14 AM, Michigan
     107             :     abstract interface
     108             :         PURE function get_proc(self, x) result(func)
     109             :             use pm_kind, only: RKC => RKH
     110             :             import :: func_type
     111             :             class(func_type)    , intent(in)    :: self
     112             :             real(RKC)           , intent(in)    :: x
     113             :             real(RKC)                           :: func
     114             :         end function
     115             :     end interface
     116             : 
     117             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     118             : 
     119             :     !>  \brief
     120             :     !>  This is the derived type for generating test function objects of the algebraic form as described below.
     121             :     !>
     122             :     !>  \details
     123             :     !>  The full function is defined as,<br>
     124             :     !>  \f{equation}{
     125             :     !>
     126             :     !>      f(x) = x (x^2 - 1)(x^2 - 4) ~,~ x \in (\ms{lb}, \ms{ub})
     127             :     !>
     128             :     !>  \f}
     129             :     !>  where the function bounds could be infinities.<br>
     130             :     !>  The real roots of the function are `-2, -1, 0, 1, 2`.<br>
     131             :     !>
     132             :     !>  \param[in]  lb      :   The input scalar of type `real` of kind \RKH, containing the lower limit of the root search bracket.<br>
     133             :     !>                          (**optional**, default = `-3.`)<br>
     134             :     !>  \param[in]  ub      :   The input scalar of the same type and kind as `lb`, containing the upper limit of the root search bracket.<br>
     135             :     !>                          (**optional**, default = `+3.`)<br>
     136             :     !>
     137             :     !>  \interface{func1_type}
     138             :     !>  \code{.F90}
     139             :     !>
     140             :     !>      use pm_mathRootTest, only: func1_type
     141             :     !>      type(func1_type) :: Func
     142             :     !>
     143             :     !>      Func = func1_type(lb = lb, ub = ub)
     144             :     !>      print *, "description: ", Func%desc
     145             :     !>      print *, "lower search limit: ", Func%lb
     146             :     !>      print *, "upper search limit: ", Func%ub
     147             :     !>      print *, "Example function value: ", Func%get(x)
     148             :     !>
     149             :     !>  \endcode
     150             :     !>
     151             :     !>  \see
     152             :     !>  [func_type](@ref pm_mathRootTest::func_type)<br>
     153             :     !>
     154             :     !>  \test
     155             :     !>  [test_pm_quadPack](@ref test_pm_quadPack)
     156             :     !>
     157             :     !>  \finmain{func1_type}
     158             :     !>
     159             :     !>  \author
     160             :     !>  \AmirShahmoradi, Oct 16, 2009, 11:14 AM, Michigan
     161             :     type, extends(func_type) :: func1_type
     162             :     contains
     163             :         procedure               :: get => getFunc1
     164             :     end type
     165             : 
     166             :     !>  \cond excluded
     167             :     interface func1_type
     168             :     PURE module function constructFunc1(lb, ub) result(self)
     169             : #if __INTEL_COMPILER && DLL_ENABLED && (_WIN32 || _WIN64)
     170             :         !DEC$ ATTRIBUTES DLLEXPORT :: constructFunc1
     171             : #endif
     172             :         use pm_kind, only: RKC => RKH
     173             :         real(RKC), intent(in), optional :: lb, ub
     174             :         type(func1_type)                :: self
     175             :     end function
     176             :     end interface
     177             :     !>  \endcond excluded
     178             : 
     179             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     180             : 
     181             :     interface
     182             :     PURE module function getFunc1(self, x) result(func)
     183             : #if __INTEL_COMPILER && DLL_ENABLED && (_WIN32 || _WIN64)
     184             :         !DEC$ ATTRIBUTES DLLEXPORT :: getFunc1
     185             : #endif
     186             :         use pm_kind, only: RKC => RKH
     187             :         class(func1_type)   , intent(in)    :: self
     188             :         real(RKC)           , intent(in)    :: x
     189             :         real(RKC)                           :: func
     190             :     end function
     191             :     end interface
     192             : 
     193             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     194             : 
     195           0 : end module pm_mathRootTest

ParaMonte: Parallel Monte Carlo and Machine Learning Library 
The Computational Data Science Lab
© Copyright 2012 - 2024