Skip to content

Commit

Permalink
Add lift/drag function object
Browse files Browse the repository at this point in the history
  • Loading branch information
sayerhs committed Jan 22, 2024
1 parent e021536 commit 822d978
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
53 changes: 53 additions & 0 deletions caelus/post/funcobj/forces.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from io import StringIO
from pathlib import Path

import numpy as np
import pandas as pd

from .funcobj import FunctionObject
Expand Down Expand Up @@ -165,3 +166,55 @@ def __call__(self, time=None):
moments = self._parse_file(dpath / "moment.dat", self._col_names('M'))
moments.drop(columns=['Time'], inplace=True)
return pd.concat([forces, moments], axis=1)


class LiftDrag(FunctionObject):
"""A variation of ForceCoeffs that calculates lift/drag for specific use case."""

_funcobj_type = "liftDrag"
_funcobj_libs = "forces"

_dict_properties = [
('patches', None),
('liftDirection', None),
('dragDirection', None),
('pitchAxis', None),
('Uinf', None),
('rhoInfo', None),
('referenceArea', None),
('referenceLength', None),
('nAveragingSteps', 1),
('maxCp', 1.0e14),
('minCp', 1.0e14),
('wheelbase', None),
('runOnLastIterOnly', False),
('porosity', True),
('outputRegionData', False),
('writeFields', False)
]

def __call__(self, time: str =None):
"""Load the liftDrag file and return as pandas DataFrame."""
dtime = str(time) if time else self.latest_time
dpath = self.root / dtime
fname = dpath / "liftDrag.dat"

if not fname.exists():
raise FileNotFoundError(f"Lift-drag output not found: {fname}")

data = np.loadtxt(fname)
return pd.DataFrame(data, columns=self._col_names())

def _col_names(self):
"""Get the column names for the dataset"""
return [
"time",
"total_lift",
"front_lift",
"rear_lift",
"drag",
"side_force",
"x_moment",
"y_moment",
"z_moment",
]
3 changes: 2 additions & 1 deletion caelus/post/funcobj/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@

from ...io import ControlDict
from ...io.caelusdict import CaelusDict
from .forces import ForceCoeffs, Forces
from .forces import ForceCoeffs, Forces, LiftDrag
from .sampling import SampledSets, SampledSurfaces

_func_objects_list = [
ForceCoeffs,
Forces,
LiftDrag,
SampledSets,
SampledSurfaces,
]
Expand Down

0 comments on commit 822d978

Please sign in to comment.