本文整理汇总了C++中Adapt::set_spaces方法的典型用法代码示例。如果您正苦于以下问题:C++ Adapt::set_spaces方法的具体用法?C++ Adapt::set_spaces怎么用?C++ Adapt::set_spaces使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Adapt
的用法示例。
在下文中一共展示了Adapt::set_spaces方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
P_space->assign_dofs();
}
// Adaptivity loop:
int as = 1;
bool done = false;
do
{
Hermes::Mixins::Loggable::Static::info("Adaptivity step %d:", as);
// Construct globally refined reference mesh and setup reference space.
int order_increase = 1;
Mesh::ReferenceMeshCreator refMeshCreatorE(E_mesh);
Mesh::ReferenceMeshCreator refMeshCreatorH(H_mesh);
Mesh::ReferenceMeshCreator refMeshCreatorP(P_mesh);
MeshSharedPtr ref_mesh_E = refMeshCreatorE.create_ref_mesh();
MeshSharedPtr ref_mesh_H = refMeshCreatorH.create_ref_mesh();
MeshSharedPtr ref_mesh_P = refMeshCreatorP.create_ref_mesh();
Space<double>::ReferenceSpaceCreator refSpaceCreatorE(E_space, ref_mesh_E, order_increase);
SpaceSharedPtr<double> ref_space_E = refSpaceCreatorE.create_ref_space();
Space<double>::ReferenceSpaceCreator refSpaceCreatorH(H_space, ref_mesh_H, order_increase);
SpaceSharedPtr<double> ref_space_H = refSpaceCreatorH.create_ref_space();
Space<double>::ReferenceSpaceCreator refSpaceCreatorP(P_space, ref_mesh_P, order_increase);
SpaceSharedPtr<double> ref_space_P = refSpaceCreatorP.create_ref_space();
std::vector<SpaceSharedPtr<double> > ref_spaces({ ref_space_E, ref_space_H, ref_space_P });
int ndof = Space<double>::get_num_dofs(ref_spaces);
Hermes::Mixins::Loggable::Static::info("ndof = %d.", ndof);
try
{
runge_kutta.set_spaces(ref_spaces);
runge_kutta.set_time(current_time);
runge_kutta.set_time_step(time_step);
runge_kutta.rk_time_step_newton(slns_time_prev, slns_time_new);
}
catch (Exceptions::Exception& e)
{
e.print_msg();
throw Hermes::Exceptions::Exception("Runge-Kutta time step failed");
}
// Visualize the solutions.
char title[100];
sprintf(title, "E1, t = %g", current_time + time_step);
E1_view.set_title(title);
E1_view.show(E_time_new, H2D_FN_VAL_0);
sprintf(title, "E2, t = %g", current_time + time_step);
E2_view.set_title(title);
E2_view.show(E_time_new, H2D_FN_VAL_1);
sprintf(title, "H, t = %g", current_time + time_step);
H_view.set_title(title);
H_view.show(H_time_new);
sprintf(title, "P1, t = %g", current_time + time_step);
P1_view.set_title(title);
P1_view.show(P_time_new, H2D_FN_VAL_0);
sprintf(title, "P2, t = %g", current_time + time_step);
P2_view.set_title(title);
P2_view.show(P_time_new, H2D_FN_VAL_1);
// Project the fine mesh solution onto the coarse mesh.
Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh.");
示例2: main
int main(int argc, char* argv[])
{
// Choose a Butcher's table or define your own.
ButcherTable bt(butcher_table_type);
if (bt.is_explicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage explicit R-K method.", bt.get_size());
if (bt.is_diagonally_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage diagonally implicit R-K method.", bt.get_size());
if (bt.is_fully_implicit()) Hermes::Mixins::Loggable::Static::info("Using a %d-stage fully implicit R-K method.", bt.get_size());
// Load the mesh.
MeshSharedPtr basemesh(new Mesh), T_mesh(new Mesh), w_mesh(new Mesh);
MeshReaderH2D mloader;
mloader.load("domain.mesh", basemesh);
// Create temperature and moisture meshes.
// This also initializes the multimesh hp-FEM.
T_mesh->copy(basemesh);
w_mesh->copy(basemesh);
// Initialize boundary conditions.
EssentialBCNonConst temp_reactor("bdy_react", REACTOR_START_TIME, T_INITIAL, T_REACTOR_MAX);
EssentialBCs<double> bcs_T(&temp_reactor);
SpaceSharedPtr<double> T_space(new H1Space<double>(T_mesh, &bcs_T, P_INIT));
SpaceSharedPtr<double> w_space(new H1Space<double>(MULTI ? w_mesh : T_mesh, P_INIT));
std::vector<SpaceSharedPtr<double> > spaces({ T_space, w_space });
adaptivity.set_spaces(spaces);
// Define constant initial conditions.
Hermes::Mixins::Loggable::Static::info("Setting initial conditions.");
MeshFunctionSharedPtr<double> T_time_prev(new ConstantSolution<double>(T_mesh, T_INITIAL));
MeshFunctionSharedPtr<double> w_time_prev(new ConstantSolution<double>(w_mesh, W_INITIAL));
MeshFunctionSharedPtr<double> T_time_new(new Solution<double>(T_mesh));
MeshFunctionSharedPtr<double> w_time_new(new Solution<double>(w_mesh));
// Solutions.
MeshFunctionSharedPtr<double> T_coarse(new Solution<double>), w_coarse(new Solution<double>);
// Initialize the weak formulation.
WeakFormSharedPtr<double> wf(new CustomWeakFormHeatMoistureRK(c_TT, c_ww, d_TT, d_Tw, d_wT, d_ww,
k_TT, k_ww, T_EXTERIOR, W_EXTERIOR, "bdy_ext"));
// Initialize refinement selector.
H1ProjBasedSelector<double> selector(CAND_LIST);
// Geometry and position of visualization windows.
WinGeom* T_sln_win_geom = new WinGeom(0, 0, 300, 450);
WinGeom* w_sln_win_geom = new WinGeom(310, 0, 300, 450);
WinGeom* T_mesh_win_geom = new WinGeom(620, 0, 280, 450);
WinGeom* w_mesh_win_geom = new WinGeom(910, 0, 280, 450);
// Initialize views.
ScalarView T_sln_view("Temperature", T_sln_win_geom);
ScalarView w_sln_view("Moisture (scaled)", w_sln_win_geom);
OrderView T_order_view("Temperature mesh", T_mesh_win_geom);
OrderView w_order_view("Moisture mesh", w_mesh_win_geom);
// Show initial conditions.
T_sln_view.show(T_time_prev);
w_sln_view.show(w_time_prev);
T_order_view.show(T_space);
w_order_view.show(w_space);
// Time stepping loop:
int ts = 1;
while (current_time < SIMULATION_TIME)
{
Hermes::Mixins::Loggable::Static::info("Simulation time = %g s (%d h, %d d, %d y)",
current_time, (int)current_time / 3600,
(int)current_time / (3600 * 24), (int)current_time / (3600 * 24 * 364));
// Update time-dependent essential BCs.
if (current_time <= REACTOR_START_TIME) {
Hermes::Mixins::Loggable::Static::info("Updating time-dependent essential BC.");
Space<double>::update_essential_bc_values({ T_space, w_space }, current_time);
}
// Uniform mesh derefinement.
if (ts > 1 && ts % UNREF_FREQ == 0) {
Hermes::Mixins::Loggable::Static::info("Global mesh derefinement.");
switch (UNREF_METHOD) {
case 1: T_mesh->copy(basemesh);
w_mesh->copy(basemesh);
T_space->set_uniform_order(P_INIT);
w_space->set_uniform_order(P_INIT);
break;
case 2: T_mesh->unrefine_all_elements();
if (MULTI)
w_mesh->unrefine_all_elements();
T_space->set_uniform_order(P_INIT);
w_space->set_uniform_order(P_INIT);
break;
case 3: T_mesh->unrefine_all_elements();
if (MULTI)
w_mesh->unrefine_all_elements();
T_space->adjust_element_order(-1, -1, P_INIT, P_INIT);
w_space->adjust_element_order(-1, -1, P_INIT, P_INIT);
break;
default: throw Hermes::Exceptions::Exception("Wrong global derefinement method.");
}
T_space->assign_dofs();
//.........这里部分代码省略.........
示例3: main
int main(int argc, char* argv[])
{
// Time measurement.
Hermes::Mixins::TimeMeasurable cpu_time;
cpu_time.tick();
// Load the mesh.
MeshSharedPtr u_mesh(new Mesh), v_mesh(new Mesh);
MeshReaderH2D mloader;
mloader.load("domain.mesh", u_mesh);
if (MULTI == false)
u_mesh->refine_towards_boundary("Bdy", INIT_REF_BDY);
// Create initial mesh (master mesh).
v_mesh->copy(u_mesh);
// Initial mesh refinements in the v_mesh towards the boundary.
if (MULTI == true)
v_mesh->refine_towards_boundary("Bdy", INIT_REF_BDY);
// Set exact solutions.
MeshFunctionSharedPtr<double> exact_u(new ExactSolutionFitzHughNagumo1(u_mesh));
MeshFunctionSharedPtr<double> exact_v(new ExactSolutionFitzHughNagumo2(MULTI ? v_mesh : u_mesh, K));
// Define right-hand sides.
CustomRightHandSide1 g1(K, D_u, SIGMA);
CustomRightHandSide2 g2(K, D_v);
// Initialize the weak formulation.
CustomWeakForm wf(&g1, &g2);
// Initialize boundary conditions
DefaultEssentialBCConst<double> bc_u("Bdy", 0.0);
EssentialBCs<double> bcs_u(&bc_u);
DefaultEssentialBCConst<double> bc_v("Bdy", 0.0);
EssentialBCs<double> bcs_v(&bc_v);
// Create H1 spaces with default shapeset for both displacement components.
SpaceSharedPtr<double> u_space(new H1Space<double>(u_mesh, &bcs_u, P_INIT_U));
SpaceSharedPtr<double> v_space(new H1Space<double>(MULTI ? v_mesh : u_mesh, &bcs_v, P_INIT_V));
// Initialize coarse and reference mesh solutions.
MeshFunctionSharedPtr<double> u_sln(new Solution<double>()), v_sln(new Solution<double>()), u_ref_sln(new Solution<double>()), v_ref_sln(new Solution<double>());
Hermes::vector<MeshFunctionSharedPtr<double> > slns(u_sln, v_sln);
Hermes::vector<MeshFunctionSharedPtr<double> > ref_slns(u_ref_sln, v_ref_sln);
Hermes::vector<MeshFunctionSharedPtr<double> > exact_slns(exact_u, exact_v);
// Initialize refinement selector.
H1ProjBasedSelector<double> selector(CAND_LIST);
//HOnlySelector<double> selector;
// Initialize views.
Views::ScalarView s_view_0("Solution[0]", new Views::WinGeom(0, 0, 440, 350));
s_view_0.show_mesh(false);
Views::OrderView o_view_0("Mesh[0]", new Views::WinGeom(450, 0, 420, 350));
Views::ScalarView s_view_1("Solution[1]", new Views::WinGeom(880, 0, 440, 350));
s_view_1.show_mesh(false);
Views::OrderView o_view_1("Mesh[1]", new Views::WinGeom(1330, 0, 420, 350));
// DOF and CPU convergence graphs.
SimpleGraph graph_dof_est, graph_cpu_est;
SimpleGraph graph_dof_exact, graph_cpu_exact;
NewtonSolver<double> newton;
newton.set_weak_formulation(&wf);
// Adaptivity loop:
int as = 1;
bool done = false;
do
{
Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as);
// Construct globally refined reference mesh and setup reference space->
Mesh::ReferenceMeshCreator u_ref_mesh_creator(u_mesh);
MeshSharedPtr u_ref_mesh = u_ref_mesh_creator.create_ref_mesh();
Mesh::ReferenceMeshCreator v_ref_mesh_creator(v_mesh);
MeshSharedPtr v_ref_mesh = v_ref_mesh_creator.create_ref_mesh();
Space<double>::ReferenceSpaceCreator u_ref_space_creator(u_space, u_ref_mesh);
SpaceSharedPtr<double> u_ref_space = u_ref_space_creator.create_ref_space();
Space<double>::ReferenceSpaceCreator v_ref_space_creator(v_space, MULTI ? v_ref_mesh : u_ref_mesh);
SpaceSharedPtr<double> v_ref_space = v_ref_space_creator.create_ref_space();
Hermes::vector<SpaceSharedPtr<double> > ref_spaces_const(u_ref_space, v_ref_space);
newton.set_spaces(ref_spaces_const);
int ndof_ref = Space<double>::get_num_dofs(ref_spaces_const);
// Initialize reference problem.
Hermes::Mixins::Loggable::Static::info("Solving on reference mesh.");
// Time measurement.
cpu_time.tick();
// Perform Newton's iteration.
try
{
newton.solve();
}
//.........这里部分代码省略.........