CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Give the file the proper header for being used as TimeVaryingMappedFixedValue input (https://www.cfd-online.com/Forums/openfoam-programming-development/160541-give-file-proper-header-being-used-timevaryingmappedfixedvalue-input.html)

syavash October 9, 2015 19:01

Give the file the proper header for being used as TimeVaryingMappedFixedValue input
 
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;

which prints the sampled field, e.g. U as the output. I should sample velocity at the inlet BC at each time step, during a very long time. In this way, I would have a huge number of time folders, yet lacking the OpenFOAM header (just vector values and coordinates).

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()

the following error appears when compiling:

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

Is there any way to solve this problem and adding the proper header to the files generated through the sampling??

Thanks,
Syavash

syavash October 12, 2015 07:43

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;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

How can I generate a header like one in above for my sampled inlet boundary??

Thanks,
Syavash

syavash October 12, 2015 07:46

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;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

How can I generate a header like one in above for my sampled inlet boundary??

Thanks,
Syavash

syavash October 13, 2015 07:28

No one can help me??!:(
I am really stuck in this!

Likun October 15, 2015 04:23

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 );

// ************************************************************************* //

After sample you will have many timestep folders under the directory: 'xx/postProcessing/surfaces/' and within each timestep folder you have the sampled surface 'mySampleSurface/'.

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

After this you can copy the folder ''mySampleSurface" to the ''constant/boundaryData" of your new case.

Hope this helps.

Best,
Likun

syavash October 20, 2015 14:09

Quote:

Originally Posted by Likun (Post 568336)
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 );

// ************************************************************************* //

After sample you will have many timestep folders under the directory: 'xx/postProcessing/surfaces/' and within each timestep folder you have the sampled surface 'mySampleSurface/'.

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

After this you can copy the folder ''mySampleSurface" to the ''constant/boundaryData" of your new case.

Hope this helps.

Best,
Likun


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;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Then, I replaced keyword vectorField with vectorAverageField and '960'with '(0 0 0) 960', (960 is the number of faces in inlet bc) respectively using the following commands in linux terminal:
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/' {} \;
These command find and replace the desired keywords. The option '-i' allows the command 'sed' to be executed as 'in place', i.e. find a file in a folder, open and replace the desired word, save and then close to continue searching for another file.

Regards,
Syavash

ali.m.1 January 11, 2016 09:16

Quote:

Originally Posted by syavash (Post 569292)
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;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Then, I replaced keyword vectorField with vectorAverageField and '960'with '(0 0 0) 960', (960 is the number of faces in inlet bc) respectively using the following commands in linux terminal:
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/' {} \;
These command find and replace the desired keywords. The option '-i' allows the command 'sed' to be executed as 'in place', i.e. find a file in a folder, open and replace the desired word, save and then close to continue searching for another file.

Regards,
Syavash

Hi

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?

tomislav_maric January 12, 2016 11:57

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;
}

When executed, it will write the header to the output stream, using the global messageStream Info object, and also to the output file stream (file), named "myFile".

If you want to change the parameters of the header, change the IOobject constructor arguments.

syavash January 12, 2016 12:56

Quote:

Hi

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?
Ali,

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

ali.m.1 January 13, 2016 08:15

Thanks Syavash

I'm planning on trying something like that, but it looks like it's going to be difficult!

regards


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