00001 #include "dealbasedofs.h"
00002 #include "numericmethods.h"
00003 #include <vector>
00004 #include <fe/fe_base.h>
00005 #include <grid/grid_generator.h>
00006 DoFCell DealBaseDoFs::getDoFCellAtPoint(const DoFHandler<DIM>& dof,const Point<DIM> &p)
00007 {
00008 DoFCell cell = dof.begin_active();
00009 DoFCell endc = dof.end();
00010
00011 for (;cell!= endc;cell++)
00012 {
00013 if (NumericMethods::isInCube(p,cell->vertex(VERTEX_000),cell->vertex(VERTEX_111)))
00014 {
00015 return cell;
00016 }
00017 }
00018 return DoFCell();
00019
00020 }
00021
00022
00030 DoFCell DealBaseDoFs::getAdjDoFCell(DoFCell cell,CellDirection3D dir)
00031 {
00032 if (cell->face(dir)->at_boundary())
00033 return DoFCell();
00034 else
00035 return cell->neighbor(dir);
00036 }
00037
00038
00039
00040
00043 double DealBaseDoFs::getDoFVerticeValue(DoFCell cell,VertexDirection3D dir,unsigned deg,const VecDouble &vSol)
00044 {
00045 assert(cell->vertex_dof_index(dir,deg) < vSol.size());
00046 return vSol(cell->vertex_dof_index(dir,deg));
00047 }
00048
00049
00050
00051 void DealBaseDoFs::printCellDofsInformation(const DoFHandler<2>& dofs,std::ostream &out)
00052 {
00053 const DoFHandler<2> &dof = dofs;
00054 DoFHandler<2>::active_cell_iterator cell = dof.begin_active(),
00055 endc = dof.end();
00056 char strOut[500];
00057
00058 for (;cell!=endc; ++cell)
00059 {
00060 sprintf(strOut,"\n==================\nCell %d:\nDoFs: %d\n\nVertices:\n",cell->index(),dof.get_fe().dofs_per_cell);
00061 out << strOut;
00062 for (unsigned i=0;i<GeometryInfo<DIM>::vertices_per_cell;i++)
00063 {
00064 sprintf(strOut,"\n%d) Pt: <%6g,%6g>, Index: %d, Dofs Index:",i,cell->vertex(i)(0),cell->vertex(i)(1),cell->vertex_index(i));
00065 out << strOut;
00066 for (unsigned j=0;j<dof.get_fe().dofs_per_vertex;j++)
00067 {
00068 out << cell->vertex_dof_index(i,j) << " ";
00069 }
00070 }
00071 }
00072 }
00073 void DealBaseDoFs::printCellDofsInformation(const DoFHandler<3>& dofs)
00074 {
00075 const DoFHandler<DIM> &dof = dofs;
00076 DoFHandler<DIM>::active_cell_iterator cell = dof.begin_active(),
00077 endc = dof.end();
00078 int dofs_per_face = dof.get_fe().n_dofs_per_face();
00079 vector<unsigned> dofs_face(dofs_per_face);
00080
00081 for (;cell!=endc; ++cell)
00082 {
00083 printf("\n==================\nCell %d at <%3g,%3g,%3g>\n",cell->index(),
00084 cell->barycenter()[0],
00085 cell->barycenter()[1],
00086 cell->barycenter()[2]);
00087 if (dofs_per_face > 0)
00088 {
00089 printf("Dof at Faces:\n");
00090
00091 for (unsigned i=0;i<GeometryInfo<DIM>::faces_per_cell;i++)
00092 {
00093
00094 printf("%d) Index: %d Dofs:",i,cell->face(i)->index());
00095 cell->face(i)->get_dof_indices(dofs_face);
00096 for (int j=0;j<dofs_per_face;j++)
00097 {
00098 printf("%d ",dofs_face[j]);
00099 }
00100 printf("\n");
00101 }
00102 }
00103 }
00104 }
00105
00106
00107
00108 void DealBaseDoFs::getVerticeValuesFromDofs(DoFHandler<DIM> &dofs,const VecDouble &vSol,VecDouble &vVerticesValues,unsigned deg)
00109 {
00110
00111
00112 assert(dofs.get_fe().is_primitive());
00113 assert(vSol.size() == dofs.n_dofs());
00114 assert(vVerticesValues.size() == dofs.get_tria().n_vertices());
00115
00116
00117 const unsigned int dofs_per_cell = dofs.get_fe().dofs_per_cell;
00118 std::vector<unsigned int> local_dof_indices (dofs_per_cell);
00119 DoFHandler<3>::active_cell_iterator cell = dofs.begin_active(),
00120 endc = dofs.end();
00121 for (; cell!=endc; ++cell)
00122 {
00123 cell->get_dof_indices (local_dof_indices);
00124 for (unsigned i=0;i<GeometryInfo<2>::vertices_per_cell;i++)
00125 {
00126 vVerticesValues(cell->vertex_index(i))= vSol(cell->vertex_dof_index(i,deg));
00127 }
00128 }
00129 return;
00130 }
00131
00136 void DealBaseDoFs::printFE(FiniteElement<3> &fe)
00137 {
00138 cout << "Finite Element Name: " << fe.get_name() << std::endl;
00139 cout << "Is primitive: " << fe.is_primitive() << std::endl;
00140 cout << "Num Base Elements: " << fe.n_base_elements() << std::endl;
00141 cout << "Num components: " << fe.n_components() << std::endl;
00142
00143 cout << "DOFS per vertex: " << fe.n_dofs_per_vertex() << std::endl;
00144 cout << "DOFS per line: " << fe.n_dofs_per_line() << std::endl;
00145 cout << "DOFS per quad: " << fe.n_dofs_per_quad() << std::endl;
00146 cout << "DOFS per hex: " << fe.n_dofs_per_hex() << std::endl;
00147 cout << "DOFS per face: " << fe.n_dofs_per_face() << std::endl;
00148 cout << "DOFS per cell: " << fe.n_dofs_per_cell() << std::endl;
00149
00150 cout << "Unit Support Points: " << std::endl;
00151
00152 const std::vector<Point<3> > &vPts = fe.get_unit_support_points();
00153 for (unsigned i =0; i < vPts.size(); i++)
00154 printf("%d) %g, %g, %g\n", i, vPts[i](0), vPts[i](1) , vPts[i](2));
00155 if (vPts.size() == 0)
00156 printf("None\n");
00157
00158
00159
00160
00161
00162
00163 Triangulation<3> tria;
00164 Point<3> P1(0,0,0);
00165 Point<3> P2(1,1,1);
00166 std::vector<unsigned> v(3);
00167 v[0]=2;
00168 v[1]=2;
00169 v[2]=2;
00170 GridGenerator::subdivided_hyper_rectangle(tria,v,P1,P2);
00171
00172
00173
00174 DoFHandler<3> dof(tria);
00175 dof.distribute_dofs(fe);
00176 DoFHandler<3>::active_cell_iterator cell = dof.begin_active();
00177
00178
00179
00180
00181 std::vector<Point<3> > vQuad;
00182 vQuad.push_back(Point<3>(0,0,0));
00183 vQuad.push_back(Point<3>(1,0,0));
00184 vQuad.push_back(Point<3>(0,1,0));
00185 vQuad.push_back(Point<3>(1,1,0));
00186 vQuad.push_back(Point<3>(0,0,1));
00187 vQuad.push_back(Point<3>(1,0,1));
00188 vQuad.push_back(Point<3>(0,1,1));
00189 vQuad.push_back(Point<3>(1,1,1));
00190
00191 std::vector<double> vWeights(8,1);
00192 Quadrature<3> quad(vQuad,vWeights);
00193 FEValues<3> feValues(fe,quad,UpdateFlags(update_values | update_JxW_values));
00194 feValues.reinit(cell);
00195
00196
00197 cout << "Shape Values At Vertex: " <<std::endl;
00198 for (unsigned int i=0; i<fe.dofs_per_cell; ++i)
00199 {
00200 cout << "Shape Value: " << i <<"\n";
00201 for (unsigned int q_point=0; q_point < quad.size(); ++q_point)
00202 {
00203 cout << vQuad[q_point] << ":\t";
00204 for (unsigned int component=0; component < fe.n_components(); component++)
00205 {
00206
00207 cout << feValues.shape_value_component(i,q_point,component);
00208
00209
00210 }
00211 cout << std::endl;
00212 }
00213 }
00214
00215
00216
00217
00218 }
00219
00220
00227 void DealBaseDoFs::getCentralValuesFromDofs(DoFHandler<3> &dof,const VecDouble &sol, VecDouble &cValues,unsigned component)
00228 {
00229 assert(sol.size() == dof.n_dofs());
00230 assert(cValues.size() == dof.get_tria().n_active_cells());
00231 assert(component < dof.get_fe().n_components());
00232
00233 QMidpoint<DIM> qMidPoint;
00234 FEValues<DIM> fe_values(dof.get_fe(),qMidPoint,update_values);
00235
00236 const unsigned int dofs_per_cell = dof.get_fe().dofs_per_cell;
00237
00238 std::vector<unsigned int> local_dof_indices (dofs_per_cell);
00239
00240 DoFHandler<3>::active_cell_iterator cell = dof.begin_active(),
00241 endc = dof.end();
00242
00243 double acum;
00244 for (; cell!=endc; ++cell)
00245 {
00246 fe_values.reinit (cell);
00247 acum =0.0;
00248 cell->get_dof_indices(local_dof_indices);
00249 for (unsigned int i=0; i<dofs_per_cell; ++i)
00250 {
00251 acum+= sol(local_dof_indices[i])*fe_values.shape_value_component(i,0,component);
00252 }
00253 cValues(cell->index())=acum;
00254 }
00255
00256 }
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277