Skip to content

Commit

Permalink
Merge branch 'gradient_and_user_guides' of https://github.com/tmathis…
Browse files Browse the repository at this point in the history
  • Loading branch information
tmathis720 committed Nov 17, 2024
2 parents 59423af + 4c1a475 commit e8ba897
Show file tree
Hide file tree
Showing 36 changed files with 19,027 additions and 1,374 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ rayon = "1.5"
crossbeam = "0.8.4"
dashmap = "5.1"
approx = "0.5"
lazy_static = "1.5"

[dev-dependencies]
criterion = "0.4"
Expand Down
13 changes: 12 additions & 1 deletion src/boundary/bc_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use dashmap::DashMap;
use std::sync::Arc;
use std::sync::{Arc, RwLock};
use lazy_static::lazy_static;
use crate::domain::mesh_entity::MeshEntity;
use crate::boundary::dirichlet::DirichletBC;
use crate::boundary::neumann::NeumannBC;
Expand Down Expand Up @@ -29,6 +30,11 @@ pub struct BoundaryConditionHandler {
conditions: DashMap<MeshEntity, BoundaryCondition>,
}

lazy_static! {
static ref GLOBAL_BC_HANDLER: Arc<RwLock<BoundaryConditionHandler>> =
Arc::new(RwLock::new(BoundaryConditionHandler::new()));
}

impl BoundaryConditionHandler {
/// Creates a new BoundaryConditionHandler with an empty map to store boundary conditions.
pub fn new() -> Self {
Expand All @@ -37,6 +43,10 @@ impl BoundaryConditionHandler {
}
}

pub fn global() -> Arc<RwLock<BoundaryConditionHandler>> {
GLOBAL_BC_HANDLER.clone()
}

/// Sets a boundary condition for a specific mesh entity.
pub fn set_bc(&self, entity: MeshEntity, condition: BoundaryCondition) {
self.conditions.insert(entity, condition);
Expand Down Expand Up @@ -105,6 +115,7 @@ impl BoundaryConditionHandler {
}
}


/// The BoundaryConditionApply trait defines the `apply` method, which is used to apply
/// a boundary condition to a given mesh entity.
pub trait BoundaryConditionApply {
Expand Down
8 changes: 5 additions & 3 deletions src/domain/mesh/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use super::Mesh;
use crate::domain;
use crate::domain::mesh_entity::MeshEntity;
use crate::geometry::{Geometry, CellShape, FaceShape};
use dashmap::DashMap;
use crate::domain::section::Vector3;

impl Mesh {
/// Retrieves all the faces of a given cell, filtering only face entities.
Expand Down Expand Up @@ -152,7 +154,7 @@ impl Mesh {
&self,
face: &MeshEntity,
reference_cell: Option<&MeshEntity>,
) -> Option<[f64; 3]> {
) -> Option<Vector3> {
// Retrieve face vertices
let face_vertices = self.get_face_vertices(face);
let face_shape = match face_vertices.len() {
Expand Down Expand Up @@ -186,10 +188,10 @@ impl Mesh {

if dot_product < 0.0 {
// Reverse the normal direction to make it outward-pointing
return Some([-normal[0], -normal[1], -normal[2]]);
return Some(domain::section::Vector3([-normal[0], -normal[1], -normal[2]]));
}
}

Some(normal)
Some(domain::section::Vector3(normal))
}
}
9 changes: 9 additions & 0 deletions src/domain/mesh/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::domain::sieve::Sieve;
use rustc_hash::{FxHashMap, FxHashSet};
use std::sync::{Arc, RwLock};
use crossbeam::channel::{Sender, Receiver};
use lazy_static::lazy_static;

// Delegate methods to corresponding modules

Expand Down Expand Up @@ -43,6 +44,10 @@ pub struct Mesh {
pub boundary_data_receiver: Option<Receiver<FxHashMap<MeshEntity, [f64; 3]>>>,
}

lazy_static! {
static ref GLOBAL_MESH: Arc<RwLock<Mesh>> = Arc::new(RwLock::new(Mesh::new()));
}

impl Mesh {
/// Creates a new instance of the `Mesh` struct with initialized components.
///
Expand All @@ -67,6 +72,10 @@ impl Mesh {
boundary_data_receiver: Some(receiver),
}
}

pub fn global() -> Arc<RwLock<Mesh>> {
GLOBAL_MESH.clone()
}
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit e8ba897

Please sign in to comment.