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>
6#include "../PostProcessing/computeStresses.hh"
7#include "../PostProcessing/plot_properties.hh"
8#include "localOperator/linearelasticity.hh"
18 template <
typename MODEL>
22 typedef Dune::PDELab::istl::VectorBackend<Dune::PDELab::istl::Blocking::none,1> Scalar_VectorBackend;
23 typedef Dune::PDELab::istl::VectorBackend<Dune::PDELab::istl::Blocking::fixed,3> VectorBackend;
24 typedef Dune::PDELab::istl::BCRSMatrixBackend<> MBE;
29 Dune::MPIHelper& helper;
35 void inline setElementOrder(
int val = 2){
39 void inline apply(MODEL& myModel){
40 if (myModel.setUp_Required ==
true){
42 myModel.setUpMaterials();
43 myModel.computeElasticTensors();
47 std::vector<double> times(3);
51 typedef Dune::YaspGrid<3,Dune::TensorProductCoordinates<double,3>> YGRID;
53 YGRID yaspgrid(myModel.coords,myModel.periodic,myModel.overlap,helper.getCommunicator(),(Dune::YLoadBalance<3>*)&yp);
54 int refinements = myModel.refineBaseGrid;
55 if(refinements > 0) yaspgrid.globalRefine(refinements);
56 typedef YGRID::LeafGridView YGV;
57 const YGV& ygv = yaspgrid.leafGridView();
58 int size = yaspgrid.globalSize(0)*yaspgrid.globalSize(1)*yaspgrid.globalSize(2);
60 if(helper.rank() == 0){
61 std::cout <<
"Number of elements per processor: " << ygv.size(0) << std::endl;
62 std::cout <<
"Number of nodes per processor: " << ygv.size(3) << std::endl;
71 GRID_TRAFO gTrafo(myModel,helper.rank());
73 typedef typename Dune::GeometryGrid<YGRID,GRID_TRAFO> GRID;
74 GRID grid(yaspgrid,gTrafo);
75 if(helper.rank() == 0)
76 std::cout <<
"Grid transformation complete" << std::endl;
79 typedef typename GRID::LeafGridView GV;
80 const GV& gv = grid.leafGridView();
82 if(helper.rank() == 0)
83 std::cout <<
"Grid view set up" << std::endl;
85 times[1] = watch.elapsed();
89 typedef Dune::PDELab::CompositeConstraintsParameters<BC,BC,BC> Constraints;
94 myModel.template computeTensorsOnGrid<GV,YGV>(gv,ygv);
98 InitialDisp u1(gv, myModel,0), u2(gv, myModel,1), u3(gv, myModel,2);
101 typedef Dune::PDELab::CompositeGridFunction<InitialDisp,InitialDisp,InitialDisp> InitialSolution;
102 InitialSolution initial_solution(u1,u2,u3);
105 typedef Dune::PDELab::OverlappingConformingDirichletConstraints CON;
108 times[2] = watch.elapsed();
112 const int element_order = 2;
113 const int dofel = 3 * 20;
114 const int non_zeros = 81;
116 if(helper.rank() == 0)
117 std::cout <<
"Piecewise quadratic serendipity elements" << std::endl;
122 typedef Dune::PDELab::GridFunctionSpace<GV, FEM, CON, Scalar_VectorBackend> SCALAR_GFS;
123 SCALAR_GFS dispU1(gv,fem,con); dispU1.name(
"U1");
124 SCALAR_GFS dispU2(gv,fem,con); dispU2.name(
"U2");
125 SCALAR_GFS dispU3(gv,fem,con); dispU3.name(
"U3");
128 typedef Dune::PDELab::CompositeGridFunctionSpace <VectorBackend,Dune::PDELab::EntityBlockedOrderingTag, SCALAR_GFS, SCALAR_GFS, SCALAR_GFS> GFS;
129 const GFS gfs(dispU1, dispU2, dispU3);
131 typedef typename GFS::template ConstraintsContainer<RF>::Type C;
137 BC U1_cc(gv,myModel,0), U2_cc(gv,myModel,1), U3_cc(gv,myModel,2);
138 Constraints constraints(U1_cc,U2_cc,U3_cc);
139 Dune::PDELab::constraints(constraints,gfs,cg);
232 double total_fail = 0;
234 while(std::abs(total_fail-1.0) > 1e-2){
235 if(gv.comm().rank() == 0) std::cout <<
"Lambda " << lambda << std::endl;
236 myModel.setThermal(
true);
237 myModel.setPressure(lambda);
239 typedef Dune::PDELab::linearelasticity<GV, MODEL, dofel> LOP;
240 LOP lop(gv, myModel);
242 typedef Dune::PDELab::GridOperator<GFS,GFS,LOP,MBE,RF,RF,RF,C,C> GO;
243 GO go(gfs,cg,gfs,cg,lop,mbe);
246 typedef Dune::PDELab::Backend::Vector<GFS,double> V;
248 Dune::PDELab::interpolate(initial_solution,gfs,u);
251 Dune::PDELab::set_shifted_dofs(cg,0.0,u);
254 myModel.template solve<GO,V,GFS,C,Constraints,MBE,LOP>(go,u,gfs,cg,constraints,mbe,lop);
258 if(gv.comm().rank() == 0) std::cout <<
"=== Calculate Stresses" << std::endl;
259 calculateStresses<MODEL,V,GV,GFS,MBE>(myModel,u,gv,gfs,mbe);
262 using Dune::PDELab::Backend::native;
264 typedef typename GV::Traits::template Codim<0>::Iterator ElementIterator;
265 for (ElementIterator it = gv.template begin<0>(); it!=gv.template end<0>(); ++it)
267 int id = gv.indexSet().index(*it);
268 auto stress = myModel.getStress(
id);
269 double h = myModel.FailureCriteria(stress);
272 MPI_Allreduce(&max, &total_fail, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
273 if(gv.comm().rank() == 0) std::cout <<
"Total failure " << total_fail << std::endl;
275 lambda = lambda/total_fail;
277 if(std::abs(total_fail-1.0)<1e-2){
278 if(gv.comm().rank() == 0) std::cout <<
"Number of solves " << cnt << std::endl;
280 Dune::SubsamplingVTKWriter<GV> vtkwriter(gv,0);
281 Dune::PDELab::addSolutionToVTKWriter(vtkwriter,gfs,u);
282 vtkwriter.write(myModel.vtk_displacement_output,Dune::VTK::appendedraw);
284 plotProperties<MODEL,V,GV,GFS,MBE>(myModel,gv,gfs,mbe);
286 myModel.template postprocess<GO,V,GFS,C,MBE,GV>(go,u,gfs,cg,gv,mbe);
Define Scalar Dirichlet Boundary Conditions.
Definition: dirichletBC.hh:14
Partition yaspgrid for parallelism.
Definition: parallelPartition.hh:12
Static driver including a thermal loading.
Definition: heatStaticDriver.hh:19
Definition: serendipityfem.hh:20