Skip to content

Commit

Permalink
Updated Python code and doc for new option
Browse files Browse the repository at this point in the history
  • Loading branch information
gbacco5 committed Nov 24, 2018
1 parent 456c807 commit 315d4e9
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 26 deletions.
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fluid
Copyright 2018 Giacomo Bacco
Copyright 2018, Giacomo Bacco


isOctave
Expand Down
Binary file modified doc/doc.pdf
Binary file not shown.
39 changes: 36 additions & 3 deletions doc/doc.tex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@
}
\input{matlab}

\lstdefinestyle{Python}{
language = Python,
basicstyle = \ttfamily,
keywordstyle = \color{blue},
keywordstyle = [2] \color{teal}, % just to check that it works
stringstyle = \color{green},
commentstyle = \color{red}\ttfamily
}

\usepackage{pythonhighlight}

\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc,positioning,shapes.geometric,shapes.symbols,shapes.misc,arrows,math,arrows.meta}
Expand Down Expand Up @@ -197,11 +208,21 @@ \section{How to use}
There are some ``hidden'' options which should be explained.
\begin{enumerate}
\item you can provide personal flux-barrier angles, or let the program compute
them as the average of the final points $ \pt{C} $ and $ \pt{D} $ at the rotor
periphery.
them.
This means that you have to always provide the flux-barrier thicknesses and
flux-carrier widths.
Optionally, you could also provide the electrical flux-barrier angles.
\begin{lstlisting}[style=Matlab]
rotor.barrier_angles_el = [14,26,38]*2;
\end{lstlisting}

\item if you let the program compute them, they will result the average of the
final points $ \pt{C}' $ and $ \pt{D}' $ at the rotor periphery. Alternatively,
you can define some weights which determine how close $ \pt{E} $ should be to
$ \pt{C}' $ or $ \pt{D}' $.
\begin{lstlisting}[style=Matlab]
rotor.barrier_end_wf = [20,50,80]/100;
\end{lstlisting}

\item by default, the flux-barrier-end is round, so the code solves an
additional system to determine the correct locations of the fillet points.
Expand Down Expand Up @@ -681,7 +702,7 @@ \subsection{Example of Matlab/Octave plot}


\clearpage
\section{Code}
\section{Matlab Code}

\subsection{Main file}
\lstinputlisting[style=Matlab]{../fluid.m}
Expand All @@ -695,5 +716,17 @@ \subsection{Draw fluid barrier}
\lstinputlisting[style=Matlab]{../draw/draw_fluid_barrier.m}


\clearpage
\section{Python Code}

\subsection{Main file}
\lstinputpython{../fluid.py}
\clearpage

\subsection{Fluid functions}
\lstinputpython{../fluid_functions.py}
\clearpage



\end{document}
2 changes: 1 addition & 1 deletion doc/fluid.bib
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%% LaTeX2e file `fluid.bib'
%% generated by the `filecontents' environment
%% from source `doc' on 2018/10/07.
%% from source `doc' on 2018/11/24.
%%
@online{Bacco2018fluid,
title = {fluid: Free Fluid Flux-Barriers Rotor for Synchronous
Expand Down
150 changes: 150 additions & 0 deletions doc/pythonhighlight.sty
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pythonhighlight}[2011/09/19 python code highlighting; provided by Olivier Verdier <olivier.verdier@gmail.com>]


\RequirePackage{listings}
\RequirePackage{xcolor}

\renewcommand*{\lstlistlistingname}{Code Listings}
\renewcommand*{\lstlistingname}{Code Listing}
\definecolor{gray}{gray}{0.5}
\colorlet{commentcolour}{green!50!black}

\colorlet{stringcolour}{red!60!black}
\colorlet{keywordcolour}{magenta!90!black}
\colorlet{exceptioncolour}{yellow!50!red}
\colorlet{commandcolour}{blue!60!black}
\colorlet{numpycolour}{blue!60!green}
\colorlet{literatecolour}{magenta!90!black}
\colorlet{promptcolour}{green!50!black}
\colorlet{specmethodcolour}{violet}

\newcommand*{\framemargin}{3ex}

\newcommand*{\literatecolour}{\textcolor{literatecolour}}

\newcommand*{\pythonprompt}{\textcolor{promptcolour}{{>}{>}{>}}}

\lstdefinestyle{mypython}{
%\lstset{
%keepspaces=true,
language=python,
showtabs=true,
% ******************************************************************************
numbers=left,%none,%left,%
numberstyle={\scriptsize\ttfamily\color{gray}},%\tiny
% stepnumber=2,
% numberfirstline=true,
% numbersep=2pt,
numbersep=1em,
% firstnumber=auto,
numberblanklines=false,
% ******************************************************************************
tab=,
tabsize=2,
basicstyle=\ttfamily\footnotesize,%\setstretch{.5},
stringstyle=\color{stringcolour},
showstringspaces=false,
alsoletter={1234567890},
otherkeywords={\%, \}, \{, \&, \|},
keywordstyle=\color{keywordcolour}\bfseries,
emph={and,break,class,continue,def,yield,del,elif ,else,%
except,exec,finally,for,from,global,if,import,in,%
lambda,not,or,pass,print,raise,return,try,while,assert,with},
emphstyle=\color{blue}\bfseries,
emph={[2]True, False, None},
emphstyle=[2]\color{keywordcolour},
emph={[3]object,type,isinstance,copy,deepcopy,zip,enumerate,reversed,list,set,len,dict,tuple,xrange,append,execfile,real,imag,reduce,str,repr},
emphstyle=[3]\color{commandcolour},
emph={Exception,NameError,IndexError,SyntaxError,TypeError,ValueError,OverflowError,ZeroDivisionError},
emphstyle=\color{exceptioncolour}\bfseries,
%upquote=true,
morecomment=[s]{"""}{"""},
commentstyle=\color{commentcolour}\slshape,
%emph={[4]1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
emph={[4]ode, fsolve, sqrt, exp, sin, cos,arctan, arctan2, arccos, pi, array, norm, solve, dot, arange, isscalar, max, sum, flatten, shape, reshape, find, any, all, abs, plot, linspace, legend, quad, polyval,polyfit, hstack, concatenate,vstack,column_stack,empty,zeros,ones,rand,vander,grid,pcolor,eig,eigs,eigvals,svd,qr,tan,det,logspace,roll,min,mean,cumsum,cumprod,diff,vectorize,lstsq,cla,eye,xlabel,ylabel,squeeze},
emphstyle=[4]\color{numpycolour},
emph={[5]__init__,__add__,__mul__,__div__,__sub__,__call__,__getitem__,__setitem__,__eq__,__ne__,__nonzero__,__rmul__,__radd__,__repr__,__str__,__get__,__truediv__,__pow__,__name__,__future__,__all__},
emphstyle=[5]\color{specmethodcolour},
emph={[6]assert,yield},
emphstyle=[6]\color{keywordcolour}\bfseries,
emph={[7]range},
emphstyle={[7]\color{keywordcolour}\bfseries},
% emph={[7]self},
% emphstyle=[7]\bfseries,
literate=*%
{:}{{\literatecolour:}}{1}%
{=}{{\literatecolour=}}{1}%
{-}{{\literatecolour-}}{1}%
{+}{{\literatecolour+}}{1}%
{*}{{\literatecolour*}}{1}%
{**}{{\literatecolour{**}}}2%
{/}{{\literatecolour/}}{1}%
{//}{{\literatecolour{//}}}2%
{!}{{\literatecolour!}}{1}%
%{(}{{\literatecolour(}}{1}%
%{)}{{\literatecolour)}}{1}%
{[}{{\literatecolour[}}{1}%
{]}{{\literatecolour]}}{1}%
{<}{{\literatecolour<}}{1}%
{>}{{\literatecolour>}}{1}%
{>>>}{\pythonprompt}{3}%
,%
%aboveskip=.5ex,
frame=trbl,
%frameround=tttt,
%framesep=.3ex,
rulecolor=\color{black!40},
%framexleftmargin=\framemargin,
%framextopmargin=.1ex,
%framexbottommargin=.1ex,
%framexrightmargin=\framemargin,
%framexleftmargin=1mm, framextopmargin=1mm, frame=shadowbox, rulesepcolor=\color{blue},#1
%frame=tb,
backgroundcolor=\color{white},
breakindent=.5\textwidth,frame=single,breaklines=true%
%}
}

\newcommand*{\inputpython}[3]{\lstinputlisting[firstline=#2,lastline=#3,firstnumber=#2,frame=single,breakindent=.5\textwidth,frame=single,breaklines=true,style=mypython]{#1}}

%% MOD
\newcommand*{\lstinputpython}[1]{\lstinputlisting[frame=single,breakindent=.5\textwidth,frame=single,breaklines=true,style=mypython]{#1}}

\lstnewenvironment{python}[1][]{\lstset{style=mypython}}{}

\lstdefinestyle{mypythoninline}{
style=mypython,%
basicstyle=\ttfamily,%
keywordstyle=\color{keywordcolour},%
emphstyle={[7]\color{keywordcolour}},%
emphstyle=\color{exceptioncolour},%
literate=*%
{:}{{\literatecolour:}}{2}%
{=}{{\literatecolour=}}{2}%
{-}{{\literatecolour-}}{2}%
{+}{{\literatecolour+}}{2}%
{*}{{\literatecolour*}}2%
{**}{{\literatecolour{**}}}3%
{/}{{\literatecolour/}}{2}%
{//}{{\literatecolour{//}}}{2}%
{!}{{\literatecolour!}}{2}%
%{(}{{\literatecolour(}}{2}%
%{)}{{\literatecolour)}}{2}%
{[}{{\literatecolour[}}{2}%
{]}{{\literatecolour]}}{2}%
{<}{{\literatecolour<}}{2}%
{<=}{{\literatecolour{<=}}}3%
{>}{{\literatecolour>}}{2}%
{>=}{{\literatecolour{>=}}}3%
{==}{{\literatecolour{==}}}3%
{!=}{{\literatecolour{!=}}}3%
{+=}{{\literatecolour{+=}}}3%
{-=}{{\literatecolour{-=}}}3%
{*=}{{\literatecolour{*=}}}3%
{/=}{{\literatecolour{/=}}}3%
%% emphstyle=\color{blue},%
}

\newcommand*{\pyth}{\lstinline[style=mypythoninline]}

5 changes: 5 additions & 0 deletions fluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@

# you can input flux-barrier angles or let the program compute them
#rotor.barrier_angles_el = np.array([14,26,38])*2; # [deg], electrical flux-barrier angles

# or you can also input a factor to reach the top or the bottom of each barrier
# (do not exceed 100%)
#rotor.barrier_end_wf = np.array([20,50,80])/100; # flux-barrier-end weight factors

#rotor.barrier_end = 'rect'; # choose 'rect' or comment

# you can define the rib width or comment
Expand Down
27 changes: 6 additions & 21 deletions fluid_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ def calc_fluid_barrier(r, deb):
barrier_angles_el = r.barrier_angles_el; # [deg], electrical flux-barrier angles
AutoBarrierEndCalc = 0;
else:
barrier_angles_el = np.zeros([1,Nb]);
barrier_angles_el = np.zeros(Nb);
AutoBarrierEndCalc = 1;
if hasattr(r,'barrier_end_wf'):
wf = r.barrier_end_wf;
else:
wf = 0.5*np.ones(Nb);

if hasattr(r,'wm'):
wm = r.wm*ScalingFactor;
Expand Down Expand Up @@ -200,7 +204,7 @@ def calc_fluid_barrier(r, deb):
yDprime = Dend/2*np.sin(teDprime);

if AutoBarrierEndCalc:
teE = (teCprime + teDprime)/2;
teE = ( teCprime*(1 - wf) + teDprime*wf );
aphE = pi/2/p - teE;
barrier_angles = 180/np.pi*aphE;
barrier_angles_el = p*barrier_angles;
Expand All @@ -216,14 +220,6 @@ def calc_fluid_barrier(r, deb):











## Outer base points C (top)
if barrier_end == 'rect':
RC = RCprime;
Expand Down Expand Up @@ -321,14 +317,6 @@ def calc_fluid_barrier(r, deb):











XX = [];
YY = [];
Rm = [];
Expand Down Expand Up @@ -388,7 +376,6 @@ def calc_fluid_barrier(r, deb):
barrier.Rm = Rm;



if deb == 1:
Apt = np.multiply(RA/ScalingFactor, np.exp(1j*teA) );
Bpt = np.multiply(RB/ScalingFactor, np.exp(1j*teB) );
Expand All @@ -406,6 +393,4 @@ def calc_fluid_barrier(r, deb):





return barrier

0 comments on commit 315d4e9

Please sign in to comment.