/* Monomial evaluation. in 1D, for point p(x) : x^xDeg in 2D, for point p(x,y) : x^xDeg * y^yDeg in 3D, for point p(x,y,z): x^xDeg * y^yDeg * z^zDeg */ double computeMonomial(FieldContainer<double> & p, int xDeg, int yDeg=0, int zDeg=0) { double val = 1.0; int polydeg[3]; polydeg[0] = xDeg; polydeg[1] = yDeg; polydeg[2] = zDeg; for (int i=0; i<p.dimension(0); i++) { val *= std::pow(p(i),polydeg[i]); } return val; }
void MPIWrapper::entryWiseSum(FieldContainer<int> &values) { #ifdef HAVE_MPI Epetra_MpiComm Comm(MPI_COMM_WORLD); FieldContainer<int> valuesCopy = values; // it appears this copy is necessary Comm.SumAll(&valuesCopy[0], &values[0], values.size()); #else #endif }
void func_u(FieldContainer<ScalarT> fu, FieldContainer<ScalarT> u) { int num_cells = u.dimension(0); int num_cub_p = u.dimension(1); for(int c=0; c<num_cells; c++){ for(int p=0; p<num_cub_p; p++){ fu(c,p) = std::pow(u(c,p),3) + std::exp(u(c,p)); } } }
void dfunc_u(FieldContainer<double> dfu, FieldContainer<double> u) { int num_cells = u.dimension(0); int num_cub_p = u.dimension(1); for(int c=0; c<num_cells; c++) { for(int p=0; p<num_cub_p; p++) { dfu(c,p) = 3*u(c,p)*u(c,p) + std::exp(u(c,p)); } } }
void values(FieldContainer<double> &values, BasisCachePtr basisCache) { int numCells = values.dimension(0); int numPoints = values.dimension(1); const FieldContainer<double> *points = &(basisCache->getPhysicalCubaturePoints()); double tol=1e-14; for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { double x = (*points)(cellIndex,ptIndex,0); double y = (*points)(cellIndex,ptIndex,1); values(cellIndex,ptIndex) = y; } } }
void values(FieldContainer<double> &values, BasisCachePtr basisCache) { FieldContainer<double> points = basisCache->getPhysicalCubaturePoints(); FieldContainer<double> normals = basisCache->getSideNormals(); int numCells = points.dimension(0); int numPoints = points.dimension(1); FieldContainer<double> Tv(numCells,numPoints); FieldContainer<double> u1v(numCells,numPoints);; _u1->values(u1v,basisCache); _T->values(Tv,basisCache); bool isSubsonic = false; double min_y = YTOP; double max_y = 0.0; values.initialize(0.0); for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { double x = points(cellIndex,ptIndex,0); double y = points(cellIndex,ptIndex,1); double T = Tv(cellIndex,ptIndex); double un = u1v(cellIndex,ptIndex); // WARNING: ASSUMES NORMAL AT OUTFLOW = (1,0) double c = sqrt(_gamma * (_gamma-1.0) * _cv * T); bool outflowMatch = ((abs(x-2.0) < _tol) && (y > 0.0) && (y < YTOP)); bool subsonicMatch = (un < c) && (un > 0.0); if (subsonicMatch && outflowMatch) { values(cellIndex,ptIndex) = 1.0; isSubsonic = true; min_y = min(y,min_y); max_y = max(y,max_y); // cout << "y = " << y << endl; } } } if (isSubsonic) { // cout << "subsonic in interval y =(" << min_y << "," << max_y << ")" << endl; } }
/*! Fills this changelist with entries that represent the current state of the system starting at the container with the given id. Prototypes are skipped unless skipPrototypes is false. For every container a 'Create' entry and a 'Change' entry (marking all fields as modified) is added and as many 'AddReference' entries as the ref count of the container. */ void ChangeList::fillFromCurrentState(UInt32 uiFieldContainerId, bool skipPrototypes ) { this->clear(); UInt32 uiNumContainers = FieldContainerFactory::the()->getNumContainers(); if(uiNumContainers <= uiFieldContainerId) { return; } for(UInt32 i = uiFieldContainerId; i < uiNumContainers; ++i) { FieldContainer *pContainer = FieldContainerFactory::the()->getContainer(i); // skip destroyed FC if(pContainer == NULL) continue; // skip prototypes - unless requested if(skipPrototypes == true && (pContainer->getType().getPrototype() == pContainer || pContainer->getType().getPrototype() == NULL )) { continue; } this->addCreated(i, TypeTraits<BitVector>::BitsClear); for(Int32 j = 0; j < pContainer->getRefCount(); ++j) this->addAddRefd(i); ContainerChangeEntry *pEntry = this->getNewEntry(); pEntry->uiEntryDesc = ContainerChangeEntry::Change; pEntry->pFieldFlags = pContainer->getFieldFlags(); pEntry->uiContainerId = i; pEntry->whichField = FieldBits::AllFields; pEntry->pList = this; } }
/*! Visits a MFFieldContainerPtr (or more specific pointer type) during preWrite. It creates elements for the pointed to containers and calls preWrite on them. If the pointed to containers are not in the root's id set they are added and thus scheduled for writing. \param[in] fieldId Id of the field in the container of this element. */ void OSBCommonElement::preWritePtrMultiField(const UInt32 fieldId) { OSG_OSB_LOG(("OSBCommonElement::preWritePtrMultiField: " "fieldId: [%u]\n", fieldId)); OSBRootElement *root = editRoot(); FieldContainerPtrMFieldBase::GetHandlePtr mfPtrField = boost::dynamic_pointer_cast<FieldContainerPtrMFieldBase::GetHandle>( getContainer()->getField(fieldId)); if(mfPtrField == NULL || mfPtrField->isValid() == false) return; FieldContainerPtrMFieldBase::const_iterator fieldIt = (*mfPtrField)->begin(); FieldContainerPtrMFieldBase::const_iterator fieldEnd = (*mfPtrField)->end (); for(; fieldIt != fieldEnd; ++fieldIt) { FieldContainer *refedFC = *fieldIt; if(refedFC == NULL) continue; UInt32 refedId = refedFC->getId (); const std::string &typeName = refedFC->getType().getName(); // only schedule a container once if(root->getIdSet().count(refedId) > 0) continue; OSBElementBase *elem = OSBElementFactory::the()->acquire( typeName, root); root->editIdSet ().insert (refedId); root->editElementList().push_back(elem ); elem->setContainer(refedFC); elem->preWrite (refedFC); } }
void BilinearFormUtility::computeStiffnessMatrixForCell(FieldContainer<double> &stiffness, Teuchos::RCP<Mesh> mesh, int cellID) { Teuchos::RCP<DofOrdering> trialOrder = mesh->getElement(cellID)->elementType()->trialOrderPtr; Teuchos::RCP<DofOrdering> testOrder = mesh->getElement(cellID)->elementType()->testOrderPtr; shards::CellTopology cellTopo = *(mesh->getElement(cellID)->elementType()->cellTopoPtr); FieldContainer<double> physicalCellNodes = mesh->physicalCellNodesForCell(cellID); FieldContainer<double> cellSideParities = mesh->cellSideParitiesForCell(cellID); int numCells = 1; stiffness.resize(numCells,testOrder->totalDofs(),trialOrder->totalDofs()); computeStiffnessMatrix(stiffness,mesh->bilinearForm(),trialOrder,testOrder,cellTopo,physicalCellNodes,cellSideParities); }
void values(FieldContainer<double> &values, BasisCachePtr basisCache) { int numCells = values.dimension(0); int numPoints = values.dimension(1); int spaceDim = values.dimension(2); const FieldContainer<double> *points = &(basisCache->getPhysicalCubaturePoints()); for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { for (int d = 0; d < spaceDim; d++) { double x = (*points)(cellIndex,ptIndex,0); double y = (*points)(cellIndex,ptIndex,1); if ((x+.5)*(x+.5)+y*y < .25*.25) values(cellIndex,ptIndex) = 1.0; else values(cellIndex,ptIndex) = 0.0; } } } }
void values(FieldContainer<double> &values, BasisCachePtr basisCache) { int numCells = values.dimension(0); int numPoints = values.dimension(1); const FieldContainer<double> *points = &(basisCache->getPhysicalCubaturePoints()); for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { double x = (*points)(cellIndex,ptIndex,0); double y = (*points)(cellIndex,ptIndex,1); if (abs(y) <= halfWidth) values(cellIndex, ptIndex) = -1.0*(1.0-y*y); else values(cellIndex, ptIndex) = 0; } } }
void ExactSolution::solutionValues(FieldContainer<double> &values, int trialID, FieldContainer<double> &physicalPoints) { int numCells = physicalPoints.dimension(0); int numPoints = physicalPoints.dimension(1); int spaceDim = physicalPoints.dimension(2); Teuchos::Array<int> pointDimensions; pointDimensions.push_back(spaceDim); // cout << "ExactSolution: physicalPoints:\n" << physicalPoints; for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { FieldContainer<double> point(pointDimensions,&physicalPoints(cellIndex,ptIndex,0)); double value = solutionValue(trialID, point); values(cellIndex,ptIndex) = value; } } }
void values(FieldContainer<double> &values, BasisCachePtr basisCache) { int numCells = values.dimension(0); int numPoints = values.dimension(1); FieldContainer<double> beta_pts(numCells,numPoints); _f->values(values,basisCache); for (int i = 0; i<numCells; i++) { for (int j = 0; j<numPoints; j++) { if (values(i,j)<0) { values(i,j) = 0.0; } } } }
void LinearTermTests::transposeFieldContainer(FieldContainer<double> &fc) { // this is NOT meant for production code. Could do the transpose in place if we were concerned with efficiency. FieldContainer<double> fcCopy = fc; int numCells = fc.dimension(0); int dim1 = fc.dimension(1); int dim2 = fc.dimension(2); fc.resize(numCells,dim2,dim1); for (int i=0; i<numCells; i++) { for (int j=0; j<dim1; j++) { for (int k=0; k<dim2; k++) { fc(i,k,j) = fcCopy(i,j,k); } } } }
void values(FieldContainer<double> &values, BasisCachePtr basisCache){ vector<int> cellIDs = basisCache->cellIDs(); int numPoints = values.dimension(1); for (int i = 0;i<cellIDs.size();i++){ int partitionNumber = _mesh->partitionForCellID(cellIDs[i]); for (int j = 0;j<numPoints;j++){ values(i,j) = partitionNumber; } } }
void values(FieldContainer<double> &values, BasisCachePtr basisCache){ vector<int> cellIDs = basisCache->cellIDs(); int numPoints = values.dimension(1); for (int i = 0;i<cellIDs.size();i++){ double energyError = _energyErrorForCell[cellIDs[i]]; for (int j = 0;j<numPoints;j++){ values(i,j) = energyError; } } }
bool FunctionTests::testVectorFunctionValuesOrdering() { bool success = true; FunctionPtr x = Function::xn(1); FunctionPtr x_vector = Function::vectorize(x, Function::zero()); BasisCachePtr basisCache = BasisCache::parametricQuadCache(10); FieldContainer<double> points = basisCache->getPhysicalCubaturePoints(); int numCells = points.dimension(0); int numPoints = points.dimension(1); int spaceDim = points.dimension(2); FieldContainer<double> values(numCells,numPoints,spaceDim); x_vector->values(values, basisCache); // cout << "(x,0) function values:\n" << values; double tol = 1e-14; for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { double xValueExpected = points(cellIndex,ptIndex,0); double yValueExpected = 0; double xValue = values(cellIndex,ptIndex,0); double yValue = values(cellIndex,ptIndex,1); double xErr = abs(xValue-xValueExpected); double yErr = abs(yValue-yValueExpected); if ( (xErr > tol) || (yErr > tol) ) { success = false; cout << "testVectorFunctionValuesOrdering(): vectorized function values incorrect (presumably out of order).\n"; cout << "x: " << xValueExpected << " ≠ " << xValue << endl; cout << "y: " << yValueExpected << " ≠ " << yValue << endl; } } } return success; }
void ParametricSurface::values(FieldContainer<double> &values, BasisCachePtr basisCache) { FieldContainer<double> parametricPoints = basisCache->computeParametricPoints(); int numCells = parametricPoints.dimension(0); int numPoints = parametricPoints.dimension(1); for (int cellIndex=0; cellIndex<numCells; cellIndex++) { double x, y; for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { double t1, t2; t1 = parametricPoints(cellIndex,ptIndex,0); t2 = parametricPoints(cellIndex,ptIndex,1); this->value(t1, t2, x, y); values(cellIndex,ptIndex,0) = x; values(cellIndex,ptIndex,1) = y; } } }
void values(FieldContainer<double> &values, BasisCachePtr basisCache) { int numCells = values.dimension(0); int numPoints = values.dimension(1); FieldContainer<double> beta_pts(numCells,numPoints,2); _beta->values(beta_pts,basisCache); const FieldContainer<double> *points = &(basisCache->getPhysicalCubaturePoints()); double tol=1e-14; for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { double x = (*points)(cellIndex,ptIndex,0); double y = (*points)(cellIndex,ptIndex,1); double b1 = beta_pts(cellIndex,ptIndex,0); double b2 = beta_pts(cellIndex,ptIndex,1); double beta_norm =b1*b1 + b2*b2; values(cellIndex,ptIndex) = sqrt(beta_norm); } } }
/// neumann boundary conditions void neumann(FieldContainer<double> & result, const FieldContainer<double> & points, const FieldContainer<double> & jacs, const shards::CellTopology & parentCell, int sideOrdinal, int xd, int yd, int zd) { int x = 0, y = 1, z = 2; int numCells = result.dimension(0); int numPoints = result.dimension(1); FieldContainer<double> grad_u(numCells, numPoints, 3); FieldContainer<double> side_normals(numCells, numPoints, 3); FieldContainer<double> normal_lengths(numCells, numPoints); // first x-derivatives of u if (xd > 0) { for (int cell=0; cell<numCells; cell++) { for (int pt=0; pt<numPoints; pt++) { grad_u(cell,pt,x) = xd*std::pow(points(cell,pt,x), xd-1) * std::pow(points(cell,pt,y), yd) * std::pow(points(cell,pt,z), zd); } } } // first y-derivatives of u if (yd > 0) { for (int cell=0; cell<numCells; cell++) { for (int pt=0; pt<numPoints; pt++) { grad_u(cell,pt,y) = yd*std::pow(points(cell,pt,y), yd-1) * std::pow(points(cell,pt,x), xd) * std::pow(points(cell,pt,z), zd); } } } // first z-derivatives of u if (zd > 0) { for (int cell=0; cell<numCells; cell++) { for (int pt=0; pt<numPoints; pt++) { grad_u(cell,pt,z) = zd*std::pow(points(cell,pt,z), zd-1) * std::pow(points(cell,pt,x), xd) * std::pow(points(cell,pt,y), yd); } } } CellTools<double>::getPhysicalSideNormals(side_normals, jacs, sideOrdinal, parentCell); // scale normals RealSpaceTools<double>::vectorNorm(normal_lengths, side_normals, NORM_TWO); FunctionSpaceTools::scalarMultiplyDataData<double>(side_normals, normal_lengths, side_normals, true); FunctionSpaceTools::dotMultiplyDataData<double>(result, grad_u, side_normals); }
void values(FieldContainer<double> &values, BasisCachePtr basisCache){ int numCells = values.dimension(0); int numPoints = values.dimension(1); MeshPtr mesh = basisCache->mesh(); vector<int> cellIDs = basisCache->cellIDs(); double tol=1e-14; for (int cellIndex=0; cellIndex<numCells; cellIndex++) { double h = 1.0; if (_spatialCoord==0){ h = mesh->getCellXSize(cellIDs[cellIndex]); }else if (_spatialCoord==1){ h = mesh->getCellYSize(cellIDs[cellIndex]); } for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { values(cellIndex,ptIndex) = sqrt(h); } } }
void MeshPolyOrderFunction::values(FieldContainer<double> &values, BasisCachePtr basisCache) { vector<GlobalIndexType> cellIDs = basisCache->cellIDs(); IndexType cellIndex = 0; int numPoints = values.dimension(1); for (vector<GlobalIndexType>::iterator cellIDIt = cellIDs.begin(); cellIDIt != cellIDs.end(); cellIDIt++, cellIndex++) { GlobalIndexType cellID = *cellIDIt; int polyOrder = _mesh->cellPolyOrder(cellID); // H1 order for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { values(cellIndex, ptIndex) = polyOrder-1; } } }
void u_exact( FieldContainer<double> &result, const FieldContainer<double> &points, int xd, int yd) { for (int cell=0; cell<result.dimension(0); cell++) { for (int pt=0; pt<result.dimension(1); pt++) { result(cell,pt) = std::pow(points(cell,pt,0),xd)*std::pow(points(cell,pt,1),yd); } } return; }
// sum the contents of valuesToSum across all processors, and returns the result: // (valuesToSum may vary in length across processors) GlobalIndexType MPIWrapper::sum(const FieldContainer<GlobalIndexType> &valuesToSum) { // this is fairly inefficient in the sense that the MPI overhead will dominate the cost here. // insofar as it's possible to group such calls into entryWiseSum() calls, this is preferred. GlobalIndexType mySum = 0; for (int i=0; i<valuesToSum.size(); i++) { mySum += valuesToSum[i]; } return sum(mySum); }
void EricksonManufacturedSolution::getValues(FieldContainer<double> &functionValues, const FieldContainer<double> &physicalPoints){ int numCells = physicalPoints.dimension(0); int numPoints = physicalPoints.dimension(1); int spaceDim = physicalPoints.dimension(2); functionValues.resize(numCells,numPoints); Teuchos::Array<int> pointDimensions; pointDimensions.push_back(spaceDim); for (int i=0;i<numCells;i++){ for (int j=0;j<numPoints;j++){ double x = physicalPoints(i,j,0); double y = physicalPoints(i,j,1); FieldContainer<double> physicalPoint(pointDimensions); physicalPoint(0) = x; physicalPoint(1) = y; functionValues(i,j) = solutionValue(ConfusionBilinearForm::U,physicalPoint); } } }
/// right-hand side function void rhsFunc(FieldContainer<double> & result, const FieldContainer<double> & points, int xd, int yd) { int x = 0, y = 1; // second x-derivatives of u if (xd > 1) { for (int cell=0; cell<result.dimension(0); cell++) { for (int pt=0; pt<result.dimension(1); pt++) { result(cell,pt) = - xd*(xd-1)*std::pow(points(cell,pt,x), xd-2) * std::pow(points(cell,pt,y), yd); } } } // second y-derivatives of u if (yd > 1) { for (int cell=0; cell<result.dimension(0); cell++) { for (int pt=0; pt<result.dimension(1); pt++) { result(cell,pt) -= yd*(yd-1)*std::pow(points(cell,pt,y), yd-2) * std::pow(points(cell,pt,x), xd); } } } // add u for (int cell=0; cell<result.dimension(0); cell++) { for (int pt=0; pt<result.dimension(1); pt++) { result(cell,pt) += std::pow(points(cell,pt,x), xd) * std::pow(points(cell,pt,y), yd); } } }
FCPtr BasisEvaluation::getValuesCrossedWithNormals(constFCPtr values,const FieldContainer<double> &sideNormals) { // values should have dimensions (C,basisCardinality,P,D) int numCells = sideNormals.dimension(0); int numPoints = sideNormals.dimension(1); int spaceDim = sideNormals.dimension(2); int basisCardinality = values->dimension(1); if (spaceDim != 2) { TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, "crossing with normal only supported for 2D right now"); } if ( (numCells != values->dimension(0)) || (basisCardinality != values->dimension(1)) || (numPoints != values->dimension(2)) || (spaceDim != values->dimension(3)) ) { TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, "values should have dimensions (C,basisCardinality,P,D)"); } Teuchos::RCP< FieldContainer<double> > result = Teuchos::rcp(new FieldContainer<double>(numCells,basisCardinality,numPoints)); for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int basisOrdinal=0; basisOrdinal<basisCardinality; basisOrdinal++) { for (int pointIndex=0; pointIndex<numPoints; pointIndex++) { double n1 = sideNormals(cellIndex,pointIndex,0); double n2 = sideNormals(cellIndex,pointIndex,1); double xValue = (*values)(cellIndex,basisOrdinal,pointIndex,0); double yValue = (*values)(cellIndex,basisOrdinal,pointIndex,1); /*cout << "(n1,n2) = (" << n1 << ", " << n2 << ")" << endl; cout << "(x,y) = (" << xValue << ", " << yValue << ")" << endl; cout << "(x,y) x n = " << xValue*n2 - yValue*n1 << endl;*/ // cout << "WARNING: pretty sure that we've reversed the sign of OP_CROSS_NORMAL.\n"; (*result)(cellIndex,basisOrdinal,pointIndex) = yValue*n1 - xValue*n2; } } } return result; }
//---------------------------------------------------------------------------------- //! Constructor //---------------------------------------------------------------------------------- StringToCurve::StringToCurve () : BaseOp(0, 0) { ML_TRACE_IN("StringToCurve::StringToCurve ()") handleNotificationOff(); FieldContainer *fieldC = getFieldContainer(); m_OutCurveList = new CurveList; f_OutCurveList = fieldC->addBase( "outCurveList" ); f_OutCurveList->setBaseValue( m_OutCurveList ); f_CurveString = fieldC->addString("curveString"); f_CurveString->setStringValue(""); f_IndexString = fieldC->addString("indexString"); f_IndexString->setStringValue(""); f_ValueSeparator = fieldC->addString("valueSeparator"); f_ValueSeparator->setStringValue(" "); f_CurveSeparator = fieldC->addString( "curveSeparator" ); f_CurveSeparator->setStringValue(";"); handleNotificationOn(); }
//---------------------------------------------------------------------------------- //! Constructor //---------------------------------------------------------------------------------- WEMVolume::WEMVolume (std::string type) : WEMInspector(type) { ML_TRACE_IN("WEMVolume::WEMVolume()") FieldContainer *fields = getFieldContainer(); ML_CHECK(fields); // Suppress calls of handleNotification on field changes. handleNotificationOff(); // Add min, max volume, and corresponding index fields _minVolumeFld = fields->addFloat("minVolume"); _minVolumeFld->setFloatValue(0.0f); _maxVolumeFld = fields->addFloat("maxVolume"); _maxVolumeFld->setFloatValue(0.0f); _minVolumeIndexFld = fields->addInt("minVolumePatchIndex"); _minVolumeIndexFld->setIntValue(0); _maxVolumeIndexFld = fields->addInt("maxVolumePatchIndex"); _maxVolumeIndexFld->setIntValue(0); // Add output curve field _outputVolumeCurveFld = fields->addBase("outputVolumeCurve"); _outputVolumeCurveFld->setBaseValue(&_outputVolumeCurve); // Reactivate calls of handleNotification on field changes. handleNotificationOn(); }
void values(FieldContainer<double> &values, BasisCachePtr basisCache) { CHECK_VALUES_RANK(values); FunctionPtr fsq = _f*_f; int numCells = basisCache->cellIDs().size(); int numPoints = values.dimension(1); FieldContainer<double> cellIntegs(numCells); fsq->integrate(cellIntegs,basisCache); for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { values(cellIndex,ptIndex) = cellIntegs(cellIndex); } } }