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

OpenFOAM: Adding a transient pressure gradient to a solver

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 28, 2016, 16:24
Default OpenFOAM: Adding a transient pressure gradient to a solver
  #1
New Member
 
Join Date: Apr 2012
Posts: 9
Rep Power: 14
dsh5400 is on a distinguished road
I am trying to add a pressure gradient, that changes with time, to a solver. I have a sinusoidal pressure gradient working, but I am having trouble ramping up the frequency. I'm new to OpenFOAM and C++, and it's pretty clear I am not calling functions properly, but I don't know how to resolve.

As a test, I want to apply the sinusoidal gradient until time = 5, then have the gradient go to zero for the remainder of the simulation. If I can get this working, I should be able to set up the actual ramping I want.

I'm mostly interested in calling the ceiling, floor, and minimum functions properly. And, I know the arguments for the minimum function are not of the same type, but don't know how to get them to match.

Thanks for any insight,
Dan

In UEqn.H:

tmp<fvVectorMatrix> UEqn
(
fvm::ddt(U)
+ fvm::div(phi, U)
+ turbulence->divDevReff(U)
==
fvOptions(U)
+dpdx*cos(Freq*runTime.time().value())
*ceil((t0-std::min(runTime.time().value(),t0))/t0)
);


In createFields.H:

dimensionedScalar t0
(
transportProperties.lookup("t0")
);


In transportProperties:

t0 t0 [ 0 0 1 0 0 0 0 ] 5 ;

When I compile the solver, I get the following errors:

./UEqn.H:11:12: error: no matching function for call to 'min'
*ceil((t0-std::min(runTime.time().value(),t0))/t0)
^~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:2589:1: note:
candidate template ignored: deduced conflicting types for parameter '_Tp' ('double' vs.
'Foam::dimensioned<double>')
min(const _Tp& __a, const _Tp& __b)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:2599:1: note:
candidate template ignored: could not match 'initializer_list<type-parameter-0-0>' against 'double'
min(initializer_list<_Tp> __t, _Compare __comp)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:2581:1: note:
candidate function template not viable: requires 3 arguments, but 2 were provided
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:2607:1: note:
candidate function template not viable: requires single argument '__t', but 2 arguments were provided
min(initializer_list<_Tp> __t)
^
1 error generated.
make: *** [Make/darwinIntel64ClangDPOpt/pimpleFoamPulsTempRamp.o] Error 1
dsh5400 is offline   Reply With Quote

Old   January 28, 2016, 23:29
Default
  #2
New Member
 
Darrin Stephens
Join Date: Mar 2009
Posts: 25
Rep Power: 17
darrin is on a distinguished road
Hi Dan,
Your compilation problem is caused by t0 being a dimensionsedScalar. Try using t0.value() in the min function.
darrin is offline   Reply With Quote

Old   January 29, 2016, 09:32
Default
  #3
New Member
 
Join Date: Apr 2012
Posts: 9
Rep Power: 14
dsh5400 is on a distinguished road
Darrin,
Thank you for the response. I should have mentioned that I tried using t0.value() but it produced a much longer list of errors. But the first error was again a mismatched-arguments-for-min-function error:

In file included from pimpleFoamPulsTempRamp.C:77:
./UEqn.H:11:2: error: invalid operands to binary expression ('Foam::dimensioned<typename Foam::outerProduct<Vector<double>, double>::type>' and 'double')
*std::min(runTime.time().value(),t0.value())
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/Users/dshagan/OpenFOAM/OpenFOAM-2.3.1/src/OpenFOAM/lnInclude/dimensionedScalar.H:55:19: note: candidate function not viable: no known conversion from 'dimensioned<typename Foam::outerProduct<Vector<double>, double>::type>' to 'const dimensioned<scalar>' for 1st argument
dimensionedScalar operator*(const dimensionedScalar&, const scalar);


So, I simplified my UEqn to focus on the min function:

tmp<fvVectorMatrix> UEqn
(
fvm::ddt(U)
+ fvm::div(phi, U)
+ turbulence->divDevReff(U)
==
fvOptions(U)
+dpdx*cos(Freq*runTime.time().value())
*std::min(runTime.time().value(),t0.value())
// *ceil((t0-min(runTime.time().value(),t0.value()))/t0)
);


But again the arguments for the min function are "invalid operands". I have attached the compilation log. How can I make the two following types of operands compatible?
'Foam::dimensioned<typename Foam::outerProduct<Vector<double>, double>::type>'
and
'double'

And am I calling the min function properly by using "std::min"?

Any input is much appreciated. Thanks again,
Dan
Attached Files
File Type: txt log.txt (77.3 KB, 4 views)
dsh5400 is offline   Reply With Quote

Old   January 29, 2016, 17:08
Default
  #4
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 437
Rep Power: 22
marupio is on a distinguished road
The compiler is complaining that something is a type:
Code:
Foam::dimensioned<typename Foam::outerProduct<Vector<double>, double>::type>
What in the world could that be. That's where it is confused. This isn't what runTime.value() is. Well, perhaps if it resolves outerProduct.

Oh, it isn't complaining about std::min, it's complaining about your multiplication before that. What's dpdx?
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   January 29, 2016, 18:54
Default
  #5
New Member
 
Join Date: Apr 2012
Posts: 9
Rep Power: 14
dsh5400 is on a distinguished road
marupio,
Thanks for the response. The 'dpdx' term is a unit vector which defines the direction of the pressure gradient. I have the following code.

In createFields.H:

// Pressure gradient direction
dimensionedVector dpdx
(
transportProperties.lookup("dpdx")
);
// Frequency of sinusoidal pressure gradient
dimensionedScalar Freq
(
transportProperties.lookup("Freq")
);
// Time at which Freq is ramped up
dimensionedScalar t0
(
transportProperties.lookup("t0")
);


In transportProperties:

//define the pressure gradient value
dpdx dpdx [ 0 1 -2 0 0 0 0 ] ( 1 0 0 );
// Freq = 2pi/Period
// Period=30: Freq = 0.20943951
Freq Freq [ 0 0 0 0 0 0 0 ] 0.20943951;
//ramp up frequency times
t0 t0 [ 0 0 1 0 0 0 0 ] 5 ;


I also noticed that my "simplified" pressure gradient term, in Post #3, unbalances the units of the righthand side of the UEqn. But it doesn't sound like that is the problem here.

Thanks!
Dan

Last edited by dsh5400; January 30, 2016 at 10:24.
dsh5400 is offline   Reply With Quote

Old   January 31, 2016, 15:50
Default
  #6
New Member
 
Darrin Stephens
Join Date: Mar 2009
Posts: 25
Rep Power: 17
darrin is on a distinguished road
Hi Dan,
Change you code as follows

In UEqn.H

scalar minValue(min(runTime.time().value(),t0.value()));
dimensionedScalar factor(minValue*cos(Freq*runTime.time().value()));

tmp<fvVectorMatrix> UEqn
(
fvm::ddt(U)
+ fvm::div(phi, U)
+ turbulence->divDevReff(U)
==
fvOptions(U)
+ factor*dpdx
);

I believe it was the order of the multiplication that the compiler didn't like.
darrin is offline   Reply With Quote

Old   February 4, 2016, 08:32
Default
  #7
New Member
 
Join Date: Apr 2012
Posts: 9
Rep Power: 14
dsh5400 is on a distinguished road
Thank you darrin!

This gives me what I need. I will post my final code once I get everything working as it should.

Thank you!
Dan
dsh5400 is offline   Reply With Quote

Old   April 7, 2016, 15:13
Default
  #8
New Member
 
Join Date: Apr 2012
Posts: 9
Rep Power: 14
dsh5400 is on a distinguished road
I was able generate a transient pressure gradient of the form:
Pgrad.pdf
The pressure gradient is sinusoidal with a a constant period of 60 until time t0, a linearly increasing period from 60 to 30 at time tF, then a constant period of 30 after time tF. In the attached figure, t0=60 and tF=180.

To do this in OpenFOAM, I modified the UEqn.H file:

Code:
// Solve the Momentum equation
//

// First constant frequency value
scalar firstMinValue(min(runTime.time().value(),t0.value()));
scalar firstBinMin(ceil((t0.value()-firstMinValue)/t0.value()));
dimensionedScalar firstFactor(firstBinMin*cos(firstFreq*runTime.time().value()));

// Second constant frequency value
scalar secondMaxValue(max(runTime.time().value(),tF.value()));
scalar secondBinMax(ceil((secondMaxValue-tF.value())/tEnd.value()));
dimensionedScalar secondFactor(-secondBinMax*cos(secondFreq*runTime.time().value()));

// Intermediate ramping frequency value(s)
scalar rampTime((runTime.time().value()-t0.value())/(tF.value()-t0.value()));
dimensionedScalar rampFreqDiff(0.5*(secondFreq-firstFreq)); //
dimensionedScalar rampFreq(firstFreq+rampTime*rampFreqDiff);
scalar rampMaxValue(max(runTime.time().value(),t0.value()));
scalar rampMinValue(min(runTime.time().value(),tF.value()));
scalar rampBinFactor(floor(0.5*(ceil((rampMaxValue-t0.value())/tEnd.value())
                               +ceil((tF.value()-rampMinValue)/tEnd.value()))));
dimensionedScalar rampFactor(rampBinFactor*cos(rampFreq*runTime.time().value()));

// Exact frequency value at t0
scalar firstAbsTime(std::abs(runTime.time().value()-t0.value()));
scalar firstExactVal(1.0-ceil(firstAbsTime/tEnd.value()));
dimensionedScalar firstExactFactor(firstExactVal*cos(firstFreq*runTime.time().value()));

// Exact frequency value at tF
scalar secondAbsTime(std::abs(runTime.time().value()-tF.value()));
scalar secondExactVal(1.0-ceil(secondAbsTime/tEnd.value()));
dimensionedScalar secondExactFactor(-secondExactVal*cos(secondFreq*runTime.time().value()));

tmp<fvVectorMatrix> UEqn
(
    fvm::ddt(U)
  + fvm::div(phi, U)
  + turbulence->divDevReff(U)
 ==
    fvOptions(U)
  + firstFactor*dpdx
  + secondFactor*dpdx
  + rampFactor*dpdx
  + firstExactFactor*dpdx
  + secondExactFactor*dpdx
);

UEqn().relax();

fvOptions.constrain(UEqn());

volScalarField rAU(1.0/UEqn().A());

if (pimple.momentumPredictor())
{
    solve(UEqn() == -fvc::grad(p));
    fvOptions.correct(U);
}
And the following was added to the transportProperties file:
Code:
//define the pressure gradient value

dpdx            dpdx [ 0 1 -2 0 0 0 0 ] ( 1 0 0 );

// Freq = 2pi/Period
// Period=30: Freq = 0.20943951
// Period=40: Freq = 0.15707963
// Period=60: Freq = 0.104719755
firstFreq	firstFreq [ 0 0 0 0 0 0 0 ] 0.104719755;
secondFreq	secondFreq [ 0 0 0 0 0 0 0 ] 0.20943951;

//ramp up frequency times (removed units!!)
t0              t0   [ 0 0 0 0 0 0 0 ] 60;  //1 ;  //300 ;
tF              tF   [ 0 0 0 0 0 0 0 ] 180; //600; //30 ; //400 ;
tEnd            tEnd [ 0 0 0 0 0 0 0 ] 900 ;
Many thanks to darrin and everyone who provided some advice!
dsh5400 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
Rotating Reference Frame Pressure Gradient clac FLUENT 0 August 22, 2012 18:20
Rotating wall: Pressure BC in OpenFoam using rhoCentralFoam solver vinaykr OpenFOAM 0 June 27, 2011 04:11
The correction on pressure equation of SIMPLE algorithm in MRFSimpleFOAM solver renyun0511 OpenFOAM Running, Solving & CFD 0 November 10, 2010 01:47
Conjugate gradient solver for pressure. R.F. Main CFD Forum 0 November 12, 2004 11:49
pressure gradient term in low speed flow Atit Koonsrisuk Main CFD Forum 2 January 10, 2002 10:52


All times are GMT -4. The time now is 02:21.