Loading [MathJax]/extensions/tex2jax.js

dune-composites (unstable)

computeStresses.hh
1#ifndef COMPUTE_STRESSES_HH
2#define COMPUTE_STRESSES_HH
3
4#include<dune/pdelab/finiteelementmap/qkdg.hh>
5#include "getStress.hh"
6
7template<class MODEL, typename V, typename GV1, typename GFS, typename MBE>
8void calculateStresses(MODEL& model, V& x0, const GV1& gv1, const GFS& gfs, MBE& mbe, int dofel = 60){
10 using Dune::PDELab::Backend::native;
11
12 typedef Dune::PDELab::ISTL::VectorBackend<> Scalar_VectorBackend;
13 typedef double RF;
14 std::string vtk_output = config.get<std::string>("ModelName","TestModel");
15 Dune::Timer timer;
16
17 using GV = Dune::PDELab::AllEntitySet<GV1>;
18 auto gv = GV(gv1);
19
20 // Initially we consider only a DG stress plot
21 //Function spaces for Stresses
22 typedef typename GV::Grid::ctype e_ctype;
23 typedef Dune::PDELab::QkDGLocalFiniteElementMap<e_ctype,double,0,3> FEM_stress;
24 FEM_stress fem_stress;
25
26 typedef Dune::PDELab::GridFunctionSpace<GV, FEM_stress, Dune::PDELab::NoConstraints, Scalar_VectorBackend> SCALAR_P1GFS;
27 SCALAR_P1GFS p1gfs_00(gv,fem_stress); p1gfs_00.name("stress00"); SCALAR_P1GFS p1gfs_11(gv,fem_stress); p1gfs_11.name("stress11");
28 SCALAR_P1GFS p1gfs_22(gv,fem_stress); p1gfs_22.name("stress22"); SCALAR_P1GFS p1gfs_12(gv,fem_stress); p1gfs_12.name("stress12");
29 SCALAR_P1GFS p1gfs_02(gv,fem_stress); p1gfs_02.name("stress02"); SCALAR_P1GFS p1gfs_01(gv,fem_stress); p1gfs_01.name("stress01");
30
31 typedef Dune::PDELab::ISTL::VectorBackend<Dune::PDELab::ISTL::Blocking::fixed> VectorBackend;
32 typedef Dune::PDELab::PowerGridFunctionSpace <SCALAR_P1GFS,6,VectorBackend,Dune::PDELab::EntityBlockedOrderingTag> P1GFS;
33
34 P1GFS p1gfs(p1gfs_00,p1gfs_11,p1gfs_22,p1gfs_12,p1gfs_02,p1gfs_01);
35
36 //Set up local operator to calculate stresses
37 Dune::PDELab::getStress<GV,MODEL,60> lopStress(gv,model);
38
39 typedef Dune::PDELab::EmptyTransformation NoTrafo;
40 typedef Dune::PDELab::GridOperator<GFS,P1GFS,Dune::PDELab::getStress<GV,MODEL,60>,MBE,RF,RF,RF,NoTrafo,NoTrafo> GOStress;
41 GOStress goStress(gfs,p1gfs,lopStress,mbe);
42
43 typedef typename GOStress::Traits::Range V1;
44 V1 stress(p1gfs,0.0);
45 goStress.residual(x0,stress);
46
47 // Record Stresses to MODEL class to be used later if required
48 model.sizeStressVector(native(stress).size()); // Make sure stress contain in model class is the right size
49 for (unsigned int i = 0; i < native(stress).size(); i++){
50 model.setStress(i,native(stress)[i]);
51 }
52
53 // Save solution in vtk format for paraview
54 if(model.stress_Plot){
55 Dune::SubsamplingVTKWriter<GV1> vtkwriter(gv1,Dune::refinementLevels(0));
56 Dune::PDELab::addSolutionToVTKWriter(vtkwriter,p1gfs,stress);
57 vtkwriter.write(model.vtk_stress_output,model.stress_Plot_ascii ? Dune::VTK::ascii : Dune::VTK::appendedraw);
58 }
59}
60
61
62template<class MODEL, typename V, typename GV1, typename GFS, typename MBE>
63void calculateStressesUG(MODEL& model, V& x0, const GV1& gv1, const GFS& gfs, MBE& mbe, int dofel = 12){
65 using Dune::PDELab::Backend::native;
66 using GV = Dune::PDELab::AllEntitySet<GV1>;
67 auto gv = GV(gv1);
68 typedef double RF;
69
70 typedef typename GV::Grid::ctype e_ctype;
71 typedef Dune::PDELab::PkLocalFiniteElementMap<GV,e_ctype,double,1> FEM_stress;
72 // Construct FEM Space
73 FEM_stress fem_stress(gv);
74 typedef Dune::PDELab::ISTL::VectorBackend<> Scalar_VectorBackend;
75
76 typedef Dune::PDELab::GridFunctionSpace<GV, FEM_stress, Dune::PDELab::NoConstraints, Scalar_VectorBackend> SCALAR_P1GFS;
77 SCALAR_P1GFS p1gfs_00(gv,fem_stress); p1gfs_00.name("stress00"); SCALAR_P1GFS p1gfs_11(gv,fem_stress); p1gfs_11.name("stress11");
78 SCALAR_P1GFS p1gfs_22(gv,fem_stress); p1gfs_22.name("stress22"); SCALAR_P1GFS p1gfs_12(gv,fem_stress); p1gfs_12.name("stress12");
79 SCALAR_P1GFS p1gfs_02(gv,fem_stress); p1gfs_02.name("stress02"); SCALAR_P1GFS p1gfs_01(gv,fem_stress); p1gfs_01.name("stress01");
80 typedef Dune::PDELab::ISTL::VectorBackend<Dune::PDELab::ISTL::Blocking::fixed> VectorBackend;
81 typedef Dune::PDELab::PowerGridFunctionSpace <SCALAR_P1GFS,6,VectorBackend,Dune::PDELab::EntityBlockedOrderingTag> P1GFS;
82
83 P1GFS p1gfs(p1gfs_00,p1gfs_11,p1gfs_22,p1gfs_12,p1gfs_02,p1gfs_01);
84
85 Dune::PDELab::countElem lopCnt;
86 SCALAR_P1GFS cntpgfs(gv,fem_stress);
87 typedef Dune::PDELab::EmptyTransformation NoTrafo;
88 typedef Dune::PDELab::GridOperator<GFS,SCALAR_P1GFS,Dune::PDELab::countElem,MBE,RF,RF,RF,NoTrafo,NoTrafo> GOCnt;
89 GOCnt goCnt(gfs,cntpgfs,lopCnt,mbe);
90
91 typedef typename GOCnt::Traits::Range Vcnt;
92 Vcnt ElemCnt(cntpgfs,0.0);
93
94 goCnt.residual(x0,ElemCnt);
95
96 //Turn counter into discrete grid function
97 typedef Dune::PDELab::DiscreteGridFunction<SCALAR_P1GFS,Vcnt> DGF;
98 DGF dgfCnt(cntpgfs, ElemCnt);
99
100 //Set up local operator to calculate stresses
101 double maxDisp = 0.0;
102 Dune::PDELab::getStressUG<GV,MODEL,DGF,12> lopStress(gv,model,dgfCnt,maxDisp);
103 typedef Dune::PDELab::GridOperator<GFS,P1GFS,Dune::PDELab::getStressUG<GV,MODEL,DGF,12>,MBE,RF,RF,RF,NoTrafo,NoTrafo> GOStress;
104 GOStress goStress(gfs,p1gfs,lopStress,mbe);
105
106 typedef typename GOStress::Traits::Range V1;
107 V1 stress(p1gfs,0.0);
108 goStress.residual(x0,stress);
109
110 // Record Stresses to MODEL class to be used later if required
111 model.sizeStressVector(native(stress).size()); // Make sure stress contain in model class is the right size
112 for (unsigned int i = 0; i < native(stress).size(); i++){
113 model.setStress(i,native(stress)[i]);
114 }
115
116 // Save solution in vtk format for paraview
117 if(model.stress_Plot){
118 Dune::SubsamplingVTKWriter<GV1> vtkwriter(gv1,Dune::refinementLevels(0));
119 Dune::PDELab::addSolutionToVTKWriter(vtkwriter,p1gfs,stress);
120 vtkwriter.write(model.vtk_stress_output,model.stress_Plot_ascii ? Dune::VTK::ascii : Dune::VTK::appendedraw);
121 }
122}
123
124#endif
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Apr 15, 23:04, 2025)