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

writing values to IOdictionary subDict not generating expected output?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 17, 2019, 14:32
Default writing values to IOdictionary subDict not generating expected output?
  #1
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13
massive_turbulence is on a distinguished road
Hello All,

Below I have the code that tries to output values to a dict file ( nevermind that it doesn't make sense in terms of actual scientific use as it's only for a reading and writing example). Basically I have a mesh that is read and some math is used to find scalars and I want to write this to a dictionary file in /constant.

Right now it just writes out the dimensions but not the result of the calculation
for volScalarField DVals = cellCentroid & cellCentroid;

Code:
#include "fvCFD.H"

int main(int argc, char *argv[])
{
	#include "setRootCase.H"
	#include "createTime.H"
	#include "createMesh.H"	
	
	IOdictionary electrolyteProperties
	(
		IOobject
		(
		  "electrolyteProperties",
		  runTime.constant(),
		  mesh,
		  IOobject::MUST_READ_IF_MODIFIED,
		  IOobject::NO_WRITE
		)
	);

	dictionary& DDict = electrolyteProperties.subDict("D");

	volVectorField cellCentroid = mesh.C();		
	volScalarField DVals = cellCentroid & cellCentroid;

	DDict.set("values", DVals);
	electrolyteProperties.regIOobject::write();

	return 0;
}
blockMeshDict

Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  plus                                  |
|   \\  /    A nd           | Web:      www.OpenFOAM.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    object      blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

convertToMeters 1;

a 32;
b 32;
c 32;
yi -2;
yf 2;
zi -2;
zf 2;
xi -2;
xf 2;

vertices
(
    ($xi $yi $zi) //0
    ($xf $yi $zi) //1
    ($xf $yf $zi) //2
    ($xi $yf $zi) //3
    ($xi $yi $zf) //4
    ($xf $yi $zf) //5
    ($xf $yf $zf) //6
    ($xi $yf $zf) //7
);


blocks
(
    hex (0 1 2 3 4 5 6 7) ($a $b $c) simpleGrading (1 1 1)
);

edges
(
);

patches
(
);
boundaryField
{
	/// Patches should have same names as in
	/// polyMesh/boundary
	patch_1
	{
		type zeroGradient;
	}
/// other patches
}
mergePatchPairs
(
);
// ************************************************************************* //
/constant/electrolyteProperties


Code:
/*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v1806                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      binary;
    class       dictionary;
    arch        "LSB;label=32;scalar=64";
    location    "constant";
    object      electrolyteProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

D
{
    values          dimensions [ 0 2 0 0 0 0 0 ];
}


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

Last edited by massive_turbulence; January 17, 2019 at 19:41.
massive_turbulence is offline   Reply With Quote

Old   January 19, 2019, 13:13
Default
  #2
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13
massive_turbulence is on a distinguished road
I got this to work!

Code:
#include "fvCFD.H"

int main(int argc, char *argv[])
{
	#include "setRootCase.H"
	#include "createTime.H"
	#include "createMesh.H"	
	
	IOdictionary electrolyteProperties
	(
		IOobject
		(
		  "electrolyteProperties",
		  runTime.constant(),
		  mesh,
		  IOobject::MUST_READ_IF_MODIFIED,
		  IOobject::NO_WRITE
		)
	);	

	volVectorField cellCentroid = mesh.C();		
	volScalarField DVals = cellCentroid & cellCentroid;	
	
	 fileName outputDir = mesh.time().path()/"postProcessing";
    mkDir(outputDir); 
	autoPtr<OFstream> outputFilePtr;
    outputFilePtr.reset(new OFstream(outputDir/"customOutputFile.dat"));  
    outputFilePtr() << DVals << endl;

	return 0;
}
Now the problem I have is how to read it back into a variable,
for this type..
internalField nonuniform List<scalar>
massive_turbulence is offline   Reply With Quote

Old   January 21, 2019, 09:48
Default
  #3
Senior Member
 
Andrew Somorjai
Join Date: May 2013
Posts: 175
Rep Power: 13
massive_turbulence is on a distinguished road
Now I get nulls in my output in the internalField?

Basically I'm reaeding the mesh into a volVectorField and trying to write
to disk (file /0/result) but for some reason it's turning into garbage?

Something like this

Code:
internalField   nonuniform List<vector> 
32768
(      ÿ¿      ÿ .....
Any suggestions?

Code:
#include "fvCFD.H"

int main(int argc, char *argv[])
{
	#include "setRootCase.H"
	#include "createTime.H"
	#include "createMesh.H"	
	
	volVectorField cellCentroid = mesh.C();		
	volScalarField DVals = cellCentroid & cellCentroid;		
      Info << DVals << endl;
	
	volVectorField result
    (
        IOobject
        (
            "result",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
		mesh.C()       
    );
	result.write(); 
	
	return 0;
}

EDIT:NEVERMIND

I read the result IOobject into Info and it reproduced the list. I still don't see why nulls are created? Must be a type of openfoam "codex"?

Code:
#include "fvCFD.H"

int main(int argc, char *argv[])
{
	#include "setRootCase.H"
	#include "createTime.H"
	#include "createMesh.H"	
	
	volVectorField cellCentroid = mesh.C();	
	
	volVectorField result
    (
        IOobject
        (
            "result",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
		cellCentroid      
    );
	result.write(); 	
	
	Info << result << endl;
	
	return 0;
}
Whole project solver.zip

Last edited by massive_turbulence; January 21, 2019 at 11:20.
massive_turbulence is offline   Reply With Quote

Reply

Tags
iodictionary, output


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
Writing IOdictionary to user-defined folder Arnoldinho OpenFOAM Programming & Development 3 June 16, 2021 05:04
writing subDict in a dictionary ubaid OpenFOAM Programming & Development 3 October 25, 2014 18:17
How to output values only on cell center or vertex? huangxianbei OpenFOAM Post-Processing 10 April 25, 2014 21:56
It would be wonderful if a tool for FoamToTecplot is available luckyluke OpenFOAM Post-Processing 165 November 27, 2012 07:54
POSDAT problem piotka STAR-CD 4 June 12, 2009 09:43


All times are GMT -4. The time now is 00:30.