|
[Sponsors] |
October 12, 2018, 14:33 |
codedMixed boundaryField + time vary
|
#1 |
New Member
RoWoM
Join Date: Jul 2018
Posts: 5
Rep Power: 8 |
Want a boundary condition where temperature's a function of time and space, so using codedMixed.
I can get time out: scalar ti = this->db().time().value(); Now want to use this (and eventually xyz) to look up values in some 10,000 long lookup tables. But how to get these big blocks of data into the boundary condition? If I read these from file that will happen every time step. All the methods I have found involve recompiling, but that's not possible on windows and with our IT department. Very new to openFoam so have spent all this week looking for an answer to this. It feels like such a basic thing to want to do, I am sure there's a good answer. Sorry for what must be a very new person question. |
|
October 15, 2018, 09:14 |
Update after working all weekend
|
#2 |
New Member
RoWoM
Join Date: Jul 2018
Posts: 5
Rep Power: 8 |
Almost there.
Just need to store a value between time steps...if anyone knows how. Would like to read new data only every 360 iterations... not every single one. Code posted below to help anyone else (including the failed store between iterations): This should apply a temperature and external HTC as a function of time: Code:
ceiling { type codedMixed; // so we can set either grad or value or a mix // default values refValue uniform 300; refGradient uniform 0; valueFraction uniform 1; redirectType ceiling; // name of generated BC code #{ // ~~~~~~~~~~~~~~~Read Constants~~~~~~~~~~~~~~~~~~~~~~~~ // reading flags from thermophysical properties. //Not the right place, but I don't know how to access the controldict. //~ // Extract the dictionary from the database const dictionary& ContProp = db().lookupObject<IOdictionary> ( "thermophysicalProperties" ); //~ // Exctract subdictionary from the main dictionary dictionary mySubDict ( ContProp.subDict("RWMReadFiles") ); //~ // Extracting scalar value scalar TempFileReadFlag(readScalar(mySubDict.lookup("temp"))); // ~~~~~~~~~~~~~~~Set Constants~~~~~~~~~~~~~~~~~~~~~~~~~~~ const scalar refCp = 4200.0; // ~~~~~~~~~~~~~~~Access time~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ scalar ti = this->db().time().value(); int hour=int(ti/3600); // ~~~~~~~~~~~~~~~Read Files~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // deal with stored values double tsolar=10.0; double HTC=28.0; // this bit doesn't work properly, and should be fixed or removed. //Idea is to store values between iterations. Otherwise we are having to // access temperature file every single iteration (and it slows things down) if((ti-int(ti/3600)*3600)<60){ Info << " Low iteration number, reset read file stamp " <<endl; ContProp.set("ShouldReadTemp",1); mySubDict.set("tsolar",tsolar); mySubDict.set("HTC",HTC); } scalar ShouldReadTemp(readScalar(ContProp.lookup("ShouldReadTemp"))); // this bit reads two files. Would have liked to use a more foam way, // but didn't know how so am just reading the files with standard C++. if ((TempFileReadFlag==1) and (ShouldReadTemp==1)){ double tsolararray [8860]; double HTCarray [8860]; int hourcount; // Read Temperature Files std::ifstream infileTSOL("tSolC.RWM"); hourcount =0; if (infileTSOL.is_open()) { while (!infileTSOL.eof()) { infileTSOL >> tsolararray[hourcount]; hourcount++; } } infileTSOL.close(); tsolar=tsolararray[hour]; // Read HTC Files std::ifstream infileHTC("HTC.RWM"); hourcount =0; if (infileHTC.is_open()) { while (!infileHTC.eof()) { infileHTC >> HTCarray[hourcount]; hourcount++; } } infileHTC.close(); HTC=HTCarray[hour]; // more of the not working code. //Just need somewhere to store values between iterations. ContProp.set("ShouldReadTemp",0); mySubDict.set("tsolar",tsolar); mySubDict.set("HTC",HTC); Info << " RWM Temp File Read " <<endl; } // more of the not working code. // Just need somewhere to store values between iterations. scalar tsolarS(readScalar(mySubDict.lookup("tsolar"))); scalar HTCS(readScalar(mySubDict.lookup("HTC"))); tsolar=tsolarS; HTC=HTCS; //~ // ~~~~~~~~~~~~~~~handle heat transfer coefficients~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ this->refValue() = tsolar+273.15; // Tinf this->refGrad() = 0.0; //~ // look up patch fields directly: const scalarField& alphaEffPatchField = this->patch().lookupPatchField<volScalarField, scalar>("thermo:alpha"); //~ // delta = inverse of distance from patch to cell centre const scalarField& delta = patch().deltaCoeffs(); //~ // Value fraction (w) Tface = wTinf + (1-w)Tcentre this->valueFraction() = 1.0/(1+alphaEffPatchField*refCp*delta/HTC);// something odd here. it appears alphaEff doesn't included density.... //~ // report what we did: Info << " RWM day = " << int(ti/3600/24) << " hour = " << int(ti/3600) <<endl; Info << " RWM tsolar = " << tsolar << " HTC= " << HTC <<endl; #}; codeInclude #{ #include <fstream> #}; } |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
bash script for pseudo-parallel usage of reconstructPar | kwardle | OpenFOAM Post-Processing | 42 | May 8, 2024 00:17 |
Elastic or Plastic Deformations in OpenFOAM | NickolasPl | OpenFOAM Pre-Processing | 36 | September 23, 2023 09:22 |
pimpleDyMFoam computation randomly stops | babapeti | OpenFOAM Running, Solving & CFD | 5 | January 24, 2018 06:28 |
How to export time series of variables for one point? | mary mor | OpenFOAM Post-Processing | 8 | July 19, 2017 11:54 |
pressure in incompressible solvers e.g. simpleFoam | chrizzl | OpenFOAM Running, Solving & CFD | 13 | March 28, 2017 06:49 |