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

How to use multisolver

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By Yann
  • 2 Post By olesen

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 1, 2023, 10:18
Default How to use multisolver
  #1
New Member
 
Huang, Ching-Chan
Join Date: Jan 2023
Posts: 16
Rep Power: 3
Allen_Huang is on a distinguished road
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?
Allen_Huang is offline   Reply With Quote

Old   April 3, 2023, 03:53
Default
  #2
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,096
Rep Power: 26
Yann will become famous soon enough
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
dlahaye likes this.
Yann is online now   Reply With Quote

Old   April 4, 2023, 03:27
Default
  #3
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 741
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Any idea on how to customise nut, e.g. , replacing nut by nut/Pr, in scalarTransport?

Merci bien. A+.
dlahaye is offline   Reply With Quote

Old   April 4, 2023, 04:09
Default
  #4
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,096
Rep Power: 26
Yann will become famous soon enough
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
Yann is online now   Reply With Quote

Old   April 4, 2023, 04:42
Default
  #5
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 741
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Thx! Will give this a look.
dlahaye is offline   Reply With Quote

Old   April 6, 2023, 14:46
Default
  #6
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 741
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
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
    {
        // ...
    }

  }

}
dlahaye is offline   Reply With Quote

Old   April 7, 2023, 04:01
Default
  #7
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,096
Rep Power: 26
Yann will become famous soon enough
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!
Yann is online now   Reply With Quote

Old   April 7, 2023, 10:02
Default
  #8
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 741
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
Thx again. I am looking into the matter.
dlahaye is offline   Reply With Quote

Old   April 11, 2023, 16:56
Default
  #9
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 741
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
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;
        #};

     }
dlahaye is offline   Reply With Quote

Old   April 13, 2023, 03:42
Default
  #10
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,695
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Quote:
Originally Posted by dlahaye View Post


Code:
          // static autoPtr to field to be created
          static autoPtr<volScalarField> pField;
...

           Info << "Add Tscaled to the registry" << nl;
           Tscaled.checkIn();
           Tscaled.store();
           mesh().store( Tscaled );
You really need to decide if you want to store the field on the object registry, or if you want to store it locally in an autoPtr.


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.
olesen is offline   Reply With Quote

Old   April 13, 2023, 04:15
Default
  #11
Senior Member
 
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,695
Rep Power: 40
olesen has a spectacular aura aboutolesen has a spectacular aura about
Now added information in https://develop.openfoam.com/Develop...terns/registry
Yann and dlahaye like this.
olesen is offline   Reply With Quote

Old   July 28, 2023, 04:47
Default
  #12
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 741
Blog Entries: 1
Rep Power: 17
dlahaye is on a distinguished road
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.
dlahaye is offline   Reply With Quote

Reply

Tags
multisolver, openfoam, scalartransportfoam, simplefoam, solver


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
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


All times are GMT -4. The time now is 10:59.