
[Sponsors] 
verification of a new BC whit codedfixedValue 

LinkBack  Thread Tools  Search this Thread  Display Modes 
June 4, 2020, 06:46 
help for new BC with codedfixedValue

#1 
Member
Join Date: Mar 2020
Posts: 66
Rep Power: 5 
Hi at all,
I created a newBC on the outlet for the pressure using codedfixedvalue. How can i import the flow rate at time 0 of the outlet as the initial value in my new code (Q_0)? code #{ const scalar &t = this >db().time().value(); // time reading const surfaceScalarField& phi = db().lookupObject<surfaceScalarField>("phi"); //flowrate reading in the outlet const fvsPatchField<scalar>& phip=patch().patchField<surfaceScalarField,scalar> (phi); const scalar &dt = this >db().time().deltaTValue(); //delta t reading for integration const scalar C = 4.82e9; //m4*s2/kg const scalar Rp= 2.79245; // kg*s/m4 const scalar Rd= 1.7; //kg/s*m4 const scalar p_0=1.07; //pressure t=0 m2/s2 const scalar Q_0=0; //flow rate t=0 m3/s const scalar e(M_E); //nepero number operator==(Rp*gSum(phip)+(p_0+Rp*Q_0)*(pow(e,(t/(Rd*C))))+((1/C)*(gSum(pow(e,(t(t/(Rd*C))))*(phip)))*dt)); #}; thanks!! Last edited by Neb; June 4, 2020 at 12:56. 

June 4, 2020, 14:25 
Some comments

#2  
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 8 
Hi Neb,
Some things to consider:
Quote:
Code:
const dimensionedScalar C (dimensionSet(1, 4, 2, 0, 0, 0, 0), 4.82e9); const dimensionedScalar Rp (dimensionSet(1, 4, 1, 0, 0, 0, 0), 2.79245); const dimensionedScalar Rd (dimensionSet(1, 4, 1, 0, 0, 0, 0), 1.7);


June 5, 2020, 04:57 

#3 
Member
Join Date: Mar 2020
Posts: 66
Rep Power: 5 
Thanks for your answer, you have been very helpful!!
Unfortunately I recently started with OpenFoam and I am in difficulty. I don't even know the language used.. I figured there were these problems on the integral and the flow rate calculation in the outlet.
I can't understand what I have to do here. If I leave gSum (phip) does it not calculate the sum of the flow rate on my patch (outlet) at each instant of calculation? I am sorry for this question that may seem simple, but I searched a lot and found nothing that could clarify my ideas. Do I have to do a cycle for every t? 

June 5, 2020, 07:01 
A solution for uniform application

#4 
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 8 
Ok, I think I know what are you trying. I was thinking that you want that each of the faces conforming the patch has a different value, but maybe want you wanted is to have a uniform pressure on all the patch, right?
In that case you almost got it in the first place, I think you just needed to reconsider the integral part. I was thinking about how to deal with this term and I think it is in fact quite easy to handle. Using the exponential property you can split the weigth term inside the integral into:. Now the second part is not dependent on the integrand variable so you can put outside the integral. With this approach, what is it inside the integral is not dependent on the integral limits so you can track the sum in an external variable and update. The resultant code is: Code:
#{ const scalar t = this>db().time().value(); // time reading const surfaceScalarField& phi = db().lookupObject<surfaceScalarField>("phi"); //flowrate reading in the outlet const fvsPatchField<scalar>& phip=patch().patchField<surfaceScalarField,scalar> (phi); const scalar dt = this >db().time().deltaTValue(); //delta t reading for integration const scalar C (4.82e9); const scalar Rp (2.79245); const scalar Rd (1.7); const scalar p_0 (1.07); const scalar Q_0 (0); const scalar e(M_E); //nepero number static scalar integrand(0); integrand += pow(e,t/(Rd*C))*gSum(phip)*dt; operator==( Rp*gSum(phip) + pow(e,t/(Rd*C))* ((p_0Rp*Q_0) + (1/C)*integrand) ); #}; PD: You may want to double check the constants. The actual value of C is of the order and Rp is of order 1, so the factor multiply the exponential is really small. I don't know where do you want to apply this formula, but to match these values you're need operation times on the order of 100 ns. Once you do times higher than those there is no point in having to take into account the integrand part, in any practical effect the value if the integral is just the value of the last instant. Moreover, the approach of split the exponential term will blow the simulation will be inmense. 

June 5, 2020, 08:42 

#5 
Member
Join Date: Mar 2020
Posts: 66
Rep Power: 5 
Thanks!! This is of great help to me!
Yes, that is whant I want to do. I have to calibrate the constants better, so they are not correct. C is probably too small. I entered the code in my calculation but returns the following error: "invalid operands of types 'void' and 'Foam::scalar{aka double}' to binary 'operator' 

June 5, 2020, 09:08 

#6  
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 8 
Quote:
You can try some alternative way to set the field. For example using this instead of the operator==( ... ) Code:
vectorField& field = *this; forAll(field, facei) { field[facei] = (Rp*gSum(phip) + pow(e,t/(Rd*C))* ((p_0Rp*Q_0) + (1/C)*integrand)) } 

June 5, 2020, 10:19 

#7 
Member
Join Date: Mar 2020
Posts: 66
Rep Power: 5 
I found my mistake. Simply a parenthesis problem after operator.
Now everything works! Thank you very much for your help, you have been very kind! One last question: could you recommend any material to study to learn this programming? 

June 5, 2020, 11:58 

#8  
Senior Member
Carlos Rubio Abujas
Join Date: Jan 2018
Location: Spain
Posts: 127
Rep Power: 8 
Glad to know it worked!
Quote:
You can check the following link to some tutorials to learn how to program in OF. OpenFOAM programming tutorials for beginners You can download it and play around. The tutorials are well documented and you can play around with them. It may be convenient to have a good comprehension of C++, and learn how to consult doxygent to understand how the different objects are made. You can have some grasp about C++ in this link: http://www.cplusplus.com/doc/tutorial/ You may not know what is doxygen. It is a webbased reference of all the classes and funcitions that constitute OpenFoam. You can create a local version of your own but you can also check the online version: https://cpp.openfoam.org/v7/ It may be a little be intimidating at first, with all the templates, pointers, clasess and abstract concepts, but do not despair. I would start trying to apply some solution with the tutorial and in parallel checking some manual of C++. Checking from time to time something in doxygen to get use to it. Good luck! 

June 5, 2020, 12:02 

#9 
Member
Join Date: Mar 2020
Posts: 66
Rep Power: 5 
Thanks! It will certainly be fun!
Have a nice day 

Tags 
codedfixedvalue, integral computing, new bc 
Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
including parameter file in codedFixedValue  Loekatoni  OpenFOAM Running, Solving & CFD  4  November 9, 2023 17:56 
Why does the result not the same as the verification manuals?  Heqian Zhao  FLUENT  1  April 20, 2020 16:29 
codedFixedValue: accessing other patch causes crash in parallel  RLS  OpenFOAM Running, Solving & CFD  2  December 24, 2019 22:20 
Problem to run simpleFoam using qsub?  be_inspired  OpenFOAM  1  December 22, 2015 13:53 
Using codedFixedvalue to apply totalPressure Boundary Condition  cdm  OpenFOAM Running, Solving & CFD  2  June 22, 2013 15:10 