/* pdnmesh - a 2D finite element solver Copyright (C) 2001-2005 Sarod Yatawatta 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; either version 2 of the License, or (at your option) any later version. 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 $Id: model.cpp,v 1.7 2005/02/16 13:16:15 sarod Exp $ */ #include #include #include "model.h" Model::Model() { free_everything(); //initialize global variables contour_levels=40; /* no of contour levels */ current_plotting_contour=0; /* number in z array < degree_of_freedom */ g_badness_limit=2; /* max triangle badness */ g_area_floor=0.001; /* min triangle area */ g_area_ceil=0.005; /* max triangle area */ max_iteration_limit=20; /* default waveguide parameters */ global_wave_k0=1.0; global_wave_beta=10.0; g_gradient_limit=1000; solve_equation = POISSON_SPARSE; /* POISSON, HELMHOLTZ */ /* default plotting */ plot_mesh=0; plot_cont=1; plot_grad=0; plot_fill=0; plot_legend=0; /* default saving */ output_file_option=OUT_CONT_COLOR; } Model::~Model() { free_everything(); } bool Model::LoadCoordFile(const char *filename) { solve_problem_from_scratch(filename); return TRUE; } bool Model::Solve(void) { CWaitCursor wait; if ( solve_equation!=POISSON && solve_equation!=POISSON_SPARSE ) { /* number of eigenvectors to be found */ if (requested_degree_of_freedom) { degree_of_freedom=requested_degree_of_freedom; /* global change */ } else { degree_of_freedom=3; } if((eig_array= (MY_DOUBLE*) realloc((void*)eig_array,(size_t)degree_of_freedom*sizeof(MY_DOUBLE)))==0){ fprintf(stderr, "%s: %d: no free memory\n", __FILE__,__LINE__); exit(1); } if (solve_equation==HELMHOLTZ) { re_number_and_solve_helmholtz(); } else if ((solve_equation == HELMHOLTZ_INHOMO) || (solve_equation == HELMHOLTZ_FREQ) || (solve_equation == HELMHOLTZ_BETA)) { buildup_hash_table_and_equation(M,dt); } } else if (solve_equation==POISSON_SPARSE) { re_number_and_solve_poisson_sparse(); } else { /* POISSON */ re_number_and_solve_poisson(); } wait.Restore(); return TRUE; } void Model::Render(void) { global_render(); } bool Model::SaveOutput(const char *filename) { switch (output_file_option) { case OUT_CONT: print_contour_all((char*)filename,0,M); break; case OUT_CONT_COLOR: print_contour_all((char*)filename,1,M); break; case OUT_CONT_COLOR_LEGEND: print_contour_all((char*)filename,2,M); break; case OUT_GRAD: print_gradient((char*)filename,M); break; case OUT_MESH_EPS: print_mesh_eps((char*)filename,M); break; case OUT_MESH: print_mesh_ascii((char*)filename,M); break; case OUT_POTENTIAL: print_potential((char*)filename,M); break; default: break; } return TRUE; }