|
[Sponsors] |
Give the file the proper header for being used as TimeVaryingMappedFixedValue input |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 9, 2015, 19:01 |
Give the file the proper header for being used as TimeVaryingMappedFixedValue input
|
#1 |
Senior Member
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18 |
Hi Foamers,
In the file foamFileSurfaceWriter.C in "src/sampling/sampledSurface/writers/foamFile" , I can see the following line Code:
// values OFstream(valuesDir/fieldName)() << values; I want to feed these time series into another simulation as boundary condition using TimeVaryingMappedFixedValue BC. But this BC demands for input files with headers. Unfortunately, it is not possible to add header to each file manually, because the number is huge! I have tried something like the following code to add the proper header, but without success: Code:
vectorAverageField values ( IOobject ( "values", runTime.constant()/valuesDir/fieldName, mesh, IOobject::NO_READ, IOobject::NO_WRITE ) ,facesSet.size() ); values.write() Code:
SOURCE=sampledSurface/writers/foamFile/foamFileSurfaceWriter.C ; g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3 -DNoRepository -ftemplate-depth-100 -I/home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/finiteVolume/lnInclude -I/home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/meshTools/lnInclude -I/home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/surfMesh/lnInclude -I/home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/fileFormats/lnInclude -I/home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/triSurface/lnInclude -I/home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/conversion/lnInclude -I/home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/lagrangian/basic/lnInclude -IlnInclude -I. -I/home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude -I/home/syavash/OpenFOAM/OpenFOAM-2.3.1/src/OSspecific/POSIX/lnInclude -fPIC -c $SOURCE -o Make/linux64GccDPOpt/foamFileSurfaceWriter.o sampledSurface/writers/foamFile/foamFileSurfaceWriter.C: In member function ‘void Foam::foamFileSurfaceWriter::writeTemplate(const Foam::fileName&, const Foam::fileName&, const pointField&, const faceList&, const Foam::word&, const Foam::Field<Type>&, bool, bool) const’: sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:82:6: error: ‘vectorAverageField’ was not declared in this scope vectorAverageField values ^ sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:82:25: error: expected ‘;’ before ‘values’ vectorAverageField values ^ sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:96:1: error: expected ‘;’ before ‘}’ token } ^ sampledSurface/writers/foamFile/foamFileSurfaceWriter.C: In instantiation of ‘void Foam::foamFileSurfaceWriter::writeTemplate(const Foam::fileName&, const Foam::fileName&, const pointField&, const faceList&, const Foam::word&, const Foam::Field<Type>&, bool, bool) const [with Type = double; Foam::pointField = Foam::Field<Foam::Vector<double> >; Foam::faceList = Foam::List<Foam::face>]’: sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:157:1: required from here sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:95:9: error: ‘const class Foam::Field<double>’ has no member named ‘write’ values.write() ^ sampledSurface/writers/foamFile/foamFileSurfaceWriter.C: In instantiation of ‘void Foam::foamFileSurfaceWriter::writeTemplate(const Foam::fileName&, const Foam::fileName&, const pointField&, const faceList&, const Foam::word&, const Foam::Field<Type>&, bool, bool) const [with Type = Foam::Vector<double>; Foam::pointField = Foam::Field<Foam::Vector<double> >; Foam::faceList = Foam::List<Foam::face>]’: sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:157:1: required from here sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:95:9: error: ‘const class Foam::Field<Foam::Vector<double> >’ has no member named ‘write’ sampledSurface/writers/foamFile/foamFileSurfaceWriter.C: In instantiation of ‘void Foam::foamFileSurfaceWriter::writeTemplate(const Foam::fileName&, const Foam::fileName&, const pointField&, const faceList&, const Foam::word&, const Foam::Field<Type>&, bool, bool) const [with Type = Foam::SphericalTensor<double>; Foam::pointField = Foam::Field<Foam::Vector<double> >; Foam::faceList = Foam::List<Foam::face>]’: sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:157:1: required from here sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:95:9: error: ‘const class Foam::Field<Foam::SphericalTensor<double> >’ has no member named ‘write’ sampledSurface/writers/foamFile/foamFileSurfaceWriter.C: In instantiation of ‘void Foam::foamFileSurfaceWriter::writeTemplate(const Foam::fileName&, const Foam::fileName&, const pointField&, const faceList&, const Foam::word&, const Foam::Field<Type>&, bool, bool) const [with Type = Foam::SymmTensor<double>; Foam::pointField = Foam::Field<Foam::Vector<double> >; Foam::faceList = Foam::List<Foam::face>]’: sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:157:1: required from here sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:95:9: error: ‘const class Foam::Field<Foam::SymmTensor<double> >’ has no member named ‘write’ sampledSurface/writers/foamFile/foamFileSurfaceWriter.C: In instantiation of ‘void Foam::foamFileSurfaceWriter::writeTemplate(const Foam::fileName&, const Foam::fileName&, const pointField&, const faceList&, const Foam::word&, const Foam::Field<Type>&, bool, bool) const [with Type = Foam::Tensor<double>; Foam::pointField = Foam::Field<Foam::Vector<double> >; Foam::faceList = Foam::List<Foam::face>]’: sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:157:1: required from here sampledSurface/writers/foamFile/foamFileSurfaceWriter.C:95:9: error: ‘const class Foam::Field<Foam::Tensor<double> >’ has no member named ‘write’ make: *** [Make/linux64GccDPOpt/foamFileSurfaceWriter.o] Error 1 Thanks, Syavash |
|
October 12, 2015, 07:43 |
|
#2 |
Senior Member
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18 |
Anyone who might be interested?? This is a real problem for me since I need inlet velocity at each time step to be saved and used as boundary condition for another LES simulation!
I also checked sample utility but it similarly only saves values and generates no header! TimeVaryingMappedFixedValue demands a header for velocity like this: Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 2.3.1 | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class vectorAverageField; object values; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Thanks, Syavash |
|
October 12, 2015, 07:46 |
|
#3 |
Senior Member
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18 |
Anyone who might be interested?? This is a real problem for me since I need inlet velocity at each time step to be saved and used as boundary condition for another LES simulation!
I also checked sample utility but it similarly only saves values and generates no header! TimeVaryingMappedFixedValue demands a header for velocity like this: [CODE] Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 2.3.1 | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class vectorAverageField; object values; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Thanks, Syavash |
|
October 13, 2015, 07:28 |
|
#4 |
Senior Member
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18 |
No one can help me??!
I am really stuck in this! |
|
October 15, 2015, 04:23 |
|
#5 |
Member
|
Dear Syavash,
I also met similar problem before, and I have written a matlab script to add the head to the sampled file. Suppose your sampleDict reads like this: Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 2.1.1 | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "system"; object sampleDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // //Example to output facecentres, faces and points for the selected patches interpolationScheme cellPoint; surfaceFormat foamFile; surfaces ( mySampleSurface { type plane; basePoint (0.01 0.0 0.0); normalVector (1.0 0.0 0.0); // type patch; // patches (OUTLET); } ); //Not really required when run before a simulation as the velocity will be empty. fields ( U ); // ************************************************************************* // Here is the matlab script that I used to add the header and to move the required files directly under the timestep folder. Code:
num_time = 9; % Total number of timestep folders stp_time = 1e-4; % size of timestep case_dir = 'xx/postProcessing/surfaces/'; for i = 1:num_time time_dir = (i-1)*stp_time; old_dir = strcat(case_dir, num2str(time_dir), '/mySampleSurface/vectorField/'); new_dir = strcat(case_dir, num2str(time_dir), '/'); fid = fopen([new_dir 'header'],'w'); fprintf(fid,'/*--------------------------------*- C++ -*----------------------------------*\\'); fprintf(fid,'\n| ========= | |'); fprintf(fid,'\n| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |'); fprintf(fid,'\n| \\ / O peration | Version: 2.3.x |'); fprintf(fid,'\n| \\ / A nd | Web: http://www.OpenFOAM.com |'); fprintf(fid,'\n| \\/ M anipulation | |\n'); fprintf(fid,'\\*---------------------------------------------------------------------------*/'); fprintf(fid,'\nFoamFile \n{\n'); fprintf(fid,' version 2.0;\n'); fprintf(fid,' format ascii;\n'); fprintf(fid,' class vectorAverageField;\n'); fprintf(fid,' location "constant/boundaryData/mySampleSurface/%s";\n', num2str(time_dir)); fprintf(fid,' object U;\n}\n'); fprintf(fid,'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //'); fprintf(fid,'\n\n'); fprintf(fid,'//Average\n'); fprintf(fid,'(0 0 0)\n'); fclose(fid); system(sprintf('%s %s%s %s%s', 'cp', old_dir, 'U', new_dir, 'U.org')); system(sprintf('%s %s%s %s%s %s %s%s', 'cat', new_dir, 'header', new_dir, 'U.org', '>', new_dir, 'U')); system(sprintf('%s %s%s', 'rm', new_dir, 'U.org')); system(sprintf('%s %s%s', 'rm', new_dir, 'header')); end system(sprintf('%s %s%s %s%s', 'cp', new_dir, 'mySampleSurface/faceCentres', case_dir, 'points.org')); fid = fopen([case_dir 'header'],'w'); fprintf(fid,'/*--------------------------------*- C++ -*----------------------------------*\\'); fprintf(fid,'\n| ========= | |'); fprintf(fid,'\n| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |'); fprintf(fid,'\n| \\ / O peration | Version: 2.3.x |'); fprintf(fid,'\n| \\ / A nd | Web: http://www.OpenFOAM.com |'); fprintf(fid,'\n| \\/ M anipulation | |\n'); fprintf(fid,'\\*---------------------------------------------------------------------------*/'); fprintf(fid,'\nFoamFile \n{\n'); fprintf(fid,' version 2.0;\n'); fprintf(fid,' format ascii;\n'); fprintf(fid,' class vectorField;\n'); fprintf(fid,' object points;\n}\n'); fprintf(fid,'// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //'); fprintf(fid,'\n'); fclose(fid); system(sprintf('%s %s%s %s%s %s %s%s', 'cat', case_dir, 'header', case_dir, 'points.org', '>', case_dir, 'points')); system(sprintf('%s %s%s', 'rm', case_dir, 'points.org')); system(sprintf('%s %s%s', 'rm', case_dir, 'header')); for i = 1:num_time time_dir = (i-1)*stp_time; old_dir = strcat(case_dir, num2str(time_dir), '/mySampleSurface/vectorField/'); new_dir = strcat(case_dir, num2str(time_dir), '/'); system(sprintf('%s %s %s%s', 'rm', '-r', new_dir, 'mySampleSurface')); system(sprintf('%s %s %s%s', 'rm', '-r', new_dir, 'vectorField')); end Hope this helps. Best, Likun Last edited by Likun; October 15, 2015 at 10:07. |
|
October 20, 2015, 14:09 |
|
#6 | |
Senior Member
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18 |
Quote:
Dear Likun, Thank you for sharing your solution. Unfortunately, Matlab could not recognize 'cp' and 'rm' commands in your scrip! But I am aware that this is an issue with the version installed on my PC! I could find a workaround. I could make the solver (pimpleFoam) to write the sampled plane (inlet bc) at each time steps. In this way, OpenFoam automatically generates a header with class vectorField just like the following: Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 2.3.1 | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class vectorField; location "constant/boundaryData/inlet/0.2"; object U; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Code:
find ./ -type f -readable -writable -exec sed -i '0,/vectorField/s/vectorField/vectorAverageField/' {} \; Code:
find ./ -type f -readable -writable -exec sed -i '0,/960/s/960/(0 0 0) 960/' {} \; Regards, Syavash |
||
January 11, 2016, 09:16 |
|
#7 | |
Member
Ali
Join Date: Oct 2013
Location: Scotland
Posts: 66
Rep Power: 12 |
Quote:
If you got this to work, do you think it would be possible to run both simulations simultaneously? So the 'inlet' BC reads the 'outlet' BC while the solver is running? |
||
January 12, 2016, 11:57 |
|
#8 |
Senior Member
Tomislav Maric
Join Date: Mar 2009
Location: Darmstadt, Germany
Posts: 284
Blog Entries: 5
Rep Power: 21 |
The IOobject class has the member functions writeHeader and readHeader that write the appropriate headers to streams. Since files are abstracted as streams in C++, we can use the IOobject class to write a header to a file. Here is how the application looks like:
Code:
#include "fvCFD.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: int main(int argc, char *argv[]) { #include "setRootCase.H" #include "createTime.H" IOobject myObject ( "widget", runTime.timeName(), runTime, IOobject::NO_READ, IOobject::NO_WRITE ); // Write the header to the output stream. myObject.writeHeader(Info); // Write the header to a file. OFstream headerFile("myFile"); myObject.writeHeader(headerFile); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Info<< "\nEnd\n" << endl; return 0; } If you want to change the parameters of the header, change the IOobject constructor arguments.
__________________
When asking a question, prepare a SSCCE. |
|
January 12, 2016, 12:56 |
|
#9 | |
Senior Member
Syavash Asgari
Join Date: Apr 2010
Posts: 473
Rep Power: 18 |
Quote:
I am not really sure. The above-mentioned solution makes me able to perform a precursor simulation before doing the primary simulation.Adding that my computational resource does not allow me to have two simultaneous simulations! Besides, I think it is the most appropriate solution for me to save data on a plane in advance, since I would be able to implement the data for as many simulations as I want to perform. Regards |
||
January 13, 2016, 08:15 |
|
#10 |
Member
Ali
Join Date: Oct 2013
Location: Scotland
Posts: 66
Rep Power: 12 |
Thanks Syavash
I'm planning on trying something like that, but it looks like it's going to be difficult! regards |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[OpenFOAM.org] Patches to compile OpenFOAM 2.2 on Mac OS X | gschaider | OpenFOAM Installation | 136 | October 10, 2017 17:25 |
Trouble compiling utilities using source-built OpenFOAM | Artur | OpenFOAM Programming & Development | 14 | October 29, 2013 10:59 |
centOS 5.6 : paraFoam not working | yossi | OpenFOAM Installation | 2 | October 9, 2013 01:41 |
[OpenFOAM] Annoying issue of automatic "Rescale to Data Range " with paraFoam/paraview 3.12 | keepfit | ParaView | 60 | September 18, 2013 03:23 |
Version 15 on Mac OS X | gschaider | OpenFOAM Installation | 113 | December 2, 2009 10:23 |