ug4
scalar_obstacle_impl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3  * Author: Raphael Prohl
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef __H__UG__LIB_ALGEBRA__OPERATOR__PRECONDITIONER__PROJECTED_GAUSS_SEIDEL__SCALAR_OBSTACLE_IMPL__
34 #define __H__UG__LIB_ALGEBRA__OPERATOR__PRECONDITIONER__PROJECTED_GAUSS_SEIDEL__SCALAR_OBSTACLE_IMPL__
35 
36 #include "scalar_obstacle.h"
37 
38 namespace ug{
39 
41 // SCALAR LOWER OBSTACLE
43 
44 template <typename TDomain, typename TAlgebra>
45 void
47 adjust_sol_and_cor(value_type& sol_i, value_type& c_i, bool& dofIsActive,
48  const DoFIndex& dof)
49 {
50  const size_t comp = dof[1];
51 
52  // tmpSol := u_{s-1/2} = u_{s-1} + c
53  const number tmpSol = BlockRef(sol_i, comp) + BlockRef(c_i, comp);
54 
55  // get lower obstacle value corresponding to the dof
56  const number obsVal = m_mObstacleValues[dof];
57 
58  // check, if dof is active (tmpSol <= obsVal)
59  if (!(tmpSol > obsVal))
60  {
61  // is active DoF
62  m_vActiveDofs.push_back(dof);
63 
64  // adjust correction & set solution to obstacle-value
65  BlockRef(c_i, comp) = obsVal - BlockRef(sol_i, comp);
66  BlockRef(sol_i, comp) = obsVal;
67  dofIsActive = true;
68  }
69 }
70 
71 template <typename TDomain, typename TAlgebra>
72 void
75 {
76  for (std::vector<MultiIndex<2> >::iterator itActiveInd = m_vActiveDofs.begin();
77  itActiveInd < m_vActiveDofs.end(); ++itActiveInd)
78  {
79  // check, if Ax <= b. For that case the new defect is set to zero,
80  // since all equations/constraints are fulfilled
81  number defect = BlockRef(d[(*itActiveInd)[0]], (*itActiveInd)[1]);
82  if (defect < 0.0)
83  BlockRef(d[(*itActiveInd)[0]], (*itActiveInd)[1]) = 0.0;
84  }
85 }
86 
87 template <typename TDomain, typename TAlgebra>
88 void
91 {}
92 
94 // SCALAR UPPER OBSTACLE
96 
97 template <typename TDomain, typename TAlgebra>
98 void
100 adjust_sol_and_cor(value_type& sol_i, value_type& c_i, bool& dofIsActive,
101  const DoFIndex& dof)
102 {
103  const size_t comp = dof[1];
104 
105  // tmpSol := u_{s-1/2} = u_{s-1} + c
106  const number tmpSol = BlockRef(sol_i, comp) + BlockRef(c_i, comp);
107 
108  // get upper obstacle value corresponding to the dof
109  const number obsVal = m_mObstacleValues[dof];
110 
111  // check, if dof is active (tmpSol >= obsVal)
112  if (!(tmpSol < obsVal))
113  {
114  // is active DoF
115  m_vActiveDofs.push_back(dof);
116 
117  // adjust correction & set solution to obstacle-value
118  BlockRef(c_i, comp) = obsVal - BlockRef(sol_i, comp);
119  BlockRef(sol_i, comp) = obsVal;
120  dofIsActive = true;
121  }
122  //UG_LOG("dof " <<dof<< " is active: " <<dofIsActive<<"\n");
123 }
124 
125 template <typename TDomain, typename TAlgebra>
126 void
129 {
130  for (std::vector<MultiIndex<2> >::iterator itActiveInd = m_vActiveDofs.begin();
131  itActiveInd < m_vActiveDofs.end(); ++itActiveInd)
132  {
133  // check, if Ax > b. For that case the new defect is set to zero,
134  // since all equations/constraints are fulfilled
135  //UG_LOG("adjust_defect: " << (*itActiveInd)[0] <<","<< (*itActiveInd)[1] << "\n");
136  number defect = BlockRef(d[(*itActiveInd)[0]], (*itActiveInd)[1]);
137  if (defect > 0.0)
138  {
139  //UG_LOG("defect > 0 \n");
140  BlockRef(d[(*itActiveInd)[0]], (*itActiveInd)[1]) = 0.0;
141  }
142  }
143 }
144 
145 template <typename TDomain, typename TAlgebra>
146 void
149 {}
150 
151 } // end namespace ug
152 
153 #endif /* __H__UG__LIB_ALGEBRA__OPERATOR__PRECONDITIONER__PROJECTED_GAUSS_SEIDEL__SCALAR_OBSTACLE_IMPL__ */
vector_type::value_type value_type
Value type.
Definition: obstacle_constraint_interface.h:88
algebra_type::vector_type vector_type
Vector type.
Definition: obstacle_constraint_interface.h:85
Definition: multi_index.h:50
void restrict_obs_values()
restricts the obstacle values to a coarser grid in a multigrid hierarchy
Definition: scalar_obstacle_impl.h:90
void adjust_defect_to_constraint(vector_type &d)
the defect needs to be adjusted for the active indices (those indices, which are in contact)
Definition: scalar_obstacle_impl.h:74
void adjust_sol_and_cor(value_type &sol_i, value_type &c_i, bool &dofIsActive, const DoFIndex &dof)
projects the i-th index of the solution onto the admissible set and adjusts the correction
Definition: scalar_obstacle_impl.h:47
void adjust_defect_to_constraint(vector_type &d)
the defect needs to be adjusted for the active indices (those indices, which are in contact)
Definition: scalar_obstacle_impl.h:128
void restrict_obs_values()
restricts the obstacle values to a coarser grid in a multigrid hierarchy
Definition: scalar_obstacle_impl.h:148
void adjust_sol_and_cor(value_type &sol_i, value_type &c_i, bool &dofIsActive, const DoFIndex &dof)
projects the i-th index of the solution onto the admissible set and adjusts the correction
Definition: scalar_obstacle_impl.h:100
double number
Definition: types.h:124
the ug namespace
double & BlockRef(T &vec, size_t i)
Definition: blocks.h:66