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

app-bholger/gfem/inputHelp.h
Go to the documentation of this file.
00001 #pragma once
00002 
00003 #include "basics.hh"
00004 #include "toolbox.hh"
00005 #include "unitcell.h"
00006 #include "hp2D.hh"
00007 #include "graphics.hh"
00008 #include "operator/denseMatrix.hh"
00009 #include <memory>
00010 
00011 namespace concepts {
00012 namespace gfem {
00013 
00014 class InputUC_filename : public InputParameter 
00015 {
00016   public:
00018     InputUC_filename(InOutParameters& input, std::string filename="") 
00019       : InputParameter(input)
00020       , filename(filename)
00021     {}
00022 
00023     virtual std::ostream& letters(std::ostream& os) const {
00024       return os << "u:";
00025     }
00026     virtual std::ostream& arguments(std::ostream& os) const {
00027       return os << "[-u uc_filename]";
00028     }
00029     virtual std::ostream& description(std::ostream& os) const {
00030       os << "  uc_filename    : filename with a cig configuration "
00031         " file for the unitcell."
00032         << std::endl;
00033       return os;
00034     }
00035 
00039     virtual int input(int opt, const char* optarg); 
00040 
00041     std::string& getFilename() {
00042       return filename;
00043     }
00044   protected:
00045     virtual std::ostream& info(std::ostream& os) const {
00046          os << "InputUC_filename(";
00047          return arguments(os) << ")";
00048     }
00049   private:
00051     unsigned long long slot_;
00052     std::string filename;
00053 };
00054 
00055 class InputSol_filename : public InputParameter 
00056 {
00057   public:
00059     InputSol_filename(InOutParameters& input, std::string filename="") 
00060       : InputParameter(input)
00061       , filename(filename)
00062     {}
00063 
00064     virtual std::ostream& letters(std::ostream& os) const {
00065       return os << "e:";
00066     }
00067     virtual std::ostream& arguments(std::ostream& os) const {
00068       return os << "[-e EF_filename]";
00069     }
00070     virtual std::ostream& description(std::ostream& os) const {
00071       os << "  EF_filename    : filename with the matlab matrix of"
00072         " the eigenfunction which will be converted in a format"
00073         " suitable for simplemesh and stored in 'ef_out.m'. "
00074         " If specified the functionality of the file changes"
00075         " and _no_ TE/TM Matrices are stored, but you need to"
00076         " give the same input parameters."
00077         << std::endl;
00078       return os;
00079     }
00080 
00084     virtual int input(int opt, const char* optarg); 
00085 
00086     std::string& getFilename() {
00087       return filename;
00088     }
00089   protected:
00090     virtual std::ostream& info(std::ostream& os) const {
00091          os << "InputSol_filename(";
00092          return arguments(os) << ")";
00093     }
00094   private:
00096     unsigned long long slot_;
00097     std::string filename;
00098 };
00099 
00120 extern void loadEFs(const Space<Real>& uc_space, Unitcell& uc, std::string ef_filename = "work/efs.dat");
00121 
00127 extern bool loadCoeffVector(std::string filename, 
00128     concepts::Vector<Cmplx>& coeffs);
00129 
00130 template<class SpaceType, class SpaceTypeUC>
00131 inline void storeMatlabExt(SpaceType& space, SpaceTypeUC& spaceUC, 
00132     std::string filename, 
00133     std::string filenameGrad, 
00134     concepts::Vector<concepts::Cmplx> sol, 
00135     std::string additional="", 
00136     bool restoreQR = true,
00137     int graphik = 12, 
00138     std::string quadType_str="trapeze"
00139     )
00140 {
00141     concepts::intRule quadType = concepts::GAUSS_JACOBI; 
00142     if(quadType_str == "trapeze") {
00143       quadType = concepts::TRAPEZE;
00144     } else if(quadType_str == "gauss_lobatto") {
00145       quadType = concepts::GAUSS_LOBATTO;
00146     } else if(quadType_str == "gauss_jacobi") {
00147       quadType = concepts::GAUSS_JACOBI;
00148     } else {
00149       printf("Error, invalid quadrature type '%s'\n", quadType_str.c_str());
00150       exit(1);
00151     }
00152     printf("(store matlab graphics) using %d graphic points and quad"
00153         " rule of type %d (%s)\n", 
00154         graphik, int(quadType), quadType_str.c_str());
00155     
00156 #if 1
00157     hp2D::IntegrableQuad::rule().set( quadType, true, graphik);
00158     spaceUC.recomputeShapefunctions();
00159     space.recomputeShapefunctions();
00160 #endif
00161 
00162     hp2D::Value<Cmplx> eval_f;
00163     graphics::MatlabGraphics(space, filename, sol, 2, &eval_f);
00164 
00165     if(filenameGrad != "") {
00166       hp2D::Grad<Cmplx> eval_f_G;
00167       graphics::MatlabGraphics(space, filenameGrad, sol, 2, &eval_f_G);
00168     }
00169 
00170     if(restoreQR) {
00171       hp2D::IntegrableQuad::rule().set( concepts::GAUSS_JACOBI, true, 2);
00172       spaceUC.recomputeShapefunctions();
00173       space.recomputeShapefunctions();
00174     }
00175 
00176     FILE* f = fopen(filename.c_str(), "a");
00177     if(f) {
00178       fprintf(f, "\n %s\n", additional.c_str());
00179       fclose(f);
00180     } else {
00181       fprintf(stderr, "**** Failed to write to '%s'\n ***", filename.c_str());
00182     }
00183 }
00184 
00185 // version without spaceUC
00186 template<class SpaceType>
00187 inline void storeMatlabExt(SpaceType& space, 
00188     std::string filename, 
00189     std::string filenameGrad, 
00190     concepts::Vector<concepts::Cmplx> sol, 
00191     std::string additional="", 
00192     bool restoreQR = true,
00193     int graphik = 12, 
00194     std::string quadType_str="trapeze",
00195     bool addPolDegToGraphik = false // false: number of QR points = graphik 
00196                                     // true:  number of QR points = graphik + pol_deg
00197     )
00198 {
00199     concepts::intRule quadType = concepts::GAUSS_JACOBI; 
00200     if(quadType_str == "trapeze") {
00201       quadType = concepts::TRAPEZE;
00202     } else if(quadType_str == "gauss_lobatto") {
00203       quadType = concepts::GAUSS_LOBATTO;
00204     } else if(quadType_str == "gauss_jacobi") {
00205       quadType = concepts::GAUSS_JACOBI;
00206     } else {
00207       printf("Error, invalid quadrature type '%s'\n", quadType_str.c_str());
00208       exit(1);
00209     }
00210     printf("using %d graphic points and quad rule of type %d (%s)\n", graphik, int(quadType), 
00211         quadType_str.c_str());
00212     
00213 #if 1
00214     hp2D::IntegrableQuad::rule().set( quadType, !addPolDegToGraphik, graphik);
00215     space.recomputeShapefunctions();
00216 #endif
00217 
00218     hp2D::Value<Cmplx> eval_f;
00219     graphics::MatlabGraphics(space, filename, sol, 2, &eval_f);
00220 
00221     hp2D::Grad<Cmplx> eval_f_G;
00222     graphics::MatlabGraphics(space, filenameGrad, sol, 2, &eval_f_G);
00223 
00224     if(restoreQR) {
00225       hp2D::IntegrableQuad::rule().set( concepts::GAUSS_JACOBI, true, 2);
00226       space.recomputeShapefunctions();
00227     }
00228 
00229     FILE* f = fopen(filename.c_str(), "a");
00230     if(f) {
00231       fprintf(f, "\n %s\n", additional.c_str());
00232       fclose(f);
00233     } else {
00234       fprintf(stderr, "**** Failed to write to '%s'\n ***", filename.c_str());
00235     }
00236 }
00237 
00238 std::auto_ptr< DenseMatrix<Real> > loadRawMatrix(std::string filename);
00239 
00240 } // namespace
00241 } // namespace

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