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

How to multiply a field by another?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By HPE

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 16, 2020, 07:18
Default How to multiply a field by another?
  #1
New Member
 
Romain SL
Join Date: Apr 2020
Location: Lyon, France
Posts: 8
Rep Power: 6
rsaintlege is on a distinguished road
Hello,

I'm trying to find a function to multiply a field by another but I can't find what I want.
However I found the functions 'sum' and 'subtract' so I'm assuming that it is possible to multiply fields as well with functions...

I also found the function 'scale' but it allows to multiply a field by a scalar only.

Any ideas?
rsaintlege is offline   Reply With Quote

Old   May 16, 2020, 15:13
Default
  #2
HPE
Senior Member
 
HPE's Avatar
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 931
Rep Power: 13
HPE is on a distinguished road
Hi,

- I assume you really meant `function object` by `function`.
- To my knowledge, there is no compiled FO for field multiplications, like there is `add`
- You can use `codedFunctionObject`s.
- You can modify an existing function object for your requirements.

Hope this helps for a start.
rsaintlege likes this.
HPE is offline   Reply With Quote

Old   May 17, 2020, 07:11
Default
  #3
New Member
 
Romain SL
Join Date: Apr 2020
Location: Lyon, France
Posts: 8
Rep Power: 6
rsaintlege is on a distinguished road
Thank you for your answer it helped me a lot. I tried to use codedFunctionObject and I wrote this (I'm not sure about it):

Code:
    compute_Power
    {
        functionObjectLibs ( "libutilityFunctionObjects.so" );
        type coded;
        enabled true;
        redirectType Power;
	executeControl  writeTime;
	writeControl    writeTime;
        code
        #{
            const volScalarField& T = mesh().lookupObject<volScalarField>("T");
            const volVectorField& U = mesh().lookupObject<volVectorField>("U");
            volScalarField Power
            (
                IOobject
                (
                    "Power",
                    mesh().time().timeName(),
                    Power.mesh(),
                    IOobject::NO_READ,
                    IOobject::AUTO_WRITE
                ),
                Power= 4185*1000*mag(U)*(T-293)
            );
	    Power.write();
        #};
    }
However, when I run the code, it seems to work fine but when I check the results in paraview, it appears that the field that I call "power" doesn't show up. Did I write something wrong or forget something in the code above?

Last edited by rsaintlege; May 17, 2020 at 10:16.
rsaintlege is offline   Reply With Quote

Old   May 17, 2020, 10:39
Default
  #4
New Member
 
Romain SL
Join Date: Apr 2020
Location: Lyon, France
Posts: 8
Rep Power: 6
rsaintlege is on a distinguished road
This is finally the best I managed to do:

Code:
compute_Power
	{
	    libs        ("libutilityFunctionObjects.so");

	    type coded;
	    name compute_Power;
	    outputControl  writeTime;

	    codeWrite
	    #{
		    const volScalarField& h = mesh().lookupObject<volScalarField>("h");
		    const volScalarField& h_0 = mesh().lookupObject<volScalarField>("h_0");
		    const volVectorField& U = mesh().lookupObject<volVectorField>("U");
		    volScalarField Power = 1000*mag(U)*(h-h_0);
		    Power.write();
	    #};
	}
That seems to work but the generated files don't have a real name, it's something like "(1000*mag(U)*(h-h_0))". Paraview cannnot therefore open those files. How can I name those files?
rsaintlege is offline   Reply With Quote

Old   May 17, 2020, 11:36
Default
  #5
Senior Member
 
JNSN's Avatar
 
Jan
Join Date: Jul 2009
Location: Hamburg
Posts: 144
Rep Power: 20
JNSN is on a distinguished road
Do you need this field just for post proccesing? Then you could also do this just in paraview.
JNSN is offline   Reply With Quote

Old   May 17, 2020, 12:08
Default
  #6
New Member
 
Romain SL
Join Date: Apr 2020
Location: Lyon, France
Posts: 8
Rep Power: 6
rsaintlege is on a distinguished road
Quote:
Originally Posted by JNSN View Post
Do you need this field just for post proccesing? Then you could also do this just in paraview.
Thank you for your answer.

Yes I just need it for post processing actually. How would you do to get this field with paraview? I previously did it by exporting the needed datas as csv files in Excel but I can't do it 100 times

I'm new on OpenFOAM so I don't really know what are the possibilities yet.

I'm still interested about making the previous function object work though. I think it would be more convenient, if you have an idea.

*EDIT*: I finally managed to do it with the 'calculator' option in Paraview
rsaintlege is offline   Reply With Quote

Old   September 28, 2021, 05:00
Default
  #7
New Member
 
Thomas Michelon
Join Date: Sep 2021
Posts: 1
Rep Power: 0
thomas_mhn is on a distinguished road
Quote:
Originally Posted by rsaintlege View Post
Thank you for your answer.

Yes I just need it for post processing actually. How would you do to get this field with paraview? I previously did it by exporting the needed datas as csv files in Excel but I can't do it 100 times

I'm new on OpenFOAM so I don't really know what are the possibilities yet.

I'm still interested about making the previous function object work though. I think it would be more convenient, if you have an idea.

*EDIT*: I finally managed to do it with the 'calculator' option in Paraview
Hi I'm also interested in making this kind of function.

Did you manage to change the name of the output file? I also have something like ( field1 * field2 ) as the name of the file.
thomas_mhn is offline   Reply With Quote

Old   May 22, 2023, 09:26
Default
  #8
New Member
 
Join Date: Apr 2023
Posts: 11
Rep Power: 3
little_fish is on a distinguished road
Hello,



i m still interested to use this postprocess function object, because i don t need to compute this field for each iteration, and i also need the field for calculation (so paraview is not the best option...)



here my coded function :



Code:
field_UthetaT
    {
        libs        ("libutilityFunctionObjects.so");

        type coded;
        name UthetaT;
        // executeControl  writeTime;
        // writeControl    writeTime;
        // region         region1;
        // patches         (cyclic1);

        codeWrite
        #{
            const volScalarField& Utheta = mesh().lookupObject<volScalarField>("Utheta.gz");
            const volScalarField& T = mesh().lookupObject<volScalarField>("T.gz");
            volScalarField UthetaT = Utheta * T;
            UthetaT.write();
        #};
        }
and here the error i get when i use the function.



Code:
Create time

Create mesh for time = 20000

Using dynamicCode for functionObject field_UthetaT at line 3 in "functions.field_UthetaT"
Time = 20000

Reading fields:

Executing functionObjects


--> FOAM FATAL ERROR: (openfoam-2112 patch=220610)

    failed lookup of Utheta.gz (objectRegistry region0)
    available objects of type volScalarField:
0()


    From const Type& Foam::objectRegistry::lookupObject(const Foam::word&, bool) const [with Type = Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>]
    in file /usr/lib/openfoam/openfoam2112/src/OpenFOAM/lnInclude/objectRegistryTemplates.C at line 463.

FOAM exiting
If someone could help me, it would be very cool.



Regards
little_fish is offline   Reply With Quote

Old   May 22, 2023, 09:29
Default
  #9
New Member
 
Join Date: Apr 2023
Posts: 11
Rep Power: 3
little_fish is on a distinguished road
ps: i did not write the function in the control dict because i have already some datas i need to postprocess, so i m using the following command :



postProcess -func field_UthetaT -latestTime



cordially
little_fish is offline   Reply With Quote

Old   May 24, 2023, 09:21
Default
  #10
Senior Member
 
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22
cnsidero is on a distinguished road
Checkout multiply Class Reference

You can find an example of it in the openfoam.com tutorials:

Code:
$FOAM_TUTORIALS/incompressible/pisoFoam/RAS/cavity/system/FOs/FOmultiply
cnsidero is offline   Reply With Quote

Old   November 13, 2023, 17:24
Default
  #11
New Member
 
Turhan
Join Date: Sep 2022
Posts: 16
Rep Power: 4
Turhan is on a distinguished road
Quote:
Originally Posted by rsaintlege View Post
This is finally the best I managed to do:

Code:
compute_Power
	{
	    libs        ("libutilityFunctionObjects.so");

	    type coded;
	    name compute_Power;
	    outputControl  writeTime;

	    codeWrite
	    #{
		    const volScalarField& h = mesh().lookupObject<volScalarField>("h");
		    const volScalarField& h_0 = mesh().lookupObject<volScalarField>("h_0");
		    const volVectorField& U = mesh().lookupObject<volVectorField>("U");
		    volScalarField Power = 1000*mag(U)*(h-h_0);
		    Power.write();
	    #};
	}
That seems to work but the generated files don't have a real name, it's something like "(1000*mag(U)*(h-h_0))". Paraview cannnot therefore open those files. How can I name those files?
You have written this code, I have done something similar but I could not find the output values after doing the simulation.

I am not sure if my code is wrong or that I cannot find the output file from this code. Anyhow, I was wondering where I can find it, is it in the postprocessing file or in the ?
Turhan is offline   Reply With Quote

Reply

Tags
field, function, multiply


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
potential flows, helmholtz decomposition and other stuffs pigna Main CFD Forum 1 October 26, 2017 09:34
Access to field which is evaluated at the moment Tobi OpenFOAM Programming & Development 6 April 19, 2017 14:09
[General] How to create an additional vector with {Field 4, Field 5, Field 6} Bombacar ParaView 1 August 15, 2015 19:05
[Netgen] Import netgen mesh to OpenFOAM hsieh OpenFOAM Meshing & Mesh Conversion 32 September 13, 2011 06:50
CheckMeshbs errors ivanyao OpenFOAM Running, Solving & CFD 2 March 11, 2009 03:34


All times are GMT -4. The time now is 16:30.