예제 #1
0
    def test_domain_with_circle(self):
        fname = 'circle.npz'
        dom2d = copy.deepcopy(self.dom2d)
        dom2d['elements'] = [pylbm.Circle([0.5, 1.], .5, label=10)]
        dom = pylbm.Domain(dom2d)

        check_from_file(dom, fname)
예제 #2
0
    def test_domain_with_two_schemes_with_label(self):
        lleft, lright = 1, 2
        dom1d = copy.deepcopy(self.dom1d)
        dom1d['box'] = {'x': [0, 1], 'label': [lleft, lright]}
        dom1d['schemes'].append({'velocities':list(range(5))})

        dom = pylbm.Domain(dom1d)

        desired_in_or_out = self.valin*np.ones(8)
        desired_in_or_out[[0, 1, -2, -1]] = self.valout
        assert(np.all(dom.in_or_out == desired_in_or_out))

        desired_distance = self.valin*np.ones((5, 8))
        desired_distance[tuple(((1, 2), (-3, 2)))] = .5
        desired_distance[tuple(((3, 4), (-3, 2)))] = .25
        desired_distance[tuple(((3, 4), (-4, 3)))] = .75
        assert(np.all(dom.distance == desired_distance))

        desired_flag = self.valin*np.ones((5, 8), dtype=int)
        ind0_left = (2,) + (4,)*2
        ind1_left = (2,)*2 + (3,)
        ind0_right = (1,) + (3,)*2
        ind1_right = (-3,)*2 + (-4,)
        desired_flag[tuple((ind0_left, ind1_left))] = lleft
        desired_flag[tuple((ind0_right, ind1_right))] = lright
        assert(np.all(dom.flag == desired_flag))
예제 #3
0
    def __call__(self, path, test_case, simu_cfg):
        ref = None
        if hasattr(test_case, 'ref_solution'):
            domain = pylbm.Domain(simu_cfg)
            time_e = test_case.duration
            ref = test_case.ref_solution(time_e, domain.x, field=self.field)

        return pylbm_responses.Plot(os.path.join(path, f'{self.field}.png'),
                                    self.expr, ref)
예제 #4
0
    def __call__(self, path, test_case, simu_cfg):
        domain = pylbm.Domain(simu_cfg)
        time_e = test_case.duration
        ref = test_case.ref_solution(time_e, domain.x, field=self.field)

        return pylbm_responses.Error(ref,
                                     self.expr,
                                     log10=self.log10,
                                     relative=self.relative)
예제 #5
0
    def test_domain_with_triangle(self):
        fname = 'triangle.npz'
        dom2d = copy.deepcopy(self.dom2d)
        dom2d['elements'] = [
            pylbm.Triangle([0.23, 0.73], [0.5, 0], [0., .5], label=10)
        ]
        dom = pylbm.Domain(dom2d)

        check_from_file(dom, fname)
예제 #6
0
    def test_simple_domain_with_labels(self):
        dom1d = copy.deepcopy(self.dom1d)
        dom1d['box'] = {'x': [0, 1], 'label': [0, 1]}
        dom = pylbm.Domain(dom1d)

        assert(dom.shape_halo == [6])
        assert(dom.shape_in == [4])
        assert(dom.dx == .25)
        assert(np.all(dom.geom.bounds == [[0., 1.]]))
        assert(np.all(dom.x_halo == np.linspace(-.125, 1.125, 6)))
예제 #7
0
    def test_domain_with_fluid_circle(self):
        fname = 'fluid_circle.npz'
        dom2d = copy.deepcopy(self.dom2d)
        dom2d['elements'] = [
            pylbm.Parallelogram([0., 0.], [1., 0], [0., 2.], label=20),
            pylbm.Circle([0.5, 1.], .5, label=10, isfluid=True)
        ]
        dom = pylbm.Domain(dom2d)

        check_from_file(dom, fname)
예제 #8
0
    def test_simple_domain_with_labels(self):
        dom2d = copy.deepcopy(self.dom2d)
        dom2d['box']['label'] = [0, 1, 2, 0]
        dom = pylbm.Domain(dom2d)

        # assert(dom.Ng == [4, 8])
        # assert(dom.N == [4, 8])
        assert (dom.dx == .25)
        #assert(np.all(dom.bounds == [[0., 1.], [0., 2.]]))
        assert (np.all(dom.x_halo == [np.linspace(-.125, 1.125, 6)]))
        assert (np.all(dom.y_halo == [np.linspace(-.125, 2.125, 10)]))
예제 #9
0
    def test_domain_with_one_scheme(self):
        dom = pylbm.Domain(self.dom1d)

        desired_in_or_out = self.valin*np.ones(6)
        desired_in_or_out[[0, -1]] = self.valout
        assert(np.all(dom.in_or_out == desired_in_or_out))

        desired_distance = self.valin*np.ones((3, 6))
        desired_distance[tuple(((1, 2), (-2, 1)))] = .5
        print(dom.distance)
        assert(np.all(dom.distance == desired_distance))

        desired_flag = self.valin*np.ones((3, 6), dtype=int)
        desired_flag[tuple(((1, 2), (-2, 1)))] = 0
        assert(np.all(dom.flag == desired_flag))
예제 #10
0
    def test_domain_with_two_schemes_without_label(self):
        dom1d = copy.deepcopy(self.dom1d)
        dom1d['schemes'].append({'velocities':list(range(5))})

        dom = pylbm.Domain(dom1d)

        desired_in_or_out = self.valin*np.ones(8)
        desired_in_or_out[[0, 1, -2, -1]] = self.valout
        assert(np.all(dom.in_or_out == desired_in_or_out))

        desired_distance = self.valin*np.ones((5, 8))
        desired_distance[tuple(((1, 2), (-3, 2)))] = .5
        desired_distance[tuple(((3, 4), (-3, 2)))] = .25
        desired_distance[tuple(((3, 4), (-4, 3)))] = .75
        assert(np.all(dom.distance == desired_distance))

        desired_flag = self.valin*np.ones((5, 8), dtype=int)
        ind0 = (1, 2) + (3, 4)*2
        ind1 = (-3, 2)*2 + (-4, 3)
        desired_flag[tuple((ind0, ind1))] = 0
        assert(np.all(dom.flag == desired_flag))
예제 #11
0
D_DOM = {
    'box': {
        'x': [0, 2],
        'y': [0, 1],
        'label': 0
    },
    'elements': [
        pylbm.Circle((0.5, 0.5), 0.2, label=1),
    ],
    'space_step': 0.05,
    'schemes': [{
        'velocities': list(range(13))
    }],
}
DOMAIN = pylbm.Domain(D_DOM)
print(DOMAIN)
DOMAIN.visualize(scale=1.5)
DOMAIN.visualize(view_distance=True,
                 label=None,
                 view_in=True,
                 view_out=True,
                 view_bound=True)
DOMAIN.visualize(
    view_distance=True,
    label=None,
    view_in=True,
    view_out=True,
    view_bound=True,
    view_normal=True,
)
예제 #12
0
# Authors:
#     Loic Gouarin <*****@*****.**>
#     Benjamin Graille <*****@*****.**>
#
# License: BSD 3 clause
"""
Example of a square in 2D with a circular hole with a D2Q13
"""
from six.moves import range
import pylbm
dico = {
    'box': {
        'x': [0, 2],
        'y': [0, 1],
        'label': 0
    },
    'elements': [pylbm.Circle((0.5, 0.5), 0.2)],
    'space_step': 0.05,
    'schemes': [{
        'velocities': list(range(13))
    }],
}
dom = pylbm.Domain(dico)
dom.visualize()
dom.visualize(view_distance=True)
예제 #13
0
# Authors:
#     Loic Gouarin <*****@*****.**>
#     Benjamin Graille <*****@*****.**>
#
# License: BSD 3 clause
"""
Example of a square in 2D
"""
from six.moves import range
import pylbm

# pylint: disable=invalid-name

ddom = {
    'box': {
        'x': [0, 1],
        'y': [0, 1],
        'label': [0, 1, 2, 3]
    },
    'space_step': 0.1,
    'schemes': [{
        'velocities': list(range(9))
    }],
}
dom = pylbm.Domain(ddom)
print(dom)
dom.visualize()
dom.visualize(view_distance=True)
예제 #14
0
    if k == 'la':
        symb = sp.symbols('lambda')
    else:
        symb = sp.symbols(k)
    to_exclude.append(symb)
    extra[symb] = v

simu_cfg = pylbm_ui.simulation.get_config(test_case, lb_scheme, data['dx'], exclude=to_exclude)
sol = pylbm.Simulation(simu_cfg, initialize=False)
sol.extra_parameters = extra

responses = []

fields = test_case.equation.get_fields()

domain = pylbm.Domain(simu_cfg)
time_e = test_case.duration
ref = test_case.ref_solution(time_e, domain.x, field='mass')

responses_list = pylbm_ui.widgets.responses.build_responses_list(test_case, lb_scheme)

responses = []
for r in data['responses']:
    responses.append(responses_list[r])


output = [0]*len(responses)

for i, r in enumerate(responses):
    if isinstance(r, pylbm_ui.responses.FromConfig):
        output[i] = r(simu_cfg, extra)
예제 #15
0
    def test_domain_with_one_scheme(self):
        fname = 'simple_domain.npz'
        dom = pylbm.Domain(self.dom2d)

        check_from_file(dom, fname)