tfuns.cpp

00001 /*************************************************************************************
00002  * MechSys - A C++ library to simulate (Continuum) Mechanical Systems                *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>       *
00004  * Copyright (C) 2005 Raul Dario Durand Farfan  <raul.durand at gmail.com>           *
00005  *                                                                                   *
00006  * This file is part of MechSys.                                                     *
00007  *                                                                                   *
00008  * MechSys is free software; you can redistribute it and/or modify it under the      *
00009  * terms of the GNU General Public License as published by the Free Software         *
00010  * Foundation; either version 2 of the License, or (at your option) any later        *
00011  * version.                                                                          *
00012  *                                                                                   *
00013  * MechSys is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   *
00015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.          *
00016  *                                                                                   *
00017  * You should have received a copy of the GNU General Public License along with      *
00018  * MechSys; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  * Fifth Floor, Boston, MA 02110-1301, USA                                           *
00020  *************************************************************************************/
00021 
00022 #include <iostream>
00023 
00024 #include "tensors/tensors.h"
00025 #include "tensors/functions.h"
00026 
00027 using namespace std;
00028 
00029 int main(int argc, char **argv)
00030 {
00031     //Tensors::Tensor2 a("1 2 3 4 5 6");
00032     //Tensors::Tensor2 a; a=2,2,2,0,0,0.0001;
00033     Tensors::Tensor2 a; a(0)=10; a(1)=20; a(2)=30; a(3)=4*sqrt(2.0); a(4)=6*sqrt(2.0);  a(5)=5*sqrt(2.0);
00034     Tensors::Tensor2 b; b(0)=20; b(1)=40; b(2)=60; b(3)=8*sqrt(2.0); b(4)=12*sqrt(2.0); b(5)=10*sqrt(2.0); // with this tensor, the matrix product a*b will be symmetric
00035     //Tensors::Tensor2 b(" 6  5  4  3  2  1"); // with this tensor, the matrix product a*b will NOT be symmetric
00036 
00037     cout << "a = " << a << endl;
00038     cout << "b = " << b << endl;
00039 
00040     Tensors::Tensor4 T;
00041     for (int i=0; i<6; ++i)
00042     for (int j=0; j<6; ++j)
00043         T(i,j) = 10*(i+1) + (j+1);
00044 
00045     Tensors::Tensor2 ab;
00046     Tensors::Tensor2 inv_a;
00047     REAL             only_ev_a[3];
00048     REAL             ev_a[3];
00049     Tensors::Tensor2 ep_a[3];
00050     Tensors::Tensor2 sqrt_a;
00051 
00052     Tensors::Mult(a,b,ab);
00053 
00054     if (!Tensors::Inv(a,inv_a))
00055     {
00056         cout << "ERROR: Inv(a) failed\n";
00057     }
00058     if (!Tensors::Eigenvals(a,only_ev_a))
00059     {
00060         cout << "ERROR: Eigenvals(a) failed\n";
00061     }
00062     if (!Tensors::Eigenvp(a,ev_a,ep_a))
00063     {
00064         cout << "ERROR: Eigenvp(a) failed\n";
00065     }
00066     if (!Tensors::Sqrt(a,sqrt_a))
00067     {
00068         cout << "ERROR: sqrt(a) failed\n";
00069     }
00070 
00071     cout << "ab =     \n" << ab << endl;
00072     cout << "Norm(a) = " << Tensors::Norm(a) << endl;
00073     cout << "inv_a =  \n" << inv_a << endl;
00074     cout << "only_ev_a =   \n"; for (int i=0; i<3; ++i) cout << only_ev_a[i] << endl;
00075     cout << "ev_a =   \n"; for (int i=0; i<3; ++i) cout << ev_a[i] << endl;
00076     cout << "ep_a =   \n"; for (int i=0; i<3; ++i) cout << ep_a[i] << endl;
00077     cout << "sqrt_a = \n" << sqrt_a << endl;
00078 
00079     REAL Ia[3];
00080     REAL Ev,Ed,p,q,tn,ts,P,Q;
00081 
00082     Tensors::Tensor2 I; I(0)=1.0; I(1)=1.0; I(2)=1.0; I(3)=0.0; I(4)=0.0; I(5)=0.0; 
00083     //Tensors::Tensor2 isoA; isoA = 
00084     //Tensors::Tensor2 devA;
00085     Tensors::CharInvs(a,Ia);
00086     Tensors::Strain_Ev_Ed(a,Ev,Ed);
00087     Tensors::Stress_p_q(a,p,q);
00088     Tensors::Stress_tn_ts(a,tn,ts);
00089     Tensors::Stress_P_Q(a,P,Q);
00090 
00091     cout << "a = " << a << endl;
00092     cout << "Ia[0]=" << Ia[0] << ", Ia[1]=" << Ia[1] << ", Ia[2]=" << Ia[2] << endl;
00093     cout << "Ev=" << Ev << ", Ed=" << Ed << ", p=" << p << ", q=" << q << endl;
00094     cout << "tn=" << tn << ", ts=" << ts << endl;
00095     cout << "P=" << P << ", Q=" << Q << endl;
00096 
00097     cout << "I=" << Tensors::I << endl;
00098     cout << "IIsym=\n" << Tensors::IIsym << endl;
00099     cout << "IdyI=\n"  << Tensors::IdyI << endl;
00100 
00101     REAL sin3th;
00102     Tensors::Tensor2 S;
00103     Tensors::Stress_p_q_S_sin3th(a, p,q,S,sin3th);
00104     cout << "p=" << p << ", q=" << q << ", S=" << S << ", sin3th=" << sin3th << endl;
00105 
00106     Tensors::Stress_P_Q_S_sin3th(a, P,Q,S,sin3th);
00107     cout << "P=" << P << ", Q=" << Q << ", sin3th=" << sin3th << endl;
00108 
00109     return 0;
00110 }

Generated on Wed Jan 24 15:56:27 2007 for MechSys by  doxygen 1.4.7