CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Installation

[OpenFOAM.org] Build OPENFOAM from Source and Debug with VisualCode

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 3 Post By reverseila

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 14, 2022, 10:47
Post Build OPENFOAM from Source and Debug with VisualCode
  #1
New Member
 
Claudia
Join Date: Dec 2022
Posts: 2
Rep Power: 0
Claudia.Park is on a distinguished road
Hello,
Season's greetings!
Can someone please help me with setting up the openfoam repository in visual studio code or any other opensource IDE. I wish to debug into the source code repository with my added functions.

Any lead or step-by-step process to do this will be appreciated. Thanks
Claudia.Park is offline   Reply With Quote

Old   December 16, 2022, 17:03
Default
  #2
Member
 
Ali B.
Join Date: Mar 2020
Location: abzrg.github.io
Posts: 34
Rep Power: 6
reverseila is on a distinguished road
Hello Claudia

First compile OpenFOAM in debug mode. For that you have to set the following environment variable to Debug in
$WM_PROJECT_DIR/etc/bashrc before compiling OpenFOAM

Code:
# [WM_COMPILE_OPTION] - Optimised(default), debug, profiling, other:
# = Opt | Debug | Prof
export WM_COMPILE_OPTION=Opt  # change this to Debug
Tobias Holzmann have a video series in his website that touch on this (watch 2nd video).

Then you have to install VSCode and the C/C++ extension (from MicroSoft)...

Now, load OpenFOAM environment and open the VSCode in the root of your project,

Code:
cd path/to/my/project
of22 # or your version of Foam
code .
Next, open an arbitrary source file (at least one that contains a #include "..." statement). VSCode will probably issues warnings/errors that it can't find some header files.

Hover over one of the missing header files and click on the "Quick Fix..." and then click on the "Edit includePath settings". It will open a tab + create a .vscode directory in the root of the workspace. Close the tab! Open the file [font=courier]c_cpp_properties.json[font] and edit it as follows

Code:
{
            ...
            "includePath": [
                "${workspaceFolder}/**",
                "${env:FOAM_SRC}/**"
            ],
             ...
}
With this, VSCode can find all the source codes in the OpenFOAM libraries ($FOAM_SRC)...
If you have any other directories that contain source code, you can also put them here. for example

Code:
{
            ...
            "includePath": [
                "${workspaceFolder}/**",
                "${env:FOAM_SRC}/**",
                "${env:WM_PROJECT_USER_DIR}/src/**",
                "${env:WM_PROJECT_USER_DIR}/applications/solvers/mySolver/"
            ],
             ...
}
After you've done that, VSCode does some magic (look at the fire icon down in the bottom bar) and then you can jump around in the code. You can find definitions of most of the functions and variables (hopefully) by doing a right click and go to definition or go to references... (Note that this doesn't work in snippet files like "createFields.H")

If you also want to run & debug your code in VSCode, you can follow links below,
F42, Hughtong and Claudia.Park like this.

Last edited by reverseila; December 26, 2022 at 11:44.
reverseila is offline   Reply With Quote

Old   December 16, 2022, 23:48
Default
  #3
New Member
 
Claudia
Join Date: Dec 2022
Posts: 2
Rep Power: 0
Claudia.Park is on a distinguished road
Hi reverseila! On it
Thank you so much for the details. Really appreciate it.
Claudia.Park is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to develop OpenFOAM with CMake and popular IDEs cosscholar OpenFOAM Programming & Development 0 March 16, 2022 15:17
OpenFOAM 4.0 Released CFDFoundation OpenFOAM Announcements from OpenFOAM Foundation 2 October 6, 2017 05:40
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 19:08
UDF Scalar Code: HT 1 Greg Perkins FLUENT 8 October 20, 2000 12:40
UDFs for Scalar Eqn - Fluid/Solid HT Greg Perkins FLUENT 0 October 11, 2000 03:43


All times are GMT -4. The time now is 15:27.