27 void mesh_fem_global_function::set_functions
28 (
const std::vector<pglobal_function>& funcs,
const mesh_im &mim) {
29 GMM_ASSERT1(linked_mesh_ != 0,
"Mesh fem need to be initialized with"
35 GMM_ASSERT1(&(mim.linked_mesh()) == linked_mesh_,
36 "The provided mesh_im has to be linked to the same mesh"
37 " as this mesh_fem.");
45 void mesh_fem_global_function::clear() {
163 void params_for_uniform_1d_bspline_basis_functions
165 bspline_boundary bc_low, bspline_boundary bc_high,
166 std::vector<scalar_type> &xmin, std::vector<scalar_type> &xmax,
167 std::vector<scalar_type> &xshift, std::vector<size_type> &xtype) {
169 if (bc_low == bspline_boundary::PERIODIC ||
170 bc_high == bspline_boundary::PERIODIC)
171 GMM_ASSERT1(bc_low == bc_high,
172 "Periodic BC has to be assigned to both matching sides");
173 const scalar_type dx = (x1-x0)/scalar_type(N);
175 n_low = (bc_low == bspline_boundary::PERIODIC) ? 0 :
176 (bc_low == bspline_boundary::SYMMETRY ? order/2 :
178 n_high = (bc_high == bspline_boundary::PERIODIC) ? order-1 :
179 (bc_high == bspline_boundary::SYMMETRY ? order/2 :
181 n_mid = N - order + 1;
190 if (bc_low == bspline_boundary::FREE && i < n_low) {
193 xmax[i] = xmin[i] + scalar_type(xtype[i])*dx;
194 }
else if (bc_high == bspline_boundary::FREE && i >= n_low+n_mid) {
197 xmax[i] = xmin[i] - scalar_type(xtype[i])*dx;
198 }
else if (bc_low == bspline_boundary::SYMMETRY && i < n_low) {
200 xmin[i] = x0 - scalar_type(n_low-i)*dx;
201 xmax[i] = xmin[i] + scalar_type(xtype[i])*dx;
202 xshift[i] = -(xmin[i]+xmax[i]-2*x0);
203 }
else if (bc_high == bspline_boundary::SYMMETRY && i >= n_low+n_mid) {
205 xmin[i] = x0 + scalar_type(i-n_low)*dx;
206 xmax[i] = xmin[i] + scalar_type(xtype[i])*dx;
207 xshift[i] = 2*x1-xmin[i]-xmax[i];
209 GMM_ASSERT1(i >= n_low,
"Internal error");
211 xmin[i] = x0 + scalar_type(i-n_low)*dx;
212 xmax[i] = xmin[i] + scalar_type(xtype[i])*dx;
217 if (bc_low == bspline_boundary::PERIODIC && xmax[i] > x1)
218 xshift[i] = -(x1-x0);
224 bspline_boundary bcX_low, bspline_boundary bcX_high,
228 "This function expects a mesh_fem defined in 1d");
230 base_node Pmin, Pmax;
232 const scalar_type x0=Pmin[0], x1=Pmax[0];
234 std::vector<scalar_type> xmin, xmax, xshift;
235 std::vector<size_type> xtype;
236 params_for_uniform_1d_bspline_basis_functions
237 (x0, x1, NX, order, bcX_low, bcX_high,
238 xmin, xmax, xshift, xtype);
240 std::vector<pglobal_function> funcs(0);
241 for (
size_type i=0; i < xtype.size(); ++i) {
242 if (gmm::abs(xshift[i]) < 1e-10)
243 funcs.push_back(global_function_bspline
244 (xmin[i], xmax[i], order, xtype[i]));
246 std::vector<pglobal_function> sum;
247 sum.push_back(global_function_bspline
248 (xmin[i], xmax[i], order, xtype[i]));
249 sum.push_back(global_function_bspline
250 (xmin[i]+xshift[i], xmax[i]+xshift[i],
252 funcs.push_back(std::make_shared<getfem::global_function_sum>(sum));
255 mf.set_functions(funcs, mim);
261 bspline_boundary bcX_low, bspline_boundary bcY_low,
262 bspline_boundary bcX_high, bspline_boundary bcY_high,
266 "This function expects a mesh_fem defined in 2d");
268 base_node Pmin, Pmax;
270 const scalar_type x0=Pmin[0], x1=Pmax[0],
271 y0=Pmin[1], y1=Pmax[1];
273 std::vector<scalar_type> xmin, xmax, xshift;
274 std::vector<size_type> xtype;
275 params_for_uniform_1d_bspline_basis_functions
276 (x0, x1, NX, order, bcX_low, bcX_high,
277 xmin, xmax, xshift, xtype);
278 std::vector<scalar_type> ymin, ymax, yshift;
279 std::vector<size_type> ytype;
280 params_for_uniform_1d_bspline_basis_functions
281 (y0, y1, NY, order, bcY_low, bcY_high,
282 ymin, ymax, yshift, ytype);
284 std::vector<pglobal_function> funcs(0);
285 for (
size_type i=0; i < xtype.size(); ++i) {
286 for (
size_type j=0; j < ytype.size(); ++j) {
287 if (gmm::abs(xshift[i]) < 1e-10 &&
288 gmm::abs(yshift[j]) < 1e-10)
289 funcs.push_back(global_function_bspline
290 (xmin[i], xmax[i], ymin[j], ymax[j],
291 order, xtype[i], ytype[j]));
293 std::vector<pglobal_function> sum;
294 sum.push_back(global_function_bspline
295 (xmin[i], xmax[i], ymin[j], ymax[j],
296 order, xtype[i], ytype[j]));
297 if (gmm::abs(xshift[i]) >= 1e-10)
298 sum.push_back(global_function_bspline
299 (xmin[i]+xshift[i], xmax[i]+xshift[i],
301 order, xtype[i], ytype[j]));
302 if (gmm::abs(yshift[j]) >= 1e-10) {
303 sum.push_back(global_function_bspline
305 ymin[j]+yshift[j], ymax[j]+yshift[j],
306 order, xtype[i], ytype[j]));
307 if (gmm::abs(xshift[i]) >= 1e-10)
308 sum.push_back(global_function_bspline
309 (xmin[i]+xshift[i], xmax[i]+xshift[i],
310 ymin[j]+yshift[j], ymax[j]+yshift[j],
311 order, xtype[i], ytype[j]));
313 funcs.push_back(std::make_shared<getfem::global_function_sum>(sum));
317 mf.set_functions(funcs, mim);
323 bspline_boundary bcX_low,
324 bspline_boundary bcY_low,
325 bspline_boundary bcZ_low,
326 bspline_boundary bcX_high,
327 bspline_boundary bcY_high,
328 bspline_boundary bcZ_high,
const mesh_im &mim) {
331 "This function expects a mesh_fem defined in 3d");
333 base_node Pmin, Pmax;
335 const scalar_type x0=Pmin[0], x1=Pmax[0],
336 y0=Pmin[1], y1=Pmax[1],
337 z0=Pmin[2], z1=Pmax[2];
339 std::vector<scalar_type> xmin, xmax, xshift;
340 std::vector<size_type> xtype;
341 params_for_uniform_1d_bspline_basis_functions
342 (x0, x1, NX, order, bcX_low, bcX_high,
343 xmin, xmax, xshift, xtype);
344 std::vector<scalar_type> ymin, ymax, yshift;
345 std::vector<size_type> ytype;
346 params_for_uniform_1d_bspline_basis_functions
347 (y0, y1, NY, order, bcY_low, bcY_high,
348 ymin, ymax, yshift, ytype);
349 std::vector<scalar_type> zmin, zmax, zshift;
350 std::vector<size_type> ztype;
351 params_for_uniform_1d_bspline_basis_functions
352 (z0, z1, NZ, order, bcZ_low, bcZ_high,
353 zmin, zmax, zshift, ztype);
355 std::vector<pglobal_function> funcs(0);
356 for (
size_type i=0; i < xtype.size(); ++i) {
357 for (
size_type j=0; j < ytype.size(); ++j) {
358 for (
size_type k=0; k < ztype.size(); ++k) {
360 bool has_xshift = gmm::abs(xshift[i]) >= 1e-10;
361 bool has_yshift = gmm::abs(yshift[j]) >= 1e-10;
362 bool has_zshift = gmm::abs(zshift[k]) >= 1e-10;
363 if (!has_xshift && !has_yshift && !has_yshift)
364 funcs.push_back(global_function_bspline
368 order, xtype[i], ytype[j], ztype[k])) ;
370 std::vector<pglobal_function> sum;
371 sum.push_back(global_function_bspline
375 order, xtype[i], ytype[j], ztype[k]));
377 sum.push_back(global_function_bspline
378 (xmin[i]+xshift[i], xmax[i]+xshift[i],
381 order, xtype[i], ytype[j], ztype[k]));
383 sum.push_back(global_function_bspline
385 ymin[j]+yshift[j], ymax[j]+yshift[j],
387 order, xtype[i], ytype[j], ztype[k]));
389 sum.push_back(global_function_bspline
392 zmin[k]+zshift[k], zmax[k]+zshift[k],
393 order, xtype[i], ytype[j], ztype[k]));
394 if (has_xshift && has_yshift)
395 sum.push_back(global_function_bspline
396 (xmin[i]+xshift[i], xmax[i]+xshift[i],
397 ymin[j]+yshift[j], ymax[j]+yshift[j],
399 order, xtype[i], ytype[j], ztype[k]));
400 if (has_yshift && has_zshift)
401 sum.push_back(global_function_bspline
403 ymin[j]+yshift[j], ymax[j]+yshift[j],
404 zmin[k]+zshift[k], zmax[k]+zshift[k],
405 order, xtype[i], ytype[j], ztype[k]));
406 if (has_zshift && has_xshift)
407 sum.push_back(global_function_bspline
408 (xmin[i]+xshift[i], xmax[i]+xshift[i],
410 zmin[k]+zshift[k], zmax[k]+zshift[k],
411 order, xtype[i], ytype[j], ztype[k]));
412 if (has_xshift && has_yshift && has_zshift)
413 sum.push_back(global_function_bspline
414 (xmin[i]+xshift[i], xmax[i]+xshift[i],
415 ymin[j]+yshift[j], ymax[j]+yshift[j],
416 zmin[k]+zshift[k], zmax[k]+zshift[k],
417 order, xtype[i], ytype[j], ztype[k]));
418 funcs.push_back(std::make_shared<getfem::global_function_sum>(sum));
423 mf.set_functions(funcs, mim);
this is a convenience class for defining a mesh_fem with base functions which are global functions (f...
const mesh & linked_mesh() const
Return a reference to the underlying mesh.
void set_finite_element(size_type cv, pfem pf)
Set the finite element method of a convex.
Describe an integration method linked to a mesh.
void bounding_box(base_node &Pmin, base_node &Pmax) const
Return the bounding box [Pmin - Pmax] of the mesh.
Define a mesh_fem with base functions which are global functions given by the user.
size_t size_type
used as the common size type in the library
GEneric Tool for Finite Element Methods.
void del_fem_global_function(const pfem &pf)
release a global function FEM
void define_uniform_bspline_basis_functions_for_mesh_fem(mesh_fem_global_function &mf, size_type NX, size_type order, bspline_boundary bcX_low=bspline_boundary::FREE, bspline_boundary bcX_high=bspline_boundary::FREE, const mesh_im &mim=dummy_mesh_im())
This function will generate bspline basis functions on NX uniform elements along a line.
const mesh_im & dummy_mesh_im()
Dummy mesh_im for default parameter of functions.
pfem new_fem_global_function(const std::vector< pglobal_function > &funcs, const mesh &m)
create a new global function FEM.