本文整理汇总了C++中SparseMatrix::alloc方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseMatrix::alloc方法的具体用法?C++ SparseMatrix::alloc怎么用?C++ SparseMatrix::alloc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SparseMatrix
的用法示例。
在下文中一共展示了SparseMatrix::alloc方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char* argv[])
{
// Load the mesh.
Mesh mesh;
H2DReader mloader;
// We load the mesh on a (-1, 1)^2 domain.
mloader.load("ref_square.mesh", &mesh);
// Enter boundary markers
// (If no markers are entered, default is a natural BC).
BCTypes bc_types;
// Create an H1 space with default shapeset,
// natural BC, and linear elements.
H1Space space(&mesh, &bc_types, P_INIT);
// The type of element, mesh_mode = 4 means a rectangle element.
int mesh_mode = 4;
int ndof = Space::get_num_dofs(&space);
printf("ndof = %d\n", ndof);
if(ndof > FNS_NUM) error("Max number of shape functions exceeded.");
int *fn_idx = new int [FNS_NUM];
int m = 0;
int order = P_INIT;
// Get the vertex fns index.
info("Get the vertex fns index.");
for (int i = 0; i < mesh_mode; i++, m++)
{
fn_idx[m] = space.get_shapeset()->get_vertex_index(i);
printf("m = %d, get_vertex_index(m) = %d\n",
m, space.get_shapeset()->get_vertex_index(m));
}
// Get the edge fns index.
info("Get the edge fns index.");
for (int edge_order = 2; edge_order <= order; edge_order++)
{
for (int j = 0; j < mesh_mode; j++, m++)
{
fn_idx[m] = space.get_shapeset()->get_edge_index(j, 0, edge_order);
printf("m = %d, get_edge_index(m) = %d\n", m, fn_idx[m]);
}
}
// Get the bubble fns index.
info("Get the bubble fns index.");
int number_bubble = space.get_shapeset()->get_num_bubbles(H2D_MAKE_QUAD_ORDER(order, order));
int *bubble_idx = space.get_shapeset()->get_bubble_indices(H2D_MAKE_QUAD_ORDER(order, order));
for (int i = 0; i < number_bubble; i++, m++ )
{
fn_idx[m] = bubble_idx[i];
printf("m = %d, get_bubble_index(m) = %d\n", m, fn_idx[m]);
}
// Initialize the matrix solver.
SparseMatrix* mat = create_matrix(matrix_solver);
Vector* rhs = create_vector(matrix_solver);
Solver* solver = create_linear_solver(matrix_solver, mat, rhs);
// precalc structure
mat->prealloc(ndof);
for (int i = 0; i < ndof; i++)
for (int j = 0; j < ndof; j++)
mat->pre_add_ij(i, j);
mat->alloc();
rhs->alloc(ndof);
info("Assembling matrix ...");
for (int i = 0; i < ndof; i++)
{
for (int j = 0; j < order; j++)
{
double x1 = -1 + (2.0/order)*j;
double y1 = -1;
double value = space.get_shapeset()->get_fn_value(fn_idx[i], x1, y1, 0);
mat->add(i, j, value);
printf("get fn[%d] value = %f ", i, value);
printf("x1 = %f, y1 = %f\n", x1, y1);
}
for (int j = 0; j < order; j++)
{
double y2 = -1 + (2.0/order)*j;;
double x2 = 1;
double value = space.get_shapeset()->get_fn_value(fn_idx[i], x2, y2, 0);
mat->add(i, j+order, value);
printf("get fn[%d] value = %f ", i, value);
printf("x2 = %f, y2 = %f\n", x2, y2);
}
for (int j = 0; j < order; j++)
{
double x3 = 1 + (-1.0)*(2.0/order)*j;
double y3 = 1;
double value = space.get_shapeset()->get_fn_value(fn_idx[i], x3, y3, 0);
mat->add(i, j+2*order, value);
printf("get fn[%d] value = %f ", i, value);
printf("x3 = %f, y3 = %f\n", x3, y3);
}
for (int j = 0; j < order; j++)
{
double x4 = -1;
//.........这里部分代码省略.........