linearElasticity.cc 4.34 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "AMDiS.h"
#include "LinearElasticityPhase.h"
#include "navierStokes.h"
#include "Refinement.h"
#include "MeshFunction_Level.h"
#include "PhaseFieldConvert.h"
#include "Helpers.h"

#include "boost/date_time/posix_time/posix_time.hpp"

using namespace AMDiS;
using namespace boost::posix_time;

struct BoundaryStress : AbstractFunction<double, WorldVector<double> >
{
  BoundaryStress(int comp_, 
		 WorldVector<double> center_, 
		 AbstractFunction<double, WorldVector<double> >* phaseFct_, 
		 double factor_)
  : comp(comp_),
    center(center_),
    phaseFct(phaseFct_),
    factor(factor_) {}
   
  double operator()(const WorldVector<double>& x) const
  {
    return factor*(x[comp]-center[comp])*(*phaseFct)(x);
  }
  
private:
  int comp;
  WorldVector<double> center;
  AbstractFunction<double, WorldVector<double> >* phaseFct;
  double factor;
};


class ElasticityDemo : public LinearElasticityPhase
{
public:
  typedef LinearElasticityPhase super;
  
public:
  ElasticityDemo(std::string name_) : super(name_) {}
  
  void initData()
  {
    super::initData();
    
    phaseField = new DOFVector<double>(getFeSpace(0), "phase");
    super::setPhase(phaseField);
    
    for (int i = 0; i < dow; i++) {
      boundaryDOFs[i] = new DOFVector<double>(getFeSpace(i), "boundary" + Helpers::toString(i));
    }
  }
  
  void solveInitialProblem(AdaptInfo *adaptInfo) 
  {
    super::solveInitialProblem(adaptInfo);
    
    size_t nVertices = 0;
    WorldVector<double> x;
    Parameters::get("beam->num vertices",nVertices);
    std::vector<WorldVector<double> > v(nVertices,x);
    for (size_t i = 0; i < nVertices; i++)
      Parameters::get("beam->vertex["+boost::lexical_cast<std::string>(i)+"]",v[i]);
    v.push_back(v[0]);
    
    SignedDistRefinement refFunction(getMesh());
    RefinementLevelCoords2 refinement(
      getFeSpace(),
      &refFunction,
      new Polygon(v));

    // initial refinement
    refinement.refine(10);
    
    phaseField->interpol(new SignedDistFctToPhaseField(getEpsilon(), new Polygon(v), 3.0));
    VtkWriter::writeFile(phaseField, "phaseField.vtu");
    transformDOF(phaseField, 1.e-5, phaseField, new AMDiS::Max<double>);
    
    
    nVertices = 0;
    Parameters::get("boundary->num vertices",nVertices);
    std::vector<WorldVector<double> > v2(nVertices,x);
    for (size_t i = 0; i < nVertices; i++)
      Parameters::get("boundary->vertex["+boost::lexical_cast<std::string>(i)+"]",v2[i]);
    v2.push_back(v2[0]);
    
    DOFVector<double> boundaryPhase(getFeSpace(0), "boundaryPhase");
    boundaryPhase.interpol(new SignedDistFctToPhaseField(getEpsilon(), new Polygon(v2), 3.0));
    VtkWriter::writeFile(&boundaryPhase, "boundaryPhase.vtu");
    
    WorldVector<double> center; center.set(0.5);
    Parameters::get("beam->center", center);
    double factor = 1.0;
    Parameters::get("boundary->factor", factor);
    boundaryDOFs[0]->interpol(new BoundaryStress(1, center, new SignedDistFctToPhaseField(getEpsilon(), new Polygon(v2), 3.0), factor));
    boundaryDOFs[1]->interpol(new BoundaryStress(0, center, new SignedDistFctToPhaseField(getEpsilon(), new Polygon(v2), -3.0), factor));
    VtkWriter::writeFile(boundaryDOFs[0], "boundaryDOF0.vtu");
  }

protected:
  void fillBoundaryConditions()
  { FUNCNAME("NS_DrivenCavity::fillBoundaryConditions()");
  
    for (int i = 0; i < dow; i++)
      super::setBcDOF(boundaryDOFs[i],i);
    
    super::fillBoundaryConditions();
  
    WorldVector<double> center; center.set(0.5);
    Parameters::get("beam->center", center);
    AbstractFunction<double, WorldVector<double> > *zero = new AMDiS::Const<double, WorldVector<double> >(0.0);
    prob->addSingularDirichletBC(center, 1, 1, *zero);
    
  }
  
  DOFVector<double>* phaseField;
  WorldVector<DOFVector<double>*> boundaryDOFs;
};

int main(int argc, char** argv)
{ FUNCNAME("main");

  AMDiS::init(argc, argv);

  ElasticityDemo elastProb("elasticity");
  elastProb.initialize(INIT_ALL);

  // Adapt-Infos
  AdaptInfo adaptInfo("adapt", elastProb.getNumComponents());

  // adaption loop
  AdaptInstationary adaptInstat("adapt", elastProb, adaptInfo, elastProb, adaptInfo);

  ptime start_time = microsec_clock::local_time();
  elastProb.initTimeInterface();
  int error_code = adaptInstat.adapt(); 
  time_duration td = microsec_clock::local_time()-start_time;

  MSG("elapsed time= %d sec\n", td.total_seconds());

  AMDiS::finalize();

  return error_code;
};