18 #ifndef __H2D_OGPROJECTION_NOX_H
19 #define __H2D_OGPROJECTION_NOX_H
21 #include "../function/solution.h"
23 #include "../weakform/weakform.h"
26 #if(defined HAVE_NOX && defined HAVE_EPETRA && defined HAVE_TEUCHOS)
28 #ifdef _POSIX_C_SOURCE
29 # undef _POSIX_C_SOURCE // pyconfig.h included by NOX_Epetra defines it
32 # undef _XOPEN_SOURCE // pyconfig.h included by NOX_Epetra defines it
34 #include <NOX_Epetra.H>
40 template<
typename Scalar>
41 class HERMES_API OGProjectionNOX :
public Hermes::Mixins::Loggable
46 static void project_global(SpaceSharedPtr<Scalar> space,
47 MatrixFormVol<Scalar>* custom_projection_jacobian,
48 VectorFormVol<Scalar>* custom_projection_residual,
49 Scalar* target_vec,
double newton_tol = 1e-6,
int newton_max_iter = 10);
70 static void project_global(SpaceSharedPtr<Scalar> space, MeshFunction<Scalar>* source_meshfn,
71 Scalar* target_vec,
NormType proj_norm = HERMES_UNSET_NORM,
72 double newton_tol = 1e-6,
int newton_max_iter = 10);
75 static void project_global(SpaceSharedPtr<Scalar> space, MeshFunctionSharedPtr<Scalar> source_meshfn,
76 Scalar* target_vec,
NormType proj_norm = HERMES_UNSET_NORM,
77 double newton_tol = 1e-6,
int newton_max_iter = 10);
80 static void project_global(SpaceSharedPtr<Scalar> space,
81 MeshFunctionSharedPtr<Scalar> source_sln, MeshFunctionSharedPtr<Scalar> target_sln,
82 NormType proj_norm = HERMES_UNSET_NORM,
83 double newton_tol = 1e-6,
int newton_max_iter = 10);
86 static void project_global(std::vector<SpaceSharedPtr<Scalar> > spaces, std::vector<MeshFunction<Scalar>* > source_meshfns,
87 Scalar* target_vec, std::vector<NormType> proj_norms = std::vector<NormType>(),
88 double newton_tol = 1e-6,
int newton_max_iter = 10);
91 static void project_global(std::vector<SpaceSharedPtr<Scalar> > spaces, std::vector<MeshFunctionSharedPtr<Scalar> > source_slns,
92 Scalar* target_vec, std::vector<NormType> proj_norms = std::vector<NormType>(),
93 double newton_tol = 1e-6,
int newton_max_iter = 10);
95 static void project_global(std::vector<SpaceSharedPtr<Scalar> > spaces,
96 std::vector<MeshFunctionSharedPtr<Scalar> > source_slns, std::vector<MeshFunctionSharedPtr<Scalar> > target_slns,
97 std::vector<NormType> proj_norms = std::vector<NormType>(),
bool delete_old_mesh =
false,
98 double newton_tol = 1e-6,
int newton_max_iter = 10);
106 static void project_internal(SpaceSharedPtr<Scalar> space, WeakForm<Scalar>* proj_wf, Scalar* target_vec,
107 double newton_tol = 1e-6,
int newton_max_iter = 10);
110 class ProjectionMatrixFormVol :
public MatrixFormVol < Scalar >
113 ProjectionMatrixFormVol(
int i,
int j,
NormType norm_type) : MatrixFormVol<Scalar>(i, j)
115 this->norm_type = norm_type;
118 Scalar value(
int n,
double *wt, Func<Scalar> *u_ext[], Func<double> *u, Func<double> *v,
119 Geom<double> *e, Func<Scalar> **ext)
const
124 return l2_projection_biform<double, Scalar>(n, wt, u_ext, u, v, e, ext);
126 return h1_projection_biform<double, Scalar>(n, wt, u_ext, u, v, e, ext);
127 case HERMES_H1_SEMINORM:
128 return h1_semi_projection_biform<double, Scalar>(n, wt, u_ext, u, v, e, ext);
129 case HERMES_HCURL_NORM:
130 return hcurl_projection_biform<double, Scalar>(n, wt, u_ext, u, v, e, ext);
131 case HERMES_HDIV_NORM:
132 return hdiv_projection_biform<double, Scalar>(n, wt, u_ext, u, v, e, ext);
134 throw Hermes::Exceptions::Exception(
"Unknown projection type");
139 Hermes::Ord ord(
int n,
double *wt, Func<Hermes::Ord> *u_ext[], Func<Hermes::Ord> *u, Func<Hermes::Ord> *v,
140 Geom<Hermes::Ord> *e, Func<Ord> **ext)
const
145 return l2_projection_biform<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, u, v, e, ext);
147 return h1_projection_biform<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, u, v, e, ext);
148 case HERMES_H1_SEMINORM:
149 return h1_semi_projection_biform<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, u, v, e, ext);
150 case HERMES_HCURL_NORM:
151 return hcurl_projection_biform<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, u, v, e, ext);
152 case HERMES_HDIV_NORM:
153 return hdiv_projection_biform<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, u, v, e, ext);
155 throw Hermes::Exceptions::Exception(
"Unknown projection type");
156 return Hermes::Ord();
160 MatrixFormVol<Scalar>* clone()
162 return new ProjectionMatrixFormVol(*
this);
168 template<
typename TestFunctionDomain,
typename SolFunctionDomain>
169 static SolFunctionDomain h1_projection_biform(
int n,
double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *u,
170 Func<TestFunctionDomain> *v, Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
172 SolFunctionDomain result = SolFunctionDomain(0);
173 for (
int i = 0; i < n; i++)
174 result += wt[i] * (u->val[i] * v->val[i] + u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]);
178 template<
typename TestFunctionDomain,
typename SolFunctionDomain>
179 static SolFunctionDomain h1_semi_projection_biform(
int n,
double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *u,
180 Func<TestFunctionDomain> *v, Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
182 SolFunctionDomain result = SolFunctionDomain(0);
183 for (
int i = 0; i < n; i++)
184 result += wt[i] * (u->dx[i] * v->dx[i] + u->dy[i] * v->dy[i]);
188 template<
typename TestFunctionDomain,
typename SolFunctionDomain>
189 static SolFunctionDomain l2_projection_biform(
int n,
double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *u,
190 Func<TestFunctionDomain> *v, Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
192 SolFunctionDomain result = SolFunctionDomain(0);
193 for (
int i = 0; i < n; i++)
194 result += wt[i] * (u->val[i] * v->val[i]);
198 template<
typename TestFunctionDomain,
typename SolFunctionDomain>
199 static SolFunctionDomain hcurl_projection_biform(
int n,
double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *u,
200 Func<TestFunctionDomain> *v, Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
202 SolFunctionDomain result = SolFunctionDomain(0);
203 for (
int i = 0; i < n; i++) {
204 result += wt[i] * (u->curl[i] * conj(v->curl[i]));
205 result += wt[i] * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i]));
210 template<
typename TestFunctionDomain,
typename SolFunctionDomain>
211 static SolFunctionDomain hdiv_projection_biform(
int n,
double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *u,
212 Func<TestFunctionDomain> *v, Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
214 SolFunctionDomain result = SolFunctionDomain(0);
215 for (
int i = 0; i < n; i++) {
216 result += wt[i] * (u->div[i] * conj(v->div[i]));
217 result += wt[i] * (u->val0[i] * conj(v->val0[i]) + u->val1[i] * conj(v->val1[i]));
224 class ProjectionVectorFormVol :
public VectorFormVol < Scalar >
227 ProjectionVectorFormVol(
int i,
NormType norm_type) : VectorFormVol<Scalar>(i)
229 this->norm_type = norm_type;
232 Scalar value(
int n,
double *wt, Func<Scalar> *u_ext[], Func<double> *v,
233 Geom<double> *e, Func<Scalar> **ext)
const
238 return l2_projection_residual<double, Scalar>(n, wt, u_ext, v, e, ext);
240 return h1_projection_residual<double, Scalar>(n, wt, u_ext, v, e, ext);
241 case HERMES_H1_SEMINORM:
242 return h1_semi_projection_residual<double, Scalar>(n, wt, u_ext, v, e, ext);
243 case HERMES_HCURL_NORM:
244 return hcurl_projection_residual<double, Scalar>(n, wt, u_ext, v, e, ext);
245 case HERMES_HDIV_NORM:
246 return hdiv_projection_residual<double, Scalar>(n, wt, u_ext, v, e, ext);
248 throw Hermes::Exceptions::Exception(
"Unknown projection type");
253 Hermes::Ord ord(
int n,
double *wt, Func<Hermes::Ord> *u_ext[], Func<Hermes::Ord> *v,
254 Geom<Hermes::Ord> *e, Func<Ord> **ext)
const
259 return l2_projection_residual<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, v, e, ext);
261 return h1_projection_residual<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, v, e, ext);
262 case HERMES_H1_SEMINORM:
263 return h1_semi_projection_residual<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, v, e, ext);
264 case HERMES_HCURL_NORM:
265 return hcurl_projection_residual<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, v, e, ext);
266 case HERMES_HDIV_NORM:
267 return hdiv_projection_residual<Hermes::Ord, Hermes::Ord>(n, wt, u_ext, v, e, ext);
269 throw Hermes::Exceptions::Exception(
"Unknown projection type");
270 return Hermes::Ord();
274 VectorFormVol<Scalar>* clone()
276 return new ProjectionVectorFormVol(*
this);
282 template<
typename TestFunctionDomain,
typename SolFunctionDomain>
283 SolFunctionDomain h1_projection_residual(
int n,
double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *v,
284 Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
const
286 SolFunctionDomain result = SolFunctionDomain(0);
287 for (
int i = 0; i < n; i++)
288 result += wt[i] * ((u_ext[this->i]->val[i] - ext[0]->val[i]) * v->val[i]
289 + (u_ext[this->i]->dx[i] - ext[0]->dx[i]) * v->dx[i]
290 + (u_ext[this->i]->dy[i] - ext[0]->dy[i]) * v->dy[i]);
294 template<
typename TestFunctionDomain,
typename SolFunctionDomain>
295 SolFunctionDomain h1_semi_projection_residual(
int n,
double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *v,
296 Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
const
298 SolFunctionDomain result = SolFunctionDomain(0);
299 for (
int i = 0; i < n; i++)
300 result += wt[i] * ((u_ext[this->i]->dx[i] - ext[0]->dx[i]) * v->dx[i]
301 + (u_ext[this->i]->dy[i] - ext[0]->dy[i]) * v->dy[i]);
305 template<
typename TestFunctionDomain,
typename SolFunctionDomain>
306 SolFunctionDomain l2_projection_residual(
int n,
double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *v,
307 Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
const
309 SolFunctionDomain result = SolFunctionDomain(0);
310 for (
int i = 0; i < n; i++)
311 result += wt[i] * (u_ext[this->i]->val[i] - ext[0]->val[i]) * v->val[i];
315 template<
typename TestFunctionDomain,
typename SolFunctionDomain>
316 SolFunctionDomain hcurl_projection_residual(
int n,
double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *v,
317 Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
const
319 SolFunctionDomain result = SolFunctionDomain(0);
320 for (
int i = 0; i < n; i++) {
321 result += wt[i] * (u_ext[this->i]->curl[i] - ext[0]->curl[i]) * conj(v->curl[i]);
322 result += wt[i] * ((u_ext[this->i]->val0[i] - ext[0]->val0[i]) * conj(v->val0[i])
323 + (u_ext[this->i]->val1[i] - ext[0]->val1[i]) * conj(v->val1[i]));
329 template<
typename TestFunctionDomain,
typename SolFunctionDomain>
330 SolFunctionDomain hdiv_projection_residual(
int n,
double *wt, Func<SolFunctionDomain> *u_ext[], Func<TestFunctionDomain> *v,
331 Geom<TestFunctionDomain> *e, Func<SolFunctionDomain> **ext)
const
333 SolFunctionDomain result = SolFunctionDomain(0);
334 for (
int i = 0; i < n; i++) {
335 result += wt[i] * (u_ext[this->i]->div[i] - ext[0]->div[i]) * conj(v->div[i]);
336 result += wt[i] * ((u_ext[this->i]->val0[i] - ext[0]->val0[i]) * conj(v->val0[i])
337 + (u_ext[this->i]->val1[i] - ext[0]->val1[i]) * conj(v->val1[i]));