|
[Sponsors] |
May 16, 2020, 07:18 |
How to multiply a field by another?
|
#1 |
New Member
Romain SL
Join Date: Apr 2020
Location: Lyon, France
Posts: 8
Rep Power: 6 |
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? |
|
May 16, 2020, 15:13 |
|
#2 |
Senior Member
Herpes Free Engineer
Join Date: Sep 2019
Location: The Home Under The Ground with the Lost Boys
Posts: 931
Rep Power: 13 |
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.
__________________
The OpenFOAM community is the biggest contributor to OpenFOAM: User guide/Wiki-1/Wiki-2/Code guide/Code Wiki/Journal Nilsson/Guerrero/Holzinger/Holzmann/Nagy/Santos/Nozaki/Jasak/Primer Governance Bugs/Features: OpenFOAM (ESI-OpenCFD-Trademark) Bugs/Features: FOAM-Extend (Wikki-FSB) Bugs: OpenFOAM.org How to create a MWE New: Forkable OpenFOAM mirror |
|
May 17, 2020, 07:11 |
|
#3 |
New Member
Romain SL
Join Date: Apr 2020
Location: Lyon, France
Posts: 8
Rep Power: 6 |
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(); #}; } Last edited by rsaintlege; May 17, 2020 at 10:16. |
|
May 17, 2020, 10:39 |
|
#4 |
New Member
Romain SL
Join Date: Apr 2020
Location: Lyon, France
Posts: 8
Rep Power: 6 |
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(); #}; } |
|
May 17, 2020, 11:36 |
|
#5 |
Senior Member
Jan
Join Date: Jul 2009
Location: Hamburg
Posts: 144
Rep Power: 20 |
Do you need this field just for post proccesing? Then you could also do this just in paraview.
|
|
May 17, 2020, 12:08 |
|
#6 | |
New Member
Romain SL
Join Date: Apr 2020
Location: Lyon, France
Posts: 8
Rep Power: 6 |
Quote:
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 |
||
September 28, 2021, 05:00 |
|
#7 | |
New Member
Thomas Michelon
Join Date: Sep 2021
Posts: 1
Rep Power: 0 |
Quote:
Did you manage to change the name of the output file? I also have something like ( field1 * field2 ) as the name of the file. |
||
May 22, 2023, 09:26 |
|
#8 |
New Member
Join Date: Apr 2023
Posts: 11
Rep Power: 3 |
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(); #}; } 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 Regards |
|
May 22, 2023, 09:29 |
|
#9 |
New Member
Join Date: Apr 2023
Posts: 11
Rep Power: 3 |
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 |
|
May 24, 2023, 09:21 |
|
#10 |
Senior Member
Chris Sideroff
Join Date: Mar 2009
Location: Ottawa, ON, CAN
Posts: 434
Rep Power: 22 |
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 |
|
November 13, 2023, 17:24 |
|
#11 | |
New Member
Turhan
Join Date: Sep 2022
Posts: 16
Rep Power: 4 |
Quote:
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 ? |
||
Tags |
field, function, multiply |
|
|
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 |