WISDEM / CCBlade

A blade element momentum method for analyzing wind turbine aerodynamic performance that is robust (guaranteed convergence), fast (superlinear convergence rate), and smooth (continuously differentiable).
Other
45 stars 40 forks source link

CCBlade Installation #31

Open James-Ilosta opened 1 year ago

James-Ilosta commented 1 year ago

I'm trying to download CCBlade as a stand alone module. In the description it says that the only prerequisite is gfortran, however I also had to install GCC, meson and ninja too.

I wanted to install CCBlade inside a virtual environment, so I created one and began installation. When doing so it asked me to install meson, which I did. I then installed the GCC compiler and put it inside the virtual environment folder (I had some trouble with installing it and just adding it to the system path) Similarly with GFortran. It then asked me to install ninja, which I did. Following this I received the following error:

above ['C:\Users\user1\virtualenvironments\VENV1\Scripts\meson.EXE', 'setup', 'meson_build', '--prefix=C:\Users\user1\Downloads\CCBlade-master\CCBlade-master\meson_build', '-Dpython.purelibdir=.', '-Dpython.platlibdir=.'] below ['C:\Users\user1\virtualenvironments\VENV1\Scripts\meson.EXE', 'compile', '-vC', 'meson_build'] ninja: Entering directory `C:/Users/user1/Downloads/CCBlade-master/CCBlade-master/meson_build' [1/6] "C:\Users\user1\virtualenvironments\VENV1\Scripts\python.EXE" "-m" "numpy.f2py" "../ccblade/src/bem.f90" "-m" "_bem" "--lower" "--build-dir" "ccblade" Reading fortran codes... Reading file '../ccblade/src/bem.f90' (format:free) Post-processing... Block: _bem Block: inductionfactors In: :_bem:../ccblade/src/bem.f90:inductionfactors get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Block: relativewind In: :_bem:../ccblade/src/bem.f90:relativewind get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Block: definecurvature In: :_bem:../ccblade/src/bem.f90:definecurvature get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Block: windcomponents In: :_bem:../ccblade/src/bem.f90:windcomponents get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Block: thrusttorque In: :_bem:../ccblade/src/bem.f90:thrusttorque get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Block: inductionfactors_dv In: :_bem:../ccblade/src/bem.f90:inductionfactors_dv get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Block: relativewind_dv In: :_bem:../ccblade/src/bem.f90:relativewind_dv get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Block: windcomponents_dv In: :_bem:../ccblade/src/bem.f90:windcomponents_dv get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Block: definecurvature_dv In: :_bem:../ccblade/src/bem.f90:definecurvature_dv get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Block: thrusttorque_bv In: :_bem:../ccblade/src/bem.f90:thrusttorque_bv get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Block: definecurvature_bv In: :_bem:../ccblade/src/bem.f90:definecurvature_bv get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Block: definecurvature_dv2 In: :_bem:../ccblade/src/bem.f90:definecurvature_dv2 get_parameters: got "eval() arg 1 must be a string, bytes or code object" on 8 Applying post-processing hooks... character_backward_compatibility_hook Post-processing (stage 2)... Building modules... Building module "_bem"... Generating possibly empty wrappers" Maybe empty "_bem-f2pywrappers.f" Constructing wrapper function "inductionfactors"... fzero,a,ap = inductionfactors(r,chord,rhub,rtip,phi,cl,cd,b,vx,vy,[usecd,hubloss,tiploss,wakerotation]) Generating possibly empty wrappers" Maybe empty "_bem-f2pywrappers.f" Constructing wrapper function "relativewind"... alpha,w,re = relativewind(phi,a,ap,vx,vy,pitch,chord,theta,rho,mu) Generating possibly empty wrappers" Maybe empty "_bem-f2pywrappers.f" Constructing wrapper function "definecurvature"... x_az,y_az,z_az,cone,s = definecurvature(r,precurve,presweep,precone,[n]) Generating possibly empty wrappers" Maybe empty "_bem-f2pywrappers.f" Constructing wrapper function "windcomponents"... vx,vy = windcomponents(r,precurve,presweep,precone,yaw,tilt,azimuth,uinf,omegarpm,hubht,shearexp,[n]) Generating possibly empty wrappers" Maybe empty "_bem-f2pywrappers.f"

" I'm not familiar with fortran and so I'm not sure how to progress with the install. If you could provide any insight into what I'm doing wrong, This would be greatly appreciated.

gbarter commented 1 year ago

Apologies for the delay in reply. Also apologies that you are correct that the documentation is out of sync with the state of the code. I will update the README.

First, the easiest way to install CCBlade is to pip install wisdem or conda install wisdem (or mamba in place of conda).

If you want to continue building from source, can you let me know how you have installed the meson, ninja, gfortran, and gcc packages? Via conda or other means?

James-Ilosta commented 1 year ago

No worries.

I wasn't aware that you could simply use pip to install wisdem, as the documentation suggests using conda instead.

For installing meson and ninja i used pip. For downloading gcc and gfortran I used mingw64 to download gcc and gfortran, after which I moved it to my virtual environment root folder. Originally I had tried to add my mingw64 folder to path, but I couldn't seem to get my powershell terminal to recognise gcc or gfortran. I'm not that experienced in using mingw64 or downloading and installing programs in this way. So there is likely a better way to run ccblade without having to move the compilers to that folder.

gbarter commented 1 year ago

I am familiar with the struggle to get all of the PATH and ENVIRONMENT variables sorted out when using virtual environments and mingw64 on Windows. I have had success using Chocolatey as a Windows package manager instead.

It sounds like you found some workarounds to use CCBlade, but let me know if that isn't true. Yes, having WISDEM up on PyPi for pip-installs is a recent update and does simplify things.

James-Ilosta commented 1 year ago

I have tried installing WISDEM using pip and when running a script where ccblade is called I keep getting the following error:

Exception has occurred: ModuleNotFoundError (note: full exception trace is shown but execution is paused at: ) No module named 'wisdem.ccblade._bem' File "C:\Users\user1\Desktop\WISDEM\wisdem\ccblade\ccblade.py", line 32, in (Current frame) import wisdem.ccblade._bem as _bem File "C:\Users\user1\Desktop\WISDEM\wisdem\rotorse\rotor_power.py", line 16, in from wisdem.ccblade.ccblade import CCBlade, CCAirfoil File "C:\Users\user1\Desktop\WISDEM\wisdem\rotorse\rotor.py", line 4, in from wisdem.rotorse.rotor_power import RotorPower, NoStallConstraint File "C:\Users\user1\Desktop\WISDEM\wisdem\glue_code\glue_code.py", line 4, in from wisdem.rotorse.rotor import RotorSE File "C:\Users\user1\Desktop\WISDEM\wisdem\glue_code\runWISDEM.py", line 11, in from wisdem.glue_code.glue_code import WindPark File "C:\Users\user1\Desktop\WISDEM\wisdem__init__.py", line 1, in from wisdem.glue_code.runWISDEM import run_wisdem File "C:\Users\user1\Desktop\WISDEM\ROSCO_toolbox\utilities.py", line 30, in from wisdem.inputs import load_yaml File "C:\Users\user1\Desktop\WISDEM\ROSCO_toolbox\ofTools\fast_io\FAST_reader.py", line 8, in from ROSCO_toolbox.utilities import read_DISCON, load_from_txt File "C:\Users\user1\Desktop\WISDEM\script.py", line 20, in from ROSCO_toolbox.ofTools.fast_io.FAST_reader import * ModuleNotFoundError: No module named 'wisdem.ccblade._bem'

I've had this before and I can't seem to get past it. I've tried changing "wisdem.ccblade._bem" to the relative path to the script however I still can't seem to get it to work.

gbarter commented 1 year ago

I finally got onto a Windows machine and recreated the error using pip install wisdem. Looks like the compiled libraries were not getting built properly. I will do my best to fix them . . .

gbarter commented 1 year ago

After banging my head against the wall a number of times, I cannot get past this error on a pure pip-workflow in Windows. Everything works when using conda/mamba though and for Windows that might just have to be the recommended course of action. Apologies that I couldn't find the solution you were hoping for.

James-Ilosta commented 1 year ago

Hi Garrett. Thank you for trying. I really appreciate it. Is there a way to compile the libraries elsewhere and then simply move them to the pip module folder or when they are compiled, does is use environmental variables specified during the conda build? I'm really keen to use WISDEM inside my own virtual environment without needing conda, so I'm just wondering if there is another way.

gbarter commented 1 year ago

A compiled library will usually depend on some core system libraries, so it is a little tricky to compile in one environment on a specific platform and hope they will work elsewhere. On PyPI, we were uploaded a dozen or so different python-compiler-platform combinations. The benefit of Anaconda is that they tightly manage and control all of that for you.

ibrahim-hanif commented 3 months ago

I encountered a similar issue, which I recognized after installation and running the "unit tests" on the installation page (link) and couldn't solve it until a colleague reiterated that the fortran compiler should be installed without problems (from above link):

conda install -y m2w64-toolchain libpython       # (Windows only)
pip install --no-deps -e . -v

with this and going forward with the test, the error was solved and the test was run successfully, I hope. :)

(test_all.py output)

======================= 22 failed, 1285 passed, 13 skipped, 18122 warnings, 2 errors in 466.74s (0:07:46) =======================

Hope it is helpful.

spuech commented 2 months ago

Hi everyone,

I'm working with CCBlade and i have similar installation problems on my linux machine.

Step to reproduce

git clone https://github.com/WISDEM/CCBlade.git
cd CCBlade
python3 -m venv venv
source ./venv/bin/activate
pip install .
python test/test_ccblade.py

And below was the output :

Cloning into 'CCBlade'...
remote: Enumerating objects: 790, done.
remote: Counting objects: 100% (121/121), done.
remote: Compressing objects: 100% (71/71), done.
remote: Total 790 (delta 57), reused 100 (delta 42), pack-reused 669 (from 1)
Receiving objects: 100% (790/790), 8.80 MiB | 42.11 MiB/s, done.
Resolving deltas: 100% (405/405), done.
Processing /media/spuech/2674b085-8c34-4424-8954-94c7e9c7c8ea/spuech/Code/tmp/CCBlade
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Collecting numpy
  Using cached numpy-2.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.3 MB)
Collecting openmdao
  Using cached openmdao-3.34.2-py3-none-any.whl
Collecting scipy
  Using cached scipy-1.14.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (41.2 MB)
Collecting numpy
  Using cached numpy-1.26.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.2 MB)
Collecting networkx>=2.0
  Using cached networkx-3.3-py3-none-any.whl (1.7 MB)
Collecting requests
  Using cached requests-2.32.3-py3-none-any.whl (64 kB)
Collecting packaging
  Using cached packaging-24.1-py3-none-any.whl (53 kB)
Collecting urllib3<3,>=1.21.1
  Using cached urllib3-2.2.3-py3-none-any.whl (126 kB)
Collecting charset-normalizer<4,>=2
  Using cached charset_normalizer-3.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)
Collecting idna<4,>=2.5
  Using cached idna-3.10-py3-none-any.whl (70 kB)
Collecting certifi>=2017.4.17
  Using cached certifi-2024.8.30-py3-none-any.whl (167 kB)
Building wheels for collected packages: CCBlade
  Building wheel for CCBlade (pyproject.toml) ... done
  Created wheel for CCBlade: filename=CCBlade-1.3.1-cp310-cp310-linux_x86_64.whl size=78298 sha256=43581b117d128095c35beca4fd0d1838a284ba627c4c0db71d06a997fff85e09
  Stored in directory: /tmp/pip-ephem-wheel-cache-q64aqr1a/wheels/79/9d/5e/b17efbe5fa031c038fd9b84f690ecf7297f071dd4e1371fe6d
Successfully built CCBlade
Installing collected packages: urllib3, packaging, numpy, networkx, idna, charset-normalizer, certifi, scipy, requests, openmdao, CCBlade
Successfully installed CCBlade-1.3.1 certifi-2024.8.30 charset-normalizer-3.3.2 idna-3.10 networkx-3.3 numpy-1.26.4 openmdao-3.34.2 packaging-24.1 requests-2.32.3 scipy-1.14.1 urllib3-2.2.3
Traceback (most recent call last):
  File "/media/spuech/2674b085-8c34-4424-8954-94c7e9c7c8ea/spuech/Code/tmp/CCBlade/test/test_ccblade.py", line 20, in <module>
    from ccblade.ccblade import CCBlade, CCAirfoil
  File "/media/spuech/2674b085-8c34-4424-8954-94c7e9c7c8ea/spuech/Code/tmp/CCBlade/venv/lib/python3.10/site-packages/ccblade/__init__.py", line 1, in <module>
    from .ccblade import CCAirfoil, CCBlade
  File "/media/spuech/2674b085-8c34-4424-8954-94c7e9c7c8ea/spuech/Code/tmp/CCBlade/venv/lib/python3.10/site-packages/ccblade/ccblade.py", line 31, in <module>
    import ccblade._bem as _bem
ModuleNotFoundError: No module named 'ccblade._bem'

I feel like a part of the code that might be in fortran is being left out. I've been using the tag v1.3 from 2022 but the install process doesn't work anymore as well. I spent quite some times yesterday trying to figure this out but i have to admit this is too complicated for me.

@gbarter, I hope you'll find a solution and stop banging your head against the wall as it must hurt :stuck_out_tongue_winking_eye: .

gbarter commented 2 months ago

You are also sure that you have fortran compiler installed on your linux machine (usually gfortran)? Could you try the install in verbose mode: pip install . -vv? That should give some good hints as to what is going wrong.

spuech commented 2 months ago

Hey, i was in a meeting but here are the logs i obtained : log.txt Here is an error in the logs :

  *** Error compiling '/media/spuech/2674b085-8c34-4424-8954-94c7e9c7c8ea/spuech/Code/tmp/CCBlade/venv/lib/python3.10/site-packages/docs/examples/gradients.py'...
    File "/media/spuech/2674b085-8c34-4424-8954-94c7e9c7c8ea/spuech/Code/tmp/CCBlade/venv/lib/python3.10/site-packages/docs/examples/gradients.py", line 187
      print '(analytic) dNp_i/dr_i =', dNp_dr[idx, idx]
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?

Actually, i commented prints lines an it fix the issue

gbarter commented 2 months ago

If you are running off of the old release source code, that might be the issue. Would you be able to grab the current master branch? Alternatively, I could tag a new release.

spuech commented 2 months ago

I've checked and i was on the master branch :

(venv) spuech@titan:/media/spuech/2674b085-8c34-4424-8954-94c7e9c7c8ea/spuech/Code/tmp/CCBlade$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   docs/examples/gradients.py

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    log.txt
    venv/

no changes added to commit (use "git add" and/or "git commit -a")

The changes to docs/example/gradients are used to fix the error from before. The venv is my python venv in which i work and the log is the above log.

spuech commented 2 months ago

I think i progressed a bit. I've been able to identify a manual workaround.

here are the command i used :

mkdir ccblade_install_test
cd ccblade_install_test
python3.11 -m venv venv
source ./venv/bin/activate
pip install git+ssh://git@github.com/spuech/CCBlade.git -vv --no-clean > log.txt

#In the log.txt file, i have a line is like this :
#Copying build file /tmp/pip-req-build-vnoicw1m/meson_build/ccblade/_bem.cpython-311-x86_64-linux-gnu.so -> ccblade/_bem.cpython-311-x86_64-linux-gnu.so

Then i do :

cp /tmp/pip-req-build-vnoicw1m/meson_build/ccblade/_bem.cpython-311-x86_64-linux-gnu.so ./venv/lib/python3.11/site-packages/ccblade/
python -c "import ccblade._bem as _bem"

From this point i'm able to use ccblade as i was before. They might be something about the copy past of the library _bem.cpython-311-x86_64-linux-gnu.so that is not done. However from the logs i can see i don't identify why the library isn't copy pasted.

PS : thanks @gbarter, i did not know about pip install -vv option which is super useful :heart_decoration: !

gbarter commented 2 months ago

Oh, interesting. Yes, that is definitely a shortcoming in the meson script. It probably hasn't been as well tested for virtual environments that are not conda environments. I'm glad you were able to resolve it on your end. Definitely an area for improvement on my side too.