aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--credit.txt5
-rw-r--r--fluid.gpr81
-rw-r--r--readme.md33
-rw-r--r--readme.txt24
-rw-r--r--src/ansi_terminal.adb15
-rw-r--r--src/ansi_terminal.ads9
-rw-r--r--src/datatypes.adb8
-rw-r--r--src/datatypes.ads9
-rw-r--r--src/fluid_simulator.adb37
9 files changed, 173 insertions, 48 deletions
diff --git a/credit.txt b/credit.txt
deleted file mode 100644
index b5a6194..0000000
--- a/credit.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-
-This project was written and programmed by Jedidiah Barber.
-
-See http://jedbarber.id.au/ for other details.
-
diff --git a/fluid.gpr b/fluid.gpr
index 1a7a74e..312920b 100644
--- a/fluid.gpr
+++ b/fluid.gpr
@@ -1,20 +1,93 @@
+
project Fluid is
+
for Languages use ("Ada");
- for Source_Dirs use ("src/**");
- for Object_Dir use "obj";
- for Exec_Dir use "bin";
+ for Source_Dirs use ("src");
+ for Object_Dir use "obj";
+ for Exec_Dir use "bin";
+
for Main use ("fluid_simulator.adb");
+
+ type Build_Kind is ("release", "debug");
+
+ Ver : Build_Kind := external ("build", "release");
+
+
package Builder is
for Executable ("fluid_simulator.adb") use "fluid";
+
+ for Default_Switches ("Ada") use ("-j4", "-m");
+ for Global_Compilation_Switches ("Ada") use ("-shared");
+
+ case Ver is
+ when "release" =>
+ null;
+ when "debug" =>
+ for Default_Switches ("Ada") use Builder'Default_Switches ("Ada") & "-g";
+ end case;
end Builder;
+
+ Ada_Common :=
+ ("-gnaty"
+ & "4" -- indentation
+ & "a" -- attribute casing
+ & "A" -- array attribute indices
+ & "b" -- blanks at end of lines
+ & "c" -- two space comments
+ & "e" -- end/exit labels
+ & "f" -- no form feeds or vertical tabs
+ & "h" -- no horizontal tabs
+ & "i" -- if/then layout
+ & "k" -- keyword casing
+ & "l" -- reference manual layout
+ & "M100" -- max line length
+ & "n" -- package Standard casing
+ & "p" -- pragma casing
+ & "r" -- identifier casing
+ & "t", -- token separation
+ "-gnatw"
+ & "a" -- various warning modes
+ & "F" -- don't check for unreferenced formal parameters
+ & "J" -- don't check for obsolescent feature use
+ & "U"); -- don't check for unused entities
+
package Compiler is
- for Default_Switches("Ada") use ("-gnaty4aAbcefhiklM100nprt");
+ case Ver is
+ when "release" =>
+ for Default_Switches ("Ada") use Ada_Common & "-O3" & "-gnatn";
+ when "debug" =>
+ for Default_Switches ("Ada") use Ada_Common & "-O0" & "-gnata" & "-gnato" & "-g";
+ end case;
end Compiler;
+
+ package Binder is
+ for Default_Switches ("Ada") use ("-shared");
+
+ case Ver is
+ when "release" =>
+ null;
+ when "debug" =>
+ for Default_Switches ("Ada") use Binder'Default_Switches ("Ada") & "-Es";
+ end case;
+ end Binder;
+
+
+ package Linker is
+ case Ver is
+ when "release" =>
+ null;
+ when "debug" =>
+ for Default_Switches ("Ada") use ("-g");
+ end case;
+ end Linker;
+
+
end Fluid;
+
diff --git a/readme.md b/readme.md
new file mode 100644
index 0000000..5e20917
--- /dev/null
+++ b/readme.md
@@ -0,0 +1,33 @@
+
+## ASCII Fluid Simulator
+
+This project duplicates the functionality of an ASCII fluid simulator written
+by Yusuke Endoh for an
+[IOCCC entry in 2012](https://web.archive.org/web/20190311013952/http://www.ioccc.org/2012/endoh1/).
+
+While the functionality was duplicated, the original code was too obfuscated to
+use as a guide and so this project was essentially written from scratch.
+
+
+
+#### Build Instructions
+
+To compile, use
+
+`gprbuild fluid.gpr`
+
+and to run, redirect an input file into the program's standard input
+
+`bin/fluid < data/column.txt`
+
+Several such input files can be found in the `data` subdirectory.
+
+
+
+#### Credits and Licensing
+
+Written by Jedidiah Barber.
+
+Licensed under the Sunset License v1.0. For details see `license.txt`.
+
+
diff --git a/readme.txt b/readme.txt
deleted file mode 100644
index 4d09bae..0000000
--- a/readme.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-
-ASCII Fluid Simulator
-=====================
-
-
-This project duplicates the functionality of an ASCII fluid simulator written by Yusuke Endoh for
-an IOCCC entry in 2012. The original entry can be viewed at
-
- https://web.archive.org/web/20190311013952/http://www.ioccc.org/2012/endoh1/
-
-While the functionality was duplicated, the original code was too obfuscated to use as a guide and
-so this project was essentially written from scratch.
-
-
-
-To compile, use
-
- gprbuild fluid.gpr
-
-and to run, redirect an input file into the program's standard input
-
- bin/fluid < data/column.txt
-
-
diff --git a/src/ansi_terminal.adb b/src/ansi_terminal.adb
index c356c21..8e47d06 100644
--- a/src/ansi_terminal.adb
+++ b/src/ansi_terminal.adb
@@ -1,10 +1,18 @@
+
+-- Programmed by Jedidiah Barber
+-- Licensed under the Sunset License v1.0
+
+-- See license.txt for further details
+
+
with
Ada.Characters.Latin_1,
Ada.Strings.Fixed,
Ada.Text_IO;
+
package body ANSI_Terminal is
package Latin renames Ada.Characters.Latin_1;
@@ -60,8 +68,10 @@ package body ANSI_Terminal is
X, Y : in Integer)
return String
is
- Average_Density : Natural := Integer (Quantity'Ceiling (Input (X, Y).Density / 4.0));
- Bit_Index : Positive := Integer (Input (X, Y).Index) + 1;
+ Average_Density : constant Natural :=
+ Integer (Quantity'Ceiling (Input (X, Y).Density / 4.0));
+ Bit_Index : constant Positive :=
+ Integer (Input (X, Y).Index) + 1;
Choice : Natural;
begin
case Average_Density is
@@ -121,3 +131,4 @@ package body ANSI_Terminal is
end ANSI_Terminal;
+
diff --git a/src/ansi_terminal.ads b/src/ansi_terminal.ads
index 027f771..9167f1f 100644
--- a/src/ansi_terminal.ads
+++ b/src/ansi_terminal.ads
@@ -1,8 +1,16 @@
+
+-- Programmed by Jedidiah Barber
+-- Licensed under the Sunset License v1.0
+
+-- See license.txt for further details
+
+
with
Datatypes;
+
package ANSI_Terminal is
function Clear_Screen
@@ -39,3 +47,4 @@ private
end ANSI_Terminal;
+
diff --git a/src/datatypes.adb b/src/datatypes.adb
index 64ff017..30f2d86 100644
--- a/src/datatypes.adb
+++ b/src/datatypes.adb
@@ -1,4 +1,11 @@
+
+-- Programmed by Jedidiah Barber
+-- Licensed under the Sunset License v1.0
+
+-- See license.txt for further details
+
+
package body Datatypes is
@@ -13,3 +20,4 @@ package body Datatypes is
end Datatypes;
+
diff --git a/src/datatypes.ads b/src/datatypes.ads
index 50d21f9..403bf0e 100644
--- a/src/datatypes.ads
+++ b/src/datatypes.ads
@@ -1,9 +1,17 @@
+
+-- Programmed by Jedidiah Barber
+-- Licensed under the Sunset License v1.0
+
+-- See license.txt for further details
+
+
with
Ada.Numerics.Generic_Complex_Types,
Ada.Containers.Vectors;
+
package Datatypes is
type Quantity is digits 18;
@@ -31,3 +39,4 @@ package Datatypes is
end Datatypes;
+
diff --git a/src/fluid_simulator.adb b/src/fluid_simulator.adb
index 4f33a2f..b13f107 100644
--- a/src/fluid_simulator.adb
+++ b/src/fluid_simulator.adb
@@ -1,4 +1,11 @@
+
+-- Programmed by Jedidiah Barber
+-- Licensed under the Sunset License v1.0
+
+-- See license.txt for further details
+
+
with
Datatypes,
@@ -14,6 +21,7 @@ use type
Datatypes.Plane.Complex;
+
procedure Fluid_Simulator is
package ANSI renames ANSI_Terminal;
@@ -87,19 +95,21 @@ procedure Fluid_Simulator is
Rij : Quantity;
begin
for P of Store loop
- P.Acceleration := Gravity_Factor;
- for Q of Store loop
- Displacement := P.Place - Q.Place;
- Rij := Plane.Modulus (Displacement);
- if Rij < Particle_Radius then
- Pressure := (P.Density + Q.Density - 2.0 * P0) *
- Pressure_Factor * Displacement;
- Viscosity := (P.Velocity - Q.Velocity) * Viscosity_Factor;
- P.Acceleration := P.Acceleration +
- Plane.Compose_From_Cartesian (1.0 - Rij / Particle_Radius) /
- P.Density * (Pressure - Viscosity);
- end if;
- end loop;
+ if not P.Solid then
+ P.Acceleration := Gravity_Factor;
+ for Q of Store loop
+ Displacement := P.Place - Q.Place;
+ Rij := Plane.Modulus (Displacement);
+ if Rij < Particle_Radius then
+ Pressure := (P.Density + Q.Density - 2.0 * P0) *
+ Pressure_Factor * Displacement;
+ Viscosity := (P.Velocity - Q.Velocity) * Viscosity_Factor;
+ P.Acceleration := P.Acceleration +
+ Plane.Compose_From_Cartesian (1.0 - Rij / Particle_Radius) /
+ P.Density * (Pressure - Viscosity);
+ end if;
+ end loop;
+ end if;
end loop;
end Calculate_Interaction;
@@ -150,3 +160,4 @@ begin
end Fluid_Simulator;
+