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

How to impose a boundary condition inside a solver

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By ssss
  • 1 Post By Democritus

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 20, 2016, 03:51
Default How to impose a boundary condition inside a solver
  #1
New Member
 
Democritus's Avatar
 
Xiaoqiu HE
Join Date: Mar 2016
Location: Wuhan, China
Posts: 29
Rep Power: 10
Democritus is on a distinguished road
Hi Dear Foamers~!
I am trying to test a program by prescribing the dirichlet BCs and source terms which are all calculated from the prescribed exact solution:
Code:
fvScalarMatrix p1SinEquation
(
    fvm::Sp(1, p1) + fvc::div(v)
); // v is already known
solve( p1SinEquation == p1SourceTerm )

//impose the source term
p1SourceTerm = p1_Exact + fvc::div(v);
//impose the BC
const fvBoundaryMesh & meshBoundary = mesh.boundary();
  forAll( meshBoundary, fvPatchID )
  {
    const fvPatch & instantPatch = meshBoundary[ fvPatchID ];
    forAll( instantPatch, elmtID )
    {
      p1.boundaryField()[fvPatchID][elmtID]  
      = 
      p1_Exact.boundaryField()[fvPatchID][elmtID];
    }
  }
By this way I succecced in imposing the BC and source term, but after the calculation, the field p1's boundary value changes, which means that the fixed Dirichlet boundary conditions shifted. How to make it fixed firmly during all the program runtime?

I am open for all advices and thanks in advance!
Democritus is offline   Reply With Quote

Old   April 20, 2016, 05:43
Default
  #2
Senior Member
 
anonymous
Join Date: Aug 2014
Posts: 205
Rep Power: 13
ssss is on a distinguished road
You could create a variable inside the solver and create a custom boundary conditions using swak4foam or codexFixed custom BC
Democritus likes this.
ssss is offline   Reply With Quote

Old   April 20, 2016, 07:10
Default Thank you for your reply!
  #3
New Member
 
Democritus's Avatar
 
Xiaoqiu HE
Join Date: Mar 2016
Location: Wuhan, China
Posts: 29
Rep Power: 10
Democritus is on a distinguished road
Quote:
Originally Posted by ssss View Post
You could create a variable inside the solver and create a custom boundary conditions using swak4foam or codexFixed custom BC
Thank you! I am trying my best to implement a new BC on the base of fixed value BC.
Democritus is offline   Reply With Quote

Old   April 20, 2016, 10:47
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Use swak4Foam and live gets so easy
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   April 27, 2016, 01:53
Default
  #5
Member
 
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10
Zhiheng Wang is on a distinguished road
Hi Tobi,
I am facing problem to write grrovy BC while the Boundary Condition is coupled/mapped of 0/T and 0/U , can I write a coupled or mapped boundary I have tried by Code stream but it was a disaster.
U=(diff*(gradYi)/(1-Yi))
and

gradT= rho*U*Hf/kappa Can i write this with groovy BC for inlet ???
Zhiheng Wang is offline   Reply With Quote

Old   April 27, 2016, 04:29
Default
  #6
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Yes you can use values from other patches and also map stuff.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   April 28, 2016, 01:35
Default
  #7
Member
 
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10
Zhiheng Wang is on a distinguished road
Quote:
Originally Posted by Tobi View Post
Yes you can use values from other patches and also map stuff.
How to use map conditions ???? With groovy BC. I have no Idea about it.
Zhiheng Wang is offline   Reply With Quote

Old   May 9, 2016, 04:59
Default
  #8
New Member
 
Democritus's Avatar
 
Xiaoqiu HE
Join Date: Mar 2016
Location: Wuhan, China
Posts: 29
Rep Power: 10
Democritus is on a distinguished road
Hi Dear Foamers~

Here I want to share my solution about this issue. I only use OpenFOAM in order to impose a BC. The field I want to deal is pS, pC, vS, vC.

First I implemented codes for imposing the BC
Code:
    const fvBoundaryMesh & thisBoundary = mesh.boundary(); //here I get the boundary of the mesh
    forAll( thisBoundary, fvPatchID ) // go through all the patchs of the boundary
    {
      const fvPatch & thisPatch = thisBoundary[ fvPatchID ];
      Info << "\n Imposing the boundary condition on the fvPatch of " <<
      thisPatch.name() << endl;

      const vectorField & position = thisPatch.Cf(); // get the cell face centers' positions
      forAll( thisPatch, elmtID ) // imposing values on the centers of all the cell faces of this patch   
      {
        const scalar & x = position[elmtID].component(0);
        const scalar & y = position[elmtID].component(1);

        //you can replace your function on the right side of the =
        pS.boundaryField()[fvPatchID][elmtID] = -1 * Foam::exp(-1 * x) * Foam::cos( x );
        pC.boundaryField()[fvPatchID][elmtID] = Foam::exp(-1 * x) * Foam::sin( x );

        vS.boundaryField()[fvPatchID][elmtID].component(0) = -1 * Foam::exp(-1 * x) * Foam::cos( x );
        vS.boundaryField()[fvPatchID][elmtID].component(1) = 2 * Foam::cos( x ) * Foam::sin( y ) ;

        vC.boundaryField()[fvPatchID][elmtID].component(0) = Foam::exp(-1 * x) * Foam::sin( x );
        vC.boundaryField()[fvPatchID][elmtID].component(1) = Foam::sin( x ) * Foam::cos( y );

      }

    }
Then I writed these fileds into files. In the files I changed the BC type from "calculated" to "fixedValue". Then I copy these files into the cases that I want to use it.

As old saying in China goes, "抛砖引玉", which means "showing a brick on the market in order to motivate others to show sapphire on the market", here I post my solution for dear foamers' reference and I am always open for any advice of improvement.
Thanks!
mostafa kareem likes this.
Democritus is offline   Reply With Quote

Reply

Tags
boudary condition, dirichlet


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
fluent divergence for no reason sufjanst FLUENT 2 March 23, 2016 17:08
Basic Nozzle-Expander Design karmavatar CFX 20 March 20, 2016 09:44
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 07:28
An error has occurred in cfx5solve: volo87 CFX 5 June 14, 2013 18:44
meshing F1 front wing Steve FLUENT 0 April 17, 2003 13:37


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