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

Creating magnetocaloric solver from buoyantPimpleFoam

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By SHUBHAM9595

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 1, 2022, 12:13
Default Creating magnetocaloric solver from buoyantPimpleFoam
  #1
New Member
 
Join Date: Sep 2020
Location: Germany
Posts: 17
Rep Power: 6
CharIie is on a distinguished road
I am trying to create a solver for ferrofluids under the influence of a static magnetic field from buoyantPimpleFoam. I want to add another source term, the Kelvin Body force, to the momentum equation. In my case the Kelvin Body Force defines as:
KBF = \mu_0 M \nabla H with M=H(T_{Curie} - T)
If the current temperature of the fluid is closer to its curie temperature the KBF gets smaller. In green you see where I want to add the term.
I managed to add H and T_Curie in createFields.H.
But my question is how do I depict the current temperature in the momentum equation to calculate the Magnetization M each time step?

It does not work like this:
Code:
tmp<fvVectorMatrix> tUEqn
    (
        fvm::ddt(rho, U) + fvm::div(phi, U)
      + MRF.DDt(rho, U)
      + turbulence->divDevTau(U)
     + Foam::constant::electromagnetic::mu0*grad(H)*H*(Tc - T);
     ==
        fvOptions(rho, U)
I have read How to add a body force to a momentum equation but in my case my source changes over time according to the temperature.
CharIie is offline   Reply With Quote

Old   April 4, 2022, 12:44
Default
  #2
Member
 
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9
SHUBHAM9595 is on a distinguished road
Hi CharIie,

You are almost there. Just two comments that might help you

1) The expression for Magnetization
Quote:
M = H (T_{Curie} - T)
seems incorrect...

As you already know both M & H have dimensions of Amp/meter....However with the above expression the RHS will have dimesnsions of A.Kelvin/meter



2) Regarding the implementation, the only thing you need to worry about is the product of \nabla H with M (or eventually H).....as

\nabla H is a tensor of rank 2 (9 components)

whereas M or H is a tensor of rank 1 (3 components )

and the UEqn in which u wish to enter this source term is also a tensor of rank 1 (3 components)....Hence, the product of M \nabla H should be an inner product....which is implemented in the FOAM's love language as shown below

Code:
volTensorField gradHH = fvc::grad(H);
volVectorField KBF = Foam::constant::electromagnetic::mu0*(M & gradHH);
CharIie likes this.
SHUBHAM9595 is offline   Reply With Quote

Old   April 7, 2022, 07:29
Default
  #3
New Member
 
Join Date: Sep 2020
Location: Germany
Posts: 17
Rep Power: 6
CharIie is on a distinguished road
Thank you SHUBHAM for the answer.
The solver finally compiles when I use the inner product as you showed.
(For the moment I replaced M with H.)

But now I am trying to depict M as: M_0 \frac{T_{Curie}} {T_i}
This cancels out the Kelvin units and M_0 is the initial magnetization.


Code:
volVectorField M = Mo*(Tc/T);
This also does not work. I think I am messing around with Vectors, tensors and scalars again.


This is the error message I get when compiling:

Code:
UEqn.H: In function ‘int main(int, char**)’:
UEqn.H:13:25: error: no match for ‘operator/’ (operand types are ‘Foam::dimensioned<double>’ and ‘<unresolved overloaded function type>’)
   13 | volVectorField M = Mo*(Tc/T);
      |                     ~~~~~^~

Last edited by CharIie; April 7, 2022 at 11:17.
CharIie is offline   Reply With Quote

Old   April 7, 2022, 16:51
Default
  #4
Member
 
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9
SHUBHAM9595 is on a distinguished road
Indeed it is because of the different declarations of T, M,\&   M_{o}....

I assume u r providing both T_{c} and M_{o} as constant parameters.....as shown below
Code:
     // Curie Temp
    dimensionedScalar    Tc(transportProperties.lookup("Tc"));
      //Equilibrium Magnetization
    dimensionedScalar    Mo(transportProperties.lookup("Mo"));
So, now if u see....as per ur code
Code:
volVectorField M = Mo*(Tc/T);
on LHS M_{o} is volVectorField however on RHS all of them are either dimensionedScalar (M_{o}, T_{c}) or volScalarField (T)

One of the many workarounds is you create volVectorField Mnot using the dimensionedScalar M_{o}

Code:
volVectorField Mnot
( 
	IOobject 
      ( 
	       "Mnot", 
	        runTime.timeName(), 
		mesh, 
		IOobject::NO_READ, 
		IOobject::AUTO_WRITE 
	), 
	mesh, 
dimensionedVector("vU", dimensionSet(0,-1,0,0,0,1,0),vector(Mo.value(), Mo.value(), Mo.value()))
);
Finally,
Code:
volVectorField M = Mnot*(Tc/T);
should do the job...
SHUBHAM9595 is offline   Reply With Quote

Old   April 8, 2022, 06:38
Default
  #5
New Member
 
Join Date: Sep 2020
Location: Germany
Posts: 17
Rep Power: 6
CharIie is on a distinguished road
Thank you again!
I have added Tc and Mo in createFileds.H like this: ( i will later a file with the magnetic properties to constant folder)
Code:
 
Info<< "Reading magnetic properties\n" << endl;
IOdictionary magneticProperties
(
    IOobject
    (
        "magneticProperties",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ_IF_MODIFIED,
        IOobject::NO_WRITE
    )
);

dimensionedScalar Mo ( "Mo",    magneticProperties.lookup("Mo"));
dimensionedScalar Tc ( "Tc",    magneticProperties.lookup("Tc"));

volVectorField Mnot
( 
    IOobject 
      ( 
           "Mnot", 
            runTime.timeName(), 
        mesh, 
        IOobject::NO_READ, 
        IOobject::AUTO_WRITE 
    ), 
    mesh, 
dimensionedVector("Mnot", dimensionSet(0,-1,0,0,0,1,0),vector(Mo.value(), Mo.value(), Mo.value()))
 );
(I have changed "vU" to "Mnot" from your example.)
and my UEqn.H looks like this now:
Code:
// Curie Temp
    dimensionedScalar    Tc(magneticProperties.lookup("Tc"));
//Equilibrium Magnetization
    dimensionedScalar    Mo(magneticProperties.lookup("Mo"));


volTensorField gradHH = fvc::grad(H);
volVectorField M = Mnot*(Tc/T);
volVectorField KBF = Foam::constant::electromagnetic::mu0*(M & gradHH);


    tmp<fvVectorMatrix> tUEqn
    (
        fvm::ddt(rho, U) + fvm::div(phi, U)
      + MRF.DDt(rho, U)
      + turbulence->divDevTau(U)
     + KBF
     
     ==
        fvOptions(rho, U)
        
     );
But still I get this error message:
Code:
 In file included from fhdFoam.C:157:
UEqn.H: In function ‘int main(int, char**)’:
UEqn.H:17:28: error: no match for ‘operator/’ (operand types are ‘Foam::dimensionedScalar’ {aka ‘Foam::dimensioned<double>’} and ‘<unresolved overloaded function type>’)
       17 | volVectorField M = Mnot*(Tc/T);
          |                          ~~^~
I also tried to add Tnot as volScalarField in similar way to Mnot, but it also results in the same error. A vector multiplied with a scalar should stay a vector. I don't understand where this error is still coming from.
CharIie is offline   Reply With Quote

Old   April 9, 2022, 10:21
Default
  #6
Member
 
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9
SHUBHAM9595 is on a distinguished road
are you sure you didn't forgot to declare the Temperature field ?

Code:
UEqn.H:17:28: error: no match for ‘operator/’ .....and <unresolved overloaded function type>’)
SHUBHAM9595 is offline   Reply With Quote

Old   April 9, 2022, 10:30
Default
  #7
New Member
 
Join Date: Sep 2020
Location: Germany
Posts: 17
Rep Power: 6
CharIie is on a distinguished road
What do you mean by declaring the temperature field? Isn't the temperature already declared onboard with buoyantPimpleFoam?
CharIie is offline   Reply With Quote

Old   April 9, 2022, 14:24
Default
  #8
Member
 
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9
SHUBHAM9595 is on a distinguished road
buoyantPimpleFoam solve either enthalpy based or internal energy based equation (EEeqn) instead of directly solving for Temperature....(https://cfd.direct/openfoam/energy-equation/#x1-70004)

You can easily check out the contents of createFields.H....(https://develop.openfoam.com/Develop...createFields.H)......

there does not exist any field variable "T"....

Last edited by SHUBHAM9595; April 9, 2022 at 16:25.
SHUBHAM9595 is offline   Reply With Quote

Old   April 10, 2022, 11:42
Default
  #9
New Member
 
Join Date: Sep 2020
Location: Germany
Posts: 17
Rep Power: 6
CharIie is on a distinguished road
Ok, this brings me back to my initial question in this thread:
Quote:
Originally Posted by CharIie View Post
But my question is how do I depict the current temperature in the momentum equation to calculate the Magnetization M each time step?
If the temperture is not directly solved, but via enthalpy based or internal energy based equation in EEeqn; how do I make use of the temperature, since a physical value for T is shown to me in Paraview?

How can I depict the current temperature in the momentum equation for simple calculations?
CharIie is offline   Reply With Quote

Old   April 12, 2022, 18:32
Default
  #10
Member
 
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9
SHUBHAM9595 is on a distinguished road
There are two approaches....assuming that you want to stick with buoyancy driven flow solvers....

1) You can switch to buoyantBoussinesqPimpleFoam which inherently solves Temperature based energy equation.

2) In the current buoyantPimpleFoam version..... comment the EEqn.H in buoyantPimpleFoam.C.....and instead add TEqn.H....more details can be found here https://openfoamwiki.net/index.php/H...ure_to_icoFoam
SHUBHAM9595 is offline   Reply With Quote

Old   April 20, 2022, 13:12
Default
  #11
New Member
 
Join Date: Sep 2020
Location: Germany
Posts: 17
Rep Power: 6
CharIie is on a distinguished road
I decided to go with approach 2 since buoyantBoussinesqPimpleFoam isnot part of my OpenFOAM V8 .

I added the TEqn.H according to https://openfoamwiki.net/index.php/H...ure_to_icoFoam, I did not comment out old the EEqn.H, since it seems to do no harm to my solver.

My solver also does compile now, but when I try to solve my test case I get the following error:
Code:
--> FOAM FATAL ERROR: 
incompatible dimensions for operation 
    [T[0 0 -1 1 0 0 0] ] + [T[1 -3 -1 1 0 0 0] ]
This error comes from the new temperature calculation in the EEqn. buoyantPimpleFoam is compressible, icoFoam incompressible. What changes could I make to get rid of the dimensions error?
CharIie is offline   Reply With Quote

Old   April 26, 2022, 10:55
Default
  #12
Member
 
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9
SHUBHAM9595 is on a distinguished road
Hi CharIie,

As you mentioned the issue seems to come from extra density....kg/m3 in one of your equations.....
Code:
--> FOAM FATAL ERROR: 
incompatible dimensions for operation 
    [T[0 0 -1 1 0 0 0] ] + [T[1 -3 -1 1 0 0 0] ]

Now, if we follow the link https://openfoamwiki.net/index.php/H...ure_to_icoFoam about adding Temp...…we don't have any term that have dimensions of kg/m3....(T = K, phi = m3/s, DT = m2/s)

So there's high probability that the error might be coming from the EEqn.H.....Have u tried any simulation without EEqn.H ?


regards,
Shubham
SHUBHAM9595 is offline   Reply With Quote

Old   April 27, 2022, 05:52
Default
  #13
New Member
 
Join Date: Sep 2020
Location: Germany
Posts: 17
Rep Power: 6
CharIie is on a distinguished road
Hi I have added TEqn like this:
Code:
            #include "UEqn.H"
            #include "EEqn.H"

            // --- Pressure corrector loop
            while (pimple.correct())
            {
                #include "pEqn.H"
            }

            if (pimple.turbCorr())
            {
                turbulence->correct();
                thermophysicalTransport->correct();
            }
        }

        rho = thermo.rho();
       //add these lines...
Info<< "Temperature calculation\n" << endl;
        fvScalarMatrix TEqn
        (
            fvm::ddt(rho,T) //added rho
            + fvm::div(phi, T)
            //- fvm::laplacian(DT, T) 
        );

        TEqn.solve();
//done adding lines...
   
        runTime.write();

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info<< "End\n" << endl;

     return 0;
In accordance with How to add temperature to cavitatingFoam solver I added rho in the temperature calculation. It works now without or together with the energy equation.

I finally get results with my solver, but the courant number is way to high:
Code:
Courant Number mean: 49.3032 max: 353.349
I need help with including the the molecular transport (- fvm::laplacian(DT, T)) or does someone have a better idea on how to better address the current temperature?

Last edited by CharIie; April 27, 2022 at 13:09.
CharIie is offline   Reply With Quote

Old   April 28, 2022, 14:31
Default
  #14
Member
 
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9
SHUBHAM9595 is on a distinguished road
Glad to know that u r not getting any error. However, you should not solve the same governing equation TWICE.....as in ur modified version u have both EEqn.H & contents of TEqn.H........

Out of curiosity, can u specify exact steps and command u r follwoing after making the changes in .C file.....I'm afraid we might be missing out some intermediate steps here
SHUBHAM9595 is offline   Reply With Quote

Old   May 2, 2022, 06:40
Default
  #15
New Member
 
Join Date: Sep 2020
Location: Germany
Posts: 17
Rep Power: 6
CharIie is on a distinguished road
Okay, here we go:
My new solver is a copy of buyantPimpleFoam saved in /OpenFOAM-8/applications/solvers/heatTransfer/fhdFoam.
So I far I have made changes to fhdFoam.C, UEqn, createFields and the make files of course.

I changed the column including the EEqn like this:
// #include "EEqn.H"
Then I type wclean and wmake in the terminal. The solver compiles.

Then I go into my test case where I have added a H field with mapFields from another solver. I delete old solved time steps greater than 0. Then I start my solver with the command fhdFoam.


Also when I only calculate the TEqn only, I get weird looking results and this courant result in the last time step:
Courant Number mean: 49.3029 max: 353.347
CharIie is offline   Reply With Quote

Old   May 16, 2022, 13:09
Default
  #16
Member
 
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9
SHUBHAM9595 is on a distinguished road
The steps look correct. Regarding the high Courant number.....have u already tried using the following options in ur controlDict ?

Code:
maxCo         1;

adjustTimeStep  true;
SHUBHAM9595 is offline   Reply With Quote

Old   May 17, 2022, 05:12
Default
  #17
New Member
 
Join Date: Sep 2020
Location: Germany
Posts: 17
Rep Power: 6
CharIie is on a distinguished road
Yes, that is what I did and gives me first results.
But computational time is 10x longer.

Do you have an idea how I can include the the molecular transport.
Now the temperature is static in my results and does not change and is not influenced by the fluid flow.
CharIie is offline   Reply With Quote

Old   June 29, 2022, 07:47
Default Final Answer
  #18
New Member
 
Join Date: Sep 2020
Location: Germany
Posts: 17
Rep Power: 6
CharIie is on a distinguished road
Quote:
Originally Posted by CharIie View Post
Ok, this brings me back to my initial question in this thread:

If the temperture is not directly solved, but via enthalpy based or internal energy based equation in EEeqn; how do I make use of the temperature, since a physical value for T is shown to me in Paraview?

How can I depict the current temperature in the momentum equation for simple calculations?
If someone might be interested some day. T can be used buoyantPimpleFoam:
Simply use:
Code:
const volScalarField& T = mesh.lookupObject<volScalarField>("T");
CharIie is offline   Reply With Quote

Reply


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
foam-extend-4.1 release hjasak OpenFOAM Announcements from Other Sources 19 July 16, 2021 06:02
Creating a solver for porous media rsdevako OpenFOAM Programming & Development 4 May 15, 2019 22:23
Unsteady solver in OpenFOAM: problems with using buoyantPimpleFoam for validation Mukul.P OpenFOAM Running, Solving & CFD 12 March 17, 2016 04:46
Working directory via command line Luiz CFX 4 March 6, 2011 21:02
Creating a new solver from chtMultiRegionFoam David_010 OpenFOAM Programming & Development 0 April 20, 2010 12:36


All times are GMT -4. The time now is 03:23.