Programming tasks to Scientific Computing I
ex1.cpp
Go to the documentation of this file.
1 
5 #include <iostream>
6 
7 #include <Eigen/Dense>
8 #include <Eigen/Sparse>
9 #include <Eigen/SparseCholesky>
10 
11 #include <configuratorsShellFE.h>
12 #include <EigenDataContainer.h>
13 #include <quadratureShellFE.h>
14 #include <legacyVtkWriter.h>
15 #include <shellHandler.h>
16 #include <triangMesh.h>
17 #include <triangleShellFE.h>
18 #include "rhs.h"
20 
21 // typedefs for better code readability
22 typedef double RealType;
29 
30 void printHelp()
31 {
32  cout << "Usage: ex1 meshFile resultFile\n";
33  cout << "\tmeshFile\tLegacy VTK file defining the Finite Element mesh "
34  << "to use\n";
35  cout << "\tresultFile\tLegacy VTK file to write the result to\n\n";
36 }
37 
39 int main(int argc, char **argv)
40 {
41  if (argc != 3) {
42  printHelp();
43  return 1;
44  }
45 
46  // Load a mesh
47  MeshType mesh(argv[1]);
48  // set neighbor relations
49  mesh.makeNeighbour();
50 
51  // The configurator handles information about basis functions,
52  // quadrature points etc.
53  ConfiguratorType conf(mesh);
54 
55  // The shellHandler handles additional information about the mesh
56  // including neighbor relations and the mapping from the unit triangle
57  // to the elements of the mesh
58  shellFE::ShellHandler<ConfiguratorType> shellHandler(conf);
59 
60  // Construct the right hand side
61  VectorType rhs(conf.getNumGlobalDofs());
62  createMaskedConstantRHS<ConfiguratorType>(conf, shellHandler, 1.0, rhs, true);
63 
64  // Construct the system matrix
65  SparseMatrixType systemMat(conf.getNumGlobalDofs(), conf.getNumGlobalDofs());
67  // Assemble the system matrix
68  integrand.assembleDirichlet<SparseMatrixType> (systemMat, shellHandler.getDirichletMask());
69 
70  // Construct a linear solver (Cholesky solver)
71  Eigen::SimplicialLLT<SparseMatrixType> solver;
72  // Decompose the matrix
73  solver.compute(systemMat);
74  // Solve the linear system
75  VectorType sol = solver.solve(rhs);
76 
77  // Save the mesh and solution as legacy VTK
78  LegacyVtkWriter<MeshType> vtkWriter ( mesh );
79  vtkWriter.addScalarData(sol, "solution", VERTEX_DATA);
80  vtkWriter.addScalarData(rhs, "rhs", VERTEX_DATA);
81  vtkWriter.save(argv[2]);
82 
83  return 0;
84 }
void makeNeighbour() const
Definition: triangMesh.h:180
DataTypeContainer::VectorType VectorType
shellFE::ShellElementWithTangentSpaceAtVertex< DataTypeContainerShellFE > TriangleType
Definition: ex1.cpp:23
Different quadrature types for triangular meshes.
shellFE::CenterOfMassQuadrature< RealType, typename DataTypeContainerShellFE::DomVecType > QuadType
Definition: ex1.cpp:25
DataTypeContainer::SparseMatrixType SparseMatrixType
shellFE::UnitTriangMeshConfiguratorP1< DataTypeContainerShellFE, MeshType, QuadType > ConfiguratorType
Definition: ex1.cpp:26
Additional information about TriangleMeshes.
Definition: shellHandler.h:20
Implements right hand side assembly for exercise 1.
void printHelp()
Definition: ex1.cpp:30
ConfiguratorType::SparseMatrixType SparseMatrixType
Definition: ex1.cpp:28
int getNumGlobalDofs() const
Returns the number of global degrees of freedom.
void save(string filename) const
LegacyVtkWriter & addScalarData(const VectorType &data, string dataDescr, DataSupp supp)
ConfiguratorType::VectorType VectorType
Definition: ex1.cpp:27
double RealType
Definition: ex1.cpp:22
shellFE::TriangMesh< DataTypeContainerShellFE, TriangleType > MeshType
Definition: ex1.cpp:24
Eigen typedefs for use with the TriangleMesh.
Configurator for Finite Elements.
Triangle which has a tangent space at each node.
int main(int argc, char **argv)
Main function containing the basic structure of the code.
Definition: ex1.cpp:39