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

Manually setting boundaryField types

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By chrisb2244

Reply
 
LinkBack Thread Tools Display Modes
Old   March 9, 2014, 23:17
Default Manually setting boundaryField types
  #1
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 84
Rep Power: 4
chrisb2244 is on a distinguished road
Hi,

I'm writing a class to create and recreate an alpha1 field.
It's (sort of, at least) working for internal cells, but the boundary fields are a bit of a problem.

Currently, I have:
Code:
Foam::volScalarField Foam::regenerateAlphaClass::regenerateAlpha()
{
	if (1) Pout<< "Calling regenerateAlphaClass::regenerateAlpha()" << endl;
	// Going to set values of the data points in a constructor.
	// A separate function can calculate the expected heights.
	// This only (?) needs to work out which cells should be given which values,
	// and write an alpha1 file.
	
	volScalarField alpha1
	(
		IOobject
		(
			"alpha1",
			mesh_.time().timeName(),
			mesh_,
			IOobject::NO_READ,
			IOobject::AUTO_WRITE,
			true // registery
		),
		mesh_,
		dimensionedScalar
		(
			"alpha1",
			dimensionSet(0, 0, 0, 0, 0, 0, 0),
			0.0
		)
	);

	double yMid;
	yMid = 0.6; // set this using the dictionary? Or some sort of IO operation.
	double yHeight = yMid;
	forAll(mesh_.cellCentres(), i)
	{
		double cellHeight = sqrt(mesh_.cellVolumes()[i] / cellDepth_);
		//~ Pout<< "cellHeight = " << cellHeight << endl;
		yHeight = yMid;
		Foam::vector position(mesh_.cellCentres()[i]);
		for (unsigned int k=0; k < cosineVector.size(); k++)
		{
			yHeight += cosineVector[k](position[0]);
		}
		double deltaY = yHeight - position[1];
		if (deltaY < -cellHeight)
		{
			alpha1.internalField()[i] = 1.0;
		}
		else if (deltaY > cellHeight)
		{
			alpha1.internalField()[i] = 0.0;
		}
		else
		{
			double value_Alpha = (0.5+(-0.5 * (deltaY/cellHeight)));
			alpha1.internalField()[i] = value_Alpha;
		}
	}
	forAll(alpha1.boundaryField()[0], faceI)//side left?
	{
		alpha1.boundaryField()[0][faceI] = alpha1.internalField()[mesh_.owner()[faceI]];
	}
	forAll(alpha1.boundaryField()[1], faceI)//side right
	{
		Pout<< "Right: intField = " << alpha1.internalField()[mesh_.owner()[faceI]] << endl;
		alpha1.boundaryField()[1][faceI] = alpha1.internalField()[mesh_.owner()[faceI]];
	}
	forAll(alpha1.boundaryField()[2], faceI) //bottom
	{
		alpha1.boundaryField()[2][faceI] = 0;
	}
	forAll(alpha1.boundaryField()[3], faceI)//top
	{
		alpha1.boundaryField()[3][faceI] = 1;
	}
	
	
	forAll(alpha1.boundaryField(), i)
	{
		Pout<< "name of bF()[i]? (types) = " << alpha1.boundaryField().types() << endl;
		Pout<< "boundaryField()[i] = " << alpha1.boundaryField()[i] << endl;
		
	}
	return alpha1;
}
The internal cells, like I said, are being given values which (at least to first glance) seem sensible, but the boundary cells are being set to 0 for the alpha1.internalField() calls (even though in the top half, they should be =1, etc).

Firstly, can I change this from setting boundaryField()[0, 1, 2, 3] to something like boundaryField()[name of patch?] or alternatively
Code:
forAll(alpha1.boundaryField(), fieldI)
{
    if (alpha1.boundaryField()[fieldI].name() == top)
    // set to top conditions, etc
}
The patchIdentifier class looks like it might be helpful for that, but looking at the Doxygen information I can't see how I would construct a meaningful patchIdentifier object (and assuming I therefore need already existing patchIdentifier objects, I can't work out how to get references to them).

My second problem relates to the values of internalField being set to 0 in the boundaryField section, but I expect this might be related to a mislabelling of faceI? If someone could confirm this, that'd be great!

A much preferable solution would be if I could find the patch (by name?) and then set it's condition (currently all to calculated) to, for example, zeroGradient, or fixedValue (0), or whatever.

Any help would be much appreciated,

Christian
chrisb2244 is offline   Reply With Quote

Old   March 10, 2014, 03:47
Default
  #2
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 84
Rep Power: 4
chrisb2244 is on a distinguished road
Simple solution (at least for all one type of boundary except the one set to empty)

use:
Code:
volScalarField alpha1
	(
		IOobject
		(
			"alpha1",
			mesh_.time().timeName(),
			mesh_,
			IOobject::NO_READ,
			IOobject::AUTO_WRITE,
			true // registery
		),
		mesh_,
		dimensionedScalar
		(
			"alpha1",
			dimensionSet(0, 0, 0, 0, 0, 0, 0),
			0.0
		),
		zeroGradientFvPatchField<scalar>::typeName
	);
To find the patches more reliably (independent of order of input now) (although I don't need this anymore)
Code:
label topID = mesh_.boundaryMesh().findPatchID("top");
etc.
sharonyue likes this.
chrisb2244 is offline   Reply With Quote

Old   March 17, 2014, 03:23
Default Better solution
  #3
Member
 
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 84
Rep Power: 4
chrisb2244 is on a distinguished road
Derp - the doxygen information also lists a constructor with a wordList for 'wantedTypes'

Constructor can be written something like:

Code:
        wordList wantedTypes;
	wantedTypes.append(cyclicPolyPatch::typeName);
	wantedTypes.append(cyclicPolyPatch::typeName);
	wantedTypes.append(zeroGradientFvPatchField<scalar>::typeName);
	wantedTypes.append(zeroGradientFvPatchField<scalar>::typeName);
	wantedTypes.append(emptyPolyPatch::typeName);
	
	volScalarField alpha1
	(
		IOobject
		(
			"alpha1",
			mesh_.time().timeName(),
			mesh_,
			IOobject::NO_READ,
			IOobject::AUTO_WRITE,
			true // registery
		),
		mesh_,
		dimensionedScalar
		(
			"alpha1",
			dimensionSet(0, 0, 0, 0, 0, 0, 0),
			0.0
		),
		wantedTypes
	);
chrisb2244 is offline   Reply With Quote

Reply

Tags
boundary condition

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
determining displacement for added points CFDnewbie147 OpenFOAM Native Meshers: snappyHexMesh and Others 1 October 22, 2013 09:53
Setting boundaryField for a volScalarField Hisham OpenFOAM Programming & Development 5 October 25, 2011 08:54
Cells with t below lower limit Purushothama CD-adapco 2 May 31, 2010 21:58
changing the names and types of a boundaryField gerado OpenFOAM Running, Solving & CFD 0 March 24, 2009 09:55
Warning 097- AB CD-adapco 6 November 15, 2004 05:41


All times are GMT -4. The time now is 00:40.