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

OpenFOAM Mac terminal cannot execute openfile command

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 30, 2017, 08:54
Default OpenFOAM Mac terminal cannot execute openfile command
  #1
New Member
 
Haozhong Jiang
Join Date: May 2017
Posts: 2
Rep Power: 0
evojiang is on a distinguished road
Dear All,

I have a problem with running external shell script inside OpenFOAM, and I spent several days on it but still not fixed.

Here is the problem.

I wrote a C++ code to read the data from a local .txt file.
Here is the .cpp file:
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
string line;
size_t pos = 0;
string token;
const char * V;

cout << "Starts" <<endl;

ifstream vMyFile;
vMyFile.open("/Users/Desktop/laminarVortexShedding/postProcessing/probes/0/U", std::fstream::in);
if (vMyFile.is_open())
{
int i = 0;

while (! vMyFile.eof() )
{
getline(vMyFile,line);
if (i >= 3)
{
if (line.find("(") == 28)
{
pos = line.find("(");
token = line.erase(0, pos);
// pos = token.find(" ");
// token = token.substr(0, pos);
//cout << "i = " << i << token << endl;
}
}
i++;
}
vMyFile.close();
V = token.c_str();

cout << "Last iteration velocity: " << V << endl;

}
else cout << "Unable to open file11111" << endl;


ofstream vEstimate_file ("/Users/Desktop/laminarVortexShedding/U_estimate");
if (vEstimate_file.is_open())
{
vEstimate_file << V;
vEstimate_file.close();
}
else cout << "Unable to open file22222" << endl;

return 0;
}



And then I made a shell script which compile the C++ code and ./run the program.

#!/bin/bash
# My first script

g++ -std=c++11 -o runf main.cpp
./runf

In the terminal, I type ./shell.sh, everything works fine and I get the result I want.

However, once I do the exact same thing in the OpenFOAM terminal window(Because OF on Mac is based on Docker? therefore I have to run it in a different terminal window, which has ofuser@98032082cf7e on the left.), it shows cannot open file.

Unable to open file11111
Unable to open file22222


Can anyone give me some help on this problem? Why it won't work on the OpenFOAM terminal?

Thanks a lot!
evojiang 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
How to contribute to the community of OpenFOAM users and to the OpenFOAM technology wyldckat OpenFOAM 17 November 10, 2017 16:54
OpenFOAM v3.0+ ?? SBusch OpenFOAM 22 December 26, 2016 15:24
OpenFOAM Training Jan-Apr 2017, Virtual, London, Houston, Berlin cfd.direct OpenFOAM Announcements from Other Sources 0 September 21, 2016 12:50
OpenFOAM Training, London, Chicago, Munich, Houston 2016-2017 cfd.direct OpenFOAM Announcements from Other Sources 0 September 14, 2016 04:19
Is it a good idea to use OpenFoam on a Mac (OS 10.7.5) or on Windows7? bzz77 OpenFOAM Installation 4 November 21, 2012 18:06


All times are GMT -4. The time now is 01:04.