Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
generateGaussLegendre.cpp
Go to the documentation of this file.
1/* This file is part of MODEL, the Mechanics Of Defect Evolution Library.
2 *
3 * Copyright (C) 2011 by Giacomo Po <gpo@ucla.edu>.
4 *
5 * model is distributed without any warranty under the
6 * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>.
7 */
8
9#ifndef model_GENERATEGAUSSLEGENDRE_H_
10#define model_GENERATEGAUSSLEGENDRE_H_
11
12#include <iostream>
13#include <assert.h>
14#include <math.h>
15#include <fstream>
16#include <string>
17#include <sstream>
18#include <iomanip>
19
20
21#include <model/Quadrature/QuadratureRecursiveRelation.h>
22#include <model/Quadrature/GaussLegendre/GaussLegendreRecursiveRelation.h>
23
24
25std::string modelHeader()
26{
27 return " /* This file is part of MODEL, the Mechanics Of Defect Evolution Library. \n * \n * Copyright (C) 2011 by Giacomo Po <gpo@ucla.edu>. \n * \n * model is distributed without any warranty under the \n * GNU General Public License (GPL) v2 <http://www.gnu.org/licenses/>. \n */";
28}
29
30int main(int argc, char *argv[])
31{
32
33 assert(argc==2 && "YOU MUST PASS EXACTLY ONE ARGUMENT (quadraturePowerMax).");
34
35 const int quadraturePowerMax(atoi(argv[1])); // convert arg[1] to int
36 assert(quadraturePowerMax>0 && "quadraturePowerMax MUST BE > 0.");
37
38 std::cout<<"quadraturePowerMax="<<quadraturePowerMax<<std::endl;
39
40 int dim=1;
41
42 std::string includeFileName("../includeGaussLegendre1D.h");
43 std::ofstream includeFile(includeFileName.c_str(), std::ios::out);
44 assert(includeFile.good() && "includeFile is not good.");
45
46 includeFile << modelHeader() << "\n\n";
47 includeFile << "/*** This file is automatically generated by generateGaussLegendre.cpp ***/\n";
48 includeFile << "#ifndef model_INCLUDEGAUSSLEGENDRE_"<<dim<<"_H_ \n";
49 includeFile << "#define model_INCLUDEGAUSSLEGENDRE_"<<dim<<"_H_ \n\n";
50
51 const double div=4;
52 std::set<int> orders;
53 for (int p=0; p<quadraturePowerMax;++p)
54 {
55 const int p0=std::pow(2.0,p);
56 const int p1=std::pow(2.0,p+1);
57 for (int d=1;d<=div;d++)
58 {
59 orders.emplace(p0+d/div*(p1-p0));
60 }
61 }
62
63
64// for (int p=0; p<=quadraturePowerMax;++p)
65 for(const int& qOrder : orders)
66 {
67
68// int qOrder = std::pow(2.0,p);
69 //int qOrder = p;
70
71// std::cout<<"computing qOrder="<<qOrder<<"..."<<std::flush;
72 // Compute Abscissas and weights for current case
74
75 // Write to file
76 std::ostringstream filestream;
77 filestream << "../dim1/GaussLegendre_1_" << qOrder << ".h";
78 std::string filename=filestream.str();
79 std::cout<<"Writing file "<<filestream.str()<<std::endl;
80 remove(filename.c_str()); // eventually delete existing file
81 std::ofstream file(filename.c_str(), std::ios::out);
82 assert(file.good() && "file is not good.");
83
84 file << modelHeader() << "\n\n";
85 file << "/*** This file is automatically generated by generateGaussLegendre.cpp ***/\n";
86 file << "#ifndef model_GAUSSLEGENDRE_"<<dim<<"_"<<qOrder<<"_H_ \n";
87 file << "#define model_GAUSSLEGENDRE_"<<dim<<"_"<<qOrder<<"_H_ \n\n";
88 file << "namespace model\n{\n\n";
89 file << " template<>\n";
90 file << " struct GaussLegendre<"<<dim<<","<<qOrder<<">\n";
91 file << " {\n";
92 file << " static Eigen::Matrix<double,"<<dim+1<<","<<qOrder<<"> abcsissasAndWeights()\n";
93 file << " {\n";
94 file << " Eigen::Matrix<double,"<<qOrder<<","<<dim+1<<"> aw;\n";
95 file << " aw<<";
96 for (int q=0;q<qOrder;++q)
97 {
98 for (int d=0;d<dim+1;++d)
99 {
100 if (d==dim && q==qOrder-1)
101 {
102 file <<std::setprecision(15)<<std::scientific<<abcsissasAndWeights(d,q) << "; ";
103 }
104 else
105 {
106 file <<std::setprecision(15)<<std::scientific<<abcsissasAndWeights(d,q) << ", ";
107 }
108 }
109 file << "\n";
110 file << " ";
111 }
112 file << "\n";
113 file << " return aw.transpose();\n";
114 file << " } \n";
115 file << " }; \n";
116 file << "/*************************************************/\n";
117 file << "} \n";
118 file << "#endif \n"<<std::endl;
119 file.close();
120
121 // add to include file
122 includeFile << "#include <model/Quadrature/GaussLegendre/dim1/GaussLegendre_1_"<<qOrder<<".h>\n";
123 }
124
125
126 includeFile << " \n";
127 includeFile << "#endif \n"<<std::endl;
128 includeFile.close();
129
130}
131
133#endif
134
std::string modelHeader()
the magnitude of the R vector q
static Eigen::MatrixXd abcsissasAndWeights(const int &qOrder)
void argv
vertex p1
void b int argc
vertex p[3]