<commit_before>#================================================================================
#
# Imports
#
#================================================================================
import sys
import numpy as np

import solution

#================================================================================
#
# Class definitions
#
#================================================================================
class Limiter:
    'Generate the limiter'

    #================================================================================
    def __init__(self,limiting_type,solution):

        print("Setting up the limiter.")

        # Pre-allocate vector holding 1/(2*k+1). The little None
        # business is to do the multiplication broadcasting with the
        # delta. According to
        # http://stackoverflow.com/questions/16229823/how-to-multiply-numpy-2d-array-with-numpy-1d-array
        self.c = 1.0/(2*np.arange(0,solution.basis.p) + 1)[:, None]

        # By default, do not limit
        self.do_limiting = False 
        
        # Pre-allocate some vectors when doing limiting everywhere in
        # the domain
        if limiting_type == 'full':
            print('Limiting everywhere')
            self.do_limiting = True
            
        elif limiting_type == 'adaptive':
            print('Adaptive limiting')
            self.do_limiting = True
            
        else:
            print('No limiting.')
            
            
    #================================================================================
    def limit(self,solution):
        """Limit a solution"""

        if self.do_limiting:

            # Get the differences with the left/right neighbors
            deltam,deltap = self.deltas(solution)
        
            # Apply the minmod procedure
            solution.u[1:,solution.N_F:-solution.N_F] = self.minmod(deltam,deltap,solution.u[1:,solution.N_F:-solution.N_F])
<commit_msg>Hacked limiting to make it "adaptive"<commit_after>#================================================================================
#
# Imports
#
#================================================================================
import sys
import numpy as np

import solution

#================================================================================
#
# Class definitions
#
#================================================================================
class Limiter:
    'Generate the limiter'

    #================================================================================
    def __init__(self,limiting_type,solution):

        print("Setting up the limiter.")

        # Pre-allocate vector holding 1/(2*k+1). The little None
        # business is to do the multiplication broadcasting with the
        # delta. According to
        # http://stackoverflow.com/questions/16229823/how-to-multiply-numpy-2d-array-with-numpy-1d-array
        self.c = 1.0/(2*np.arange(0,solution.basis.p) + 1)[:, None]

        # By default, do not limit
        self.do_limiting = False 
        
        # Pre-allocate some vectors when doing limiting everywhere in
        # the domain
        if limiting_type == 'full':
            print('Limiting everywhere')
            self.do_limiting = True
            
        elif limiting_type == 'adaptive':
            print('Adaptive limiting')
            self.do_limiting = True
            
        else:
            print('No limiting.')
            
            
    #================================================================================
    def limit(self,solution):
        """Limit a solution"""

        if self.do_limiting:

            # Get the differences with the left/right neighbors
            deltam,deltap = self.deltas(solution)
        
            # Apply the minmod procedure
            #solution.u[1:,solution.N_F:-solution.N_F] = self.minmod(deltam,deltap,solution.u[1:,solution.N_F:-solution.N_F])

            result = self.minmod(deltam,deltap,solution.u[1:,solution.N_F:-solution.N_F])
            for e in range(1,solution.N_E+1):
                for f in range(0,solution.N_F):

                    stop = False
                    
                    for k in range(solution.basis.p,0,-1):
                        if (np.fabs(solution.u[k,e*solution.N_F+f] - result[k-1,(e-1)*solution.N_F+f]) < 1e-14) or stop:
                            stop = True
                        else:
                            solution.u[k,e*solution.N_F+f] = result[k-1,(e-1)*solution.N_F+f]
                                        

{'fraction_non_alphanumeric': 0.2948885976408912, 'fraction_numerical': 0.011577107907383137, 'mean_word_length': 2.484779299847793, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6047863', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1089, 'n_words': 238}