Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

app-kersten/Eddy2D_E.hh
Go to the documentation of this file.
00001 #ifndef Eddy2D_hh
00002 #define Eddy2D_hh
00003 
00004 #include "space.hh"
00005 #include "basics/debug.hh"
00006 
00007 using concepts::Real;
00008 using concepts::Real2d;
00009 using concepts::Cmplx;
00010 
00011 //************************************************************ Standardwerte **
00012 // Polynomgrad
00013 uint p = 0;
00014 // Anzahl gleichmaessiger Verfeinerungen
00015 uint l = 0;
00016 // Anzahl geometrischer Verfeinerung
00017 uint g = 0;
00018 // leitendes Objekt
00019 bool leitend = true;
00020 // Grunddatei des Gitters
00021 std::string gitter = "E2"; // E2, Es, 4Q oder 2R
00022 // soll geloest werden
00023 bool solve = true;
00024 // sollen die Matrizen gespeichert werden
00025 bool matrixoutput = false;
00026 // soll eine graphische Ausgabe erfolgen
00027 uint graphik = 2;
00028 // Stringstreams fuer Ausgabedateinamen
00029 std::ostringstream sl, sp, sg;
00030 // Standardpfad
00031 std::string path = SOURCEDIR "/app-kersten/Wirbelstrom2D/";
00032 // Dateiname fuer Matrizenausgabe
00033 std::string filename;
00034 
00035 void input(int& argc, char** argv, std::string& probname) {
00036   int opt;
00037   filename = path + probname + "_Matrices.m";
00038   while ((opt = getopt(argc, argv, "-l:p:g:L:n:s:mG:hH")) != EOF)
00039     switch(opt) {
00040     case 'l': l = atoi(optarg); break;
00041     case 'p': p = atoi(optarg); break;
00042     case 'g': g = atoi(optarg); break;
00043     case 'L': leitend = std::atoi(optarg)>0; break;
00044     case 'n': gitter = optarg; break;
00045     case 's': solve = std::atoi(optarg)>0; break;
00046     case 'm': matrixoutput = true; break;
00047     case 'G': {
00048       graphik = std::atoi(optarg);
00049       if (graphik < 2) graphik = 2;
00050       break;
00051     }
00052     default:
00053       if ((opt != 'h') && (opt != 'H'))
00054   std::cout << "Option '" << opt << "' unkown." << std::endl;
00055       std::cout << "Usage: " << argv[0] 
00056     << " [-l LEVEL] [-p POLY] [-g GEOMLEVEL]"
00057     << "[-L CONDUCT] [-n MESH_NAME] [-s SOLVE]"
00058     << "[-m]" << std::endl
00059     << "where" << std::endl
00060     << "  LEVEL: level of refinement" << std::endl
00061     << "  POLY: starting polynomial degree" << std::endl
00062     << "  GEOMLEVEL: additonal level of geometrical refinement"
00063     << std::endl
00064     << "  CONDUCT: (0) non conducting material (1) conducting" 
00065     << std::endl
00066     << "  MESH_NAME: name of the mesh (thickLshape)" << std::endl
00067     << "  SOLVE: (0) not solving (1) solving system" << std::endl
00068     << "-m : matrices are stored into " << filename << std::endl;
00069   exit(1);
00070   break;
00071       }
00072   sl << l; sp << p; sg << g;
00073   std::cout << "Polynomgrad  : " << p << std::endl
00074       << "Verfeinerung : " << l << std::endl
00075             << "geom.Verfein : " << g << std::endl
00076             << "leitend      : " << leitend << std::endl
00077       << "Gitter       : " << gitter << std::endl
00078       << "Matrixausgabe: ";
00079   if (matrixoutput)
00080     std::cout << filename << std::endl;
00081   else {
00082     std::cout << "nein" << std::endl;
00083     filename.clear();
00084   }
00085 }
00086 
00087 //****************************************************************** Gitter **
00088 
00089 std::string coord, elem, bound; // Gitterdateien
00090 std::auto_ptr<concepts::Mesh2> msh;     // Gitter
00091 
00092 void Gitter() {
00093   coord = path + "Coord_" + gitter + ".dat";
00094   elem  = path + "Elem_" + gitter + ".dat";
00095   bound = path + "Bound_" + gitter + ".dat";
00096 
00097   msh.reset
00098     (new concepts::Import2dMesh(coord.c_str(), elem.c_str(), bound.c_str()));
00099 
00100   std::cout << "Gitter aus den Dateien: " << std::endl
00101       << "  " << coord << std::endl
00102       << "  " << elem << std::endl
00103       << "  " << bound << std::endl;
00104 
00105   std::cout << "Gitter: " << *msh << std::endl;
00106 }
00107 
00108 //*************************************************************** Konstanten **
00109 
00110 // Kreisfrequenz
00111 const Real omega = 50.0/2/M_PI;   // Kreisfrequenz in 1/s
00112 
00113 // Materialkonstanten
00114 const Real sigma = 5.8e7;         // Leitfähigkeit in 1/Ohm/m
00115 const Real eps_0 = 8.85419e-12;   // Dielektrizitätskonstante in s/(Ohm*m)
00116 // const Real eps_0 = 1;
00117 const Real mu_0  = 1.25644e-6;    // Permabilitätskonstante in Ohm*s/m
00118 const Real J0 = 1;                // Stromdichte in A/m^2
00119 
00120 //********************************************************** Materialformeln **
00121 
00122 // stückweise definierte und konstante Leitfähigkeit
00123 // Standardwert: 0
00124 concepts::PiecewiseConstFormula<Real> Sigma;
00125 // stückweise definierte Dielektrizität
00126 // Standardwert: eps_0 (überall)
00127 concepts::PiecewiseConstFormula<Real> Eps(eps_0);
00128 // stückweise definierte und konstanter Quellstrom
00129 // Standardwert: (0,0)
00130 const Real sqrt2 = std::sqrt(0.5);
00131 concepts::PiecewiseConstFormula<Real> J0x, J0y;
00132 
00133 void material() {
00134   if (leitend) {
00135     Sigma[2] = sigma;                 // Werkstueck
00136     //     for(uint i = 2; i < 11; ++i) Sigma[i] = sigma;
00137   }
00138   std::cout << "Sigma: " << Sigma << std::endl;
00139 
00140   J0x[3] = J0x[4] = J0y[4] = J0y[5] = J0y[6] = J0x[10] = J0;
00141   J0y[3] = J0x[5] = J0x[9] = J0y[7] = 0.0;
00142   J0x[6] = J0x[7] = J0x[8] = J0y[8] = J0y[9] = J0y[10] = -J0; 
00143 // J0x[3] = J0; J0y[3] = 0.0;
00144 // J0x[4] = J0y[4] = sqrt2 * J0;
00145 // J0x[5] = 0.0; J0y[5] = J0;
00146 // J0x[6] = -sqrt2 * J0; J0y[6] = sqrt2 * J0;
00147 // J0x[7] = -J0x[3]; J0x[8] = -J0x[4]; J0x[9] = -J0x[5]; J0x[10] = -J0x[6];
00148 // J0y[7] = -J0y[3]; J0y[8] = -J0y[4]; J0y[9] = -J0y[5]; J0y[10] = -J0y[6];
00149   std::cout << "J0x: " << J0x << std::endl;
00150   std::cout << "J0y: " << J0y << std::endl;
00151 }
00152 
00153 //**************************************************************** FEM-Raum **
00154 
00155 // Gemischter Raum
00156 vectorial::Space<Real> Spc(2);
00157 
00158 // geometrisches Verfeinern zu Ecken oder Kanten mit Attribut attrib
00159 template<class F>
00160 void verfeinern(F& spc, uint attrib, int pMax[2]) {
00161   for(uint i=0; i < g; ++i) {
00162     hp2D::APrioriRefinement refineSpace(spc, attrib, attrib, pMax);
00163     concepts::GlobalPostprocess<Real> post(spc);
00164     post(refineSpace);
00165     spc.rebuild();
00166     std::cout << std::endl;
00167   }
00168 }
00169 
00170 template<class F>
00171 void verfeinerElm(F& spc, uint nrElm, uint l, uint p, bool rebuild = false) {
00172   concepts::AdaptiveAdjustP<2> a(l, p);
00173   std::auto_ptr<concepts::Space<Real>::Scanner> sc(spc.scan());
00174   const concepts::Element<Real>* elm;
00175   while (*sc && nrElm-- > 0)
00176     elm = &(*sc)++;
00177   spc.adjust(*elm, a);
00178   if (rebuild) spc.rebuild();
00179 }
00180 
00181 void elemente(concepts::Space<Real>& spc){
00182   std::auto_ptr<concepts::Space<Real>::Scanner> sc(spc.scan());
00183   uint i = 1;
00184   while (*sc) {
00185     const concepts::Element<Real>& elm = (*sc)++;
00186     std::cout << i++ << ".Element = " << elm << std::endl;
00187   }
00188 }
00189 
00190 //*********************************************************** Bilinearformen **
00191 
00192 // a(.,.) Bilinearform
00193 hp2Dedge::RotRot rotrot;
00194 // m_Eddy(.,.) Bilinearform
00195 std::auto_ptr<hp2Dedge::Identity> eddy;
00196 
00197 // Systemmatrix
00198 std::auto_ptr<concepts::SparseMatrix<Cmplx> > S;
00199 // Rot-Rot-Matrix
00200 std::auto_ptr<concepts::SparseMatrix<Real> > A;
00201 // Wirbelstrom-Massenmatrix
00202 std::auto_ptr<concepts::SparseMatrix<Real> > M_eddy;
00203 
00204 std::auto_ptr<concepts::Vector<Cmplx> > rhs, sol, solN;
00205 
00206 void rotrotMatrix(hp2Dedge::Space& spc) {
00207   concepts::ResourceMonitor timer;
00208   A.reset(new concepts::SparseMatrix<Real>(spc, rotrot));
00209   *A *= 1.0/mu_0;
00210   std::cout << "time for RotRot= " << timer << std::endl;
00211   std::cout << "A = " << *A << std::endl;
00212   A->storeMatlab(filename.c_str(), "A");
00213   A->addInto(*S, Cmplx(1.0,0.0));
00214 }
00215 
00216 void eddyMatrix(hp2Dedge::Space& spc) {
00217   // m_Eddy(.,.) Bilinearform mit Leitfaehigkeit
00218   eddy.reset(new hp2Dedge::Identity(Sigma));
00219   concepts::ResourceMonitor timer;
00220   M_eddy.reset(new concepts::SparseMatrix<Real>(spc, *eddy));
00221   *M_eddy *= omega;
00222   std::cout << "time for M_eddy= " << timer << std::endl;
00223   std::cout << "M_eddy = " << *M_eddy << std::endl;
00224   M_eddy->storeMatlab(filename.c_str(), "M_eddy", true);
00225   M_eddy->addInto(*S, Cmplx(0.0, 1.0));
00226 }
00227 
00228 void regMatrix(hp2Dedge::Space& spcE, hp2D::Space& spcN) {
00229   // Regularisierung
00230   vectorial::BilinearForm<Real> Bf(2);
00231   hp2Dedge::Graduv graduv;
00232   Bf.put(graduv, 1, 0);
00233   // Massenmatrix fuer Regularisierung
00234   concepts::ResourceMonitor timer;
00235   concepts::SparseMatrix<Real> M(Spc, Bf);
00236   std::cout << "time for Graduv= " << timer << std::endl;
00237   std::cout << "M = " << M << std::endl;
00238   M.storeMatlab(filename.c_str(), "M1", true);
00239   M.addInto(*S, Cmplx(10000000.0,0.0), 0, 0);
00240   M.addIntoT(*S, Cmplx(10000000.0,0.0), 0, 0); // transposed 
00241 }
00242 
00243 void lumpingMatrix(hp2Dedge::Space& spcE, hp2D::Space& spcN) {
00244   // Lumping-Beitrag
00245   hp2D::Laplace<Real> stiff;
00246   concepts::SparseMatrix<Real> A(spcN, stiff);
00247   std::cout << "A_ = " << A << std::endl;
00248   A.storeMatlab(filename.c_str(), "A_", true);
00249   A.addInto(*S, Cmplx(-1.0,0.0), spcE.dim(), spcE.dim());
00250 }
00251 
00252 void gesamtMatrix() {
00253   std::cout << "S = " << *S << std::endl;
00254   S->storeMatlab(filename.c_str(), "S", true);
00255 //   S->compress();
00256 //   std::cout << "S after compression = " << *S << std::endl;
00257 }
00258 
00259 template<class F>
00260 void linearform(hp2Dedge::Space& spc, concepts::Space<F>& Spc) {
00261   rhs.reset(new concepts::Vector<Cmplx>(Spc));
00262   {
00263     hp2Dedge::Riesz lform(J0x, J0y);
00264     concepts::Vector<Real> rhs_(spc, lform);
00265     rhs_ *= -1.0;
00266     rhs->add(rhs_);
00267   }
00268   if (Spc.dim()<40)
00269     std::cout << "rhs = " << *rhs << std::endl;
00270 }
00271 
00272 void loeser(concepts::Space<Real>& spc) {
00273   sol.reset(new concepts::Vector<Cmplx>(spc));
00274 
00275   // kein Loesen, falls kein SuperLU vorhanden oder dies gewuenscht ist
00276 #ifdef HAS_SuperLU
00277   if (!solve)
00278     return;
00279 
00280   concepts::SuperLU<Cmplx> solver(*S);
00281   solver(*rhs, *sol);
00282 
00283   if (spc.dim() < 40)
00284     std::cout << "sol = " << *sol << std::endl;
00285 #endif
00286 }
00287 
00288 //******************************************************* graphische Ausgabe **
00289 
00290 std::string dateiname(std::string varname, bool p = false) {
00291   std::string tmp(path);
00292   tmp += varname + '_' + gitter + "_l" + sl.str() + "_g" + sg.str();
00293   if (p) tmp += "_p" + sp.str();
00294   std::cout << tmp << std::endl;
00295   return tmp;
00296 }
00297 
00298 void formelausgabe(concepts::Space<Real>& spc,
00299                    concepts::PiecewiseFormulaBase<Real>& frm,
00300                    std::string frmstr) {
00301   graphics::MatlabGraphics(spc, dateiname(frmstr), frm);
00302 }
00303 
00304 void graphicalout(hp2Dedge::Space& spc, std::string probname) {
00305   if (graphik==0) return;
00306 
00307   hp2D::IntegrableQuad::rule().set(concepts::TRAPEZE, true, graphik);
00308   spc.recomputeShapefunctions();
00309 
00310   // Ausgabe von Gitter und des Materials in Matlab-Datei
00311   // Ansicht mit fill(x(msh),y(msh),u(msh))
00312   formelausgabe(spc, Sigma, "Sigma");
00313   formelausgabe(spc, J0x, "J0x");
00314   formelausgabe(spc, J0x, "J0y");
00315 
00316   graphics::drawMeshEPS(spc, 
00317       (dateiname(probname + "/Mesh/Mesh")+ ".eps").c_str());
00318 
00319   // Ausgabe der Lösung
00320   if (solve) {
00321     graphics::MatlabGraphics
00322       (spc, dateiname(probname + "/Grafik/" + probname + "_Sol", true), *sol);
00323   }
00324 }
00325 
00326 //**************************************************************** Energien **
00327 
00328 // Verlustleistung 1/2 int j * e dx = 1/2 int sigma e * e dx [1 W]
00329 template<class F>
00330 Real dissipation(concepts::Vector<F>& sol) {
00331   concepts::Vector<F> tmp(sol.dim());
00332   (*M_eddy)(sol, tmp);
00333   tmp.apply(std::conj);
00334   return real(sol * tmp) / omega / 2.0;
00335 }
00336 
00337 // Magnetische Energie 1/2 int b * h dx [1 J]
00338 template<class F>
00339 Real magneticEnergy(concepts::Vector<F>& sol) {
00340   concepts::Vector<F> tmp(sol.dim());
00341   (*A)(sol, tmp);
00342   tmp.apply(std::conj);
00343   return real(sol * tmp) / 2.0 / (omega*omega);
00344 }
00345 
00346 #endif // Eddy2D_hh

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)