Skip to main content

Point

Struct Point 

Source
pub struct Point {
    pub x: f64,
    pub y: f64,
}

Fields§

§x: f64§y: f64

Implementations§

Source§

impl Point

Source

pub fn new(x: f64, y: f64) -> Self

Examples found in repository?
examples/debug_c_el.rs (line 7)
5fn main() {
6    let points = [
7        Point::new(0.0, 0.0), // node 0
8        Point::new(1.0, 0.0), // node 1
9        Point::new(0.0, 1.0), // node 2
10        Point::new(0.5, 0.0), // node 3 (mid 0-1)
11        Point::new(0.5, 0.5), // node 4 (mid 1-2)
12        Point::new(0.0, 0.5), // node 5 (mid 2-0)
13    ];
14
15    let tri6 = Tri6::from_points(0, points, [0, 1, 2, 3, 4, 5], 1.0, 1.0, 1.0).unwrap();
16
17    let (k_el, f_el, c_el) = tri6.torsion_properties();
18
19    println!("=== Tri6 Element Matrices on Unit Triangle (C_e with 7-point rule) ===");
20    println!("\nC_e (6x1):");
21    for i in 0..6 {
22        println!("  C[{}] = {:.10}", i, c_el[i]);
23    }
24    let c_sum: f64 = c_el.iter().sum();
25    println!("Sum C_e = {:.10} (expected 0.5)", c_sum);
26
27    // Expected with correct 7-point rule:
28    // C_corner = A/12 = 0.5/12 = 0.041666...
29    // C_mid = A/6 = 0.5/6 = 0.08333...
30    println!(
31        "\nExpected: corner = {:.10}, mid = {:.10}",
32        0.5 / 12.0,
33        0.5 / 6.0
34    );
35}
More examples
Hide additional examples
examples/export_element.rs (line 37)
34fn main() {
35    // Create a simple channel-like element for comparison
36    let points = [
37        Point::new(0.0, 0.0),
38        Point::new(10.0, 0.0),
39        Point::new(0.0, 2.0),
40        Point::new(5.0, 0.0),
41        Point::new(5.0, 1.0),
42        Point::new(0.0, 1.0),
43    ];
44
45    let tri6 = Tri6::from_points(
46        0,
47        points,
48        [0, 1, 2, 3, 4, 5],
49        200_000.0, // E = 200 GPa
50        76_923.0,  // G
51        7850.0,    // density
52    )
53    .unwrap();
54
55    let (k_el, f_el, c_el) = tri6.torsion_properties();
56    let gps = gauss_points(6);
57
58    // Compute Gauss point details
59    let mut gauss_details = String::new();
60    for i in 0..6 {
61        let sf = shape_function(&tri6.coords, (gps[i].1, gps[i].2, gps[i].3));
62        let n_str = format_array(&sf.n);
63        let b0_str = format_array(&sf.b[0]);
64        let b1_str = format_array(&sf.b[1]);
65
66        gauss_details.push_str(&format!(
67            "    {{\n      \"w\": {:.10},\n      \"eta\": {:.10},\n      \"xi\": {:.10},\n      \"zeta\": {:.10},\n      \"n\": [{}],\n      \"b\": [\n        [{}],\n        [{}]\n      ],\n      \"j\": {:.10},\n      \"x\": {:.10},\n      \"y\": {:.10}\n    }}{}\n",
68            gps[i].0, gps[i].1, gps[i].2, gps[i].3,
69            n_str, b0_str, b1_str,
70            sf.j, sf.x, sf.y,
71            if i < 5 { "," } else { "" }
72        ));
73    }
74
75    // Write to JSON file
76    let mut file = File::create("element_data.json").unwrap();
77    writeln!(file, "{{").unwrap();
78    writeln!(file, "  \"coords\": {{").unwrap();
79    writeln!(
80        file,
81        "    \"x\": [{}],",
82        format_array(&[
83            tri6.coords[0][0],
84            tri6.coords[0][1],
85            tri6.coords[0][2],
86            tri6.coords[0][3],
87            tri6.coords[0][4],
88            tri6.coords[0][5]
89        ])
90    )
91    .unwrap();
92    writeln!(
93        file,
94        "    \"y\": [{}]",
95        format_array(&[
96            tri6.coords[1][0],
97            tri6.coords[1][1],
98            tri6.coords[1][2],
99            tri6.coords[1][3],
100            tri6.coords[1][4],
101            tri6.coords[1][5]
102        ])
103    )
104    .unwrap();
105    writeln!(file, "  }},").unwrap();
106
107    writeln!(file, "  \"k_el\": [\n{}  ],", format_matrix(&k_el)).unwrap();
108    writeln!(file, "  \"f_el\": [{}],", format_array(&f_el)).unwrap();
109    writeln!(file, "  \"c_el\": [{}]", format_array(&c_el)).unwrap();
110    writeln!(file, ",").unwrap();
111
112    // Gauss points
113    writeln!(file, "  \"gauss_points\": [").unwrap();
114    for i in 0..6 {
115        writeln!(
116            file,
117            "    [{:.10}, {:.10}, {:.10}, {:.10}]{}",
118            gps[i].0,
119            gps[i].1,
120            gps[i].2,
121            gps[i].3,
122            if i < 5 { "," } else { "" }
123        )
124        .unwrap();
125    }
126    writeln!(file, "  ],").unwrap();
127
128    writeln!(file, "  \"gauss_details\": [\n{}\n  ]", gauss_details).unwrap();
129    writeln!(file, "}}").unwrap();
130
131    println!("Element data exported to element_data.json");
132}

Trait Implementations§

Source§

impl Clone for Point

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Point

Source§

impl Debug for Point

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Point

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Point

Auto Trait Implementations§

§

impl Freeze for Point

§

impl RefUnwindSafe for Point

§

impl Send for Point

§

impl Sync for Point

§

impl Unpin for Point

§

impl UnsafeUnpin for Point

§

impl UnwindSafe for Point

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.