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/)
-   -   null volScalarField (https://www.cfd-online.com/Forums/openfoam-programming-development/118450-null-volscalarfield.html)

galap May 28, 2013 04:04

null volScalarField
 
Since OF2.2 there are a lot of changes to the thermophysicalModels. We are running libs here derived from basicThermo which requires now the specification of several virtual functions. I want to solve this by returning NULL pointer fields. Unfortunately I am not able to clearify how a NULL volScalarField can be returned. Does anyone know this?

Thanks in advance

ngj May 28, 2013 05:55

Hi Fabian,

In such cases, where certain functions need implementation, but I know that they will never be used/does not make sense, I use the following in the source code:

Code:

notImplemented("<some string describing the issue>");
This will terminate the simulation with a FatalError, so cleaner than making the program work on NULL-pointers. With respect to the return type, then I simply ignore the warnings in the compilation, since the program will never reach

Code:

return <some object>;
Kind regards

Niels

thomasArk47 May 30, 2013 18:15

Hi,

return volScalarField::null();

works fine (as well for volScalarField than for tmp<volScalarField>)

galap January 29, 2014 04:19

I met again this issue. The ::null() actually works, but I have problems to check, whether it is set or not.

What I am using now is: (schematic)

Code:

void request_data(autoPtr<volScalarField> data)
{
    if (..) { data.set(&<object-you-want-to-return>); }
    else { data.clear() }

    return data;
}


in main script:

autoPtr<volScalarField> data;
request_data(data);

if (data.valid()) { .... }

Maybe this helps someone

galap January 29, 2014 04:44

Be aware that autoPtr takes over control of the prior associated pointer. Instead of autoPtr its better to use tmp. You can use the same syntax, just replace autoPtr with tmp. Instead the set function you have to use data = tmp<volScalarField>(&<object-you-want-to-return);


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