CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   Writing a function object (https://www.cfd-online.com/Forums/openfoam/139776-writing-function-object.html)

samiam1000 July 31, 2014 05:44

Writing a function object
 
1 Attachment(s)
Dear Foamers,

I am writing a function object and I do have some issues to be solved. I hope someone can help:

I am attaching a very simple case. Could you have a look?

I case: Enter the case directory and launch: "scalarTransportFoam"
Everything is ok. In the 10 dir I have the T*2 field.

II case: Enter the case directory and launch: "scalarTransportFoam -noFunctionObjects" and as a post processing run "execFlowFunctionObjects -noZero -latestTime" I get this error:
Code:

samuele@pc-zampini:~/Documenti/PhD/02tesiDomenico/workingDirLocal/dummyCase/passiveScalarBaseGeometry$ execFlowFunctionObjects -noZero -latestTime
/*---------------------------------------------------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.3.0                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
Build  : 2.3.0-f5222ca19ce6
Exec  : execFlowFunctionObjects -noZero -latestTime
Date  : Jul 31 2014
Time  : 10:53:20
Host  : "pc-zampini"
PID    : 21188
Case  : /home/samuele/Documenti/PhD/02tesiDomenico/workingDirLocal/dummyCase/passiveScalarBaseGeometry
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 10

Using dynamicCode for functionObject difference at line 57 in "/home/samuele/Documenti/PhD/02tesiDomenico/workingDirLocal/dummyCase/passiveScalarBaseGeometry/system/controlDict.functions.difference"
Time = 10
    Reading phi
    Reading U
    Reading p
--> FOAM Warning :
--> FOAM FATAL IO ERROR:
cannot find file

file: /home/samuele/Documenti/PhD/02tesiDomenico/workingDirLocal/dummyCase/passiveScalarBaseGeometry/10/p at line 0.

    From function regIOobject::readStream()
    in file db/regIOobject/regIOobjectRead.C at line 73.

samuele@pc-zampini:~/Documenti/PhD/02tesiDomenico/workingDirLocal/dummyCase/passiveScalarBaseGeometry$

Hence, I copy a "p" file in the 10 directory. Nevertheless, I get this:
Code:

samuele@pc-zampini:~/Documenti/PhD/02tesiDomenico/workingDirLocal/dummyCase/passiveScalarBaseGeometry$ execFlowFunctionObjects -noZero -latestTime
/*---------------------------------------------------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.3.0                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
Build  : 2.3.0-f5222ca19ce6
Exec  : execFlowFunctionObjects -noZero -latestTime
Date  : Jul 31 2014
Time  : 10:52:07
Host  : "pc-zampini"
PID    : 21126
Case  : /home/samuele/Documenti/PhD/02tesiDomenico/workingDirLocal/dummyCase/passiveScalarBaseGeometry
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 10

Using dynamicCode for functionObject difference at line 57 in "/home/samuele/Documenti/PhD/02tesiDomenico/workingDirLocal/dummyCase/passiveScalarBaseGeometry/system/controlDict.functions.difference"
Time = 10
    Reading phi
    Reading U
    Reading p
Looking up field T



--> FOAM FATAL ERROR:

    request for volScalarField T from objectRegistry region0 failed
    available objects of type volScalarField are
1(p)

    From function objectRegistry::lookupObject<Type>(const word&) const
    in file /home/samuele/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/objectRegistryTemplates.C at line 198.

FOAM aborting

#0  Foam::error::printStack(Foam::Ostream&) in "/home/samuele/OpenFOAM/OpenFOAM-2.3.0/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#1  Foam::error::abort() in "/home/samuele/OpenFOAM/OpenFOAM-2.3.0/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#2  Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const& Foam::objectRegistry::lookupObject<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >(Foam::word const&) const in "/home/samuele/OpenFOAM/OpenFOAM-2.3.0/platforms/linux64GccDPOpt/lib/libincompressibleRASModels.so"
#3  Foam::mixingEvaluationFunctionObject::write() at /usr/include/c++/4.7/bits/basic_string.h:536
#4  Foam::OutputFilterFunctionObject<Foam::mixingEvaluationFunctionObject>::execute(bool) at ~/OpenFOAM/OpenFOAM-2.3.0/src/OpenFOAM/lnInclude/OutputFilterFunctionObject.C:173
#5  Foam::functionObjectList::execute(bool) in "/home/samuele/OpenFOAM/OpenFOAM-2.3.0/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#6 
 in "/home/samuele/OpenFOAM/OpenFOAM-2.3.0/platforms/linux64GccDPOpt/bin/execFlowFunctionObjects"
#7 
 in "/home/samuele/OpenFOAM/OpenFOAM-2.3.0/platforms/linux64GccDPOpt/bin/execFlowFunctionObjects"
#8  __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6"
#9 
 in "/home/samuele/OpenFOAM/OpenFOAM-2.3.0/platforms/linux64GccDPOpt/bin/execFlowFunctionObjects"
Annullato
samuele@pc-zampini:~/Documenti/PhD/02tesiDomenico/workingDirLocal/dummyCase/passiveScalarBaseGeometry$

Could anyone help?

Also, one more question: how abaout if I want to get an average on each section?

Thanks a lot,
Samuele

Bernhard July 31, 2014 09:53

You also need to -noFlow flag for execFlowFunctionObjects. All variables will then be loaded.

samiam1000 July 31, 2014 10:13

Hi Bernard and thanks for helping.

Also, about my secondo issue, I was thinking about exploiting the sample function and then to average it.

The point is that I would insert a loop in the sampleDict. Is that possible?

I wrote something like:

Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.3.0                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version        2.0;
    format          ascii;
    class          dictionary;
    location        "system";
    object          sampleDict;
}

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

interpolationScheme cellPoint;
 
  surfaceFormat      foamFile;
points = 100;
L = 3000;

dx = $points/$L;

for i = 1:$points

  surfaces
  (
      plane%d, i
      {
                  type        plane;
          basePoint (0.0001 -0.0016+($dx*%i)  0.0001);
          normalVector (0 1 0);
      }
 
  );
}
end
 
fields          ( U );

Any idea?

Thanks again.

samiam1000 July 31, 2014 11:46

I tryed the following solution:
Code:

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

application    scalarTransportFoam;

startFrom      latestTime;

startTime      0;

stopAt          endTime;

endTime        10;                // T = 7.5e-3

deltaT          1;

writeControl    adjustableRunTime;

writeInterval  1;

purgeWrite      0;

writeFormat    ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision  6;

runTimeModifiable true;

adjustTimeStep        yes;

maxCo                        0.9;


functions
{
new_planes
{
    type            faceSource;
    functionObjectLibs ("libfieldFunctionObjects.so");
    enabled        true;
    outputControl  timeStep;
    log            true;
    valueOutput    true;
    source          sampledSurface;
    surfaceFormat  vtk;

        sampledSurfaceDict
        {
                type            plane;
                basePoint      (0.0001 -0.00115 0.0001);
                normalVector    (0 1 0);
        }

        sampledSurfaceDict
        {
                type            plane;
                basePoint      (0.0001 -0.00065 0.0001);
                normalVector    (0 1 0);
        }

    operation      areaAverage;
        fields
        (
                T
        );
}

The point is that it does not allow me to write more than one value of T. How can I do this?


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