File: fluids_test.f90

package info (click to toggle)
python-fluids 1.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,108 kB
  • sloc: python: 59,520; f90: 481; lisp: 342; ansic: 337; cpp: 228; ruby: 145; haskell: 118; perl: 106; makefile: 59; javascript: 49
file content (610 lines) | stat: -rw-r--r-- 21,246 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
module python_utils
  use iso_c_binding
  implicit none

  ! Python object handles
  type(c_ptr) :: py_module = c_null_ptr
  type(c_ptr) :: py_none = c_null_ptr
  
contains
  subroutine init_python()
    interface
      subroutine Py_Initialize() bind(c, name='Py_Initialize')
      end subroutine
      
      function PyImport_ImportModule(name) bind(c, name='PyImport_ImportModule')
        use iso_c_binding
        character(kind=c_char), dimension(*) :: name
        type(c_ptr) :: PyImport_ImportModule
      end function
    end interface

    ! Initialize Python
    call Py_Initialize()
    
    ! Import fluids module
    py_module = PyImport_ImportModule('fluids'//c_null_char)
    if (.not. c_associated(py_module)) then
      print *, 'Failed to import fluids module'
      call exit(1)
    end if
  end subroutine

  subroutine test_fluids()
    interface
      function PyObject_GetAttrString(obj, name) bind(c, name='PyObject_GetAttrString')
        use iso_c_binding
        type(c_ptr), value :: obj
        character(kind=c_char), dimension(*) :: name
        type(c_ptr) :: PyObject_GetAttrString
      end function
      
      function PyFloat_AsDouble(obj) bind(c, name='PyFloat_AsDouble')
        use iso_c_binding
        type(c_ptr), value :: obj
        real(c_double) :: PyFloat_AsDouble
      end function

      function PyUnicode_AsUTF8(obj) bind(c, name='PyUnicode_AsUTF8')
        use iso_c_binding
        type(c_ptr), value :: obj
        type(c_ptr) :: PyUnicode_AsUTF8
      end function
      
      function PyTuple_New(size) bind(c, name='PyTuple_New')
        use iso_c_binding
        integer(c_size_t), value :: size
        type(c_ptr) :: PyTuple_New
      end function
      
      function PyDict_New() bind(c, name='PyDict_New')
        use iso_c_binding
        type(c_ptr) :: PyDict_New
      end function
      
      function PyFloat_FromDouble(val) bind(c, name='PyFloat_FromDouble')
        use iso_c_binding
        real(c_double), value :: val
        type(c_ptr) :: PyFloat_FromDouble
      end function
      
      subroutine PyDict_SetItemString(dict, key, val) bind(c, name='PyDict_SetItemString')
        use iso_c_binding
        type(c_ptr), value :: dict
        character(kind=c_char), dimension(*) :: key
        type(c_ptr), value :: val
      end subroutine
      
      function PyObject_Call(callable, args, kwargs) bind(c, name='PyObject_Call')
        use iso_c_binding
        type(c_ptr), value :: callable
        type(c_ptr), value :: args
        type(c_ptr), value :: kwargs
        type(c_ptr) :: PyObject_Call
      end function
    end interface

    type(c_ptr) :: version, reynolds_func, args, kwargs, result, str_ptr
    real(c_double) :: re
    character(len=100), pointer :: version_str
    character(kind=c_char), pointer :: c_str(:)
    character(len=100) :: temp_str
    integer :: i

    print *, 'Running fluids tests from Fortran...'

    ! Get version
    version = PyObject_GetAttrString(py_module, '__version__'//c_null_char)
    if (c_associated(version)) then
      str_ptr = PyUnicode_AsUTF8(version)
      call c_f_pointer(str_ptr, c_str, [100])
      temp_str = ''
      i = 1
      do while (c_str(i) /= c_null_char .and. i <= 100)
        temp_str(i:i) = c_str(i)
        i = i + 1
      end do
      
      print *, '✓ Successfully imported fluids'
      print *, '✓ Fluids version: ', trim(temp_str)
    end if
    ! Test Reynolds number calculation
    reynolds_func = PyObject_GetAttrString(py_module, 'Reynolds'//c_null_char)
    if (c_associated(reynolds_func)) then
      args = PyTuple_New(0_c_size_t)
      kwargs = PyDict_New()
      
      call PyDict_SetItemString(kwargs, 'V'//c_null_char, PyFloat_FromDouble(2.5d0))
      call PyDict_SetItemString(kwargs, 'D'//c_null_char, PyFloat_FromDouble(0.1d0))
      call PyDict_SetItemString(kwargs, 'rho'//c_null_char, PyFloat_FromDouble(1000.0d0))
      call PyDict_SetItemString(kwargs, 'mu'//c_null_char, PyFloat_FromDouble(0.001d0))
      
      result = PyObject_Call(reynolds_func, args, kwargs)
      if (c_associated(result)) then
        re = PyFloat_AsDouble(result)
        print *, '✓ Reynolds number calculation successful: ', re
        if (re > 0) then
          print *, 'Assert passed: Re > 0'
        else
          print *, 'Assert failed: Re <= 0'
        end if
      end if
    end if
  end subroutine

  subroutine benchmark_fluids()
    interface
      function PyObject_GetAttrString(obj, name) bind(c, name='PyObject_GetAttrString')
        use iso_c_binding
        type(c_ptr), value :: obj
        character(kind=c_char), dimension(*) :: name
        type(c_ptr) :: PyObject_GetAttrString
      end function
      
      function PyTuple_New(size) bind(c, name='PyTuple_New')
        use iso_c_binding
        integer(c_size_t), value :: size
        type(c_ptr) :: PyTuple_New
      end function
      
      function PyDict_New() bind(c, name='PyDict_New')
        use iso_c_binding
        type(c_ptr) :: PyDict_New
      end function

      function PyFloat_FromDouble(val) bind(c, name='PyFloat_FromDouble')
        use iso_c_binding
        real(c_double), value :: val
        type(c_ptr) :: PyFloat_FromDouble
      end function
      
      subroutine PyDict_SetItemString(dict, key, val) bind(c, name='PyDict_SetItemString')
        use iso_c_binding
        type(c_ptr), value :: dict
        character(kind=c_char), dimension(*) :: key
        type(c_ptr), value :: val
      end subroutine
      
      function PyObject_Call(callable, args, kwargs) bind(c, name='PyObject_Call')
        use iso_c_binding
        type(c_ptr), value :: callable
        type(c_ptr), value :: args
        type(c_ptr), value :: kwargs
        type(c_ptr) :: PyObject_Call
      end function
    end interface

    type(c_ptr) :: friction_func
    type(c_ptr) :: args, kwargs, result
    integer :: i
    real(c_double) :: start_time, end_time
    
    print *, 'Running benchmarks:'
    
    ! Get friction_factor function
    friction_func = PyObject_GetAttrString(py_module, 'friction_factor'//c_null_char)
    if (.not. c_associated(friction_func)) then
      print *, 'Failed to get friction_factor function'
      return
    end if
    
    ! Benchmark friction_factor
    print *, 'Benchmarking friction_factor:'
    call cpu_time(start_time)
    
    do i = 1, 1000000
      args = PyTuple_New(0_c_size_t)
      kwargs = PyDict_New()
      
      call PyDict_SetItemString(kwargs, 'Re'//c_null_char, PyFloat_FromDouble(1.0d5))
      call PyDict_SetItemString(kwargs, 'eD'//c_null_char, PyFloat_FromDouble(0.0001d0))
      
      result = PyObject_Call(friction_func, args, kwargs)
    end do
    
    call cpu_time(end_time)
    print *, 'Time for 1e6 friction_factor calls: ', end_time - start_time, ' seconds'
    print *, 'Average time per call: ', (end_time - start_time) / 1000000.0, ' seconds'
  end subroutine


  subroutine test_tank()
    interface
      function PyObject_GetAttrString(obj, name) bind(c, name='PyObject_GetAttrString')
        use iso_c_binding
        type(c_ptr), value :: obj
        character(kind=c_char), dimension(*) :: name
        type(c_ptr) :: PyObject_GetAttrString
      end function
      
      function PyTuple_New(size) bind(c, name='PyTuple_New')
        use iso_c_binding
        integer(c_size_t), value :: size
        type(c_ptr) :: PyTuple_New
      end function
      
      function PyDict_New() bind(c, name='PyDict_New')
        use iso_c_binding
        type(c_ptr) :: PyDict_New
      end function

      function PyFloat_FromDouble(val) bind(c, name='PyFloat_FromDouble')
        use iso_c_binding
        real(c_double), value :: val
        type(c_ptr) :: PyFloat_FromDouble
      end function
      
      function PyBool_FromLong(val) bind(c, name='PyBool_FromLong')
        use iso_c_binding
        integer(c_long), value :: val
        type(c_ptr) :: PyBool_FromLong
      end function
      
      function PyFloat_AsDouble(obj) bind(c, name='PyFloat_AsDouble')
        use iso_c_binding
        type(c_ptr), value :: obj
        real(c_double) :: PyFloat_AsDouble
      end function

      function PyUnicode_FromString(str) bind(c, name='PyUnicode_FromString')
        use iso_c_binding
        character(kind=c_char), dimension(*) :: str
        type(c_ptr) :: PyUnicode_FromString
      end function
      
      subroutine PyDict_SetItemString(dict, key, val) bind(c, name='PyDict_SetItemString')
        use iso_c_binding
        type(c_ptr), value :: dict
        character(kind=c_char), dimension(*) :: key
        type(c_ptr), value :: val
      end subroutine
      
      function PyObject_Call(callable, args, kwargs) bind(c, name='PyObject_Call')
        use iso_c_binding
        type(c_ptr), value :: callable
        type(c_ptr), value :: args
        type(c_ptr), value :: kwargs
        type(c_ptr) :: PyObject_Call
      end function

      subroutine PyTuple_SetItem(tup, pos, item) bind(c, name='PyTuple_SetItem')
        use iso_c_binding
        type(c_ptr), value :: tup
        integer(c_size_t), value :: pos
        type(c_ptr), value :: item
      end subroutine

      function PyUnicode_AsUTF8(obj) bind(c, name='PyUnicode_AsUTF8')
        use iso_c_binding
        type(c_ptr), value :: obj
        type(c_ptr) :: PyUnicode_AsUTF8
      end function

      function PyObject_CallMethod(obj, method, format) bind(c, name='PyObject_CallMethod')
        use iso_c_binding
        type(c_ptr), value :: obj
        character(kind=c_char), dimension(*) :: method
        character(kind=c_char), dimension(*) :: format
        type(c_ptr) :: PyObject_CallMethod
      end function

      function PyObject_Str(obj) bind(c, name='PyObject_Str')
        use iso_c_binding
        type(c_ptr), value :: obj
        type(c_ptr) :: PyObject_Str
      end function

      subroutine Py_DecRef(obj) bind(c, name='Py_DecRef')
        use iso_c_binding
        type(c_ptr), value :: obj
      end subroutine

    end interface

    type(c_ptr) :: tank_class, args1, kwargs1, T1, length, diameter
    type(c_ptr) :: tank_ellip, args_ellip, kwargs_ellip, ellip_length
    type(c_ptr) :: args2, kwargs2, DIN, h_max, tank_str
    type(c_ptr) :: h_from_V, V_from_h, SA_from_h
    type(c_ptr) :: arg40, arg41, arg21, result40, result41, result21
    real(c_double) :: tank_length, tank_diameter, ellip_l, max_height
    real(c_double) :: height_40, volume_41, surface_area_21
    character(kind=c_char), pointer :: c_str(:)
    character(len=1000) :: temp_str
    integer :: i
    type(c_ptr) :: str_ptr

    print *, 'Testing tank calculations:'

    ! Get TANK class
    tank_class = PyObject_GetAttrString(py_module, 'TANK'//c_null_char)
    if (.not. c_associated(tank_class)) then
      print *, 'Failed to get TANK class'
      return
    end if

    ! Test basic tank creation
    args1 = PyTuple_New(0_c_size_t)
    kwargs1 = PyDict_New()
    
    call PyDict_SetItemString(kwargs1, 'V'//c_null_char, PyFloat_FromDouble(10.0d0))
    call PyDict_SetItemString(kwargs1, 'L_over_D'//c_null_char, PyFloat_FromDouble(0.7d0))
    call PyDict_SetItemString(kwargs1, 'sideB'//c_null_char, PyUnicode_FromString('conical'//c_null_char))
    call PyDict_SetItemString(kwargs1, 'horizontal'//c_null_char, PyBool_FromLong(0_c_long))

    T1 = PyObject_Call(tank_class, args1, kwargs1)
    if (c_associated(T1)) then
      length = PyObject_GetAttrString(T1, 'L'//c_null_char)
      diameter = PyObject_GetAttrString(T1, 'D'//c_null_char)
      
      if (c_associated(length) .and. c_associated(diameter)) then
        tank_length = PyFloat_AsDouble(length)
        tank_diameter = PyFloat_AsDouble(diameter)
        print *, '✓ Tank length: ', tank_length
        print *, '✓ Tank diameter: ', tank_diameter
      end if
    end if

    ! Test ellipsoidal tank
    args_ellip = PyTuple_New(0_c_size_t)
    kwargs_ellip = PyDict_New()
    
    call PyDict_SetItemString(kwargs_ellip, 'D'//c_null_char, PyFloat_FromDouble(10.0d0))
    call PyDict_SetItemString(kwargs_ellip, 'V'//c_null_char, PyFloat_FromDouble(500.0d0))
    call PyDict_SetItemString(kwargs_ellip, 'horizontal'//c_null_char, PyBool_FromLong(0_c_long))
    call PyDict_SetItemString(kwargs_ellip, 'sideA'//c_null_char, PyUnicode_FromString('ellipsoidal'//c_null_char))
    call PyDict_SetItemString(kwargs_ellip, 'sideB'//c_null_char, PyUnicode_FromString('ellipsoidal'//c_null_char))
    call PyDict_SetItemString(kwargs_ellip, 'sideA_a'//c_null_char, PyFloat_FromDouble(1.0d0))
    call PyDict_SetItemString(kwargs_ellip, 'sideB_a'//c_null_char, PyFloat_FromDouble(1.0d0))

    tank_ellip = PyObject_Call(tank_class, args_ellip, kwargs_ellip)
    if (c_associated(tank_ellip)) then
      ellip_length = PyObject_GetAttrString(tank_ellip, 'L'//c_null_char)
      if (c_associated(ellip_length)) then
        ellip_l = PyFloat_AsDouble(ellip_length)
        print *, '✓ Ellipsoidal tank L: ', ellip_l
      end if
    end if

    ! Test torispherical tank
    args2 = PyTuple_New(0_c_size_t)
    kwargs2 = PyDict_New()
    
    call PyDict_SetItemString(kwargs2, 'L'//c_null_char, PyFloat_FromDouble(3.0d0))
    call PyDict_SetItemString(kwargs2, 'D'//c_null_char, PyFloat_FromDouble(5.0d0))
    call PyDict_SetItemString(kwargs2, 'horizontal'//c_null_char, PyBool_FromLong(0_c_long))
    call PyDict_SetItemString(kwargs2, 'sideA'//c_null_char, PyUnicode_FromString('torispherical'//c_null_char))
    call PyDict_SetItemString(kwargs2, 'sideB'//c_null_char, PyUnicode_FromString('torispherical'//c_null_char))
    call PyDict_SetItemString(kwargs2, 'sideA_f'//c_null_char, PyFloat_FromDouble(1.0d0))
    call PyDict_SetItemString(kwargs2, 'sideA_k'//c_null_char, PyFloat_FromDouble(0.1d0))
    call PyDict_SetItemString(kwargs2, 'sideB_f'//c_null_char, PyFloat_FromDouble(1.0d0))
    call PyDict_SetItemString(kwargs2, 'sideB_k'//c_null_char, PyFloat_FromDouble(0.1d0))

    DIN = PyObject_Call(tank_class, args2, kwargs2)
    if (c_associated(DIN)) then
      ! Get string representation
      tank_str = PyObject_Str(DIN)
      if (c_associated(tank_str)) then
        str_ptr = PyUnicode_AsUTF8(tank_str)
        if (c_associated(str_ptr)) then
          call c_f_pointer(str_ptr, c_str, [1000])
          temp_str = ''
          i = 1
          do while (c_str(i) /= c_null_char .and. i <= 1000)
            temp_str(i:i) = c_str(i)
            i = i + 1
          end do
          print *, '✓ Tank representation: ', trim(temp_str)
        end if
      end if

      ! Get max height
      h_max = PyObject_GetAttrString(DIN, 'h_max'//c_null_char)
      if (c_associated(h_max)) then
        max_height = PyFloat_AsDouble(h_max)
        print *, '✓ Tank max height: ', max_height
      end if

      ! Test h_from_V method
      h_from_V = PyObject_GetAttrString(DIN, 'h_from_V'//c_null_char)
      if (c_associated(h_from_V)) then
        ! Create tuple argument
        arg40 = PyTuple_New(1_c_size_t)
        ! Set tuple item directly
        call PyTuple_SetItem(arg40, 0_c_size_t, PyFloat_FromDouble(40.0d0))
        ! Call method
        result40 = PyObject_Call(h_from_V, arg40, c_null_ptr)
        if (c_associated(result40)) then
          height_40 = PyFloat_AsDouble(result40)
          print *, '✓ Height at V=40: ', height_40

          ! Cleanup
          if (c_associated(result40)) then
            call Py_DecRef(result40)
          end if
        end if

        ! Cleanup
        if (c_associated(h_from_V)) then
          call Py_DecRef(h_from_V)
        end if
        if (c_associated(arg40)) then
          call Py_DecRef(arg40)
        end if
      end if



      ! Test SA_from_h method
      SA_from_h = PyObject_GetAttrString(DIN, 'SA_from_h'//c_null_char)
      if (c_associated(SA_from_h)) then
        ! Create tuple argument
        arg21 = PyTuple_New(1_c_size_t)
        ! Set tuple item directly
        call PyTuple_SetItem(arg21, 0_c_size_t, PyFloat_FromDouble(2.1d0))
        ! Call method
        result21 = PyObject_Call(SA_from_h, arg21, c_null_ptr)
        if (c_associated(result21)) then
          surface_area_21 = PyFloat_AsDouble(result21)
          print *, '✓ Surface area at h=2.1: ', surface_area_21

          ! Cleanup
          if (c_associated(result21)) then
            call Py_DecRef(result21)
          end if
        end if

        ! Cleanup
        if (c_associated(SA_from_h)) then
          call Py_DecRef(SA_from_h)
        end if
        if (c_associated(arg21)) then
          call Py_DecRef(arg21)
        end if
      end if
    end if

  end subroutine test_tank
  ! Helper function to convert C string pointer to Fortran string
  subroutine c_f_string_ptr(c_str, f_str)
    type(c_ptr), intent(in) :: c_str
    character(len=*), pointer, intent(out) :: f_str
    
    character(kind=c_char), pointer :: tmp(:)
    integer :: i, n
    character(len=1000) :: temp_str  ! Temporary buffer
    
    call c_f_pointer(c_str, tmp, [1000])  ! Limited to reasonable size
    n = 0
    do while (tmp(n+1) /= c_null_char .and. n < 1000)
      n = n + 1
      temp_str(n:n) = tmp(n)
    end do
    
    allocate(character(len=n) :: f_str)
    f_str = temp_str(1:n)
  end subroutine

subroutine test_reynolds()
    use iso_c_binding
    implicit none

    interface
      function PyObject_GetAttrString(obj, name) bind(c, name='PyObject_GetAttrString')
        import :: c_ptr, c_char
        type(c_ptr), value :: obj
        character(kind=c_char), dimension(*) :: name
        type(c_ptr) :: PyObject_GetAttrString
      end function
      
      function PyTuple_New(size) bind(c, name='PyTuple_New')
        import :: c_ptr, c_size_t
        integer(c_size_t), value :: size
        type(c_ptr) :: PyTuple_New
      end function
      
      function PyDict_New() bind(c, name='PyDict_New')
        import :: c_ptr
        type(c_ptr) :: PyDict_New
      end function

      function PyFloat_FromDouble(val) bind(c, name='PyFloat_FromDouble')
        import :: c_ptr, c_double
        real(c_double), value :: val
        type(c_ptr) :: PyFloat_FromDouble
      end function
      
      function PyFloat_AsDouble(obj) bind(c, name='PyFloat_AsDouble')
        import :: c_ptr, c_double
        type(c_ptr), value :: obj
        real(c_double) :: PyFloat_AsDouble
      end function
      
      subroutine PyDict_SetItemString(dict, key, val) bind(c, name='PyDict_SetItemString')
        import :: c_ptr, c_char
        type(c_ptr), value :: dict
        character(kind=c_char), dimension(*) :: key
        type(c_ptr), value :: val
      end subroutine
      
      function PyObject_Call(callable, args, kwargs) bind(c, name='PyObject_Call')
        import :: c_ptr
        type(c_ptr), value :: callable
        type(c_ptr), value :: args
        type(c_ptr), value :: kwargs
        type(c_ptr) :: PyObject_Call
      end function
    end interface

    type(c_ptr) :: reynolds_func, args, kwargs, result
    real(c_double) :: Re1, Re2
    logical :: test_passed

    print *, 'Testing Reynolds number calculations:'

    ! Get Reynolds function
    reynolds_func = PyObject_GetAttrString(py_module, "Reynolds"//C_NULL_CHAR)
    if (.not. c_associated(reynolds_func)) then
      print *, 'Failed to get Reynolds function'
      return
    end if

    ! Test with density and viscosity
    args = PyTuple_New(0_c_size_t)
    kwargs = PyDict_New()
    
    call PyDict_SetItemString(kwargs, "V"//C_NULL_CHAR, PyFloat_FromDouble(2.5d0))
    call PyDict_SetItemString(kwargs, "D"//C_NULL_CHAR, PyFloat_FromDouble(0.25d0))
    call PyDict_SetItemString(kwargs, "rho"//C_NULL_CHAR, PyFloat_FromDouble(1.1613d0))
    call PyDict_SetItemString(kwargs, "mu"//C_NULL_CHAR, PyFloat_FromDouble(1.9d-5))
    
    result = PyObject_Call(reynolds_func, args, kwargs)
    if (c_associated(result)) then
      Re1 = PyFloat_AsDouble(result)
      print *, '✓ Re (with rho, mu): ', Re1
      
      ! Assert abs(Re1 - 38200.6579) < 0.1
      test_passed = abs(Re1 - 38200.6579d0) < 0.1d0
      if (test_passed) then
        print *, 'Assert passed: |Re1 - 38200.6579| < 0.1'
      else
        print *, 'Assert failed: |Re1 - 38200.6579| < 0.1'
      end if
    end if

    ! Test with kinematic viscosity
    args = PyTuple_New(0_c_size_t)
    kwargs = PyDict_New()
    
    call PyDict_SetItemString(kwargs, "V"//C_NULL_CHAR, PyFloat_FromDouble(2.5d0))
    call PyDict_SetItemString(kwargs, "D"//C_NULL_CHAR, PyFloat_FromDouble(0.25d0))
    call PyDict_SetItemString(kwargs, "nu"//C_NULL_CHAR, PyFloat_FromDouble(1.636d-5))
    
    result = PyObject_Call(reynolds_func, args, kwargs)
    if (c_associated(result)) then
      Re2 = PyFloat_AsDouble(result)
      print *, '✓ Re (with nu): ', Re2
      
      ! Assert abs(Re2 - 38202.934) < 0.1
      test_passed = abs(Re2 - 38202.934d0) < 0.1d0
      if (test_passed) then
        print *, 'Assert passed: |Re2 - 38202.934| < 0.1'
      else
        print *, 'Assert failed: |Re2 - 38202.934| < 0.1'
      end if
    end if

  end subroutine test_reynolds  
end module
  
program main
  use python_utils
  implicit none
  
  call init_python()
  call test_fluids()
  call test_tank()
  call test_reynolds()
  call benchmark_fluids()
  
  print *, 'All tests completed!'
end program main