|
[Sponsors] |
November 9, 2010, 04:47 |
Sample a volume field
|
#1 |
Senior Member
Gijsbert Wierink
Join Date: Mar 2009
Posts: 383
Rep Power: 18 |
Dear all,
I would like to "sample a volume", i.e. write out a volumetric field as raw data. I normally use the sample utility, but that samples points, lines, and surfaces. Does anyone know a trick to write out a volumetric field in the same way sample writes out e.g. a surface? Is the only option writing a "volume function" in the sample utility or python scripting with paraview? Thanks in advance!
__________________
Regards, Gijs |
|
November 10, 2010, 10:42 |
|
#2 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Quote:
"foamToVTK -cellSet" might help. |
||
November 10, 2010, 11:36 |
|
#3 |
Senior Member
Gijsbert Wierink
Join Date: Mar 2009
Posts: 383
Rep Power: 18 |
Hi Mark,
Thanks for your reply. I would like to get the alpha field with xyz coordinates out of a twoPhaseEulerFoam case. So, what I now tried is to run cellSet with the following cellSetDict: Code:
// Name of set to operate on name alpha;//c0; // One of clear/new/invert/add/delete|subset/list action new; // Actions to apply to cellSet. These are all the topoSetSource's ending // in ..ToCell (see the meshTools library). topoSetSources ( // Cells with cell centre within box boxToCell { box (0 0 0) (1 1.5 1); } // values of field within certain range fieldToCell { fieldName alpha;//U; // Note: uses mag(U) since volVectorField min 0.0; max 1.0; } ); Code:
foamToVTK -cellSet alpha
__________________
Regards, Gijs |
|
May 8, 2014, 08:18 |
Sampling data in twoPhaseEulerFoam
|
#4 |
Member
Gitesh
Join Date: Jan 2010
Location: Finland
Posts: 73
Rep Power: 16 |
Hello,
I want to store volume averaged values of some fields (i.e., alpha, k and epsilon) only in particular area of interest (around the interface region) in twoPhaseEulerFoam. Does we have any utility in OpenFOAM which can be useful to achieve the data? Thanks in advanced! With regards, GP |
|
June 5, 2014, 07:54 |
topoSet and foamToVtk
|
#5 |
New Member
Renato Sousa
Join Date: Jul 2013
Posts: 2
Rep Power: 0 |
take a look at topoSet utility with topoSetDict, I'm still exploring it but it might create a set with the cells that you want according to different filter options.
then use the foamToVtk with the -cellSet option to extract the values from your set. |
|
March 11, 2021, 07:01 |
Sample volumes instead of only surfaces or points
|
#6 |
Senior Member
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8 |
Hi,
there are functions to sample data from points and surfaces. However, is there a libsampling function which can sample volumes in my domain during runtime? There are 6 Valid function types : patchProbes probes psiReactionThermoMoleFractions rhoReactionThermoMoleFractions sets surfaces I tried to use "sets". Moreover, I used a topoSetDict to define the cell volume of interest: Code:
actions ( { name volume_of_interest; type cellSet; action new; source boxToCell; sourceInfo { box (0.1 -0.06 -0.06) (0.16 0.06 0.06); } } ); I tried this but it is not working so far. Code:
sample_volume //Name of the sample plane folder in /postprocessing { type sets; libs (sampling); writeControl timeStep; timeStart 0; writeInterval 1; surfaceFormat vtk; interpolationScheme cell; fields ( U ); sets (volume_of_interest); } |
|
June 30, 2021, 17:23 |
|
#7 |
New Member
Join Date: Aug 2020
Posts: 20
Rep Power: 6 |
Hi lukasf,
any luck with that? Thank you |
|
July 1, 2021, 03:48 |
|
#8 |
Senior Member
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8 |
Unfortunately not, any suggestions?
|
|
July 1, 2021, 11:57 |
|
#9 |
New Member
Join Date: Aug 2020
Posts: 20
Rep Power: 6 |
Hi Lukas,
I couldn't figure a staightforward way. The volFieldValue solution posted in this thread ( sampling on cellSet ) produced an empty file in latestTime/ instead of the values at the cells of the cellSet. I'm using OF 2006 so maybe there are some differences there. I ended up making a coded function object that reads the field and the cellSet Id list and prints just the field values of the cells in the cellSet. Here is the function object: sampleCellSet { type coded; libs (utilityFunctionObjects); name sampleCellSet; writeControl timeStep; writeInterval 1; codeWrite #{ Info << " Sampling cellSet..." ; const Time& runTime = mesh().time(); cellSet sampleSet(mesh(), "wakeSet"); volVectorField U = mesh().lookupObject<volVectorField>("U"); fileName timeDir = runTime.path()/runTime.timeName(); if (!isDir(timeDir)) { mkDir(timeDir); } OFstream file(timeDir/"U_wake.dat"); forAll(mesh().C(), id) { if (sampleSet[id]) { file << U[id] << endl; } } Info << "done. " <<endl; #}; codeInclude #{ #include "cellSet.H" #}; codeOptions #{ #}; } Surely there are better ways to go about it but for me this is a simple way to avoid interpolations of data, as long as I need the values at the cell centres. Best |
|
July 6, 2021, 03:44 |
|
#10 |
Senior Member
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8 |
Hi Agavi,
thanks for sharing. You are right that the following code returns emtpy fields (OF v1912). Code:
volFieldValue2 { // Mandatory entries (unmodifiable) type volFieldValue; libs (fieldFunctionObjects); // Mandatory entries (runtime modifiable) fields (U); operation none; regionType cellZone; name box; // Optional entries (runtime modifiable) postOperation none; //weightField alpha1; // Optional (inherited) entries writeFields true; //false; scalingFactor 1.0; region region0; enabled true; log true; writePrecision 8; writeToFile true; useUserTime true; timeStart 0; timeEnd 1000; executeControl timeStep; executeInterval 1; writeControl timeStep; //adjustableRunTime; writeInterval 1; } Code:
cellObj1 { type volRegion; libs ("libfieldFunctionObjects.so"); enabled true; writeControl adjustableRunTime; writeInterval 0.01; log true; writeFields true; regionType cellZone; name d0z; operation none; fields ( p U ); } Your code does work to create .dat files with the field content. Thank you! How do you post process this format to visualize it in ParaView or load it into Matlab / Python? How do you read the matching coordinates of the cells from the cellSet (or cellZone?) |
|
January 21, 2022, 07:29 |
|
#11 |
Senior Member
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8 |
Hi,
I am planing to do the following to sample volumes and apply the DMD. 1. I need to sample a volume within my simulation. I could not find a function which does this for me. So there are 2 options: Option1: use a topoSetDict to define a cellSet. Export the cellCenters with paraview to a .csv file. I could read this file and create probe points at those locations of the cellSet. I am not sure how good this idea is if your region of interest has e.g. 10 million cells which would lead to 10 million files. Option2 is which I prefer. I just save the whole 3D field. Afterwards I use the function foamToVTK to create VTK files which are readable by ParaView: Code:
foamToVTK -cellSet DMD_cellset -time '0.1:0.2' -useTimeName -ascii -excludePatches '(".*")' -noFaceZones https://github.com/mathLab/PyDMD#readme. Afterwards, I need to save the postprocessing result of the DMD into the VTK format again so that I can postprocess the solution further with Paraview. I am happy for any ideas to improve this approach. Lukas |
|
February 2, 2022, 10:23 |
|
#12 |
Senior Member
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8 |
The problem was using v1912. v2112 does not have a problem using the volFieldValue function.
Code:
volFieldValue1 { type volFieldValue; libs ("libfieldFunctionObjects.so"); log false; //true; writeControl adjustableRunTime; writeFormat ascii; //binary; writeInterval 1e-5; writeFields true;//writes the fields of the volume //timeStart 0; //timeEnd 1000; regionType cellSet; //cellZone; name box; // box is the cellSet or cellZone defined by the topoSetDict operation none; fields ( U T p ); } One receives a file in postProcessing/volFieldValue1 which is not important. The volume field is directly written to the time directories or time directories of the processor0. In this directory I run this command. Code:
foamToVTK -cellSet box -useTimeName -excludePatches '(".*")' -noFaceZones Moreover, I source a non ESI openfoam Version for the foamToVTK command because this way the "-useTimeName" is available which I prefer. |
|
September 19, 2022, 12:45 |
|
#13 |
New Member
Luiz Oliveira
Join Date: Aug 2018
Location: Napoli, Italy
Posts: 24
Rep Power: 8 |
I confirm that this solution also works for v2206, with a small change into the last step, because -useTimeName and -excludePatches entries are now deprecated.
Code:
foamToVTK -cellSet extendedPorousZone -exclude-patches '(".*")' -noFaceZones
__________________
Luiz Oliveira PhD. Student in Environmental Fluid Dynamics University of Napoli: Federico II |
|
September 20, 2022, 04:34 |
|
#14 |
Senior Member
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8 |
Hi Luiz,
I ended up not using the sample volume field method because of this problem. My Workflow right now: 1. Saving the whole flow field (Downside: One has to stop the simulation before the sampling interval, to adjust PurgeWrite and the WriteInterval in the controlDict) 2. Reconstructing of the time range of interest 3. Formatting the OpenFOAM solution to VTK and selecting specific volume region (cellSet) foamToVTK -cellSet DMDVolume -no-point-data -fields '(T U)' -time '0.164960439:0.1699812643' I think I used "no point data" to reduce the file size. 4. Remove reconstructed fields with foamListTimes -time ‘:’ -rm .. (save disk space)
I am happy if you find a better solution and share it here. |
|
September 22, 2022, 11:23 |
|
#15 |
New Member
Luiz Oliveira
Join Date: Aug 2018
Location: Napoli, Italy
Posts: 24
Rep Power: 8 |
Hi Lukas,
This sounds like a good workflow, at the end this is what I've doing in the past as well to increase the saving frequency. I did not think about exporting into vtk for long storage, although I will certainly give it a try. I would only suggest a small change into your first step. You can automate changes into any OF file using the following procedure, this implies that you do not have to stop the simulation if you have runTimeModifiable option as yes in controlDict: Code:
functions { saveFrequencyUpdate { type timeActivatedFileUpdate; libs ("libutilityFunctionObjects.so"); writeControl timeStep; writeInterval 1; fileToUpdate "$FOAM_CASE/system/controlDict"; timeVsFile ( (-1 "$FOAM_CASE/system/controlDict.0") // Initial time (150 "$FOAM_CASE/system/controlDict.150") // Begin sampling ); } } PS: Since we are both interested into saving disk space. I recommend saving all the data into binary instead of ASCII. This saved a great amount of space in all my simulations, even if I was using compressed ASCII before.
__________________
Luiz Oliveira PhD. Student in Environmental Fluid Dynamics University of Napoli: Federico II Last edited by Luiz; September 22, 2022 at 11:31. Reason: Disk spacing tips |
|
September 22, 2022, 12:49 |
|
#16 |
Senior Member
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8 |
I think the good thing about vtk format is that:
1. you could reduce your domain further to save disk space -cellSet DMDVolume 2. you can only extract the fields of interest -fields '(T U)' 3. python can read and manipulate the files easily 4. paraview can visualize the files |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to compare volume scalar field with constant values | sachin | OpenFOAM Running, Solving & CFD | 4 | April 11, 2019 04:34 |
FloWorks (Flow Express) Volume Goal Setting Issue | rbigelow | FloEFD, FloWorks & FloTHERM | 1 | November 16, 2009 02:32 |
FloWorks (Flow Express) Volume Goal Setting | rbigelow | Main CFD Forum | 0 | November 13, 2009 15:28 |
Problem with rhoSimpleFoam | matteo_gautero | OpenFOAM Running, Solving & CFD | 0 | February 28, 2008 07:51 |
fluent add additional zones for the mesh file | SSL | FLUENT | 2 | January 26, 2008 12:55 |