|
[Sponsors] |
The effect of write precision on CFD solution with codeStream |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 13, 2022, 13:01 |
The effect of write precision on CFD solution with codeStream
|
#1 |
New Member
Join Date: Feb 2022
Posts: 25
Rep Power: 4 |
Hi,
Following my previous post, Custom boundaries and explicit operators, I met another "funny" thing. I am new to OF and did not find this information anywhere so I decided to share it. I am using OF2106. If one is using codeStream/setExprField, and I guess coded boundaries conditions. The writePrecision parameter in controlDict can have some significance! I have the following codestream code for defining the internalField in p: Code:
dimensions [1 -1 -2 0 0 0 0]; internalField nonuniform #codeStream { codeInclude #{ #include "fvCFD.H" #}; codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude #}; codeLibs #{ -lmeshTools \ -lfiniteVolume #}; code #{ const IOdictionary& d = static_cast<const IOdictionary&>(dict); const fvMesh& mesh = refCast<const fvMesh>(d.db()); scalarField myInteriorField(mesh.nCells(), 0.0); const volVectorField& C = mesh.C(); forAll(myInteriorField, cellI) { const scalar x = C[cellI].x(); const scalar y = C[cellI].y(); const scalar tmp0 = (5.0/4.0)*M_PI; myInteriorField[cellI] = 1000.0*Foam::sin(tmp0*y) + 1000.0*Foam::cos(tmp0*x) + 100000.0; } os.writeEntry("", myInteriorField); #}; }; Code:
const volVectorField& C = mesh.C(); volScalarField dummyField ( IOobject ( "dummyField", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh, dimensionedScalar("dummyScalar", dimless, 0.0) ); forAll(dummyField, cellI) { const scalar x = C[cellI].x(); const scalar y = C[cellI].y(); const scalar tmp0 = (5.0/4.0)*M_PI; const scalar solution = 1000.0*Foam::sin(tmp0*y) + 1000.0*Foam::cos(tmp0*x) + 100000.0; dummyField[cellI] = mag(solution - p[cellI]); } Code:
const scalarField& V = mesh.V(); Info << "Error is " << Foam::sqrt( gSum(dummyField*dummyField*V)/gSum(V) ) << endl; |
|
February 16, 2022, 13:10 |
|
#2 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,686
Rep Power: 40 |
You need to adjust your expectations and/or find another way to handle the problem. The codeStream bits work by outputting to StringStream and then reparsing that to get tokens to populate the dictionary contents. These are the tokens that are actually used to populate the field.
Yes, you are correct to think that this sounds ugly! |
|
April 7, 2022, 02:11 |
|
#3 |
Senior Member
TWB
Join Date: Mar 2009
Posts: 401
Rep Power: 19 |
Hi,
I just found this out too after a week plus of debugging. Besides increasing precision for writePrecision and maybe timePrecision, there may also be a need to increase the read/write precision for reading/writing files: Code:
while(MyReadFile.good() && (getline(MyReadFile, line))) { istringstream iss(line); iss >> std::fixed >> std::setprecision(8) >> time_saved >> old_incoming_vel; } MyReadFile.close(); |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Importing CFD solution data in CFD POST | Aveek Pal | ANSYS | 2 | February 24, 2020 03:04 |
Effect Sloshing in a tank of water with CFD | RobinReiban | FLUENT | 0 | April 2, 2019 15:01 |
Steady state CFD in a solid - effect of Cp and density? | Abhya | Main CFD Forum | 0 | February 15, 2018 08:52 |
how to model polymer solution in CFD | koraltp | Main CFD Forum | 0 | November 16, 2017 01:23 |
confusion on how to write udf for density of a mixture solution in multiphase problem | Hirakjyoti | Fluent UDF and Scheme Programming | 1 | September 11, 2017 01:21 |