main.cpp

来自「OFELI is an object oriented library of C」· C++ 代码 · 共 161 行

CPP
161
字号
/*==============================================================================                                ********************                                *     E C 2 D 1    *                                ********************             A Finite Element Code for Quasi-Static Eddy Current Problems                Model for 2-D Geometries with scalar magnetic field  ------------------------------------------------------------------------------   Copyright (C) 1998 - 2002 Rachid Touzani   This program is free software; you can redistribute it and/or modify it under   the terms of the GNU General Public License as published by the Free    Software Foundation; Version 2 of the License.   This program is distributed in the hope that it will be useful, but WITHOUT   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS   FOR A PARTICULAR PURPOSE. See the GNU General Public License for more    details.   You should have received a copy of the GNU General Public License    along with this program; if not, write to the :   Free Software Foundation   Inc., 59 Temple Place - Suite 330   Boston, MA  02111-1307, USA  ==============================================================================*/#include <string.h>#include "OFELI.h"#include "User.h"#include "UpdateMF.h"using namespace OFELI;

using std::complex;void ScaledMF(Mesh &ms, SkMatrix<complex<double> > &a, Vect<complex<double> > &b,              complex<double> &current, double omega, int flag);int main(int argc, char *argv[]){   char mfile0[80], mfile1[80];   Mesh *ms0=NULL, *ms1=NULL;   SkMatrix<complex<double> > *a0=NULL, *a1=NULL;   Vect<complex<double> >     *b0=NULL, *b1=NULL;   NodeVect<complex<double> > *u0=NULL, *u1=NULL;   FDF *pl_file=NULL;   if (argc < 2) {     cout << "\nUsage:  EC2D1 <parameter_file>\n";     return 0;   }   IPF data("ec2d1 - 1.0",argv[1]);   int output_flag = data.Output();   int save_flag = data.Save();   int flag_volt = data.IntPar(1);   double omega = data.DoublePar(1);   complex<double> volt = data.ComplexPar(1);   complex<double> current(1,0);   if (!flag_volt)     current = volt;   if (save_flag)     pl_file = new FDF(data.PlotFile(),"w");   if (output_flag) {     cout << endl << endl;     cout << "=====================================================================\n\n";     cout << "                          E  C  2  D  1\n\n";     cout << "            A Finite Element Code for Quasi-Static Analysis\n";     cout << "      of Eddy Currents in 2-D Geometries with Scalar Magnetic Field\n\n";     cout << "            EC2D1 uses OFELI Library of Finite Element Classes\n\n";     cout << "                           V E R S I O N   1.0\n\n";     cout << "                     Copyright R. Touzani, 1999\n\n";     cout << "=====================================================================\n\n";   }//---------------------------------// Read data//---------------------------------// Read Mesh data   if (output_flag > 1)     cout << "Reading mesh data ...\n";   if (flag_volt) {     strcpy(mfile0,data.MeshFile());     ms0 = new Mesh(mfile0);   }   strcpy(mfile1,data.AuxFile(1));   ms1 = new Mesh(mfile1);   if (output_flag > 1 && flag_volt)     cout << "Mesh Data of Inductor\n\n" << *ms0;   if (output_flag > 1)     cout << "Mesh Data of Conductor\n\n" << *ms1;// Declare problem data (matrix, rhs, boundary conditions, body forces)   if (output_flag > 1)     cout << "Allocating memory for matrices and R.H.S. ...\n";   a1 = new SkMatrix<complex<double> >(*ms1);
   b1 = new Vect<complex<double> >(ms1->NbDOF());
   if (flag_volt) {     a0 = new SkMatrix<complex<double> >(*ms0);     b0 = new Vect<complex<double> >(ms0->NbDOF());   }// Calculate scaled magnetic field// -------------------------------   if (output_flag > 1)     cout << "Calculating scaled magnetic field ...\n";   if (flag_volt)     ScaledMF(*ms0,*a0,*b0,current,omega,flag_volt);   ScaledMF(*ms1,*a1,*b1,current,omega,flag_volt);// Calculate magnetic field in the free space and update it in the conductors// --------------------------------------------------------------------------   if (output_flag > 1)     cout << "Updating magnetic field ...\n";   if (flag_volt)     UpdateMF(*ms0, *ms1, omega, volt, *b0, *b1);// Output and save fields// ----------------------   if (flag_volt)     u0 = new NodeVect<complex<double> >(*ms0,*b0,"Field in Inductor");   u1 = new NodeVect<complex<double> >(*ms1,*b1,"Field in Conductor");   if (flag_volt && output_flag > 0)     cout << *u0;   if (output_flag > 0)     cout << *u1;/*   if (save_flag) {     pl_file->Put(u1);     if (flag_volt)       pl_file->Put(u0);   }*/   delete ms1;
   delete a1;   delete b1;
   delete u1;   delete pl_file;   if (flag_volt) {
     delete ms0;
     delete b0;
     delete a0;
     delete u0;
   }
   return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?