User subroutine for Dirichlet BC

Questions and remarks about code_saturne usage
Forum rules
Please read the forum usage recommendations before posting.
Post Reply
bajsi
Posts: 15
Joined: Wed Jul 18, 2012 12:51 pm

User subroutine for Dirichlet BC

Post by bajsi »

Hi,
I am using CS 3.3.2 and Salome-Meca 2014.2 as pre/post-processor.

I want to apply constant pressure to inlet / outlet.
I copied cs_user_boundary_conditions.f90 to /SCR and naively modified it to apply a pressure of 4 bar to inlet and 1 bar to outlet.
There is probably some very noob-like error in the code - file is attached.

My variables start at line 440 and code at 472.

Any help is greatly appreciated.
Attachments
cs_user_boundary_conditions.f90
(20.85 KiB) Downloaded 230 times
Alexandra MartinS
Posts: 3
Joined: Thu Jan 09, 2014 2:41 pm

Re: User subroutine for Dirichlet BC

Post by Alexandra MartinS »

Hello,

I've had a look at your file. Haven't you forgotten to set the value of the local variable

Code: Select all

nphas
? You have a loop with it as upper limit, but you never initialise this variable, so I don't think this loop is properly performed.

Nevertheless, what is the error you get?

Regards,

Alexandra
Yvan Fournier
Posts: 4085
Joined: Mon Feb 20, 2012 3:25 pm

Re: User subroutine for Dirichlet BC

Post by Yvan Fournier »

Hello,

There are multiple problems with what you are trying to do :

- when you post, please also provide the error message you obtain (here, I can guess, but it is not always so easy)

- where did you get the code you "inserted" from ? iphas and nphas do not exist anymore since Code_Saturne 3.0, so I assume you took an example from version 2.0. Just remove (iphas) in expressions and remove the loop in iphas and things will be better.

- If you have a single inlet and outlet, you cannot apply a pressure both to inlet and outlet with an incompressible model. This might work if you active the compressible model, but with the main incompressible model, this leads to an overconstrained problem.

- Last, for such simple boundary conditions, why do you not use the GUI ? (you can mix the GUI with user subroutines for specific parts of the setup) ? I ask that because most of the people who do not use the GUI do so out of habit (in which case they are not beginners, and do not need much help), or because someone recommended them not to use it. In that case, those who give those recommendations should do the support themselves...

Regards,

Yvan
bajsi
Posts: 15
Joined: Wed Jul 18, 2012 12:51 pm

Re: User subroutine for Dirichlet BC

Post by bajsi »

Hi,

- I wont forget to post the error message next time.

- I think applying the pressure on both inlet and outlet (both single) should be OK, as I am trying to calculate mass flow at imposed pressure differential (I do not think the model is over-constrained). But until I get the model right I will try to define pressure condition on inlet only.

- I am using GUI - as far as I know it is not possible to assign Dirichlet condition with GUI. Supposedly a script in /SRC ought to override and GUI settings?

- The code I copied from is indeed from version 2, that I found in an 2009 post on this forum. I removed the loop with iphas and it compiles and links OK. Simulation runs without errors, but the Dirichlet definition is not used - the BC set in GUI (velocity on inlet) is used instead.

I attached is the compile.log and corrected cs_user_boundary_conditions.f90 file.

Best regards,
Niko
Attachments
cs_user_boundary_conditions.f90
(20.82 KiB) Downloaded 229 times
compile.log
(3.82 KiB) Downloaded 216 times
Yvan Fournier
Posts: 4085
Joined: Mon Feb 20, 2012 3:25 pm

Re: User subroutine for Dirichlet BC

Post by Yvan Fournier »

Hello,

Yes, the GUI only allows you to apply a pressure BC when using the compressible model.

You can mix GUI and SRC/cs_use_boundary_conditions.f90, but you did not initialize ivar
in your code, so the Dirichlet may apply to a random value.

Add ivar = ipr in your code, and things should be better.

If you want to compute mass flow at an imposed pressure difference, and your flow reaches a steady state, a safer (but more complicated) way of forcing the differential is to "measure" the pressure at the inlet and outlet, and use a velocity source term (or adjust a Dirichlet BC) so as to converge towards the correct pressure differential. If your computation works with Dirichlet pressure BC's, fine, but if it crashes, then you need to move to that approach. There are probably examples on the Forum, but you can also check the examples in your case's EXAMPLES/cs_user_source_terms* files (you may need to adapt them, as they are designed for a fixed rate of flow, not a fixed pressure).

Regards,

Yvan
bajsi
Posts: 15
Joined: Wed Jul 18, 2012 12:51 pm

Re: User subroutine for Dirichlet BC

Post by bajsi »

Hi,

the problem has been solved.
I am just posting corrected cs_user_boundary_conditions.f90 if someone finds it useful.
Attachments
cs_user_boundary_conditions.f90
(20.56 KiB) Downloaded 248 times
Post Reply