Foam::AveragingMethods::Basic<Type>::Basic ( const IOobject& io, const dictionary& dict, const fvMesh& mesh ) : AveragingMethod<Type>(io, dict, mesh, labelList(1, mesh.nCells())), data_(FieldField<Field, Type>::operator[](0)), dataGrad_(mesh.nCells()) {}
fvFieldDecomposer::processorVolPatchFieldDecomposer:: processorVolPatchFieldDecomposer ( const fvMesh& mesh, const unallocLabelList& addressingSlice ) : sizeBeforeMapping_(mesh.nCells()), addressing_(addressingSlice.size()), weights_(addressingSlice.size()) { const scalarField& weights = mesh.weights().internalField(); const labelList& own = mesh.faceOwner(); const labelList& neighb = mesh.faceNeighbour(); forAll (addressing_, i) { // Subtract one to align addressing. HJ, 5/Dec/2001 label ai = mag(addressingSlice[i]) - 1; if (ai < neighb.size()) { // This is a regular face. it has been an internal face // of the original mesh and now it has become a face // on the parallel boundary addressing_[i].setSize(2); weights_[i].setSize(2); addressing_[i][0] = own[ai]; addressing_[i][1] = neighb[ai]; weights_[i][0] = weights[ai]; weights_[i][1] = 1.0 - weights[ai]; } else { // This is a face that used to be on a cyclic boundary // but has now become a parallel patch face. I cannot // do the interpolation properly (I would need to look // up the different (face) list of data), so I will // just grab the value from the owner cell // HJ, 16/Mar/2001 addressing_[i].setSize(1); weights_[i].setSize(1); addressing_[i][0] = own[ai]; weights_[i][0] = 1.0; } }
Foam::solidChemistryModel<CompType, SolidThermo>:: solidChemistryModel ( const fvMesh& mesh ) : CompType(mesh), ODESystem(), Ys_(this->solidThermo().composition().Y()), reactions_ ( dynamic_cast<const reactingMixture<SolidThermo>& > ( this->solidThermo() ) ), solidThermo_ ( dynamic_cast<const reactingMixture<SolidThermo>& > ( this->solidThermo() ).speciesData() ), nSolids_(Ys_.size()), nReaction_(reactions_.size()), RRs_(nSolids_), reactingCells_(mesh.nCells(), true) { // create the fields for the chemistry sources forAll(RRs_, fieldI) { RRs_.set ( fieldI, new DimensionedField<scalar, volMesh> ( IOobject ( "RRs." + Ys_[fieldI].name(), mesh.time().timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), mesh, dimensionedScalar("zero", dimMass/dimVolume/dimTime, 0.0) ) ); }
Foam::ODEChemistryModel<CompType, ThermoType>::ODEChemistryModel ( const fvMesh& mesh, const objectRegistry& obj, const word& compTypeName, const word& thermoTypeName ) : CompType(mesh, obj, thermoTypeName), ODE(), Y_(this->thermo().composition().Y()), reactions_ ( dynamic_cast<const reactingMixture<ThermoType>&>(this->thermo()) ), specieThermo_ ( dynamic_cast<const reactingMixture<ThermoType>&> (this->thermo()).speciesData() ), nSpecie_(Y_.size()), nReaction_(reactions_.size()), solver_ ( chemistrySolver<CompType, ThermoType>::New ( *this, compTypeName, thermoTypeName ) ), RR_(nSpecie_), coeffs_(nSpecie_ + 2) { // create the fields for the chemistry sources forAll(RR_, fieldI) { RR_.set ( fieldI, new scalarField(mesh.nCells(), 0.0) ); }
Foam::tmp<Foam::volScalarField> Foam::sampledIsoSurface::average ( const fvMesh& mesh, const pointScalarField& pfld ) const { tmp<volScalarField> tcellAvg ( new volScalarField ( IOobject ( "cellAvg", mesh.time().timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE, false ), mesh, dimensionedScalar("zero", dimless, scalar(0.0)) ) ); volScalarField& cellAvg = tcellAvg(); labelField nPointCells(mesh.nCells(), 0); { for (label pointI = 0; pointI < mesh.nPoints(); pointI++) { const labelList& pCells = mesh.pointCells(pointI); forAll(pCells, i) { label cellI = pCells[i]; cellAvg[cellI] += pfld[pointI]; nPointCells[cellI]++; } } }
conservativeMeshToMesh::conservativeMeshToMesh ( const fvMesh& srcMesh, const fvMesh& tgtMesh, const label nThreads, const bool forceRecalculation, const bool writeAddressing ) : meshSrc_(srcMesh), meshTgt_(tgtMesh), addressing_ ( IOobject ( "addressing", tgtMesh.time().timeName(), tgtMesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), tgtMesh.nCells() ), weights_ ( IOobject ( "weights", tgtMesh.time().timeName(), tgtMesh, IOobject::NO_READ, IOobject::NO_WRITE ), tgtMesh.nCells() ), centres_ ( IOobject ( "centres", tgtMesh.time().timeName(), tgtMesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ), tgtMesh.nCells() ), cellAddressing_(tgtMesh.nCells()), counter_(0), boundaryAddressing_(tgtMesh.boundaryMesh().size()) { if (addressing_.headerOk() && weights_.headerOk() && centres_.headerOk()) { // Check if sizes match. Otherwise, re-calculate. if ( addressing_.size() == tgtMesh.nCells() && weights_.size() == tgtMesh.nCells() && centres_.size() == tgtMesh.nCells() && !forceRecalculation ) { Info<< " Reading addressing from file." << endl; return; } Info<< " Recalculating addressing." << endl; } else { Info<< " Calculating addressing." << endl; } // Check if the source mesh has a calculated addressing // If yes, try and invert that. IOobject srcHeader ( "addressing", srcMesh.time().timeName(), srcMesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE ); if (srcHeader.headerOk() && !addressing_.headerOk()) { Info<< " Found addressing in source directory." << " Checking for compatibility." << endl; if (invertAddressing()) { Info<< " Inversion successful. " << endl; return; } } // Track calculation time clockTime calcTimer; // Compute nearest cell addressing calcCellAddressing(); if (nThreads == 1) { calcAddressingAndWeights(0, tgtMesh.nCells(), true); } else { // Prior to multi-threaded operation, // force calculation of demand-driven data tgtMesh.cells(); srcMesh.cells(); srcMesh.cellCentres(); srcMesh.cellCells(); multiThreader threader(nThreads); // Set one handler per thread PtrList<handler> hdl(threader.getNumThreads()); forAll(hdl, i) { hdl.set(i, new handler(*this, threader)); } // Simple, but inefficient load-balancing scheme labelList tStarts(threader.getNumThreads(), 0); labelList tSizes(threader.getNumThreads(), 0); label index = tgtMesh.nCells(), j = 0; while (index--) { tSizes[(j = tSizes.fcIndex(j))]++; } label total = 0; for (label i = 1; i < tStarts.size(); i++) { tStarts[i] = tSizes[i-1] + total; total += tSizes[i-1]; } if (debug) { Info<< " Load starts: " << tStarts << endl; Info<< " Load sizes: " << tSizes << endl; } // Set the argument list for each thread forAll(hdl, i) { // Size up the argument list hdl[i].setSize(2); // Set the start/end cell indices hdl[i].set(0, &tStarts[i]); hdl[i].set(1, &tSizes[i]); // Lock the slave thread first hdl[i].lock(handler::START); hdl[i].unsetPredicate(handler::START); hdl[i].lock(handler::STOP); hdl[i].unsetPredicate(handler::STOP); }
void getCellTable(const fvMesh & mesh) { cellTableMap_.clear(); cellTableId_.setSize(mesh.nCells(), 1); IOdictionary cellTableDict ( IOobject ( "cellTable", "constant", mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false ) ); volScalarField volField ( IOobject ( "cellTableId", mesh.time().timeName(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false ), mesh, dimensionedScalar("cellTableId", dimless, 1.0) ); // get cellTableId information from the volScalarField if possible if (volField.headerOk()) { const scalarField & field = volField.internalField(); forAll(field, cellI) { cellTableId_[cellI] = static_cast<int>(field[cellI]); } if (cellTableDict.headerOk()) { // convert dictionary to map wordList toc = cellTableDict.toc(); forAll(toc, i) { word keyword = toc[i]; if (!cellTableDict.isDict(keyword)) continue; const dictionary & dict = cellTableDict.subDict(keyword); if (dict.found("Id") && dict.found("MaterialType")) { label Id; dict["Id"] >> Id; dict["MaterialType"] >> keyword; if (keyword == "fluid") { cellTableMap_.insert(Id, 1); } else if (keyword == "solid") { cellTableMap_.insert(Id, 2); } } }
void Foam::vtkFoam::addInternalMesh ( const fvMesh& mesh, vtkUnstructuredGrid* vtkMesh ) { SetName(vtkMesh, "Internal Mesh"); // Number of additional points needed by the decomposition of polyhedra label nAddPoints = 0; // Number of additional cells generated by the decomposition of polyhedra label nAddCells = 0; const cellModel& tet = *(cellModeller::lookup("tet")); const cellModel& pyr = *(cellModeller::lookup("pyr")); const cellModel& prism = *(cellModeller::lookup("prism")); const cellModel& wedge = *(cellModeller::lookup("wedge")); const cellModel& tetWedge = *(cellModeller::lookup("tetWedge")); const cellModel& hex = *(cellModeller::lookup("hex")); // Scan for cells which need to be decomposed and count additional points // and cells if (debug) { Info<< "building cell-shapes" << endl; } const cellShapeList& cellShapes = mesh.cellShapes(); if (debug) { Info<< "scanning" << endl; } forAll(cellShapes, cellI) { const cellModel& model = cellShapes[cellI].model(); if ( model != hex && model != wedge && model != prism && model != pyr && model != tet && model != tetWedge ) { const cell& cFaces = mesh.cells()[cellI]; forAll(cFaces, cFaceI) { const face& f = mesh.faces()[cFaces[cFaceI]]; label nFacePoints = f.size(); label nQuads = (nFacePoints - 2)/2; label nTris = (nFacePoints - 2)%2; nAddCells += nQuads + nTris; } nAddCells--; nAddPoints++; } } // Set size of additional point addressing array // (from added point to original cell) addPointCellLabels_.setSize(nAddPoints); // Set size of additional cells mapping array // (from added cell to original cell) superCells_.setSize(mesh.nCells() + nAddCells); if (debug) { Info<< "converting points" << endl; } // Convert Foam mesh vertices to VTK vtkPoints *vtkpoints = vtkPoints::New(); vtkpoints->Allocate(mesh.nPoints() + nAddPoints); const Foam::pointField& points = mesh.points(); forAll(points, i) { vtkFoamInsertNextPoint(vtkpoints, points[i]); }
Foam::timeActivatedExplicitSource::timeActivatedExplicitSource ( const word& sourceName, const fvMesh& mesh ) : dict_ ( IOobject ( sourceName + "Properties", mesh.time().constant(), mesh, IOobject::MUST_READ, IOobject::NO_WRITE ) ), mesh_(mesh), runTime_(mesh.time()), cellSource_(dict_.lookup("cellSource")), timeStart_(dimensionedScalar(dict_.lookup("timeStart")).value()), duration_(dimensionedScalar(dict_.lookup("duration")).value()), onValue_(dict_.lookup("onValue")), offValue_(dict_.lookup("offValue")), currentValue_(dimensionedScalar("zero", onValue_.dimensions(), 0.0)), cellSelector_ ( topoSetSource::New ( cellSource_, mesh, dict_.subDict(cellSource_ + "Coeffs") ) ), selectedCellSet_ ( mesh, "timeActivatedExplicitSourceCellSet", mesh.nCells()/10 + 1 // Reasonable size estimate. ) { // Check dimensions of on/off values are consistent if (onValue_.dimensions() != offValue_.dimensions()) { FatalErrorIn ( "Foam::timeActivatedExplicitSource::timeActivatedExplicitSource" )<< "Dimensions of on and off values must be equal" << nl << "onValue = " << onValue_ << nl << "offValue = " << offValue_ << exit(FatalError); } // Create the cell set cellSelector_->applyToSet ( topoSetSource::NEW, selectedCellSet_ ); // Give some feedback Info<< "timeVaryingExplitSource(" << sourceName << ")" << nl << "Selected " << returnReduce(selectedCellSet_.size(), sumOp<label>()) << " cells." << endl; // Initialise the value update(); }