本文整理汇总了C++中Linearizer类的典型用法代码示例。如果您正苦于以下问题:C++ Linearizer类的具体用法?C++ Linearizer怎么用?C++ Linearizer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Linearizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
// in order to obtain initial vector for NOX.
info("Projecting initial solution on the FE mesh.");
scalar* coeff_vec = new scalar[Space::get_num_dofs(Hermes::vector<Space*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e))];
OGProjection::project_global(Hermes::vector<Space*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e),
Hermes::vector<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), coeff_vec);
// Filters for visualization of Mach number, pressure and entropy.
MachNumberFilter Mach_number(Hermes::vector<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA);
PressureFilter pressure(Hermes::vector<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA);
EntropyFilter entropy(Hermes::vector<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), KAPPA, RHO_EXT, P_EXT);
ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300));
ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300));
ScalarView entropy_production_view("Entropy estimate", new WinGeom(0, 400, 600, 300));
/*
ScalarView s1("1", new WinGeom(0, 0, 600, 300));
ScalarView s2("2", new WinGeom(700, 0, 600, 300));
ScalarView s3("3", new WinGeom(0, 400, 600, 300));
ScalarView s4("4", new WinGeom(700, 400, 600, 300));
*/
// Initialize NOX solver.
NoxSolver solver(&dp, NOX_MESSAGE_TYPE);
solver.set_ls_tolerance(NOX_LINEAR_TOLERANCE);
solver.disable_abs_resid();
solver.set_conv_rel_resid(NOX_NONLINEAR_TOLERANCE);
if(PRECONDITIONING) {
RCP<Precond> pc = rcp(new MlPrecond("sa"));
solver.set_precond(pc);
}
int iteration = 0; double t = 0;
for(t = 0.0; t < 3.0; t += time_step) {
info("---- Time step %d, time %3.5f.", iteration++, t);
OGProjection::project_global(Hermes::vector<Space*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e),
Hermes::vector<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), coeff_vec);
solver.set_init_sln(coeff_vec);
info("Assembling by DiscreteProblem, solving by NOX.");
if (solver.solve())
Solution::vector_to_solutions(solver.get_solution(), Hermes::vector<Space*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e),
Hermes::vector<Solution *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e));
else
error("NOX failed.");
// Visualization.
if((iteration - 1) % EVERY_NTH_STEP == 0) {
// Hermes visualization.
if(HERMES_VISUALIZATION) {
Mach_number.reinit();
pressure.reinit();
entropy.reinit();
pressure_view.show(&pressure);
entropy_production_view.show(&entropy);
Mach_number_view.show(&Mach_number);
/*
s1.show(&prev_rho);
s2.show(&prev_rho_v_x);
s3.show(&prev_rho_v_y);
s4.show(&prev_e);
*/
}
// Output solution in VTK format.
if(VTK_VISUALIZATION) {
pressure.reinit();
Mach_number.reinit();
Linearizer lin;
char filename[40];
sprintf(filename, "pressure-%i.vtk", iteration - 1);
lin.save_solution_vtk(&pressure, filename, "Pressure", false);
sprintf(filename, "pressure-3D-%i.vtk", iteration - 1);
lin.save_solution_vtk(&pressure, filename, "Pressure", true);
sprintf(filename, "Mach number-%i.vtk", iteration - 1);
lin.save_solution_vtk(&Mach_number, filename, "MachNumber", false);
sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1);
lin.save_solution_vtk(&Mach_number, filename, "MachNumber", true);
}
}
info("Number of nonlin iterations: %d (norm of residual: %g)",
solver.get_num_iters(), solver.get_residual());
info("Total number of iterations in linsolver: %d (achieved tolerance in the last step: %g)",
solver.get_num_lin_iters(), solver.get_achieved_tol());
}
pressure_view.close();
entropy_production_view.close();
Mach_number_view.close();
/*
s1.close();
s2.close();
s3.close();
s4.close();
*/
return 0;
}
示例2: main
int main() {
// Create coarse mesh, set Dirichlet BC, enumerate
// basis functions
Mesh *mesh = new Mesh(A, B, N_elem, P_init, N_eq);
mesh->set_bc_left_dirichlet(0, Val_dir_left);
mesh->set_bc_right_dirichlet(0, Val_dir_right);
mesh->assign_dofs();
// Create discrete problem on coarse mesh
DiscreteProblem *dp = new DiscreteProblem();
dp->add_matrix_form(0, 0, jacobian);
dp->add_vector_form(0, residual);
// Convergence graph wrt. the number of degrees of freedom
GnuplotGraph graph;
graph.set_log_y();
graph.set_captions("Convergence History", "Degrees of Freedom", "Error");
graph.add_row("exact error [%]", "k", "-", "o");
graph.add_row("max FTR error", "k", "--");
// Main adaptivity loop
int adapt_iterations = 1;
double ftr_errors[MAX_ELEM_NUM]; // This array decides what
// elements will be refined.
ElemPtr2 ref_ftr_pairs[MAX_ELEM_NUM]; // To store element pairs from the
// FTR solution. Decides how
// elements will be hp-refined.
for (int i=0; i < MAX_ELEM_NUM; i++) {
ref_ftr_pairs[i][0] = new Element();
ref_ftr_pairs[i][1] = new Element();
}
while(1) {
printf("============ Adaptivity step %d ============\n", adapt_iterations);
printf("N_dof = %d\n", mesh->get_n_dof());
// Newton's loop on coarse mesh
newton(dp, mesh, NULL, NEWTON_TOL_COARSE, NEWTON_MAXITER);
// For every element perform its fast trial refinement (FTR),
// calculate the norm of the difference between the FTR
// solution and the coarse mesh solution, and store the
// error in the ftr_errors[] array.
int n_elem = mesh->get_n_active_elem();
for (int i=0; i < n_elem; i++) {
printf("=== Starting FTR of Elem [%d]\n", i);
// Replicate coarse mesh including solution.
Mesh *mesh_ref_local = mesh->replicate();
// Perform FTR of element 'i'
mesh_ref_local->reference_refinement(i, 1);
printf("Elem [%d]: fine mesh created (%d DOF).\n",
i, mesh_ref_local->assign_dofs());
// Newton's loop on the FTR mesh
newton(dp, mesh_ref_local, NULL, NEWTON_TOL_REF, NEWTON_MAXITER);
// Print FTR solution (enumerated)
Linearizer *lxx = new Linearizer(mesh_ref_local);
char out_filename[255];
sprintf(out_filename, "solution_ref_%d.gp", i);
lxx->plot_solution(out_filename);
delete lxx;
// Calculate norm of the difference between the coarse mesh
// and FTR solutions.
// NOTE: later we want to look at the difference in some quantity
// of interest rather than error in global norm.
double err_est_array[MAX_ELEM_NUM];
ftr_errors[i] = calc_error_estimate(NORM, mesh, mesh_ref_local,
err_est_array);
//printf("Elem [%d]: absolute error (est) = %g\n", i, ftr_errors[i]);
// Copy the reference element pair for element 'i'
// into the ref_ftr_pairs[i][] array
Iterator *I = new Iterator(mesh);
Iterator *I_ref = new Iterator(mesh_ref_local);
Element *e, *e_ref;
while (1) {
e = I->next_active_element();
e_ref = I_ref->next_active_element();
if (e->id == i) {
e_ref->copy_into(ref_ftr_pairs[e->id][0]);
// coarse element 'e' was split in space
if (e->level != e_ref->level) {
e_ref = I_ref->next_active_element();
e_ref->copy_into(ref_ftr_pairs[e->id][1]);
}
break;
}
}
delete I;
delete I_ref;
delete mesh_ref_local;
}
// If exact solution available, also calculate exact error
//.........这里部分代码省略.........
示例3: main
int main(int argc, char* argv[])
{
// Load the mesh.
MeshSharedPtr mesh(new Mesh);
if (USE_XML_FORMAT == true)
{
MeshReaderH2DXML mloader;
Hermes::Mixins::Loggable::Static::info("Reading mesh in XML format.");
try
{
mloader.load("domain.xml", mesh);
}
catch(Hermes::Exceptions::Exception& e)
{
e.print_msg();
}
}
else
{
MeshReaderH2D mloader;
Hermes::Mixins::Loggable::Static::info("Reading mesh in original format.");
mloader.load("domain.mesh", mesh);
}
// Perform initial mesh refinements (optional).
for (int i = 0; i < INIT_REF_NUM; i++)
mesh->refine_all_elements();
// Initialize the weak formulation.
CustomWeakFormPoisson wf("Aluminum", new Hermes1DFunction<double>(LAMBDA_AL),
"Copper", new Hermes1DFunction<double>(LAMBDA_CU),
new Hermes2DFunction<double>(-VOLUME_HEAT_SRC));
// Initialize essential boundary conditions.
DefaultEssentialBCConst<double> bc_essential(
Hermes::vector<std::string>("Bottom", "Inner", "Outer", "Left"), FIXED_BDY_TEMP);
EssentialBCs<double> bcs(&bc_essential);
// Create an H1 space with default shapeset.
SpaceSharedPtr<double> space(new H1Space<double>(mesh, &bcs, P_INIT));
int ndof = space->get_num_dofs();
Hermes::Mixins::Loggable::Static::info("ndof = %d", ndof);
// Initialize the FE problem.
DiscreteProblem<double> dp(&wf, space);
// Initialize Newton solver.
NewtonSolver<double> newton(&dp);
// Perform Newton's iteration.
try
{
// When newton.solve() is used without any parameters, this means that the initial coefficient
// vector will be the zero vector, tolerance will be 1e-8, maximum allowed number of iterations
// will be 100, and residual will be measured using Euclidean vector norm.
newton.solve();
}
catch(std::exception& e)
{
std::cout << e.what();
}
// Translate the resulting coefficient vector into a Solution.
MeshFunctionSharedPtr<double> sln(new Solution<double>);
Solution<double>::vector_to_solution(newton.get_sln_vector(), space, sln);
// VTK output.
if (VTK_VISUALIZATION)
{
// Output solution in VTK format.
Linearizer lin;
bool mode_3D = true;
lin.save_solution_vtk(sln, "sln.vtk", "Temperature", mode_3D);
Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk");
// Output mesh and element orders in VTK format.
Orderizer ord;
ord.save_orders_vtk(space, "ord.vtk");
Hermes::Mixins::Loggable::Static::info("Element orders in VTK format saved to file %s.", "ord.vtk");
}
// Visualize the solution.
if (HERMES_VISUALIZATION)
{
ScalarView view("Solution", new WinGeom(0, 0, 440, 350));
// Hermes uses adaptive FEM to approximate higher-order FE solutions with linear
// triangles for OpenGL. The second parameter of View::show() sets the error
// tolerance for that. Options are HERMES_EPS_LOW, HERMES_EPS_NORMAL (default),
// HERMES_EPS_HIGH and HERMES_EPS_VERYHIGH. The size of the graphics file grows
// considerably with more accurate representation, so use it wisely.
view.show(sln, HERMES_EPS_HIGH);
View::wait();
}
return 0;
}
示例4: main
int main(int argc, char* argv[])
{
// Load the mesh.
Mesh mesh;
H2DReader mloader;
mloader.load("cathedral.mesh", &mesh);
// Perform initial mesh refinements.
for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements();
mesh.refine_towards_boundary(bdy_air, INIT_REF_NUM_BDY);
// Initialize an H1 space with default shepeset.
H1Space space(&mesh, bc_types, essential_bc_values, P_INIT);
int ndof = get_num_dofs(&space);
info("ndof = %d.", ndof);
// Set initial condition.
Solution tsln;
tsln.set_const(&mesh, T_INIT);
// Initialize weak formulation.
WeakForm wf;
wf.add_matrix_form(bilinear_form<double, double>, bilinear_form<Ord, Ord>);
wf.add_matrix_form_surf(bilinear_form_surf<double, double>, bilinear_form_surf<Ord, Ord>, bdy_air);
wf.add_vector_form(linear_form<double, double>, linear_form<Ord, Ord>, H2D_ANY, &tsln);
wf.add_vector_form_surf(linear_form_surf<double, double>, linear_form_surf<Ord, Ord>, bdy_air);
// Initialize the linear problem.
LinearProblem lp(&wf, &space);
// Initialize matrix solver.
Matrix* mat; Vector* rhs; CommonSolver* solver;
init_matrix_solver(matrix_solver, ndof, mat, rhs, solver);
// Time stepping:
int nsteps = (int)(FINAL_TIME/TAU + 0.5);
bool rhsonly = false;
for(int ts = 1; ts <= nsteps; ts++)
{
info("---- Time step %d, time %3.5f, ext_temp %g", ts, TIME, temp_ext(TIME));
// Assemble stiffness matrix and rhs.
lp.assemble(mat, rhs, rhsonly);
rhsonly = true;
// Solve the matrix problem.
if (!solver->solve(mat, rhs)) error ("Matrix solver failed.\n");
// Update tsln.
tsln.set_fe_solution(&space, rhs);
if (ts % OUTPUT_FREQUENCY == 0) {
Linearizer lin;
int item = H2D_FN_VAL_0;
double eps = H2D_EPS_NORMAL;
double max_abs = -1.0;
MeshFunction* xdisp = NULL;
MeshFunction* ydisp = NULL;
double dmult = 1.0;
lin.process_solution(&tsln, item, eps, max_abs, xdisp, ydisp, dmult);
char* filename = new char[100];
sprintf(filename, "tsln_%d.lin", ts);
// Save Linearizer data.
lin.save_data(filename);
info("Linearizer data saved to file %s.", filename);
// Save complete Solution.
sprintf(filename, "tsln_%d.dat", ts);
bool compress = false; // Gzip compression not used as it only works on Linux.
tsln.save(filename, compress);
info("Complete Solution saved to file %s.", filename);
}
// Update the time variable.
TIME += TAU;
}
info("Let's assume that the remote computation has finished and you fetched the *.lin files.");
info("Visualizing Linearizer data from file tsln_40.lin.");
// First use ScalarView to read and show the Linearizer data.
WinGeom* win_geom_1 = new WinGeom(0, 0, 450, 600);
ScalarView sview_1("Saved Linearizer data", win_geom_1);
sview_1.lin.load_data("tsln_40.lin");
sview_1.set_min_max_range(0,20);
sview_1.fix_scale_width(3);
sview_1.show_linearizer_data();
info("Visualizing Solution from file tsln_60.dat.");
Solution sln_from_file;
sln_from_file.load("tsln_60.dat");
WinGeom* win_geom_2 = new WinGeom(460, 0, 450, 600);
ScalarView sview_2("Saved Solution data", win_geom_2);
sview_2.set_min_max_range(0,20);
sview_2.fix_scale_width(3);
sview_2.show(&sln_from_file);
info("Visualizing Mesh and Orders extracted from the Solution.");
//.........这里部分代码省略.........
示例5: main
//.........这里部分代码省略.........
// Select preconditioner.
if(PRECONDITIONING)
{
RCP<Precond<double> > pc = rcp(new Preconditioners::MlPrecond<double>("sa"));
solver.set_precond(pc);
}
int iteration = 0; double t = 0;
for(t = 0.0; t < 100.0; t += time_step)
{
info("---- Time step %d, time %3.5f.", iteration++, t);
OGProjection<double>::project_global(Hermes::vector<Space<double>*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_c),
Hermes::vector<MeshFunction<double>*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_c), coeff_vec);
info("Assembling by DiscreteProblem, solving by NOX.");
if (solver.solve(coeff_vec))
Solution<double>::vector_to_solutions(solver.get_sln_vector(), Hermes::vector<Space<double>*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_c),
Hermes::vector<Solution<double>*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_c));
else
error("NOX failed.");
util_time_step = time_step;
CFL.calculate(Hermes::vector<Solution<double>*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e), &mesh_flow, util_time_step);
time_step = util_time_step;
ADES.calculate(Hermes::vector<Solution<double>*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y), &mesh_concentration, util_time_step);
if(util_time_step < time_step)
time_step = util_time_step;
// Visualization.
if((iteration - 1) % EVERY_NTH_STEP == 0) {
// Hermes visualization.
if(HERMES_VISUALIZATION)
{ /*
Mach_number.reinit();
pressure.reinit();
entropy.reinit();
pressure_view.show(&pressure);
entropy_production_view.show(&entropy);
Mach_number_view.show(&Mach_number);
s5.show(&prev_c);
*/
s1.show(&prev_rho);
s2.show(&prev_rho_v_x);
s3.show(&prev_rho_v_y);
s4.show(&prev_e);
s5.show(&prev_c);
/*
s1.save_numbered_screenshot("density%i.bmp", iteration, true);
s2.save_numbered_screenshot("density_v_x%i.bmp", iteration, true);
s3.save_numbered_screenshot("density_v_y%i.bmp", iteration, true);
s4.save_numbered_screenshot("energy%i.bmp", iteration, true);
s5.save_numbered_screenshot("concentration%i.bmp", iteration, true);
*/
//s5.wait_for_close();
}
// Output solution in VTK format.
if(VTK_VISUALIZATION)
{
pressure.reinit();
Mach_number.reinit();
Linearizer<double> lin;
char filename[40];
sprintf(filename, "pressure-%i.vtk", iteration - 1);
lin.save_solution_vtk(&pressure, filename, "Pressure", false);
sprintf(filename, "pressure-3D-%i.vtk", iteration - 1);
lin.save_solution_vtk(&pressure, filename, "Pressure", true);
sprintf(filename, "Mach number-%i.vtk", iteration - 1);
lin.save_solution_vtk(&Mach_number, filename, "MachNumber", false);
sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1);
lin.save_solution_vtk(&Mach_number, filename, "MachNumber", true);
sprintf(filename, "Concentration-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_c, filename, "Concentration", true);
sprintf(filename, "Concentration-3D-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_c, filename, "Concentration", true);
}
}
}
/*
pressure_view.close();
entropy_production_view.close();
Mach_number_view.close();
s5.close();
*/
s1.close();
s2.close();
s3.close();
s4.close();
s5.close();
return 0;
}
示例6: main
//.........这里部分代码省略.........
ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300));
ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300));
ScalarView entropy_production_view("Entropy estimate", new WinGeom(0, 400, 600, 300));
VectorView vview("Velocity", new WinGeom(700, 400, 600, 300));
*/
ScalarView s1("w0", new WinGeom(0, 0, 600, 300));
ScalarView s2("w1", new WinGeom(700, 0, 600, 300));
ScalarView s3("w2", new WinGeom(0, 400, 600, 300));
ScalarView s4("w3", new WinGeom(700, 400, 600, 300));
ScalarView s5("Concentration", new WinGeom(350, 200, 600, 300));
// Iteration number.
int iteration = 0;
// Output of the approximate time derivative.
std::ofstream time_der_out("time_der");
// Initialize NOX solver.
NoxSolver solver(&dp);
solver.set_ls_tolerance(1E-2);
solver.disable_abs_resid();
solver.set_conv_rel_resid(1.00);
// Select preconditioner.
if(PRECONDITIONING) {
RCP<Precond> pc = rcp(new MlPrecond("sa"));
solver.set_precond(pc);
}
for(t = 0.0; t < 3.0; t += TAU)
{
info("---- Time step %d, time %3.5f.", iteration++, t);
OGProjection::project_global(Hermes::vector<Space*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_c),
Hermes::vector<MeshFunction*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_c), coeff_vec);
info("Assembling by DiscreteProblem, solving by NOX.");
solver.set_init_sln(coeff_vec);
if (solver.solve())
Solution::vector_to_solutions(solver.get_solution(), Hermes::vector<Space*>(&space_rho, &space_rho_v_x, &space_rho_v_y, &space_e, &space_c),
Hermes::vector<Solution *>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e, &prev_c));
else
error("NOX failed.");
/*
// Visualization.
pressure.reinit();
u.reinit();
w.reinit();
Mach_number.reinit();
entropy_estimate.reinit();
pressure_view.show(&pressure);
entropy_production_view.show(&entropy_estimate);
Mach_number_view.show(&Mach_number);
vview.show(&u, &w);
*/
info("Number of nonlin iterations: %d (norm of residual: %g)",
solver.get_num_iters(), solver.get_residual());
info("Total number of iterations in linsolver: %d (achieved tolerance in the last step: %g)",
solver.get_num_lin_iters(), solver.get_achieved_tol());
// Visualization.
if((iteration - 1) % EVERY_NTH_STEP == 0) {
// Hermes visualization.
if(HERMES_VISUALIZATION) {
s1.show(&prev_rho);
s2.show(&prev_rho_v_x);
s3.show(&prev_rho_v_y);
s4.show(&prev_e);
s5.show(&prev_c);
}
// Output solution in VTK format.
if(VTK_OUTPUT) {
Linearizer lin;
char filename[40];
sprintf(filename, "w0-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_rho, filename, "w0", false);
sprintf(filename, "w1-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_rho_v_x, filename, "w1", false);
sprintf(filename, "w2-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_rho_v_y, filename, "w2", false);
sprintf(filename, "w3-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_e, filename, "w3", false);
sprintf(filename, "concentration-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_c, filename, "concentration", false);
}
}
}
s1.close();
s2.close();
s3.close();
s4.close();
s5.close();
time_der_out.close();
return 0;
}
示例7: main
//.........这里部分代码省略.........
order_view_flow.show((*ref_spaces_local)[0]);
order_view_conc.show((*ref_spaces_local)[1]);
order_view_flow.save_numbered_screenshot("FlowMesh%i.bmp", (int)(iteration / 5), true);
order_view_conc.save_numbered_screenshot("ConcentrationMesh%i.bmp", (int)(iteration / 5), true);
for(unsigned int i = 0; i < ref_spaces_local->size(); i++) {
delete (*ref_spaces_local)[i]->get_mesh();
delete (*ref_spaces_local)[i];
}
}
if(VTK_VISUALIZATION)
{
Orderizer ord;
char filename[40];
sprintf(filename, "Flow-mesh-%i.vtk", iteration - 1);
ord.save_orders_vtk((*ref_spaces)[0], filename);
sprintf(filename, "Concentration-mesh-%i.vtk", iteration - 1);
ord.save_orders_vtk((*ref_spaces)[4], filename);
}
}
// Clean up.
delete solver;
delete matrix;
delete rhs;
for(unsigned int i = 0; i < ref_spaces->size(); i++)
delete (*ref_spaces)[i];
}
while (done == false);
// Copy the solutions into the previous time level ones.
prev_rho.copy(&rsln_rho);
prev_rho_v_x.copy(&rsln_rho_v_x);
prev_rho_v_y.copy(&rsln_rho_v_y);
prev_e.copy(&rsln_e);
prev_c.copy(&rsln_c);
delete rsln_rho.get_mesh();
delete rsln_rho_v_x.get_mesh();
delete rsln_rho_v_y.get_mesh();
delete rsln_e.get_mesh();
delete rsln_c.get_mesh();
// Visualization.
if((iteration - 1) % EVERY_NTH_STEP == 0) {
// Hermes visualization.
if(HERMES_VISUALIZATION)
{
Mach_number.reinit();
pressure.reinit();
pressure_view.show_mesh(false);
pressure_view.show(&pressure);
pressure_view.set_scale_format("%1.3f");
Mach_number_view.show_mesh(false);
Mach_number_view.set_scale_format("%1.3f");
Mach_number_view.show(&Mach_number);
s5.show_mesh(false);
s5.set_scale_format("%0.3f");
s5.show(&prev_c);
pressure_view.save_numbered_screenshot("pressure%i.bmp", (int)(iteration / 5), true);
Mach_number_view.save_numbered_screenshot("Mach_number%i.bmp", (int)(iteration / 5), true);
s5.save_numbered_screenshot("concentration%i.bmp", (int)(iteration / 5), true);
}
// Output solution in VTK format.
if(VTK_VISUALIZATION)
{
pressure.reinit();
Mach_number.reinit();
Linearizer<double> lin;
char filename[40];
//sprintf(filename, "pressure-%i.vtk", iteration - 1);
//lin.save_solution_vtk(&pressure, filename, "Pressure", false);
sprintf(filename, "pressure-3D-%i.vtk", iteration - 1);
lin.save_solution_vtk(&pressure, filename, "Pressure", true);
//sprintf(filename, "Mach number-%i.vtk", iteration - 1);
//lin.save_solution_vtk(&Mach_number, filename, "MachNumber", false);
sprintf(filename, "Mach number-3D-%i.vtk", iteration - 1);
lin.save_solution_vtk(&Mach_number, filename, "MachNumber", true);
//sprintf(filename, "Concentration-%i.vtk", iteration - 1);
//lin.save_solution_vtk(&prev_c, filename, "Concentration", true);
sprintf(filename, "Concentration-3D-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_c, filename, "Concentration", true);
}
}
}
/*
pressure_view.close();
entropy_production_view.close();
Mach_number_view.close();
s5.close();
*/
return 0;
}
示例8: main
int main(int argc, char* argv[])
{
// Instantiate a class with global functions.
Hermes2D hermes2d;
// Load the mesh.
Mesh mesh;
H2DReader mloader;
mloader.load("domain.mesh", &mesh);
// Perform initial mesh refinements (optional).
for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements();
// Initialize the weak formulation.
CustomWeakForm wf;
// Initialize boundary conditions.
CustomDirichletCondition bc_essential(Hermes::vector<std::string>("Bdy"),
BDY_A_PARAM, BDY_B_PARAM, BDY_C_PARAM);
EssentialBCs bcs(&bc_essential);
// Create an H1 space with default shapeset.
H1Space space(&mesh, &bcs, P_INIT);
int ndof = space.get_num_dofs();
info("ndof = %d", ndof);
// Initialize the FE problem.
DiscreteProblem dp(&wf, &space);
// Set up the solver, matrix, and rhs according to the solver selection.
SparseMatrix* matrix = create_matrix(matrix_solver);
Vector* rhs = create_vector(matrix_solver);
Solver* solver = create_linear_solver(matrix_solver, matrix, rhs);
// Initial coefficient vector for the Newton's method.
scalar* coeff_vec = new scalar[ndof];
memset(coeff_vec, 0, ndof*sizeof(scalar));
// Perform Newton's iteration.
bool jacobian_changed = true;
double newton_tol = 1e-8;
int newton_max_iter = 100;
bool verbose = true;
if (!hermes2d.solve_newton(coeff_vec, &dp, solver, matrix, rhs, jacobian_changed,
newton_tol, newton_max_iter, verbose)) error("Newton's iteration failed.");
// Translate the resulting coefficient vector into the Solution sln.
Solution sln;
Solution::vector_to_solution(coeff_vec, &space, &sln);
// VTK output.
if (VTK_VISUALIZATION) {
// Output solution in VTK format.
Linearizer lin;
bool mode_3D = true;
lin.save_solution_vtk(&sln, "sln.vtk", "Temperature", mode_3D);
info("Solution in VTK format saved to file %s.", "sln.vtk");
// Output mesh and element orders in VTK format.
Orderizer ord;
ord.save_orders_vtk(&space, "ord.vtk");
info("Element orders in VTK format saved to file %s.", "ord.vtk");
}
// Visualize the solution.
if (HERMES_VISUALIZATION) {
ScalarView view("Solution", new WinGeom(0, 0, 440, 350));
view.show(&sln, HERMES_EPS_HIGH);
View::wait();
}
// Clean up.
delete solver;
delete matrix;
delete rhs;
delete [] coeff_vec;
return 0;
}
示例9: main
int main(int argc, char* argv[])
{
// Load the mesh.
Mesh mesh;
H2DReader mloader;
mloader.load("domain.mesh", &mesh);
// Perform initial mesh refinements (optional).
//mesh.refine_all_elements();
// Initialize boundary conditions
DefaultEssentialBCConst bc_essential(Hermes::vector<std::string>(BDY_BOTTOM, BDY_OUTER, BDY_LEFT, BDY_INNER), 0.0);
EssentialBCs bcs(&bc_essential);
// Create an H1 space with default shapeset.
H1Space space(&mesh, &bcs, P_INIT);
int ndof = Space::get_num_dofs(&space);
info("ndof = %d", ndof);
// Initialize the weak formulation. Not providing the order determination form
// (or callback) turns on adaptive numerical quadrature. The quadrature begins
// with using a first-order rule in the entire element. Then the element is split
// uniformly in space and the quadrature order is increased by "adapt_order_increase".
// Then the form is calculated again by employing the new quadrature in subelements.
// This provides a more accurate result. If relative error is less than
// "adapt_rel_error_tol", the computation stops, otherwise the same procedure is
// applied recursively to all four subelements.
int adapt_order_increase = 1;
double adapt_rel_error_tol = 1e1;
WeakFormPoisson wf(CONST_F, ADAPTIVE_QUADRATURE, adapt_order_increase, adapt_rel_error_tol);
if (ADAPTIVE_QUADRATURE)
info("Adaptive quadrature ON.");
else
info("Adaptive quadrature OFF.");
// Initialize the FE problem.
bool is_linear = true;
DiscreteProblem dp(&wf, &space, is_linear);
// Set up the solver, matrix, and rhs according to the solver selection.
SparseMatrix* matrix = create_matrix(matrix_solver);
Vector* rhs = create_vector(matrix_solver);
Solver* solver = create_linear_solver(matrix_solver, matrix, rhs);
// Initialize the solution.
Solution sln;
// Assemble the stiffness matrix and right-hand side vector.
info("Assembling the stiffness matrix and right-hand side vector.");
dp.assemble(matrix, rhs);
// Solve the linear system and if successful, obtain the solution.
info("Solving the matrix problem.");
if(solver->solve()) Solution::vector_to_solution(solver->get_solution(), &space, &sln);
else error ("Matrix solver failed.\n");
// VTK output.
if (VTK_VISUALIZATION) {
// Output solution in VTK format.
Linearizer lin;
bool mode_3D = true;
lin.save_solution_vtk(&sln, "sln.vtk", "Temperature", mode_3D);
info("Solution in VTK format saved to file %s.", "sln.vtk");
// Output mesh and element orders in VTK format.
Orderizer ord;
ord.save_orders_vtk(&space, "ord.vtk");
info("Element orders in VTK format saved to file %s.", "ord.vtk");
}
// Visualize the solution.
if (HERMES_VISUALIZATION) {
ScalarView view("Solution", new WinGeom(0, 0, 440, 350));
view.show(&sln);
View::wait();
}
// Clean up.
delete solver;
delete matrix;
delete rhs;
return 0;
}
示例10: main
//.........这里部分代码省略.........
DiscreteProblem<std::complex<double> > dp(&wf, ref_space);
// Time measurement.
cpu_time.tick();
// Perform Newton's iteration.
Hermes::Hermes2D::NewtonSolver<std::complex<double> > newton(&dp);
try
{
newton.set_newton_max_iter(NEWTON_MAX_ITER);
newton.set_newton_tol(NEWTON_TOL);
newton.solve();
}
catch(Hermes::Exceptions::Exception e)
{
e.print_msg();
throw Hermes::Exceptions::Exception("Newton's iteration failed.");
};
// Translate the resulting coefficient vector into the Solution<std::complex<double> > sln.
Hermes::Hermes2D::Solution<std::complex<double> >::vector_to_solution(newton.get_sln_vector(), ref_space, &ref_sln);
// Project the fine mesh solution onto the coarse mesh.
Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh.");
OGProjection<std::complex<double> > ogProjection; ogProjection.project_global(&space, &ref_sln, &sln);
// View the coarse mesh solution and polynomial orders.
RealFilter real(&sln);
MagFilter<double> magn(&real);
ValFilter limited_magn(&magn, 0.0, 4e3);
char title[100];
sprintf(title, "Electric field, adaptivity step %d", as);
eview.set_title(title);
//eview.set_min_max_range(0.0, 4e3);
eview.show(&limited_magn);
sprintf(title, "Polynomial orders, adaptivity step %d", as);
oview.set_title(title);
oview.show(&space);
// Calculate element errors and total error estimate.
Hermes::Mixins::Loggable::Static::info("Calculating error estimate.");
Adapt<std::complex<double> >* adaptivity = new Adapt<std::complex<double> >(&space);
// Set custom error form and calculate error estimate.
CustomErrorForm cef(kappa);
adaptivity->set_error_form(0, 0, &cef);
double err_est_rel = adaptivity->calc_err_est(&sln, &ref_sln) * 100;
// Report results.
Hermes::Mixins::Loggable::Static::info("ndof_coarse: %d, ndof_fine: %d, err_est_rel: %g%%",
Space<std::complex<double> >::get_num_dofs(&space),
Space<std::complex<double> >::get_num_dofs(ref_space), err_est_rel);
// Time measurement.
cpu_time.tick();
// Add entry to DOF and CPU convergence graphs.
graph_dof.add_values(Space<std::complex<double> >::get_num_dofs(&space), err_est_rel);
graph_dof.save("conv_dof_est.dat");
graph_cpu.add_values(cpu_time.accumulated(), err_est_rel);
graph_cpu.save("conv_cpu_est.dat");
// If err_est too large, adapt the mesh.
if (err_est_rel < ERR_STOP) done = true;
else
{
Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh.");
done = adaptivity->adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY);
}
if (space.get_num_dofs() >= NDOF_STOP) done = true;
delete adaptivity;
if(!done)
{
delete ref_space->get_mesh();
delete ref_space;
}
// Increase counter.
as++;
}
while (done == false);
Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated());
RealFilter ref_real(&sln);
MagFilter<double> ref_magn(&ref_real);
ValFilter ref_limited_magn(&ref_magn, 0.0, 4e3);
eview.set_title("Fine mesh solution - magnitude");
eview.show(&ref_limited_magn);
// Output solution in VTK format.
Linearizer lin;
bool mode_3D = true;
lin.save_solution_vtk(&ref_limited_magn, "sln.vtk", "Magnitude of E", mode_3D);
Hermes::Mixins::Loggable::Static::info("Solution in VTK format saved to file %s.", "sln.vtk");
// Wait for all views to be closed.
View::wait();
return 0;
}
示例11: main
int main(int argc, char* argv[])
{
// Instantiate a class with global functions.
Hermes2D hermes2d;
// Load the mesh.
Mesh mesh;
H2DReader mloader;
mloader.load("../domain.mesh", &mesh);
// Perform initial mesh refinements (optional).
for (int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements();
// Initialize the weak formulation.
CustomWeakFormPoissonDirichlet wf("Aluminum", LAMBDA_AL, "Copper",
LAMBDA_CU, VOLUME_HEAT_SRC);
// Initialize boundary conditions.
CustomDirichletCondition bc_essential(Hermes::vector<std::string>("Bottom", "Inner", "Outer", "Left"),
BDY_A_PARAM, BDY_B_PARAM, BDY_C_PARAM);
EssentialBCs bcs(&bc_essential);
// Create an H1 space with default shapeset.
H1Space space(&mesh, &bcs, P_INIT);
int ndof = space.get_num_dofs();
info("ndof = %d", ndof);
// Initialize the FE problem.
DiscreteProblem dp(&wf, &space);
// Set up the solver, matrix, and rhs according to the solver selection.
SparseMatrix* matrix = create_matrix(matrix_solver);
Vector* rhs = create_vector(matrix_solver);
Solver* solver = create_linear_solver(matrix_solver, matrix, rhs);
// Initial coefficient vector for the Newton's method.
scalar* coeff_vec = new scalar[ndof];
memset(coeff_vec, 0, ndof*sizeof(scalar));
// Perform Newton's iteration.
if (!hermes2d.solve_newton(coeff_vec, &dp, solver, matrix, rhs)) error("Newton's iteration failed.");
// Translate the resulting coefficient vector into the Solution sln.
Solution sln;
Solution::vector_to_solution(coeff_vec, &space, &sln);
// VTK output.
if (VTK_VISUALIZATION) {
// Output solution in VTK format.
Linearizer lin;
bool mode_3D = true;
lin.save_solution_vtk(&sln, "sln.vtk", "Temperature", mode_3D);
info("Solution in VTK format saved to file %s.", "sln.vtk");
// Output mesh and element orders in VTK format.
Orderizer ord;
ord.save_orders_vtk(&space, "ord.vtk");
info("Element orders in VTK format saved to file %s.", "ord.vtk");
}
ndof = Space::get_num_dofs(&space);
printf("ndof = %d\n", ndof);
double sum = 0;
for (int i=0; i < ndof; i++) sum += coeff_vec[i];
printf("coefficient sum = %g\n", sum);
bool success = true;
if (fabs(sum + 4.2471) > 1e-3) success = 0;
if (success == 1) {
printf("Success!\n");
return ERR_SUCCESS;
}
else {
printf("Failure!\n");
return ERR_FAILURE;
}
}
示例12: main
//.........这里部分代码省略.........
SimpleFilter entropy_estimate(calc_entropy_estimate_func, Hermes::vector<MeshFunction*>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e));
ScalarView pressure_view("Pressure", new WinGeom(0, 0, 600, 300));
ScalarView Mach_number_view("Mach number", new WinGeom(700, 0, 600, 300));
ScalarView entropy_production_view("Entropy estimate", new WinGeom(0, 400, 600, 300));
VectorView vview("Velocity", new WinGeom(700, 400, 600, 300));
*/
ScalarView s1("w0", new WinGeom(0, 0, 600, 300));
ScalarView s2("w1", new WinGeom(700, 0, 600, 300));
ScalarView s3("w2", new WinGeom(0, 400, 600, 300));
ScalarView s4("w3", new WinGeom(700, 400, 600, 300));
ScalarView s5("Concentration", new WinGeom(350, 200, 600, 300));
// Iteration number.
int iteration = 0;
// Set up the solver, matrix, and rhs according to the solver selection.
SparseMatrix* matrix = create_matrix(matrix_solver);
Vector* rhs = create_vector(matrix_solver);
Solver* solver = create_linear_solver(matrix_solver, matrix, rhs);
// Output of the approximate time derivative.
std::ofstream time_der_out("time_der");
for(t = 0.0; t < 3.0; t += TAU) {
info("---- Time step %d, time %3.5f.", iteration++, t);
bool rhs_only = (iteration == 1 ? false : true);
// Assemble stiffness matrix and rhs or just rhs.
if (rhs_only == false) info("Assembling the stiffness matrix and right-hand side vector.");
else info("Assembling the right-hand side vector (only).");
dp.assemble(matrix, rhs, rhs_only);
// Solve the matrix problem.
info("Solving the matrix problem.");
if(solver->solve())
Solution::vector_to_solutions(solver->get_solution(), Hermes::vector<Space *>(&space_rho, &space_rho_v_x,
&space_rho_v_y, &space_e, &space_c), Hermes::vector<Solution *>(&sln_rho, &sln_rho_v_x, &sln_rho_v_y, &sln_e, &sln_c));
else
error ("Matrix solver failed.\n");
// Copy the solutions into the previous time level ones.
prev_rho.copy(&sln_rho);
prev_rho_v_x.copy(&sln_rho_v_x);
prev_rho_v_y.copy(&sln_rho_v_y);
prev_e.copy(&sln_e);
prev_c.copy(&sln_c);
// Visualization.
/*
pressure.reinit();
u.reinit();
w.reinit();
Mach_number.reinit();
entropy_estimate.reinit();
pressure_view.show(&pressure);
entropy_production_view.show(&entropy_estimate);
Mach_number_view.show(&Mach_number);
vview.show(&u, &w);
*/
// Visualization.
if((iteration - 1) % EVERY_NTH_STEP == 0) {
// Hermes visualization.
if(HERMES_VISUALIZATION) {
s1.show(&prev_rho);
s2.show(&prev_rho_v_x);
s3.show(&prev_rho_v_y);
s4.show(&prev_e);
s5.show(&prev_c);
}
// Output solution in VTK format.
if(VTK_OUTPUT) {
Linearizer lin;
char filename[40];
sprintf(filename, "w0-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_rho, filename, "w0", false);
sprintf(filename, "w1-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_rho_v_x, filename, "w1", false);
sprintf(filename, "w2-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_rho_v_y, filename, "w2", false);
sprintf(filename, "w3-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_e, filename, "w3", false);
sprintf(filename, "concentration-%i.vtk", iteration - 1);
lin.save_solution_vtk(&prev_c, filename, "concentration", false);
}
}
}
s1.close();
s2.close();
s3.close();
s4.close();
s5.close();
time_der_out.close();
return 0;
}
示例13: main
//.........这里部分代码省略.........
// NOTE: at least one full iteration forced
// here because sometimes the initial
// residual on fine mesh is too small.
if(res_l2_norm < NEWTON_TOL_REF && it > 1) break;
// Multiply the residual vector with -1 since the matrix
// equation reads J(Y^n) \deltaY^{n+1} = -F(Y^n).
for(int i=0; i<ndof; i++) rhs->set(i, -rhs->get(i));
// Solve the linear system.
if(!solver->solve())
error ("Matrix solver failed.\n");
// Add \deltaY^{n+1} to Y^n.
for (int i = 0; i < ndof; i++) coeff_vec[i] += solver->get_solution()[i];
// If the maximum number of iteration has been reached, then quit.
if (it >= NEWTON_MAX_ITER) error ("Newton method did not converge.");
// Copy coefficients from vector y to elements.
set_coeff_vector(coeff_vec, space_ref_local);
it++;
}
// Cleanup.
delete matrix;
delete rhs;
delete solver;
delete dp;
delete [] coeff_vec;
// Print FTR solution (enumerated).
Linearizer *lxx = new Linearizer(space_ref_local);
char out_filename[255];
sprintf(out_filename, "solution_ref_%d.gp", i);
lxx->plot_solution(out_filename);
delete lxx;
// Calculate norm of the difference between the coarse space
// and FTR solutions.
// NOTE: later we want to look at the difference in some quantity
// of interest rather than error in global norm.
double err_est_array[MAX_ELEM_NUM];
elem_errors[i] = calc_err_est(NORM, space, space_ref_local,
err_est_array) * 100;
info("Elem [%d]: absolute error (est) = %g%%", i, elem_errors[i]);
// Copy the reference element pair for element 'i'.
// into the ref_elem_pairs[i][] array
Iterator *I = new Iterator(space);
Iterator *I_ref = new Iterator(space_ref_local);
Element *e, *e_ref;
while (1) {
e = I->next_active_element();
e_ref = I_ref->next_active_element();
if (e->id == i) {
e_ref->copy_into(ref_elem_pairs[e->id][0]);
// coarse element 'e' was split in space.
if (e->level != e_ref->level) {
e_ref = I_ref->next_active_element();
e_ref->copy_into(ref_elem_pairs[e->id][1]);
}
break;
}
}
示例14: main
int main(int argc, char* argv[])
{
// Load the mesh.
Mesh mesh;
H2DReader mloader;
mloader.load("motor.mesh", &mesh);
// Enter boundary markers.
BCTypes bc_types;
bc_types.add_bc_dirichlet(Hermes::vector<int>(OUTER_BDY, STATOR_BDY));
// Enter Dirichlet boundary values.
BCValues bc_values;
bc_values.add_const(STATOR_BDY, VOLTAGE);
bc_values.add_const(OUTER_BDY, 0.0);
// Create an H1 space with default shapeset.
H1Space space(&mesh, &bc_types, &bc_values, P_INIT);
// Initialize the weak formulation.
int adapt_order_increase = 1;
double adapt_rel_error_tol = 1e1;
WeakForm wf;
if (ADAPTIVE_QUADRATURE) {
info("Adaptive quadrature ON.");
wf.add_matrix_form(biform1, HERMES_SYM, MATERIAL_1,
Hermes::vector<MeshFunction*>(),
adapt_order_increase, adapt_rel_error_tol);
wf.add_matrix_form(biform2, HERMES_SYM, MATERIAL_2,
Hermes::vector<MeshFunction*>(),
adapt_order_increase, adapt_rel_error_tol);
}
else {
info("Adaptive quadrature OFF.");
wf.add_matrix_form(callback(biform1), HERMES_SYM, MATERIAL_1);
wf.add_matrix_form(callback(biform2), HERMES_SYM, MATERIAL_2);
}
// Initialize coarse and reference mesh solution.
Solution sln, ref_sln;
// Initialize refinement selector.
H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER);
// Initialize views.
ScalarView sview("Solution", new WinGeom(0, 0, 410, 600));
sview.fix_scale_width(50);
sview.show_mesh(false);
OrderView oview("Polynomial orders", new WinGeom(420, 0, 400, 600));
// DOF and CPU convergence graphs initialization.
SimpleGraph graph_dof, graph_cpu;
// Time measurement.
TimePeriod cpu_time;
cpu_time.tick();
// Adaptivity loop:
int as = 1;
bool done = false;
do
{
info("---- Adaptivity step %d:", as);
// Construct globally refined reference mesh and setup reference space.
Space* ref_space = construct_refined_space(&space);
// Initialize matrix solver.
SparseMatrix* matrix = create_matrix(matrix_solver);
Vector* rhs = create_vector(matrix_solver);
Solver* solver = create_linear_solver(matrix_solver, matrix, rhs);
// Assemble reference problem.
info("Solving on reference mesh.");
bool is_linear = true;
DiscreteProblem* dp = new DiscreteProblem(&wf, ref_space, is_linear);
dp->assemble(matrix, rhs);
// Time measurement.
cpu_time.tick();
// Solve the linear system of the reference problem.
// If successful, obtain the solution.
if(solver->solve()) Solution::vector_to_solution(solver->get_solution(), ref_space, &ref_sln);
else error ("Matrix solver failed.\n");
// Project the fine mesh solution onto the coarse mesh.
info("Projecting reference solution on coarse mesh.");
OGProjection::project_global(&space, &ref_sln, &sln, matrix_solver);
// Time measurement.
cpu_time.tick();
// VTK output.
if (VTK_OUTPUT) {
// Output solution in VTK format.
Linearizer lin;
char* title = new char[100];
sprintf(title, "sln-%d.vtk", as);
lin.save_solution_vtk(&sln, title, "Potential", false);
//.........这里部分代码省略.........
示例15: main
//.........这里部分代码省略.........
Hermes::vector<Solution<double>*>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e)) * 100;
CFL.calculate_semi_implicit(Hermes::vector<Solution<double> *>(&rsln_rho, &rsln_rho_v_x, &rsln_rho_v_y, &rsln_e), (*ref_spaces)[0]->get_mesh(), time_step);
// Report results.
info("err_est_rel: %g%%", err_est_rel_total);
// If err_est too large, adapt the mesh.
if (err_est_rel_total < ERR_STOP)
done = true;
else
{
info("Adapting coarse mesh.");
if (Space<double>::get_num_dofs(Hermes::vector<const Space<double> *>(&space_rho, &space_rho_v_x,
&space_rho_v_y, &space_e)) >= NDOF_STOP)
done = true;
else
{
REFINEMENT_COUNT++;
done = adaptivity->adapt(Hermes::vector<RefinementSelectors::Selector<double> *>(&selector, &selector, &selector, &selector),
THRESHOLD, STRATEGY, MESH_REGULARITY);
}
if(!done)
as++;
}
// Visualization and saving on disk.
if(done && (iteration - 1) % EVERY_NTH_STEP == 0 && iteration > 1)
{
// Hermes visualization.
if(HERMES_VISUALIZATION)
{
Mach_number.reinit();
pressure.reinit();
entropy.reinit();
pressure_view.show(&pressure);
entropy_production_view.show(&entropy);
Mach_number_view.show(&Mach_number);
pressure_view.save_numbered_screenshot("Pressure-%u.bmp", iteration - 1, true);
Mach_number_view.save_numbered_screenshot("Mach-%u.bmp", iteration - 1, true);
}
// Output solution in VTK format.
if(VTK_VISUALIZATION)
{
pressure.reinit();
Mach_number.reinit();
Linearizer lin;
char filename[40];
sprintf(filename, "Pressure-%i.vtk", iteration - 1);
lin.save_solution_vtk(&pressure, filename, "Pressure", false);
sprintf(filename, "Mach number-%i.vtk", iteration - 1);
lin.save_solution_vtk(&Mach_number, filename, "MachNumber", false);
}
// Save a current state on the disk.
if(iteration > 1)
{
continuity.add_record(t);
continuity.get_last_record()->save_mesh(&mesh);
continuity.get_last_record()->save_spaces(Hermes::vector<Space<double> *>(&space_rho, &space_rho_v_x,
&space_rho_v_y, &space_e));
continuity.get_last_record()->save_solutions(Hermes::vector<Solution<double>*>(&prev_rho, &prev_rho_v_x, &prev_rho_v_y, &prev_e));
continuity.get_last_record()->save_time_step_length(time_step);
}
}
// Clean up.
delete solver;
delete matrix;
delete rhs;
delete adaptivity;
}
while (done == false);
// Copy the solutions into the previous time level ones.
prev_rho.copy(&rsln_rho);
prev_rho_v_x.copy(&rsln_rho_v_x);
prev_rho_v_y.copy(&rsln_rho_v_y);
prev_e.copy(&rsln_e);
delete rsln_rho.get_mesh();
delete rsln_rho.get_space();
rsln_rho.own_mesh = false;
delete rsln_rho_v_x.get_mesh();
delete rsln_rho_v_x.get_space();
rsln_rho_v_x.own_mesh = false;
delete rsln_rho_v_y.get_mesh();
delete rsln_rho_v_y.get_space();
rsln_rho_v_y.own_mesh = false;
delete rsln_e.get_mesh();
delete rsln_e.get_space();
rsln_e.own_mesh = false;
}
pressure_view.close();
entropy_production_view.close();
Mach_number_view.close();
return 0;
}