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

problem with codedfixedValue

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 15, 2020, 14:11
Default
  #21
Senior Member
 
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 9
crubio.abujas is on a distinguished road
I'm sorry but I think we are talking about different versions of the code. What loop are you talking about? In the final version there's no loop at all! As we've been back and from with the code a lot this time maybe there could be some misunderstanding.

I've tried this version of the code and worked for me. I've added a bunch of CUSTOM: flags to have some insight of the code behavior.

Code:
    inlet
    {
        type            codedFixedValue;
        value           uniform 0;
        name            CardiacImpuse;
        code
        #{
            const scalar &t = this ->db().time().value();
            const scalar dt = this ->db().time().deltaTValue();

            const surfaceScalarField& phi = db().lookupObject<surfaceScalarField>("phi"); 
            const fvsPatchField<scalar>& phip =
                patch().patchField<surfaceScalarField,scalar> (phi);
            const fvsPatchField<scalar>& phip_last =
                patch().patchField<surfaceScalarField,scalar> (phi.oldTime());

            // Constants
            const scalar C=1.16e-05;
            const scalar R1=1.64e+03;
            const scalar R2=1.79e+05;
            const scalar p_0=7.55;
            const scalar Q_0=1.03e-4;
            const scalar T_REF=0.1;

            // Static variables
            static scalar integrand (0);
            static scalar current_time (0);

            scalar tau = std::fmod(t, T_REF);

             // Check if the timestep in new
            if (current_time < t) {

                // Update the stored timestep
                current_time = t;

                Info << "CUSTOM: current_time=" << current_time << nl
                     << "CUSTOM: dt=" << dt << nl
                     << "CUSTOM: tau=" << tau << endl;

                // Update the integrand with the previous value
                integrand += (exp(tau/(R2*C))*gSum(phip_last)*dt);
                Info << "CUSTOM: Updated integrad to " << integrand << endl;

                // Check for reset condition
                if (tau < dt) {
                    integrand = 0;
                    Info << "CUSTOM: Reseting the integrand" << endl;
                }
            }

            operator ==(R1*gSum(phip)+exp(-tau/(R2*C))*((p_0-R1*Q_0)+(1/C)*integrand));
        #};
    }
crubio.abujas is offline   Reply With Quote

Old   July 15, 2020, 15:29
Default
  #22
Neb
Member
 
Join Date: Mar 2020
Posts: 66
Rep Power: 6
Neb is on a distinguished road
Oh No, I'm sorry, my mistake, I meant in the IF, not loop!: Eek:
The simulation has now ended and it worked!!!
I still have to fix something, but finally the pressure values ​​are correct!

I don't know how to thank you, you were very kind.
Neb is offline   Reply With Quote

Old   July 17, 2020, 06:00
Default
  #23
Neb
Member
 
Join Date: Mar 2020
Posts: 66
Rep Power: 6
Neb is on a distinguished road
I am very sorry to to disturb again.

Unfortunately there is one last problem.
I checked the values, the code compiles without errors and the pressures are now correct, but it does not read the IF. So it do not apply the correction to t = 1 with integrand=0.

I have tried other order:

if (tau<dt)
{
operator ==(7.55);
integrand=0;
}
and this too:

const volScalarField & p = db (). lookupObject <volScalarField> ("p");
const fvPatchField<scalar> & pip = patch().patchField<volScalarField,scalar> (p);
fvPatchField& P_new=const_cast<fvPatchScalarField&>(pip);
if ( tau<dt)
{
forAll (P_new , facei)
{ P_new[facei]=7.55; } }

but it continues the calculation ignoring them, the final pressure always remains different from 7.55 and it's always the same value. How is it possible?
I want that at time = 1 the pressure is 7.55.

Last edited by Neb; July 17, 2020 at 10:45.
Neb is offline   Reply With Quote

Old   July 20, 2020, 18:01
Default
  #24
Neb
Member
 
Join Date: Mar 2020
Posts: 66
Rep Power: 6
Neb is on a distinguished road
I solved the code. : D: D: D

Thank you very much for all the suggestions have been very useful!
Neb 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
SU2-7.0.1 on ubuntu 18.04 hyunko SU2 Installation 7 March 16, 2020 04:37
BuoyantBoussinesqSimpleFoam_Facing problem Mondal131211 OpenFOAM Running, Solving & CFD 1 April 10, 2019 19:41
Gambit - meshing over airfoil wrapping (?) problem JFDC FLUENT 1 July 11, 2011 05:59
natural convection problem for a CHT problem Se-Hee CFX 2 June 10, 2007 06:29
Adiabatic and Rotating wall (Convection problem) ParodDav CFX 5 April 29, 2007 19:13


All times are GMT -4. The time now is 04:19.