|
[Sponsors] |
How to save data to a file from OpenFoam code structure? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
May 6, 2021, 05:59 |
How to save data to a file from OpenFoam code structure?
|
#1 |
Member
Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 7 |
Dear all,
I am working on extracting the faceIndex from a particular patch. For this, I have written the code as below. Code:
code #{ const fvPatch& mesh = this->patch(); const fvBoundaryMesh& boundaryMesh = mesh.boundaryMesh(); for (int patch = 0; patch < mesh.boundaryMesh().size(); patch++) { const word& patchName = mesh.boundaryMesh()[patch].name(); Info << patchName << endl; for (int facei = 0; facei < mesh.boundaryMesh()[patch].size(); facei++) { const label& face = boundaryMesh[patch].start() + facei; Info << facei << "," << face << endl; } } #}; 1. How to save the output to an external file in a particular folder.? Any leads will be appreciated. Regards, Sunag R A. |
|
May 6, 2021, 15:20 |
|
#2 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Look somewhere in the OpenFOAM code base for 'OFstream' and you will how it is used. Can also just use a plain 'std:fstream' if you want. Just needs a little effort on your part.
|
|
May 7, 2021, 00:50 |
|
#3 | |
Member
Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 7 |
Dear Olesen,
Thank you for your reply. Quote:
I have actually used this code in 0/region/T file. Here is the region with codedFixedValue BC. So, if I try to add #include "OFstream.H" inside "codeInclude", but I am unable to continue further. So, how to proceed with it. Below is the region BC as said. Code:
gland { type codedFixedValue; value #include "actualData"; name glandsurface; codeInclude #{ #include "OFstream.H" #}; code #{ const fvPatch& mesh = this->patch(); const fvBoundaryMesh& boundaryMesh = mesh.boundaryMesh(); for (int patch = 0; patch < 1; patch++) { const word& patchName = mesh.boundaryMesh()[patch].name(); Info << patchName << endl; for (int facei = 0; facei < mesh.boundaryMesh()[patch].size(); facei++) { const label& face = boundaryMesh[patch].start() + facei; Info << facei << "," << face << endl; } } #}; } Sunag R A. Last edited by sunagra27; May 7, 2021 at 02:16. |
||
May 7, 2021, 02:33 |
|
#4 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 |
Sorry, but I already given you what you need to do. You need to google some and read something.
|
|
May 7, 2021, 05:31 |
|
#5 |
Member
Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 7 |
Dear Oselen,
Thank you for the suggestion. I worked on it and it is saving to a file. Below is the related code in case anyone wants it. Code:
codeInclude #{ #include "OFstream.H" #}; code #{ const fvPatch& mesh = this->patch(); const fvBoundaryMesh& boundaryMesh = mesh.boundaryMesh(); for (int patch = 0; patch < 1; patch++) { const word& patchName = mesh.boundaryMesh()[patch].name(); std::ofstream file; file.open("face.txt"); for (int facei = 0; facei < mesh.boundaryMesh()[patch].size(); facei++) { const label& face = boundaryMesh[patch].start() + facei; file << face << endl; file << nl << endl; // For new line creation. } file.close(); } This is now saving in a file named "file.txt" Regards, Sunag R A. |
|
Tags |
code, development, face, openfoam, programming |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] swak4foam for OpenFOAM 4.0 | mnikku | OpenFOAM Community Contributions | 80 | May 17, 2022 09:06 |
[swak4Foam] funkyDoCalc with OF2.3 massflow | NiFl | OpenFOAM Community Contributions | 14 | November 25, 2020 04:30 |
[swak4Foam] Installation Problem with OF 6 version | Aurel | OpenFOAM Community Contributions | 14 | November 18, 2020 17:18 |
polynomial BC | srv537 | OpenFOAM Pre-Processing | 4 | December 3, 2016 10:07 |
DxFoam reader update | hjasak | OpenFOAM Post-Processing | 69 | April 24, 2008 02:24 |