From 32a15318bf04f6d54f33128540e435dc8dabad64 Mon Sep 17 00:00:00 2001 From: jsampaio Date: Thu, 11 Jan 2018 12:21:20 +0100 Subject: [PATCH 1/6] Update relax.go changing stopping criterion --- engine/relax.go | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/engine/relax.go b/engine/relax.go index 2986e71cc..7699f7626 100644 --- a/engine/relax.go +++ b/engine/relax.go @@ -7,8 +7,12 @@ import ( "math" ) +var thresholdTorque := 1e-3; //to be replaced by a sane default value + func init() { DeclFunc("Relax", Relax, "Try to minimize the total energy") + DeclVar("RelaxThresholdTorque", &thresholdTorque, "Stopping maximum torque threshold for relax()") + } // are we relaxing? @@ -55,26 +59,23 @@ func Relax() { } // Now we are already close to equilibrium, but energy is too noisy to be used any further. - // So now we minimize the total torque which is less noisy and does not have to cross any - // bumps once we are close to equilibrium. + // So now we minimize the maximum torque which is less noisy. solver := stepper.(*RK23) defer stepper.Free() // purge previous rk.k1 because FSAL will be dead wrong. - avgTorque := func() float32 { - return cuda.Dot(solver.k1, solver.k1) - } - var T0, T1 float32 = 0, avgTorque() - - // Step as long as torque goes down. Then increase the accuracy and step more. - for MaxErr > 1e-9 && !pause { + + maxTorque := func() float32 { + return cuda.MaxVecNorm(solver.k1) //perhaps replace by (faster?) sqrt(3)*cuda.MaxAbs(...)? + } + // run as long as the max torque is above threshold. Then increase the accuracy and step more. + for !pause { + for maxTorque() < thresholdTorque && !pause { + relaxSteps(N) + } MaxErr /= math.Sqrt2 - relaxSteps(N) // TODO: Play with other values - T0, T1 = T1, avgTorque() - for T1 < T0 && !pause { - relaxSteps(N) // TODO: Play with other values - T0, T1 = T1, avgTorque() + if MaxErr < 1e-9 { + break } - } - + } pause = true } From 7f9d16243c7477b6027f512b2888ff00f0c48b3b Mon Sep 17 00:00:00 2001 From: jsampaio Date: Thu, 11 Jan 2018 16:44:43 +0100 Subject: [PATCH 2/6] Update relax.go --- engine/relax.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/relax.go b/engine/relax.go index 7699f7626..08b2952d0 100644 --- a/engine/relax.go +++ b/engine/relax.go @@ -7,7 +7,7 @@ import ( "math" ) -var thresholdTorque := 1e-3; //to be replaced by a sane default value +var thresholdTorque float64 = 1e-3; //to be replaced by a sane default value func init() { DeclFunc("Relax", Relax, "Try to minimize the total energy") From e1c9d8d9defb63e135f05c8bbc130455f211b01d Mon Sep 17 00:00:00 2001 From: jsampaio Date: Thu, 11 Jan 2018 18:21:11 +0100 Subject: [PATCH 3/6] Update relax.go --- engine/relax.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/engine/relax.go b/engine/relax.go index 08b2952d0..a47c93c0a 100644 --- a/engine/relax.go +++ b/engine/relax.go @@ -7,12 +7,11 @@ import ( "math" ) -var thresholdTorque float64 = 1e-3; //to be replaced by a sane default value +var thresholdTorque float64 = 1e-3; //in T. The user can check MaxTorque for sane values func init() { DeclFunc("Relax", Relax, "Try to minimize the total energy") - DeclVar("RelaxThresholdTorque", &thresholdTorque, "Stopping maximum torque threshold for relax()") - + DeclVar("RelaxTorqueThreshold", &thresholdTorque, "Torque threshold for relax()") } // are we relaxing? @@ -63,19 +62,18 @@ func Relax() { solver := stepper.(*RK23) defer stepper.Free() // purge previous rk.k1 because FSAL will be dead wrong. - maxTorque := func() float32 { - return cuda.MaxVecNorm(solver.k1) //perhaps replace by (faster?) sqrt(3)*cuda.MaxAbs(...)? + maxTorque := func() float64 { //the user can see the values of MaxTorque. + return cuda.MaxVecNorm(solver.k1) } + // run as long as the max torque is above threshold. Then increase the accuracy and step more. for !pause { - for maxTorque() < thresholdTorque && !pause { + for maxTorque() > thresholdTorque && !pause { relaxSteps(N) } MaxErr /= math.Sqrt2 - if MaxErr < 1e-9 { - break - } - } + if MaxErr < 1e-9 { break; } + } pause = true } From de8c4c913ed87518414c0649894e044f015ce809 Mon Sep 17 00:00:00 2001 From: jsampaio Date: Thu, 11 Jan 2018 18:35:16 +0100 Subject: [PATCH 4/6] Update relax.go --- engine/relax.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/relax.go b/engine/relax.go index a47c93c0a..fec7d5992 100644 --- a/engine/relax.go +++ b/engine/relax.go @@ -7,11 +7,11 @@ import ( "math" ) -var thresholdTorque float64 = 1e-3; //in T. The user can check MaxTorque for sane values +var RelaxTorqueThreshold float64 = 1e-3; //in T. The user can check MaxTorque for sane values func init() { DeclFunc("Relax", Relax, "Try to minimize the total energy") - DeclVar("RelaxTorqueThreshold", &thresholdTorque, "Torque threshold for relax()") + DeclVar("RelaxTorqueThreshold", &RelaxTorqueThreshold, "Torque threshold for relax()") } // are we relaxing? @@ -68,7 +68,7 @@ func Relax() { // run as long as the max torque is above threshold. Then increase the accuracy and step more. for !pause { - for maxTorque() > thresholdTorque && !pause { + for maxTorque() > RelaxTorqueThreshold && !pause { relaxSteps(N) } MaxErr /= math.Sqrt2 From 4bd8b2483d34e12d91cec4bc540295e7ca17ac37 Mon Sep 17 00:00:00 2001 From: jsampaio Date: Wed, 17 Jan 2018 14:55:33 +0100 Subject: [PATCH 5/6] keep old behaviour by default. Changed to keep previous relax() behaviour by default. When RelaxTorqueThreshold < 0, relax() will stop when the average torque rises (previous behaviour). The default value for RelaxTorqueThreshold is now -1. --- engine/relax.go | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/engine/relax.go b/engine/relax.go index fec7d5992..0bb0c34c8 100644 --- a/engine/relax.go +++ b/engine/relax.go @@ -7,11 +7,13 @@ import ( "math" ) -var RelaxTorqueThreshold float64 = 1e-3; //in T. The user can check MaxTorque for sane values +//Stopping relax Maxtorque in T. The user can check MaxTorque for sane values (e.g. 1e-3). +// If set to 0, relax() will stop when the average torque is steady or increasing. +var RelaxTorqueThreshold float64 = -1.; func init() { DeclFunc("Relax", Relax, "Try to minimize the total energy") - DeclVar("RelaxTorqueThreshold", &RelaxTorqueThreshold, "Torque threshold for relax()") + DeclVar("RelaxTorqueThreshold", &RelaxTorqueThreshold, "MaxTorque threshold for relax(). If set to -1 (default), relax() will stop when the average torque is steady or increasing.") } // are we relaxing? @@ -58,22 +60,40 @@ func Relax() { } // Now we are already close to equilibrium, but energy is too noisy to be used any further. - // So now we minimize the maximum torque which is less noisy. + // So now we minimize the torque which is less noisy. solver := stepper.(*RK23) defer stepper.Free() // purge previous rk.k1 because FSAL will be dead wrong. - maxTorque := func() float64 { //the user can see the values of MaxTorque. + maxTorque := func() float64 { return cuda.MaxVecNorm(solver.k1) - } - - // run as long as the max torque is above threshold. Then increase the accuracy and step more. - for !pause { - for maxTorque() > RelaxTorqueThreshold && !pause { - relaxSteps(N) - } - MaxErr /= math.Sqrt2 - if MaxErr < 1e-9 { break; } } + avgTorque := func() float32 { + return cuda.Dot(solver.k1, solver.k1) + } + + if RelaxTorqueThreshold > 0 { + // run as long as the max torque is above threshold. Then increase the accuracy and step more. + for !pause { + for maxTorque() > RelaxTorqueThreshold && !pause { + relaxSteps(N) + } + MaxErr /= math.Sqrt2 + if MaxErr < 1e-9 { break; } + } + } else { + // previous ( Date: Thu, 18 Jan 2018 18:18:41 +0100 Subject: [PATCH 6/6] Update relax.go default behaviour is now exactly the previous one. --- engine/relax.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/engine/relax.go b/engine/relax.go index 0bb0c34c8..3a9d65e77 100644 --- a/engine/relax.go +++ b/engine/relax.go @@ -82,16 +82,17 @@ func Relax() { } } else { // previous ( 1e-9 && !pause { + MaxErr /= math.Sqrt2 + relaxSteps(N) // TODO: Play with other values T0, T1 = T1, avgTorque() for T1 < T0 && !pause { - relaxSteps(N) + relaxSteps(N) // TODO: Play with other values T0, T1 = T1, avgTorque() } - MaxErr /= math.Sqrt2 - if MaxErr < 1e-9 { break; } } } pause = true