OpenFOAM_EN - CCSEPBVR/CS-IS-PBVR GitHub Wiki
To visualize calculation results from OpenFOAM using PBVR, you need to convert the data into a file format that PBVR support, such as VTK, EnSight Gold, or CGNS. For this purpose, you can use OpenFOAM commands like foamToVTK or foamToEnsight.
Examples are shown below (for how to enable OpenFOAM commands, refer to this article):
foamToEnsight -no-boundary -time 0:1 # Convert to EnSight Gold format
foamToVTK -no-boundary -time 0:1 # Convert to VTK format
The time
option allows you to specify the time range of the data to convert.
The no-boundary
option removes the outer polygon data and converts only the inner volume data.
PBVR cannot display data that includes outer polygons, so only the inner volume data should be converted.
Note that depending on the version of OpenFOAM, some commands or options may not be supported. You should check the manual or use help commands to verify.
If certain commands or options are not available, you can use the paraFoam
command to generate files for ParaView, and then export them in a format suitable for PBVR from within ParaView.
By inserting the FoamToPbvr adapter that comes with pbvr into OpenFOAM, the OpenFOAM solver can generate particles for visualization, which is stored in the Filter directory and can be used by referencing and linking to the particle generation library like the particle sampler. The adapter converts the variable array of computed physical values into the vtkUnstructuredGrid class using the vtk library and passes it to the particle sampler. The following shows the operation procedure of the OpenFOAM sample code attached to PBVR.
In this case, the sample code is run on a supercomputer (SGI8600) owned by JAEA. When operating on a separate server, the module, etc. should be read separately.
[Module] GNU/9.5.0 openMPI/4.1.4
[OpenFOAM] 10 (Foundation version) (pre-installed ''/home/app/OpenFOAM/OpenFOAM-10'')
【サンプルコード名】 cavity flow
【vtk】 v9.2 (pre-installed /home/center/viztools/VTK-9.2.2
)
【shell】 bash
The module loading command is as follows.
module purge; module load gnu/9.5.0 openmpi/4.1.4
Here, the path of the installation directory is ($install_dir_pbvr).
In the installation directory, run git clone.
git clone [email protected]:CCSEPBVR/CS-IS-PBVR.git -b release_v3.3.0
In order to create a library for OpenFOAM, change the compile settings of pbvr as shown in the figure as shown below. Change PBVR_MACHINE to gcc and VTK_PTAH to true. Also, if necessary, set the path to the pre-installed VTK library. (Default)
As soon as the configuration is complete, run the compilation.
make -j 40
In order to use the pbvr library in OpenFOAM, the compilation settings are matched with pbvr. In SGI8600, the pre-installed OpenFOAM is copied locally and the settings are changed.
If the path of the OpenFOAM installation directory is ($install_dir_foam), the copy command is as follows.
cp -r /home/app/OpenFOAM/OpenFOAM-10 ($install_dir_foam)
cp -r /home/app/OpenFOAM/ThirdParty-10 ($install_dir_foam)
Once copied, set the FOAM_INST_DIR of ($install_dir_foam)/OpenFOAM-10/etc/bashrc to ($install_dir_foam) and change the environment variable WM_COMPIKER to Gcc as shown in the red line in the figure.
From here, enable the OpenFOAM command. First, run /etc/bashrc once.
source ($install_dir_foam)/OpenFOAM-10/etc/bashrc
Run ./allwmake in the OpenFOAM directory.
cd OpenFOAM-10
./Allwmake
Ready to enable by running /etc/bashrc again. When the help log appears with the following command, it is enabled.
source ($install_dir_foam)/OpenFOAM-10/etc/bashrc
icoFOAM –help
Compilation command part ( CC = ... ) in the compile configuration file (''$install_dir_foam)/OpenFOAM-10/wmake/rules/linux64Gcc/c++'') as shown in the figure.
Go to the sample code directory for OpenFOAM (here, IS_DaemonAndSampler/Example/C/gcc_mpi_omp/cavity_flow_vtk) and add the path in Make/options to use the pbvr library as follows. (Already added in the sample code)
This completes the configuration on the OpenFOAM side.
Build the sample code. After compilation is complete, binaries are generated in $FOAM_APPBIN.
wmake -j
As a pre-process, execute the mesh generation command.
blockMesh
decomposePar
Set the environment variables as per the in-situ setup.
export VIS_PARAM_DIR=($install_dir_pbvr)/CS-IS-PBVR/IS_DaemonAndSampler/Example/C/gcc_mpi_omp/cavity_flow_vtk
export PARTICLE_DIR=($install_dir_pbvr)/CS-IS-PBVR/IS_DaemonAndSampler/Example/C/gcc_mpi_omp/cavity_flow_vtk/particle_out
Create a particle_out as a directory for particle data.
mkdir particle_out
Now that the solver is ready to run, run the OpenFOAM solver. Since icoFoam.C is used as a sample code, the execution command is as follows.
mpirun –n 2 icoFoam –parallel
The procedure for running the daemon on a remote server is shown here. Note that the solver and daemon are expected to run concurrently, so it is recommended to work in a new tab (don't forget to load the module).
The construction work of the daemon code is omitted because it is performed at the same time as the solver is built. Set the following two environment variables before execution.
export VIS_PARAM_DIR=($install_dir_pbvr)/CS-IS-PBVR/IS_DaemonAndSampler/Example/C/gcc_mpi_omp/cavity_flow_vtk
export PARTICLE_DIR=($install_dir_pbvr)/CS-IS-PBVR/IS_DaemonAndSampler/Example/C/gcc_mpi_omp/cavity_flow_vtk/particle_out
Navigate to the Daemon directory and run the pbvr_daemon.
cd ($install_dir_pbvr)/CS-IS-PBVR/IS_DaemonAndSampler/Daemon
./pbvr_daemon
“waiting connection… If the log appears, it is successful. Since it is in a waiting state for connection, move on to connection operation from the client side without stopping.
You have been given a tutorial on how to port forward, run a client, and connect to a remote server.
The visualization result of the sample code is shown in the figure below. The visualization parameters at this time are described below.
- Time step: 300 (steady state)
Transfer function
- Color Function Synthesizer : C1
- Opacity Function Synthesizer : O1
- Color Map Function [C1] : f(q1)
- Opacity Map Function[O1] : f(q1)
- minmax mode: server size Min Max
Glyph
- scale factor : 0.1
- Distribution mode: AllPoints
- Size: constant
- Color : Variables Array
- Number of variables: 3
- q1
- q2
- q3
- Number of variables: 3
plot over line
- Resolution:256
- Target: q1
- Start point: (0.5, 0, 0.05)
- End point: (0.5, 1, 0.05)
The calculation content of this sample code is a two-dimensional cavity flow. The z direction is uniform by imposing periodic boundary conditions.
The calculation parameters are as follows.
- MPI Process: 2MPI
- Wall velocity : 1(m/s)
- Number of cells (n_x, n_y, n_z): 400(20, 20, 1)
- Talk:Hexahedra
- Computing field (L_x, L_y, L_z): (1, 1, 0.5)
- Reynolds number (kinematic viscosity): 100
The above figure is just an example, and the required files vary depending on the solver.
Here, an example of embedding PBVR function in icoFoam.C and output interval control is described.
Like OpenFOAM, the adapter uses a method of inserting include files. As shown in the figure, the PBVR function is called by expanding the specified filter file (red line). (Details will be described later)
There are two types of adapters, the polyhedron type and the mixed cell type. For the mixed cell type, only HEX, WEDGE, PRISM, and PYR type cells included in the cellModel Class of OpenFOAM can be visualized, but the processing speed is fast. On the other hand, the Polyhedron type can handle cells as they are, so it has a wide range of support.
There is no difference between the two usage methods described below, but I was warned to use only one of them, as mixing them can cause errors.
Supported Types | File Name |
---|---|
mixed cell type | Conversion_from_OpenFOAM_to_vtk_***.h |
polyhedron type | Conversion_from_OpenFOAM_to_vtkpolyhedron_***.h |
The adapter uses a .h file with (initial_step ) on the first use, and an .h file with (later_step) on the second and subsequent uses.
Here, a FoamToPbvr adapter that performs information refilling processing from OpenFOAM format to VTK format will be described. This adapter uses vtk library functions to convert coordinates, connection information, and variable data in OpenFOAM format to the vtk format supported by the particle sampler. Conversion processing is performed for variable data at each output step, but conversion processing is performed only for the first output step for coordinate and connection information data, reducing processing costs. In addition, conversion processing from cell data to point data is also performed during the conversion process.
If you want to change or add the calculation parameters you want to visualize, you need to edit the adapter.
The adapter is stored in the ''($install_dir_pbvr)/CS-IS-PBVR/IS_DaemonAndSampler /insitulib/unstruct/filter directory.
You can increase the number of variables by copying and pasting the black frame part of the figure below and inserting the variable array to be visualized into InsertNextValue(). Be careful not to duplicate variable names.
The "depthCharge3D" tutorial from OpenFOAM is used as sample data in the Ensight Gold format for CS-PBVR. The following explains how to execute the simulation and export the data.
In this case, the sample code is run on a supercomputer (SGI8600) owned by JAEA.
When operating on a separate server, the module, etc. should be read separately.
【Module】gnu/9.5.0 openmpi/4.1.4
【OpenFOAM】v2206 (ESI version) (pre-installed /home/app/OpenFOAM/OpenFOAM-v2206
)
【shell】bash
The module loading command is as follows.
module purge; module load gnu/9.5.0 openmpi/4.1.4
If the path of the OpenFOAM installation directory is ($install_dir_foam), the copy command is as follows.
cp -r /home/app/OpenFOAM/OpenFOAM-v2206 ($install_dir_foam)
cp -r /home/app/OpenFOAM/ThirdParty-v2206 ($install_dir_foam)
Make sure that WM_COMPILER is set to Gcc in $(install_dir_foam)/OpenFOAM-v2206/etc/bashrc.
Set projectDir
to $(install_dir_foam)
/OpenFOAM-v2206 in $(install_dir_foam)
/OpenFOAM-v2206/etc/bashrc.
From here, enable the OpenFOAM command. First, run /etc/bashrc once.
source ($install_dir_foam)/OpenFOAM-v2206/etc/bashrc
Run ./allwmake in the OpenFOAM directory.
cd OpenFOAM-2206
./Allwmake
Ready to enable by running /etc/bashrc again. When the help log appears with the following command, it is enabled.
source ($install_dir_foam)/OpenFOAM-v2206/etc/bashrc
icoFOAM –help
The execution method is as follows.
# Move to the "depthCharge3D" tutorial directory
cd $(install_dir_foam)/OpenFOAM-v2206/tutorials/multiphase/compressibleInterFoam/laminar/depthCharge3D
# Copy initial conditions
cp -r 0.orig 0
# Generate the mesh
blockMesh
setFields # Divide the computational domain into subdomains and assign each subdomain
decomposePar # Partition the mesh
# Run the simulation
mpirun -np 4 compressibleInterFoam -parallel > output.log
tail -f output.log # Check the simulation status
Create sample data from the simulation results. The execution method is as follows.
You can specify the time of the data to be converted with the time
option.
The no-boundary
option removes the outer polygon data and converts only the inner volume data.
reconstructPar -time 0:0.1 # Combine the data from all processors
foamToEnsight -no-boundary -time 0:0.1 # Convert to Ensight Gold format
foamToVTK -no-boundary -time 0:0.1 # Convert to VTK format