Skip to content

Commit d17369d

Browse files
authored
Merge pull request #4 from cmccomb/codex/update-right-boundary-conditions-and-test
Fix right boundary condition helper
2 parents d6e948f + da4e274 commit d17369d

File tree

1 file changed

+23
-22
lines changed

1 file changed

+23
-22
lines changed

src/lib.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -556,48 +556,33 @@ impl Settings {
556556
impl Settings {
557557
/// Apply a boundary condition to the left side of the domain. The arguments define whether or not the nodes are fixed in the _x_ and _y_ directions.
558558
pub fn with_left_bc(&mut self, x: bool, y: bool) -> Self {
559-
for idx in 0..=self.nelx {
560-
for jdx in 0..=self.nely {
561-
if idx == 0 {
562-
self.boundary[(idx, jdx)] = (x, y);
563-
}
564-
}
559+
for jdx in 0..=self.nely {
560+
self.boundary[(0, jdx)] = (x, y);
565561
}
566562
self.clone()
567563
}
568564

569565
/// Apply a boundary condition to the right side of the domain. The arguments define whether or not the nodes are fixed in the _x_ and _y_ directions.
570566
pub fn with_right_bc(&mut self, x: bool, y: bool) -> Self {
571-
for idx in 0..=self.nelx {
572-
for jdx in 0..=self.nely {
573-
if idx == self.nelx + 1 {
574-
self.boundary[(idx, jdx)] = (x, y);
575-
}
576-
}
567+
let rightmost_column = self.nelx;
568+
for jdx in 0..=self.nely {
569+
self.boundary[(rightmost_column, jdx)] = (x, y);
577570
}
578571
self.clone()
579572
}
580573

581574
/// Apply a boundary condition to the top side of the domain. The arguments define whether or not the nodes are fixed in the _x_ and _y_ directions.
582575
pub fn with_top_bc(&mut self, x: bool, y: bool) -> Self {
583576
for idx in 0..=self.nelx {
584-
for jdx in 0..=self.nely {
585-
if jdx == 0 {
586-
self.boundary[(idx, jdx)] = (x, y);
587-
}
588-
}
577+
self.boundary[(idx, 0)] = (x, y);
589578
}
590579
self.clone()
591580
}
592581

593582
/// Apply a boundary condition to the bottom side of the domain. The arguments define whether or not the nodes are fixed in the _x_ and _y_ directions.
594583
pub fn with_bottom_bc(&mut self, x: bool, y: bool) -> Self {
595584
for idx in 0..=self.nelx {
596-
for jdx in 0..=self.nely {
597-
if jdx == self.nely {
598-
self.boundary[(idx, jdx)] = (x, y);
599-
}
600-
}
585+
self.boundary[(idx, self.nely)] = (x, y);
601586
}
602587
self.clone()
603588
}
@@ -775,4 +760,20 @@ mod settings_tests {
775760

776761
assert_eq!(assembled_loads, expected);
777762
}
763+
764+
#[test]
765+
fn right_bc_sets_rightmost_column() {
766+
let mut settings = Settings::new(3, 2, 0.5);
767+
let fixed_directions = (true, false);
768+
769+
settings.with_right_bc(fixed_directions.0, fixed_directions.1);
770+
771+
for jdx in 0..=settings.nely {
772+
assert_eq!(settings.boundary[(settings.nelx, jdx)], fixed_directions);
773+
}
774+
775+
for jdx in 0..=settings.nely {
776+
assert_eq!(settings.boundary[(settings.nelx - 1, jdx)], (false, false));
777+
}
778+
}
778779
}

0 commit comments

Comments
 (0)