CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

Unknown character in name of output variable when using coded function object

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By Wenyuan
  • 1 Post By Wenyuan
  • 2 Post By Wenyuan

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 10, 2020, 06:05
Default Unknown character in name of output variable when using coded function object
  #1
New Member
 
Philomène Vergnol
Join Date: Apr 2020
Posts: 11
Rep Power: 6
pvergnol is on a distinguished road
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
Attached Images
File Type: png mu.PNG (847 Bytes, 7 views)
pvergnol is offline   Reply With Quote

Old   August 11, 2020, 18:06
Default
  #2
New Member
 
Wenyuan Fan
Join Date: Mar 2017
Posts: 27
Rep Power: 9
Wenyuan is on a distinguished road
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 likes this.
Wenyuan is offline   Reply With Quote

Old   August 12, 2020, 06:36
Default
  #3
New Member
 
Philomène Vergnol
Join Date: Apr 2020
Posts: 11
Rep Power: 6
pvergnol is on a distinguished road
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
pvergnol is offline   Reply With Quote

Old   August 12, 2020, 06:57
Default
  #4
New Member
 
Wenyuan Fan
Join Date: Mar 2017
Posts: 27
Rep Power: 9
Wenyuan is on a distinguished road
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 likes this.
Wenyuan is offline   Reply With Quote

Old   August 12, 2020, 10:57
Default
  #5
New Member
 
Philomène Vergnol
Join Date: Apr 2020
Posts: 11
Rep Power: 6
pvergnol is on a distinguished road
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!
pvergnol is offline   Reply With Quote

Old   August 12, 2020, 14:29
Default
  #6
New Member
 
Wenyuan Fan
Join Date: Mar 2017
Posts: 27
Rep Power: 9
Wenyuan is on a distinguished road
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
pvergnol and pingtao like this.
Wenyuan is offline   Reply With Quote

Reply

Tags
codedfunctionobject, compressibleinterfoam


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
[Other] mesh airfoil NACA0012 anand_30 OpenFOAM Meshing & Mesh Conversion 13 March 7, 2022 18:22
emag beta feature: charge density charlotte CFX 4 March 22, 2011 10:14
Error with Wmake skabilan OpenFOAM Installation 3 July 28, 2009 01:35
Compilation error OF1.5-dev on Suse10.3 darenyang OpenFOAM Installation 0 April 29, 2009 05:55
[blockMesh] BlockMeshmergePatchPairs hjasak OpenFOAM Meshing & Mesh Conversion 11 August 15, 2008 08:36


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