ProblemNonLin.cc 6.35 KB
Newer Older
1
2
3
4
5
6
7
#include "ProblemNonLin.h"
#include "NonLinSolver.h"
#include "CreatorMap.h"
#include "NonLinUpdater.h"
#include "Traverse.h"
#include "AdaptInfo.h"

8
#if 0
9
10
11
12
namespace AMDiS {

  void ProblemNonLinScal::initialize(Flag initFlag,
				     ProblemScal *adoptProblem /*= NULL*/,
Thomas Witkowski's avatar
Thomas Witkowski committed
13
14
				     Flag adoptFlag /*= INIT_NOTHING*/) 
  {
15
16
17
18

    ProblemScal::initialize(initFlag, adoptProblem, adoptFlag);

    // === create Updater ===
Thomas Witkowski's avatar
Thomas Witkowski committed
19
    if (updater_) { 
20
21
      WARNING("updater already created\n");
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
22
23
24
25
26
27
28
29
30
31
32
33
34
      if (initFlag.isSet(INIT_UPDATER) || 
	  ((!adoptFlag.isSet(INIT_UPDATER))&&
	   (initFlag.isSet(INIT_NONLIN_SOLVER)))) {
	createUpdater();
      } 
      
      if (adoptProblem && 
	  (adoptFlag.isSet(INIT_UPDATER) ||  
	   ((!initFlag.isSet(INIT_UPDATER))&&
	    (adoptFlag.isSet(INIT_NONLIN_SOLVER))))) {
	TEST_EXIT(updater_ == NULL)("updater already created\n");
	updater_ = dynamic_cast<ProblemNonLinScal*>(adoptProblem)->getUpdater();
      }
35
36
37
38
39
    }

    if(updater_==NULL) WARNING("no updater created\n");

    // === create nonlinear solver ===
Thomas Witkowski's avatar
Thomas Witkowski committed
40
    if (nonLinSolver_) { 
41
42
      WARNING("nonlinear solver already created\n");
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
43
44
45
46
47
48
49
50
      if (initFlag.isSet(INIT_NONLIN_SOLVER)) {
	createNonLinSolver();
      } 

      if (adoptProblem && adoptFlag.isSet(INIT_NONLIN_SOLVER)) {
	TEST_EXIT(nonLinSolver_==NULL)("nonlinear solver already created\n");
	nonLinSolver_ = dynamic_cast<ProblemNonLinScal*>(adoptProblem)->getNonLinSolver();
      }
51
52
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
53
54
    if (nonLinSolver_ == NULL) 
      WARNING("no nonlinear solver created\n");
55
56
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
57
58
  void ProblemNonLinScal::createNonLinSolver() 
  {
59
    // create non-linear solver
60
#if 0
Thomas Witkowski's avatar
Thomas Witkowski committed
61
    std::string nonLinSolverType("no");
62

Thomas Witkowski's avatar
Thomas Witkowski committed
63
    GET_PARAMETER(0, name + "->nonlin solver", &nonLinSolverType);
64
65

    NonLinSolverCreator<DOFVector<double> > *nonLinSolverCreator = 
Thomas Witkowski's avatar
Thomas Witkowski committed
66
67
      dynamic_cast<NonLinSolverCreator<DOFVector<double> >*>(CreatorMap<NonLinSolver<DOFVector<double> > >::getCreator(nonLinSolverType));

68
    nonLinSolverCreator->setLinearSolver(solver);
Thomas Witkowski's avatar
Thomas Witkowski committed
69
    nonLinSolverCreator->setName(name + "->nonlin solver");
70
71
    nonLinSolverCreator->setNonLinUpdater(updater_);
    nonLinSolver_ = nonLinSolverCreator->create();
Thomas Witkowski's avatar
Thomas Witkowski committed
72
    nonLinSolver_->setVectorCreator(new  DOFVector<double>::Creator(feSpace));
73
#endif
74
75
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
76
77
  void ProblemNonLinScal::solve(AdaptInfo *adaptInfo) 
  {
78
#if 0
79
    TEST_EXIT(nonLinSolver_)("no non-linear solver!\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
80
    int iter = nonLinSolver_->solve(matVec, solution, rhs, leftPrecon, rightPrecon);
81
    adaptInfo->setSolverIterations(solver->getIterations());
82
#endif
83
84
85
  }


Thomas Witkowski's avatar
Thomas Witkowski committed
86
87
88
89
  void ProblemNonLinScal::buildAfterCoarsen(AdaptInfo *adaptInfo, Flag) 
  {
    feSpace->getMesh()->dofCompress();
    MSG("%d DOFs for %s\n", feSpace->getAdmin()->getUsedSize(), feSpace->getName().c_str());
90
91
  
    TraverseStack stack;
92
    ElInfo *elInfo = stack.traverseFirst(mesh, -1, 
93
94
95
96
97
98
					 Mesh::CALL_LEAF_EL | 
					 Mesh::FILL_BOUND |
					 Mesh::FILL_COORDS |
					 Mesh::FILL_DET |
					 Mesh::FILL_GRD_LAMBDA);
    // for all elements ...
99
100
101
    while (elInfo) {
      if (solution->getBoundaryManager())
	solution->getBoundaryManager()->fillBoundaryConditions(elInfo, solution);
102
103
104
105
106
107
108
    
      elInfo = stack.traverseNext(elInfo);
    }
  }

  void ProblemNonLinVec::initialize(Flag initFlag,
				    ProblemVec *adoptProblem /*= NULL*/,
Thomas Witkowski's avatar
Thomas Witkowski committed
109
110
				    Flag adoptFlag /*= INIT_NOTHING*/) 
  {
111
112
113
    ProblemVec::initialize(initFlag, adoptProblem, adoptFlag);

    // === create Updater ===
Thomas Witkowski's avatar
Thomas Witkowski committed
114
    if (updater_) { 
115
116
      WARNING("updater already created\n");
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
117
118
119
120
121
122
123
124
125
126
127
      if (initFlag.isSet(INIT_UPDATER) || 
	  ((!adoptFlag.isSet(INIT_UPDATER)) && initFlag.isSet(INIT_NONLIN_SOLVER))) {
	createUpdater();
      } 

      if (adoptProblem && 
	  (adoptFlag.isSet(INIT_UPDATER) ||  
	   ((!initFlag.isSet(INIT_UPDATER))&& adoptFlag.isSet(INIT_NONLIN_SOLVER)))) {
	TEST_EXIT(updater_==NULL)("updater already created\n");
	updater_ = dynamic_cast<ProblemNonLinVec*>(adoptProblem)->getUpdater();
      }
128
129
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
130
131
    if (updater_ == NULL) 
      WARNING("no updater created\n");
132
133

    // === create nonlinear solver ===
Thomas Witkowski's avatar
Thomas Witkowski committed
134
    if (nonLinSolver_) { 
135
136
      WARNING("nonlinear solver already created\n");
    } else {
Thomas Witkowski's avatar
Thomas Witkowski committed
137
138
139
      if (initFlag.isSet(INIT_NONLIN_SOLVER)) {
	createNonLinSolver();
      } 
140

Thomas Witkowski's avatar
Thomas Witkowski committed
141
142
143
144
145
      if (adoptProblem && adoptFlag.isSet(INIT_NONLIN_SOLVER)) {
	TEST_EXIT(nonLinSolver_ == NULL)("nonlinear solver already created\n");
	nonLinSolver_ = dynamic_cast<ProblemNonLinVec*>(adoptProblem)->getNonLinSolver();
      }
    }
146

Thomas Witkowski's avatar
Thomas Witkowski committed
147
148
    if (nonLinSolver_ == NULL)
      WARNING("no nonlinear solver created\n");
149
150
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
151
152
  void ProblemNonLinVec::createNonLinSolver() 
  {
153
#if 0
154
    // create non-linear solver
155
    std::string nonLinSolverType("no");
156

Thomas Witkowski's avatar
Thomas Witkowski committed
157
    GET_PARAMETER(0, name + "->nonlin solver", &nonLinSolverType);
158
159

    NonLinSolverCreator<SystemVector> *nonLinSolverCreator = 
Thomas Witkowski's avatar
Thomas Witkowski committed
160
161
162
163
      dynamic_cast<NonLinSolverCreator<SystemVector>*>(CreatorMap<NonLinSolver<SystemVector> >::getCreator(nonLinSolverType));

    nonLinSolverCreator->setLinearSolver(solver);
    nonLinSolverCreator->setName(name + "->nonlin solver");
164
165
    nonLinSolverCreator->setNonLinUpdater(updater_);
    nonLinSolver_ = nonLinSolverCreator->create();
Thomas Witkowski's avatar
Thomas Witkowski committed
166
    nonLinSolver_->setVectorCreator(new SystemVector::Creator("temp",
167
							      componentSpaces, 
168
							      nComponents));
169
#endif
170
171
172
  }


Thomas Witkowski's avatar
Thomas Witkowski committed
173
174
  void ProblemNonLinVec::solve(AdaptInfo *adaptInfo) 
  {
175
    TEST_EXIT(nonLinSolver_)("no non-linear solver!\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
176
    nonLinSolver_->solve(matVec, solution, rhs, leftPrecon, rightPrecon);
177
178
179
180
181
  }

  void ProblemNonLinVec::buildAfterCoarsen(AdaptInfo *adaptInfo, Flag) 
  {
    FUNCNAME("ProblemNonLinVec::buildAfterCoarsen()");
Thomas Witkowski's avatar
Thomas Witkowski committed
182
    int nMeshes = static_cast<int>(meshes.size());
183

184
    for (int i = 0; i < nMeshes; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
185
      meshes[i]->dofCompress();
186
187
    }

188
    for (int i = 0; i < nComponents; i++) {
189
      MSG("%d DOFs for %s\n", 
190
191
	  componentSpaces[i]->getAdmin()->getUsedSize(), 
	  componentSpaces[i]->getName().c_str());
192
193
194
195
196
197
    }
    
    TraverseStack stack;
    ElInfo *elInfo;
    
    // for all elements ...
198
    for (int i = 0; i < nComponents; i++) {
Thomas Witkowski's avatar
Thomas Witkowski committed
199
      elInfo = stack.traverseFirst(componentMeshes[i], -1, 
200
201
202
203
204
				   Mesh::CALL_LEAF_EL | 
				   Mesh::FILL_BOUND |
				   Mesh::FILL_COORDS |
				   Mesh::FILL_DET |
				   Mesh::FILL_GRD_LAMBDA);
205
      while (elInfo) {
Thomas Witkowski's avatar
Thomas Witkowski committed
206
207
208
	if (solution->getDOFVector(i)->getBoundaryManager()) {
	  solution->getDOFVector(i)->
	    getBoundaryManager()->fillBoundaryConditions(elInfo, solution->getDOFVector(i));
209
210
211
212
213
214
215
	}
	elInfo = stack.traverseNext(elInfo);
      }
    }
  }

}
216
#endif