<commit_before>########################################################################
#
#  Copyright 2014 Johns Hopkins University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Contact: <EMAIL>
# Website: http://turbulence.pha.jhu.edu/
#
########################################################################

import numpy as np
import os
import pickle
import gzip
import ctypes as ct
import distutils
import distutils.command
import distutils.command.build_ext
import distutils.core
import distutils.dist
import tempfile

import pyJHTDB
import pyJHTDB.generic_splines as gs

if pyJHTDB.found_scipy:
    from scipy.ndimage.filters import correlate1d

class spline_interpolator:
    def __init__(
            self,
            info,
            n = 1,
            m = 1,
            compute_fast_beta = False,
            nx = None,
            mx = None,
            ny = None,
            my = None,
            nz = None,
            mz = None):
        self.nx = n if (type(nx) == type(None)) else nx
        self.ny = n if (type(ny) == type(None)) else ny
        self.nz = n if (type(nz) == type(None)) else nz
        self.mx = m if (type(mx) == type(None)) else mx
        self.my = m if (type(my) == type(None)) else my
        self.mz = m if (type(mz) == type(None)) else mz
        self.info = info
        pickle_file = os.path.join(
                pyJHTDB.lib_folder,
                info['name'] + '_spline_interpolator_' +
                'xn{0}m{1}_'.format(self.nx, self.mx) +
                'yn{0}m{1}_'.format(self.ny, self.my) +
                'zn{0}m{1}.'.format(self.nz, self.mz) +
                'pickle.gz')
        if os.path.exists(pickle_file):
            self.spline = pickle.load(gzip.open(pickle_file))
        else:
            func = []
            for coord in ['x', 'y', 'z']:
                if info[coord + 'uniform'] and info[coord + 'periodic']:
                    func.append(gs.generic_spline_1D(
                            info[coord + 'nodes'][:2],
                            max_deriv = getattr(self, 'm' + coord),
                            neighbours = getattr(self, 'n' + coord),
                            period = info['l' + coord]))
                else:
                    func.append(gs.generic_spline_1D(
                            info[coord + 'nodes'],
                            max_deriv = getattr(self, 'm' + coord),
                            neighbours = getattr(self, 'n' + coord)))
                func[-1].compute_derivs()
                func[-1].compute_beta()
            self.spline = {'x': func[0],
                           'y': func[1],
                           'z': func[2]}
            pickle.dump(self.spline,
                        gzip.open(pickle_file,
                             'wb'))
        # either channel or periodic cube, so it's cheap to compute fast betas for x and z
        self.spline['x'].compute_fast_beta()
        self.spline['z'].compute_fast_beta()
        self.bx = self.spline['x'].fast_beta
        self.bz = self.spline['z'].fast_beta
        if compute_fast_beta:
            self.spline['y'].compute_fast_beta()
            self.by = self.spline['y'].fast_beta
        else:
            self.by = self.spline['y'].beta
        self.clib_loaded = False
        return None
    def __call__(
            self,
            time = 0.,
            points = np.zeros((1,3)),
            dorder = [(0, 0, 0)],
            lTDB = None,
            getFunction = 'getVelocityAndPressure'):
        if (not len(points.shape) == 2):
            return None
        field_points = np.zeros((points.shape[0], 2*self.nz+2, 2*self.ny+2, 2*self.nx+2, 3), dtype = np.float32)
        xgrid = np.floor(points[:, 0] / self.info['dx']).astype(np.int) % self.info['nx']
        xfrac = (points[:, 0] - self.info['xnodes'][xgrid])/self.info['dx']
        for p in range(points.shape[0]):
            field_points[p, :, :, :, 0] = (self.info['xnodes'][xgrid[p]]
                    + np.array(list(range(-self.nx, self.nx+2)))*self.info['dx'])[np.newaxis, np.newaxis, :]
        if self.info['yperiodic']:
            ygrid = np.floor(points[:, 1] / self.info['dy']).astype(np.int) % self.info['ny']
            yfrac = (points[:, 1] - self.info['ynodes'][ygrid])/self.info['dy']
            for p in range(points.shape[0]):<commit_msg>interpolator: save coeffs in per-direction file<commit_after>########################################################################
#
#  Copyright 2014 Johns Hopkins University
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Contact: <EMAIL>
# Website: http://turbulence.pha.jhu.edu/
#
########################################################################

import numpy as np
import os
import pickle
import gzip
import ctypes as ct
import distutils
import distutils.command
import distutils.command.build_ext
import distutils.core
import distutils.dist
import tempfile

import pyJHTDB
import pyJHTDB.generic_splines as gs

if pyJHTDB.found_scipy:
    from scipy.ndimage.filters import correlate1d

class spline_interpolator:
    def __init__(
            self,
            info,
            n = 1,
            m = 1,
            compute_fast_beta = False,
            nx = None,
            mx = None,
            ny = None,
            my = None,
            nz = None,
            mz = None):
        self.nx = n if (type(nx) == type(None)) else nx
        self.ny = n if (type(ny) == type(None)) else ny
        self.nz = n if (type(nz) == type(None)) else nz
        self.mx = m if (type(mx) == type(None)) else mx
        self.my = m if (type(my) == type(None)) else my
        self.mz = m if (type(mz) == type(None)) else mz
        self.info = info
        pickle_file = {
                'x' : os.path.join(
                        pyJHTDB.lib_folder,
                        (info['name'] + '_spline_' +
                         'xn{0}m{1}.pickle.gz'.format(self.nx, self.mx))),
                'y' : os.path.join(
                        pyJHTDB.lib_folder,
                        (info['name'] + '_spline_' +
                         'yn{0}m{1}.pickle.gz'.format(self.ny, self.my))),
                'z' : os.path.join(
                        pyJHTDB.lib_folder,
                        (info['name'] + '_spline_' +
                         'zn{0}m{1}.pickle.gz'.format(self.nz, self.mz)))}
        self.spline = {}
        for coord in ['x', 'y', 'z']:
            if os.path.exists(pickle_file[coord]):
                self.spline[coord] = pickle.load(gzip.open(pickle_file[coord]))
            else:
                if info[coord + 'uniform'] and info[coord + 'periodic']:
                    self.spline[coord] = gs.generic_spline_1D(
                            info[coord + 'nodes'][:2],
                            max_deriv = getattr(self, 'm' + coord),
                            neighbours = getattr(self, 'n' + coord),
                            period = info['l' + coord])
                else:
                    self.spline[coord] = gs.generic_spline_1D(
                            info[coord + 'nodes'],
                            max_deriv = getattr(self, 'm' + coord),
                            neighbours = getattr(self, 'n' + coord))
                self.spline[coord].compute_derivs()
                self.spline[coord].compute_beta()
                pickle.dump(self.spline[coord],
                            gzip.open(pickle_file[coord],
                                 'wb'))
        # either channel or periodic cube, so it's cheap to compute fast betas for x and z
        self.spline['x'].compute_fast_beta()
        self.spline['z'].compute_fast_beta()
        self.bx = self.spline['x'].fast_beta
        self.bz = self.spline['z'].fast_beta
        if compute_fast_beta:
            self.spline['y'].compute_fast_beta()
            self.by = self.spline['y'].fast_beta
        else:
            self.by = self.spline['y'].beta
        self.clib_loaded = False
        return None
    def __call__(
            self,
            time = 0.,
            points = np.zeros((1,3)),
            dorder = [(0, 0, 0)],
            lTDB = None,
            getFunction = 'getVelocityAndPressure'):
        if (not len(points.shape) == 2):
            return None
        field_points = np.zeros((points.shape[0], 2*self.nz+2, 2*self.ny+2, 2*self.nx+2, 3), dtype = np.float32)
        xgrid = np.floor(points[:, 0] / self.info['dx']).astype(np.int) % self.info['nx']
        xfrac = (points[:, 0] - self.info['xnodes'][xgrid])/self.info['dx']
        for p in range(points.shape[0]):
            field_points[p, :, :, :, 0] = (self.info['xnodes'][xgrid[p]]
                    + np.array(list(range(-self.nx, self.nx+2)))*self.info['dx'])[np.newaxis, np.newaxis, :]
        if self.info['yperiodic']:
            ygrid = np.floor(points[:, 1] / self.info['dy']).astype(np.int) % self.info['ny']
            yfrac = (points[:, 1] - self.info['ynodes'][ygrid])/self.info['dy']
            for p in range(points.shape[0]):
{'fraction_non_alphanumeric': 0.1598880783451584, 'fraction_numerical': 0.00949335465174378, 'mean_word_length': 1.8504699515807461, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1515717', 'n_tokens_mistral': 3134, 'n_tokens_neox': 3020, 'n_words': 727}