Spring class with run time energy methods

For simulations at small scales or in highly viscous liquids, Langevin dynamics and Monte Carlo methods can be computationally efficient. To implement these computations, methods are needed to return the energies and force vectors associated with Springs. The code below can be inserted into the base Spring class to implement three new methods, "get-energy", "get-energy-derivative" and "get-strength".

This implementation uses the Steve language rather than diving into the C code, although an implementation in the latter might be computationally more efficient.

	+ to get-strength:
		return strength.
	
	+ to get-energy:
		lcur (double).
		if springPointer: {
			lcur = (springGetCurrentLength(springPointer)).
			return 0.5*(lcur - length)*(lcur - length).
		}
		else: return 0.0.

	+ to get-energy-derivative:
		lcur (double).
		f (vector).
		if springPointer: {
			f = ((start get-location) - (end get-location)).
			if |f| == 0.0: return (0.0, 0.0, 0.0).
			lcur = (springGetCurrentLength(springPointer)).
			return (lcur - length) * f / |f|.
		}
		else: return (0.0, 0.0, 0.0).

David

P.S. Documentation and code are available at http://www.stateslab.org/Software/Breve/Spring.html and http://www.stateslab.org/Software/Breve/Spring.tz

Not Exactly

Energy Potentials need to be calculated over the entire range of movement. Example:
+ get-energy:
i,n (int).
fx (list).
x (float).
n = | fx |
for i = 1, i < n , i++ : {
x+=sqrt((1/i)*fx{ i }^2+fx{ i - 1 }^2).
}
return x.
.
.
.
+to iterate:
count++.
fx = move-spring.
while count < 100: {
x' = self get-energy.
}

A quick approximation of the above could be over 1000 iterations, and at fx{990} could be the original position.

spring.tz -> getting 404

i am getting 404 error,when i want to download the spring.tz

please update the thread.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.