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

Compact BC using patchInternalField

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 21, 2021, 17:37
Default Compact BC using patchInternalField
  #1
New Member
 
Giovanni Luddeni
Join Date: Jan 2021
Posts: 14
Rep Power: 5
gionni is on a distinguished road
Hi,
developing a set of BC for a plasma simulation (2 fluids model with drift-diffusion) I'm wasting quite a lot of time defining all the fields and constants for each test and I'm looking for a way to speed up the process, if possible.

I'm using the codedMixed type (openfoam 6), since in general I have to implement Robin BC. Here an example of a simple and working one.

Code:
ns	{
code 
#{
// CONST LOOKUP
	const scalar& pi = constant::mathematical::pi;
	const dictionary& physicalProperties =
							db().lookupObject<IOdictionary>("physicalProperties");
		scalar& Kb = dimensionedScalar(physicalProperties.lookup("Kb")).value();
		scalar& M_ion = dimensionedScalar(physicalProperties.lookup("M_ion")).value();
		scalar& T0 = dimensionedScalar(physicalProperties.lookup("T0")).value();
		
		// FILEDS LOOKUP
	const volScalarField& Ds_ = db().lookupObject<volScalarField>("Ds");
	const volScalarField& ns_ = db().lookupObject<volScalarField>("ns");
		
		// DECLARATIONS
	scalarField gradField = scalarField(patch().size());
	scalar v_th, ns, Ds;
		// LOOP
	const labelUList& cell = patch().faceCells();
	forAll(cell, faceID){
			v_th = sqrt(8/pi*Kb*T0/M_ion);
			ns = ns_[cell[faceID]];
			Ds = Ds_[cell[faceID]];
			gradField[faceID] = -0.5*v_th*ns/Ds;
	}
	
	refGrad() = (gradField);		
#};	
}
In this case I have a Neumann BC implementing diffusion flux only.
I usually divide the code in this way:
- lookup of constants,
- lookup of fields,
- definition of in-loop variables and loop on all faces.

What I'm trying to understand is if it is possible to avoid the loop, looking up directly the internal fields next to the boundary patch and performing the calculations field-wise.
I was looking into the function patchInternalField from the fvPatch reference, which states: Return given internal field next to patch as patch field..
This seems exactly what I need, but I can't find any example and I find challenging to understand from the reference how to implement it.
Any idea? Does this whole thing make sense or should I give up and stick to the loops?
I accept any suggestion!
gionni is offline   Reply With Quote

Reply

Tags
codedboundarycondition, codedmixed


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
How to make a compact heatsink model in FloTHERM XT? hank0301 FloEFD, FloWorks & FloTHERM 2 April 16, 2017 18:26
Compact finite difference arunsmec Main CFD Forum 5 August 18, 2013 05:20
Bug in patchInternalField() psosnows OpenFOAM Bugs 5 October 12, 2011 04:22
Compact finite difference schemes Tom Clay Main CFD Forum 4 November 28, 2002 08:59
COMPACT CFD users? Robert Kim Main CFD Forum 1 January 13, 1999 12:20


All times are GMT -4. The time now is 18:47.