/
NenNil
/
vmk2025-parallel-computing
Обзор
Документация
Войти
/
NenNil
/
vmk2025-parallel-computing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
omp2/scheme.cpp
253 строки
7 KB
Нил Ненахов
some not essential changes
03 дек 2025, 16:49
03 дек 2025, 16:49
02715ff
Код
Авторство
О чём код?
#include "scheme.h" #include <cmath> #include <iostream> #include <vector> Coef::Coef(double h1, double h2, double(*fun)(double x, double y), double(*funx)(double y, bool positive), double(*funy)(double x, bool positive), double epsilon) { this->h1 = h1; this->h2 = h2; this->fun = fun; this->funx = funx; this->funy = funy; this->eps = epsilon; this->koef = 0; } void Coef::build_coef(int x, int y, std::vector<double> &coef_vec) { cols = x; rows = y; for(int j=0; j<y; j++) for(int i=0; i<x; i++) { coef_vec[i+j*x] = this->getcoef(i,j); } // print_matrix(); } void Coef::print_matrix() { // Вывод результата для проверки for (size_t k = 0; k < coef_vec.size(); ++k) { if ((k % cols) == 0 && k != 0) std::cout << "\n"; std::cout << Coef::coef_vec[k] << " "; } std::cout << std::endl; } double Coefb::countx(int i) { return -2+i*h1; } double Coefb::county(int i) { return 1-h2/2-i*h2; } double Coefa::countx(int i) { return -2+h1/2+i*h1; } double Coefa::county(int i) { return 1-i*h2; } double Coefa::getcoef(int x, int y1) { int y2 = y1+1; double fun1 = fun(countx(x), county(y1)); double fun2 = fun(countx(x), county(y2)); if (fun1*fun2>0) { if (fun1 > 0) return (1/eps)/(h1*h1); else return 1/(h1*h1); } else if (county(y1)>0) { return (std::abs(county(y2) - funy(countx(x), true))/h2 + (std::abs(county(y1) - funy(countx(x), true))/h2)/eps)/(h1*h1); } else { return (std::abs(county(y1) - funy(countx(x), false))/h2+ (std::abs(county(y2) - funy(countx(x), false))/h2)/eps)/(h1*h1); } } double Coefb::getcoef(int x1, int y) { int x2 = x1+1; double fun1 = fun(countx(x1), county(y)); double fun2 = fun(countx(x2), county(y)); if (fun1*fun2>=0) { if (fun1 > 0) return (1/eps)/(h2*h2); else return 1/(h2*h2); } else if (countx(x2)>0) { return (std::abs(countx(x2) - funx(county(y), true))/h1 + (std::abs(countx(x1) - funx(county(y), true))/h1)/eps)/(h2*h2); } else { return (std::abs(countx(x1) - funx(county(y), false))/h1+ (std::abs(countx(x2) - funx(county(y), false))/h1)/eps)/(h2*h2); } } Matrix_coef::Matrix_coef(double h1, double h2, Coefa a, Coefb b) { Matrix_coef::h1 = h1; Matrix_coef::h2 = h2; Matrix_coef::a = a; Matrix_coef::b = b; } double Matrix_coef::diag(int i, int j) { return (1/pow(h1, 2)*(a.getcoef(i+1, j)+a.getcoef(i, j))) + (1/pow(h2,2)*(b.getcoef(i, j+1)+b.getcoef(i, j))); } double Matrix_coef::left(int i, int j) { return -1/pow(h1,2)*a.getcoef(i, j); } double Matrix_coef::right(int i, int j) { return -1/pow(h1,2)*a.getcoef(i+1, j); } double Matrix_coef::up(int i, int j) { return -1/pow(h2,2)*b.getcoef(i, j); } double Matrix_coef::down(int i, int j) { return -1/pow(h2,2)*b.getcoef(i, j+1); } BorderF::BorderF(double h1, double h2, double(*fun)(double x, double y), double(*funx)(double y, bool positive), double(*funy)(double x, bool positive) ) { BorderF::h1 = h1; BorderF::h2 = h2; BorderF::fun = fun; BorderF::funx = funx; BorderF::funy = funy; } double BorderF::getcoef(int x1, int y1) { bool left = fun(countx(x1), county(y1))*fun(countx(x1), county(y1+1))<=0; bool up = fun(countx(x1), county(y1))*fun(countx(x1+1), county(y1))<=0; bool down = fun(countx(x1), county(y1+1))*fun(countx(x1+1), county(y1+1))<=0; bool right = fun(countx(x1+1), county(y1))*fun(countx(x1+1), county(y1+1))<=0; // std::cout << "left: " << left << ", up: " << up << ", right: " << right << ", down: " << down << std::endl; if (fun(countx(x1), county(y1)) > 0) return 0; else return 1; if (!(left || up || down || right)) { if (fun(countx(x1), county(y1))>0) return 1; else return 0; } else if (left && right) { // std::cout << "left+right; "; double a, b; a = funy(countx(x1), county(y1)>0) - county(y1+1); b = funy(countx(x1+1), county(y1)>0) - county(y1+1); // std::cout << "funy: " << funy(countx(x1+1), county(y1)>0) << ", y1+1: " << county(y1+1) << "; "; double buf; if (a < b){ buf = a; a = b; b = buf; } // std::cout << "a: " << a << ", " << "b: " << b << "; "; if (fun(countx(x1), county(y1))<0) return (h1*(a - b)/2+h1*b)/h1/h2; else return (h1*h2 - (h1*(a - b)/2+h1*b))/h1/h2; } else if (down && up) { // std::cout << "down+up" << "; "; double a, b; a = countx(x1+1)-funx(county(y1), countx(x1)>0); b = countx(x1+1)-funx(county(y1+1), countx(x1)>0); double buf; if (a < b){ buf = a; a = b; b = buf; } if (fun(countx(x1), county(y1))<0) return (h2*(a - b)/2+h2*b)/h1/h2; else return (h1*h2 - (h2*(a - b)/2+h2*b))/h1/h2; } else if ((left && up) || (up && right) || (right && down) || (down && left)) { double yCross_down, yCross_up; yCross_down = funx(county(y1), countx(x1)>0); yCross_up = funx(county(y1+1), countx(x1)>0); double a, b; if (left && up) { a = h1-(countx(x1+1)-funx(county(y1), countx(x1)>0)); b = h2-(funy(countx(x1), county(y1))-county(y1+1)); if (fun(countx(x1), county(y1))>0) return (a*b)/h1/h2; else return (h1*h2-a*b)/h1/h2; } else if(up && right) { // std::cout << "up+right; "; a = countx(x1+1)-funx(county(y1), countx(x1)>0); b = h2+(county(y1+1)-funy(countx(x1+1), county(y1)>0)); if (fun(countx(x1), county(y1))<0) return (a*b)/h1/h2; else return (h1*h2-a*b)/h1/h2; } else if(right && down) { // std::cout << "right+down; "; a = countx(x1+1)-funx(county(y1+1), countx(x1)>0); b = -(county(y1+1)-funy(countx(x1+1), county(y1)>0)); if (fun(countx(x1), county(y1))<0) return (a*b)/h1/h2; else return (h1*h2-a*b)/h1/h2; // std::cout << "countx: " << countx(x1+1) << ", funx: " << funx(county(y1+1), countx(x1)>0) << "; "; // std::cout << "a: " << a << ", b: " << b << "; "; } else if(down && left) { a = h1-(countx(x1+1)-funx(county(y1+1), countx(x1)>0)); b = -(county(y1+1)-funy(countx(x1+1), county(y1)>0)); if (fun(countx(x1), county(y1))<0) return (a*b)/h1/h2; else return (h1*h2-a*b)/h1/h2; } } return -1; } double BorderF::countx(int i) { return -2+h1/2+i*h1; } double BorderF::county(int i) { return 1-h2/2-i*h2; }