|
[Sponsors] |
![]() |
![]() |
#1 |
New Member
Huang, Ching-Chan
Join Date: Jan 2023
Posts: 16
Rep Power: 3 ![]() |
I want use simpleFoam and scalarTransportFoam at the same time.
The simpleFoam will solve the U field first. Then the scalarTransportFoam solve the diffusion field. It just look like at first time, run simpleFoam then run scalarTransportFoam. At second time, run simpleFoam then run scalarTransportFoam. and so one..., until end time. Most of the websites about multisolve just mention about multisolver have existed, but do not show how to use. If anyone can help me by providing some tutorials or informations about multisolver? |
|
![]() |
![]() |
![]() |
![]() |
#2 |
Senior Member
Yann
Join Date: Apr 2012
Location: France
Posts: 1,169
Rep Power: 27 ![]() |
Hello,
You can use the scalarTransport function object while running simpleFoam.
Search for scalarTransport in tutorials, there must be some tutorials using this function. Cheers, Yann |
|
![]() |
![]() |
![]() |
![]() |
#4 |
Senior Member
Yann
Join Date: Apr 2012
Location: France
Posts: 1,169
Rep Power: 27 ![]() |
This is just an idea but in the OpenCFD branch it seems your can define an alternate variable for nut, so if you manage to compute a new variable nut/Pr (for instance using another function object), you should be able to use it in scalarTransport.
In the foundation branch this is not documented and after a quick look at the code it does not seem possible to define another variable for nut. I hope this helps, Yann |
|
![]() |
![]() |
![]() |
![]() |
#6 |
Senior Member
|
What governs the scope of variables in function objects?
The code below results in the error message "request for volScalarField scaled_nut from objectRegistry region0 failed" Code:
functions { mf // mixture fraction { type scalarTransport; libs ("libsolverFunctionObjects.so" "utilityFunctionObjects"); codeExecute #{ const volScalarField& nut = mesh().thermo.nut(); volScalarField scaled_nut; ( IOobject ( "scaled_nut", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE ), mesh(), dimensionedScalar("scaled_nut", nut.dimensions()) ); const scalar sigmat = 0.8; forAll(nut, celli) { scaled_nut.internalField()[celli] = nut[celli].internalField()/sigmat; } #}; // Optional: Name of scalar field to transport, default = 's' field mixture_fraction; // Optional: Name of flux field, default = 'phi' phi phi; // Optional: Name of density field for compressible cases, default = 'rho' rho rho; // Optional: Name of phase field to constrain scalar to, default = 'none' phase none; // Optional: Set the scalar to zero on start/re-start resetOnStartUp no; // Optional: Name of field to use when looking up schemes from fvSchemes // default = <field> schemesField Yi; // Optional: Diffusivity: Fixed value diffusivity // D 1000; // Optional: Name of field to use as diffusivity, default = 'none' nut scaled_nut; // Optional: Run-time selectable sources fvOptions { // ... } } } |
|
![]() |
![]() |
![]() |
![]() |
#7 |
Senior Member
Yann
Join Date: Apr 2012
Location: France
Posts: 1,169
Rep Power: 27 ![]() |
I may be wrong but I don't think you can just insert code into the scalarTransport function. Are you sure your code snippet is executed? If it's not it would explain your error message.
I would use a coded function object to compute your code snippet and then use the new variable in scalarTransport. This should work as long as the coded function is defined/executed before the scalarTransport one. If you're using the OpenCFD branch, the exprField function object might be an alternative to the coded function. Let me know if this is of any help for you! |
|
![]() |
![]() |
![]() |
![]() |
#9 |
Senior Member
|
Currently trying with two coded function objects. The goal here to pass a volScalarField defined in the first to the second coded function object. Retrieving volScalarField in the second function object currently fails. Advice is much appreciated.
Code:
// here autoPtr is used to avoid that Tsclaled goes out of scope as soon as the function is left; // for an example, see e.g. https://www.cfd-online.com/Forums/openfoam-programming-development/99207-create-registered-object-runtime-using-functionobject.html // how to share this data among functionObjects: using object registry (currently checkin() fails) or using shared pointer // scales the temperature with a constant and stores scaled value in the object registry scalingT { type coded; libs ("libutilityFunctionObjects.so"); name scalingT; codeOptions // this seems mandatory: without it, code fails to compile #{ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/OpenFOAM/lnInclude #}; codeExecute #{ #}; codeWrite // "to avoid No critical "code" prefixed keywords found." #{ Info<<" Scaling the temperature at time "<<endl; Info<<" t = " << mesh().time().timeName() <<" with scaling factor "<< endl; #}; code #{ // defines scaling constant as a fixed scalar const scalar sigmat = .8; Info<<" sigmat = "<<sigmat<<endl; // const pointer to existing T-field const volScalarField& T = mesh().lookupObject<volScalarField>("T"); // static autoPtr to field to be created static autoPtr<volScalarField> pField; // if autoPtr is null then create new volScalarField if (!pField.valid()) { Info << "creating Tscaled" << nl; pfield.set ( new volScalarField ( IOobject ( "Tscaled", mesh().time().timeName(), T.mesh(), IOobject::NO_READ, IOobject::NO_WRITE ), T/sigmat ); } // end of if(!pField.valid()) // retrieve volScalarField from autoPtr volScalarField &Tscaled = pField(); forAll(T,cellI){ Tscaled[i] = T[i]/sigmat; } Info << "Add Tscaled to the registry" << nl; Tscaled.checkIn(); Tscaled.store(); mesh().store( Tscaled ); } const volScalarField& Tscaled2 = mesh().lookupObject<volScalarField>("Tscaled"); Info<<" Looking up the scaled temperature at time "<<endl; Info<<" t = " << mesh().time().timeName() << endl; Info<<" with magnitude = " << mag(Tscaled2) << endl; #}; } Code:
lookupScaledT { type coded; libs ("libutilityFunctionObjects.so"); name lookupScaledT; codeOptions // this seems mandatory: without it, code fails to compile #{ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/OpenFOAM/lnInclude #}; codeExecute #{ #}; codeWrite // "to avoid No critical "code" prefixed keywords found." #{ // const volScalarField& Tscaled = mesh().lookupObject<volScalarField>("Tscaled"); const volScalarField& T = mesh().lookupObject<volScalarField>("T"); Info<<" Looking up the scaled temperature at time "<<endl; Info<<" t = " << mesh().time().timeName() << endl; //Info<<" with magnitude = " << mag(Tscaled) << endl; Info<<" with magnitude = " << mag(T) << endl; #}; } |
|
![]() |
![]() |
![]() |
![]() |
#10 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 ![]() ![]() |
Quote:
What you are currently doing will likely produce rubbish. Starting with an empty autoPtr, you create it and fill with values (NOTE: you probably want a correctBoundaryConditions() there too). At the end, you mark it as being known and stored on the registry, which moves ownership of the pointer from the autoPtr to the registry. This means that the second call will again have an empty autoPtr and the cycle continues. However, since you already have that named field in the registry, nothing will be updated. Potentially you will also leak memory there as well. |
||
![]() |
![]() |
![]() |
![]() |
#11 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,714
Rep Power: 40 ![]() ![]() |
Now added information in https://develop.openfoam.com/Develop...terns/registry
|
|
![]() |
![]() |
![]() |
![]() |
#12 |
Senior Member
|
Dear Mark,
Sincere apologies for not getting in touch earlier. Regarding your contribution at https://develop.openfoam.com/Develop...terns/registry I have the following two queries: 1/ Should mesh read mesh() at various instances? 2/ How do "auto* result = *fieldPtr;" and "auto result = *fieldPtr;" I am happy to provide the application I am working on as example on the wiki page. Kind wishes, Domenico. |
|
![]() |
![]() |
![]() |
Tags |
multisolver, openfoam, scalartransportfoam, simplefoam, solver |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
multiSolver released | marupio | OpenFOAM Announcements from Other Sources | 12 | June 3, 2011 09:44 |
Problem with multisolver installation | 1gn0rant | OpenFOAM | 1 | August 5, 2010 08:00 |
Trouble with Multisolver installation... | 1gn0rant | OpenFOAM Running, Solving & CFD | 6 | August 2, 2010 11:34 |