1 | subroutine s2_bar_func(xprime,yprime,zprime,s2_bar, |
---|
2 | * s2_bar_x,s2_bar_y,s2_bar_z,g2s2b, |
---|
3 | * Lz,s2_scale) |
---|
4 | c |
---|
5 | c *****input arguments xprime,yprime,zprime are DIMENSIONLESS as are all returned values |
---|
6 | c (xprime,yprime,zprime): d'less spatial position |
---|
7 | c Lz: vertical size of computational domain [m] |
---|
8 | c s2_scale: characteristic range of s2 values, used to scale s2 |
---|
9 | c units are dimensional, e.g. psu for s2-->Salinity |
---|
10 | |
---|
11 | c *****output variables, these need to be specified in this routine |
---|
12 | c s2_bar, s2_bar_x, s2_bar_y, s2_bar_z, g2s2b |
---|
13 | c scalar concentration, and spatial gradients, g2s2b=grad2(s2_bar) [dimensional units] |
---|
14 | |
---|
15 | implicit none |
---|
16 | real xprime,yprime,zprime |
---|
17 | real Lz,s2_scale |
---|
18 | real s2_bar,s2_bar_x,s2_bar_y,s2_bar_z,g2s2b |
---|
19 | |
---|
20 | c local variables: you may need some intermediate variables, |
---|
21 | c these need to be explicitly declared here |
---|
22 | real x,y,z,ans,ansp,ansm,delta_z,delta_x |
---|
23 | |
---|
24 | |
---|
25 | c it may be convenient to know the dimensional spatial location (x,y,z) in [m], so we compute it |
---|
26 | x = xprime*Lz ! use dimensional value to evaluate formulae |
---|
27 | y = yprime*Lz ! use dimensional value to evaluate formulae |
---|
28 | z = zprime*Lz ! use dimensional value to evaluate formulae |
---|
29 | |
---|
30 | |
---|
31 | c**** USER CUSTOMIZED CODE SEGMENT STARTS HERE ************************ |
---|
32 | c scalars='TS' --> s2 = T' and s2 = S' |
---|
33 | |
---|
34 | delta_z = Lz/10000. ! [m] (offset for estimating derivs) |
---|
35 | delta_x = 100. ! "" |
---|
36 | |
---|
37 | ! stay underwater |
---|
38 | if(z >= Lz-delta_z) z=Lz-delta_z |
---|
39 | |
---|
40 | call interp2d(x,z,'S',ans) |
---|
41 | call interp2d(x,z+delta_z,'S',ansp) |
---|
42 | call interp2d(x,z-delta_z,'S',ansm) |
---|
43 | |
---|
44 | s2_bar = ans ! [psu] |
---|
45 | s2_bar_z = (ansp-ansm)/(2.*delta_z) ! [psu/m] |
---|
46 | g2s2b = (ansp -2.*ans + ansm)/(delta_z**2) ! [psu/m2] |
---|
47 | |
---|
48 | |
---|
49 | call interp2d(x+delta_x,z,'S',ansp) |
---|
50 | call interp2d(x-delta_x,z,'S',ansm) |
---|
51 | |
---|
52 | s2_bar_x = (ansp-ansm)/(2.*delta_x) ! [psu/m] |
---|
53 | |
---|
54 | |
---|
55 | s2_bar_y = 0.0 ! [psu/m] |
---|
56 | |
---|
57 | |
---|
58 | c**** USER DEFINED CODE SEGMENT ENDS HERE ******************************** |
---|
59 | |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | c |
---|
64 | c*** LEAVE THIS SECTION AS IS, SCALING MUST BE CONSISTENT******************** |
---|
65 | c*** WITH THE REST OF THE ALGORITHM **************************************** |
---|
66 | s2_bar=s2_bar/(s2_scale) |
---|
67 | s2_bar_x = s2_bar_x/(s2_scale/Lz) |
---|
68 | s2_bar_y = s2_bar_y/(s2_scale/Lz) |
---|
69 | s2_bar_z = s2_bar_z/(s2_scale/Lz) |
---|
70 | g2s2b = g2s2b/(s2_scale/Lz**2) |
---|
71 | c***************************************************************************** |
---|
72 | c***************************************************************************** |
---|
73 | |
---|
74 | c print*,'s2_bar interpoled ...' |
---|
75 | return |
---|
76 | end |
---|
77 | |
---|
78 | |
---|
79 | |
---|
80 | c It may seem odd to have the inputs in dimensionless form |
---|
81 | c when it is usually convenient for the user to define the |
---|
82 | c ambient quantities in dimensional form. Also, we have a |
---|
83 | c **do not touch** section of code that converts the user |
---|
84 | c specified dimenaional quantities back to dimensionless form. |
---|
85 | c I chose to do it this way because this function gets called |
---|
86 | c from so many places in the code, it would be a pain and |
---|
87 | c a potential source of typos to do the scalings just before |
---|
88 | c and just after each call. This is not the case with |
---|
89 | c user_defined_ics and user_defined_forcing. These routines |
---|
90 | c get called in one location only and so it makes sense to |
---|
91 | c make the scaling "invisible" to the user. |
---|