Creating Setting up Windows 10 for OF use by Franco Otaola

From OpenFOAM Wiki
Jump to navigation Jump to search

Go back to Collection by authors.

Go back to Tips.

Setting up Windows 10 for OF use

In this tutorial some helpful tips for the setting up of a Windows 10 machine will be given. This steps are not essential for the use of OF in Windows but rather an improvement in usability and a speed improvement for the case setups. This tutorial will not touch the installation of OF in windows but rather steps to follow after its installation, for installation of OF in windows please refer to Installing OpenFOAM in Windows 10

Setting up Windows 10

Open linux shell here

One option that I missed a lot from my linux computer was to navigate with the file explorer to my case and then simply by right click we can open the terminal in that folder location, without the need of "cd path". Once you installed your WSL in Windows 10 exists too, by default, we need to use Shift+right click in the folder, this will give us the “advanced” version of the contextual menu, give us more choices (and having the open linux shell here). For people that really want to use only the right click, we can add this option to the classic contextual menu of windows. For this, we need to install ExectTI (ExectTI) and then follow the steps:

  • Install ExectTi (to be able to modify the registry of windows with the highest privilege)
  • Run regedit.exe -m (this will open the regedit)
  • Go to HKEY_CLASSES_ROOT\Directory\shell\WSL
  • Remove the "Extended" value right click>delete
  • Go to HKEY_CLASSES_ROOT\Directory\Background\shell\WSL
  • Remove the "Extended" value right click>delete
  • Restart your computer if necessary

These steps, will put the "open linux shell here" directly in the right click menu that can be helpful, all the credits for this tutorial to this page.


New text editor

Frequently in linux base system, the default text editors are more powerful than the windows default app, notepad, being able to automatically detect the language that the file is and highlighting the keywords. This utility can be quiet helpful for the modification of dictionary files as it allow us to see comments, vectors, loops, conditionals highlighted. The default windows app, is rather featureless, while it does the job, there are better suited free options out there. Notepad ++ (https://notepad-plus-plus.org/) is an excellent tool for an windows 10 OF user, it give us some life improvents when editing scripts and dictionaries, such as:

  • Line numbers, this can be rather helpful, a lot of times we need to know specifically the line number of an option inside an specific dictionary.
  • It can open several files at the same time in one windows in a tab-like style
  • Text highlight depending in the language (language > select specific language), at least from my experience, an OF user will at least use: C++ for the dictionaries and shell/python for scripting. It is possible to define a default language (Settings>New Document>Default language) I personally set up shell as I commonly find myself editing this type of files.
  • It can follow a log file (automatic update) while it is being generated. For this, open the log file in notepad++ and go to view>Monitoring (tail -f) or by clicking in the small eye icon. This as the brackets mentions will do exactly the same thing as using tail -f log.file in a terminal.

Some last tips about Notepad++, by default it, the software "saves" the session, this meaning when we close the window and we re open it, it will open all the files that were previously opened. To change this behavior, we need to go to Settings>Preferences>Backup and turn it off. One last tip in setting up Notepad++, is to turn on the auto update file option, this will update the files each X minutes if it has been modified by and external source, to turn on this option we need to go to settings>preferences>MISC. and turn on "Update silently", "Scroll to last line after update". While we are here you can turn on Document switcher (Ctrl+Tab), with this we can add the Alt+Tab windows behavior but for the different files opened inside Notepad++.


Setting up default text editor for extensionless files

Something quiet annoying in Windows is that, if the file does not have any extension or that it has an unknown extension, windows will ask with which program we want to open the file. In the later case, when the file has an unknown extension we can set up a default app, but when the file does not have any extension it is not possible (by GUI) to set up a default app. Nevertheless, we can set up this with some command lines in the windows terminal to set up a default app for extensionless files:


  • Open the windows terminal
  • Run <<assoc .="No Extension" >> (without the << >>)
  • Then run <<ftype "No Extension"="C:\path\to\my editor.exe" "%1" >> (without the << >> and also modifying the path "C:\path\to\my editor.exe" with the text editor of our preference, for example if we use notepad++ with the default windows location: " ftype "No Extension"=^"^%ProgramFiles^%\Notepad++\notepad++.exe^" "%1""

If, for any reason we want to go back to the previews state, where windows ask us each time with which software to open the files we can follow the steps:

  • Open the windows terminal
  • Run << ftype "No Extension"=" >> (without the << >>)
  • Run << assoc "No Extension"\DefaultIcon= >> (without the << >>)
  • Run << assoc .= >> (without the << >>)

All credits given to hasen from this post.


Creating a paraFoam-like command

At the moment (WSL2) the use of GUI linux apps can be quiet annoying. Therefore in case we miss the paraFOAM command that created an .FOAM file and opened directly in paraview, a workaround for this can be made. By installing paraview for windows and we can create an alias to it in the bashrc file.

  • Install paraview windows version for example in "/mnt/c/Program\ Files/ParaView\ 5.9.0-Windows-Python3.8-msvc2017-64bit"
  • Add to the bashrc << alias paraviewWindows="touch simulation.foam && /mnt/c/Program\ Files/ParaView\ 5.9.0-Windows-Python3.8-msvc2017-64bit/bin/paraview.exe simulation.foam" >> (without << >>)


This will create an alias (that we can call in the linux terminal) that will create in .foam file and open it in the paraview windows version.

Note 1: paraFoam has some build in features that OF adds to paraview, so sometimes some features can be missing, in my case I have not experienced this, but it is worth noticing it.

Note 2: the path of paraview installation depends on the computer so, it needs to be modified.


Creating bash scripts that uses trace scripts in paraview that are compatible to run in windows and in linux machines

Sometimes we can use the trace tool in paraview to automatize the post processing of our case, and this can be quiet helpful in an annoying boring tasks. The trace tool will create automatically a python script that then can be run it with pvpython application from paraview and it will do all the tasks for us. As in case of paraFoam if the script will use the GUI of paraview, the command: << pvpython traceScript.py >> will not work. An easy way around to be able to use the trace scripts in our bash scripts that will work in either windows and linux is to create a conditional that will detect it the script is being run in windows (and therefore it will use the pvpython installed in paraview for windows) or run the pvpython installed in the linux computer. When we are working in WSL over a windows folder we have /mnt/ before the windows path.

   cp ./code_1.py ./code_modif_1.py                             #we copy the original python code where the full path for the .foam file is 'PATH/file.foam'
   #EG.(inside code_1.py)===> simulationfoam = OpenFOAMReader(registrationName='simulation.foam', FileName='PATH/simulation.foam')
   sed -i "s|PATH|$(pwd)|" ./code_modif_1.py            #we change PATH to the current folder location


   if  head -c 5)" = "/mnt/" ;then
       echo "        - Running Windows paraview version"
       sed -i 's/\/mnt\/c/c:/' ./code_modif_1.py                 #In case that we are in a windows machine, we need to modify a second time the full path of the files
       /mnt/c/Program\ Files/ParaView\ 5.9.0-Windows-Python3.8-msvc2017-64bit/bin/pvpython.exe code_modif_1.py 2> /dev/null
   else
       echo "        - Running Linux paraview version"
       pvpython code_modif_1.py 2> /dev/null
   fi

This small conditional will automatically select what to run depending on the system that we are running it.


Note 1: remember that the path in the python script also needs to be changed depending in the system version.