Skip to content
Snippets Groups Projects
Commit 1eaf5036 authored by Michael Leuschel's avatar Michael Leuschel
Browse files

first working version of physics model

parent 20136c1c
No related branches found
No related tags found
No related merge requests found
MACHINE MovingParticles
INCLUDES Vectors
DEFINITIONS
"LibraryReals.def";
"LibraryReals.def"; "SORT.def";
MASS == FLOAT;
POS == FLOAT;
SPEED == FLOAT;
......@@ -10,13 +10,25 @@ DEFINITIONS
SCALE == 1.25e11; // 100 % in visualisation
SCALE100 == (SCALE/100.0);
SPEED_MULTIPLIER == 1000000.0;
MAXMASS == 1.989e30
GRAV_MULTIPLIER == 1000000000000.0;
MAXMASS == 1.989e30;
gravitation == %i.(i:OBJ | sigma_vecs(
SQUASH(
%j.(j:OBJ & j/=i |
times_vec( force_between(i,j,pos(i),pos(j)) / mass(i) ,
unit_vec(delta_vec(pos(j),pos(i)))))
) ) ) // acceleration
ABSTRACT_CONSTANTS
force_between
CONSTANTS mass, nobjs
PROPERTIES
nobjs : 1..10 &
mass : OBJ --> MASS &
force_between = %(a,b,pa,pb).(a:OBJ & b:OBJ & a/=b | (G * mass(a) * mass(b)) / (distance(pa,pb)**2))
&
n = 2 & // two dimensional space
nobjs = 3 & mass = [5.97e24, 1.989e30, 1.989e30]
VARIABLES pos, speed
......@@ -27,9 +39,10 @@ INITIALISATION pos := [ [0.0,0.0] , [0.0,4.5e10] , [0.0,-4.5e10 ] ] ||
speed := [ [0.05e04,0.0], [3.0e04,0.0], [-3.0e04,0.0] ]
OPERATIONS
r <-- ForceBetween(a,b) = PRE a:OBJ & b:OBJ & a/= b THEN
r := (G * mass(a) * mass(b)) / (distance(pos(a),pos(b))**2)
r := force_between(a,b,pos(a),pos(b))
END;
Move(delta) = PRE delta:REAL & delta = 100000.0 THEN
Move(delta) = PRE delta:REAL & delta = 10000.0 THEN
speed := %i.(i:OBJ | add_vec(speed(i),times_vec(delta,gravitation(i)) )) ||
pos := %i.(i:OBJ | add_vec(pos(i),times_vec(delta,speed(i))) )
END
END
......
......@@ -13,7 +13,9 @@ ABSTRACT_CONSTANTS
distance,
add_first,
sigma_reals
sigma_reals,
add_firstv,
sigma_vecs
PROPERTIES
n:NATURAL1 &
DIM = (1..n) &
......@@ -22,6 +24,9 @@ PROPERTIES
add_first = %v.(v:seq1(REAL) | (v(1)+v(2)) -> tail(tail(v))) &
sigma_reals = %v.(v:VEC | (iterate(add_first,n-1)(v))(1)) &
add_firstv = %v.(v:seq1(VEC) | add_vec(v(1),v(2)) -> tail(tail(v))) &
sigma_vecs = %v.(v:seq1(VEC) | (iterate(add_firstv,size(v)-1)(v))(1)) &
add_vec = %(v1,v2).(v1:VEC & v2:VEC | %i.(i:DIM| v1(i)+v2(i))) &
delta_vec = %(v1,v2).(v1:VEC & v2:VEC | %i.(i:DIM| v1(i)-v2(i))) &
// dot_product = %(v1,v2).(v1:VEC & v2:VEC | SIGMA(i).(i:DIM| v1(i)*v2(i))) &
......
......@@ -44,6 +44,31 @@
"id": "speed%0",
"attr": "y2",
"value" : "(pos(%0)(2)+ SPEED_MULTIPLIER*speed(%0)(2)) / SCALE100"
},
{
"for": {"from":1, "to":3},
"id": "gravitation%0",
"attr": "x1",
"value" : "pos(%0)(1) / SCALE100"
},
{
"for": {"from":1, "to":3},
"id": "gravitation%0",
"attr": "y1",
"value" : "pos(%0)(2) / SCALE100"
},
{
"for": {"from":1, "to":3},
"id": "gravitation%0",
"attr": "x2",
"value" : "(pos(%0)(1)+ GRAV_MULTIPLIER*gravitation(%0)(1)) / SCALE100"
},
{
"for": {"from":1, "to":3},
"id": "gravitation%0",
"attr": "y2",
"value" : "(pos(%0)(2)+ GRAV_MULTIPLIER*gravitation(%0)(2)) / SCALE100"
}
],
"events": [
......
......@@ -14,12 +14,12 @@
<marker id="startarrow" markerWidth="10" markerHeight="7"
refX="10" refY="3.5" orient="auto">
<polygon points="10 0, 10 7, 0 3.5" fill="blue" />
<polygon points="10 0, 10 7, 0 3.5" fill="green" />
</marker>
<marker id="endarrow" markerWidth="10" markerHeight="7"
refX="0" refY="3.5" orient="auto">
<polygon points="0 0, 10 3.5, 0 7" fill="blue" />
<polygon points="0 0, 10 3.5, 0 7" fill="green" />
</marker>
</defs>
......@@ -47,4 +47,17 @@
id = "speed3"
/>
<line x1="45" y1="15" x2="55" y2="15" stroke="green"
stroke-width="0.3" marker-end="url(#endarrow)"
id = "gravitation1"
/>
<line x1="5" y1="15" x2="0" y2="0" stroke="green"
stroke-width="0.3" marker-end="url(#endarrow)"
id = "gravitation2"
/>
<line x1="35" y1="45" x2="35" y2="55" stroke="green"
stroke-width="0.3" marker-end="url(#endarrow)"
id = "gravitation3"
/>
</svg>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment