本文整理汇总了C++中Space::get_mesh方法的典型用法代码示例。如果您正苦于以下问题:C++ Space::get_mesh方法的具体用法?C++ Space::get_mesh怎么用?C++ Space::get_mesh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Space
的用法示例。
在下文中一共展示了Space::get_mesh方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
// Time measurement.
TimePeriod cpu_time;
cpu_time.tick();
// Load the mesh.
Mesh mesh, basemesh;
H2DReader mloader;
mloader.load("domain.mesh", &basemesh);
// Perform initial mesh refinements.
mesh.copy(&basemesh);
for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements();
mesh.refine_towards_boundary(3, INIT_REF_NUM_BDY);
// Create an H1 space with default shapeset.
H1Space space(&mesh, bc_types, essential_bc_values, P_INIT);
int ndof = Space::get_num_dofs(&space);
info("ndof = %d.", ndof);
// Create an H1 space for the initial coarse mesh solution.
H1Space init_space(&basemesh, bc_types, essential_bc_values, P_INIT);
// Create a selector which will select optimal candidate.
H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER);
// Solutions for the time stepping and the Newton's method.
Solution sln, ref_sln, sln_prev_time;
// Adapt mesh to represent initial condition with given accuracy.
info("Mesh adaptivity to an exact function:");
// Initialize views.
char title_init[200];
sprintf(title_init, "Projection of initial condition");
ScalarView* view_init = new ScalarView(title_init, new WinGeom(0, 0, 410, 300));
sprintf(title_init, "Initial mesh");
OrderView* ordview_init = new OrderView(title_init, new WinGeom(420, 0, 350, 300));
view_init->fix_scale_width(80);
int as = 1; bool done = false;
do
{
// Setup space for the reference solution.
Space *rspace = construct_refined_space(&init_space);
// Assign the function f() to the fine mesh.
ref_sln.set_exact(rspace->get_mesh(), init_cond);
// Project the function f() on the coarse mesh.
OGProjection::project_global(&init_space, &ref_sln, &sln_prev_time, matrix_solver);
// Calculate element errors and total error estimate.
Adapt adaptivity(&init_space, HERMES_H1_NORM);
bool solutions_for_adapt = true;
double err_est_rel = adaptivity.calc_err_est(&sln_prev_time, &ref_sln, solutions_for_adapt,
HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL) * 100;
info("Step %d, ndof %d, proj_error %g%%", as, Space::get_num_dofs(&init_space), err_est_rel);
// If err_est_rel too large, adapt the mesh.
if (err_est_rel < ERR_STOP) done = true;
else {
double to_be_processed = 0;
done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY, to_be_processed);
if (Space::get_num_dofs(&init_space) >= NDOF_STOP) done = true;
view_init->show(&sln_prev_time);
char title_init[100];
sprintf(title_init, "Initial mesh, step %d", as);
ordview_init->set_title(title_init);
ordview_init->show(&init_space);
}
as++;
}
while (done == false);
// Initialize the weak formulation.
WeakForm wf;
if (TIME_INTEGRATION == 1) {
wf.add_matrix_form(jac_form_vol_euler, jac_form_vol_ord, HERMES_UNSYM, HERMES_ANY,
&sln_prev_time);
wf.add_matrix_form_surf(jac_form_surf_1_euler, jac_form_surf_1_ord, BDY_1);
wf.add_matrix_form_surf(jac_form_surf_4_euler, jac_form_surf_4_ord, BDY_4);
wf.add_matrix_form_surf(jac_form_surf_6_euler, jac_form_surf_6_ord, BDY_6);
wf.add_vector_form(res_form_vol_euler, res_form_vol_ord, HERMES_ANY,
&sln_prev_time);
wf.add_vector_form_surf(res_form_surf_1_euler, res_form_surf_1_ord, BDY_1);
wf.add_vector_form_surf(res_form_surf_4_euler, res_form_surf_4_ord, BDY_4);
wf.add_vector_form_surf(res_form_surf_6_euler, res_form_surf_6_ord, BDY_6);
}
else {
wf.add_matrix_form(jac_form_vol_cranic, jac_form_vol_ord, HERMES_UNSYM, HERMES_ANY,
&sln_prev_time);
wf.add_matrix_form_surf(jac_form_surf_1_cranic, jac_form_surf_1_ord, BDY_1);
wf.add_matrix_form_surf(jac_form_surf_4_cranic, jac_form_surf_4_ord, BDY_4);
wf.add_matrix_form_surf(jac_form_surf_6_cranic, jac_form_surf_6_ord, BDY_6);
wf.add_vector_form(res_form_vol_cranic, res_form_vol_ord, HERMES_ANY,
&sln_prev_time);
wf.add_vector_form_surf(res_form_surf_1_cranic, res_form_surf_1_ord, BDY_1,
//.........这里部分代码省略.........
示例2: main
int main(int argc, char* argv[])
{
// Time measurement.
TimePeriod cpu_time;
cpu_time.tick();
// Load the mesh.
Mesh mesh, basemesh;
H2DReader mloader;
mloader.load("domain.mesh", &basemesh);
// Perform initial mesh refinements.
mesh.copy(&basemesh);
for(int i = 0; i < INIT_REF_NUM; i++) mesh.refine_all_elements();
mesh.refine_towards_boundary(3, INIT_REF_NUM_BDY);
// Create an H1 space with default shapeset.
H1Space space(&mesh, bc_types, essential_bc_values, P_INIT);
int ndof = Space::get_num_dofs(&space);
info("ndof = %d.", ndof);
// Create a selector which will select optimal candidate.
H1ProjBasedSelector selector(CAND_LIST, CONV_EXP, H2DRS_DEFAULT_ORDER);
// Solutions for the time stepping and the Newton's method.
Solution sln, ref_sln, sln_prev_time;
// Adapt mesh to represent initial condition with given accuracy.
info("Mesh adaptivity to an exact function:");
int as = 1; bool done = false;
do
{
// Setup space for the reference solution.
Space *rspace = construct_refined_space(&space);
// Assign the function f() to the fine mesh.
ref_sln.set_exact(rspace->get_mesh(), init_cond);
// Project the function f() on the coarse mesh.
OGProjection::project_global(&space, &ref_sln, &sln_prev_time, matrix_solver);
// Calculate element errors and total error estimate.
Adapt adaptivity(&space, HERMES_H1_NORM);
bool solutions_for_adapt = true;
double err_est_rel = adaptivity.calc_err_est(&sln_prev_time, &ref_sln, solutions_for_adapt, HERMES_TOTAL_ERROR_REL | HERMES_ELEMENT_ERROR_REL) * 100;
info("Step %d, ndof %d, proj_error %g%%", as, Space::get_num_dofs(&space), err_est_rel);
// If err_est_rel too large, adapt the mesh.
if (err_est_rel < ERR_STOP) done = true;
else {
double to_be_processed = 0;
done = adaptivity.adapt(&selector, THRESHOLD, STRATEGY, MESH_REGULARITY, to_be_processed);
if (Space::get_num_dofs(&space) >= NDOF_STOP) done = true;
}
as++;
}
while (done == false);
// Project the initial condition on the FE space
// to obtain initial coefficient vector for the Newton's method.
info("Projecting initial condition to obtain coefficient vector for Newton on coarse mesh.");
scalar* coeff_vec_coarse = new scalar[Space::get_num_dofs(&space)];
OGProjection::project_global(&space, init_cond, coeff_vec_coarse, matrix_solver);
OGProjection::project_global(&space, &sln_prev_time, &sln, matrix_solver);
// Initialize the weak formulation.
WeakForm wf;
if (TIME_INTEGRATION == 1) {
wf.add_matrix_form(jac_form_vol_euler, jac_form_vol_ord, HERMES_UNSYM, HERMES_ANY,
&sln_prev_time);
wf.add_matrix_form_surf(jac_form_surf_1_euler, jac_form_surf_1_ord, BDY_1);
wf.add_matrix_form_surf(jac_form_surf_4_euler, jac_form_surf_4_ord, BDY_4);
wf.add_matrix_form_surf(jac_form_surf_6_euler, jac_form_surf_6_ord, BDY_6);
wf.add_vector_form(res_form_vol_euler, res_form_vol_ord, HERMES_ANY,
&sln_prev_time);
wf.add_vector_form_surf(res_form_surf_1_euler, res_form_surf_1_ord, BDY_1);
wf.add_vector_form_surf(res_form_surf_4_euler, res_form_surf_4_ord, BDY_4);
wf.add_vector_form_surf(res_form_surf_6_euler, res_form_surf_6_ord, BDY_6);
}
else {
wf.add_matrix_form(jac_form_vol_cranic, jac_form_vol_ord, HERMES_UNSYM, HERMES_ANY,
&sln_prev_time);
wf.add_matrix_form_surf(jac_form_surf_1_cranic, jac_form_surf_1_ord, BDY_1);
wf.add_matrix_form_surf(jac_form_surf_4_cranic, jac_form_surf_4_ord, BDY_4);
wf.add_matrix_form_surf(jac_form_surf_6_cranic, jac_form_surf_6_ord, BDY_6);
wf.add_vector_form(res_form_vol_cranic, res_form_vol_ord, HERMES_ANY,
&sln_prev_time);
wf.add_vector_form_surf(res_form_surf_1_cranic, res_form_surf_1_ord, BDY_1,
&sln_prev_time);
wf.add_vector_form_surf(res_form_surf_4_cranic, res_form_surf_4_ord, BDY_4,
&sln_prev_time);
wf.add_vector_form_surf(res_form_surf_6_cranic, res_form_surf_6_ord, BDY_6,
&sln_prev_time);
}
// Error estimate and discrete problem size as a function of physical time.
//.........这里部分代码省略.........