16 #include "projections/ogprojection.h"
18 #include "linear_solver.h"
24 template<
typename Scalar>
25 OGProjection<Scalar>::OGProjection() : Hermes::Mixins::Loggable(), ndof(0)
29 template<
typename Scalar>
35 throw Hermes::Exceptions::Exception(
"this->space == NULL in project_internal().");
43 linear_solver.set_verbose_output(this->get_verbose_output());
46 linear_solver.
solve();
48 if(target_vec != NULL)
50 target_vec[i] = linear_solver.get_sln_vector()[i];
53 template<
typename Scalar>
65 project_internal(space, proj_wf, target_vec);
71 template<
typename Scalar>
77 if(target_vec == NULL)
78 throw Exceptions::NullException(3);
83 if(proj_norm == HERMES_UNSET_NORM)
85 SpaceType space_type = space->
get_type();
88 case HERMES_H1_SPACE: norm = HERMES_H1_NORM;
break;
89 case HERMES_HCURL_SPACE: norm = HERMES_HCURL_NORM;
break;
90 case HERMES_HDIV_SPACE: norm = HERMES_HDIV_NORM;
break;
91 case HERMES_L2_SPACE: norm = HERMES_L2_NORM;
break;
92 default:
throw Hermes::Exceptions::Exception(
"Unknown space type in OGProjection<Scalar>::project_global().");
95 else norm = proj_norm;
98 WeakForm<Scalar>* proj_wf =
new WeakForm<Scalar>(1);
99 proj_wf->warned_nonOverride =
true;
100 proj_wf->set_ext(source_meshfn);
102 proj_wf->add_matrix_form(
new ProjectionMatrixFormVol(0, 0, norm));
104 proj_wf->add_vector_form(
new ProjectionVectorFormVol(0, norm));
107 project_internal(space, proj_wf, target_vec);
113 template<
typename Scalar>
118 if(proj_norm == HERMES_UNSET_NORM)
120 SpaceType space_type = space->
get_type();
123 case HERMES_H1_SPACE: proj_norm = HERMES_H1_NORM;
break;
124 case HERMES_HCURL_SPACE: proj_norm = HERMES_HCURL_NORM;
break;
125 case HERMES_HDIV_SPACE: proj_norm = HERMES_HDIV_NORM;
break;
126 case HERMES_L2_SPACE: proj_norm = HERMES_L2_NORM;
break;
127 default:
throw Hermes::Exceptions::Exception(
"Unknown space type in OGProjection<Scalar>::project_global().");
133 Scalar* target_vec =
new Scalar[ndof];
134 project_global(space, source_sln, target_vec, proj_norm);
140 delete [] target_vec;
143 template<
typename Scalar>
146 Scalar* target_vec, Hermes::vector<ProjNormType> proj_norms)
148 int n = spaces.size();
151 if(n != source_meshfns.size())
152 throw Exceptions::LengthException(1, 2, n, source_meshfns.size());
153 if(target_vec == NULL)
154 throw Exceptions::NullException(3);
155 if(!proj_norms.empty() && n != proj_norms.size())
156 throw Exceptions::LengthException(1, 5, n, proj_norms.size());
159 for (
int i = 0; i < n; i++)
162 this->info(
"Projection: %d-th space", i);
164 this->info(
"Projection: %d-st space", i);
166 this->info(
"Projection: %d-nd space", i);
168 this->info(
"Projection: %d-rd space", i);
170 this->info(
"Projection: %d-th space", i);
171 if(proj_norms.empty())
172 project_global(spaces[i], source_meshfns[i], target_vec + start_index, HERMES_UNSET_NORM);
174 project_global(spaces[i], source_meshfns[i], target_vec + start_index, proj_norms[i]);
175 spaces[i]->assign_dofs(start_index);
176 start_index += spaces[i]->get_num_dofs();
180 template<
typename Scalar>
182 Scalar* target_vec, Hermes::vector<ProjNormType> proj_norms)
184 int n = spaces.size();
187 if(n != source_slns.size())
188 throw Exceptions::LengthException(1, 2, n, source_slns.size());
189 if(target_vec == NULL)
190 throw Exceptions::NullException(3);
191 if(!proj_norms.empty() && n != proj_norms.size())
192 throw Exceptions::LengthException(1, 5, n, proj_norms.size());
195 for (
int i = 0; i < n; i++)
198 this->info(
"Projection: %d-th space", i);
200 this->info(
"Projection: %d-st space", i);
202 this->info(
"Projection: %d-nd space", i);
204 this->info(
"Projection: %d-rd space", i);
206 this->info(
"Projection: %d-th space", i);
207 if(proj_norms.empty())
208 project_global(spaces[i], source_slns[i], target_vec + start_index, HERMES_UNSET_NORM);
210 project_global(spaces[i], source_slns[i], target_vec + start_index, proj_norms[i]);
211 start_index += spaces[i]->get_num_dofs();
215 template<
typename Scalar>
217 Hermes::vector<
Solution<Scalar>*> target_slns, Hermes::vector<ProjNormType> proj_norms,
bool delete_old_meshes)
219 int n = spaces.size();
222 if(n != source_slns.size())
223 throw Exceptions::LengthException(1, 2, n, source_slns.size());
224 if(n != target_slns.size())
225 throw Exceptions::LengthException(1, 2, n, target_slns.size());
226 if(!proj_norms.empty() && n != proj_norms.size())
227 throw Exceptions::LengthException(1, 5, n, proj_norms.size());
230 for (
int i = 0; i < n; i++)
233 this->info(
"Projection: %d-th space", i);
235 this->info(
"Projection: %d-st space", i);
237 this->info(
"Projection: %d-nd space", i);
239 this->info(
"Projection: %d-rd space", i);
241 this->info(
"Projection: %d-th space", i);
242 if(proj_norms.empty())
243 project_global(spaces[i], source_slns[i], target_slns[i], HERMES_UNSET_NORM);
245 project_global(spaces[i], source_slns[i], target_slns[i], proj_norms[i]);
246 start_index += spaces[i]->get_num_dofs();
250 template class HERMES_API OGProjection<double>;
251 template class HERMES_API OGProjection<std::complex<double> >;