diff options
| author | eug-vs <eugene@eug-vs.xyz> | 2022-05-19 03:48:00 +0400 | 
|---|---|---|
| committer | eug-vs <eugene@eug-vs.xyz> | 2022-05-19 03:48:00 +0400 | 
| commit | bd5b9c012a3a91ef9260ca89596b1e13d0c5bb4f (patch) | |
| tree | a8465415c3de49bfaeb47d7cb828448a665844eb /src | |
| parent | d460983ac34b6de32ade0790c371494de75c19f7 (diff) | |
| download | CFD-SIMPLE-bd5b9c012a3a91ef9260ca89596b1e13d0c5bb4f.tar.gz | |
feat: iterate until error is small enough
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.py | 13 | ||||
| -rw-r--r-- | src/simple.py | 15 | 
2 files changed, 15 insertions, 13 deletions
| diff --git a/src/main.py b/src/main.py index 01f0c19..551595e 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,16 @@  from simple import SIMPLE  problem = SIMPLE((1, 2), (0.7, 0.5), 0.02, 120) -  problem.prep() -for i in range(3000): -    print(f'Iteration {i}') +error = 1 +iteration = 0 +while error > 10 ** -7: +    iteration += 1      problem.iterate() -    if i % 5 == 0 or i == 1: +    error = problem.avg_error() +    print(f'Iteration {iteration}') +    print(f'Avg error: {error}') + +    if iteration % 5 == 0 or iteration == 1:          problem.plot(True, 2) diff --git a/src/simple.py b/src/simple.py index d524659..9a3aa31 100644 --- a/src/simple.py +++ b/src/simple.py @@ -115,8 +115,8 @@ class SIMPLE:              self.v_star[0][j] = 0              self.u_star[0][j] = 0 -            self.u_star[self.shape[0] - 1][j] = 0              self.v_star[self.shape[0] - 1][j] = 0 +            self.u_star[self.shape[0] - 1][j] = 0      def apply_bfs_boundary(self):          '''Apply Backwards Facing Step boundary conditions''' @@ -157,25 +157,22 @@ class SIMPLE:                  self.u[i][j] = self.u_star[i][j] + self.d_e[i][j] * (self.p_prime[i][j + 1] - self.p_prime[i][j])                  self.v[i][j] = self.v_star[i][j] + self.d_n[i][j] * (self.p_prime[i][j] - self.p_prime[i + 1][j]) -    def apply_outflow_boundary(self): -        for i in range(self.shape[0]): -            self.u[i][self.shape[1] - 1] = self.u[i][self.shape[1] - 2] -            self.v[i][self.shape[1] - 1] = self.v[i][self.shape[1] - 2] -      def iterate(self): +        self.apply_sides_boundary()          self.apply_inflow_boundary() +        self.apply_bfs_boundary()          self.solve_momentum_equations()          self.apply_sides_boundary() +        self.apply_inflow_boundary()          self.apply_bfs_boundary()          self.correct_pressure()          self.correct_velocities() -        # self.apply_outflow_boundary() - -        self.apply_bfs_boundary()  # Is it needed? +    def avg_error(self): +        return np.absolute(self.b).sum()      def plot(self, normalize=False, density=1):          if self.patch: | 
