-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathinitial_condition.py
60 lines (49 loc) · 1.92 KB
/
initial_condition.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
Copyright 2021 Mohamed Khalil
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.
"""
from __future__ import annotations
import os
from typing import TYPE_CHECKING
from pyhype.states.primitive import PrimitiveState
from pyhype.states.conservative import ConservativeState
from pyhype.initial_conditions.base import InitialCondition
if TYPE_CHECKING:
from pyhype.blocks.quad_block import QuadBlock
os.environ["NUMPY_EXPERIMENTAL_ARRAY_FUNCTION"] = "0"
import numpy as np
class ExplosionInitialCondition(InitialCondition):
def apply_to_block(self, block: QuadBlock):
# Free stream
rhoL = 4.6968
pL = 404400.0
uL = 0.0
vL = 0.0
left_state = PrimitiveState(
fluid=block.config.fluid,
array=np.array([rhoL, uL, vL, pL]).reshape((1, 1, 4)),
).to_type(ConservativeState)
# Post shock
rhoR = 1.1742
pR = 101100.0
uR = 0.0
vR = 0.0
right_state = PrimitiveState(
fluid=block.config.fluid,
array=np.array([rhoR, uR, vR, pR]).reshape((1, 1, 4)),
).to_type(ConservativeState)
# Fill state vector in each block
_x_cond = np.logical_and(block.mesh.x >= 3, block.mesh.x <= 7)
_y_cond = np.logical_and(block.mesh.y >= 3, block.mesh.y <= 7)
block.state.data = np.where(
np.logical_and(_x_cond, _y_cond), left_state.data, right_state.data
)
block.state.make_non_dimensional()