bool matchesPoints(FieldContainer<bool> &pointsMatch, BasisCachePtr basisCache) { const FieldContainer<double> *points = &(basisCache->getPhysicalCubaturePoints()); const FieldContainer<double> *normals = &(basisCache->getSideNormals()); int numCells = (*points).dimension(0); int numPoints = (*points).dimension(1); double tol = 1e-3; bool somePointMatches = false; 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 n1 = (*normals)(cellIndex,ptIndex,0); double n2 = (*normals)(cellIndex,ptIndex,1); double beta_n = _beta[0]*n1 + _beta[1]*n2 ; pointsMatch(cellIndex,ptIndex) = false; if (abs((x-.5)*(x-.5)+y*y) < 0.75+tol && beta_n < 0) { pointsMatch(cellIndex,ptIndex) = true; somePointMatches = true; } } } return somePointMatches; }
void FunctionTests::checkFunctionsAgree(FunctionPtr f1, FunctionPtr f2, BasisCachePtr basisCache) { ASSERT_EQ(f1->rank(), f2->rank()) << "f1->rank() " << f1->rank() << " != f2->rank() " << f2->rank() << endl; int rank = f1->rank(); int numCells = basisCache->getPhysicalCubaturePoints().dimension(0); int numPoints = basisCache->getPhysicalCubaturePoints().dimension(1); int spaceDim = basisCache->getPhysicalCubaturePoints().dimension(2); Teuchos::Array<int> dim; dim.append(numCells); dim.append(numPoints); for (int i=0; i<rank; i++) { dim.append(spaceDim); } FieldContainer<double> f1Values(dim); FieldContainer<double> f2Values(dim); f1->values(f1Values,basisCache); f2->values(f2Values,basisCache); double tol = 1e-14; double maxDiff; EXPECT_TRUE(fcsAgree(f1Values,f2Values,tol,maxDiff)) << "Test failed: f1 and f2 disagree; maxDiff " << maxDiff << ".\n" << "f1Values: \n" << f1Values << "f2Values: \n" << f2Values; }
bool ScratchPadTests::testConstantFunctionProduct() { bool success = true; // set up basisCache (even though it won't really be used here) BasisCachePtr basisCache = Teuchos::rcp( new BasisCache( _elemType, _spectralConfusionMesh ) ); vector<GlobalIndexType> cellIDs; int cellID = 0; cellIDs.push_back(cellID); basisCache->setPhysicalCellNodes( _spectralConfusionMesh->physicalCellNodesForCell(cellID), cellIDs, true ); int numCells = _basisCache->getPhysicalCubaturePoints().dimension(0); int numPoints = _testPoints.dimension(0); FunctionPtr three = Function::constant(3.0); FunctionPtr two = Function::constant(2.0); FieldContainer<double> values(numCells,numPoints); two->values(values,basisCache); three->scalarMultiplyBasisValues( values, basisCache ); FieldContainer<double> expectedValues(numCells,numPoints); expectedValues.initialize( 3.0 * 2.0 ); double tol = 1e-15; double maxDiff = 0.0; if ( ! fcsAgree(expectedValues, values, tol, maxDiff) ) { success = false; cout << "Expected product differs from actual; maxDiff: " << maxDiff << endl; } return success; }
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); } } }
bool FunctionTests::testAdaptiveIntegrate() { bool success = true; // we must create our own basisCache here because _basisCache // has had its ref cell points set, which basically means it's // opted out of having any help with integration. BasisCachePtr basisCache = Teuchos::rcp( new BasisCache( _elemType, _spectralConfusionMesh ) ); vector<GlobalIndexType> cellIDs; cellIDs.push_back(0); basisCache->setPhysicalCellNodes( _spectralConfusionMesh->physicalCellNodesForCell(0), cellIDs, true ); double eps = .1; // FunctionPtr boundaryLayerFunction = Teuchos::rcp( new BoundaryLayerFunction(eps) ); int numCells = basisCache->cellIDs().size(); FieldContainer<double> integrals(numCells); double quadtol = 1e-2; double computedIntegral = boundaryLayerFunction->integrate(_spectralConfusionMesh,quadtol); double trueIntegral = (eps*(exp(1/eps) - exp(-1/eps)))*2.0; double diff = trueIntegral-computedIntegral; double relativeError = abs(diff)/abs(trueIntegral); // relative error double tol = 1e-2; if (relativeError > tol) { success = false; cout << "failing testAdaptiveIntegrate() with computed integral " << computedIntegral << " and true integral " << trueIntegral << endl; } return success; }
// bool matchesPoint(double x, double y) { // return true; // } bool matchesPoints(FieldContainer<bool> &pointsMatch, BasisCachePtr basisCache) { const FieldContainer<double> *points = &(basisCache->getPhysicalCubaturePoints()); const FieldContainer<double> *normals = &(basisCache->getSideNormals()); int numCells = (*points).dimension(0); int numPoints = (*points).dimension(1); FieldContainer<double> beta_pts(numCells,numPoints,2); _beta->values(beta_pts,basisCache); double tol=1e-14; bool somePointMatches = false; for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { double n1 = (*normals)(cellIndex,ptIndex,0); double n2 = (*normals)(cellIndex,ptIndex,1); double beta_n = beta_pts(cellIndex,ptIndex,0)*n1 + beta_pts(cellIndex,ptIndex,1)*n2 ; // cout << "beta = (" << beta_pts(cellIndex,ptIndex,0)<<", "<< // beta_pts(cellIndex,ptIndex,1)<<"), n = ("<<n1<<", "<<n2<<")"<<endl; pointsMatch(cellIndex,ptIndex) = false; if (beta_n < 0) { pointsMatch(cellIndex,ptIndex) = true; somePointMatches = true; } } } return somePointMatches; }
void MeshTransformationFunction::values(FieldContainer<double> &values, BasisCachePtr basisCache) { CHECK_VALUES_RANK(values); vector<GlobalIndexType> cellIDs = basisCache->cellIDs(); // identity map is the right thing most of the time // we'll do something different only where necessary int spaceDim = values.dimension(2); TEUCHOS_TEST_FOR_EXCEPTION(basisCache->cellTopology()->getDimension() != spaceDim, std::invalid_argument, "cellTopology dimension does not match the shape of the values container"); if (_op == OP_VALUE) { values = basisCache->getPhysicalCubaturePoints(); // identity } else if (_op == OP_DX) { // identity map is 1 in all the x slots, 0 in all others int mod_value = 0; // the x slots are the mod spaceDim = 0 slots; for (int i=0; i<values.size(); i++) { values[i] = (i%spaceDim == mod_value) ? 1.0 : 0.0; } } else if (_op == OP_DY) { // identity map is 1 in all the y slots, 0 in all others int mod_value = 1; // the y slots are the mod spaceDim = 1 slots; for (int i=0; i<values.size(); i++) { values[i] = (i%spaceDim == mod_value) ? 1.0 : 0.0; } } else if (_op == OP_DZ) { // identity map is 1 in all the z slots, 0 in all others int mod_value = 2; // the z slots are the mod spaceDim = 2 slots; for (int i=0; i<values.size(); i++) { values[i] = (i%spaceDim == mod_value) ? 1.0 : 0.0; } } // if (_op == OP_DX) { // cout << "values before cellTransformation:\n" << values; // } for (int cellIndex=0; cellIndex < cellIDs.size(); cellIndex++) { GlobalIndexType cellID = cellIDs[cellIndex]; if (_cellTransforms.find(cellID) == _cellTransforms.end()) continue; TFunctionPtr<double> cellTransformation = _cellTransforms[cellID]; ((CellTransformationFunction*)cellTransformation.get())->setCellIndex(cellIndex); cellTransformation->values(values, basisCache); } // if (_op == OP_DX) { // cout << "values after cellTransformation:\n" << values; // } }
// computes riesz representation over a single element - map is from int (testID) to FieldContainer of values (sized cellIndex, numPoints) void RieszRep::computeRepresentationValues(FieldContainer<double> &values, int testID, IntrepidExtendedTypes::EOperatorExtended op, BasisCachePtr basisCache){ if (_repsNotComputed){ cout << "Computing riesz rep dofs" << endl; computeRieszRep(); } int spaceDim = _mesh->getTopology()->getSpaceDim(); int numCells = values.dimension(0); int numPoints = values.dimension(1); vector<GlobalIndexType> cellIDs = basisCache->cellIDs(); // all elems coming in should be of same type ElementPtr elem = _mesh->getElement(cellIDs[0]); ElementTypePtr elemTypePtr = elem->elementType(); DofOrderingPtr testOrderingPtr = elemTypePtr->testOrderPtr; CellTopoPtrLegacy cellTopoPtr = elemTypePtr->cellTopoPtr; int numTestDofsForVarID = testOrderingPtr->getBasisCardinality(testID, 0); BasisPtr testBasis = testOrderingPtr->getBasis(testID); bool testBasisIsVolumeBasis = (spaceDim == testBasis->domainTopology()->getDimension()); bool useCubPointsSideRefCell = testBasisIsVolumeBasis && basisCache->isSideCache(); Teuchos::RCP< const FieldContainer<double> > transformedBasisValues = basisCache->getTransformedValues(testBasis,op,useCubPointsSideRefCell); int rank = values.rank() - 2; // if values are shaped as (C,P), scalar... if (rank > 1) { cout << "ranks greater than 1 not presently supported...\n"; TEUCHOS_TEST_FOR_EXCEPTION(true, std::invalid_argument, "ranks greater than 1 not presently supported..."); } // Camellia::print("cellIDs",cellIDs); values.initialize(0.0); for (int cellIndex = 0;cellIndex<numCells;cellIndex++){ int cellID = cellIDs[cellIndex]; for (int j = 0;j<numTestDofsForVarID;j++) { int dofIndex = testOrderingPtr->getDofIndex(testID, j); for (int i = 0;i<numPoints;i++) { if (rank==0) { double basisValue = (*transformedBasisValues)(cellIndex,j,i); values(cellIndex,i) += basisValue*_rieszRepDofsGlobal[cellID](dofIndex); } else { for (int d = 0; d<spaceDim; d++) { double basisValue = (*transformedBasisValues)(cellIndex,j,i,d); values(cellIndex,i,d) += basisValue*_rieszRepDofsGlobal[cellID](dofIndex); } } } } } // TestSuite::serializeOutput("rep values", values); }
void values(FieldContainer<double> &values, BasisCachePtr basisCache) { vector<GlobalIndexType> cellIDs = basisCache->cellIDs(); int numPoints = values.dimension(1); FieldContainer<double> points = basisCache->getPhysicalCubaturePoints(); for (int i = 0; i<cellIDs.size(); i++) { for (int j = 0; j<numPoints; j++) { values(i,j) = cellIDs[i]; } } }
void UnitNormalFunction::values(Intrepid::FieldContainer<double> &values, BasisCachePtr basisCache) { this->CHECK_VALUES_RANK(values); int numCells = values.dimension(0); int numPoints = values.dimension(1); int spaceDim = basisCache->getSpaceDim(); if (_comp == -1) { // check the the "D" dimension of values is correct: if (_spaceTime) { TEUCHOS_TEST_FOR_EXCEPTION(values.dimension(2) != spaceDim+1, std::invalid_argument, "For space-time normals, values.dimension(2) should be spaceDim + 1."); } else { TEUCHOS_TEST_FOR_EXCEPTION(values.dimension(2) != spaceDim, std::invalid_argument, "For spatial normals, values.dimension(2) should be spaceDim."); } } const Intrepid::FieldContainer<double> *sideNormals = _spaceTime ? &(basisCache->getSideNormalsSpaceTime()) : &(basisCache->getSideNormals()); int comp = _comp; if (comp == -2) { // want to select the temporal component, t() comp = spaceDim; } for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { if (comp == -1) { for (int d=0; d<spaceDim; d++) { double nd = (*sideNormals)(cellIndex,ptIndex,d); values(cellIndex,ptIndex,d) = nd; } if (_spaceTime) { double nd = (*sideNormals)(cellIndex,ptIndex,spaceDim); values(cellIndex,ptIndex,spaceDim) = nd; } } else { double ni = (*sideNormals)(cellIndex,ptIndex,comp); values(cellIndex,ptIndex) = ni; } } } }
bool RHSTests::testIntegrateAgainstStandardBasis() { bool success = true; double tol = 1e-14; Teuchos::RCP<ElementType> elemType = _mesh->getElement(0)->elementType(); int rank = _mesh->Comm()->MyPID(); vector< Teuchos::RCP< Element > > elemsInPartitionOfType = _mesh->elementsOfType(rank, elemType); FieldContainer<double> physicalCellNodes = _mesh->physicalCellNodes(elemType); int numCells = elemsInPartitionOfType.size(); int numTestDofs = elemType->testOrderPtr->totalDofs(); // set up diagonal testWeights matrices so we can reuse the existing computeRHS, and compare results… FieldContainer<double> testWeights(numCells,numTestDofs,numTestDofs); for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int i=0; i<numTestDofs; i++) { testWeights(cellIndex,i,i) = 1.0; } } FieldContainer<double> rhsExpected(numCells,numTestDofs); FieldContainer<double> rhsActual(numCells,numTestDofs); // determine cellIDs vector<GlobalIndexType> cellIDs = _mesh->globalDofAssignment()->cellIDsOfElementType(rank, elemType); if (numCells > 0) { // prepare basisCache and cellIDs BasisCachePtr basisCache = Teuchos::rcp(new BasisCache(elemType,_mesh)); bool createSideCacheToo = true; basisCache->setPhysicalCellNodes(physicalCellNodes,cellIDs,createSideCacheToo); _rhs->integrateAgainstStandardBasis(rhsActual, elemType->testOrderPtr, basisCache); _rhs->integrateAgainstOptimalTests(rhsExpected, testWeights, elemType->testOrderPtr, basisCache); } double maxDiff = 0.0; if ( ! fcsAgree(rhsExpected,rhsActual,tol,maxDiff) ) { success = false; cout << "Failed testIntegrateAgainstStandardBasis: maxDiff = " << maxDiff << endl; } // check success across MPI nodes return allSuccess(success); }
void ExactSolution::solutionValues(FieldContainer<double> &values, int trialID, BasisCachePtr basisCache) { if (_exactFunctions.find(trialID) != _exactFunctions.end() ) { _exactFunctions[trialID]->values(values,basisCache); return; } // TODO: change ExactSolution::solutionValues (below) to take a *const* points FieldContainer, to avoid this copy: FieldContainer<double> points = basisCache->getPhysicalCubaturePoints(); if (basisCache->getSideIndex() >= 0) { FieldContainer<double> unitNormals = basisCache->getSideNormals(); this->solutionValues(values,trialID,points,unitNormals); } else { this->solutionValues(values,trialID,points); } }
void values(FieldContainer<double> &values, BasisCachePtr basisCache){ MeshPtr mesh = basisCache->mesh(); vector<int> cellIDs = basisCache->cellIDs(); int numPoints = values.dimension(1); for (int i = 0;i<cellIDs.size();i++){ double h = mesh->getCellXSize(cellIDs[i]); // default to x-direction if (_xyDim == 1){ h = mesh->getCellYSize(cellIDs[i]); } double hPower = pow(h,_power); for (int j = 0;j<numPoints;j++){ values(i,j) = hPower; } } }
bool RHSTests::testTrivialRHS() { bool success = true; double tol = 1e-14; int rank = _mesh->Comm()->MyPID(); Teuchos::RCP<ElementType> elemType = _mesh->getElement(0)->elementType(); vector< Teuchos::RCP< Element > > elemsInPartitionOfType = _mesh->elementsOfType(rank, elemType); FieldContainer<double> physicalCellNodes = _mesh->physicalCellNodes(elemType); int numCells = elemsInPartitionOfType.size(); int numTestDofs = elemType->testOrderPtr->totalDofs(); // determine cellIDs vector<GlobalIndexType> cellIDs = _mesh->globalDofAssignment()->cellIDsOfElementType(rank, elemType); if (numCells > 0) { // prepare basisCache and cellIDs BasisCachePtr basisCache = Teuchos::rcp(new BasisCache(elemType,_mesh)); bool createSideCacheToo = true; basisCache->setPhysicalCellNodes(physicalCellNodes,cellIDs,createSideCacheToo); FieldContainer<double> rhsExpected(numCells,numTestDofs); FunctionPtr zero = Function::constant(0.0); RHSPtr rhs = RHS::rhs(); FunctionPtr f = zero; rhs->addTerm( f * _v ); // obviously, with f = 0 adding this term is not necessary! rhs->integrateAgainstStandardBasis(rhsExpected, elemType->testOrderPtr, basisCache); for (int i = 0; i<numCells; i++) { for (int j = 0; j<numTestDofs; j++) { if (abs(rhsExpected(i,j))>tol) { success = false; } } } } return allSuccess(success); }
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++) { double xCenter = 0; double yCenter = 0; int nPts = 0; for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { double x = (*points)(cellIndex,ptIndex,0); double y = (*points)(cellIndex,ptIndex,1); xCenter += x; yCenter += y; nPts++; } xCenter /= nPts; yCenter /= nPts; for (int ptIndex=0; ptIndex<numPoints; ptIndex++) { double x = (*points)(cellIndex,ptIndex,0); double y = (*points)(cellIndex,ptIndex,1); if (abs(y) <= halfWidth && abs(yCenter) < halfWidth) values(cellIndex, ptIndex) = 1.0; else values(cellIndex, ptIndex) = 0.0; } } }
bool checkLTSumConsistency(LinearTermPtr a, LinearTermPtr b, DofOrderingPtr dofOrdering, BasisCachePtr basisCache) { double tol = 1e-14; int numCells = basisCache->cellIDs().size(); int numDofs = dofOrdering->totalDofs(); bool forceBoundaryTerm = false; FieldContainer<double> aValues(numCells,numDofs), bValues(numCells,numDofs), sumValues(numCells,numDofs); a->integrate(aValues,dofOrdering,basisCache,forceBoundaryTerm); b->integrate(bValues,dofOrdering,basisCache,forceBoundaryTerm); (a+b)->integrate(sumValues, dofOrdering, basisCache, forceBoundaryTerm); int size = aValues.size(); for (int i=0; i<size; i++) { double expectedValue = aValues[i] + bValues[i]; double diff = abs( expectedValue - sumValues[i] ); if (diff > tol) { return false; } } return true; }
virtual void values(FieldContainer<double> &values, BasisCachePtr basisCache) { // not the most efficient implementation _fxn->values(values,basisCache); vector<GlobalIndexType> contextCellIDs = basisCache->cellIDs(); int cellIndex=0; // keep track of index into values int entryCount = values.size(); int numCells = values.dimension(0); int numEntriesPerCell = entryCount / numCells; for (vector<GlobalIndexType>::iterator cellIt = contextCellIDs.begin(); cellIt != contextCellIDs.end(); cellIt++) { GlobalIndexType cellID = *cellIt; if (_cellIDs.find(cellID) == _cellIDs.end()) { // clear out the associated entries for (int j=0; j<numEntriesPerCell; j++) { values[cellIndex*numEntriesPerCell + j] = 0; } } cellIndex++; } }
bool RHSTests::testRHSEasy() { bool success = true; double tol = 1e-14; int rank = _mesh->Comm()->MyPID(); int numProcs = Teuchos::GlobalMPISession::getNProc(); Teuchos::RCP<ElementType> elemType = _mesh->getElement(0)->elementType(); vector< Teuchos::RCP< Element > > elemsInPartitionOfType = _mesh->elementsOfType(rank, elemType); FieldContainer<double> physicalCellNodes = _mesh->physicalCellNodes(elemType); int numCells = elemsInPartitionOfType.size(); int numTestDofs = elemType->testOrderPtr->totalDofs(); FieldContainer<double> rhsExpected(numCells,numTestDofs); FieldContainer<double> rhsActual(numCells,numTestDofs); // determine cellIDs vector<GlobalIndexType> cellIDs = _mesh->globalDofAssignment()->cellIDsOfElementType(rank, elemType); // prepare basisCache and cellIDs if (numCells > 0) { BasisCachePtr basisCache = Teuchos::rcp(new BasisCache(elemType,_mesh)); bool createSideCacheToo = true; basisCache->setPhysicalCellNodes(physicalCellNodes,cellIDs,createSideCacheToo); _rhs->integrateAgainstStandardBasis(rhsActual, elemType->testOrderPtr, basisCache); _rhsEasy->integrateAgainstStandardBasis(rhsExpected, elemType->testOrderPtr, basisCache); } double maxDiff = 0.0; if ( ! fcsAgree(rhsExpected,rhsActual,tol,maxDiff) ) { success = false; cout << "Failed testRHSEasy: maxDiff = " << maxDiff << endl; cout << "Expected values:\n" << rhsExpected; cout << "Actual values:\n" << rhsActual; cout << "Test dof ordering:\n" << *(elemType->testOrderPtr); } return allSuccess(success); }
double basisSumAtParametricPoint(FieldContainer<double> &basisCoefficients, BasisPtr basis, double tValue, BasisCachePtr parametricBasisCache) { int numPoints = 1; int spaceDim = 1; FieldContainer<double> parametricPoints(numPoints,spaceDim); parametricPoints[0] = tValue; FieldContainer<double> refCellPoints = parametricBasisCache->getRefCellPointsForPhysicalPoints(parametricPoints); parametricBasisCache->setRefCellPoints(refCellPoints); Teuchos::RCP< const FieldContainer<double> > basisValues = parametricBasisCache->getValues(basis, OP_VALUE); double sum = 0; int ptIndex = 0; // one point for (int fieldIndex=0; fieldIndex<basisCoefficients.size(); fieldIndex++) { sum += (*basisValues)(fieldIndex,ptIndex) * basisCoefficients(fieldIndex); } return sum; }
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; } }
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 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 values(FieldContainer<double> &values, BasisCachePtr sliceBasisCache) { vector<GlobalIndexType> sliceCellIDs = sliceBasisCache->cellIDs(); Teuchos::Array<int> dim; values.dimensions(dim); dim[0] = 1; // one cell Teuchos::Array<int> offset(dim.size()); for (int cellOrdinal = 0; cellOrdinal < sliceCellIDs.size(); cellOrdinal++) { offset[0] = cellOrdinal; int enumeration = values.getEnumeration(offset); FieldContainer<double>valuesForCell(dim,&values[enumeration]); GlobalIndexType sliceCellID = sliceCellIDs[cellOrdinal]; int numPoints = sliceBasisCache->getPhysicalCubaturePoints().dimension(1); int spaceDim = sliceBasisCache->getPhysicalCubaturePoints().dimension(2); FieldContainer<double> spaceTimePhysicalPoints(1,numPoints,spaceDim+1); for (int ptOrdinal=0; ptOrdinal<numPoints; ptOrdinal++) { for (int d=0; d<spaceDim; d++) { spaceTimePhysicalPoints(0,ptOrdinal,d) = sliceBasisCache->getPhysicalCubaturePoints()(cellOrdinal,ptOrdinal,d); } spaceTimePhysicalPoints(0,ptOrdinal,spaceDim) = _t; } GlobalIndexType cellID = _cellIDMap[sliceCellID]; BasisCachePtr spaceTimeBasisCache = BasisCache::basisCacheForCell(_spaceTimeMesh, cellID); FieldContainer<double> spaceTimeRefPoints(1,numPoints,spaceDim+1); CamelliaCellTools::mapToReferenceFrame(spaceTimeRefPoints, spaceTimePhysicalPoints, _spaceTimeMesh, cellID); spaceTimeRefPoints.resize(numPoints,spaceDim+1); spaceTimeBasisCache->setRefCellPoints(spaceTimeRefPoints); _spaceTimeFunction->values(valuesForCell, spaceTimeBasisCache); } }
void PreviousSolutionFunction::values(FieldContainer<double> &values, BasisCachePtr basisCache) { int rank = Teuchos::GlobalMPISession::getRank(); if (_overrideMeshCheck) { _solnExpression->evaluate(values, _soln, basisCache); return; } if (!basisCache.get()) cout << "basisCache is nil!\n"; if (!_soln.get()) cout << "_soln is nil!\n"; // values are stored in (C,P,D) order if (basisCache->mesh().get() == _soln->mesh().get()) { _solnExpression->evaluate(values, _soln, basisCache); } else { static bool warningIssued = false; if (!warningIssued) { if (rank==0) cout << "NOTE: In PreviousSolutionFunction, basisCache's mesh doesn't match solution's. If this is not what you intended, it would be a good idea to make sure that the mesh is passed in on BasisCache construction; the evaluation will be a lot slower without it...\n"; warningIssued = true; } // get the physicalPoints, and make a basisCache for each... FieldContainer<double> physicalPoints = basisCache->getPhysicalCubaturePoints(); FieldContainer<double> value(1,1); // assumes scalar-valued solution function. int numCells = physicalPoints.dimension(0); int numPoints = physicalPoints.dimension(1); int spaceDim = physicalPoints.dimension(2); physicalPoints.resize(numCells*numPoints,spaceDim); vector< ElementPtr > elements = _soln->mesh()->elementsForPoints(physicalPoints, false); // false: don't make elements null just because they're off-rank. FieldContainer<double> point(1,spaceDim); FieldContainer<double> refPoint(1,spaceDim); int combinedIndex = 0; vector<GlobalIndexType> cellID; cellID.push_back(-1); BasisCachePtr basisCacheOnePoint; for (int cellIndex=0; cellIndex<numCells; cellIndex++) { for (int ptIndex=0; ptIndex<numPoints; ptIndex++, combinedIndex++) { if (elements[combinedIndex].get()==NULL) continue; // no element found for point; skip it… ElementTypePtr elemType = elements[combinedIndex]->elementType(); for (int d=0; d<spaceDim; d++) { point(0,d) = physicalPoints(combinedIndex,d); } if (elements[combinedIndex]->cellID() != cellID[0]) { cellID[0] = elements[combinedIndex]->cellID(); basisCacheOnePoint = Teuchos::rcp( new BasisCache(elemType, _soln->mesh()) ); basisCacheOnePoint->setPhysicalCellNodes(_soln->mesh()->physicalCellNodesForCell(cellID[0]),cellID,false); // false: don't createSideCacheToo } // compute the refPoint: typedef CellTools<double> CellTools; int whichCell = 0; CellTools::mapToReferenceFrame(refPoint,point,_soln->mesh()->physicalCellNodesForCell(cellID[0]), *(elemType->cellTopoPtr),whichCell); basisCacheOnePoint->setRefCellPoints(refPoint); // cout << "refCellPoints:\n " << refPoint; // cout << "physicalCubaturePoints:\n " << basisCacheOnePoint->getPhysicalCubaturePoints(); _solnExpression->evaluate(value, _soln, basisCacheOnePoint); // cout << "value at point (" << point(0,0) << ", " << point(0,1) << ") = " << value(0,0) << endl; values(cellIndex,ptIndex) = value(0,0); } } } }
bool FunctionTests::functionsAgree(FunctionPtr f1, FunctionPtr f2, BasisCachePtr basisCache) { if (f2->rank() != f1->rank() ) { cout << "f1->rank() " << f1->rank() << " != f2->rank() " << f2->rank() << endl; return false; } int rank = f1->rank(); int numCells = basisCache->getPhysicalCubaturePoints().dimension(0); int numPoints = basisCache->getPhysicalCubaturePoints().dimension(1); int spaceDim = basisCache->getSpaceDim(); Teuchos::Array<int> dim; dim.append(numCells); dim.append(numPoints); for (int i=0; i<rank; i++) { dim.append(spaceDim); } FieldContainer<double> f1Values(dim); FieldContainer<double> f2Values(dim); f1->values(f1Values,basisCache); f2->values(f2Values,basisCache); double tol = 1e-14; double maxDiff; bool functionsAgree = TestSuite::fcsAgree(f1Values,f2Values,tol,maxDiff); if ( ! functionsAgree ) { functionsAgree = false; cout << "Test failed: f1 and f2 disagree; maxDiff " << maxDiff << ".\n"; cout << "f1Values: \n" << f1Values; cout << "f2Values: \n" << f2Values; } else { // cout << "f1 and f2 agree!" << endl; } return functionsAgree; }
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); } } }
void LagrangeConstraints::getCoefficients(FieldContainer<double> &lhs, FieldContainer<double> &rhs, int elemConstraintIndex, DofOrderingPtr trialOrdering, BasisCachePtr basisCache) { LinearTermPtr lt = _constraints[elemConstraintIndex].linearTerm(); TFunctionPtr<double> f = _constraints[elemConstraintIndex].f(); lt->integrate(lhs, trialOrdering, basisCache); bool onBoundary = f->boundaryValueOnly(); if ( !onBoundary ) { f->integrate(rhs, basisCache); } else { int numSides = basisCache->cellTopology()->getSideCount(); rhs.initialize(0); for (int sideIndex=0; sideIndex<numSides; sideIndex++) { f->integrate(rhs, basisCache->getSideBasisCache(sideIndex), true); // true: sumInto } } }
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); values(cellIndex, ptIndex) = 0; } } }