CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Dynamic BCs Based on Probes/Properties at a Specific Point (https://www.cfd-online.com/Forums/openfoam-programming-development/239345-dynamic-bcs-based-probes-properties-specific-point.html)

alexsym November 1, 2021 20:58

Dynamic BCs Based on Probes/Properties at a Specific Point
 
Hello,

Context:
I am trying to set up a model with dynamic boundary conditions. The model is a carpark with a fire, where I want inlet and outlet fans (BCs) to dynamically turn on/off when a certain measured property is reached in a specific location (Probe/Detector). For example when a temperature of 68*C is reached in a specific location, I want the inlet and outlet fans (BCs) to turn off. I know I could run an initial model to figure out when certain events occur, then reset the model with the BC modified to turn off at the specified time. However, i would rather run the model once to save time and computer recourses. Note this is intended to emulate heat/smoke/CO detectors controlling controlling active systems such as fans/dampers, as they would in real life.

My question:
Is it possible to dynamically modify a BC based on the properties in a specific location of the model?

Additional:
I believe it may be possible using the codedFixedValue BC, however I am new to C++ coding and could not find any examples. Because of this I am not sure it is possible using the codedFixedValue BC.

If there are any other ways, that are known or could be developed, to dynamically modify a BCs, any information would be greatly appreciated.

alexsym November 11, 2021 15:26

I figures out how to do this using functions in the controlDict to stop the model and an All_run bash script to restart and modify the boundary condition.

control dict functions:

Code:

functions
{
    temp_0
    {
        type            volFieldValue;
        libs            ( "libfieldFunctionObjects.so" );
        fields          ( T );
        operation      max;
        writeFields    false;
        writeInterval  1;
        log            true;
        regionType      cellZone;
        name            cz0;
    }
    runTimeControl1
    {
        type            runTimeControl;
        libs            ( "libutilityFunctionObjects.so" );
        conditions
        {
            condition0
            {
                type            minMax;
                functionObject  temp_0;
                mode            minimum;
                value          293;
                fields          ( max(cz0,T) );
            }
        }
    }
}

topoSetDict for the above function in control dict:

Code:

actions
(

        {
                name    c0;
                type    cellSet;
                action  new;
                source  nearestToCell;
        points
        (
            (0 0 1)
        );

        }
       
    {
        name    cz0;
        type    cellZoneSet;
        action  new;
        source  setToCellZone;
        set    c0;
    }

);

All_run bash script for a parallel run

# Application name
Code:

application=$(getApplication)

processes=4
detThresh=295
detInit=293
endTime=20
timeStepBA=1
timeStepAA=10

foamDictionary system/decomposeParDict -entry numberOfSubdomains -set "$processes"
foamDictionary system/controlDict -entry functions.runTimeControl1.conditions.condition0.value -set "$detThresh"
foamDictionary system/controlDict -entry endTime -set "$endTime"
foamDictionary system/controlDict -entry functions.runTimeControl1.conditions.condition0.mode -set "maximum"
foamDictionary system/controlDict -entry writeInterval -set "$timeStepBA"

runApplication topoSet

runApplication decomposePar

runParallel $(getApplication)

foamDictionary system/controlDict -entry functions.runTimeControl1.conditions.condition0.mode -set "minimum"
latestFolder=$(ls processor0/ -t | head -1)
rm -r processor*/$latestFolder
unset latestFolder

latestFolder=$(ls processor0/ -t | head -1)
latestFolder=$((latestFolder + timeStepBA))

foamDictionary system/controlDict -entry endTime -set "$latestFolder"
foamDictionary system/controlDict -entry functions.runTimeControl1.conditions.condition0.value -set "$detInit"
unset latestFolder

rm log.fireFoam
runParallel $(getApplication)

x=0
processes=$((processes-1))
while [ $x -le $processes ]
do
        processor=processor$x
        latestFolder=$(ls $processor/ -t | head -1)
        var_0=$(foamDictionary $processor/$latestFolder/U -entry boundaryField.outlet_1.refValue -value)
        x=$(( $x + 1 ))
        var_1="nonuniform List<scalar> 0()"
        if [ "$var_0" != "$var_1" ]
        then
                foamDictionary $processor/$latestFolder/U -entry boundaryField.outlet_1.refValue -set "uniform 0"
        fi
done
unset latestFolder
unset x
unset var_0
unset var_1
unset processes
unset processor

latestFolder=$(ls processor0/ -t | head -1)
stepTime=$latestFolder
x=$((stepTime%timeStepAA))
while [ $x -ne 0 ]
do
        stepTime=$((stepTime+timeStepBA))
        x=$((stepTime%timeStepAA))
done
foamDictionary system/controlDict -entry endTime -set "$stepTime"
rm log.fireFoam
runParallel $(getApplication)

foamDictionary system/controlDict -entry endTime -set "$endTime"
foamDictionary system/controlDict -entry writeInterval -set "$timeStepAA"
rm log.fireFoam
runParallel $(getApplication)

runApplication reconstructPar

foamDictionary system/controlDict -entry functions.runTimeControl1.conditions.condition0.value -set "$detThresh"
#rm -r processor*
#rm -r postProcessing
rm log.decomposePar
rm log.fireFoam
rm log.toposet
rm log.reconstructPar

foamDictionary system/controlDict -entry functions.runTimeControl1.conditions.condition0.mode -set "maximum"


Tobermory November 14, 2021 06:27

Nice work Alex, and thanks for posting your solution - it's always good to see other's solutions, and to swap ideas. By the way, for getting the name of the latest time folder
Code:

latestFolder=$(ls processor0/ -t | head -1)
note that you can also just use the foamListTimes utility, eg
Code:

time=$(foamListTimes -latestTime)


All times are GMT -4. The time now is 18:06.