Skip to content

Commit

Permalink
Merge pull request #98 from tldr-group/feature-vertical-flux
Browse files Browse the repository at this point in the history
calc vertical flux function
  • Loading branch information
amirDahari1 authored Feb 20, 2024
2 parents 2e3ab8a + 4e2add3 commit e9552d4
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions taufactor/taufactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,16 @@ def check_convergence(self, verbose, conv_crit):
self.old_fl = self.new_fl
return False

def check_vertical_flux(self, conv_crit):
def calc_vertical_flux(self):
'''Calculates the vertical flux through the volume'''
vert_flux = self.conc[:, 1:-1, 1:-1, 1:-1] - \
self.conc[:, :-2, 1:-1, 1:-1]
vert_flux[self.conc[:, :-2, 1:-1, 1:-1] == 0] = 0
vert_flux[self.conc[:, 1:-1, 1:-1, 1:-1] == 0] = 0
return vert_flux

def check_vertical_flux(self, conv_crit):
vert_flux = self.calc_vertical_flux()
fl = torch.sum(vert_flux, (0, 2, 3))[1:-1]
err = (fl.max() - fl.min())/(fl.max())
if fl.min() == 0:
Expand Down Expand Up @@ -286,10 +291,15 @@ def solve(self, iter_limit=5000, verbose=True, conv_crit=2*10**-2, D_0=1):
self.end_simulation(iter_limit, verbose, start)
return self.tau

def check_vertical_flux(self, conv_crit):
def calc_vertical_flux(self):
'''Calculates the vertical flux through the volume'''
vert_flux = abs(self.conc - torch.roll(self.conc, 1, 1))
vert_flux[self.conc == 0] = 0
vert_flux[torch.roll(self.conc, 1, 1) == 0] = 0
return vert_flux

def check_vertical_flux(self, conv_crit):
vert_flux = self.calc_vertical_flux()
fl = torch.sum(vert_flux, (0, 2, 3))[3:-2]
err = (fl.max() - fl.min())*2/(fl.max() + fl.min())
if err < conv_crit or torch.isnan(err).item():
Expand Down Expand Up @@ -488,10 +498,15 @@ def check_convergence(self, verbose, conv_crit):

return False

def check_vertical_flux(self, conv_crit):
def calc_vertical_flux(self):
'''Calculates the vertical flux through the volume'''
vert_flux = (self.conc[:, 1:-1, 1:-1, 1:-1] - self.conc[:,
:-2, 1:-1, 1:-1]) * self.pre_factors[1][:, :-2, 1:-1, 1:-1]
vert_flux[self.nn == torch.inf] = 0
return vert_flux

def check_vertical_flux(self, conv_crit):
vert_flux = self.calc_vertical_flux()
fl = torch.sum(vert_flux, (0, 2, 3))[2:-2]
err = (fl.max() - fl.min())*2/(fl.max() + fl.min())
if err < conv_crit or torch.isnan(err).item():
Expand Down

0 comments on commit e9552d4

Please sign in to comment.