source: trunk/LMDZ.PLUTO/libf/muphypluto/lint_core.F90 @ 3608

Last change on this file since 3608 was 3560, checked in by debatzbr, 7 weeks ago

Addition of the microphysics model in moments.

File size: 4.7 KB
Line 
1! Copyright (c) Université de Reims Champagnne-Ardenne (2010-2015)
2! Contributor: Jérémie Burgalat (jeremie.burgalat@univ-reims.fr)
3!
4! This software is a computer program whose purpose is to compute multi-variate
5! linear interpolation.
6!
7! This software is governed by the CeCILL-B license under French law and
8! abiding by the rules of distribution of free software.  You can  use,
9! modify and/ or redistribute the software under the terms of the CeCILL-B
10! license as circulated by CEA, CNRS and INRIA at the following URL
11! "http://www.cecill.info".
12!
13! As a counterpart to the access to the source code and  rights to copy,
14! modify and redistribute granted by the license, users are provided only
15! with a limited warranty  and the software's author,  the holder of the
16! economic rights,  and the successive licensors  have only  limited
17! liability.
18!
19! In this respect, the user's attention is drawn to the risks associated
20! with loading,  using,  modifying and/or developing or reproducing the
21! software by the user in light of its specific status of free software,
22! that may mean  that it is complicated to manipulate,  and  that  also
23! therefore means  that it is reserved for developers  and  experienced
24! professionals having in-depth computer knowledge. Users are therefore
25! encouraged to load and test the software's suitability as regards their
26! requirements in conditions enabling the security of their systems and/or
27! data to be ensured and,  more generally, to use and operate it in the
28! same conditions as regards security.
29!
30! The fact that you are presently reading this means that you have had
31! knowledge of the CeCILL-B license and that you accept its terms.
32
33!! File:    lint_core.F90
34!! Summary: Linear interpolation core function file
35!! Author:  J. Burgalat
36!! Date:    2010-2014
37
38MODULE LINT_CORE
39    !! Core module of the library.
40    !!
41    !! This module contains a single function that performs the linear
42    !! interpolation of a single _N_-D point between \(2^{N}\) adjacents
43    !! points.
44    USE LINT_PREC
45    IMPLICIT NONE
46 
47    PRIVATE :: wp ! from LINT_PREC
48 
49    INTERFACE
50      FUNCTION locate(value,vector) RESULT(idx)
51        !! Locate the nearest default value in vector
52        !!
53        !! the method should search the subscript of the nearest value by default in
54        !! in the input vector.
55        IMPORT wp
56        REAL(kind=wp), INTENT(in)               :: value   !! value to search
57        REAL(kind=wp), INTENT(in), DIMENSION(:) :: vector  !! Vector to search in
58        INTEGER :: idx                                     !! Subscript of the nearest value in vector
59      END FUNCTION locate
60    END INTERFACE
61 
62 
63    CONTAINS
64 
65    FUNCTION lintc_(point,grid) RESULT(res)
66      !! Multivariate linear interpolation core function
67      !!
68      !! The method computes multivariate linear interpolation at the given __point__ using its
69      !! neighbours given in __grid__.
70      !!
71      !! @warning
72      !! In order to get a correct result, __grid__ must be ordered so first dimensions vary first
73      !! (see [Generic method](page/index.html/#generic-method) section of main documentation).
74      !!
75      !! @warning
76      !! The method in its current version does not check array boundaries. This operation should be
77      !! performed in wrappers of the function !
78      INTEGER, PARAMETER :: np = 2
79      REAL(kind=wp), INTENT(in), DIMENSION(:)   :: point
80        !! Coordinates of the point to compute.
81        !!
82        !! For __N__-D interpolation, ut should be a vector of __N__ points.
83      REAL(kind=wp), INTENT(in), DIMENSION(:,:) :: grid
84        !! Grid of values used for interpolation.
85        !!
86        !! For __N__-D interpolation, it should be a 2D-array of \(2^{N}\) rows and \(N+1\) columns.
87        !! Each row corresponds to a point with N coordinates, the last column is reserved for the
88        !! value of the point.
89      REAL(kind=wp) :: res
90        !! Interpolated value
91      REAL(kind=wp), DIMENSION(:),ALLOCATABLE :: val
92      REAL(kind=wp)                           :: cd
93      INTEGER                                 :: nv,mi,ngp,cp,i,j,k
94      nv = SIZE(point) ; mi = np**nv
95      ALLOCATE(val(2*mi-1))
96      val(1:mi) = grid(:,nv+1) ; val(mi+1:2*mi-1) = 0._wp
97      ! Computes the QnD linear interpolation
98      cp = 0
99      DO i=1,nv
100        cd = (point(i)-grid(1,i))/(grid(mi,i)-grid(1,i))
101        k = 1 ; ngp = np**(nv-i+1) ; cp = cp + ngp
102        DO j=1,ngp,np
103          val(cp+k) = val(j+cp-ngp) * (1._wp - cd) + val(j+cp-ngp+1)*cd
104          k = k + 1
105        ENDDO
106      ENDDO
107      res = val(cp+k-1)
108      DEALLOCATE(val) ! useless normally
109      RETURN
110    END FUNCTION lintc_
111 
112  END MODULE LINT_CORE 
Note: See TracBrowser for help on using the repository browser.