Commit 12ea4e1c by dkammer

### week 9

parent f9e68568
 build *~ \ No newline at end of file
 # Assignment This week we look a bit more into data structures. We work on the same code we have used over the past couple of weeks. The objective here is to find a more optimal data structure for the matrix. The direct stiffness method, much like the finite-element method, leads to a matrix that contains mostly zeros. Such matrices are referred to as Sparse Matrix. For this assignment, follow these steps: 1. read about Sparse Matrix: [https://en.wikipedia.org/wiki/Sparse_matrix](https://en.wikipedia.org/wiki/Sparse_matrix) and summarize on 1-2 slides (e.g., underlying data structure and advantages/disadvantages) 2. evaluate the changes needed in the code to use a sparse matrix, and summarize on 1-2 slides 3. make the changes and summarize problems/insights/result on slides As a reminder: The code is provided in the folder `code`. It can be compile via `cmake`. Follow these steps: 1. `cd code` 2. `mkdir build` 3. `cd build` 4. `ccmake ..` 5. configure and generate 6. `make`
This diff is collapsed.
 # project-example
 add_simulation(basic_example) configure_file(basic_example_1.inp basic_example_1.inp COPYONLY) configure_file(basic_example_1.run basic_example_1.run COPYONLY)
 #include // print to console (cout) //#include // math operations //#include // file streaming for input file #include "Model.hpp" int main(int argc, char *argv[]) { std::string fname; std::string odir; if(argc<3) { std::cerr << "Not enough arguments:" << " ./basic_example " << std::endl; return 0; } else { fname = argv[1]; odir = argv[2]; } Model my_model; std::cout << "read input" << std::endl; my_model.read_input(fname+".inp"); my_model.assemble(); // Get unconstrained stiffness matrix + load vector my_model.apply_BC(); std::cout << "solve" << std::endl; my_model.solve(); // Solve linear system and get displacement vector my_model.compute_reaction(); // Calculate reaction my_model.print_results(odir,fname); // print results return 0; }
 2 # Nel (Number of elements) 2 # Nen (Number of nodes per element) 3 # Nnp (Number of nodes) 2 # n (Number of dofs / degrees of freedom per node) 1 0; 0 0; 1 1 # nodes (node coordinates (x,y)) 1 3; 2 3 # elements (Nodes connecting each element) 1 1 # E (Young Modulus of all elements) 1 1 # A (Cross-section area of all elements) 0 0; 0 0; 1 1 # pli (Prescribed Load Index) 0 0; 0 0; 10 0 # pl (Prescribed Load) 1 1; 1 1; 0 0 # pdi (Prescribed Displacement Index) 0 0; 0 0; 0 0 # pd (Prescribed Displacement)
 odir=~/dev/output name=basic_example_1 ./basic_example \$name \$odir 2>&1 | tee \$name.progress cp \$name.inp \$odir/\$name.inp cp \$name.run \$odir/\$name.run cp \$name.progress \$odir/\$name.progress
 #ifndef MODELHEADERDEF #define MODELHEADERDEF #include // file streaming for input file #include // armadillo library class Model { public: template void read_line(T*, std::ifstream&); void read_line(int*, std::ifstream&); void read_input(const std::string&); void assemble (); void apply_BC (); void solve (); void compute_reaction (); void print_results(const std::string & path, const std::string & fname); protected: void local_stiffness_element(arma::mat & k_e, int el); private: int Nel,Nen,Nnp,n; // Number of elements, nodes-per-element, nodes, dofs per node arma::mat nodes; // Coordinates of all nodes arma::imat elements; // Node index pair from every element arma::vec E, A; // Young modulus and cross section of every element arma::imat pli, pdi; // constrained dofs matrix (1 -> constrained / 0 -> free) arma::mat pl, pd; // load and displacement boundary conditions for every dof // Struct to store all vectors and matrices of the 2d truss stiffness model. arma::mat K,K_f; // Final stiffness matrix + unconstrained stiffness matrix (floating). arma::vec f,d,r; // Load + displacement + reaction. }; #endif