https://github.com/melchiorrecaruso/adimpas
Type checking of dimensioned quantities at compile time in FreePascal
https://github.com/melchiorrecaruso/adimpas
dimensional-analysis freepascal lazarus pascal type-checking unit-of-measurement
Last synced: 5 months ago
JSON representation
Type checking of dimensioned quantities at compile time in FreePascal
- Host: GitHub
- URL: https://github.com/melchiorrecaruso/adimpas
- Owner: melchiorrecaruso
- License: lgpl-3.0
- Created: 2023-03-26T09:35:06.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-15T14:44:02.000Z (almost 2 years ago)
- Last Synced: 2024-09-15T15:59:02.261Z (almost 2 years ago)
- Topics: dimensional-analysis, freepascal, lazarus, pascal, type-checking, unit-of-measurement
- Language: Pascal
- Homepage:
- Size: 5.91 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING.LGPL
Awesome Lists containing this project
README
# ADimPas Library
Another library for type checking of dimensioned quantities at compile time in FreePascal. From a [circular's](https://github.com/circular17/DimPas) idea.
[](https://github.com/melchiorrecaruso/ADimPas/actions)
## 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
``` pas
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
``` pas
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](adimtest.pas) source code for additional examples.
## Requirements
- [FreePascal compiler (recommended trunk version)](https://www.freepascal.org)
- [Lazarus IDE](https://www.lazarus-ide.org)
## Supported mathematical formulae:
- [Mechanics](doc/mechanics.md)
- [Fluid Mechanics](doc/fluidmechanics.md)
- [Electricity and Magnetism](doc/electricityandmagnetism.md)
- [Heat and Thermodynamics](doc/heatandthermodynamics.md)
- [Waves and Hearing](doc/waves.md)
- [Light and Vision](doc/lightandvision.md)
- [Relativity](doc/relativity.md)
- [Quantum Mechanics](doc/quantummechanics.md)
- [Units of measurement](doc/unitsofmeasurement.md)
## References
- [HyperPhysics](http://hyperphysics.phy-astr.gsu.edu/hbase/hframe.html)
- [University Physics Volume 1](https://openstax.org/details/books/university-physics-volume-1)
- [University Physics Volume 2](https://openstax.org/details/books/university-physics-volume-2)
- [University Physics Volume 3](https://openstax.org/details/books/university-physics-volume-3)
- [National Institute of Standards and Technology](https://www.nist.gov/pml/owm/metric-si/si-units)
- [Bureau international des poids et mesures](https://www.bipm.org/en/)
## LICENSE
[GNU Lesser General Public License v3.0](https://github.com/melchiorrecaruso/ADimPas/blob/main/LICENSE)