|
[Sponsors] |
August 24, 2013, 05:57 |
Modifying forces.C to output CSV
|
#1 |
Member
Anand Lobo
Join Date: Jun 2013
Posts: 56
Rep Power: 13 |
Hi all.
I'm attempting to make sense of the forces/moments output I get from OpenFOAM, and it's getting rather tiresome to have to edit my forces output into CSV and perform further calculations for every simulation. I've (kind of) found where the forces is output to file, in src/postProcessing/functionObjects/forces/forces/forces.C: Code:
00676 file() << obr_.time().value() << tab 00677 << "(" 00678 << sum(force_[0]) << "," 00679 << sum(force_[1]) << "," 00680 << sum(force_[2]) 00681 << ") " 00682 << "(" 00683 << sum(moment_[0]) << "," 00684 << sum(moment_[1]) << "," 00685 << sum(moment_[2]) 00686 << ")" 00687 << endl; |
|
August 24, 2013, 07:50 |
|
#2 |
Senior Member
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,902
Rep Power: 37 |
Hi Bolar,
The easiest would probably be to make a small shell script, which does all the modifications for you. Something along these lines (but please test on a copy first, since it is untested): Code:
#!/bin/bash ## Put the first input argument into variable 'inputFile' inputFile=$1 ## Check whether the first argument is empty if [ -z "$inputFile" ] then echo "Please provide the path to the forces files as input argument." exit fi ## Count the number of lines in the input file nLines=`wc -l < $inputFile` ## Strip the first line with the header information (line 2->nLines) and ## then after the piping (sign: |) it strips all of the parentheses. The ## result is outputted in the filename $inputFile.mod, i.e. at the same ## location as the input file with a ".mod" added in the end. sed -n '2,'$nLines'p' < $inputFile | sed 's/[()]//g' > $inputFile.mod 1. First, create the directory (if not already existing): Code:
mkdir $HOME/bin Code:
$HOME/bin/processForces.sh Code:
chmod +x $HOME/bin/processForces.sh Code:
export PATH=$HOME/bin/:$PATH A: Code:
cp -r forces forcesPlay Code:
processForces.sh forcesPlay/0/forces.dat Code:
processForces.sh forces/0/forces.dat I hope that this has helped. Kind regards Niels
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request. |
|
August 26, 2013, 02:56 |
|
#3 |
Member
Anand Lobo
Join Date: Jun 2013
Posts: 56
Rep Power: 13 |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] outputTime in Swak function | immortality | OpenFOAM Community Contributions | 20 | October 6, 2022 13:08 |
RNG diverged during the analysis the flow over a multi element airfoil, why? | s.m | OpenFOAM Running, Solving & CFD | 0 | August 5, 2013 09:39 |
mixerVesselAMI2D's mass is not balancing | sharonyue | OpenFOAM Running, Solving & CFD | 6 | June 10, 2013 10:34 |
[OpenFOAM] Probe Multiple Points in ParaView and Output as CSV | eric.m.tridas | ParaView | 4 | November 29, 2011 14:30 |
Output transient file to csv | Ben | CFX | 3 | September 23, 2008 09:17 |