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

HOW TO STOP CODE & WRITE RESULTS IF THE temperature DIFFERENCE

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 1 Post By einstein_zee
  • 1 Post By SergioCosta

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 10, 2025, 13:01
Default HOW TO STOP CODE & WRITE RESULTS IF THE temperature DIFFERENCE
  #1
Member
 
SergioCosta's Avatar
 
RJSergio Feitoza Costa
Join Date: Sep 2024
Posts: 44
Rep Power: 2
SergioCosta is on a distinguished road
I have a heat transfer case in which I monitor temperatures in a certain region ( heater_1 in code below)at each writeInterval settled in ControlDict file.
I want to stop the code and write the results- before the end time- if the difference between the temperature in the current time and in the previous moment (currentTime minus timeinterval) is lower than a certain value, for example 5K.
I suppose that I have to write a code and insert it in ControlDict file. My difficult is to write this code and to know where to insert it.

CAN YOU SUGGEST ME A CODE AND WHERE TO INSERT IT IN THIS CONTROLDICT TEXT FILE ? Thank you in advance

(controldict file in next lines)

/*--------------------------------*- C++ -*----------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 12
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application foamMultiRun;
regionSolvers //definição das diferentes regiões que compõem a simulação
{
fluid fluid;
metal solid;
heater_1 solid;
}
//Time Control
startFrom startTime;
startTime 0;
stopAt endTime; // or stop if the temperature difference to the previous writeinterval is lower than 5K
endTime 10800;
deltaT 120;/
//Data Writing
writeControl adjustableRunTime;
writeInterval 1200;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 7;
//Others Settings
runTimeModifiable true;
maxCo 750.0;
maxDi 750.0;.
maxDeltaT 10800;
adjustTimeStep yes;
// ************************************************** *********************** //
Attached Images
File Type: png ___A989_Temperature.png (12.4 KB, 12 views)

Last edited by SergioCosta; February 10, 2025 at 13:44. Reason: include figure to clarify
SergioCosta is offline   Reply With Quote

Old   February 13, 2025, 10:33
Default
  #2
Member
 
SergioCosta's Avatar
 
RJSergio Feitoza Costa
Join Date: Sep 2024
Posts: 44
Rep Power: 2
SergioCosta is on a distinguished road
Can anyone give me an example more or less like this ?
SergioCosta is offline   Reply With Quote

Old   February 16, 2025, 15:30
Default How to stop code and write results if dT/dt becomes smaler than a known value ?
  #3
Member
 
SergioCosta's Avatar
 
RJSergio Feitoza Costa
Join Date: Sep 2024
Posts: 44
Rep Power: 2
SergioCosta is on a distinguished road
How to stop the code and write the results if the difference between the temperature in the current time and in the previous write moment (currentTime minus timeinterval) is lower than a certain value, for example 5 degrees.
SergioCosta is offline   Reply With Quote

Old   February 21, 2025, 12:52
Default
  #4
Member
 
Hosein
Join Date: Nov 2011
Location: Germany
Posts: 99
Rep Power: 15
einstein_zee is on a distinguished road
Hi there,

try adding this code to the end of your controlDict :

Code:
functions
{
    heaterTemperatureChecker
    {
        libs        ("libutilityFunctionObjects.so");
        type        coded;
        region      heater_1;
        writeControl timeStep;
        writeInterval 1;

        codeExecute
        #{
            const auto& Temperature = mesh().lookupObject<volScalarField>("T");
            scalar averageT = Temperature.weightedAverage(mesh().V()).value();

            static scalar averageT_old = -10.0;

            Info << "averageTemperature = " << averageT << endl;

            if(averageT_old < 0)
            {
                averageT_old = averageT; // update old temp.
            }
            else
            {
                if(averageT - averageT_old > 5)
                {
                    // end simulation and write results
                    const auto& runTime = mesh().time();
                    runTime.stopAt(Foam::Time::stopAtControl::writeNow);
                    
                }
                else
                {
                    averageT_old = averageT; // update old temp.
                }
            }

        #};
    }

}
still in doubt or want to know why this works watch this video https://youtu.be/xkXtlWp2IKs
TheIdeal likes this.
einstein_zee is offline   Reply With Quote

Old   February 21, 2025, 14:50
Default Great solution and great site to learn
  #5
Member
 
SergioCosta's Avatar
 
RJSergio Feitoza Costa
Join Date: Sep 2024
Posts: 44
Rep Power: 2
SergioCosta is on a distinguished road
still in doubt or want to know why this works watch this video https://youtu.be/xkXtlWp2IKs[/QUOTE]

///////////////////////////////////////////////////////////

Thank you very much einstein_zee for helping me and many other people with this complete class about functions.
After seeing your great video, I understood that a more general strategy to fix the moment to stop the simulation is to do
If ( (averageT - averageT_old) / time ) < (5K / 3660 s) // lower than 5K per hour

SUGGESTION FOR VÍDEO IN YOUR SITE:
Imagine an empty metal box suspended in the air at 300K with dimensions 1x1x1 m . Walls and ceiling thickness are 5mm (5E-3m). I put a 100-Watt light bulb inside. The air heats up and I calculate the final average temperature of the air inside as in the figure in the post. Now imagine that the ceiling and floor of the box are made of a metal foam plate with 90% porosity and I put the same light bulb. The air inside will heat up less. If you wish a little bit more complicated suppose that the velocity of the air inside (buoyancy) is 0.025m/s I'm trying to find the right solver and strategy to simulate this.

Along the last 20 years of my 70s I developed a non-CFD software easier to manipulate. In this validation document there are comparing test results to simulation results. The results of the tests are rare to find.
Maybe can be useful in your teaching classes https://www.cognitor.com.br/TR_150_E...rDesignSWD.pdf

P.S: Is there any video in your site showing how to plot charts with Paraview ?
Congratulations and thanks again
TheIdeal likes this.
SergioCosta is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
somaFoam - And plasma goes weee Destouches OpenFOAM Running, Solving & CFD 11 July 17, 2024 06:55
Can I write temperature dependent UFD code in ansys fluent expression? GreyMat FLUENT 0 August 9, 2022 10:53
Changing Temperature of patch within code of solver SalvusApfel OpenFOAM Pre-Processing 1 February 24, 2017 07:29
monitoring point of total temperature rogbrito FLUENT 0 June 21, 2009 17:31
State of the art in CFD technology Juan Carlos GARCIA SALAS Main CFD Forum 39 November 1, 1999 14:34


All times are GMT -4. The time now is 13:23.