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 Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By HPE

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 16, 2020, 06: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: 2
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, 14:13
Default
  #2
HPE
Senior Member
 
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 583
Rep Power: 5
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, 06:11
Default
  #3
New Member
 
Romain SL
Join Date: Apr 2020
Location: Lyon, France
Posts: 8
Rep Power: 2
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 09:16.
rsaintlege is offline   Reply With Quote

Old   May 17, 2020, 09:39
Default
  #4
New Member
 
Romain SL
Join Date: Apr 2020
Location: Lyon, France
Posts: 8
Rep Power: 2
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, 10:36
Default
  #5
Member
 
JNSN's Avatar
 
Jan
Join Date: Jul 2009
Location: Hamburg
Posts: 80
Rep Power: 15
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, 11:08
Default
  #6
New Member
 
Romain SL
Join Date: Apr 2020
Location: Lyon, France
Posts: 8
Rep Power: 2
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

Reply

Tags
field, function, multiply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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


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