You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
is there already a library for the integration of spherical harmonics in Modelica?
I have started something. Could someone proof it? It is important that the function outputs complex-valued later, since I want to work with a linear combination of several bases.
Thanks for the feedback.
Kind regards
Simon Weber, M.Sc.
Research Associate
Institute for Acoustics and Building Physics
Pfaffenwaldring 7
70569 Stuttgart
Germany
function sphericalHarmonicsinputInteger M;
inputInteger L;
inputReal theta "Altitude within (0,pi]";
inputReal phi " Azimuth within [0,2pi]";
output Complex spharm;
protectedparameterReal pi = Modelica.Constants.pi;
Real Nlm =sqrt( (2*L+1)/2* factorial(L-M)/factorial(L+M));
Real Plm =if M<0then (-1)^M * factorial(L-M) / factorial(L+M) * LegendrePolynom(M,L,cos(theta)) else LegendrePolynom(M,L,cos(theta));
Complex Elm = Modelica.ComplexMath.exp(Complex(0,M*phi));
algorithm
spharm :=sqrt(1/2/pi)*Nlm*Plm*Elm;
end sphericalHarmonics;
function LegendrePolynominputInteger M;
inputInteger L;
inputReal x "Cos(Altitude) within [1,-1]";
outputReal legPoly;
protectedparameterInteger L2Floor =integer(floor(L/2));
Real dPL =0;
Real dx;
algorithmfor k in 0:L2Floor loop
dx :=ifnoEvent(x ==0and L -2*k - M ==0) then factorial(L -2*k)/factorial(L -2*k - M) elseifnoEvent(x ==0) then0else factorial(L
-2*k)/factorial(L -2*k - M)*x^(L -2*k - M) "M-th derivative wrt x of x^(L-2*k); This avoids 0^0 error";
dPL := dPL + (-1)^k*factorial(2*L -2*k)/(factorial(k)*factorial(L - k)*factorial(L -2*k))*dx;
end for;
legPoly :=ifnoEvent(1-x^2==0and M/2==0) then (-1)^M *1/2^L * dPL elseifnoEvent(1-x^2==0) then0else (-1)^M * (1-x^2)^(M/2) /2^L * dPL;
end LegendrePolynom;
function factorial "n-th falling factorial"inputInteger n;
outputInteger f;
protectedInteger maxInt =2147483646"Max 32-bit integer";
algorithm
f :=1;
for i in 0:(n-1) loopassert(f < maxInt, "Integer overflow");
f := f*(n-i);
end for;
end factorial;
The text was updated successfully, but these errors were encountered:
Dear Community,
is there already a library for the integration of spherical harmonics in Modelica?
I have started something. Could someone proof it? It is important that the function outputs complex-valued later, since I want to work with a linear combination of several bases.
Thanks for the feedback.
Kind regards
Simon Weber, M.Sc.
Research Associate
Institute for Acoustics and Building Physics
Pfaffenwaldring 7
70569 Stuttgart
Germany
Tel: +49 711 685 66301
E-Mail: [email protected]
Website: http://www.iabp.uni-stuttgart.de
https://orcid.org/0000-0002-6268-8547
The text was updated successfully, but these errors were encountered: