1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use std::fmt::Display;

use crate::Cell;

use super::CellSettingExport;

#[derive(Debug, Clone, Copy)]
pub struct ExternalEField {
    ex: f64,
    ey: f64,
    ez: f64,
}

impl Default for ExternalEField {
    fn default() -> Self {
        Self {
            ex: 0.0,
            ey: 0.0,
            ez: 0.0,
        }
    }
}

impl Display for ExternalEField {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(f, "{:16.10}{:16.10}{:16.10}", self.ex, self.ey, self.ez)
    }
}

impl CellSettingExport for ExternalEField {
    fn write_to_cell(&self) -> String {
        Cell::write_block(("EXTERNAL_EFIELD".into(), format!("{self}")))
    }
}

#[derive(Debug, Clone, Copy)]
pub struct ExternalPressure {
    rxx: f64,
    rxy: f64,
    rxz: f64,
    ryy: f64,
    ryz: f64,
    rzz: f64,
}

impl Default for ExternalPressure {
    fn default() -> Self {
        Self {
            rxx: 0.0,
            rxy: 0.0,
            rxz: 0.0,
            ryy: 0.0,
            ryz: 0.0,
            rzz: 0.0,
        }
    }
}

impl Display for ExternalPressure {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        writeln!(
            f,
            "{:16.10}{:16.10}{:16.10}\n{:32.10}{:16.10}\n{:48.10}",
            self.rxx, self.rxy, self.rxz, self.ryy, self.ryz, self.rzz
        )
    }
}

impl CellSettingExport for ExternalPressure {
    fn write_to_cell(&self) -> String {
        Cell::write_block(("EXTERNAL_PRESSURE".into(), format!("{self}")))
    }
}

#[cfg(test)]
mod test {
    use crate::param_writer::cell_settings::CellSettingExport;

    use super::ExternalPressure;

    #[test]
    fn extern_field_disp() {
        let pressure = ExternalPressure::default();
        println!("{}", pressure.write_to_cell());
    }
}