Wed, 06 Nov 2024 14:55:47 -0500
Test changes and more saving
src/main.rs | file | annotate | diff | comparison | revisions |
--- a/src/main.rs Wed Nov 06 10:19:59 2024 -0500 +++ b/src/main.rs Wed Nov 06 14:55:47 2024 -0500 @@ -15,7 +15,7 @@ mod zero; mod scaled; -use serde::Serialize; +use serde::{Serialize, Deserialize}; use alg_tools::logger::Logger; use alg_tools::tabledump::{TableDump, write_csv}; use alg_tools::error::DynError; @@ -40,17 +40,38 @@ simple_cube_test().unwrap() } -/// Helper structure for saving the log into a CSV file -#[derive(Serialize)] -struct CSVLog { - iter : usize, - value : f64, +/// Helper structure for saving a point on a cube into a CSV file +#[derive(Serialize,Deserialize,Debug)] +struct CSVPoint { face : Face, x : f64, y : f64, z : f64 } +impl From<&OnCube> for CSVPoint { + fn from(point : &OnCube) -> Self { + let Loc([x,y,z]) = point.embedded_coords(); + let face = point.face(); + CSVPoint { face, x, y, z } + } +} + +/// Helper structure for saving the log into a CSV file +#[derive(Serialize,Deserialize,Debug)] +struct CSVLog { + iter : usize, + value : f64, + // serde is junk + //#[serde(flatten)] + //point : CSVPoint + face : Face, + x : f64, + y : f64, + z : f64 +} + + /// Location for saving results static PREFIX : &str = "res"; @@ -61,24 +82,34 @@ //OnCube::new(F1, Loc([0.5, 0.5])), //OnCube::new(F2, Loc([0.5, 0.5])), //OnCube::new(F4, Loc([0.1, 0.1])), - OnCube::new(F1, Loc([0.5, 0.5])), - OnCube::new(F3, Loc([0.5, 0.5])), - OnCube::new(F2, Loc([0.5, 0.5])), + OnCube::new(F1, Loc([0.5, 0.7])), + OnCube::new(F2, Loc([0.3, 0.5])), + OnCube::new(F4, Loc([0.9, 0.9])), + OnCube::new(F6, Loc([0.4, 0.3])), + OnCube::new(F4, Loc([0.3, 0.7])), + OnCube::new(F3, Loc([0.3, 0.7])), ]; + let origin = OnCube::new(F4, Loc([0.5, 0.5])); + + write_points(format!("{PREFIX}/data"), points.iter())?; + write_points(format!("{PREFIX}/origin"), std::iter::once(&origin))?; + //let x = points[0].clone(); // OnCube::new(F3, Loc([0.5, 0.5])); goes to opposite side - let x = OnCube::new(F3, Loc([0.5, 0.4])); + let x = OnCube::new(F3, Loc([0.1, 0.7])); let f = Sum::new(points.into_iter().map(DistToSquaredDiv2)); //let g = ZeroFn::new(); - let g = Scaled::new(1.0, DistTo(OnCube::new(F4, Loc([0.5, 0.5])))); - let τ = 0.1; + let g = Scaled::new(0.5, DistTo(origin)); + let τ = 0.05; let mut logger = Logger::new(); let logmap = |iter, IterInfo { value, point } : IterInfo<OnCube>| { - let Loc([x,y,z]) = point.embedded_coords(); - let face = point.face(); - CSVLog { iter, value, face, x, y, z } + let CSVPoint {x , y, z, face} = CSVPoint::from(&point); + CSVLog { + iter, value, //point : CSVPoint::from(&point) + x, y, z, face + } }; let iter = AlgIteratorOptions{ max_iter : 100, @@ -95,7 +126,7 @@ logger.write_csv(format!("{PREFIX}/log.txt"))?; for face in Face::all() { - write_face_csv(format!("{PREFIX}/{face}"), face, 64, |x| f.apply(x) + g.apply(x))?; + write_face_csv(format!("{PREFIX}/{face}"), face, 32, |x| f.apply(x) + g.apply(x))?; write_face_img(format!("{PREFIX}/{face}"), face, 128, |x| f.apply(x) + g.apply(x))?; } @@ -148,3 +179,11 @@ Ok(()) } + +/// Writes a list of points on a [`OnCube`] into a CSV file +fn write_points<'a, I : Iterator<Item=&'a OnCube>>(filename : String, list : I) -> DynError { + + write_csv(list.map(CSVPoint::from), format!("{filename}.csv"))?; + Ok(()) +} +