Skip to content

Latest commit

 

History

History
92 lines (74 loc) · 3.16 KB

README.md

File metadata and controls

92 lines (74 loc) · 3.16 KB

ADimPas Library

Another library for type checking of dimensioned quantities at compile time in FreePascal. From a circular's idea.

Actions Status

What it's

Ensuring coherence of physical dimensions in physical equations or mathematical relationships involving various variables is crucial. Dimensional analysis provides a fundamental tool to verify this coherence and correct any errors in the expressions.

The ADim library allows defining variables and constants in terms of quantity and units of measurement, automating dimensional analysis at compilation time.

How to use

Example 1: Calculate speed

uses
  ADim;
var 
  distance: TMeters;
  time:     TSeconds;
  speed:    TMetersPerSecond;  
begin
  distance := 5000*m;
  time     := 2*hr;
  speed    := distance/time;
  
  writeln('The value of speed is ', speed.ToKilometerPerHour.ToString);
end;

Output:

The value of speed is 2.5 km/h

Example 2: Calculate Borh radius

uses
  ADim;
var 
  plank:  TJouleSeconds;
  e0:     TFaradsPerMeter;
  ke:     TNewtonSquareMetersPerSquareCoulomb;  
  mass:   TKilograms;
  charge: TCoulombs;  
  radius: TMeters;
begin
  plank  := 6.62607015E-34*J*s;    // Planck constant
  e0     := 8.8541878128E-12*F/m;  // vacuum permittivity
  ke     := 1/(4*pi*e0);           // Coulomb constant
  mass   := 9.1093837015E-31*kg;   // mass of an electron
  charge := 1.602176634E-19*C;     // charge of an electron   
  radius := (SquarePower(plank/2/pi)/mass)/(ke*SquarePower(charge)); 

  writeln('The value of the Bohr radius is ', radius.ToString(10, 10, [pNano]));      
end;

Output:

The value of the Bohr radius is 0.05291772109 nm

Refer to the adimtest source code for additional examples.

Requirements

Supported mathematical formulae:

References

LICENSE

GNU Lesser General Public License v3.0