38 /// Program entry point |
38 /// Program entry point |
39 fn main() { |
39 fn main() { |
40 simple_cube_test().unwrap() |
40 simple_cube_test().unwrap() |
41 } |
41 } |
42 |
42 |
43 /// Helper structure for saving the log into a CSV file |
43 /// Helper structure for saving a point on a cube into a CSV file |
44 #[derive(Serialize)] |
44 #[derive(Serialize,Deserialize,Debug)] |
45 struct CSVLog { |
45 struct CSVPoint { |
46 iter : usize, |
|
47 value : f64, |
|
48 face : Face, |
46 face : Face, |
49 x : f64, |
47 x : f64, |
50 y : f64, |
48 y : f64, |
51 z : f64 |
49 z : f64 |
52 } |
50 } |
|
51 |
|
52 impl From<&OnCube> for CSVPoint { |
|
53 fn from(point : &OnCube) -> Self { |
|
54 let Loc([x,y,z]) = point.embedded_coords(); |
|
55 let face = point.face(); |
|
56 CSVPoint { face, x, y, z } |
|
57 } |
|
58 } |
|
59 |
|
60 /// Helper structure for saving the log into a CSV file |
|
61 #[derive(Serialize,Deserialize,Debug)] |
|
62 struct CSVLog { |
|
63 iter : usize, |
|
64 value : f64, |
|
65 // serde is junk |
|
66 //#[serde(flatten)] |
|
67 //point : CSVPoint |
|
68 face : Face, |
|
69 x : f64, |
|
70 y : f64, |
|
71 z : f64 |
|
72 } |
|
73 |
53 |
74 |
54 /// Location for saving results |
75 /// Location for saving results |
55 static PREFIX : &str = "res"; |
76 static PREFIX : &str = "res"; |
56 |
77 |
57 /// A simple test on the cube |
78 /// A simple test on the cube |
59 |
80 |
60 let points = [ |
81 let points = [ |
61 //OnCube::new(F1, Loc([0.5, 0.5])), |
82 //OnCube::new(F1, Loc([0.5, 0.5])), |
62 //OnCube::new(F2, Loc([0.5, 0.5])), |
83 //OnCube::new(F2, Loc([0.5, 0.5])), |
63 //OnCube::new(F4, Loc([0.1, 0.1])), |
84 //OnCube::new(F4, Loc([0.1, 0.1])), |
64 OnCube::new(F1, Loc([0.5, 0.5])), |
85 OnCube::new(F1, Loc([0.5, 0.7])), |
65 OnCube::new(F3, Loc([0.5, 0.5])), |
86 OnCube::new(F2, Loc([0.3, 0.5])), |
66 OnCube::new(F2, Loc([0.5, 0.5])), |
87 OnCube::new(F4, Loc([0.9, 0.9])), |
|
88 OnCube::new(F6, Loc([0.4, 0.3])), |
|
89 OnCube::new(F4, Loc([0.3, 0.7])), |
|
90 OnCube::new(F3, Loc([0.3, 0.7])), |
67 ]; |
91 ]; |
|
92 |
|
93 let origin = OnCube::new(F4, Loc([0.5, 0.5])); |
|
94 |
|
95 write_points(format!("{PREFIX}/data"), points.iter())?; |
|
96 write_points(format!("{PREFIX}/origin"), std::iter::once(&origin))?; |
68 |
97 |
69 //let x = points[0].clone(); |
98 //let x = points[0].clone(); |
70 // OnCube::new(F3, Loc([0.5, 0.5])); goes to opposite side |
99 // OnCube::new(F3, Loc([0.5, 0.5])); goes to opposite side |
71 let x = OnCube::new(F3, Loc([0.5, 0.4])); |
100 let x = OnCube::new(F3, Loc([0.1, 0.7])); |
72 let f = Sum::new(points.into_iter().map(DistToSquaredDiv2)); |
101 let f = Sum::new(points.into_iter().map(DistToSquaredDiv2)); |
73 //let g = ZeroFn::new(); |
102 //let g = ZeroFn::new(); |
74 let g = Scaled::new(1.0, DistTo(OnCube::new(F4, Loc([0.5, 0.5])))); |
103 let g = Scaled::new(0.5, DistTo(origin)); |
75 let τ = 0.1; |
104 let τ = 0.05; |
76 |
105 |
77 let mut logger = Logger::new(); |
106 let mut logger = Logger::new(); |
78 let logmap = |iter, IterInfo { value, point } : IterInfo<OnCube>| { |
107 let logmap = |iter, IterInfo { value, point } : IterInfo<OnCube>| { |
79 let Loc([x,y,z]) = point.embedded_coords(); |
108 let CSVPoint {x , y, z, face} = CSVPoint::from(&point); |
80 let face = point.face(); |
109 CSVLog { |
81 CSVLog { iter, value, face, x, y, z } |
110 iter, value, //point : CSVPoint::from(&point) |
|
111 x, y, z, face |
|
112 } |
82 }; |
113 }; |
83 let iter = AlgIteratorOptions{ |
114 let iter = AlgIteratorOptions{ |
84 max_iter : 100, |
115 max_iter : 100, |
85 verbose_iter : Verbose::Every(1), |
116 verbose_iter : Verbose::Every(1), |
86 .. Default::default() |
117 .. Default::default() |