|
[Sponsors] |
March 9, 2014, 22:17 |
Manually setting boundaryField types
|
#1 |
Member
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 12 |
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; } 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 } 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 |
|
March 10, 2014, 02:47 |
|
#2 |
Member
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 12 |
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 ); Code:
label topID = mesh_.boundaryMesh().findPatchID("top"); |
|
March 17, 2014, 02:23 |
Better solution
|
#3 |
Member
Christian Butcher
Join Date: Jul 2013
Location: Japan
Posts: 85
Rep Power: 12 |
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 ); |
|
Tags |
boundary condition |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[snappyHexMesh] determining displacement for added points | CFDnewbie147 | OpenFOAM Meshing & Mesh Conversion | 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 | Siemens | 2 | May 31, 2010 21:58 |
changing the names and types of a boundaryField | gerado | OpenFOAM Running, Solving & CFD | 0 | March 24, 2009 08:55 |
Warning 097- | AB | Siemens | 6 | November 15, 2004 04:41 |