# octave Integration

This example demonstrates how to use fluids from octave.

## Source Code

      1% Test suite for fluids library in Octave
      2% Requires pythonic package or oct2py
      3
      4pkg load pythonic  % Load Python interface
      5
      6function test_fluids()
      7    try
      8        % Test basic module import
      9        fluids = py.importlib.import_module('fluids');
     10        printf('✓ Successfully imported fluids\n');
     11        printf('✓ Fluids version: %s\n', char(fluids.__version__));
     12
     13        % Test basic Reynolds number calculation
     14        Re = double(fluids.Reynolds(pyargs('V', 2.5, 'D', 0.1, 'rho', 1000, 'mu', 0.001)));
     15        printf('✓ Reynolds number calculation successful: %f\n', Re);
     16        assert(Re > 0);
     17
     18        % Test friction factor calculation
     19        fd = double(fluids.friction_factor(pyargs('Re', 1e5, 'eD', 0.0001)));
     20        printf('✓ Friction factor calculation successful: %f\n', fd);
     21        assert(fd > 0 && fd < 1);
     22
     23        printf('\nAll basic tests completed successfully!\n');
     24
     25    catch err
     26        printf('Error occurred: %s\n', err.message);
     27        rethrow(err);
     28    end
     29end
     30
     31function test_atmosphere()
     32    try
     33        fluids = py.importlib.import_module('fluids');
     34        % Test ATMOSPHERE_1976 class
     35        atm = fluids.ATMOSPHERE_1976(pyargs('Z', 5000));
     36
     37        printf('\nTesting atmosphere at 5000m elevation:\n');
     38        printf('✓ Temperature: %.4f\n', double(atm.T));
     39        printf('✓ Pressure: %.4f\n', double(atm.P));
     40        printf('✓ Density: %.6f\n', double(atm.rho));
     41
     42        % Test derived properties
     43        printf('✓ Gravity: %.6f\n', double(atm.g));
     44        printf('✓ Viscosity: %.6e\n', double(atm.mu));
     45        printf('✓ Thermal conductivity: %.6f\n', double(atm.k));
     46        printf('✓ Sonic velocity: %.4f\n', double(atm.v_sonic));
     47
     48        % Test static methods
     49        g_high = double(fluids.ATMOSPHERE_1976.gravity(pyargs('Z', 1E5)));
     50        printf('✓ High altitude gravity: %.6f\n', g_high);
     51
     52        v_sonic = double(fluids.ATMOSPHERE_1976.sonic_velocity(pyargs('T', 300)));
     53        printf('✓ Sonic velocity at 300K: %.4f\n', v_sonic);
     54
     55    catch err
     56        printf('Error in atmosphere tests: %s\n', err.message);
     57        rethrow(err);
     58    end
     59end
     60
     61function test_tank()
     62    try
     63        fluids = py.importlib.import_module('fluids');
     64        % Test basic tank creation
     65        T1 = fluids.TANK(pyargs('V', 10, 'L_over_D', 0.7, 'sideB', 'conical', 'horizontal', false));
     66        printf('\nTesting tank calculations:\n');
     67        printf('✓ Tank length: %.6f\n', double(T1.L));
     68        printf('✓ Tank diameter: %.6f\n', double(T1.D));
     69
     70        % Test ellipsoidal tank
     71        tank_ellip = fluids.TANK(pyargs('D', 10, 'V', 500, 'horizontal', false, ...
     72                                      'sideA', 'ellipsoidal', 'sideB', 'ellipsoidal', ...
     73                                      'sideA_a', 1, 'sideB_a', 1));
     74        printf('✓ Ellipsoidal tank L: %.6f\n', double(tank_ellip.L));
     75
     76        % Test torispherical tank
     77        DIN = fluids.TANK(pyargs('L', 3, 'D', 5, 'horizontal', false, ...
     78                                'sideA', 'torispherical', 'sideB', 'torispherical', ...
     79                                'sideA_f', 1, 'sideA_k', 0.1, 'sideB_f', 1, 'sideB_k', 0.1));
     80
     81        printf('✓ Tank max height: %.6f\n', double(DIN.h_max));
     82        printf('✓ Height at V=40: %.6f\n', double(DIN.h_from_V(40)));
     83        printf('✓ Volume at h=4.1: %.5f\n', double(DIN.V_from_h(4.1)));
     84        printf('✓ Surface area at h=2.1: %.5f\n', double(DIN.SA_from_h(2.1)));
     85
     86    catch err
     87        printf('Error in tank tests: %s\n', err.message);
     88        rethrow(err);
     89    end
     90end
     91
     92function benchmark_fluids()
     93    fluids = py.importlib.import_module('fluids');
     94    printf('\nRunning benchmarks:\n');
     95
     96    % Benchmark friction factor calculation
     97    printf('\nBenchmarking friction_factor:\n');
     98    tic;
     99    for i = 1:1000
    100        fluids.friction_factor(pyargs('Re', 1e5, 'eD', 0.0001));
    101    end
    102    t1 = toc;
    103    printf('Time for 1000 friction_factor calls: %.6f seconds\n', t1);
    104    printf('Average time per call: %.6f seconds\n', t1/1000);
    105
    106    % Benchmark tank creation
    107    printf('\nBenchmarking TANK creation:\n');
    108    tic;
    109    for i = 1:1000
    110        fluids.TANK(pyargs('L', 3, 'D', 5, 'horizontal', false, ...
    111                          'sideA', 'torispherical', 'sideB', 'torispherical', ...
    112                          'sideA_f', 1, 'sideA_k', 0.1, 'sideB_f', 1, 'sideB_k', 0.1));
    113    end
    114    t2 = toc;
    115    printf('Time for 1000 TANK creations: %.6f seconds\n', t2);
    116    printf('Average time per creation: %.6f seconds\n', t2/1000);
    117end
    118
    119% Run all tests
    120printf('Running fluids tests from Octave...\n');
    121test_fluids();
    122test_atmosphere();
    123test_tank();
    124benchmark_fluids();
    125printf('\nAll tests completed!\n');

## Requirements

- Python with fluids installed

- Pythonic: https://gitlab.com/mtmiller/octave-pythonic

## Usage Notes

- The example demonstrates basic integration with fluids

- 1300 microsecond friction factor, 1800 microsecond tank creation observed by author