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

Modifying forces.C to output CSV

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By ngj

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 24, 2013, 05:57
Default Modifying forces.C to output CSV
  #1
Member
 
Anand Lobo
Join Date: Jun 2013
Posts: 56
Rep Power: 13
Boloar is on a distinguished road
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;
Is there a function that outputs the magnitude of a vector input? And how can I get rid of those parentheses that show up in the output? I ask because I'm not the most competent programmer.
Boloar is offline   Reply With Quote

Old   August 24, 2013, 07:50
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,902
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
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
You can work with this script in a couple of manners, i.e. having a local copy in every case folder, but that is tedious and error prone, so I would recommend something along these lines.

1. First, create the directory (if not already existing):
Code:
mkdir $HOME/bin
2. Copy the above script into a file - and let us call it "processForces.sh" - and save it to
Code:
$HOME/bin/processForces.sh
3. To make it into an executable, execute the following command:
Code:
chmod +x $HOME/bin/processForces.sh
4. You also want to make the script available throughout the system, so you will need to add the path "$HOME/bin" to your environmental variables, so add the following line to $HOME/.bashrc file

Code:
export PATH=$HOME/bin/:$PATH
5. You are now ready to execute the script, so go to any case, and for the first time for testing also include the step "A":

A:
Code:
cp -r forces forcesPlay
and then execute the script:
Code:
processForces.sh forcesPlay/0/forces.dat
but in the future, you can merely do
Code:
processForces.sh forces/0/forces.dat
once you have found that the script works correctly.

I hope that this has helped.

Kind regards

Niels
wyldckat likes this.
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   August 26, 2013, 02:56
Default
  #3
Member
 
Anand Lobo
Join Date: Jun 2013
Posts: 56
Rep Power: 13
Boloar is on a distinguished road
Quote:
Originally Posted by ngj View Post
The easiest would probably be to make a small shell script, which does all the modifications for you ...
Much thanks Niels, I'll try this.
Boloar 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
[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


All times are GMT -4. The time now is 05:36.