16 #include "projections/localprojection.h"
18 #include "discrete_problem.h"
24 template<
typename Scalar>
25 int LocalProjection<Scalar>::ndof = 0;
27 template<
typename Scalar>
28 LocalProjection<Scalar>::LocalProjection()
32 template<
typename Scalar>
33 void LocalProjection<Scalar>::project_local(
const Space<Scalar>* space, MeshFunction<Scalar>* meshfn,
36 if(proj_norm == HERMES_UNSET_NORM)
38 SpaceType space_type = space->get_type();
41 case HERMES_H1_SPACE: proj_norm = HERMES_H1_NORM;
break;
42 case HERMES_HCURL_SPACE: proj_norm = HERMES_HCURL_NORM;
break;
43 case HERMES_HDIV_SPACE: proj_norm = HERMES_HDIV_NORM;
break;
44 case HERMES_L2_SPACE: proj_norm = HERMES_L2_NORM;
break;
45 default:
throw Hermes::Exceptions::Exception(
"Unknown space type in OGProjection<Scalar>::project_global().");
50 int ndof = space->get_num_dofs();
53 memset(target_vec, 0, ndof*
sizeof(Scalar));
58 Mesh* mesh = space->get_mesh();
61 for_all_active_elements(e, mesh)
63 int order = space->get_element_order(e->id);
66 for (
unsigned int j = 0; j < e->get_nvert(); j++)
71 double x = e->vn[j]->x;
72 double y = e->vn[j]->y;
74 typename Space<Scalar>::NodeData* nd = space->ndata + vn->id;
75 if(!vn->is_constrained_vertex() && nd->dof >= 0)
77 int dof_num = nd->dof;
83 Scalar val = meshfn->get_pt_value(x, y)->val[0];
85 target_vec[dof_num] = val;
96 template<
typename Scalar>
97 void LocalProjection<Scalar>::project_local(
const Space<Scalar>* space,
98 Solution<Scalar>* source_sln, Solution<Scalar>* target_sln,
101 int ndof = space->get_num_dofs();
102 Scalar* coeff_vec =
new Scalar[ndof];
103 project_local(space, source_sln, coeff_vec, proj_norm);
104 Solution<Scalar>::vector_to_solution(coeff_vec, space, target_sln, proj_norm);
108 template<
typename Scalar>
109 void LocalProjection<Scalar>::project_local(Hermes::vector<
const Space<Scalar>*> spaces,
110 Hermes::vector<MeshFunction<Scalar>*> meshfns, Scalar* target_vec,
111 Hermes::vector<ProjNormType> proj_norms)
113 int n = spaces.size();
115 if(n != meshfns.size())
throw Exceptions::LengthException(1, 2, n, meshfns.size());
116 if(target_vec == NULL)
throw Exceptions::NullException(3);
117 if(!proj_norms.empty() && n!=proj_norms.size())
throw Exceptions::LengthException(1, 5, n, proj_norms.size());
120 for (
int i = 0; i < n; i++)
122 if(proj_norms.empty())
123 project_local(spaces[i], meshfns[i], target_vec + start_index);
125 project_local(spaces[i], meshfns[i], target_vec + start_index, proj_norms[i]);
126 start_index += spaces[i]->get_num_dofs();
130 template<
typename Scalar>
131 void LocalProjection<Scalar>::project_local(Hermes::vector<
const Space<Scalar>*> spaces,
132 Hermes::vector<Solution<Scalar>*> slns, Scalar* target_vec,
133 Hermes::vector<ProjNormType> proj_norms)
135 int n = spaces.size();
138 if(n != slns.size())
throw Exceptions::LengthException(1, 2, n, slns.size());
139 if(target_vec == NULL)
throw Exceptions::NullException(3);
140 if(!proj_norms.empty() && n!=proj_norms.size())
throw Exceptions::LengthException(1, 5, n, proj_norms.size());
143 for (
int i = 0; i < n; i++)
145 if(proj_norms.empty())
146 project_local(spaces[i], slns[i], target_vec + start_index);
148 project_local(spaces[i], slns[i], target_vec + start_index, proj_norms[i]);
149 start_index += spaces[i]->get_num_dofs();
153 template<
typename Scalar>
154 void LocalProjection<Scalar>::project_local(Hermes::vector<
const Space<Scalar>*> spaces, Hermes::vector<Solution<Scalar>*> source_slns,
155 Hermes::vector<Solution<Scalar>*> target_slns, Hermes::vector<ProjNormType> proj_norms,
bool delete_old_meshes)
157 int n = spaces.size();
160 if(n != source_slns.size())
throw Exceptions::LengthException(1, 2, n, source_slns.size());
161 if(n != target_slns.size())
throw Exceptions::LengthException(1, 2, n, target_slns.size());
162 if(!proj_norms.empty() && n != proj_norms.size())
throw Exceptions::LengthException(1, 5, n, proj_norms.size());
164 for (
int i = 0; i < n; i++)
166 if(proj_norms.empty())
167 project_local(spaces[i], source_slns[i], target_slns[i]);
169 project_local(spaces[i], source_slns[i], target_slns[i], proj_norms[i]);
173 template class HERMES_API LocalProjection<double>;
174 template class HERMES_API LocalProjection<std::complex<double> >;