本文整理汇总了C++中TimeManager::advance方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeManager::advance方法的具体用法?C++ TimeManager::advance怎么用?C++ TimeManager::advance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeManager
的用法示例。
在下文中一共展示了TimeManager::advance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, const char *argv[])
{
ConfigManager configManager;
Domain domain(1);
Mesh mesh(domain, 2);
Field<double, 2> u, f;
Field<double> fu;
TimeManager timeManager;
IOManager io;
int outputFileIdx;
TimeLevelIndex<2> oldIdx, newIdx, halfIdx;
double dt, dx;
string outputPattern = "beam_warming.%3s.nc";
if (argc != 2) {
REPORT_ERROR("Configure file is needed!");
}
// Read configuration from file.
configManager.parse(argv[1]);
dt = configManager.getValue("beam_warming", "dt", 1);
dx = configManager.getValue("beam_warming", "dx", 0.01);
outputPattern = configManager.getValue("beam_warming", "output_pattern", outputPattern);
// Set the one dimensional space axis.
domain.setAxis(0, "x", "x axis", "m",
0, geomtk::BndType::PERIODIC,
1, geomtk::BndType::PERIODIC);
// Set the discrete mesh on the domain.
mesh.init(domain.axisSpan(0)/dx);
// Set the time manager.
Time startTime(0*geomtk::TimeUnit::SECONDS);
Time endTime(200*geomtk::TimeUnit::SECONDS);
timeManager.init(startTime, endTime, dt);
// Set up velocity and density fields.
u.create("u", "m s-1", "velocity component along x axis", mesh, X_FACE, 1, true);
f.create("f", "kg m-1", "tracer density", mesh, CENTER, 1);
fu.create("fu", "kg s-1", "tracer mass flux", mesh, X_FACE, 1);
// Set the initial conditions.
newIdx = oldIdx+1;
for (int i = mesh.is(HALF); i <= mesh.ie(HALF); ++i) {
u(oldIdx, i) = 0.005;
u(newIdx, i) = 0.005;
}
u.applyBndCond(oldIdx);
u.applyBndCond(newIdx, true);
for (int i = mesh.is(FULL); i <= mesh.ie(FULL); ++i) {
const SpaceCoord &x = mesh.gridCoord(CENTER, i);
if (x(0) >= 0.05 && x(0) <= 0.1) {
f(oldIdx, i) = 1.0;
} else {
f(oldIdx, i) = 0.0;
}
}
f.applyBndCond(oldIdx);
// Set up IO manager.
io.init(timeManager);
outputFileIdx = io.registerOutputFile(mesh, outputPattern, geomtk::TimeStepUnit::STEP, 1);
io.registerField(outputFileIdx, "double", FULL_DIMENSION, {&f});
io.output<double, 2>(outputFileIdx, oldIdx, {&f});
// Run the main loop.
double C = dt/dx;
while (!timeManager.isFinished()) {
newIdx = oldIdx+1; halfIdx = oldIdx+0.5;
for (int i = mesh.is(HALF); i <= mesh.ie(HALF); ++i) {
fu(i) = 0.5*C*( u(halfIdx, i) *(3*f(oldIdx, i)-f(oldIdx, i-1))-
C*pow(u(halfIdx, i), 2)*( f(oldIdx, i)-f(oldIdx, i-1)));
}
fu.applyBndCond();
for (int i = mesh.is(FULL); i <= mesh.ie(FULL); ++i) {
f(newIdx, i) = f(oldIdx, i)-(fu(i)-fu(i-1));
}
f.applyBndCond(newIdx);
timeManager.advance(); oldIdx.shift();
io.output<double, 2>(outputFileIdx, oldIdx, {&f});
}
return 0;
}