dune-composites (2.5.1)

linearStaticDriver.hh
1#include <dune/composites/Setup/parallelPartition.hh>
2#include <dune/composites/Setup/GridTransformation.hh>
3#include <dune/composites/Setup/dirichletBC.hh>
4#include <dune/composites/Driver/FEM/Serendipity/serendipityfem.hh>
5
6#include "../PostProcessing/computeStresses.hh"
7#include "../PostProcessing/plot_properties.hh"
8#include "localOperator/linearelasticity.hh"
9
10namespace Dune{
11 namespace Composites{
12
14 template <typename MODEL>
16
17 public:
18 typedef Dune::PDELab::istl::VectorBackend<Dune::PDELab::istl::Blocking::none,1> Scalar_VectorBackend;
19 typedef Dune::PDELab::istl::VectorBackend<Dune::PDELab::istl::Blocking::fixed,3> VectorBackend;
20 typedef Dune::PDELab::istl::BCRSMatrixBackend<> MBE;
21 typedef double RF;
22
23 int elem_order;
24
25 Dune::MPIHelper& helper;
26
27 linearStaticDriver(Dune::MPIHelper & helper_) : helper(helper_){
28 elem_order = 2; // Default Value which Can be overwritten by setElementOrder
29 };
30
31 void inline setElementOrder(int val = 2){
32 elem_order = val;
33 }
34
35 void inline apply(MODEL& myModel){
36 if (myModel.setUp_Required == true){
37 myModel.LayerCake();
38 myModel.setUpMaterials();
39 myModel.computeElasticTensors();
40 }
41
42 Dune::Timer watch;
43 std::vector<double> times(3);
44
45 // === A: Setup YaspGrid
46 watch.reset();
47 typedef Dune::YaspGrid<3,Dune::TensorProductCoordinates<double,3>> YGRID;
48 YaspPartition<3> yp(helper.size(),myModel.GridPartition());
49 YGRID yaspgrid(myModel.coords,myModel.periodic,myModel.overlap,helper.getCommunicator(),(Dune::YLoadBalance<3>*)&yp);
50 int refinements = myModel.refineBaseGrid;
51 if(refinements > 0) yaspgrid.globalRefine(refinements);
52 typedef YGRID::LeafGridView YGV;
53 const YGV& ygv = yaspgrid.leafGridView();
54
55 if(helper.rank() == 0){
56 std::cout << "Number of elements per processor: " << ygv.size(0) << std::endl;
57 std::cout << "Number of nodes per processor: " << ygv.size(3) << std::endl;
58 }
59
60 myModel.setPG(ygv); // Loops over elements and assigns a physical group
61
62 // ==================================================================
63 // Transform Grid
64 // ==================================================================
66 GRID_TRAFO gTrafo(myModel, helper.rank());
67
68 typedef typename Dune::GeometryGrid<YGRID,GRID_TRAFO> GRID;
69 GRID grid(yaspgrid,gTrafo);
70 if(helper.rank() == 0)
71 std::cout << "Grid transformation complete" << std::endl;
72
73 //Define Grid view
74 typedef typename GRID::LeafGridView GV;
75 const GV& gv = grid.leafGridView();
76
77 if(helper.rank() == 0)
78 std::cout << "Grid view set up" << std::endl;
79
80 times[1] = watch.elapsed();
81 watch.reset();
82
83 typedef Scalar_BC<GV,MODEL,RF> BC;
84 typedef Dune::PDELab::CompositeConstraintsParameters<BC,BC,BC> Constraints;
85
86 // ==================================================================
87 // Set up problem
88 // ==================================================================
89 myModel.template computeTensorsOnGrid<GV,YGV>(gv,ygv);
90
91 // Setup initial boundary conditions for each degree of freedom
92 typedef Scalar_BC<GV,MODEL,double> InitialDisp;
93 InitialDisp u1(gv, myModel,0), u2(gv, myModel,1), u3(gv, myModel,2);
94
95 // Wrap scalar boundary conditions in to vector
96 typedef Dune::PDELab::CompositeGridFunction<InitialDisp,InitialDisp,InitialDisp> InitialSolution;
97 InitialSolution initial_solution(u1,u2,u3);
98
99 // Construct grid function spaces for each degree of freedom
100 typedef Dune::PDELab::OverlappingConformingDirichletConstraints CON;
101 CON con;
102
103 times[2] = watch.elapsed();
104 watch.reset();
105
106 if(elem_order == 2){ // == Element Order
107 const int element_order = 2;
108 const int dofel = 3 * 20;
109 const int non_zeros = 81;
110
111 if(helper.rank() == 0)
112 std::cout << "Piecewise quadratic serendipity elements" << std::endl;
113
115 FEM fem(gv);
116
117 typedef Dune::PDELab::GridFunctionSpace<GV, FEM, CON, Scalar_VectorBackend> SCALAR_GFS;
118 SCALAR_GFS dispU1(gv,fem,con); dispU1.name("U1");
119 SCALAR_GFS dispU2(gv,fem,con); dispU2.name("U2");
120 SCALAR_GFS dispU3(gv,fem,con); dispU3.name("U3");
121
122 // Note that Vectors are blocked by Dune::PDELab::EntityBlockedOrderingTag
123 typedef Dune::PDELab::CompositeGridFunctionSpace <VectorBackend,Dune::PDELab::EntityBlockedOrderingTag, SCALAR_GFS, SCALAR_GFS, SCALAR_GFS> GFS;
124 const GFS gfs(dispU1, dispU2, dispU3);
125
126 typedef typename GFS::template ConstraintsContainer<RF>::Type C;
127
128 // Make constraints map and initialize it from a function
129 C cg;
130 cg.clear();
131
132 BC U1_cc(gv,myModel,0), U2_cc(gv,myModel,1), U3_cc(gv,myModel,2);
133 Constraints constraints(U1_cc,U2_cc,U3_cc);
134
135 Dune::PDELab::constraints(constraints,gfs,cg);
136
137 MBE mbe(non_zeros); // Maximal number of nonzeroes per row
138
139 // === Construct Linear Operator on FEM Space
140 typedef Dune::PDELab::linearelasticity<GV, MODEL, dofel> LOP;
141 LOP lop(gv, myModel);
142
143 typedef Dune::PDELab::GridOperator<GFS,GFS,LOP,MBE,RF,RF,RF,C,C> GO;
144 GO go(gfs,cg,gfs,cg,lop,mbe);
145
146 // === Make coefficent vector and initialize it from a function
147 typedef Dune::PDELab::Backend::Vector<GFS,double> V;
148 V u(gfs,0.0);
149 Dune::PDELab::interpolate(initial_solution,gfs,u);
150
151 // === Set non constrained dofs to zero
152 Dune::PDELab::set_shifted_dofs(cg,0.0,u);
153 myModel.template solve<GO,V,GFS,C,Constraints,MBE,LOP>(go,u,gfs,cg,constraints,mbe,lop);
154
155
156 Dune::SubsamplingVTKWriter<GV> vtkwriter(gv,0);
157 Dune::PDELab::addSolutionToVTKWriter(vtkwriter,gfs,u);
158 vtkwriter.write(myModel.vtk_displacement_output,Dune::VTK::appendedraw);
159
160
161 calculateStresses<MODEL,V,GV,GFS,MBE>(myModel,u,gv,gfs,mbe);
162
163 plotProperties<MODEL,V,GV,GFS,MBE>(myModel,gv,gfs,mbe);
164
165 myModel.template postprocess<GO,V,GFS,C,MBE,GV>(go,u,gfs,cg,gv,mbe);
166 }
167 } // end apply
168
169 };
170 }
171}
Grid Transformation.
Definition: GridTransformation.hh:19
Define Scalar Dirichlet Boundary Conditions.
Definition: dirichletBC.hh:14
Partition yaspgrid for parallelism.
Definition: parallelPartition.hh:12
linear static driver
Definition: linearStaticDriver.hh:15
Definition: serendipityfem.hh:20
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Aug 31, 22:39, 2025)