|
[Sponsors] |
Variable declaration and initialisation revisited |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
August 30, 2012, 08:19 |
Variable declaration and initialisation revisited
|
#1 |
Senior Member
Gerhard Holzinger
Join Date: Feb 2012
Location: Austria
Posts: 342
Rep Power: 28 |
Previously on ...
http://www.cfd-online.com/Forums/ope...rocessing.html http://www.cfd-online.com/Forums/ope...alization.html In the first thread there is a discussion about using functionObjects for postprocessing. In this thread there is somewhere the source code of a tool posted, which works in the described way. One downside of this tool is, that the fields which are read directly coded. I was playing around with the code to make it possible to use this tool even if some fields are not present. The first section of code is of the original code: Code:
Info<< "Reading field U\n" << endl; volVectorField U ( IOobject ( "U", runTime.timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), mesh ); I tried to make a tool that reads fields if they are present. It is still somewhat hardcoded, for all the possible fields are listed in the source code. Somewhere in this forum I found this way to handle conditional reading of the fields. Code:
IOobject UbHeader ( "Ub", runTime.timeName(), mesh, IOobject::NO_READ ); volVectorField* UbPointer; bool UbExist = false; if (UbHeader.headerOk()) { UbExist = true; Info<< "Reading Ub.\n" << endl; UbPointer = new volVectorField ( IOobject ( "Ub", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ); } Code:
# x 0.0254 # y 0.0253 # z 0 # Time 0 (0 0 0) 0.0001 (0 0 0) 0.0002 (0 0 0) 0.0003 (0 0 0) 0.0004 (0 0 0) 0.0005 (0 0 0) 0.0006 (0 0 0) 0.0007 (0 0 0) Code:
IOobject UaHeader ( "Ua", runTime.timeName(), mesh, IOobject::NO_READ ); volVectorField* UaPointer; bool UaExist = false; autoPtr<volVectorField> Ua; if (UaHeader.headerOk()) { UaExist = true; Info<< "Reading Ua.\n" << endl; //UaPointer = new volVectorField Ua.set(new volVectorField ( IOobject ( "Ua", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh )); } Code:
# x 0.0254 # y 0.0253 # z 0 # Time 0 (0 0 0) 0.0001 (-0.095783 -0.0959882 0.251371) 0.0002 (-0.0163107 -0.0163035 0.306008) 0.0003 (-0.00224914 -0.00223754 0.320491) 0.0004 (-0.000290503 -0.000285572 0.333185) 0.0005 (-0.000397366 -0.000393842 0.343691) 0.0006 (-0.000691265 -0.000688015 0.353534) 0.0007 (-0.000787074 -0.000783954 0.362863) I don't know the reason why conditional reading of fields behaves differently in the two cases. When using autoPointers it works, when not using autoPointers the tool reads only the first time step and uses this value further on. Attached you will find a modified version of the postAverage utility of Eelco van Vliet. All possible fields that can be read have their lines of code in the createFields.H file. If a field exists it is read, if it does not exist, no attempt of reading it is made. Consequently the tool will run without crashing when a field is not present. A possible next step would be to define the fields to read in a dictionary and program a somehow generic version createFields.H to enable the tool to read any field defined by the user. |
|
|
|