Изучение структур данных и алгоритмов, используемых в МКЭ, страница 2

return 0;

}

while( !feof(file) ) 

{

fscanf(file, "%d", &index);

fscanf(file, "%lf", &current[index]);

fscanf(file, "%c", &symbol);

while( (symbol != '\n') && (!feof(file)) )

fscanf(file, "%c", &symbol);

}

Fclose(file, "toku");

// Считываем файл "inf2tr.dat"

file = Fopen("inf2tr.dat", "r");

symbol = ' ';

while( symbol != '\n')

fscanf(file, "%c", &symbol);

while( symbol != '=' )

fscanf(file, "%c", &symbol);

fscanf(file, "%d", &amount_node);           // Считали количество узлов

symbol = ' ';

while( symbol != '=' )

fscanf(file, "%c", &symbol);

fscanf(file, "%d", &amount_triangle);       // Считали количество треугольников

symbol = ' ';

while( symbol != '=' )

fscanf(file, "%c", &symbol);

fscanf(file, "%d", &amount_marginal);       // Считали количество Первых краевых условий

amount_node -= amount_marginal;

Fclose(file, "inf2tr.dat");

// Считываем файл "nvtr.dat" 

file = Fopen("nvtr.dat", "rb");

tops_triangle = new int *[amount_triangle];

if( tops_triangle == NULL )

{

printf("Insufficient available memory for array 'tops_triangle'\n");

return 0;

}

for(int i = 0; i < amount_triangle; i++ )

{

tops_triangle[i] = new int[4];

if( tops_triangle[i] == NULL )

{

printf("Insufficient available memory for array 'tops_triangle[%d]'\n", i);

return 0;

}

}

for(i = 0; i < amount_triangle; i++ )

{

fread(&tops_triangle[i][0], sizeof(int), 1, file);

fread(&tops_triangle[i][1], sizeof(int), 1, file);

fread(&tops_triangle[i][2], sizeof(int), 1, file);

fread(&tops_triangle[i][3], sizeof(int), 1, file);

}

Fclose(file, "nvtr.dat");

//Считываем файл "xy"

file = Fopen("xy.dat", "rb");

xy = new double *[amount_node + amount_marginal];

if( xy == NULL )

{

printf("Insufficient available memory for array 'xy'\n");

return 0;

}

for(i = 0; i < amount_node + amount_marginal; i++ )

{

xy[i] = new double[2];

if( xy[i] == NULL )

{

printf("Insufficient available memory for array 'xy[%d]'\n", i);

return 0;

}

}

for(i = 0; i < amount_node + amount_marginal; i++ )

{

fread(&xy[i][0], sizeof(double), 1, file);

fread(&xy[i][1], sizeof(double), 1, file);

}

Fclose(file, "xy.dat");

//Считываем файл "ig.2d"

file = Fopen("ig.2d", "rb");

ig = new int[amount_node + 1];

if( ig == NULL )

{

printf("Insufficient available memory for array 'ig'\n");

return 0;

}

for(i = 0; i < amount_node + 1; i++ )

fread(&ig[i], sizeof(int), 1, file);

Fclose(file, "ig.2d");

//Считываем файл "jg.2d"

file = Fopen("jg.2d", "rb");

amount_element = ig[amount_node];

jg = new int[amount_element];

if( jg == NULL )

{

printf("Insufficient available memory for array 'jg'\n");

return 0;

}

for(i = 0; i < amount_element; i++ )

fread(&jg[i], sizeof(int), 1, file);

Fclose(file, "jg.2d");       

// Выделение памяти для массивов 'gg', 'di' и 'pr'

gg = new double[amount_element];

if( gg == NULL )

{

printf("Insufficient available memory for array 'gg'\n");

return 0;

}

di = new double[amount_node];

if( di == NULL )

{

printf("Insufficient available memory for array 'di'\n");

return 0;

}

pr = new double[amount_node];

if( pr == NULL )

{

printf("Insufficient available memory for array 'pr'\n");

return 0;

}

// Обнуление мамассивов

for(i = 0; i < amount_element; i++ )

gg[i] = 0;

for(i = 0; i < amount_node; i++ )

{

di[i] = 0;

pr[i] = 0;

}

// Сборка глобальной матрицы

for(int FiniteElement = 0; FiniteElement < amount_triangle; FiniteElement++ )

{

SetLocalMatrixVector(LocalMatrix, LocalVector, FiniteElement, tops_triangle, xy,

conductivity, current);

for(i = 0; i < 3; i++ )

{

index_i = tops_triangle[FiniteElement][i] - 1;

if( index_i < amount_node )

{

di[index_i] += LocalMatrix[i][i];

pr[index_i] += LocalVector[i];

for(int j = 0; j < i; j++ )

{

index_j = tops_triangle[FiniteElement][j] - 1;

if( index_j < amount_node )

for(int k = ig[index_i]; k < ig[index_i + 1]; k++ )

if( jg[k - 1] == index_j + 1 )

{

gg[k - 1] += LocalMatrix[i][j];

break;

}

}

}

}

printf("%d Finite Element Completed...\n", FiniteElement);

}

printf("\nAssembly completed!!!\n\n");

delete[] conductivity;

delete[] current;

for(i = 0; i < amount_triangle; i++ )

delete[] tops_triangle[i];

for(i = 0; i < amount_node; i++ )

delete[] xy[i];

delete[] xy;

delete[] ig;

delete[] jg;

delete[] gg;

delete[] di;

delete[] pr;

return 0;

}

Тесты:

Тест 1:

Сетка:

Результаты сборки матрицы и вектора правой части

Telma

Ручная сборка

gg

di

pr

gg

di

pr

Решение

Невязка

Telma

Ручная сборка

v2

v2