Add improved default bc
This commit is contained in:
		
							
								
								
									
										39
									
								
								multigrid/examples/double.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								multigrid/examples/double.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
			
		||||
{
 | 
			
		||||
    "grids": {
 | 
			
		||||
        "default": {
 | 
			
		||||
            "x": { "linspace": { "start": -5, "end": 5, "steps": 100 } },
 | 
			
		||||
            "operators": {
 | 
			
		||||
                "xi": "upwind9",
 | 
			
		||||
                "eta": "upwind9h2"
 | 
			
		||||
            },
 | 
			
		||||
            "boundary_conditions": {
 | 
			
		||||
                "east": "vortex",
 | 
			
		||||
                "west": "vortex"
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        "grid0": {
 | 
			
		||||
            "y": { "linspace": { "start": 0, "end": 5, "steps": 50, "h2": true } },
 | 
			
		||||
            "boundary_conditions": {
 | 
			
		||||
                "south": { "neighbour": "grid1" },
 | 
			
		||||
                "north": { "neighbour": "grid1" }
 | 
			
		||||
            }
 | 
			
		||||
        },
 | 
			
		||||
        "grid1": {
 | 
			
		||||
            "y": { "linspace": { "start": -5, "end": 0, "steps": 50, "h2": true } },
 | 
			
		||||
            "boundary_conditions": {
 | 
			
		||||
                "south": { "neighbour": "grid0" },
 | 
			
		||||
                "north": { "neighbour": "grid0" }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
    "integration_time": 2.0,
 | 
			
		||||
    "vortex": {
 | 
			
		||||
        "vortices": [{
 | 
			
		||||
            "x0": -1.0,
 | 
			
		||||
            "y0": 0.0,
 | 
			
		||||
            "rstar": 0.5,
 | 
			
		||||
            "eps": 1.0
 | 
			
		||||
        }],
 | 
			
		||||
        "mach": 0.5
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -233,9 +233,12 @@ impl Configuration {
 | 
			
		||||
                    (op::Upwind9, op::Upwind9h2) => {
 | 
			
		||||
                        Right(Box::new((&Upwind9, &Upwind9h2)) as Box<dyn UpwindOperator2d>)
 | 
			
		||||
                    }
 | 
			
		||||
                    (op::Upwind9h2, op::Upwind9) => {
 | 
			
		||||
                        Right(Box::new((&Upwind9h2, &Upwind9)) as Box<dyn UpwindOperator2d>)
 | 
			
		||||
                    }
 | 
			
		||||
                    (op::Sbp4, op::Sbp4) => Left(Box::new(SBP4) as Box<dyn SbpOperator2d>),
 | 
			
		||||
                    (op::Sbp8, op::Sbp8) => Left(Box::new(SBP8) as Box<dyn SbpOperator2d>),
 | 
			
		||||
                    _ => todo!(),
 | 
			
		||||
                    _ => todo!("Combination {:?}, {:?} not implemented", eta, xi),
 | 
			
		||||
                }
 | 
			
		||||
            })
 | 
			
		||||
            .collect();
 | 
			
		||||
@@ -244,9 +247,12 @@ impl Configuration {
 | 
			
		||||
            .iter()
 | 
			
		||||
            .enumerate()
 | 
			
		||||
            .map(|(i, (_name, g))| {
 | 
			
		||||
                let default_bc = default.boundary_conditions.clone().unwrap_or_default();
 | 
			
		||||
                g.boundary_conditions
 | 
			
		||||
                    .clone()
 | 
			
		||||
                    .unwrap_or_else(|| default.boundary_conditions.clone().unwrap_or_default())
 | 
			
		||||
                    .unwrap_or_default()
 | 
			
		||||
                    .zip(default_bc)
 | 
			
		||||
                    .map(|(bc, fallback)| bc.or(fallback))
 | 
			
		||||
                    .map(|bc| match bc {
 | 
			
		||||
                        None | Some(BoundaryType::Vortex) => {
 | 
			
		||||
                            euler::BoundaryCharacteristic::Vortex(self.vortex.clone())
 | 
			
		||||
 
 | 
			
		||||
@@ -45,6 +45,25 @@ impl<T> Direction<T> {
 | 
			
		||||
            east: f(self.east),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    pub fn zip<U>(self, other: Direction<U>) -> Direction<(T, U)> {
 | 
			
		||||
        Direction {
 | 
			
		||||
            north: (self.north, other.north),
 | 
			
		||||
            south: (self.south, other.south),
 | 
			
		||||
            west: (self.west, other.west),
 | 
			
		||||
            east: (self.east, other.east),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> Direction<Option<T>> {
 | 
			
		||||
    pub fn unwrap_or(self, other: Direction<T>) -> Direction<T> {
 | 
			
		||||
        Direction {
 | 
			
		||||
            north: self.north.unwrap_or(other.north),
 | 
			
		||||
            south: self.south.unwrap_or(other.south),
 | 
			
		||||
            west: self.west.unwrap_or(other.west),
 | 
			
		||||
            east: self.east.unwrap_or(other.east),
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl<T> Direction<T> {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user