Skip to content

Commit fdc5991

Browse files
committed
move secondary models to independent files, rename modules
1 parent 0575d90 commit fdc5991

19 files changed

Lines changed: 361 additions & 304 deletions

bemol/bem.py

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,11 @@
55
import numpy as np
66

77
from . import rotor
8-
from . import secondary
8+
from . import correction
99
from . import tools
1010

1111

1212

13-
14-
class Corrections(object):
15-
"""Class for storing corrections.
16-
17-
Consider all the corrections available in the secondary
18-
models module. If not given by the user considers the base (empty)
19-
correction with the default parameters.
20-
21-
Parameters
22-
----------
23-
corrections : optional
24-
dictionary or list with the secondary corrections, either classes of
25-
instances - in case of custom parameters. If dictionary is
26-
given, the key must be the name of the correction as defined in
27-
secondary.py with a lower first letter.
28-
29-
"""
30-
def __init__(self,corrections:dict={}):
31-
for name, obj in inspect.getmembers(secondary):
32-
if inspect.isclass(obj):
33-
_name = name[0].lower() + name[1:]
34-
if type(corrections) is dict:
35-
if _name in corrections:
36-
# instantiation of correction with default values
37-
corr = corrections[_name]
38-
corr = corr() if isinstance(corr,type) else corr
39-
setattr(self,_name,corr)
40-
else:
41-
setattr(self,_name,obj.Dummy())
42-
else:
43-
effect_name = obj.__qualname__
44-
setattr(self,_name,obj.Dummy())
45-
# loop for all effects to check if any of the input
46-
# corrections are inner of the available corrections
47-
for corr in corrections:
48-
# instantiation of correction with default values
49-
corr = corr() if isinstance(corr,type) else corr
50-
correction_name = type(corr).__qualname__
51-
if effect_name in correction_name:
52-
setattr(self,_name,corr)
53-
break
54-
55-
56-
def __iter__(self):
57-
"""Iterate corrections."""
58-
for value in self.__dict__.values():
59-
yield value
60-
61-
6213
class BaseBEM:
6314
"""Base BEM class.
6415
@@ -89,7 +40,7 @@ def __init__(self,rotor:rotor.Rotor,rho:float=1.225,corrections:dict=None):
8940
self.n = len(rotor.sections)
9041

9142
if corrections is None: corrections = {}
92-
self.corrections = Corrections(corrections)
43+
self.corrections = correction.Corrections(corrections)
9344

9445

9546

bemol/correction.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
import inspect
3+
from types import ModuleType
4+
5+
from . import secondary
6+
7+
8+
class Corrections(object):
9+
"""Class for storing corrections.
10+
11+
Consider all the corrections available in the secondary
12+
models module. If not given by the user considers the base (empty)
13+
correction with the default parameters.
14+
15+
Parameters
16+
----------
17+
corrections : optional
18+
dictionary or list with the secondary corrections, either classes of
19+
instances - in case of custom parameters. If dictionary is
20+
given, the key must be the name of the correction as defined in
21+
secondary.py with a lower first letter.
22+
23+
"""
24+
def __init__(self,corrections:dict={}):
25+
26+
for name_mod, mod in inspect.getmembers(secondary):
27+
if not isinstance(mod,ModuleType): continue
28+
effect_name = name_mod[0].lower() + name_mod[1:]
29+
for name_obj, obj in inspect.getmembers(mod):
30+
if inspect.isclass(obj):
31+
if type(corrections) is dict:
32+
if effect_name in corrections:
33+
# instantiation of correction with default values
34+
corr = corrections[effect_name]
35+
corr = corr() if isinstance(corr,type) else corr
36+
setattr(self,effect_name,corr)
37+
else:
38+
setattr(self,effect_name,mod.Dummy())
39+
else:
40+
setattr(self,effect_name,mod.Dummy())
41+
# loop for all effects to check if any of the input
42+
# corrections are classes of the available corrections
43+
for corr in corrections:
44+
# instantiation of correction with default values
45+
# TODO: check name before instanciating!
46+
corr = corr() if isinstance(corr,type) else corr
47+
if effect_name in corr.__module__:
48+
setattr(self,effect_name,corr)
49+
break
50+
51+
52+
def __iter__(self):
53+
"""Iterate corrections."""
54+
for value in self.__dict__.values():
55+
yield value

bemol/secondary.py

Lines changed: 0 additions & 202 deletions
This file was deleted.

bemol/secondary/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
from . import dynamicInflow
4+
from . import hubTipLoss
5+
from . import skewAngle
6+
from . import turbulentWakeState
7+
from . import yawModel

bemol/secondary/dynamicInflow.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
3+
4+
class Dummy:
5+
"""Empty dynamic inflow model."""
6+
7+
def __init__(self) -> None:
8+
return
9+
10+
def __call__(self,axialInduction,*args,**kwargs):
11+
return axialInduction
12+
13+
14+
class Knudsen:
15+
"""Knudsen dynamic inflow model."""
16+
17+
def __init__(self,alphaDynamic=0.3,tauScale=3.0) -> None:
18+
self._alpha0 = alphaDynamic
19+
self.alphaDynamic = alphaDynamic
20+
self.tauScale = tauScale
21+
22+
def __call__(self,axialInduction,Ux,radius,tStep):
23+
if (tStep == 0.):
24+
raise ValueError(
25+
f'Using a dynamic inflow model with tStep = {tStep} does not make sense!'
26+
)
27+
# lower bound for wind velocity
28+
kappa = 1. / (self.tauScale * radius / max(1.0,Ux) )
29+
alphaDynamic = tStep*kappa*(axialInduction - self.alphaDynamic) + self.alphaDynamic
30+
self.alphaDynamic = alphaDynamic
31+
32+
return alphaDynamic
33+
34+
def restart(self):
35+
"""Restart alpha to the starting value."""
36+
self.alphaDynamic = self._alpha0

0 commit comments

Comments
 (0)