int _tmain(int argc, _TCHAR* argv[]) { setlocale(LC_ALL, "Russian"); RealMatrix matrix1 = RealMatrix("matrix1.txt"); RealMatrix matrix2 = RealMatrix("matrix2.txt"); RealMatrix matrix3 = RealMatrix("matrix3.txt"); RealMatrix matrix4 = RealMatrix("matrix4.txt"); cout << matrix4.det(); //matrix3.printMatrix(); system("pause"); return 0; }
LPSolver::LPSolver(const RealMatrix& _A, const RealVector& _b, const RealVector& _c) { N = B = 0; eps = 10E-07; m = _b.size(); n = _c.size(); D = RealMatrix(m+2, n+2); B = new int[m]; N = new int[n+1]; // copy matrix for(int i=0; i<m; ++i) for(int j=0; j<n; ++j) D(i,j) = _A(i,j); for(int i=0; i<m; ++i) { B[i] = n+i; D(i,n) = -1; D(i,n+1) = _b(i); } for(int j=0; j<n; ++j) { N[j] = j; D(m,j) = -_c(j); } N[n] = -1; D(m+1, n) = 1; }
const RealMatrix& Triag::local_coordinates() { static const RealMatrix loc_coord = (RealMatrix(nb_nodes, dimensionality) << 1./3., 1./3. ).finished(); return loc_coord; }
const RealMatrix& Quad::local_coordinates() { static const RealMatrix loc_coord = (RealMatrix(nb_nodes, dimensionality) << 0., 0. ).finished(); return loc_coord; }
const RealMatrix& Point::local_coordinates() { static const RealMatrix loc_coord = (RealMatrix(nb_nodes, 3) << 0., 0., 0. ).finished(); return loc_coord; }
const RealMatrix& Line::mononomial_exponents() { static const RealMatrix exponents= (RealMatrix(nb_nodes, dimensionality) << 0, 1, 2, 3 ).finished(); return exponents; }
const RealMatrix& Line::mononomial_coefficients() { static const RealMatrix coeffs= (RealMatrix(nb_nodes, nb_nodes) << -1, 1, 9, -9, -1, -1, 9, 9, 9, -27, -9, 27, 9, 27, -9, -27 ).finished() / 16.; return coeffs; }
const RealMatrix& Triag::mononomial_coefficients() { static const RealMatrix coeffs= (RealMatrix(nb_nodes, nb_nodes) << 1, -3, -3, 2, 4, 2, 0, -1, 0, 2, 0, 0, 0, 0, -1, 0, 0, 2, 0, 4, 0, -4, -4, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, -4, -4 ).finished(); return coeffs; }
namespace SF { //////////////////////////////////////////////////////////////////////////////// Common::ComponentBuilder < SFTriagLagrangeP1, ShapeFunction, LibSF > SFTriagLagrangeP1_Builder; //////////////////////////////////////////////////////////////////////////////// SFTriagLagrangeP1::SFTriagLagrangeP1(const std::string& name) : ShapeFunction(name) { m_dimensionality = dimensionality; m_nb_nodes = nb_nodes; m_order = order; m_shape = shape; } //////////////////////////////////////////////////////////////////////////////// void SFTriagLagrangeP1::compute_value(const MappedCoordsT& mapped_coord, ValueT& result) { result[0] = 1. - mapped_coord[KSI] - mapped_coord[ETA]; result[1] = mapped_coord[KSI]; result[2] = mapped_coord[ETA]; } //////////////////////////////////////////////////////////////////////////////// void SFTriagLagrangeP1::compute_gradient(const MappedCoordsT& mapped_coord, GradientT& result) { result(KSI, 0) = -1.; result(ETA, 0) = -1.; result(KSI, 1) = 1.; result(ETA, 1) = 0.; result(KSI, 2) = 0.; result(ETA, 2) = 1.; } //////////////////////////////////////////////////////////////////////////////// RealMatrix SFTriagLagrangeP1::s_mapped_sf_nodes = ( RealMatrix(3,2) << 0., 0., 1., 0., 0., 1. ).finished(); //////////////////////////////////////////////////////////////////////////////// } // SF
namespace SF { //////////////////////////////////////////////////////////////////////////////// Common::ComponentBuilder < SFLineLagrangeP2, ShapeFunction, LibSF > SFLineLagrangeP2_Builder; //////////////////////////////////////////////////////////////////////////////// SFLineLagrangeP2::SFLineLagrangeP2(const std::string& name) : ShapeFunction(name) { m_dimensionality = dimensionality; m_nb_nodes = nb_nodes; m_order = order; m_shape = shape; } //////////////////////////////////////////////////////////////////////////////// void SFLineLagrangeP2::compute_value(const MappedCoordsT& mapped_coord, ValueT& result) { result[0] = 0.5 * (mapped_coord[KSI]*mapped_coord[KSI] - mapped_coord[KSI]); result[1] = 0.5 * (mapped_coord[KSI]*mapped_coord[KSI] + mapped_coord[KSI]); result[2] = (1.0 - mapped_coord[KSI]*mapped_coord[KSI]); } //////////////////////////////////////////////////////////////////////////////// void SFLineLagrangeP2::compute_gradient(const MappedCoordsT& mapped_coord, GradientT& result) { result(KSI, 0) = mapped_coord[KSI]-0.5; result(KSI, 1) = mapped_coord[KSI]+0.5; result(KSI, 2) = -2.0*mapped_coord[KSI]; } //////////////////////////////////////////////////////////////////////////////// RealMatrix SFLineLagrangeP2::s_mapped_sf_nodes = ( RealMatrix(3,1) << -1., 1., 0. ).finished(); //////////////////////////////////////////////////////////////////////////////// } // SF
namespace SF { //////////////////////////////////////////////////////////////////////////////// Common::ComponentBuilder < SFTetraLagrangeP0, ShapeFunction, LibSF > SFTetraLagrangeP0_Builder; //////////////////////////////////////////////////////////////////////////////// SFTetraLagrangeP0::SFTetraLagrangeP0(const std::string& name) : ShapeFunction(name) { m_dimensionality = dimensionality; m_nb_nodes = nb_nodes; m_order = order; m_shape = shape; } //////////////////////////////////////////////////////////////////////////////// void SFTetraLagrangeP0::compute_value(const MappedCoordsT& mapped_coord, ValueT& result) { result[0] = 1.; } //////////////////////////////////////////////////////////////////////////////// void SFTetraLagrangeP0::compute_gradient(const MappedCoordsT& mapped_coord, GradientT& result) { result(KSI, 0) = 0.; result(ETA, 0) = 0.; result(ZTA, 0) = 0.; } //////////////////////////////////////////////////////////////////////////////// RealMatrix SFTetraLagrangeP0::s_mapped_sf_nodes = ( RealMatrix(1,3) << 1./3., 1./3., 1./3. ).finished(); //////////////////////////////////////////////////////////////////////////////// } // SF
namespace SF { //////////////////////////////////////////////////////////////////////////////// Common::ComponentBuilder < QuadFluxP3, Mesh::ShapeFunction, LibSF > QuadFluxP3_Builder; //////////////////////////////////////////////////////////////////////////////// QuadFluxP3::QuadFluxP3(const std::string& name) : ShapeFunction(name) { m_dimensionality = dimensionality; m_nb_nodes = nb_nodes; m_order = order; m_shape = shape; m_nb_lines_per_orientation = nb_lines_per_orientation; m_points.resize(boost::extents[nb_orientations][nb_lines_per_orientation][nb_nodes_per_line]); m_points[KSI][0][0] = 0; m_points[KSI][0][1] = 1; m_points[KSI][0][2] = 2; m_points[KSI][0][3] = 3; m_points[KSI][1][0] = 4; m_points[KSI][1][1] = 5; m_points[KSI][1][2] = 6; m_points[KSI][1][3] = 7; m_points[KSI][2][0] = 8; m_points[KSI][2][1] = 9; m_points[KSI][2][2] = 10; m_points[KSI][2][3] = 11; m_points[ETA][0][0] = 0; m_points[ETA][0][1] = 12; m_points[ETA][0][2] = 13; m_points[ETA][0][3] = 8; m_points[ETA][1][0] = 14; m_points[ETA][1][1] = 15; m_points[ETA][1][2] = 16; m_points[ETA][1][3] = 17; m_points[ETA][2][0] = 3; m_points[ETA][2][1] = 18; m_points[ETA][2][2] = 19; m_points[ETA][2][3] = 11; m_face_points.resize(boost::extents[nb_orientations][nb_lines_per_orientation][2]); m_face_points[KSI][0][LEFT ] = 0; m_face_points[KSI][0][RIGHT] = 3; m_face_points[KSI][1][LEFT ] = 4; m_face_points[KSI][1][RIGHT] = 7; m_face_points[KSI][2][LEFT ] = 8; m_face_points[KSI][2][RIGHT] = 11; m_face_points[ETA][0][LEFT ] = 0; m_face_points[ETA][0][RIGHT] = 8; m_face_points[ETA][1][LEFT ] = 14; m_face_points[ETA][1][RIGHT] = 17; m_face_points[ETA][2][LEFT ] = 3; m_face_points[ETA][2][RIGHT] = 11; m_face_number.resize(boost::extents[nb_orientations][2]); m_face_number[KSI][LEFT ]=3; m_face_number[KSI][RIGHT]=1; m_face_number[ETA][LEFT ]=0; m_face_number[ETA][RIGHT]=2; } //////////////////////////////////////////////////////////////////////////////// const ShapeFunction& QuadFluxP3::line() const { return line_type(); } //////////////////////////////////////////////////////////////////////////////// const LineFluxP3& QuadFluxP3::line_type() { static const LineFluxP3 sf; return sf; } //////////////////////////////////////////////////////////////////////////////// void QuadFluxP3::compute_value(const MappedCoordsT& mapped_coord, ValueT& result) { throw Common::NotImplemented(FromHere(),"This should never be called, as fluxes are only being computed using LineFluxP3 instead."); } //////////////////////////////////////////////////////////////////////////////// void QuadFluxP3::compute_gradient(const MappedCoordsT& mapped_coord, GradientT& result) { throw Common::NotImplemented(FromHere(),"This should never be called, as fluxes are only being computed using LineFluxP3 instead."); } //////////////////////////////////////////////////////////////////////////////// RealMatrix QuadFluxP3::s_mapped_sf_nodes = ( RealMatrix(20,2) << -1., -1., -1./sqrt(3.), -1., 1./sqrt(3.), -1., 1., -1., -1., 0., -1./sqrt(3.), 0., 1./sqrt(3.), 0., 1., 0., -1., 1., -1./sqrt(3.), 1., 1./sqrt(3.), 1., 1., 1., -1., -1./sqrt(3.), -1., 1./sqrt(3.), 0., -1., 0., -1./sqrt(3.), 0., 1./sqrt(3.), 0., 1., 1., -1./sqrt(3.), 1., 1./sqrt(3.) ).finished(); //////////////////////////////////////////////////////////////////////////////// } // SF
namespace SF { //////////////////////////////////////////////////////////////////////////////// Common::ComponentBuilder < SFHexaLagrangeP1, ShapeFunction, LibSF > SFHexaLagrangeP1_Builder; //////////////////////////////////////////////////////////////////////////////// SFHexaLagrangeP1::SFHexaLagrangeP1(const std::string& name) : ShapeFunction(name) { m_dimensionality = dimensionality; m_nb_nodes = nb_nodes; m_order = order; m_shape = shape; } //////////////////////////////////////////////////////////////////////////////// void SFHexaLagrangeP1::compute_value(const MappedCoordsT& mapped_coord, ValueT& result) { const Real xi = mapped_coord[KSI]; const Real eta = mapped_coord[ETA]; const Real zeta = mapped_coord[ZTA]; const Real a1 = (1 + xi); const Real a2 = (1 - xi); const Real b1 = (1 + eta); const Real b2 = (1 - eta); const Real c1 = (1 + zeta); const Real c2 = (1 - zeta); result[0] = a2*b2*c2; result[1] = a1*b2*c2; result[2] = a1*b1*c2; result[3] = a2*b1*c2; result[4] = a2*b2*c1; result[5] = a1*b2*c1; result[6] = a1*b1*c1; result[7] = a2*b1*c1; result *= 0.125; } //////////////////////////////////////////////////////////////////////////////// void SFHexaLagrangeP1::compute_gradient(const MappedCoordsT& mapped_coord, GradientT& result) { const Real xi = mapped_coord[KSI]; const Real eta = mapped_coord[ETA]; const Real zeta = mapped_coord[ZTA]; const Real a1 = (1 + xi); const Real a2 = (1 - xi); const Real b1 = (1 + eta); const Real b2 = (1 - eta); const Real c1 = (1 + zeta); const Real c2 = (1 - zeta); result(KSI, 0) = -0.125 * b2*c2; result(ETA, 0) = -0.125 * a2*c2; result(ZTA, 0) = -0.125 * a2*b2; result(KSI, 1) = 0.125 * b2*c2; result(ETA, 1) = -0.125 * a1*c2; result(ZTA, 1) = -0.125 * a1*b2; result(KSI, 2) = 0.125 * b1*c2; result(ETA, 2) = 0.125 * a1*c2; result(ZTA, 2) = -0.125 * a1*b1; result(KSI, 3) = -0.125 * b1*c2; result(ETA, 3) = 0.125 * a2*c2; result(ZTA, 3) = -0.125 * a2*b1; result(KSI, 4) = -0.125 * b2*c1; result(ETA, 4) = -0.125 * a2*c1; result(ZTA, 4) = 0.125 * a2*b2; result(KSI, 5) = 0.125 * b2*c1; result(ETA, 5) = -0.125 * a1*c1; result(ZTA, 5) = 0.125 * a1*b2; result(KSI, 6) = 0.125 * b1*c1; result(ETA, 6) = 0.125 * a1*c1; result(ZTA, 6) = 0.125 * a1*b1; result(KSI, 7) = -0.125 * b1*c1; result(ETA, 7) = 0.125 * a2*c1; result(ZTA, 7) = 0.125 * a2*b1; } //////////////////////////////////////////////////////////////////////////////// RealMatrix SFHexaLagrangeP1::s_mapped_sf_nodes = ( RealMatrix(8,3) << -1., -1., -1., 1., -1., -1., 1., 1., -1., -1., 1., -1., -1., -1., 1., 1., -1., 1., 1., 1., 1., -1., 1., 1. ).finished(); //////////////////////////////////////////////////////////////////////////////// } // SF
bool Layer::Init(const Options& options) { options_ = options; RealMatrix(options_.out, options_.in, 0).swap(w_); RealVector(options_.out, 0).swap(b_); return true; }
RealMatrix ElementType::jacobian(const RealVector& mapped_coord, const RealMatrix& nodes) const { throw Common::NotImplemented(FromHere(),"jacobian not implemented for "+derived_type_name()); return RealMatrix(0,0); }