Sample a volume field
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! |
Quote:
"foamToVTK -cellSet" might help. |
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 Code:
foamToVTK -cellSet alpha |
Sampling data in twoPhaseEulerFoam
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 |
topoSet and foamToVtk
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. |
Sample volumes instead of only surfaces or points
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 I tried this but it is not working so far. Code:
sample_volume //Name of the sample plane folder in /postprocessing |
Hi lukasf,
any luck with that? Thank you |
Unfortunately not, any suggestions?
|
Hi Lukas,
I couldn't figure a staightforward way. The volFieldValue solution posted in this thread ( https://www.cfd-online.com/Forums/op...tml#post772258 ) 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 |
Hi Agavi,
thanks for sharing. You are right that the following code returns emtpy fields (OF v1912). Code:
volFieldValue2 Code:
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?) |
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 |
The problem was using v1912. v2112 does not have a problem using the volFieldValue function.
Code:
volFieldValue1 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. |
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
|
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. |
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 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. |
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 |
All times are GMT -4. The time now is 20:18. |