CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Unknown character in name of output variable when using coded function object (https://www.cfd-online.com/Forums/openfoam-post-processing/229456-unknown-character-name-output-variable-when-using-coded-function-object.html)

pvergnol August 10, 2020 05:05

Unknown character in name of output variable when using coded function object
 
1 Attachment(s)
Hello everyone,

I work with OpenFOAM v7 and the solver compressibleInterFoam.
I am studying a water/air flow in a cylinder.
For the post-processing, I want to be able to visualize the dynamic viscosity (mu) on Paraview.
When running the solver, there are multiple variables in the output directories, but mu isn't one of them.
So I use a coded function object :

Code:

myFunctionMu
    {
        type                            coded;
        libs                            ("libutilityFunctionObjects.so");
        name                          writingMu;
        codeWrite
        #{
            const volScalarField& mu = mesh().lookupObject<volScalarField>("thermo:mu");
            mu().write();
        #};
    }

Base on the template found here : https://cpp.openfoam.org/v7/classFoa...ionObject.html

This works, the mu files are written in the output directories.
The problem is the name of those files, because they contain an unknown character (image is attached). If I try to copy it here it gives : thermomu
It is a problem because I can't visualize them in Paraview, while I can with other objects I output (e.g. yPlus).

I tried putting just "mu" instead of "thermo:mu", but when I run the solver there is an error message :

Code:

request for volScalarField mu from objectRegistry region0 failed
    available objects of type volScalarField are

39
(
thermo:alpha.air
alpha.air_0
thermo:mu
alpha.water_0
thermo:alpha.water
interfaceProperties:K
thermo:psi
nut
K
K_0
alpha.water
yPlus
p_rgh_0
T.air
thermo:psi.water
rho
T.water
p_rgh
gh
thermo:psi.air
thermo:rho.water_0
delta
enstrophy
alphat
thermo:rho.air
rho_0
p
T
thermo:rho.water
T_0
alpha.air
thermo:mu.water
e.air
thermo:rho.air_0
Co
(alpha.water*div(phi))
thermo:mu.air
e.water
thermo:alpha
)

I also tried removing the parentheses here :
Code:

mu.write();
or changing the name of the constant but the problem remains.

Is there a problem in my code ? If not, is this a bug ? If yes, is there a way to change the name of the output files to be able to read them in Paraview ?

Additional question but relevant only if I solve the main (mu) problem first : Ideally, I also want to get the kinematic viscosity (nu) but it isn't in the list of the available volScalarField. Can I output them using a coded function object or an other type of function object dividing mu by rho ?

Thank you in advance,

-Philomène

Wenyuan August 11, 2020 17:06

Hi Philomène,

Your code looks fine. It is weird that the colon symbol cannot be displayed properly, since it is a legal character for filenames in Linux. There are two ways you can try:
1. rename the file after running the simulation
2. change your code to
Code:

const volScalarField& mu = mesh().lookupObject<volScalarField>("thermo:mu");
volScalarField Mu
    (
        IOobject
        (
            "mu", // any name you want
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mu
    );
Mu.write();

You can only run the above code when it's time to write to be more efficient.

Regarding nu, you just need to find out rho as you did for mu, calculate mu/rho and then write it out using the code above. You can output both using a single function object. Just add more lines to the code section.

pvergnol August 12, 2020 05:36

Hello Wenyuan, thanks you for your help!

I am running OpenFoam on WSL (Windows Subsystem for Linux) and using Paraview on Windows 10, maybe the error comes from here.
Renaming the files after running the simulation will indeed be my last option.

I tried running the simulation with your code but I have an error message and I don't understand why :

Code:

/mnt/c/Users/vergnol/Documents/liquid_piston/Simulations/SIMULATIONS_3D/SIMU_70_rho_mu/system/controlDict.functions.myFunctionMu: In member function ‘virtual bool Foam::writingMuFunctionObject::write()’:
/mnt/c/Users/vergnol/Documents/liquid_piston/Simulations/SIMULATIONS_3D/SIMU_70_rho_mu/system/controlDict.functions.myFunctionMu:81:7: error: ‘runTime’ was not declared in this scope
/mnt/c/Users/vergnol/Documents/liquid_piston/Simulations/SIMULATIONS_3D/SIMU_70_rho_mu/system/controlDict.functions.myFunctionMu:81:7: note: suggested alternative: ‘dimTime’
make: *** [Make/linux64GccDPInt32Opt/functionObjectTemplate.o] Error 1
[0]
[0]
[0] --> FOAM FATAL IO ERROR:
[0] Failed wmake "dynamicCode/writingMu/platforms/linux64GccDPInt32Opt/lib/libwritingMu_33240e2602611f4d17313e6bfbc54de6c82bead9.so"
[0]
[0]
[0] file: /mnt/c/Users/vergnol/Documents/liquid_piston/Simulations/SIMULATIONS_3D/SIMU_70_rho_mu/system/controlDict.functions.myFunctionMu from line 70 to line 74.
[0]
[0]    From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const
[0]    in file db/dynamicLibrary/codedBase/codedBase.C at line 206.
[0]
FOAM parallel run exiting

The error seems to be that "runTime" is not previously defined.
Should I add something in my controlDict ?
Here it is :

Code:

application    compressibleInterFoam;

startFrom      latestTime;

startTime      0;

stopAt          endTime;

endTime        21;

deltaT          0.001;

writeControl    timeStep;       

writeInterval  1;                       

purgeWrite      0;

writeFormat    ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision  6;

runTimeModifiable true;

adjustTimeStep  yes;

maxCo          1;
maxAlphaCo      0.4;
maxDeltaT      0.01;

functions
{
        myFunctionMu
    {
        type                            coded;
        libs                            ("libutilityFunctionObjects.so");
        name                          writingMu;
        codeWrite
        #{
            const volScalarField& mu = mesh().lookupObject<volScalarField>("thermo:mu");
            volScalarField Mu
                        (
                                IOobject
                                (
                                        "mu", // any name you want
                                        runTime.timeName(),
                                        mesh,
                                        IOobject::NO_READ,
                                        IOobject::AUTO_WRITE
                                ),
                                mu
                        );
                Mu.write();
        #};
    }
}

Best,

-Philomène

Wenyuan August 12, 2020 05:57

Hi Philomène,

Now the problem is clear to me since colon is an illegal character for Windows filename.

Regarding the error, you can try
Code:

mesh.time().timeName()
BTW, you can also try to use the Linux subsystem to run ParaView.

pvergnol August 12, 2020 09:57

Hi,

Yes you're right the problem occurs when naming the file on Windows! Thank you for helping me identify the source of the problem. I will run it with Ubuntu to solve this.

There is still a message error when I try your code though :

Code:

ln: ./lnInclude
/mnt/c/Users/vergnol/Documents/liquid_piston/Simulations/SIMULATIONS_3D/SIMU_70_rho_mu/system/controlDict.functions.myFunctionMu: In member function ‘virtual bool Foam::writingMuFunctionObject::write()’:
/mnt/c/Users/vergnol/Documents/liquid_piston/Simulations/SIMULATIONS_3D/SIMU_70_rho_mu/system/controlDict.functions.myFunctionMu:81:7: error: invalid use of member function ‘const Foam::fvMesh& Foam::writingMuFunctionObject::mesh() const’ (did you forget the ‘()’ ?)
make: *** [Make/linux64GccDPInt32Opt/functionObjectTemplate.o] Error 1
[0]
[0]
[0] --> FOAM FATAL IO ERROR:
[0] Failed wmake "dynamicCode/writingMu/platforms/linux64GccDPInt32Opt/lib/libwritingMu_d46f4e90ee27fdba7556000cf87a0f480bb19555.so"
[0]
[0]
[0] file: /mnt/c/Users/vergnol/Documents/liquid_piston/Simulations/SIMULATIONS_3D/SIMU_70_rho_mu/system/controlDict.functions.myFunctionMu from line 70 to line 74.
[0]
[0]    From function void Foam::codedBase::createLibrary(Foam::dynamicCode&, const Foam::dynamicCodeContext&) const
[0]    in file db/dynamicLibrary/codedBase/codedBase.C at line 206.
[0]
FOAM parallel run exiting
[0]

I am not familiar with the use of such code, so I still don't understand the error.

Anyways, you've helped me a lot, thank you!

Wenyuan August 12, 2020 13:29

Hi,

I should have tested the code before posting. I am sorry for that. The following code works with OpenFOAM-v1906 at least
Code:

codeWrite
#{
        if (mesh().time().writeTime())
            {
                const volScalarField& mu = mesh().lookupObject<volScalarField>("thermo:mu");
                volScalarField Mu
                (
                    IOobject
                    (
                        "mu", // any name you want
                        mesh().time().timeName(),
                        mesh(),
                        IOobject::NO_READ,
                        IOobject::AUTO_WRITE
                    ),
                    mu
                );
                Mu.write();
          }
#};

Wenyuan


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