Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
abs(nodez(inode)-z)<1.d-10 ) then
f=field(inode)
return
end if
end do
end if
end do
end do
end do
!==============
xt=x
yt=y
zt=z
do kkk=-1,1,2
zt=z+kkk*1.d-10
do jjj=-1,1,2
yt=y+jjj*1.d-10
do iii=-1,1,2
xt=x+iii*1.d-10
if (xt*(xt-1.d0).ge.0d0 .or. &
yt*(yt-1.d0).ge.0d0 .or. &
zt*(zt-1.d0).ge.0d0) goto 111
call octree_find_leaf (octree,noctree,xt,yt,zt,leaf,level,loc,x0,y0,z0,dxyz)
r=(x-x0)/dxyz*2.d0-1.d0
s=(y-y0)/dxyz*2.d0-1.d0
t=(z-z0)/dxyz*2.d0-1.d0
h(1)=(1.d0-r)*(1.d0-s)*(1.d0-t)/8.d0
h(2)=(1.d0+r)*(1.d0-s)*(1.d0-t)/8.d0
h(3)=(1.d0-r)*(1.d0+s)*(1.d0-t)/8.d0
h(4)=(1.d0+r)*(1.d0+s)*(1.d0-t)/8.d0
h(5)=(1.d0-r)*(1.d0-s)*(1.d0+t)/8.d0
h(6)=(1.d0+r)*(1.d0-s)*(1.d0+t)/8.d0
h(7)=(1.d0-r)*(1.d0+s)*(1.d0+t)/8.d0
h(8)=(1.d0+r)*(1.d0+s)*(1.d0+t)/8.d0
phi=0.d0
do k=1,8
phi=phi+h(k)*field(icon(k,leaf))
enddo
f=phi
if (abs(r)-1.d0+abs(s)-1.d0+abs(t)-1.d0.lt.1.d-10) return
111 continue
enddo
enddo
enddo
return
end
!===================================!
!=====[OCTREE_INTERPOLATE_MANY]=====!
!===================================!
subroutine octree_interpolate_many (nf,octree,noctree,icon,nleaves,nfield,x,y,z, &
field1,f1,field2,f2,field3,f3, &
field4,f4,field5,f5,field6,f6, &
field7,f7,field8,f8,field9,f9, &
field10,f10,field11,f11,field12,f12, &
field13,f13,field14,f14,field15,f15)
! This function returns the value of several fields (fieldi) known at the nodes
! of an octree by trilinear interpolation
! nf is the number of fields being interpolate (must be comprised between 1 and 15)
! icon is the connectivity matrix
! nleaves is the number of leaves in the octree
! fieldi are the arrays of dimension nfield containing the fields
! known at the nodes of the octree and to be interpolated
! x,y,z are the location of the point where the fields are to be interpolated
! fi are the resulting interpolated fields
! Note that the number of arguments to this routine depends on the number of
! fields to be interpolated (nf). This is why some of the arguments are declared
! as optional
implicit none
optional :: field2,f2,field3,f3,field4,f4,field5,f5,field6,f6
optional :: field7,f7,field8,f8,field9,f9,field10,f10
optional :: field11,f11,field12,f12,field13,f13,field14,f14,field15,f15
integer noctree,octree(noctree),nleaves,icon(8,nleaves)
integer nfield,nf
double precision field1(nfield),field2(nfield),field3(nfield),field4(nfield), &
field5(nfield),field6(nfield),field7(nfield),field8(nfield)
double precision field9(nfield),field10(nfield),field11(nfield),field12(nfield), &
field13(nfield),field14(nfield),field15(nfield)
double precision f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15
double precision x,y,z,x0,y0,z0,dxyz,r,s,t,h(8),phi,xt,yt,zt
integer leaf,level,loc,k,iii,jjj,kkk,ii
! function modified by JEAN BRAUN on September 26 2005
! to correct for an error in the logics that led to an interpolation
! from an octree to another identical octree with differences in the
! interpolated function. The reason for this problem was related to
! bad faces or hanging nodes. Indeed, for a hanging node it was very likely
! that the leaf that was detected as the loeaf in which the node resides
! was in fact a leave where the node was a hanging node (ie not one of the
! 4 corner nodes). This meant that the interpolated value was not equal
! to the "constrained" value imposed by the linear constraint at the
! hanging node. To correct for this we first check if the node can
! be interpolated with r,s,t values that are equal to 1 or -1. If this is
! true than this value is chosen as this would correspond to a nodal value
xt=x
yt=y
zt=z
if (xt.lt.-1.e-11 .or. xt.gt.1.d0+1.d-11) return
if (yt.lt.-1.e-11 .or. yt.gt.1.d0+1.d-11) return
if (zt.lt.-1.e-11 .or. zt.gt.1.d0+1.d-11) return
if (x.lt.1.e-11) xt=1.e-11
if (x.gt.1.d0-1.d-11) xt=1.d0-1.d-11
if (y.lt.1.e-11) yt=1.e-11
if (y.gt.1.d0-1.d-11) yt=1.d0-1.d-11
if (z.lt.1.e-11) zt=1.e-11
if (z.gt.1.d0-1.d-11) zt=1.d0-1.d-11
do kkk=-1,1,2
do jjj=-1,1,2
do iii=-1,1,2
xt=x+iii*1.d-10
yt=y+jjj*1.d-10
zt=z+kkk*1.d-10
if (xt*(xt-1.d0).ge.0d0 .or. yt*(yt-1.d0).ge.0d0 .or. zt*(zt-1.d0).ge.0d0) goto 111
call octree_find_leaf (octree,noctree,xt,yt,zt,leaf,level,loc,x0,y0,z0,dxyz)
r=(x-x0)/dxyz*2.d0-1.d0
s=(y-y0)/dxyz*2.d0-1.d0
t=(z-z0)/dxyz*2.d0-1.d0
h(1)=(1.d0-r)*(1.d0-s)*(1.d0-t)/8.d0
h(2)=(1.d0+r)*(1.d0-s)*(1.d0-t)/8.d0
h(3)=(1.d0-r)*(1.d0+s)*(1.d0-t)/8.d0
h(4)=(1.d0+r)*(1.d0+s)*(1.d0-t)/8.d0
h(5)=(1.d0-r)*(1.d0-s)*(1.d0+t)/8.d0
h(6)=(1.d0+r)*(1.d0-s)*(1.d0+t)/8.d0
h(7)=(1.d0-r)*(1.d0+s)*(1.d0+t)/8.d0
h(8)=(1.d0+r)*(1.d0+s)*(1.d0+t)/8.d0
phi=0.d0
do k=1,8
phi=phi+h(k)*field1(icon(k,leaf))
enddo
f1=phi
if (nf.eq.1) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field2(icon(k,leaf))
enddo
f2=phi
if (nf.eq.2) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field3(icon(k,leaf))
enddo
f3=phi
if (nf.eq.3) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field4(icon(k,leaf))
enddo
f4=phi
if (nf.eq.4) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field5(icon(k,leaf))
enddo
f5=phi
if (nf.eq.5) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field6(icon(k,leaf))
enddo
f6=phi
if (nf.eq.6) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field7(icon(k,leaf))
enddo
f7=phi
if (nf.eq.7) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field8(icon(k,leaf))
enddo
f8=phi
if (nf.eq.8) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field9(icon(k,leaf))
enddo
f9=phi
if (nf.eq.9) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field10(icon(k,leaf))
enddo
f10=phi
if (nf.eq.10) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field11(icon(k,leaf))
enddo
f11=phi
if (nf.eq.11) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field12(icon(k,leaf))
enddo
f12=phi
if (nf.eq.12) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field13(icon(k,leaf))
enddo
f13=phi
if (nf.eq.13) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field14(icon(k,leaf))
enddo
f14=phi
if (nf.eq.14) goto 222
phi=0.d0
do k=1,8
phi=phi+h(k)*field15(icon(k,leaf))
enddo
f15=phi
if (nf.gt.15) stop 'too many field'
222 continue
!if (abs(r)-1.d0+abs(s)-1.d0+abs(t)-1.d0.lt.1.d-10) return
if (abs(abs(r)-1.d0).lt.1.d-10 .and. abs(abs(s)-1.d0).lt.1.d-10 .and. abs(abs(t)-1.d0).lt.1.d-10) return
111 continue
enddo
enddo
enddo
return
end
!==============================================!
!=====[OCTREE_INTERPOLATE_MANY_DERIVATIVE]=====!
!==============================================!
subroutine octree_interpolate_many_derivative &
(nf,octree,noctree,icon,nleaves,nfield,x,y,z, &
field1,f1,df1x,df1y,df1z, &
field2,f2,df2x,df2y,df2z, &
field3,f3,df3x,df3y,df3z, &
field4,f4,df4x,df4y,df4z, &
field5,f5,df5x,df5y,df5z, &
field6,f6,df6x,df6y,df6z, &
field7,f7,df7x,df7y,df7z, &
field8,f8,df8x,df8y,df8z, &
field9,f9,df9x,df9y,df9z, &
field10,f10,df10x,df10y,df10z, &
field11,f11,df11x,df11y,df11z, &
field12,f12,df12x,df12y,df12z, &
field13,f13,df13x,df13y,df13z, &
field14,f14,df14x,df14y,df14z, &
field15,f15,df15x,df15y,df15z)
! This function returns the value of several fields (fieldi) known at the nodes
! of an octree by trilinear interpolation as well as their 3 spatial derivatives
! nf is the number of fields being interpolate (must be comprised between 1 and 15)
! icon is the connectivity matrix
! nleaves is the number of leaves in the octree
! fieldi are the arrays of dimension nfield containing the fields
! known at the nodes of the octree and to be interpolated
! x,y,z are the location of the point where the fields are to be interpolated
! fi are the resulting interpolated fields
! Note that the number of oarguments to this routine depends on the number of
! fields to be interpolated (nf). This is why some of the arguments are declared
! as optional
implicit none
optional :: field2,f2,field3,f3,field4,f4,field5,f5,field6,f6
optional :: field7,f7,field8,f8,field9,f9,field10,f10
optional :: field11,f11,field12,f12,field13,f13,field14,f14,field15,f15
optional :: df2x,df3x,df4x,df5x,df6x,df7x,df8x,df9x
optional :: df10x,df11x,df12x,df13x,df14x,df15x
optional :: df2y,df3y,df4y,df5y,df6y,df7y,df8y,df9y
optional :: df10y,df11y,df12y,df13y,df14y,df15y
optional :: df2z,df3z,df4z,df5z,df6z,df7z,df8z,df9z
optional :: df10z,df11z,df12z,df13z,df14z,df15z
integer noctree,octree(noctree),nleaves,icon(8,nleaves)
integer nfield,nf
double precision field1(nfield),field2(nfield),field3(nfield),field4(nfield), &
field5(nfield),field6(nfield),field7(nfield),field8(nfield)
double precision field9(nfield),field10(nfield),field11(nfield),field12(nfield), &
field13(nfield),field14(nfield),field15(nfield)
double precision f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15
double precision df1x,df2x,df3x,df4x,df5x,df6x,df7x,df8x,df9x
double precision df10x,df11x,df12x,df13x,df14x,df15x
double precision df1y,df2y,df3y,df4y,df5y,df6y,df7y,df8y,df9y
double precision df10y,df11y,df12y,df13y,df14y,df15y
double precision df1z,df2z,df3z,df4z,df5z,df6z,df7z,df8z,df9z
double precision df10z,df11z,df12z,df13z,df14z,df15z
double precision x,y,z,x0,y0,z0,dxyz,r,s,t,h(8),phi,xt,yt,zt
double precision phix,phiy,phiz
integer leaf,level,loc,k,iii,jjj,kkk,ii,jj,kk,ic,ijk
double precision dhdr(8),dhds(8),dhdt(8),xg(8),yg(8),zg(8),jcb(3,3),jcbi(3,3),volume
double precision dhdx(8),dhdy(8),dhdz(8)
! function modified by JEAN BRAUN on September 26 2005
! to correct for an error in the logics that led to an interpolation
! from an octree to another identical octree with differences in the
! interpolated function. The reason for this problem was related to
! bad faces or hanging nodes. Indeed, for a hanging node it was very likely
! that the leaf that was detected as the loeaf in which the node resides
! was in fact a leave where the node was a hanging node (ie not one of the
! 4 corner nodes). This meant that the interpolated value was not equal
! to the "constrained" value imposed by the linear constraint at the
! hanging node. To correct for this we first check if the node can
! be interpolated with r,s,t values that are equal to 1 or -1. If this is
! true than this value is chosen as this would correspond to a nodal value
xt=x
yt=y
zt=z
if (xt.lt.-1.e-11 .or. xt.gt.1.d0+1.d-11) return
if (yt.lt.-1.e-11 .or. yt.gt.1.d0+1.d-11) return
if (zt.lt.-1.e-11 .or. zt.gt.1.d0+1.d-11) return
if (x.lt.1.e-11) xt=1.e-11
if (x.gt.1.d0-1.d-11) xt=1.d0-1.d-11
if (y.lt.1.e-11) yt=1.e-11
if (y.gt.1.d0-1.d-11) yt=1.d0-1.d-11
if (z.lt.1.e-11) zt=1.e-11
if (z.gt.1.d0-1.d-11) zt=1.d0-1.d-11
do kkk=-1,1,2
do jjj=-1,1,2
do iii=-1,1,2
xt=x+iii*1.d-10
yt=y+jjj*1.d-10
zt=z+kkk*1.d-10
if (xt*(xt-1.d0).ge.0d0 .or. yt*(yt-1.d0).ge.0d0 .or. zt*(zt-1.d0).ge.0d0) goto 111
call octree_find_leaf (octree,noctree,xt,yt,zt,leaf,level,loc,x0,y0,z0,dxyz)
r=(x-x0)/dxyz*2.d0-1.d0
s=(y-y0)/dxyz*2.d0-1.d0
t=(z-z0)/dxyz*2.d0-1.d0
h(1)=(1.d0-r)*(1.d0-s)*(1.d0-t)/8.d0
h(2)=(1.d0+r)*(1.d0-s)*(1.d0-t)/8.d0
h(3)=(1.d0-r)*(1.d0+s)*(1.d0-t)/8.d0
h(4)=(1.d0+r)*(1.d0+s)*(1.d0-t)/8.d0
h(5)=(1.d0-r)*(1.d0-s)*(1.d0+t)/8.d0
h(6)=(1.d0+r)*(1.d0-s)*(1.d0+t)/8.d0
h(7)=(1.d0-r)*(1.d0+s)*(1.d0+t)/8.d0
h(8)=(1.d0+r)*(1.d0+s)*(1.d0+t)/8.d0
dhdr(1)=-(1.d0-s)*(1.d0-t)/8.d0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y(k)*field1(ic)
phiz=phiz+dhdz(k)*field1(ic)
enddo
f1=phi
df1x=phix
df1y=phiy
df1z=phiz
if (nf.eq.1) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field2(ic)
phix=phix+dhdx(k)*field2(ic)
phiy=phiy+dhdy(k)*field2(ic)
phiz=phiz+dhdz(k)*field2(ic)
enddo
f2=phi
df2x=phix
df2y=phiy
df2z=phiz
if (nf.eq.2) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field3(ic)
phix=phix+dhdx(k)*field3(ic)
phiy=phiy+dhdy(k)*field3(ic)
phiz=phiz+dhdz(k)*field3(ic)
enddo
f3=phi
df3x=phix
df3y=phiy
df3z=phiz
if (nf.eq.3) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field4(ic)
phix=phix+dhdx(k)*field4(ic)
phiy=phiy+dhdy(k)*field4(ic)
phiz=phiz+dhdz(k)*field4(ic)
enddo
f4=phi
df4x=phix
df4y=phiy
df4z=phiz
if (nf.eq.4) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field5(ic)
phix=phix+dhdx(k)*field5(ic)
phiy=phiy+dhdy(k)*field5(ic)
phiz=phiz+dhdz(k)*field5(ic)
enddo
f5=phi
df5x=phix
df5y=phiy
df5z=phiz
if (nf.eq.5) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field6(ic)
phix=phix+dhdx(k)*field6(ic)
phiy=phiy+dhdy(k)*field6(ic)
phiz=phiz+dhdz(k)*field6(ic)
enddo
f6=phi
df6x=phix
df6y=phiy
df6z=phiz
if (nf.eq.6) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field7(ic)
phix=phix+dhdx(k)*field7(ic)
phiy=phiy+dhdy(k)*field7(ic)
phiz=phiz+dhdz(k)*field7(ic)
enddo
f7=phi
df7x=phix
df7y=phiy
df7z=phiz
if (nf.eq.7) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field8(ic)
phix=phix+dhdx(k)*field8(ic)
phiy=phiy+dhdy(k)*field8(ic)
phiz=phiz+dhdz(k)*field8(ic)
enddo
f8=phi
df8x=phix
df8y=phiy
df8z=phiz
if (nf.eq.8) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field9(ic)
phix=phix+dhdx(k)*field9(ic)
phiy=phiy+dhdy(k)*field9(ic)
phiz=phiz+dhdz(k)*field9(ic)
enddo
f9=phi
df9x=phix
df9y=phiy
df9z=phiz
if (nf.eq.9) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field10(ic)
phix=phix+dhdx(k)*field10(ic)
phiy=phiy+dhdy(k)*field10(ic)
phiz=phiz+dhdz(k)*field10(ic)
enddo
f10=phi
df10x=phix
df10y=phiy
df10z=phiz
if (nf.eq.10) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field11(ic)
phix=phix+dhdx(k)*field11(ic)
phiy=phiy+dhdy(k)*field11(ic)
phiz=phiz+dhdz(k)*field11(ic)
enddo
f11=phi
df11x=phix
df11y=phiy
df11z=phiz
if (nf.eq.11) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field12(ic)
phix=phix+dhdx(k)*field12(ic)
phiy=phiy+dhdy(k)*field12(ic)
phiz=phiz+dhdz(k)*field12(ic)
enddo
f12=phi
df12x=phix
df12y=phiy
df12z=phiz
if (nf.eq.12) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field13(ic)
phix=phix+dhdx(k)*field13(ic)
phiy=phiy+dhdy(k)*field13(ic)
phiz=phiz+dhdz(k)*field13(ic)
enddo
f13=phi
df13x=phix
df13y=phiy
df13z=phiz
if (nf.eq.13) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field14(ic)
phix=phix+dhdx(k)*field14(ic)
phiy=phiy+dhdy(k)*field14(ic)
phiz=phiz+dhdz(k)*field14(ic)
enddo
f14=phi
df14x=phix
df14y=phiy
df14z=phiz
if (nf.eq.14) goto 222
phi=0.d0
phix=0.d0
phiy=0.d0
phiz=0.d0
do k=1,8
ic=icon(k,leaf)
phi=phi+h(k)*field15(ic)
phix=phix+dhdx(k)*field15(ic)
phiy=phiy+dhdy(k)*field15(ic)
phiz=phiz+dhdz(k)*field15(ic)
enddo
f15=phi
df15x=phix
df15y=phiy
df15z=phiz
if (nf.gt.15) stop 'too many field'
222 continue
!if (abs(r)-1.d0+abs(s)-1.d0+abs(t)-1.d0.lt.1.d-10) return
if (abs(abs(r)-1.d0).lt.1.d-10 .and. abs(abs(s)-1.d0).lt.1.d-10 .and. abs(abs(t)-1.d0).lt.1.d-10) return
111 continue
enddo
enddo
enddo
return
end
!-------------------------------------
Subroutine mrgrnk (XDONT, IRNGT, np)
!Subroutine mrgrnk (XDONT, IRNGT)
! __________________________________________________________
! MRGRNK = Merge-sort ranking of an array
! For performance reasons, the first 2 passes are taken
! out of the standard loop, and use dedicated coding.
! __________________________________________________________
! __________________________________________________________
Integer XDONT(np),IRNGT(np)
! Integer, Dimension (:), Intent (In) :: XDONT
! Integer, Dimension (:), Intent (Out) :: IRNGT
! __________________________________________________________
Integer :: XVALA, XVALB
!
Integer, Dimension(:),allocatable :: JWRKT
! Integer, Dimension (SIZE(IRNGT)) :: JWRKT
Integer :: LMTNA, LMTNC, IRNG1, IRNG2
Integer :: NVAL, IIND, IWRKD, IWRK, IWRKF, JINDA, IINDA, IINDB
!
NVAL = Min (SIZE(XDONT), SIZE(IRNGT))
Select Case (NVAL)
Case (:0)
Return
Case (1)
IRNGT (1) = 1
Return
Case Default
Continue
End Select
allocate (JWRKT(np))
!
! Fill-in the index array, creating ordered couples
!
Do IIND = 2, NVAL, 2
If (XDONT(IIND-1) <= XDONT(IIND)) Then
IRNGT (IIND-1) = IIND - 1
IRNGT (IIND) = IIND
Else
IRNGT (IIND-1) = IIND
IRNGT (IIND) = IIND - 1
End If
End Do
If (Modulo(NVAL, 2) /= 0) Then
IRNGT (NVAL) = NVAL
End If
!
! We will now have ordered subsets A - B - A - B - ...
! and merge A and B couples into C - C - ...
!
LMTNA = 2
LMTNC = 4
!
! First iteration. The length of the ordered subsets goes from 2 to 4
!
Do
If (NVAL <= 2) Exit
!
! Loop on merges of A and B into C
!
Do IWRKD = 0, NVAL - 1, 4
If ((IWRKD+4) > NVAL) Then
If ((IWRKD+2) >= NVAL) Exit
!
! 1 2 3
!
If (XDONT(IRNGT(IWRKD+2)) <= XDONT(IRNGT(IWRKD+3))) Exit
!
! 1 3 2
!
If (XDONT(IRNGT(IWRKD+1)) <= XDONT(IRNGT(IWRKD+3))) Then
IRNG2 = IRNGT (IWRKD+2)
IRNGT (IWRKD+2) = IRNGT (IWRKD+3)
IRNGT (IWRKD+3) = IRNG2
!
! 3 1 2
!
Else
IRNG1 = IRNGT (IWRKD+1)
IRNGT (IWRKD+1) = IRNGT (IWRKD+3)
IRNGT (IWRKD+3) = IRNGT (IWRKD+2)
IRNGT (IWRKD+2) = IRNG1
End If
Exit
End If
!
! 1 2 3 4
!
If (XDONT(IRNGT(IWRKD+2)) <= XDONT(IRNGT(IWRKD+3))) Cycle
!
! 1 3 x x
!
If (XDONT(IRNGT(IWRKD+1)) <= XDONT(IRNGT(IWRKD+3))) Then
IRNG2 = IRNGT (IWRKD+2)
IRNGT (IWRKD+2) = IRNGT (IWRKD+3)
If (XDONT(IRNG2) <= XDONT(IRNGT(IWRKD+4))) Then
! 1 3 2 4
IRNGT (IWRKD+3) = IRNG2
Else
! 1 3 4 2
IRNGT (IWRKD+3) = IRNGT (IWRKD+4)
IRNGT (IWRKD+4) = IRNG2
End If
!
! 3 x x x
!
Else
IRNG1 = IRNGT (IWRKD+1)
IRNG2 = IRNGT (IWRKD+2)
IRNGT (IWRKD+1) = IRNGT (IWRKD+3)
If (XDONT(IRNG1) <= XDONT(IRNGT(IWRKD+4))) Then
IRNGT (IWRKD+2) = IRNG1
If (XDONT(IRNG2) <= XDONT(IRNGT(IWRKD+4))) Then
! 3 1 2 4
IRNGT (IWRKD+3) = IRNG2
Else
! 3 1 4 2
IRNGT (IWRKD+3) = IRNGT (IWRKD+4)
IRNGT (IWRKD+4) = IRNG2
End If
Else
! 3 4 1 2
IRNGT (IWRKD+2) = IRNGT (IWRKD+4)
IRNGT (IWRKD+3) = IRNG1
IRNGT (IWRKD+4) = IRNG2
End If
End If
End Do
!
! The Cs become As and Bs
!
LMTNA = 4
Exit
End Do
!
! Iteration loop. Each time, the length of the ordered subsets
! is doubled.
!
Do
If (LMTNA >= NVAL) Exit
IWRKF = 0
LMTNC = 2 * LMTNC
!
! Loop on merges of A and B into C
!
Do
IWRK = IWRKF
IWRKD = IWRKF + 1
JINDA = IWRKF + LMTNA
IWRKF = IWRKF + LMTNC
If (IWRKF >= NVAL) Then
If (JINDA >= NVAL) Exit
IWRKF = NVAL
End If
IINDA = 1
IINDB = JINDA + 1
!
! Shortcut for the case when the max of A is smaller
! than the min of B. This line may be activated when the
! initial set is already close to sorted.
!
! IF (XDONT(IRNGT(JINDA)) <= XDONT(IRNGT(IINDB))) CYCLE
!
! One steps in the C subset, that we build in the final rank array
!
! Make a copy of the rank array for the merge iteration
!
JWRKT (1:LMTNA) = IRNGT (IWRKD:JINDA)
!
XVALA = XDONT (JWRKT(IINDA))
XVALB = XDONT (IRNGT(IINDB))
!
Do
IWRK = IWRK + 1
!
! We still have unprocessed values in both A and B
!
If (XVALA > XVALB) Then
IRNGT (IWRK) = IRNGT (IINDB)
IINDB = IINDB + 1
If (IINDB > IWRKF) Then
! Only A still with unprocessed values
IRNGT (IWRK+1:IWRKF) = JWRKT (IINDA:LMTNA)
Exit
End If
XVALB = XDONT (IRNGT(IINDB))
Else
IRNGT (IWRK) = JWRKT (IINDA)
IINDA = IINDA + 1
If (IINDA > LMTNA) Exit! Only B still with unprocessed values
XVALA = XDONT (JWRKT(IINDA))
End If
!
End Do
End Do
!
! The Cs become As and Bs
!
LMTNA = 2 * LMTNA
End Do
!
deallocate (JWRKT)
Return
!
End Subroutine mrgrnk