Skip to content

Commit db301b4

Browse files
committed
Improvements.
1 parent 8c05ba3 commit db301b4

File tree

12 files changed

+196
-101
lines changed

12 files changed

+196
-101
lines changed

hermes2d/include/discrete_problem/discrete_problem.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@ namespace Hermes
5252
/// 2 - allows for assembling Dirichlet boundary conditions using a Dirichlet lift.
5353
/// \param[in] dirichlet_lift_accordingly If true, the appropriate settings for (linear / nonlinear)
5454
/// problem will be used (use Dirichlet lift iff the problem is linear). If false, the other way round.
55-
DiscreteProblem(WeakFormSharedPtr<Scalar> wf, std::vector<SpaceSharedPtr<Scalar> > spaces, bool linear = false, bool dirichlet_lift_accordingly = true);
55+
DiscreteProblem(WeakFormSharedPtr<Scalar> wf, std::vector<SpaceSharedPtr<Scalar> > spaces, bool linear = false, bool dirichlet_lift_accordingly = true, bool use_direct_for_Dirichlet_lift = false);
5656
/// Constructor for one equation.
5757
/// Making this DiscreteProblem linear does 2 things
5858
/// 1 - turns off initialization of previous iterations for nonlinear solvers.
5959
/// 2 - allows for assembling Dirichlet boundary conditions using a Dirichlet lift.
6060
/// \param[in] dirichlet_lift_accordingly If true, the appropriate settings for (linear / nonlinear)
6161
/// problem will be used (use Dirichlet lift iff the problem is linear). If false, the other way round.
62-
DiscreteProblem(WeakFormSharedPtr<Scalar> wf, SpaceSharedPtr<Scalar> space, bool linear = false, bool dirichlet_lift_accordingly = true);
62+
DiscreteProblem(WeakFormSharedPtr<Scalar> wf, SpaceSharedPtr<Scalar> space, bool linear = false, bool dirichlet_lift_accordingly = true, bool use_direct_for_Dirichlet_lift = false);
6363
/// Non-parameterized constructor.
6464
/// Making this DiscreteProblem linear does 2 things
6565
/// 1 - turns off initialization of previous iterations for nonlinear solvers.
6666
/// 2 - allows for assembling Dirichlet boundary conditions using a Dirichlet lift.
6767
/// \param[in] dirichlet_lift_accordingly If true, the appropriate settings for (linear / nonlinear)
6868
/// problem will be used (use Dirichlet lift iff the problem is linear). If false, the other way round.
69-
DiscreteProblem(bool linear = false, bool dirichlet_lift_accordingly = true);
69+
DiscreteProblem(bool linear = false, bool dirichlet_lift_accordingly = true, bool use_direct_for_Dirichlet_lift = false);
7070
/// Destuctor.
7171
virtual ~DiscreteProblem();
7272

@@ -128,7 +128,7 @@ namespace Hermes
128128
inline std::string getClassName() const { return "DiscreteProblem"; }
129129

130130
/// Init function. Common code for the constructors.
131-
void init(bool linear, bool dirichlet_lift_accordingly);
131+
void init(bool linear, bool dirichlet_lift_accordingly, bool use_direct_for_Dirichlet_lift);
132132

133133
/// Space instances for all equations in the system.
134134
std::vector<SpaceSharedPtr<Scalar> > spaces;
@@ -138,7 +138,7 @@ namespace Hermes
138138
Vector<Scalar>* dirichlet_lift_rhs;
139139

140140
/// Internal.
141-
bool nonlinear, add_dirichlet_lift;
141+
bool nonlinear, add_dirichlet_lift, use_direct_for_Dirichlet_lift;
142142

143143
/// DiscreteProblemMatrixVector methods.
144144
bool set_matrix(SparseMatrix<Scalar>* mat);

hermes2d/src/discrete_problem/discrete_problem.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,29 @@ namespace Hermes
2929
namespace Hermes2D
3030
{
3131
template<typename Scalar>
32-
DiscreteProblem<Scalar>::DiscreteProblem(WeakFormSharedPtr<Scalar> wf_, std::vector<SpaceSharedPtr<Scalar> > spaces, bool to_set, bool dirichlet_lift_accordingly)
32+
DiscreteProblem<Scalar>::DiscreteProblem(WeakFormSharedPtr<Scalar> wf_, std::vector<SpaceSharedPtr<Scalar> > spaces, bool to_set, bool dirichlet_lift_accordingly, bool use_direct_for_Dirichlet_lift)
3333
{
34-
this->init(to_set, dirichlet_lift_accordingly);
34+
this->init(to_set, dirichlet_lift_accordingly, use_direct_for_Dirichlet_lift);
3535
this->set_spaces(spaces);
3636
this->set_weak_formulation(wf_);
3737
}
3838

3939
template<typename Scalar>
40-
DiscreteProblem<Scalar>::DiscreteProblem(WeakFormSharedPtr<Scalar> wf_, SpaceSharedPtr<Scalar> space, bool to_set, bool dirichlet_lift_accordingly)
40+
DiscreteProblem<Scalar>::DiscreteProblem(WeakFormSharedPtr<Scalar> wf_, SpaceSharedPtr<Scalar> space, bool to_set, bool dirichlet_lift_accordingly, bool use_direct_for_Dirichlet_lift)
4141
{
42-
this->init(to_set, dirichlet_lift_accordingly);
42+
this->init(to_set, dirichlet_lift_accordingly, use_direct_for_Dirichlet_lift);
4343
this->set_space(space);
4444
this->set_weak_formulation(wf_);
4545
}
4646

4747
template<typename Scalar>
48-
DiscreteProblem<Scalar>::DiscreteProblem(bool to_set, bool dirichlet_lift_accordingly)
48+
DiscreteProblem<Scalar>::DiscreteProblem(bool to_set, bool dirichlet_lift_accordingly, bool use_direct_for_Dirichlet_lift)
4949
{
50-
init(to_set, dirichlet_lift_accordingly);
50+
init(to_set, dirichlet_lift_accordingly, use_direct_for_Dirichlet_lift);
5151
}
5252

5353
template<typename Scalar>
54-
void DiscreteProblem<Scalar>::init(bool to_set, bool dirichlet_lift_accordingly)
54+
void DiscreteProblem<Scalar>::init(bool to_set, bool dirichlet_lift_accordingly, bool use_direct_for_Dirichlet_lift)
5555
{
5656
this->reassembled_states_reuse_linear_system = nullptr;
5757

@@ -64,7 +64,7 @@ namespace Hermes
6464
this->add_dirichlet_lift = this->nonlinear;
6565

6666
if (this->add_dirichlet_lift)
67-
this->dirichlet_lift_rhs = create_vector<Scalar>(false);
67+
this->dirichlet_lift_rhs = create_vector<Scalar>(use_direct_for_Dirichlet_lift);
6868
else
6969
this->dirichlet_lift_rhs = nullptr;
7070

hermes2d/src/projections/ogprojection.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace Hermes
3131
throw Exceptions::NullException(2);
3232

3333
// Initialize linear solver.
34-
Hermes::Hermes2D::LinearSolver<Scalar> linear_solver(wf, space);
34+
Hermes::Hermes2D::LinearSolver<Scalar> linear_solver(wf, space, true);
3535
linear_solver.set_verbose_output(false);
3636

3737
// Perform Newton iteration.

hermes2d/src/solver/linear_solver.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ namespace Hermes
4343
template<typename Scalar>
4444
LinearSolver<Scalar>::LinearSolver(WeakFormSharedPtr<Scalar> wf, SpaceSharedPtr<Scalar> space, bool force_use_direct_solver) : Solver<Scalar>(false), Hermes::Solvers::MatrixSolver<Scalar>(force_use_direct_solver)
4545
{
46-
this->dp = new DiscreteProblem<Scalar>(wf, space, true);
46+
this->dp = new DiscreteProblem<Scalar>(wf, space, true, true, true);
4747
this->own_dp = true;
4848
}
4949

hermes2d/test_examples/03-navier-stokes/definitions.cpp

+27-7
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,16 @@ class WeakFormNSSimpleLinearization : public WeakForm<double>
7171

7272
double value(int n, double *wt, Func<double> *u_ext[], Func<double> *u, Func<double> *v, GeomVol<double> *e, Func<double> **ext) const{
7373
double result = int_grad_u_grad_v<double, double>(n, wt, u, v) / Reynolds;
74+
if(!Stokes)
75+
result += int_u_v<double, double>(n, wt, u, v) / time_step;
7476
return result;
7577
}
7678

7779
Ord ord(int n, double *wt, Func<Ord> *u_ext[], Func<Ord> *u, Func<Ord> *v, GeomVol<Ord> *e, Func<Ord> **ext) const
7880
{
7981
Ord result = int_grad_u_grad_v<Ord, Ord>(n, wt, u, v) / Reynolds;
82+
if(!Stokes)
83+
result += int_u_v<Ord, Ord>(n, wt, u, v) / time_step;
8084
return result;
8185
}
8286

@@ -179,13 +183,21 @@ class WeakFormNSSimpleLinearization : public WeakForm<double>
179183
VectorFormVolVel(int i, bool Stokes, double time_step) : VectorFormVol<double>(i), Stokes(Stokes), time_step(time_step) {
180184
}
181185

182-
double value(int n, double *wt, Func<double> *u_ext[], Func<double> *v, GeomVol<double> *e, Func<double> **ext) const{
186+
double value(int n, double *wt, Func<double> *u_ext[], Func<double> *v, Geom<double> *e, Func<double> **ext) const{
183187
double result = 0;
188+
if(!Stokes) {
189+
Func<double>* vel_prev_time = ext[2]; // this form is used with both velocity components
190+
result = int_u_v<double, double>(n, wt, vel_prev_time, v) / time_step;
191+
}
184192
return result;
185193
}
186194

187-
Ord ord(int n, double *wt, Func<Ord> *u_ext[], Func<Ord> *v, GeomVol<Ord> *e, Func<Ord> **ext) const {
195+
Ord ord(int n, double *wt, Func<Ord> *u_ext[], Func<Ord> *v, Geom<Ord> *e, Func<Ord> **ext) const {
188196
Ord result = Ord(0);
197+
if(!Stokes) {
198+
Func<Ord>* vel_prev_time = ext[2]; // this form is used with both velocity components
199+
result = int_u_v<Ord, Ord>(n, wt, vel_prev_time, v) / time_step;
200+
}
189201
return result;
190202
}
191203

@@ -256,6 +268,8 @@ class WeakFormNSNewton : public WeakForm<double>
256268

257269
double value(int n, double *wt, Func<double> *u_ext[], Func<double> *u, Func<double> *v, GeomVol<double> *e, Func<double> **ext) const{
258270
double result = int_grad_u_grad_v<double, double>(n, wt, u, v) / Reynolds;
271+
if(!Stokes)
272+
result += int_u_v<double, double>(n, wt, u, v) / time_step;
259273
return result;
260274
}
261275

@@ -496,7 +510,8 @@ class WeakFormNSNewton : public WeakForm<double>
496510
result += wt[i] * ((xvel_prev_newton->dx[i] * v->dx[i] + xvel_prev_newton->dy[i] * v->dy[i]) / Reynolds - (p_prev_newton->val[i] * v->dx[i]));
497511
if(!Stokes)
498512
for (int i = 0; i < n; i++)
499-
result += wt[i] * (xvel_prev_newton->val[i] * xvel_prev_newton->dx[i] + yvel_prev_newton->val[i] * xvel_prev_newton->dy[i]) * v->val[i];
513+
result += wt[i] * (((xvel_prev_newton->val[i] - xvel_prev_time->val[i]) * v->val[i] / time_step )
514+
+ ((xvel_prev_newton->val[i] * xvel_prev_newton->dx[i] + yvel_prev_newton->val[i] * xvel_prev_newton->dy[i]) * v->val[i]));
500515
return result;
501516
}
502517

@@ -511,7 +526,8 @@ class WeakFormNSNewton : public WeakForm<double>
511526
result += wt[i] * ((xvel_prev_newton->dx[i] * v->dx[i] + xvel_prev_newton->dy[i] * v->dy[i]) / Reynolds - (p_prev_newton->val[i] * v->dx[i]));
512527
if(!Stokes)
513528
for (int i = 0; i < n; i++)
514-
result += wt[i] * (xvel_prev_newton->val[i] * xvel_prev_newton->dx[i] + yvel_prev_newton->val[i] * xvel_prev_newton->dy[i]) * v->val[i];
529+
result += wt[i] * (((xvel_prev_newton->val[i] - xvel_prev_time->val[i]) * v->val[i] / time_step)
530+
+ ((xvel_prev_newton->val[i] * xvel_prev_newton->dx[i] + yvel_prev_newton->val[i] * xvel_prev_newton->dy[i]) * v->val[i]));
515531
return result;
516532
}
517533

@@ -543,7 +559,8 @@ class WeakFormNSNewton : public WeakForm<double>
543559
result += wt[i] * ((yvel_prev_newton->dx[i] * v->dx[i] + yvel_prev_newton->dy[i] * v->dy[i]) / Reynolds - (p_prev_newton->val[i] * v->dy[i]));
544560
if(!Stokes)
545561
for (int i = 0; i < n; i++)
546-
result += wt[i] * (xvel_prev_newton->val[i] * yvel_prev_newton->dx[i] + yvel_prev_newton->val[i] * yvel_prev_newton->dy[i]) * v->val[i];
562+
result += wt[i] * (((yvel_prev_newton->val[i] - yvel_prev_time->val[i]) * v->val[i] / time_step )
563+
+ ((xvel_prev_newton->val[i] * yvel_prev_newton->dx[i] + yvel_prev_newton->val[i] * yvel_prev_newton->dy[i]) * v->val[i]));
547564
return result;
548565
}
549566

@@ -631,8 +648,11 @@ class EssentialBCNonConst : public EssentialBoundaryCondition<double>
631648
};
632649

633650
virtual double value(double x, double y) const {
634-
double val_y = -x*(1-x);
635-
return val_y / 4.;
651+
double val_y = vel_inlet * y*(H-y) / (H/2.)/(H/2.);
652+
if (current_time <= startup_time)
653+
return val_y * current_time/startup_time;
654+
else
655+
return val_y;
636656
};
637657

638658
protected:

0 commit comments

Comments
 (0)