<commit_before># -*- coding: UTF-8 -*-
#
# Copyright (C) 2008-2011 <NAME> <<EMAIL>>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

"""
Gas dynamics solver of the Euler equations.
"""

from solvcon.kerpak.cuse import CuseSolver
from solvcon.kerpak.cuse import CuseCase
from solvcon.kerpak.cuse import CuseBC
from solvcon.anchor import Anchor
from solvcon.hook import BlockHook

###############################################################################
# Solver.
###############################################################################

class GasdynSolver(CuseSolver):
    """
    Gas dynamics solver of the Euler equations.
    """
    def __init__(self, blk, *args, **kw):
        kw['nsca'] = 1
        super(GasdynSolver, self).__init__(blk, *args, **kw)
    from solvcon.dependency import getcdll
    __clib_gasdyn_c = {
        2: getcdll('gasdyn2d_c'),
        3: getcdll('gasdyn3d_c'),
    }
    __clib_gasdyn_cu = {
        2: getcdll('gasdyn2d_cu', raise_on_fail=False),
        3: getcdll('gasdyn3d_cu', raise_on_fail=False),
    }
    del getcdll
    @property
    def _clib_gasdyn_c(self):
        return self.__clib_gasdyn_c[self.ndim]
    @property
    def _clib_gasdyn_cu(self):
        return self.__clib_gasdyn_cu[self.ndim]
    @property
    def _clib_mcu(self):
        return self.__clib_gasdyn_cu[self.ndim]
    _gdlen_ = 0
    @property
    def _jacofunc_(self):
        return self._clib_gasdyn_c.calc_jaco
    def calccfl(self, worker=None):
        from ctypes import byref
        if self.scu:
            self._clib_gasdyn_cu.calc_cfl(self.ncuth,
                byref(self.cumgr.exd), self.cumgr.gexd.gptr)
        else:
            self._tcall(self._clib_gasdyn_c.calc_cfl, 0, self.ncell)

###############################################################################
# Case.
###############################################################################

class GasdynCase(CuseCase):
    """
    Gas dynamics case.
    """
    from solvcon.domain import Domain
    defdict = {
        'solver.solvertype': GasdynSolver,
        'solver.domaintype': Domain,
    }
    del Domain
    def load_block(self):
        loaded = super(GasdynCase, self).load_block()
        if hasattr(loaded, 'ndim'):
            ndim = loaded.ndim
        else:
            ndim = loaded.blk.ndim
        self.execution.neq = ndim+2
        return loaded

###############################################################################
# Boundary conditions.
###############################################################################

class GasdynBC(CuseBC):
    """
    Basic BC class for gas dynamics.
    """
    from solvcon.dependency import getcdll
    __clib_gasdynb_c = {
        2: getcdll('gasdynb2d_c'),
        3: getcdll('gasdynb3d_c'),
    }
    __clib_gasdynb_cu = {
        2: getcdll('gasdynb2d_cu', raise_on_fail=False),
        3: getcdll('gasdynb3d_cu', raise_on_fail=False),
    }
    del getcdll
    @property
    def _clib_gasdynb_c(self):
        return self.__clib_gasdynb_c[self.svr.ndim]
    @property
    def _clib_gasdynb_cu(self):
        return self.__clib_gasdynb_cu[self.svr.ndim]

class GasdynWall(GasdynBC):
    _ghostgeom_ = 'mirror'
    def soln(self):
        from ctypes import byref
        svr = self.svr
        if svr.scu:
            self._clib_gasdynb_cu.bound_wall_soln(svr.ncuth,
                svr.cumgr.gexd.gptr, self.facn.shape[0], self.cufacn.gptr)
        else:
            self._clib_gasdynb_c.bound_wall_soln(byref(svr.exd),
                self.facn.shape[0], self.facn.ctypes._as_parameter_)
    def dsoln(self):
        from ctypes import byref
        svr = self.svr
        if svr.scu:
            self._clib_gasdynb_cu.bound_wall_dsoln(svr.ncuth,
                svr.cumgr.gexd.gptr, self.facn.shape[0], self.cufacn.gptr)
        else:
            self._clib_gasdynb_c.bound_wall_dsoln(byref(svr.exd),
                self.facn.shape[0], self.facn.ctypes._as_parameter_)

class GasdynNswall(GasdynBC):
    _ghostgeom_ = 'mirror'
    def soln(self):
        from ctypes import byref
        svr = self.svr
        if svr.scu:
            self._clib_gasdynb_cu.bound_nswall_soln(svr.ncuth,
                svr.cumgr.gexd.gptr, self.facn.shape[0], self.cufacn.gptr)
        else:
            self._clib_gasdynb_c.bound_nswall_soln(byref(svr.exd),
                self.facn.shape[0], self.facn.ctypes._as_parameter_)
    def dsoln(self):
        from ctypes import byref
        svr = self.svr
        if svr.scu:
            self._clib_gasdynb_cu.bound_nswall_dsoln(svr.ncuth,
                svr.cumgr.gexd.gptr, self.facn.shape[0], self.cufacn.gptr)
        else:
            self._clib_gasdynb_c.bound_nswall_dsoln(byref(svr.exd),
                self.facn.shape[0], self.facn.ctypes._as_parameter_)

class GasdynInlet(GasdynBC):
    vnames = ['rho', 'v1', 'v2', 'v3', 'p', 'gamma']
    vdefaults = {
        'rho': 1.0, 'p': 1.0, 'gamma': 1.4, 'v1': 0.0, 'v2': 0.0, 'v3': 0.0,
    }
    _ghostgeom_ = 'mirror'
    def soln(self):
        from ctypes import byref
        svr = self.svr
        if svr.scu:
            self._clib_gasdynb_cu.bound_inlet_soln(svr.ncuth,
                svr.cumgr.gexd.gptr, self.facn.shape[0], self.cufacn.gptr,<commit_msg>Make nonslip wall a type of wall.<commit_after># -*- coding: UTF-8 -*-
#
# Copyright (C) 2008-2011 <NAME> <<EMAIL>>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

"""
Gas dynamics solver of the Euler equations.
"""

from solvcon.kerpak.cuse import CuseSolver
from solvcon.kerpak.cuse import CuseCase
from solvcon.kerpak.cuse import CuseBC
from solvcon.anchor import Anchor
from solvcon.hook import BlockHook

###############################################################################
# Solver.
###############################################################################

class GasdynSolver(CuseSolver):
    """
    Gas dynamics solver of the Euler equations.
    """
    def __init__(self, blk, *args, **kw):
        kw['nsca'] = 1
        super(GasdynSolver, self).__init__(blk, *args, **kw)
    from solvcon.dependency import getcdll
    __clib_gasdyn_c = {
        2: getcdll('gasdyn2d_c'),
        3: getcdll('gasdyn3d_c'),
    }
    __clib_gasdyn_cu = {
        2: getcdll('gasdyn2d_cu', raise_on_fail=False),
        3: getcdll('gasdyn3d_cu', raise_on_fail=False),
    }
    del getcdll
    @property
    def _clib_gasdyn_c(self):
        return self.__clib_gasdyn_c[self.ndim]
    @property
    def _clib_gasdyn_cu(self):
        return self.__clib_gasdyn_cu[self.ndim]
    @property
    def _clib_mcu(self):
        return self.__clib_gasdyn_cu[self.ndim]
    _gdlen_ = 0
    @property
    def _jacofunc_(self):
        return self._clib_gasdyn_c.calc_jaco
    def calccfl(self, worker=None):
        from ctypes import byref
        if self.scu:
            self._clib_gasdyn_cu.calc_cfl(self.ncuth,
                byref(self.cumgr.exd), self.cumgr.gexd.gptr)
        else:
            self._tcall(self._clib_gasdyn_c.calc_cfl, 0, self.ncell)

###############################################################################
# Case.
###############################################################################

class GasdynCase(CuseCase):
    """
    Gas dynamics case.
    """
    from solvcon.domain import Domain
    defdict = {
        'solver.solvertype': GasdynSolver,
        'solver.domaintype': Domain,
    }
    del Domain
    def load_block(self):
        loaded = super(GasdynCase, self).load_block()
        if hasattr(loaded, 'ndim'):
            ndim = loaded.ndim
        else:
            ndim = loaded.blk.ndim
        self.execution.neq = ndim+2
        return loaded

###############################################################################
# Boundary conditions.
###############################################################################

class GasdynBC(CuseBC):
    """
    Basic BC class for gas dynamics.
    """
    from solvcon.dependency import getcdll
    __clib_gasdynb_c = {
        2: getcdll('gasdynb2d_c'),
        3: getcdll('gasdynb3d_c'),
    }
    __clib_gasdynb_cu = {
        2: getcdll('gasdynb2d_cu', raise_on_fail=False),
        3: getcdll('gasdynb3d_cu', raise_on_fail=False),
    }
    del getcdll
    @property
    def _clib_gasdynb_c(self):
        return self.__clib_gasdynb_c[self.svr.ndim]
    @property
    def _clib_gasdynb_cu(self):
        return self.__clib_gasdynb_cu[self.svr.ndim]

class GasdynWall(GasdynBC):
    _ghostgeom_ = 'mirror'
    def soln(self):
        from ctypes import byref
        svr = self.svr
        if svr.scu:
            self._clib_gasdynb_cu.bound_wall_soln(svr.ncuth,
                svr.cumgr.gexd.gptr, self.facn.shape[0], self.cufacn.gptr)
        else:
            self._clib_gasdynb_c.bound_wall_soln(byref(svr.exd),
                self.facn.shape[0], self.facn.ctypes._as_parameter_)
    def dsoln(self):
        from ctypes import byref
        svr = self.svr
        if svr.scu:
            self._clib_gasdynb_cu.bound_wall_dsoln(svr.ncuth,
                svr.cumgr.gexd.gptr, self.facn.shape[0], self.cufacn.gptr)
        else:
            self._clib_gasdynb_c.bound_wall_dsoln(byref(svr.exd),
                self.facn.shape[0], self.facn.ctypes._as_parameter_)

class GasdynNswall(GasdynWall):
    def soln(self):
        from ctypes import byref
        svr = self.svr
        if svr.scu:
            self._clib_gasdynb_cu.bound_nswall_soln(svr.ncuth,
                svr.cumgr.gexd.gptr, self.facn.shape[0], self.cufacn.gptr)
        else:
            self._clib_gasdynb_c.bound_nswall_soln(byref(svr.exd),
                self.facn.shape[0], self.facn.ctypes._as_parameter_)
    def dsoln(self):
        from ctypes import byref
        svr = self.svr
        if svr.scu:
            self._clib_gasdynb_cu.bound_nswall_dsoln(svr.ncuth,
                svr.cumgr.gexd.gptr, self.facn.shape[0], self.cufacn.gptr)
        else:
            self._clib_gasdynb_c.bound_nswall_dsoln(byref(svr.exd),
                self.facn.shape[0], self.facn.ctypes._as_parameter_)

class GasdynInlet(GasdynBC):
    vnames = ['rho', 'v1', 'v2', 'v3', 'p', 'gamma']
    vdefaults = {
        'rho': 1.0, 'p': 1.0, 'gamma': 1.4, 'v1': 0.0, 'v2': 0.0, 'v3': 0.0,
    }
    _ghostgeom_ = 'mirror'
    def soln(self):
        from ctypes import byref
        svr = self.svr
        if svr.scu:
            self._clib_gasdynb_cu.bound_inlet_soln(svr.ncuth,
                svr.cumgr.gexd.gptr, self.facn.shape[0], self.cufacn.gptr,
{'fraction_non_alphanumeric': 0.17893755824790308, 'fraction_numerical': 0.011522494281114971, 'mean_word_length': 2.801610305958132, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '85481', 'n_tokens_mistral': 4226, 'n_tokens_neox': 4062, 'n_words': 833}