mirror of
https://github.com/alvierahman90/fea.git
synced 2024-12-15 11:01:59 +00:00
formatting
This commit is contained in:
parent
17942cdbe5
commit
70d19a2f26
@ -2,7 +2,7 @@ use fea::two_d::beam_elements::*;
|
||||
use fea::two_d::*;
|
||||
|
||||
fn main() {
|
||||
let student_id_last_digit = 9 as f32;
|
||||
let student_id_last_digit = 9_f32;
|
||||
let d = student_id_last_digit / 100.0;
|
||||
let r = d / 2.0;
|
||||
let e = 210e9;
|
||||
@ -38,32 +38,47 @@ fn main() {
|
||||
id: 4,
|
||||
pos: Vector(l * theta.cos(), l * theta.sin()),
|
||||
bc: BoundaryCondition::Force(Vector::from_mag_angle(p, 45_f32.to_radians())),
|
||||
beams: vec![]
|
||||
beams: vec![],
|
||||
};
|
||||
|
||||
let mut w = World::from(vec![p1, p2, p3, p4]);
|
||||
|
||||
w.link(1,4, NewBeam {
|
||||
w.link(
|
||||
1,
|
||||
4,
|
||||
NewBeam {
|
||||
cross_section: CrossSection::Circular(r),
|
||||
material: fea::Material {
|
||||
yield_stress: 95e6,
|
||||
youngs_modulus: e,
|
||||
}
|
||||
}).unwrap();
|
||||
w.link(2,4, NewBeam {
|
||||
},
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
w.link(
|
||||
2,
|
||||
4,
|
||||
NewBeam {
|
||||
cross_section: CrossSection::Circular(r),
|
||||
material: fea::Material {
|
||||
yield_stress: 95e6,
|
||||
youngs_modulus: e,
|
||||
}
|
||||
}).unwrap();
|
||||
w.link(3,4, NewBeam {
|
||||
},
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
w.link(
|
||||
3,
|
||||
4,
|
||||
NewBeam {
|
||||
cross_section: CrossSection::Circular(r),
|
||||
material: fea::Material {
|
||||
yield_stress: 95e6,
|
||||
youngs_modulus: e,
|
||||
}
|
||||
}).unwrap();
|
||||
},
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
println!("{:?}", w);
|
||||
println!("{:?}", w.stiffness_matrix().unwrap());
|
||||
|
14
src/two_d.rs
14
src/two_d.rs
@ -1,14 +1,4 @@
|
||||
pub mod beam_elements;
|
||||
pub mod vector;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Vector(pub f32, pub f32);
|
||||
|
||||
impl Vector {
|
||||
pub fn distance(&self, other: &Self) -> f32 {
|
||||
((self.0 - other.0).powi(2) + (self.1 - other.1).powi(2)).sqrt()
|
||||
}
|
||||
|
||||
pub fn from_mag_angle(magnitude: f32, angle: f32) -> Self {
|
||||
Self (magnitude * angle.cos(), magnitude * angle.sin())
|
||||
}
|
||||
}
|
||||
pub use vector::*;
|
||||
|
@ -1,25 +1,11 @@
|
||||
mod beam;
|
||||
mod boundary_condition;
|
||||
mod cross_section;
|
||||
mod point;
|
||||
mod world;
|
||||
|
||||
pub use beam::*;
|
||||
pub use boundary_condition::*;
|
||||
pub use cross_section::*;
|
||||
pub use point::*;
|
||||
pub use world::*;
|
||||
|
||||
use super::Vector;
|
||||
use crate::Material;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Point {
|
||||
pub id: usize,
|
||||
pub pos: Vector,
|
||||
pub bc: BoundaryCondition,
|
||||
pub beams: Vec<usize>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum BoundaryCondition {
|
||||
Free,
|
||||
Fixed,
|
||||
Force(Vector),
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
use super::*;
|
||||
use crate::Material;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Beam {
|
||||
@ -15,14 +16,12 @@ pub struct NewBeam {
|
||||
|
||||
impl Beam {
|
||||
pub fn new(p1: usize, p2: usize, props: NewBeam) -> Beam {
|
||||
let b = Beam {
|
||||
Beam {
|
||||
id: 0,
|
||||
points: (p1, p2),
|
||||
material: props.material,
|
||||
cross_section: props.cross_section,
|
||||
};
|
||||
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
fn get_points<'a>(&self, world: &'a World) -> (&'a Point, &'a Point) {
|
||||
@ -33,21 +32,12 @@ impl Beam {
|
||||
}
|
||||
|
||||
pub fn stiffness(&self, world: &World) -> f32 {
|
||||
let s = self.cross_section.area() * self.material.youngs_modulus / self.length(world);
|
||||
|
||||
println!("{:?} {}", self, s);
|
||||
|
||||
s
|
||||
|
||||
self.cross_section.area() * self.material.youngs_modulus / self.length(world)
|
||||
}
|
||||
|
||||
pub fn length(&self, world: &World) -> f32 {
|
||||
let (p1, p2) = self.get_points(world);
|
||||
let l = p1.pos.distance(&p2.pos);
|
||||
|
||||
println!("{:?} {}", self, l);
|
||||
|
||||
l
|
||||
p1.pos.distance(&p2.pos)
|
||||
}
|
||||
|
||||
pub fn angle(&self, world: &World) -> f32 {
|
||||
@ -60,9 +50,9 @@ impl Beam {
|
||||
|
||||
pub fn other_point(&self, p: usize) -> usize {
|
||||
if p == self.points.0 {
|
||||
return self.points.1;
|
||||
self.points.1
|
||||
} else {
|
||||
return self.points.0;
|
||||
self.points.0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
src/two_d/beam_elements/boundary_condition.rs
Normal file
8
src/two_d/beam_elements/boundary_condition.rs
Normal file
@ -0,0 +1,8 @@
|
||||
use crate::two_d::Vector;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum BoundaryCondition {
|
||||
Free,
|
||||
Fixed,
|
||||
Force(Vector),
|
||||
}
|
10
src/two_d/beam_elements/point.rs
Normal file
10
src/two_d/beam_elements/point.rs
Normal file
@ -0,0 +1,10 @@
|
||||
use super::super::Vector;
|
||||
use super::BoundaryCondition;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Point {
|
||||
pub id: usize,
|
||||
pub pos: Vector,
|
||||
pub bc: BoundaryCondition,
|
||||
pub beams: Vec<usize>,
|
||||
}
|
@ -25,7 +25,13 @@ impl World {
|
||||
let by = bx + 1;
|
||||
|
||||
let angle = beam.angle(self);
|
||||
println!("point: {} to point {} beam: {} beam_angle: {}", _point_id, other_point.id, beam.id, beam.angle(self).to_degrees());
|
||||
println!(
|
||||
"point: {} to point {} beam: {} beam_angle: {}",
|
||||
_point_id,
|
||||
other_point.id,
|
||||
beam.id,
|
||||
beam.angle(self).to_degrees()
|
||||
);
|
||||
let c2 = angle.cos().powi(2);
|
||||
let s2 = angle.sin().powi(2);
|
||||
let cs = angle.cos() * angle.sin();
|
||||
@ -86,7 +92,10 @@ impl From<Vec<Point>> for World {
|
||||
/// If this is not the case, then some points will be overriden.
|
||||
fn from(points: Vec<Point>) -> World {
|
||||
let mut points = points;
|
||||
let mut w = World { points: HashMap::new(), beams: HashMap::new() };
|
||||
let mut w = World {
|
||||
points: HashMap::new(),
|
||||
beams: HashMap::new(),
|
||||
};
|
||||
|
||||
while let Some(point) = points.pop() {
|
||||
w.points.insert(point.id, point);
|
||||
|
12
src/two_d/vector.rs
Normal file
12
src/two_d/vector.rs
Normal file
@ -0,0 +1,12 @@
|
||||
#[derive(Debug)]
|
||||
pub struct Vector(pub f32, pub f32);
|
||||
|
||||
impl Vector {
|
||||
pub fn distance(&self, other: &Self) -> f32 {
|
||||
((self.0 - other.0).powi(2) + (self.1 - other.1).powi(2)).sqrt()
|
||||
}
|
||||
|
||||
pub fn from_mag_angle(magnitude: f32, angle: f32) -> Self {
|
||||
Self(magnitude * angle.cos(), magnitude * angle.sin())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user