20 #include "SheafSystem/linear_2d.h" 22 #include "SheafSystem/assert_contract.h" 23 #include "SheafSystem/block.h" 24 #include "SheafSystem/std_cmath.h" 25 #include "SheafSystem/std_iostream.h" 26 #include "SheafSystem/std_limits.h" 43 _basis_values = _basis_value_buffer;
44 _basis_deriv_values = _basis_deriv_value_buffer;
45 _jacobian_values = _jacobian_value_buffer;
65 _basis_values = _basis_value_buffer;
66 _basis_deriv_values = _basis_deriv_value_buffer;
67 _jacobian_values = _jacobian_value_buffer;
124 require(xlocal_coord != 0);
125 require(xlocal_coord_ub >= db());
131 _basis_values[0] = xlocal_coord[0];
132 _basis_values[1] = xlocal_coord[1];
133 _basis_values[2] = 1.0 - (_basis_values[0] + _basis_values[1]);
152 require(xlocal_coords != 0);
153 require(xlocal_coords_ub >= 3);
176 _basis_deriv_value_buffer[ 0] = 1.0;
177 _basis_deriv_value_buffer[ 2] = 0.0;
178 _basis_deriv_value_buffer[ 4] = -1.0;
182 _basis_deriv_value_buffer[ 1] = 0.0;
183 _basis_deriv_value_buffer[ 3] = 1.0;
184 _basis_deriv_value_buffer[ 5] = -1.0;
212 require(xcoord_dofs != 0);
213 require(xcoord_dofs_ub >= dl()*db());
214 require(xdf == 2 || xdf == 3);
218 jacobian(xcoord_dofs, xcoord_dofs_ub, xdf, xlocal_coords, xlocal_coords_ub);
219 const value_type* jvalues = jacobian_values();
234 for(
int i=0; i<xdf; ++i)
270 require(xcoord_dofs != 0);
271 require(xcoord_dofs_ub >= dl()*db());
304 double x0 = xcoord_dofs[0];
305 double x1 = xcoord_dofs[2];
306 double x2 = xcoord_dofs[4];
308 double y0 = xcoord_dofs[1];
309 double y1 = xcoord_dofs[3];
310 double y2 = xcoord_dofs[5];
312 result = 0.5*((x1-x0)*(y2-y0)-(x2-x0)*(y1-y0));
317 for(
int i=0; i<xdf; ++i)
322 double a0 = xcoord_dofs[index];
323 double a1 = xcoord_dofs[index+xdf];
324 double a2 = xcoord_dofs[index+2*xdf];
326 double a10 = a1 - a0;
327 double a20 = a2 - a0;
333 double b0 = xcoord_dofs[index];
334 double b1 = xcoord_dofs[index+xdf];
335 double b2 = xcoord_dofs[index+2*xdf];
337 double b10 = b1 - b0;
338 double b20 = b2 - b0;
340 double v = a10*b20 - a20*b10;
349 result = 0.5*
sqrt(sum*sum);
376 require(xcoord_dofs != 0);
377 require(xcoord_dofs_ub >= dl()*db());
378 require(xintegrands != 0);
379 require(xintegrands_ub >= dl());
380 require(xresult_integrals != 0);
381 require(xresult_integrals_ub > 0);
385 double area = volume(xcoord_dofs, xcoord_dofs_ub, xdf);
386 double third_area = area/3.0;
388 for(
int i=0; i<xresult_integrals_ub; ++i)
391 const dof_type* integrands_n = &xintegrands[i*3];
393 for(
int k=0; k<3; ++k)
395 fn += integrands_n[k];
398 xresult_integrals[i] = fn*third_area;
424 require(xcoord_dofs != 0);
425 require(xcoord_dofs_ub >= dl()*db());
426 require(xintegrands != 0);
428 require(xresult_integrals != 0);
429 require(xresult_integrals_ub > 0);
433 double vol = volume(xcoord_dofs, xcoord_dofs_ub, xdf);
436 for(
int i=0; i<xresult_integrals_ub; ++i)
438 xresult_integrals[i] = xintegrands[i]*v3;
464 require(xcoord_dofs != 0);
465 require(xcoord_dofs_ub >= dl()*db());
466 require(xresult_integrals != 0);
467 require(xresult_integrals_ub >= dl());
471 double vol = volume(xcoord_dofs, xcoord_dofs_ub, xdf);
475 for(
int i=0; i<xresult_integrals_ub; ++i)
477 xresult_integrals[i] = value;
498 require((0 <= xindex) && (xindex < dof_ct()));
499 require(xresult_ub >= db());
505 static const double d = 1.0/3.0;
513 ensure(in_standard_domain(xresult, xresult_ub));
535 require(xlocal_coord_index < db());
536 require(xsource_dofs != 0);
538 require(xresult_dofs != 0);
545 dof_type derivative = xsource_dofs[xlocal_coord_index] - xsource_dofs[2];
547 for(
int i=0; i<3; ++i)
548 xresult_dofs[i] = derivative;
574 require(xcoord_dofs != 0);
575 require(xcoord_dofs_ub >= xdf*dl());
576 require(xdf == 2 || xdf == 3);
577 require(xlocal_coords != 0);
578 require(xlocal_coords_ub >= 2);
579 require(jacobian_values() != 0);
586 int local_coords_ct = 3;
588 basis_derivs_at_coord(xlocal_coords, local_coords_ct);
589 const value_type* derivs = basis_deriv_values();
594 for(
int i=0; i<local_coords_ct; ++i)
599 for(
int j=0; j<xdf; ++j)
606 for(
int k=0; k<dl(); ++k)
610 value_type deriv = derivs[local_coords_ct*k+i];
615 cout <<
"++++++++++++++++++++++++++++++++++" << endl;
616 cout <<
" deriv = " << deriv << endl;
617 cout <<
" coord = " << coord << endl;
618 cout <<
" sum = " << sum << endl;
619 cout <<
"++++++++++++++++++++++++++++++++++" << endl;
624 int ij = local_coords_ct*j+i;
625 _jacobian_values[ij] = sum;
675 require((0 <= xindex) && (xindex < dof_ct()));
676 require(xresult_ub >= db());
685 , {0.0, 1.0}, {0.0, 0.0}
688 xresult[0] = lcoords[xindex][0];
689 xresult[1] = lcoords[xindex][1];
693 ensure(in_standard_domain(xresult, xresult_ub));
707 require(xresult != 0);
708 require(xresult_ub >= db());
715 xresult[0] = one_third;
716 xresult[1] = one_third;
733 require(xresult != 0);
734 require(xresult_ub >= db());
788 xresult[0] = lcoords[xi][0];
789 xresult[1] = lcoords[xi][1];
806 require(precondition_of(center(xresult.
base(), xresult.
ub())));
810 edge_center(xi, xresult.
base(), xresult.
ub());
815 ensure(postcondition_of(edge_center(xresult.
base(), xresult.
ub())));
816 ensure(xresult.
ct() == db());
831 require(xlocal_coords != 0);
832 require(xlocal_coords_ub >= 2);
842 dof_type zero = 0.0 - 1000.0*numeric_limits<dof_type>::epsilon();
843 dof_type one = 1.0 + 1000.0*numeric_limits<dof_type>::epsilon();
846 bool result = (u >= zero) && (u <= one) && (v >= zero) && (v <= one - u);
873 require(xdofs_ub >= 6);
874 require(xglobal_coords != 0);
875 require(xglobal_coord_ub >= 2);
876 require(xlocal_coords != 0);
877 require(xlocal_coords_ub >= 2);
891 dof_type x_global = xglobal_coords[0];
892 dof_type y_global = xglobal_coords[1];
894 double a0 = x1*y2 - x2*y1;
895 double a1 = x2*y0 - x0*y2;
896 double a2 = x0*y1 - x1*y0;
906 double area_x_2 = a0 + a1 + a2;
908 double basis0 = (a0 + b0*x_global + c0*y_global) / area_x_2;
909 double basis1 = (a1 + b1*x_global + c1*y_global) / area_x_2;
914 #ifdef DIAGNOSTIC_OUTPUT 916 cout <<
"basis0 = " << basis0 << endl;
917 cout <<
"basis1 = " << basis1 << endl;
918 cout <<
"basis2 = " << 1.0 - (basis0 + basis1) << endl;
924 xlocal_coords[0] = basis0;
925 xlocal_coords[1] = basis1;
971 ensure(is_same_type(result));
984 require(is_ancestor_of(&xother));
1007 require(is_ancestor_of(&xother));
1015 ensure(invariant());
1036 result = result && linear_fcn_space::invariant();
1038 if(invariant_check())
1042 disable_invariant_check();
1044 invariance(basis_values() != 0);
1048 enable_invariant_check();
1064 require(xother != 0);
1070 bool result =
dynamic_cast<const linear_2d*
>(xother) != 0;
SHEAF_DLL_SPEC void sqrt(const sec_at0 &x0, sec_at0 &xresult, bool xauto_access)
Compute sqrt of x0 (sqrt(x0)) (pre-allocated version).
virtual void center(coord_type xresult[], size_type xresult_ub) const
The local coordinates at the center of the evaluator.
index_type ub() const
The upper bound on the storage array. The number of items current allocated in the storage array...
size_type ct() const
The number of items currently in use.
virtual bool is_ancestor_of(const any *xother) const
Conformance test; true if other conforms to this.
virtual int dl() const
The dimension of this function space.
virtual ~linear_2d()
Destructor.
sec_vd_dof_type dof_type
The type of degree of freedom.
virtual bool in_standard_domain(const dof_type xlocal_coords[], size_type xlocal_coords_ub) const
Return true if the specified local coordinates are in the "standard" domain; otherwise return false...
virtual void coord_at_value(const dof_type xdofs[], size_type xdofs_ub, const dof_type xglobal_coords[], size_type xglobal_coord_ub, dof_type xlocal_coords[], size_type xlocal_coords_ub) const
The local coordinates of a point at which the field has the value xvalue. The dofs are assumed to be ...
void gauss_point(pod_index_type xindex, coord_type xresult[], size_type xresult_ub)
The local coordinates of the gauss point with index xindex.
linear_2d()
Default constructor.
Abstract base class with useful features for all objects.
virtual void dxi_local(size_type xlocal_coord_index, const dof_type xsource_dofs[], size_type xsource_dofs_ub, dof_type xresult_dofs[], size_type xresult_dofs_ub) const
First partial derivative of this with respect to local coordinate xlocal_coord_index.
virtual linear_2d * clone() const
Virtual constructor, creates a new instance of the same type as this.
pointer_type base() const
The underlying storage array.
virtual int db() const
The base dimension; the dimension of the local coordinates (independent variable).
void set_ct(size_type xct)
Sets ct() == xct.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
void edge_center(pod_index_type xi, coord_type xresult[], size_type xresult_ub) const
The local cordinates of the xi-th edge.
chart_point_coord_type coord_type
The type of local coordinate; the scalar type for the local coordinate vector space.
vd_value_type value_type
The type of component in the value; the scalar type in the range vector space.
void jacobian(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf, const dof_type xlocal_coords[], size_type xlocal_coords_ub)
Jacobian matrix.
SHEAF_DLL_SPEC void fabs(const sec_at0 &x0, sec_at0 &xresult, bool xauto_access)
Compute fabs of x0 (fabs(x0)) (pre-allocated version).
An abstract local section evaluator; a map from {local coordinates x dofs} to section value...
value_type volume(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf)
Volume for specified coordinate dofs xcoord_dofs and fiber space dimension xdf.
void basis_derivs_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
Computes the value of the derivatives of each basis function at local coordinates xlocal_coord...
virtual linear_2d & operator=(const section_evaluator &xother)
Assignment operator.
A section evaluator using linear interpolation over a triangular 2D domain.
int_type pod_index_type
The plain old data index type.
virtual void integrate(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf, const dof_type xintegrands[], size_type xintegrands_ub, value_type xresult_integrals[], size_type xresult_integrals_ub)
Computes the value of the integral of the integrand array...
virtual void local_coordinates(pod_index_type xindex, coord_type xresult[], size_type xresult_ub) const
The local coordinates of the dof with local index xindex.
value_type jacobian_determinant(const dof_type xcoord_dofs[], size_type xcoord_dofs_ub, size_type xdf, const coord_type xlocal_coords[], size_type xlocal_coords_ub)
Determinant of Jacobian matrix (square)
An auto_block with a no-initialization initialization policy.
Namespace for the fiber_bundles component of the sheaf system.
virtual void basis_at_coord(const dof_type xlocal_coord[], size_type xlocal_coord_ub)
Computes the value of each basis function at local coordinates xlocal_coord.
virtual bool invariant() const
Class invariant.