本文整理汇总了C++中SolutionPtr::solve方法的典型用法代码示例。如果您正苦于以下问题:C++ SolutionPtr::solve方法的具体用法?C++ SolutionPtr::solve怎么用?C++ SolutionPtr::solve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SolutionPtr
的用法示例。
在下文中一共展示了SolutionPtr::solve方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL); // initialize MPI
Teuchos::CommandLineProcessor cmdp(false,true); // false: don't throw exceptions; true: do return errors for unrecognized options
int numElements = 3;
double xLeft = 0.0, xRight = 1.0;
int polyOrder = 1, delta_k = 1;
cmdp.setOption("numElements", &numElements );
cmdp.setOption("polyOrder", &polyOrder );
cmdp.setOption("delta_k", &delta_k );
cmdp.setOption("xLeft", &xLeft );
cmdp.setOption("xRight", &xRight );
if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
{
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return -1;
}
int spaceDim = 1;
bool conformingTraces = true; // conformingTraces argument has no effect in 1D
PoissonFormulation poissonForm(spaceDim, conformingTraces);
MeshPtr mesh = MeshFactory::intervalMesh(poissonForm.bf(), xLeft, xRight, numElements, polyOrder + 1, delta_k); // 1D equispaced
RHSPtr rhs = RHS::rhs(); // zero RHS
IPPtr ip = poissonForm.bf()->graphNorm();
BCPtr bc = BC::bc();
bc->addDirichlet(poissonForm.phi_hat(), SpatialFilter::allSpace(), Function::zero());
SolutionPtr solution = Solution::solution(poissonForm.bf(), mesh, bc, rhs, ip);
solution->solve();
GDAMinimumRule* minRule = dynamic_cast<GDAMinimumRule*>(mesh->globalDofAssignment().get());
// minRule->printGlobalDofInfo();
Teuchos::RCP<Epetra_CrsMatrix> A = solution->getStiffnessMatrix();
EpetraExt::RowMatrixToMatrixMarketFile("A.dat",*A, NULL, NULL, false);
HDF5Exporter exporter(mesh);
return 0;
}
示例2: main
int main(int argc, char *argv[])
{
#ifdef ENABLE_INTEL_FLOATING_POINT_EXCEPTIONS
cout << "NOTE: enabling floating point exceptions for divide by zero.\n";
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID);
#endif
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
int rank = Teuchos::GlobalMPISession::getRank();
#ifdef HAVE_MPI
Epetra_MpiComm Comm(MPI_COMM_WORLD);
//cout << "rank: " << rank << " of " << numProcs << endl;
#else
Epetra_SerialComm Comm;
#endif
Comm.Barrier(); // set breakpoint here to allow debugger attachment to other MPI processes than the one you automatically attached to.
Teuchos::CommandLineProcessor cmdp(false,true); // false: don't throw exceptions; true: do return errors for unrecognized options
double minTol = 1e-8;
bool use3D = false;
int refCount = 10;
int k = 4; // poly order for field variables
int delta_k = use3D ? 3 : 2; // test space enrichment
int k_coarse = 0;
bool useMumps = true;
bool useGMGSolver = true;
bool enforceOneIrregularity = true;
bool useStaticCondensation = false;
bool conformingTraces = false;
bool useDiagonalScaling = false; // of the global stiffness matrix in GMGSolver
bool printRefinementDetails = false;
bool useWeightedGraphNorm = true; // graph norm scaled according to units, more or less
int numCells = 2;
int AztecOutputLevel = 1;
int gmgMaxIterations = 10000;
int smootherOverlap = 0;
double relativeTol = 1e-6;
double D = 1.0; // characteristic length scale
cmdp.setOption("polyOrder",&k,"polynomial order for field variable u");
cmdp.setOption("delta_k", &delta_k, "test space polynomial order enrichment");
cmdp.setOption("k_coarse", &k_coarse, "polynomial order for field variables on coarse mesh");
cmdp.setOption("numRefs",&refCount,"number of refinements");
cmdp.setOption("D", &D, "domain dimension");
cmdp.setOption("useConformingTraces", "useNonConformingTraces", &conformingTraces);
cmdp.setOption("enforceOneIrregularity", "dontEnforceOneIrregularity", &enforceOneIrregularity);
cmdp.setOption("smootherOverlap", &smootherOverlap, "overlap for smoother");
cmdp.setOption("printRefinementDetails", "dontPrintRefinementDetails", &printRefinementDetails);
cmdp.setOption("azOutput", &AztecOutputLevel, "Aztec output level");
cmdp.setOption("numCells", &numCells, "number of cells in the initial mesh");
cmdp.setOption("useScaledGraphNorm", "dontUseScaledGraphNorm", &useWeightedGraphNorm);
// cmdp.setOption("gmgTol", &gmgTolerance, "tolerance for GMG convergence");
cmdp.setOption("relativeTol", &relativeTol, "Energy error-relative tolerance for iterative solver.");
cmdp.setOption("gmgMaxIterations", &gmgMaxIterations, "tolerance for GMG convergence");
bool enhanceUField = false;
cmdp.setOption("enhanceUField", "dontEnhanceUField", &enhanceUField);
cmdp.setOption("useStaticCondensation", "dontUseStaticCondensation", &useStaticCondensation);
if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
{
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return -1;
}
double width = D, height = D, depth = D;
VarFactory varFactory;
// fields:
VarPtr u = varFactory.fieldVar("u", L2);
VarPtr sigma = varFactory.fieldVar("\\sigma", VECTOR_L2);
FunctionPtr n = Function::normal();
// traces:
VarPtr u_hat;
if (conformingTraces)
{
u_hat = varFactory.traceVar("\\widehat{u}", u);
}
else
{
cout << "Note: using non-conforming traces.\n";
u_hat = varFactory.traceVar("\\widehat{u}", u, L2);
}
//.........这里部分代码省略.........
示例3: main
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
int commRank = Teuchos::GlobalMPISession::getRank();
Comm.Barrier(); // set breakpoint here to allow debugger attachment to other MPI processes than the one you automatically attached to.
Teuchos::CommandLineProcessor cmdp(false,true); // false: don't throw exceptions; true: do return errors for unrecognized options
// problem parameters:
int spaceDim = 2;
double Re = 40;
bool steady = false;
string problemChoice = "TaylorGreen";
int numRefs = 1;
int p = 2, delta_p = 2;
int numXElems = 1;
int numTElems = 1;
int numSlabs = 1;
bool useConformingTraces = false;
string solverChoice = "KLU";
string multigridStrategyString = "W-cycle";
bool useCondensedSolve = false;
bool useConjugateGradient = true;
bool logFineOperator = false;
// double solverTolerance = 1e-8;
double nonlinearTolerance = 1e-5;
// int maxLinearIterations = 10000;
int maxNonlinearIterations = 20;
int cgMaxIterations = 10000;
double cgTol = 1e-8;
bool computeL2Error = false;
bool exportSolution = false;
bool saveSolution = false;
bool loadSolution = false;
int loadRef = 0;
int loadDirRef = 0;
string norm = "Graph";
string rootDir = ".";
string tag="";
cmdp.setOption("spaceDim", &spaceDim, "spatial dimension");
cmdp.setOption("Re", &Re, "Re");
cmdp.setOption("steady", "transient", &steady, "use steady incompressible Navier-Stokes");
cmdp.setOption("problem", &problemChoice, "Kovasznay, TaylorGreen");
cmdp.setOption("polyOrder",&p,"polynomial order for field variable u");
cmdp.setOption("delta_p", &delta_p, "test space polynomial order enrichment");
cmdp.setOption("numRefs",&numRefs,"number of refinements");
cmdp.setOption("numXElems",&numXElems,"number of elements in x direction");
cmdp.setOption("numTElems",&numTElems,"number of elements in t direction");
cmdp.setOption("numSlabs",&numSlabs,"number of time slabs to use");
cmdp.setOption("norm", &norm, "norm");
cmdp.setOption("conformingTraces", "nonconformingTraces", &useConformingTraces, "use conforming traces");
cmdp.setOption("solver", &solverChoice, "KLU, SuperLU, MUMPS, GMG-Direct, GMG-ILU, GMG-IC");
cmdp.setOption("multigridStrategy", &multigridStrategyString, "Multigrid strategy: V-cycle, W-cycle, Full, or Two-level");
cmdp.setOption("useCondensedSolve", "useStandardSolve", &useCondensedSolve);
cmdp.setOption("CG", "GMRES", &useConjugateGradient);
cmdp.setOption("logFineOperator", "dontLogFineOperator", &logFineOperator);
// cmdp.setOption("solverTolerance", &solverTolerance, "iterative solver tolerance");
cmdp.setOption("nonlinearTolerance", &nonlinearTolerance, "nonlinear solver tolerance");
// cmdp.setOption("maxLinearIterations", &maxLinearIterations, "maximum number of iterations for linear solver");
cmdp.setOption("maxNonlinearIterations", &maxNonlinearIterations, "maximum number of iterations for Newton solver");
cmdp.setOption("exportDir", &rootDir, "export directory");
cmdp.setOption("computeL2Error", "skipL2Error", &computeL2Error, "compute L2 error");
cmdp.setOption("exportSolution", "skipExport", &exportSolution, "export solution to HDF5");
cmdp.setOption("saveSolution", "skipSave", &saveSolution, "save mesh and solution to HDF5");
cmdp.setOption("loadSolution", "skipLoad", &loadSolution, "load mesh and solution from HDF5");
cmdp.setOption("loadRef", &loadRef, "load refinement number");
cmdp.setOption("loadDirRef", &loadDirRef, "which refinement directory to load from");
cmdp.setOption("tag", &tag, "output tag");
if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
{
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return -1;
}
map<string, Teuchos::RCP<IncompressibleProblem>> problems;
problems["ManufacturedSolution"] = Teuchos::rcp(new IncompressibleManufacturedSolution(steady, Re, numXElems));
problems["Kovasznay"] = Teuchos::rcp(new KovasznayProblem(steady, Re));
problems["TaylorGreen"] = Teuchos::rcp(new TaylorGreenProblem(steady, Re, numXElems, numSlabs));
problems["Cylinder"] = Teuchos::rcp(new CylinderProblem(steady, Re, numSlabs));
problems["SquareCylinder"] = Teuchos::rcp(new SquareCylinderProblem(steady, Re, numSlabs));
Teuchos::RCP<IncompressibleProblem> problem = problems.at(problemChoice);
// if (commRank == 0)
// {
// Solver::printAvailableSolversReport();
// cout << endl;
// }
Teuchos::RCP<Time> totalTimer = Teuchos::TimeMonitor::getNewCounter("Total Time");
//.........这里部分代码省略.........
示例4: main
//.........这里部分代码省略.........
// 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;
cout << "ratio of largest / smallest h: " << sqrt(maxCellMeasure) / sqrt(minCellMeasure) << endl;
}
if (rank == 0)
{
cout << "phi ID: " << phi->ID() << endl;
cout << "psi1 ID: " << psi_1->ID() << endl;
cout << "psi2 ID: " << psi_2->ID() << endl;
cout << "streamMesh has " << streamMesh->numActiveElements() << " elements.\n";
cout << "solving for approximate stream function...\n";
}
streamSolution->solve(useMumps);
energyErrorTotal = streamSolution->energyErrorTotal();
if (rank == 0)
{
cout << "...solved.\n";
cout << "Stream mesh has energy error: " << energyErrorTotal << endl;
}
if (rank==0)
{
solution->writeToVTK("nsCavitySoln.vtk");
if (! meshHasTriangles )
{
massFlux->writeBoundaryValuesToMATLABFile(solution->mesh(), "massFlux.dat");
u_mag->writeValuesToMATLABFile(solution->mesh(), "u_mag.m");
u_div->writeValuesToMATLABFile(solution->mesh(), "u_div.m");
solution->writeFieldsToFile(u1->ID(), "u1.m");
solution->writeFluxesToFile(u1hat->ID(), "u1_hat.dat");
solution->writeFieldsToFile(u2->ID(), "u2.m");
solution->writeFluxesToFile(u2hat->ID(), "u2_hat.dat");
solution->writeFieldsToFile(p->ID(), "p.m");
streamSolution->writeFieldsToFile(phi->ID(), "phi.m");
streamSolution->writeFluxesToFile(phi_hat->ID(), "phi_hat.dat");
streamSolution->writeFieldsToFile(psi_1->ID(), "psi1.m");
streamSolution->writeFieldsToFile(psi_2->ID(), "psi2.m");
vorticity->writeValuesToMATLABFile(streamMesh, "vorticity.m");
FunctionPtr ten = Teuchos::rcp( new ConstantScalarFunction(10) );
ten->writeBoundaryValuesToMATLABFile(solution->mesh(), "skeleton.dat");
cout << "wrote files: u_mag.m, u_div.m, u1.m, u1_hat.dat, u2.m, u2_hat.dat, p.m, phi.m, vorticity.m.\n";
}
else
{
solution->writeToFile(u1->ID(), "u1.dat");
solution->writeToFile(u2->ID(), "u2.dat");
solution->writeToFile(u2->ID(), "p.dat");
cout << "wrote files: u1.dat, u2.dat, p.dat\n";
}
FieldContainer<double> points = pointGrid(0, 1, 0, 1, 100);
FieldContainer<double> pointData = solutionData(points, streamSolution, phi);
GnuPlotUtil::writeXYPoints("phi_patch_navierStokes_cavity.dat", pointData);
set<double> patchContourLevels = diagonalContourLevels(pointData,1);
vector<string> patchDataPath;
patchDataPath.push_back("phi_patch_navierStokes_cavity.dat");
GnuPlotUtil::writeContourPlotScript(patchContourLevels, patchDataPath, "lidCavityNavierStokes.p");
GnuPlotUtil::writeExactMeshSkeleton("lid_navierStokes_continuation_adaptive", mesh, 2);
writePatchValues(0, 1, 0, 1, streamSolution, phi, "phi_patch.m");
writePatchValues(0, .1, 0, .1, streamSolution, phi, "phi_patch_detail.m");
writePatchValues(0, .01, 0, .01, streamSolution, phi, "phi_patch_minute_detail.m");
writePatchValues(0, .001, 0, .001, streamSolution, phi, "phi_patch_minute_minute_detail.m");
}
return 0;
}
示例5: main
//.........这里部分代码省略.........
VarPtr tau2 = vf->testVar("tau2", HDIV);
VarPtr q = vf->testVar("q", HGRAD);
BFPtr bf = Teuchos::rcp( new BF(vf) );
bf->addTerm(1./mu*sigma1, tau1);
bf->addTerm(1./mu*sigma2, tau2);
bf->addTerm(u1, tau1->div());
bf->addTerm(u2, tau2->div());
bf->addTerm(-u1hat, tau1->dot_normal());
bf->addTerm(-u2hat, tau2->dot_normal());
bf->addTerm(sigma1, v1->grad());
bf->addTerm(sigma2, v2->grad());
bf->addTerm(-p, v1->dx());
bf->addTerm(-p, v2->dy());
bf->addTerm(t1c, v1);
bf->addTerm(t2c, v2);
bf->addTerm(mu*permInv*u1, v1);
bf->addTerm(mu*permInv*u2, v2);
bf->addTerm(-u1, q->dx());
bf->addTerm(-u2, q->dy());
bf->addTerm(u1hat, q->times_normal_x());
bf->addTerm(u2hat, q->times_normal_y());
RHSPtr rhs = RHS::rhs();
BCPtr bc = BC::bc();
SpatialFilterPtr y_equals_one = SpatialFilter::matchingY(1.0);
SpatialFilterPtr y_equals_zero = SpatialFilter::matchingY(0);
SpatialFilterPtr x_equals_one = SpatialFilter::matchingX(1.0);
SpatialFilterPtr x_equals_zero = SpatialFilter::matchingX(0.0);
bc->addDirichlet(u1hat, y_equals_zero, u1_exact);
bc->addDirichlet(u2hat, y_equals_zero, u2_exact);
bc->addDirichlet(u1hat, x_equals_zero, u1_exact);
bc->addDirichlet(u2hat, x_equals_zero, u2_exact);
bc->addDirichlet(u1hat, y_equals_one, u1_exact);
bc->addDirichlet(u2hat, y_equals_one, u2_exact);
bc->addDirichlet(u1hat, x_equals_one, u1_exact);
bc->addDirichlet(u2hat, x_equals_one, u2_exact);
bc->addZeroMeanConstraint(p);
MeshPtr mesh = MeshFactory::quadMesh(bf, k+1, delta_k, 1, 1, 4, 4);
map<string, IPPtr> brinkmanIPs;
brinkmanIPs["Graph"] = bf->graphNorm();
brinkmanIPs["Decoupled"] = Teuchos::rcp(new IP);
brinkmanIPs["Decoupled"]->addTerm(tau1);
brinkmanIPs["Decoupled"]->addTerm(tau2);
brinkmanIPs["Decoupled"]->addTerm(tau1->div());
brinkmanIPs["Decoupled"]->addTerm(tau2->div());
brinkmanIPs["Decoupled"]->addTerm(permInv*v1);
brinkmanIPs["Decoupled"]->addTerm(permInv*v2);
brinkmanIPs["Decoupled"]->addTerm(v1->grad());
brinkmanIPs["Decoupled"]->addTerm(v2->grad());
brinkmanIPs["Decoupled"]->addTerm(q);
brinkmanIPs["Decoupled"]->addTerm(q->grad());
// brinkmanIPs["CoupledRobust"] = Teuchos::rcp(new IP);
// brinkmanIPs["CoupledRobust"]->addTerm(tau->div()-beta*v->grad());
// brinkmanIPs["CoupledRobust"]->addTerm(Function<double>::min(one/Function<double>::h(),Function<double>::constant(1./sqrt(epsilon)))*tau);
// brinkmanIPs["CoupledRobust"]->addTerm(sqrt(epsilon)*v->grad());
// brinkmanIPs["CoupledRobust"]->addTerm(beta*v->grad());
// brinkmanIPs["CoupledRobust"]->addTerm(Function<double>::min(sqrt(epsilon)*one/Function<double>::h(),one)*v);
IPPtr ip = brinkmanIPs[norm];
SolutionPtr soln = TSolution<double>::solution(mesh, bc, rhs, ip);
double threshold = 0.20;
RefinementStrategy refStrategy(soln, threshold);
ostringstream refName;
refName << "brinkman";
HDF5Exporter exporter(mesh,refName.str());
for (int refIndex=0; refIndex <= numRefs; refIndex++)
{
soln->solve(false);
double energyError = soln->energyErrorTotal();
if (commRank == 0)
{
// if (refIndex > 0)
// refStrategy.printRefinementStatistics(refIndex-1);
cout << "Refinement:\t " << refIndex << " \tElements:\t " << mesh->numActiveElements()
<< " \tDOFs:\t " << mesh->numGlobalDofs() << " \tEnergy Error:\t " << energyError << endl;
}
exporter.exportSolution(soln, refIndex);
if (refIndex != numRefs)
refStrategy.refine();
}
return 0;
}
示例6: main
int main(int argc, char *argv[])
{
Teuchos::GlobalMPISession mpiSession(&argc, &argv, NULL); // initialize MPI
Teuchos::CommandLineProcessor cmdp(false,true); // false: don't throw exceptions; true: do return errors for unrecognized options
int numElements = 3;
vector<vector<double>> domainDim(3,vector<double>{0.0,1.0}); // first index: spaceDim; second: 0/1 for x0, x1, etc.
int polyOrder = 2, delta_k = 1;
int spaceDim = 2;
cmdp.setOption("numElements", &numElements );
cmdp.setOption("polyOrder", &polyOrder );
cmdp.setOption("delta_k", &delta_k );
cmdp.setOption("x0", &domainDim[0][0] );
cmdp.setOption("x1", &domainDim[0][1] );
cmdp.setOption("y0", &domainDim[1][0] );
cmdp.setOption("y1", &domainDim[1][1] );
cmdp.setOption("z0", &domainDim[2][0] );
cmdp.setOption("z1", &domainDim[2][1] );
cmdp.setOption("spaceDim", &spaceDim);
if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
{
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return -1;
}
vector<double> x0(spaceDim);
vector<double> domainSize(spaceDim);
vector<int> elementCounts(spaceDim);
for (int d=0; d<spaceDim; d++)
{
x0[d] = domainDim[d][0];
domainSize[d] = domainDim[d][1] - x0[d];
elementCounts[d] = numElements;
}
bool conformingTraces = true; // no difference for primal/continuous formulations
PoissonFormulation formCG(spaceDim, conformingTraces, PoissonFormulation::CONTINUOUS_GALERKIN);
VarPtr q = formCG.q();
VarPtr phi = formCG.phi();
BFPtr bf = formCG.bf();
MeshPtr bubnovMesh = MeshFactory::rectilinearMesh(bf, domainSize, elementCounts, polyOrder, 0, x0);
// Right now, hanging nodes don't work with continuous field variables
// there is a GDAMinimumRule test demonstrating the failure, SolvePoisson2DContinuousGalerkinHangingNode.
// make a mesh with hanging nodes (when spaceDim > 1)
// {
// set<GlobalIndexType> cellsToRefine = {0};
// bubnovMesh->hRefine(cellsToRefine);
// }
RHSPtr rhs = RHS::rhs();
rhs->addTerm(1.0 * q); // unit forcing
IPPtr ip = Teuchos::null; // will give Bubnov-Galerkin
BCPtr bc = BC::bc();
bc->addDirichlet(phi, SpatialFilter::allSpace(), Function::zero());
SolutionPtr solution = Solution::solution(bf, bubnovMesh, bc, rhs, ip);
solution->solve();
HDF5Exporter exporter(bubnovMesh, "PoissonContinuousGalerkin");
exporter.exportSolution(solution);
/**** Sort-of-primal experiment ****/
// an experiment: try doing "primal" DPG with IBP to the boundary
// ip = IP::ip();
// ip->addTerm(q->grad());
// ip->addTerm(q);
//
// solution = Solution::solution(bf, bubnovMesh, bc, rhs, ip);
// solution->solve();
//
// HDF5Exporter primalNoFluxExporter(bubnovMesh, "PoissonPrimalNoFlux");
// primalNoFluxExporter.exportSolution(solution);
//*** Primal Formulation ***//
PoissonFormulation form(spaceDim, conformingTraces, PoissonFormulation::PRIMAL);
q = form.q();
phi = form.phi();
bf = form.bf();
bc = BC::bc();
bc->addDirichlet(phi, SpatialFilter::allSpace(), Function::zero());
rhs = RHS::rhs();
rhs->addTerm(1.0 * q); // unit forcing
MeshPtr primalMesh = MeshFactory::rectilinearMesh(bf, domainSize, elementCounts, polyOrder, delta_k, x0);
ip = IP::ip();
ip->addTerm(q->grad());
ip->addTerm(q);
// Right now, hanging nodes don't work with continuous field variables
//.........这里部分代码省略.........
示例7: main
int main(int argc, char *argv[])
{
#ifdef ENABLE_INTEL_FLOATING_POINT_EXCEPTIONS
cout << "NOTE: enabling floating point exceptions for divide by zero.\n";
_MM_SET_EXCEPTION_MASK(_MM_GET_EXCEPTION_MASK() & ~_MM_MASK_INVALID);
#endif
Teuchos::GlobalMPISession mpiSession(&argc, &argv);
int rank = Teuchos::GlobalMPISession::getRank();
Teuchos::CommandLineProcessor cmdp(false,true); // false: don't throw exceptions; true: do return errors for unrecognized options
const static double PI = 3.141592653589793238462;
bool useCondensedSolve = true; // condensed solve not yet compatible with minimum rule meshes
int k = 2; // poly order for u in every direction, including temporal
int numCells = 32; // in x, y
int numTimeCells = 1;
int numTimeSlabs = -1;
int numFrames = 201;
int delta_k = 3; // test space enrichment: should be 3 for 3D
int maxRefinements = 0; // maximum # of refinements on each time slab
bool useMumpsIfAvailable = true;
bool useConstantConvection = false;
double refinementTolerance = 0.1;
int checkPointFrequency = 50; // output solution and mesh every 50 time slabs
int previousSolutionTimeSlabNumber = -1;
string previousSolutionFile = "";
string previousMeshFile = "";
cmdp.setOption("polyOrder",&k,"polynomial order for field variable u");
cmdp.setOption("delta_k", &delta_k, "test space polynomial order enrichment");
cmdp.setOption("numCells",&numCells,"number of cells in x and y directions");
cmdp.setOption("numTimeCells",&numTimeCells,"number of time axis cells");
cmdp.setOption("numTimeSlabs",&numTimeSlabs,"number of time slabs");
cmdp.setOption("numFrames",&numFrames,"number of frames for export");
cmdp.setOption("useConstantConvection", "useVariableConvection", &useConstantConvection);
cmdp.setOption("useCondensedSolve", "useUncondensedSolve", &useCondensedSolve, "use static condensation to reduce the size of the global solve");
cmdp.setOption("useMumps", "useKLU", &useMumpsIfAvailable, "use MUMPS (if available)");
cmdp.setOption("refinementTolerance", &refinementTolerance, "relative error beyond which to stop refining");
cmdp.setOption("maxRefinements", &maxRefinements, "maximum # of refinements on each time slab");
cmdp.setOption("previousSlabNumber", &previousSolutionTimeSlabNumber, "time slab number of previous solution");
cmdp.setOption("previousSolution", &previousSolutionFile, "file with previous solution");
cmdp.setOption("previousMesh", &previousMeshFile, "file with previous mesh");
if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
{
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return -1;
}
int H1Order = k + 1;
VarFactory varFactory;
// traces:
VarPtr qHat = varFactory.fluxVar("\\widehat{q}");
// fields:
VarPtr u = varFactory.fieldVar("u", L2);
// test functions:
VarPtr v = varFactory.testVar("v", HGRAD);
FunctionPtr x = Function::xn(1);
FunctionPtr y = Function::yn(1);
FunctionPtr c;
if (useConstantConvection)
{
c = Function::vectorize(Function::constant(0.5), Function::constant(0.5), Function::constant(1.0));
}
else
{
c = Function::vectorize(y-0.5, 0.5-x, Function::constant(1.0));
}
FunctionPtr n = Function::normal();
BFPtr bf = Teuchos::rcp( new BF(varFactory) );
bf->addTerm( u, c * v->grad());
bf->addTerm(qHat, v);
double width = 2.0, height = 2.0;
int horizontalCells = numCells, verticalCells = numCells;
int depthCells = numTimeCells;
double x0 = -0.5;
double y0 = -0.5;
double t0 = 0;
double totalTime = 2.0 * PI;
//.........这里部分代码省略.........
示例8: main
int main(int argc, char *argv[])
{
#ifdef HAVE_MPI
Teuchos::GlobalMPISession mpiSession(&argc, &argv,0);
Epetra_MpiComm Comm(MPI_COMM_WORLD);
#else
Epetra_SerialComm Comm;
#endif
int commRank = Teuchos::GlobalMPISession::getRank();
Comm.Barrier(); // set breakpoint here to allow debugger attachment to other MPI processes than the one you automatically attached to.
Teuchos::CommandLineProcessor cmdp(false,true); // false: don't throw exceptions; true: do return errors for unrecognized options
// problem parameters:
int spaceDim = 2;
double epsilon = 1e-2;
int numRefs = 0;
int k = 2, delta_k = 2;
int numXElems = 1;
bool useConformingTraces = true;
string solverChoice = "KLU";
string coarseSolverChoice = "KLU"; // often this beats SuperLU_Dist as coarse solver (true on BG/Q with 6000 3D elements on 256 ranks)
double solverTolerance = 1e-6;
string norm = "CoupledRobust";
cmdp.setOption("spaceDim", &spaceDim, "spatial dimension");
cmdp.setOption("polyOrder",&k,"polynomial order for field variable u");
cmdp.setOption("delta_k", &delta_k, "test space polynomial order enrichment");
cmdp.setOption("numRefs",&numRefs,"number of refinements");
cmdp.setOption("numXElems",&numXElems,"number of elements in x direction");
cmdp.setOption("epsilon", &epsilon, "epsilon");
cmdp.setOption("norm", &norm, "norm");
cmdp.setOption("conformingTraces", "nonconformingTraces", &useConformingTraces, "use conforming traces");
cmdp.setOption("coarseSolver", &coarseSolverChoice, "KLU, SuperLU");
cmdp.setOption("solver", &solverChoice, "KLU, SuperLU, MUMPS, GMG-Direct, GMG-ILU, GMG-IC");
cmdp.setOption("solverTolerance", &solverTolerance, "iterative solver tolerance");
if (cmdp.parse(argc,argv) != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL)
{
#ifdef HAVE_MPI
MPI_Finalize();
#endif
return -1;
}
FunctionPtr beta;
FunctionPtr beta_x = Function::constant(1);
FunctionPtr beta_y = Function::constant(2);
FunctionPtr beta_z = Function::constant(3);
if (spaceDim == 1)
beta = beta_x;
else if (spaceDim == 2)
beta = Function::vectorize(beta_x, beta_y);
else if (spaceDim == 3)
beta = Function::vectorize(beta_x, beta_y, beta_z);
ConvectionDiffusionFormulation form(spaceDim, useConformingTraces, beta, epsilon);
// Define right hand side
RHSPtr rhs = RHS::rhs();
// Set up boundary conditions
BCPtr bc = BC::bc();
VarPtr uhat = form.uhat();
VarPtr tc = form.tc();
SpatialFilterPtr inflowX = SpatialFilter::matchingX(-1);
SpatialFilterPtr inflowY = SpatialFilter::matchingY(-1);
SpatialFilterPtr inflowZ = SpatialFilter::matchingZ(-1);
SpatialFilterPtr outflowX = SpatialFilter::matchingX(1);
SpatialFilterPtr outflowY = SpatialFilter::matchingY(1);
SpatialFilterPtr outflowZ = SpatialFilter::matchingZ(1);
FunctionPtr zero = Function::zero();
FunctionPtr one = Function::constant(1);
FunctionPtr x = Function::xn(1);
FunctionPtr y = Function::yn(1);
FunctionPtr z = Function::zn(1);
if (spaceDim == 1)
{
bc->addDirichlet(tc, inflowX, -one);
bc->addDirichlet(uhat, outflowX, zero);
}
if (spaceDim == 2)
{
bc->addDirichlet(tc, inflowX, -1*.5*(one-y));
bc->addDirichlet(uhat, outflowX, zero);
bc->addDirichlet(tc, inflowY, -2*.5*(one-x));
bc->addDirichlet(uhat, outflowY, zero);
}
if (spaceDim == 3)
{
bc->addDirichlet(tc, inflowX, -1*.25*(one-y)*(one-z));
bc->addDirichlet(uhat, outflowX, zero);
bc->addDirichlet(tc, inflowY, -2*.25*(one-x)*(one-z));
bc->addDirichlet(uhat, outflowY, zero);
bc->addDirichlet(tc, inflowZ, -3*.25*(one-x)*(one-y));
bc->addDirichlet(uhat, outflowZ, zero);
}
//.........这里部分代码省略.........