本文整理汇总了C++中BasisCachePtr::getCellMeasures方法的典型用法代码示例。如果您正苦于以下问题:C++ BasisCachePtr::getCellMeasures方法的具体用法?C++ BasisCachePtr::getCellMeasures怎么用?C++ BasisCachePtr::getCellMeasures使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BasisCachePtr
的用法示例。
在下文中一共展示了BasisCachePtr::getCellMeasures方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
cout << "Integral of pressure: " << p_avg << endl;
// integrate massFlux over each element (a test):
// fake a new bilinear form so we can integrate against 1
VarPtr testOne = varFactory.testVar("1",CONSTANT_SCALAR);
BFPtr fakeBF = Teuchos::rcp( new BF(varFactory) );
LinearTermPtr massFluxTerm = massFlux * testOne;
CellTopoPtrLegacy quadTopoPtr = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData<shards::Quadrilateral<4> >() ));
DofOrderingFactory dofOrderingFactory(fakeBF);
int fakeTestOrder = H1Order;
DofOrderingPtr testOrdering = dofOrderingFactory.testOrdering(fakeTestOrder, *quadTopoPtr);
int testOneIndex = testOrdering->getDofIndex(testOne->ID(),0);
vector< ElementTypePtr > elemTypes = mesh->elementTypes(); // global element types
map<int, double> massFluxIntegral; // cellID -> integral
double maxMassFluxIntegral = 0.0;
double totalMassFlux = 0.0;
double totalAbsMassFlux = 0.0;
double maxCellMeasure = 0;
double minCellMeasure = 1;
for (vector< ElementTypePtr >::iterator elemTypeIt = elemTypes.begin(); elemTypeIt != elemTypes.end(); elemTypeIt++)
{
ElementTypePtr elemType = *elemTypeIt;
vector< ElementPtr > elems = mesh->elementsOfTypeGlobal(elemType);
vector<GlobalIndexType> cellIDs;
for (int i=0; i<elems.size(); i++)
{
cellIDs.push_back(elems[i]->cellID());
}
FieldContainer<double> physicalCellNodes = mesh->physicalCellNodesGlobal(elemType);
BasisCachePtr basisCache = Teuchos::rcp( new BasisCache(elemType,mesh,polyOrder) ); // enrich by trial space order
basisCache->setPhysicalCellNodes(physicalCellNodes,cellIDs,true); // true: create side caches
FieldContainer<double> cellMeasures = basisCache->getCellMeasures();
FieldContainer<double> fakeRHSIntegrals(elems.size(),testOrdering->totalDofs());
massFluxTerm->integrate(fakeRHSIntegrals,testOrdering,basisCache,true); // true: force side evaluation
// cout << "fakeRHSIntegrals:\n" << fakeRHSIntegrals;
for (int i=0; i<elems.size(); i++)
{
int cellID = cellIDs[i];
// pick out the ones for testOne:
massFluxIntegral[cellID] = fakeRHSIntegrals(i,testOneIndex);
}
// find the largest:
for (int i=0; i<elems.size(); i++)
{
int cellID = cellIDs[i];
maxMassFluxIntegral = max(abs(massFluxIntegral[cellID]), maxMassFluxIntegral);
}
for (int i=0; i<elems.size(); i++)
{
int cellID = cellIDs[i];
maxCellMeasure = max(maxCellMeasure,cellMeasures(i));
minCellMeasure = min(minCellMeasure,cellMeasures(i));
maxMassFluxIntegral = max(abs(massFluxIntegral[cellID]), maxMassFluxIntegral);
totalMassFlux += massFluxIntegral[cellID];
totalAbsMassFlux += abs( massFluxIntegral[cellID] );
}
}
if (rank==0)
{
cout << "largest mass flux: " << maxMassFluxIntegral << endl;
cout << "total mass flux: " << totalMassFlux << endl;
cout << "sum of mass flux absolute value: " << totalAbsMassFlux << endl;
cout << "largest h: " << sqrt(maxCellMeasure) << endl;
cout << "smallest h: " << sqrt(minCellMeasure) << endl;
示例2: testBestApproximationErrorComputation
bool HConvergenceStudyTests::testBestApproximationErrorComputation() {
bool success = true;
bool enrichVelocity = false; // true would be for the "compliant" norm, which isn't working well yet
int minLogElements = 0, maxLogElements = minLogElements;
int numCells1D = pow(2.0,minLogElements);
int H1Order = 1;
int pToAdd = 2;
double tol = 1e-16;
double Re = 40.0;
VarFactory varFactory = VGPStokesFormulation::vgpVarFactory();
VarPtr u1_vgp = varFactory.fieldVar(VGP_U1_S);
VarPtr u2_vgp = varFactory.fieldVar(VGP_U2_S);
VarPtr sigma11_vgp = varFactory.fieldVar(VGP_SIGMA11_S);
VarPtr sigma12_vgp = varFactory.fieldVar(VGP_SIGMA12_S);
VarPtr sigma21_vgp = varFactory.fieldVar(VGP_SIGMA21_S);
VarPtr sigma22_vgp = varFactory.fieldVar(VGP_SIGMA22_S);
VarPtr p_vgp = varFactory.fieldVar(VGP_P_S);
VGPStokesFormulation stokesForm(1/Re);
int numCellsFineMesh = 20; // for computing a zero-mean pressure
int H1OrderFineMesh = 5;
// define Kovasznay domain:
FieldContainer<double> quadPointsKovasznay(4,2);
// Domain from Evans Hughes for Navier-Stokes:
quadPointsKovasznay(0,0) = 0.0; // x1
quadPointsKovasznay(0,1) = -0.5; // y1
quadPointsKovasznay(1,0) = 1.0;
quadPointsKovasznay(1,1) = -0.5;
quadPointsKovasznay(2,0) = 1.0;
quadPointsKovasznay(2,1) = 0.5;
quadPointsKovasznay(3,0) = 0.0;
quadPointsKovasznay(3,1) = 0.5;
FunctionPtr zero = Function::zero();
bool dontEnhanceFluxes = false;
VGPNavierStokesProblem zeroProblem = VGPNavierStokesProblem(Re, quadPointsKovasznay,
numCellsFineMesh, numCellsFineMesh,
H1OrderFineMesh, pToAdd,
zero, zero, zero, enrichVelocity, dontEnhanceFluxes);
FunctionPtr u1_exact, u2_exact, p_exact;
NavierStokesFormulation::setKovasznay(Re, zeroProblem.mesh(), u1_exact, u2_exact, p_exact);
VGPNavierStokesProblem problem = VGPNavierStokesProblem(Re,quadPointsKovasznay,
numCells1D,numCells1D,
H1Order, pToAdd,
u1_exact, u2_exact, p_exact, enrichVelocity, dontEnhanceFluxes);
HConvergenceStudy study(problem.exactSolution(),
problem.mesh()->bilinearForm(),
problem.exactSolution()->rhs(),
problem.backgroundFlow()->bc(),
problem.bf()->graphNorm(),
minLogElements, maxLogElements,
H1Order, pToAdd, false, false, false);
study.setReportRelativeErrors(false); // we want absolute errors
Teuchos::RCP<Mesh> mesh = problem.mesh();
int cubatureDegreeEnrichment = 10;
int L2Order = H1Order - 1;
int meshCubatureDegree = L2Order + H1Order + pToAdd;
study.setCubatureDegreeForExact(cubatureDegreeEnrichment + meshCubatureDegree);
FunctionPtr f = u1_exact;
int trialID = u1_vgp->ID();
{
double fIntegral = f->integrate(mesh,cubatureDegreeEnrichment);
// cout << "testBestApproximationErrorComputation: integral of f on whole mesh = " << fIntegral << endl;
double l2ErrorOfAverage = (Function::constant(fIntegral) - f)->l2norm(mesh,cubatureDegreeEnrichment);
// cout << "testBestApproximationErrorComputation: l2 error of fIntegral: " << l2ErrorOfAverage << endl;
ElementTypePtr elemType = mesh->elementTypes()[0];
vector<GlobalIndexType> cellIDs = mesh->cellIDsOfTypeGlobal(elemType);
bool testVsTest = false;
BasisCachePtr basisCache = Teuchos::rcp( new BasisCache(elemType, mesh, testVsTest, cubatureDegreeEnrichment) );
basisCache->setPhysicalCellNodes(mesh->physicalCellNodesGlobal(elemType), cellIDs, false); // false: no side cache
FieldContainer<double> projectionValues(cellIDs.size());
f->integrate(projectionValues, basisCache);
FieldContainer<double> cellMeasures = basisCache->getCellMeasures();
for (int i=0; i<projectionValues.size(); i++) {
projectionValues(i) /= cellMeasures(i);
}
// since we're not worried about the actual solution values at all, just use a single zero solution:
vector< SolutionPtr > solutions;
//.........这里部分代码省略.........
示例3: main
//.........这里部分代码省略.........
if (transient)
outfile << "TransientConfusion_" << refIndex << "_" << timestepCount;
else
outfile << "TransientConfusion_" << refIndex;
solution->writeToVTK(outfile.str(), 5);
}
//////////////////////////////////////////////////////////////////////////
// Check conservation by testing against one
//////////////////////////////////////////////////////////////////////////
VarPtr testOne = varFactory.testVar("1", CONSTANT_SCALAR);
// Create a fake bilinear form for the testing
BFPtr fakeBF = Teuchos::rcp( new BF(varFactory) );
// Define our mass flux
FunctionPtr flux_current_time = Teuchos::rcp( new PreviousSolutionFunction(solution, beta_n_u_minus_sigma_n) );
FunctionPtr delta_u = Teuchos::rcp( new PreviousSolutionFunction(flowResidual, u) );
LinearTermPtr surfaceFlux = -1.0 * flux_current_time * testOne;
LinearTermPtr volumeChange = invDt * delta_u * testOne;
LinearTermPtr massFluxTerm;
if (transient)
{
massFluxTerm = volumeChange;
// massFluxTerm->addTerm(surfaceFlux);
}
else
{
massFluxTerm = surfaceFlux;
}
// cout << "surface case = " << surfaceFlux->summands()[0].first->boundaryValueOnly() << " volume case = " << volumeChange->summands()[0].first->boundaryValueOnly() << endl;
// FunctionPtr massFlux= Teuchos::rcp( new PreviousSolutionFunction(solution, beta_n_u_minus_sigma_n) );
// LinearTermPtr massFluxTerm = massFlux * testOne;
Teuchos::RCP<shards::CellTopology> quadTopoPtr = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData<shards::Quadrilateral<4> >() ));
DofOrderingFactory dofOrderingFactory(fakeBF);
int fakeTestOrder = H1Order;
DofOrderingPtr testOrdering = dofOrderingFactory.testOrdering(fakeTestOrder, *quadTopoPtr);
int testOneIndex = testOrdering->getDofIndex(testOne->ID(),0);
vector< ElementTypePtr > elemTypes = mesh->elementTypes(); // global element types
map<int, double> massFluxIntegral; // cellID -> integral
double maxMassFluxIntegral = 0.0;
double totalMassFlux = 0.0;
double totalAbsMassFlux = 0.0;
for (vector< ElementTypePtr >::iterator elemTypeIt = elemTypes.begin(); elemTypeIt != elemTypes.end(); elemTypeIt++)
{
ElementTypePtr elemType = *elemTypeIt;
vector< ElementPtr > elems = mesh->elementsOfTypeGlobal(elemType);
vector<int> cellIDs;
for (int i=0; i<elems.size(); i++) {
cellIDs.push_back(elems[i]->cellID());
}
FieldContainer<double> physicalCellNodes = mesh->physicalCellNodesGlobal(elemType);
BasisCachePtr basisCache = Teuchos::rcp( new BasisCache(elemType,mesh) );
basisCache->setPhysicalCellNodes(physicalCellNodes,cellIDs,true); // true: create side caches
FieldContainer<double> cellMeasures = basisCache->getCellMeasures();
FieldContainer<double> fakeRHSIntegrals(elems.size(),testOrdering->totalDofs());
massFluxTerm->integrate(fakeRHSIntegrals,testOrdering,basisCache,true); // true: force side evaluation
for (int i=0; i<elems.size(); i++) {
int cellID = cellIDs[i];
// pick out the ones for testOne:
massFluxIntegral[cellID] = fakeRHSIntegrals(i,testOneIndex);
}
// find the largest:
for (int i=0; i<elems.size(); i++) {
int cellID = cellIDs[i];
maxMassFluxIntegral = max(abs(massFluxIntegral[cellID]), maxMassFluxIntegral);
}
for (int i=0; i<elems.size(); i++) {
int cellID = cellIDs[i];
maxMassFluxIntegral = max(abs(massFluxIntegral[cellID]), maxMassFluxIntegral);
totalMassFlux += massFluxIntegral[cellID];
totalAbsMassFlux += abs( massFluxIntegral[cellID] );
}
}
// Print results from processor with rank 0
if (rank == 0)
{
cout << "largest mass flux: " << maxMassFluxIntegral << endl;
cout << "total mass flux: " << totalMassFlux << endl;
cout << "sum of mass flux absolute value: " << totalAbsMassFlux << endl;
}
prevTimeFlow->setSolution(solution); // reset previous time solution to current time sol
timestepCount++;
}
if (refIndex < numRefs){
if (rank==0){
cout << "Performing refinement number " << refIndex << endl;
}
refinementStrategy->refine(rank==0);
// RESET solution every refinement - make sure discretization error doesn't creep in
// prevTimeFlow->projectOntoMesh(functionMap);
}
}
return 0;
}
示例4: main
//.........这里部分代码省略.........
}
////////////////////////////////////////////////////////////////////
// DEFINE REFINEMENT STRATEGY
////////////////////////////////////////////////////////////////////
Teuchos::RCP<RefinementStrategy> refinementStrategy;
refinementStrategy = Teuchos::rcp(new RefinementStrategy(solution,energyThreshold));
////////////////////////////////////////////////////////////////////
// SOLVE
////////////////////////////////////////////////////////////////////
for (int refIndex=0; refIndex<=numRefs; refIndex++)
{
double L2Update = 1e7;
int iterCount = 0;
while (L2Update > nonlinearRelativeEnergyTolerance && iterCount < maxNewtonIterations)
{
solution->solve();
L2Update = solution->L2NormOfSolutionGlobal(u->ID());
cout << "L2 Norm of Update = " << L2Update << endl;
// backgroundFlow->clear();
backgroundFlow->addSolution(solution, newtonStepSize);
iterCount++;
}
cout << endl;
// check conservation
VarPtr testOne = varFactory.testVar("1", CONSTANT_SCALAR);
// Create a fake bilinear form for the testing
BFPtr fakeBF = Teuchos::rcp( new BF(varFactory) );
// Define our mass flux
FunctionPtr massFlux = Teuchos::rcp( new PreviousSolutionFunction(solution, fhat) );
LinearTermPtr massFluxTerm = massFlux * testOne;
Teuchos::RCP<shards::CellTopology> quadTopoPtr = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData<shards::Quadrilateral<4> >() ));
DofOrderingFactory dofOrderingFactory(fakeBF);
int fakeTestOrder = H1Order;
DofOrderingPtr testOrdering = dofOrderingFactory.testOrdering(fakeTestOrder, *quadTopoPtr);
int testOneIndex = testOrdering->getDofIndex(testOne->ID(),0);
vector< ElementTypePtr > elemTypes = mesh->elementTypes(); // global element types
map<int, double> massFluxIntegral; // cellID -> integral
double maxMassFluxIntegral = 0.0;
double totalMassFlux = 0.0;
double totalAbsMassFlux = 0.0;
for (vector< ElementTypePtr >::iterator elemTypeIt = elemTypes.begin(); elemTypeIt != elemTypes.end(); elemTypeIt++)
{
ElementTypePtr elemType = *elemTypeIt;
vector< ElementPtr > elems = mesh->elementsOfTypeGlobal(elemType);
vector<int> cellIDs;
for (int i=0; i<elems.size(); i++)
{
cellIDs.push_back(elems[i]->cellID());
}
FieldContainer<double> physicalCellNodes = mesh->physicalCellNodesGlobal(elemType);
BasisCachePtr basisCache = Teuchos::rcp( new BasisCache(elemType,mesh) );
basisCache->setPhysicalCellNodes(physicalCellNodes,cellIDs,true); // true: create side caches
FieldContainer<double> cellMeasures = basisCache->getCellMeasures();
FieldContainer<double> fakeRHSIntegrals(elems.size(),testOrdering->totalDofs());
massFluxTerm->integrate(fakeRHSIntegrals,testOrdering,basisCache,true); // true: force side evaluation
for (int i=0; i<elems.size(); i++)
{
int cellID = cellIDs[i];
// pick out the ones for testOne:
massFluxIntegral[cellID] = fakeRHSIntegrals(i,testOneIndex);
}
// find the largest:
for (int i=0; i<elems.size(); i++)
{
int cellID = cellIDs[i];
maxMassFluxIntegral = max(abs(massFluxIntegral[cellID]), maxMassFluxIntegral);
}
for (int i=0; i<elems.size(); i++)
{
int cellID = cellIDs[i];
maxMassFluxIntegral = max(abs(massFluxIntegral[cellID]), maxMassFluxIntegral);
totalMassFlux += massFluxIntegral[cellID];
totalAbsMassFlux += abs( massFluxIntegral[cellID] );
}
}
if (rank==0)
{
cout << endl;
cout << "largest mass flux: " << maxMassFluxIntegral << endl;
cout << "total mass flux: " << totalMassFlux << endl;
cout << "sum of mass flux absolute value: " << totalAbsMassFlux << endl;
cout << endl;
stringstream outfile;
outfile << "burgers_" << refIndex;
backgroundFlow->writeToVTK(outfile.str(), 5);
}
if (refIndex < numRefs)
refinementStrategy->refine(rank==0); // print to console on rank 0
}
return 0;
}