Skip to content

Commit

Permalink
update environments
Browse files Browse the repository at this point in the history
  • Loading branch information
lagemannk committed Jul 28, 2024
1 parent 805fa5e commit d8db8ad
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
8 changes: 5 additions & 3 deletions hydrogym/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class PDEBase(metaclass=abc.ABCMeta):
any information about solving the time-varying equations
"""

MAX_CONTROL = np.inf
# MAX_CONTROL = np.inf
MAX_CONTROL_LOW = -np.inf
MAX_CONTROL_UP = np.inf
DEFAULT_MESH = ""
DEFAULT_DT = np.inf

Expand Down Expand Up @@ -406,8 +408,8 @@ def __init__(self, env_config: dict):
dtype=float,
)
self.action_space = gym.spaces.Box(
low=-self.flow.MAX_CONTROL,
high=self.flow.MAX_CONTROL,
low=self.flow.MAX_CONTROL_LOW,
high=self.flow.MAX_CONTROL_UP,
shape=(self.flow.num_inputs,),
dtype=float,
)
Expand Down
5 changes: 3 additions & 2 deletions hydrogym/firedrake/envs/cavity/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ class Cavity(FlowConfig):
FUNCTIONS = ("q", "qB"
) # This flow needs a base flow to compute fluctuation KE

MAX_CONTROL = 1.0
CONTROL_SCALING = 0.1
MAX_CONTROL_LOW = 0.0
MAX_CONTROL_UP = 0.03
CONTROL_SCALING = 1.0
TAU = 0.075 # Time constant for controller damping (0.01*instability frequency)

# Domain labels
Expand Down
6 changes: 4 additions & 2 deletions hydrogym/firedrake/envs/cylinder/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def render(self, mode="human", clim=None, levels=None, cmap="RdBu", **kwargs):


class RotaryCylinder(CylinderBase):
MAX_CONTROL = 1.0
MAX_CONTROL_LOW = -1.0
MAX_CONTROL_UP = 1.0
CONTROL_SCALING = 5.0
DEFAULT_DT = 1e-2

Expand All @@ -246,7 +247,8 @@ def cyl_velocity_field(self):


class Cylinder(CylinderBase):
MAX_CONTROL = 0.1
MAX_CONTROL_LOW = -0.1
MAX_CONTROL_UP = 0.1
CONTROL_SCALING = 1.0
DEFAULT_DT = 1e-2

Expand Down
10 changes: 6 additions & 4 deletions hydrogym/firedrake/envs/pinball/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ class Pinball(FlowConfig):
x0 = [0.0, rad * 1.5 * 1.866, rad * 1.5 * 1.866]
y0 = [0.0, 1.5 * rad, -1.5 * rad]

MAX_CONTROL = 1.0 #0.5 * np.pi
MAX_CONTROL_LOW = -1.0
MAX_CONTROL_UP = 1.0
CONTROL_SCALING = 5.0
# TAU = 0.5 # TODO: Tune this based on vortex shedding period
TAU = 0.04 # Time constant for controller damping (0.01*vortex shedding period)
TAU = 0.5 # TODO: Tune this based on vortex shedding period
# TAU = 0.04 # Time constant for controller damping (0.01*vortex shedding period)

MESH_DIR = os.path.abspath(f"{__file__}/..")

Expand Down Expand Up @@ -155,7 +156,8 @@ def evaluate_objective(self, q: fd.Function = None, averaged_objective_values=No
else:
CL, CD = averaged_objective_values[:3], averaged_objective_values[3:]
# print('pinball lambda', self.reward_lambda, CD, sum(np.square(CD)), flush=True)
return sum(np.square(CD)) + self.reward_lambda * sum(np.square(CL))
# return sum(np.square(CD)) + self.reward_lambda * sum(np.square(CL))
return sum(CD)
# return -(1.5 - (sum(CD) + self.reward_lambda * np.abs(sum(CL))))

def render(self, mode="human", clim=None, levels=None, cmap="RdBu", **kwargs):
Expand Down
3 changes: 2 additions & 1 deletion hydrogym/firedrake/envs/step/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ class Step(FlowConfig):
FUNCTIONS = ("q", "qB"
) # This flow needs a base flow to compute fluctuation KE

MAX_CONTROL = 1.0
MAX_CONTROL_LOW = -1.0
MAX_CONTROL_UP = 1.0
CONTROL_SCALING = 0.1 # Arbitrary... should tune this
TAU = 0.005 # Time constant for controller damping (0.01*instability frequency)

Expand Down
4 changes: 2 additions & 2 deletions hydrogym/firedrake/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ def set_control(self, act: ArrayLike = None):

if hasattr(self, "bcu_actuation"):
for i in range(self.num_inputs):
u = np.clip(self.actuators[i].state, -self.MAX_CONTROL,
self.MAX_CONTROL)
u = np.clip(self.actuators[i].state, self.MAX_CONTROL_LOW,
self.MAX_CONTROL_UP)
self.bcu_actuation[i].set_scale(u)

def inner_product(
Expand Down

0 comments on commit d8db8ad

Please sign in to comment.