ffc team mailing list archive
-
ffc team
-
Mailing list archive
-
Message #03667
Re: [Bug 511929] Re: Missing domain_type
On Tue, Feb 02, 2010 at 11:16:20AM +0100, Mehdi Nikbakht wrote:
> On Tue, 2010-02-02 at 10:50 +0100, Anders Logg wrote:
> > On Tue, Feb 02, 2010 at 10:42:23AM +0100, Mehdi Nikbakht wrote:
> > >
> > >
> > > On Tue, 2010-02-02 at 10:30 +0100, Anders Logg wrote:
> > > > I tried looking at this but I'm unsure how it should be
> > > > handled. Should a cell_integral class be generated or should a
> > > > surface_integral class be generated?
> > > >
> > >
> > > We handle terms related to surface integral inside a class derived from
> > > ufc::cell_integral. I have started working on updating ffcpum module
> > > which is built against standard ffc.
> > >
> > > Mehdi
> >
> > So a surface integral should just result in a standard cell integral
> > being generated? Then what is the point of having *dc? When the code
> > has been generated, you won't be able to tell which cell integrals
> > came from *dx and which came from *dc.
>
> Although we could have them in a separate class, we handle them inside
> cell_integral class to have compatibility with ufc interface.
>
> Note that having *dc helps us to compute the corresponding terms by
> using gauss points located on a surface.
>
> I don't see the point on being able to tell which cell integrals came
> from *dx and which one from *dc, we add all of them to the global
> element tensor.
My point is that if FFC should treat *dc in exactly the same way as
*dx, then you might as well just write *dx and we can remove the
"support" for *dc in FFC.
Or you could just write dc = dx in your form files.
--
Anders
> Mehdi
> >
>
> // This code conforms with the UFC specification version 1.0
> // and was automatically generated by FFC version 0.7.0.
> //
> // Warning: This code was generated with the option '-l dolfin'
> // and contains DOLFIN-specific wrappers that depend on DOLFIN.
>
> #ifndef __POISSON_H
> #define __POISSON_H
>
> #include <cmath>
> #include <algorithm>
> #include <stdexcept>
> #include <fstream>
> #include <boost/assign/list_of.hpp>
> #include <ufc.h>
> #include <pum/GenericPUM.h>
>
> /// This class defines the interface for a finite element.
>
> class poisson_0_finite_element_0_0: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_0_finite_element_0_0() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_0_finite_element_0_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 3;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[3][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[3][1] = {{1}, {1}, {1}};
> static const double D[3][1][1] = {{{1}}, {{1}}, {{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[1];
> vertex_values[2] = dof_values[2];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_0_finite_element_0_0();
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_0_finite_element_0_1: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_0_finite_element_0_1() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_0_finite_element_0_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 3;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[3][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[3][1] = {{1}, {1}, {1}};
> static const double D[3][1][1] = {{{1}}, {{1}}, {{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[1];
> vertex_values[2] = dof_values[2];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_0_finite_element_0_1();
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_0_finite_element_0: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_0_finite_element_0() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_0_finite_element_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 6;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 1;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 2;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> values[0] = 0;
> values[1] = 0;
>
> if (0 <= i && i <= 2)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> values[0] = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> if (3 <= i && i <= 5)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i - 3;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> values[1] = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 2*num_derivatives; j++)
> values[j] = 0;
>
> if (0 <= i && i <= 2)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> if (3 <= i && i <= 5)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i - 3;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[num_derivatives + row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[6][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}, {{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[6][1] = {{1}, {1}, {1}, {1}, {1}, {1}};
> static const double D[6][1][2] = {{{1, 0}}, {{1, 0}}, {{1, 0}}, {{0, 1}}, {{0, 1}}, {{0, 1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[2];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 2; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[2] = dof_values[1];
> vertex_values[4] = dof_values[2];
> // Evaluate at vertices and use affine mapping
> vertex_values[1] = dof_values[3];
> vertex_values[3] = dof_values[4];
> vertex_values[5] = dof_values[5];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 2;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> switch ( i )
> {
> case 0:
> return new poisson_0_finite_element_0_0();
> break;
> case 1:
> return new poisson_0_finite_element_0_1();
> break;
> }
> return 0;
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_0_finite_element_1_0: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_0_finite_element_1_0() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_0_finite_element_1_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 3;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[3][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[3][1] = {{1}, {1}, {1}};
> static const double D[3][1][1] = {{{1}}, {{1}}, {{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[1];
> vertex_values[2] = dof_values[2];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_0_finite_element_1_0();
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_0_finite_element_1_1: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_0_finite_element_1_1() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_0_finite_element_1_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 3;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[3][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[3][1] = {{1}, {1}, {1}};
> static const double D[3][1][1] = {{{1}}, {{1}}, {{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[1];
> vertex_values[2] = dof_values[2];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_0_finite_element_1_1();
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_0_finite_element_1: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_0_finite_element_1() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_0_finite_element_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 6;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 1;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 2;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> values[0] = 0;
> values[1] = 0;
>
> if (0 <= i && i <= 2)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> values[0] = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> if (3 <= i && i <= 5)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i - 3;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> values[1] = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 2*num_derivatives; j++)
> values[j] = 0;
>
> if (0 <= i && i <= 2)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> if (3 <= i && i <= 5)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i - 3;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[num_derivatives + row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[6][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}, {{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[6][1] = {{1}, {1}, {1}, {1}, {1}, {1}};
> static const double D[6][1][2] = {{{1, 0}}, {{1, 0}}, {{1, 0}}, {{0, 1}}, {{0, 1}}, {{0, 1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[2];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 2; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[2] = dof_values[1];
> vertex_values[4] = dof_values[2];
> // Evaluate at vertices and use affine mapping
> vertex_values[1] = dof_values[3];
> vertex_values[3] = dof_values[4];
> vertex_values[5] = dof_values[5];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 2;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> switch ( i )
> {
> case 0:
> return new poisson_0_finite_element_1_0();
> break;
> case 1:
> return new poisson_0_finite_element_1_1();
> break;
> }
> return 0;
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_0_finite_element_2: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_0_finite_element_2() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_0_finite_element_2()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Discontinuous Lagrange', Cell('triangle', 1, Space(2)), 0)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 1;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
>
> // Table(s) of coefficients
> static const double coefficients0[1][1] = \
> {{1.41421356237309}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
>
> // Table(s) of coefficients
> static const double coefficients0[1][1] = \
> {{1.41421356237309}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[1][1] = \
> {{0}};
>
> static const double dmats1[1][1] = \
> {{0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[1][1][2] = {{{0.333333333333333, 0.333333333333333}}};
> static const double W[1][1] = {{1}};
> static const double D[1][1][1] = {{{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[0];
> vertex_values[2] = dof_values[0];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_0_finite_element_2();
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_0_finite_element_3: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_0_finite_element_3() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_0_finite_element_3()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 3;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[3][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[3][1] = {{1}, {1}, {1}};
> static const double D[3][1][1] = {{{1}}, {{1}}, {{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[1];
> vertex_values[2] = dof_values[2];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_0_finite_element_3();
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_0_dof_map_0_0: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
>
>
> public:
>
> /// Constructor
> poisson_0_dof_map_0_0() :ufc::dof_map()
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_0_dof_map_0_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[0];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension ;
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 3;
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 3;
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 2;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[0][0];
> dofs[1] = c.entity_indices[0][1];
> dofs[2] = c.entity_indices[0][2];
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> return new poisson_0_dof_map_0_0();
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_0_dof_map_0_1: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
> const std::vector<const pum::GenericPUM*>& pums;
>
> public:
>
> /// Constructor
> poisson_0_dof_map_0_1(const std::vector<const pum::GenericPUM*>& pums) :ufc::dof_map(), pums(pums)
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_0_dof_map_0_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = 0;
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension + pums[0]->enriched_global_dimension();
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return pums[0]->enriched_local_dimension(c);
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return pums[0]->enriched_max_local_dimension();
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 2;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> // Generate code for tabulating extra degrees of freedom.
> unsigned int local_offset = 0;
> unsigned int global_offset = 0;
>
> // Calculate local-to-global mapping for the enriched dofs related to the discontinuous field 0
> pums[0]->tabulate_enriched_dofs(dofs, c, local_offset, global_offset);
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> const std::vector<const pum::GenericPUM*>& p0 = boost::assign::list_of(pums[0]);
>
> return new poisson_0_dof_map_0_1(p0);
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_0_dof_map_0: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
> const std::vector<const pum::GenericPUM*>& pums;
>
> public:
>
> /// Constructor
> poisson_0_dof_map_0(const std::vector<const pum::GenericPUM*>& pums) :ufc::dof_map(), pums(pums)
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_0_dof_map_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[0];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension + pums[0]->enriched_global_dimension();
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 3 + pums[0]->enriched_local_dimension(c);
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 3 + pums[0]->enriched_max_local_dimension();
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 4;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[0][0];
> dofs[1] = c.entity_indices[0][1];
> dofs[2] = c.entity_indices[0][2];\
>
> // Generate code for tabulating extra degrees of freedom.
> unsigned int local_offset = 3;
> unsigned int global_offset = m.num_entities[0];
>
> // Calculate local-to-global mapping for the enriched dofs related to the discontinuous field 0
> pums[0]->tabulate_enriched_dofs(dofs, c, local_offset, global_offset);
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> dofs[2] = 4;
> dofs[3] = 5;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> dofs[2] = 3;
> dofs[3] = 5;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> dofs[2] = 3;
> dofs[3] = 4;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> coordinates[3][0] = x[0][0];
> coordinates[3][1] = x[0][1];
> coordinates[4][0] = x[1][0];
> coordinates[4][1] = x[1][1];
> coordinates[5][0] = x[2][0];
> coordinates[5][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 2;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> const std::vector<const pum::GenericPUM*>& p1 = boost::assign::list_of(pums[0]);
>
> switch ( i )
> {
> case 0:
> return new poisson_0_dof_map_0_0();
> break;
> case 1:
> return new poisson_0_dof_map_0_1(p1);
> break;
> }
> return 0;
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_0_dof_map_1_0: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
>
>
> public:
>
> /// Constructor
> poisson_0_dof_map_1_0() :ufc::dof_map()
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_0_dof_map_1_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[0];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension ;
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 3;
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 3;
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 2;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[0][0];
> dofs[1] = c.entity_indices[0][1];
> dofs[2] = c.entity_indices[0][2];
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> return new poisson_0_dof_map_1_0();
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_0_dof_map_1_1: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
> const std::vector<const pum::GenericPUM*>& pums;
>
> public:
>
> /// Constructor
> poisson_0_dof_map_1_1(const std::vector<const pum::GenericPUM*>& pums) :ufc::dof_map(), pums(pums)
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_0_dof_map_1_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = 0;
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension + pums[0]->enriched_global_dimension();
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return pums[0]->enriched_local_dimension(c);
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return pums[0]->enriched_max_local_dimension();
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 2;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> // Generate code for tabulating extra degrees of freedom.
> unsigned int local_offset = 0;
> unsigned int global_offset = 0;
>
> // Calculate local-to-global mapping for the enriched dofs related to the discontinuous field 0
> pums[0]->tabulate_enriched_dofs(dofs, c, local_offset, global_offset);
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> const std::vector<const pum::GenericPUM*>& p0 = boost::assign::list_of(pums[0]);
>
> return new poisson_0_dof_map_1_1(p0);
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_0_dof_map_1: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
> const std::vector<const pum::GenericPUM*>& pums;
>
> public:
>
> /// Constructor
> poisson_0_dof_map_1(const std::vector<const pum::GenericPUM*>& pums) :ufc::dof_map(), pums(pums)
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_0_dof_map_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[0];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension + pums[0]->enriched_global_dimension();
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 3 + pums[0]->enriched_local_dimension(c);
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 3 + pums[0]->enriched_max_local_dimension();
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 4;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[0][0];
> dofs[1] = c.entity_indices[0][1];
> dofs[2] = c.entity_indices[0][2];\
>
> // Generate code for tabulating extra degrees of freedom.
> unsigned int local_offset = 3;
> unsigned int global_offset = m.num_entities[0];
>
> // Calculate local-to-global mapping for the enriched dofs related to the discontinuous field 0
> pums[0]->tabulate_enriched_dofs(dofs, c, local_offset, global_offset);
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> dofs[2] = 4;
> dofs[3] = 5;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> dofs[2] = 3;
> dofs[3] = 5;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> dofs[2] = 3;
> dofs[3] = 4;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> coordinates[3][0] = x[0][0];
> coordinates[3][1] = x[0][1];
> coordinates[4][0] = x[1][0];
> coordinates[4][1] = x[1][1];
> coordinates[5][0] = x[2][0];
> coordinates[5][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 2;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> const std::vector<const pum::GenericPUM*>& p1 = boost::assign::list_of(pums[0]);
>
> switch ( i )
> {
> case 0:
> return new poisson_0_dof_map_1_0();
> break;
> case 1:
> return new poisson_0_dof_map_1_1(p1);
> break;
> }
> return 0;
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_0_dof_map_2: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
>
>
> public:
>
> /// Constructor
> poisson_0_dof_map_2() :ufc::dof_map()
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_0_dof_map_2()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Discontinuous Lagrange', Cell('triangle', 1, Space(2)), 0)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return false;
> break;
> case 1:
> return false;
> break;
> case 2:
> return true;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[2];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension ;
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 1;
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 1;
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 0;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[2][0];
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
>
> break;
> case 1:
>
> break;
> case 2:
>
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = 0.333333333333333*x[0][0] + 0.333333333333333*x[1][0] + 0.333333333333333*x[2][0];
> coordinates[0][1] = 0.333333333333333*x[0][1] + 0.333333333333333*x[1][1] + 0.333333333333333*x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> return new poisson_0_dof_map_2();
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_0_dof_map_3: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
>
>
> public:
>
> /// Constructor
> poisson_0_dof_map_3() :ufc::dof_map()
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_0_dof_map_3()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[0];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension ;
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 3;
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 3;
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 2;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[0][0];
> dofs[1] = c.entity_indices[0][1];
> dofs[2] = c.entity_indices[0][2];
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> return new poisson_0_dof_map_3();
> }
>
> };
>
> /// This class defines the interface for the tabulation of the cell
> /// tensor corresponding to the local contribution to a form from
> /// the integral over a cell.
>
> class poisson_0_cell_integral_0_quadrature: public ufc::cell_integral
> {
>
> const std::vector<const pum::GenericPUM*>& pums;
> mutable std::vector <double> Aa;
> mutable std::vector <double> Af;
>
>
>
> /// Tabulate the regular entities of tensor for the contribution from a local cell
> virtual void tabulate_regular_tensor(double* A,
> const double * const * w,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * x = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = x[1][0] - x[0][0];
> const double J_01 = x[2][0] - x[0][0];
> const double J_10 = x[1][1] - x[0][1];
> const double J_11 = x[2][1] - x[0][1];
>
> // Compute determinant of Jacobian
> double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
> const double Jinv_00 = J_11 / detJ;
> const double Jinv_01 = -J_01 / detJ;
> const double Jinv_10 = -J_10 / detJ;
> const double Jinv_11 = J_00 / detJ;
>
> // Set scale factor
> const double det = std::abs(detJ);
>
>
> // Array of quadrature weights
> static const double W1 = 0.5;
> // Quadrature points on the UFC reference element: (0.333333333333333, 0.333333333333333)
>
> // Value of basis functions at quadrature points.
> static const double FE0[1][3] = \
> {{0.333333333333333, 0.333333333333333, 0.333333333333333}};
>
> static const double FE1_C0_D01[1][6] = \
> {{-1, 0, 1, 0, 0, 0}};
>
> static const double FE1_C0_D10[1][6] = \
> {{-1, 1, 0, 0, 0, 0}};
>
> static const double FE1_C1_D01[1][6] = \
> {{0, 0, 0, -1, 0, 1}};
>
> static const double FE1_C1_D10[1][6] = \
> {{0, 0, 0, -1, 1, 0}};
>
>
> // local dimension of the current cell
> unsigned int offset = 3 + pums[0]->enriched_local_dimension(c);
>
>
> // Remove regular local dimension to obtain number of enriched dofs
> offset -= 3;
>
> // Compute element tensor using UFL quadrature representation
> // Optimisations: ('simplify expressions', False), ('ignore zero tables', False), ('non zero columns', False), ('remove zero terms', False), ('ignore ones', False)
> // Total number of operations to compute element tensor: 1266
>
> // Loop quadrature points for integral
> // Number of operations to compute element tensor for following IP loop = 1266
> // Only 1 integration point, omitting IP loop.
>
> // Function declarations
> double F0 = 0;
>
> // Total number of operations to compute function values = 6
> for (unsigned int r = 0; r < 3; r++)
> {
> F0 += FE0[0][r]*w[1][r];
> }// end loop over 'r'
> unsigned int m = 0;
>
> // Number of operations for primary indices = 1260
> for (unsigned int j = 0; j < 6; j++)
> {
> for (unsigned int k = 0; k < 6; k++)
> {
> if ((((0 <= j && j < 3)) && ((0 <= k && k < 3))))
> {
> // Number of operations to compute entry = 35
> A[m] += (((Jinv_00*FE1_C1_D10[0][j] + Jinv_10*FE1_C1_D01[0][j]) + (Jinv_00*FE1_C0_D10[0][j] + Jinv_10*FE1_C0_D01[0][j]))*((Jinv_00*FE1_C1_D10[0][k] + Jinv_10*FE1_C1_D01[0][k]) + (Jinv_00*FE1_C0_D10[0][k] + Jinv_10*FE1_C0_D01[0][k])) + ((Jinv_01*FE1_C0_D10[0][j] + Jinv_11*FE1_C0_D01[0][j]) + (Jinv_01*FE1_C1_D10[0][j] + Jinv_11*FE1_C1_D01[0][j]))*((Jinv_01*FE1_C1_D10[0][k] + Jinv_11*FE1_C1_D01[0][k]) + (Jinv_01*FE1_C0_D10[0][k] + Jinv_11*FE1_C0_D01[0][k])))*F0*W1*det;
>
> ++m;
> }
> }// end loop over 'k'
>
> // Offset the entries corresponding to enriched terms
> if ((((0 <= j && j < 3))))
> m += offset;
> }// end loop over 'j'
> }
>
> public:
>
> /// Constructor
> poisson_0_cell_integral_0_quadrature(const std::vector<const pum::GenericPUM*>& pums) : ufc::cell_integral(), pums(pums)
> {
> //Do nothing
> }
>
> /// Destructor
> virtual ~poisson_0_cell_integral_0_quadrature()
> {
> //Do nothing
> }
>
>
> /// Tabulate the tensor for the contribution from a local cell
> virtual void tabulate_tensor(double* A,
> const double * const * w,
> const ufc::cell& c) const
> {
> // Tabulate regular entires of element tensor
> tabulate_regular_tensor(A, w, c);
>
> // local dimension of the current cell
> unsigned int num_entries = 3 + pums[0]->enriched_local_dimension(c);
>
>
> // Remove regular local dimension to obtain number of enriched dofs
> num_entries -= 3;
>
> if (num_entries == 0)
> return;
>
>
> // Extract vertex coordinates
> const double * const * x = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = x[1][0] - x[0][0];
> const double J_01 = x[2][0] - x[0][0];
> const double J_10 = x[1][1] - x[0][1];
> const double J_11 = x[2][1] - x[0][1];
>
> // Compute determinant of Jacobian
> double detJ = J_00*J_11 - J_01*J_10;
>
>
> // Set scale factor
> const double det = std::abs(detJ);
>
> // FIXME: It will crash for multiple discontinuities, if we don't have at least one cell which all dofs are enriched
> const unsigned int min_entries = 36;
> const unsigned int _num_entries = std::max(num_entries*num_entries, min_entries);
>
> // Resizing and reseting auxiliary tensors
> Aa.resize(_num_entries);
> std::fill(Aa.begin(), Aa.end(), 0.0);
>
> // Define an array to save current quadrature point
> double coordinate[2];
>
> // Define ufc::finite_element object(s) to evalaute shape functions or their derivatives on runtime
> poisson_0_finite_element_3 element_0;
> poisson_0_finite_element_0 element_1;
>
> // Array of quadrature weights
> static const double W1[1] = {0.5};
>
>
> // Array of quadrature points
> static const double P1[2] = \
> {0.333333333333333, 0.333333333333333};
>
> // Define vectors for quadrature points and weights(note that the sizes are determined in compile time)
> std::vector <double> Wn1;
> std::vector <double> Pn1;
>
>
> // Check whether there is any need to use modified integration scheme
> if ((pums[0]->modified_quadrature(c)))
> {
>
> const std::vector<double> weight1(W1, W1 + 1);
> const std::vector<double> point1(P1, P1 + 2);
>
> ConstQuadratureRule standard_gauss = std::make_pair(point1, weight1);
> QuadratureRule modified_gauss;
>
> pums[0]->cell_quadrature_rule(modified_gauss, standard_gauss, c);
>
> Pn1 = modified_gauss.first;
> Wn1 = modified_gauss.second;
>
> }
> else
> {
> // Map quadrature points from the reference cell to the physical cell
> Wn1.resize(1);;
> Pn1.resize(2);;
>
>
> for (unsigned int i = 0; i < 1; i++)
> {
> Wn1[i] = W1[i];
> for (unsigned int j = 0; j < 2; j++)
> Pn1[2*i + j] = x[0][j]*(1.0 - P1[2*i] - P1[2*i + 1]) + x[1][j]*P1[2*i + 1] + x[2][j]*P1[2*i];
> }
> }
>
>
> // Return the values of enriched function at the quadrature points
> std::vector<double> enriched_values_1;
> pums[0]->tabulate_enriched_basis(enriched_values_1, Pn1, c);
>
> // Define auxilary indices: m, n
> unsigned int m = 0;
> unsigned int n = 0;
>
>
> // Loop over new quadrature points for integral
> for (unsigned int ip = 0; ip < Wn1.size(); ip++)
> {
> // Evalaute tables and entries in the element tensor, if the enhanced value at this quadrature point is non-zero
> if (enriched_values_1[ip] != 0)
> {
> // Pick up the coordinates of the current quadrature point
> coordinate[0] = Pn1[2*ip];
> coordinate[1] = Pn1[2*ip + 1];
>
>
> // Creating a table to save the values of shape functions at the current guass point for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)
> double value_0[1];
> double table_0_D0[3][1];
> for (unsigned int j = 0; j < 3; j++)
> {
> element_0.evaluate_basis(j, value_0, coordinate, c);
> for (unsigned int k = 0; k < 1; k++)
> table_0_D0[j][k] = value_0[k];
> }
>
>
> // Creating a table to save the values of shape functions at the current guass point for MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })
> double value_1[2];
> double table_1_D0[6][2];
> for (unsigned int j = 0; j < 6; j++)
> {
> element_1.evaluate_basis(j, value_1, coordinate, c);
> for (unsigned int k = 0; k < 2; k++)
> table_1_D0[j][k] = value_1[k];
> }
>
>
> // Creating a table to save the values of derivatives order 1 at the current guass point for MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })
> double value_2[4];
> double table_1_D1[6][4];
> for (unsigned int j = 0; j < 6; j++)
> {
> element_1.evaluate_basis_derivatives(j, 1, value_2, coordinate, c);
> for (unsigned int k = 0; k < 4; k++)
> table_1_D1[j][k] = value_2[k];
> }
>
> // Function declarations
> double F0 = 0;
>
> // Total number of operations to compute function values = 6
> for (unsigned int r = 0; r < 3; r++)
> {
> F0 += table_0_D0[r][0]*w[1][r];
> }// end loop over 'r'
>
> // Number of operations for primary indices = 396
> for (unsigned int j = 0; j < 6; j++)
> {
> for (unsigned int k = 0; k < 6; k++)
> {
> if (!(((0 <= j && j < 3)) && ((0 <= k && k < 3))))
> {
> // Move the indices of discontinuous spaces to the end of mixed space
> if ((0 <= j && j < 3) && (3 <= k && k < 6))
> {
> m = j;
> n = k;
> }
> else if ((3 <= j && j < 6) && (0 <= k && k < 3))
> {
> m = j;
> n = k;
> }
> else if ((3 <= j && j < 6) && (3 <= k && k < 6))
> {
> m = j;
> n = k;
> }
> // Number of operations to compute entry = 11
> Aa[m*6 + n] += ((table_1_D1[j][0] + table_1_D1[j][2])*(table_1_D1[k][2] + table_1_D1[k][0]) + (table_1_D1[j][3] + table_1_D1[j][1])*(table_1_D1[k][3] + table_1_D1[k][1]))*F0*Wn1[ip]*det;
> }// end check for enriched entiries
> }// end loop over 'k'
> }// end loop over 'j'
> }
> }// end loop over 'ip'
>
> // Check whether the current cell is intersected by discontinuity
> if ((pums[0]->modified_quadrature(c)))
> {
> // Define ufc::finite_element object(s) to evalaute shape functions or their derivatives on runtime
> poisson_0_finite_element_2 element_0;
> poisson_0_finite_element_0 element_1;
>
> // Array of quadrature weights
> static const double W4[2] = {0.5, 0.5};
>
>
> // Array of quadrature points
> static const double P4[2] = \
> {0.211324865405187,
> 0.788675134594813};
>
> // Define vectors for quadrature points and weights
> std::vector <double> Wn4(2);
> std::vector <double> Pn4(4);
>
>
> const std::vector<double> weight4(W4, W4 + 2);
> const std::vector<double> point4(P4, P4 + 2);
>
> ConstQuadratureRule standard_gauss = std::make_pair(point4, weight4);
> QuadratureRule modified_gauss;
>
> pums[0]->surface_quadrature(modified_gauss, standard_gauss, c);
>
> Pn4 = modified_gauss.first;
> Wn4 = modified_gauss.second;
>
>
> // Define and initialize the determinant of Jacobian
> const double det = 1.0;
>
> // Loop over new quadrature points for integral
> for (unsigned int ip = 0; ip < Wn4.size(); ip++)
> {
> // Pick up the coordinates of the current quadrature point
> coordinate[0] = Pn4[2*ip];
> coordinate[1] = Pn4[2*ip + 1];
>
>
> // Creating a table to save the values of shape functions at the current guass point for MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })
> double value_0[2];
> double table_1_D0[6][2];
> for (unsigned int j = 0; j < 6; j++)
> {
> element_1.evaluate_basis(j, value_0, coordinate, c);
> for (unsigned int k = 0; k < 2; k++)
> table_1_D0[j][k] = value_0[k];
> }
>
>
> // Creating a table to save the values of shape functions at the current guass point for FiniteElement('Discontinuous Lagrange', Cell('triangle', 1, Space(2)), 0)
> double value_1[1];
> double table_0_D0[1][1];
> for (unsigned int j = 0; j < 1; j++)
> {
> element_0.evaluate_basis(j, value_1, coordinate, c);
> for (unsigned int k = 0; k < 1; k++)
> table_0_D0[j][k] = value_1[k];
> }
>
> // Number of operations for primary indices = 180
> for (unsigned int j = 0; j < 6; j++)
> {
> for (unsigned int k = 0; k < 6; k++)
> {
> if (!(((0 <= j && j < 3)) || ((0 <= k && k < 3))))
> {
> // Move the indices of discontinuous spaces to the end of mixed space
> if ((3 <= j && j < 6) && (3 <= k && k < 6))
> {
> m = j;
> n = k;
> }
> // Number of operations to compute entry = 5
> Aa[m*6 + n] += table_1_D0[j][1]*table_1_D0[k][1]*w[0][0]*Wn4[ip]*det;
> }// end check for enriched entiries
> }// end loop over 'k'
> }// end loop over 'j'
> }// end loop over 'ip'
> }
>
>
> // Pick up entries from the total element tensor for the nodes active in the enrichment
>
> // Determine a vector that contains the local numbering of enriched degrees of freedom in ufc::cell c for the field 0
> std::vector<unsigned int> active_dofs_0;
> pums[0]->tabulate_enriched_local_dofs(active_dofs_0, c);
> std::vector<unsigned int>::iterator it_0_0, it_0_1;
>
>
> m = 0;
> for (unsigned int j = 0; j < 6; j++)
> for (unsigned int k = 0; k < 6; k++)
> if ((0 <= j && j < 3) && (0 <= k && k < 3))
> ++m;
> else
> {
> it_0_0 = find(active_dofs_0.begin(), active_dofs_0.end(), j - 3);
> it_0_1 = find(active_dofs_0.begin(), active_dofs_0.end(), k - 3);
>
>
> // Check whether the entry is coressponding to the active enriched node
> if (it_0_0 != active_dofs_0.end() || it_0_1 != active_dofs_0.end())
> if (((0 <= j && j < 3)) || ((0 <= k && k < 3)) || (it_0_0 != active_dofs_0.end() && it_0_1 != active_dofs_0.end()))
> {
> A[m] = Aa[j*6 + k];
> ++m;
> }
> }
> }
>
> };
>
> /// This class defines the interface for the tabulation of the cell
> /// tensor corresponding to the local contribution to a form from
> /// the integral over a cell.
>
> class poisson_0_cell_integral_0: public ufc::cell_integral
> {
> private:
>
> poisson_0_cell_integral_0_quadrature* integral_0_quadrature;
>
>
> const std::vector<const pum::GenericPUM*>& pums;
> mutable std::vector <double> Aa;
> mutable std::vector <double> Af;
>
>
>
> /// Tabulate the regular entities of tensor for the contribution from a local cell
> virtual void tabulate_regular_tensor(double* A,
> const double * const * w,
> const ufc::cell& c) const
> {
> // Do nothing
> }
>
> public:
>
> /// Constructor
> poisson_0_cell_integral_0(const std::vector<const pum::GenericPUM*>& pums) : ufc::cell_integral(), pums(pums)
> {
> integral_0_quadrature = new poisson_0_cell_integral_0_quadrature(pums);
> }
>
> /// Destructor
> virtual ~poisson_0_cell_integral_0()
> {
> delete integral_0_quadrature;
> }
>
>
> /// Tabulate the tensor for the contribution from a local cell
> virtual void tabulate_tensor(double* A,
> const double * const * w,
> const ufc::cell& c) const
> {
> const unsigned int num_entries = (3 + pums[0]->enriched_local_dimension(c))*(3 + pums[0]->enriched_local_dimension(c));
>
> for (unsigned int j = 0; j < num_entries; j++)
> A[j] = 0;
>
> // Add all contributions to element tensor
> integral_0_quadrature->tabulate_tensor(A, w, c);
> }
>
> };
>
> /// This class defines the interface for the assembly of the global
> /// tensor corresponding to a form with r + n arguments, that is, a
> /// mapping
> ///
> /// a : V1 x V2 x ... Vr x W1 x W2 x ... x Wn -> R
> ///
> /// with arguments v1, v2, ..., vr, w1, w2, ..., wn. The rank r
> /// global tensor A is defined by
> ///
> /// A = a(V1, V2, ..., Vr, w1, w2, ..., wn),
> ///
> /// where each argument Vj represents the application to the
> /// sequence of basis functions of Vj and w1, w2, ..., wn are given
> /// fixed functions (coefficients).
>
> class poisson_form_0: public ufc::form
> {
> const std::vector<const pum::GenericPUM*>& pums;
> public:
>
> /// Constructor
> poisson_form_0(const std::vector<const pum::GenericPUM*>& pums) : ufc::form(), pums(pums)
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_form_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the form
> virtual const char* signature() const
> {
> return "Form([Integral(Product(Function(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), 1), IndexSum(Product(Indexed(ComponentTensor(Sum(Indexed(SpatialDerivative(BasisFunction(MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) }), 0), MultiIndex((Index(0),), {Index(0): 2})), MultiIndex((FixedIndex(0),), {})), Indexed(SpatialDerivative(BasisFunction(MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) }), 0), MultiIndex((Index(0),), {Index(0): 2})), MultiIndex((FixedIndex(1),), {}))), MultiIndex((Index(0),), {Index(0): 2})), MultiIndex((Index(1),), {Index(1): 2})), Indexed(ComponentTensor(Sum(Indexed(SpatialDerivative(BasisFunction(MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) }), 1), MultiIndex((Index(2),), {Index(2): 2})), MultiIndex((FixedIndex(0),), {})), Indexed(SpatialDerivative(BasisFunction(MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) }), 1), MultiIndex((Index(2),), {Index(2): 2})), MultiIndex((FixedIndex(1),), {}))), MultiIndex((Index(2),), {Index(2): 2})), MultiIndex((Index(1),), {Index(1): 2}))), MultiIndex((Index(1),), {Index(1): 2}))), Measure('cell', 0, None)), Integral(Product(Constant(Cell('triangle', 1, Space(2)), 0), Product(Indexed(BasisFunction(MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) }), 0), MultiIndex((FixedIndex(1),), {FixedIndex(1): 2})), Indexed(BasisFunction(MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) }), 1), MultiIndex((FixedIndex(1),), {FixedIndex(1): 2})))), Measure('surface', 0, None))])";
> }
>
> /// Return the rank of the global tensor (r)
> virtual unsigned int rank() const
> {
> return 2;
> }
>
> /// Return the number of coefficients (n)
> virtual unsigned int num_coefficients() const
> {
> return 2;
> }
>
> /// Return the number of cell integrals
> virtual unsigned int num_cell_integrals() const
> {
> return 1;
> }
>
> /// Return the number of exterior facet integrals
> virtual unsigned int num_exterior_facet_integrals() const
> {
> return 0;
> }
>
> /// Return the number of interior facet integrals
> virtual unsigned int num_interior_facet_integrals() const
> {
> return 0;
> }
>
> /// Create a new finite element for argument function i
> virtual ufc::finite_element* create_finite_element(unsigned int i) const
> {
> switch ( i )
> {
> case 0:
> return new poisson_0_finite_element_0();
> break;
> case 1:
> return new poisson_0_finite_element_1();
> break;
> case 2:
> return new poisson_0_finite_element_2();
> break;
> case 3:
> return new poisson_0_finite_element_3();
> break;
> }
> return 0;
> }
>
> /// Create a new dof map for argument function i
> virtual ufc::dof_map* create_dof_map(unsigned int i) const
> {
> switch ( i )
> {
> case 0:
> return new poisson_0_dof_map_0(pums);
> break;
> case 1:
> return new poisson_0_dof_map_1(pums);
> break;
> case 2:
> return new poisson_0_dof_map_2();
> break;
> case 3:
> return new poisson_0_dof_map_3();
> break;
> }
> return 0;
> }
>
> /// Create a new cell integral on sub domain i
> virtual ufc::cell_integral* create_cell_integral(unsigned int i) const
> {
> return new poisson_0_cell_integral_0(pums);
> }
>
> /// Create a new exterior facet integral on sub domain i
> virtual ufc::exterior_facet_integral* create_exterior_facet_integral(unsigned int i) const
> {
> return 0;
> }
>
> /// Create a new interior facet integral on sub domain i
> virtual ufc::interior_facet_integral* create_interior_facet_integral(unsigned int i) const
> {
> return 0;
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_auxiliary_0_finite_element_0: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_auxiliary_0_finite_element_0() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_auxiliary_0_finite_element_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 3;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[3][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[3][1] = {{1}, {1}, {1}};
> static const double D[3][1][1] = {{{1}}, {{1}}, {{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[1];
> vertex_values[2] = dof_values[2];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_auxiliary_0_finite_element_0();
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_auxiliary_0_dof_map_0: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
>
>
> public:
>
> /// Constructor
> poisson_auxiliary_0_dof_map_0() :ufc::dof_map()
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_auxiliary_0_dof_map_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[0];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension ;
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 3;
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 3;
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 2;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[0][0];
> dofs[1] = c.entity_indices[0][1];
> dofs[2] = c.entity_indices[0][2];
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> return new poisson_auxiliary_0_dof_map_0();
> }
>
> };
>
> /// This class defines the interface for the assembly of the global
> /// tensor corresponding to a form with r + n arguments, that is, a
> /// mapping
> ///
> /// a : V1 x V2 x ... Vr x W1 x W2 x ... x Wn -> R
> ///
> /// with arguments v1, v2, ..., vr, w1, w2, ..., wn. The rank r
> /// global tensor A is defined by
> ///
> /// A = a(V1, V2, ..., Vr, w1, w2, ..., wn),
> ///
> /// where each argument Vj represents the application to the
> /// sequence of basis functions of Vj and w1, w2, ..., wn are given
> /// fixed functions (coefficients).
>
> class poisson_auxiliary_form_0: public ufc::form
> {
> public:
>
> /// Constructor
> poisson_auxiliary_form_0() : ufc::form()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_auxiliary_form_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the form
> virtual const char* signature() const
> {
> return "Auxiliary ufc::form to initialize standard functions, apply boundary conditions and obtain ufc::dof_map objects for continuous space(required for PUM objects) for a form containing discontinuous spaces.";
> }
>
> /// Return the rank of the global tensor (r)
> virtual unsigned int rank() const
> {
> return 2;
> }
>
> /// Return the number of coefficients (n)
> virtual unsigned int num_coefficients() const
> {
> return 0;
> }
>
> /// Return the number of cell integrals
> virtual unsigned int num_cell_integrals() const
> {
> return 0;
> }
>
> /// Return the number of exterior facet integrals
> virtual unsigned int num_exterior_facet_integrals() const
> {
> return 0;
> }
>
> /// Return the number of interior facet integrals
> virtual unsigned int num_interior_facet_integrals() const
> {
> return 0;
> }
>
> /// Create a new finite element for argument function i
> virtual ufc::finite_element* create_finite_element(unsigned int i) const
> {
> switch ( i )
> {
> case 0:
> return new poisson_auxiliary_0_finite_element_0();
> break;
> case 1:
> return new poisson_auxiliary_0_finite_element_0();
> break;
> }
> return 0;
> }
>
> /// Create a new dof map for argument function i
> virtual ufc::dof_map* create_dof_map(unsigned int i) const
> {
> switch ( i )
> {
> case 0:
> return new poisson_auxiliary_0_dof_map_0();
> break;
> case 1:
> return new poisson_auxiliary_0_dof_map_0();
> break;
> }
> return 0;
> }
>
> /// Create a new cell integral on sub domain i
> virtual ufc::cell_integral* create_cell_integral(unsigned int i) const
> {
> return 0;
> }
>
> /// Create a new exterior facet integral on sub domain i
> virtual ufc::exterior_facet_integral* create_exterior_facet_integral(unsigned int i) const
> {
> return 0;
> }
>
> /// Create a new interior facet integral on sub domain i
> virtual ufc::interior_facet_integral* create_interior_facet_integral(unsigned int i) const
> {
> return 0;
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_1_finite_element_0_0: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_1_finite_element_0_0() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_1_finite_element_0_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 3;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[3][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[3][1] = {{1}, {1}, {1}};
> static const double D[3][1][1] = {{{1}}, {{1}}, {{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[1];
> vertex_values[2] = dof_values[2];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_1_finite_element_0_0();
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_1_finite_element_0_1: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_1_finite_element_0_1() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_1_finite_element_0_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 3;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[3][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[3][1] = {{1}, {1}, {1}};
> static const double D[3][1][1] = {{{1}}, {{1}}, {{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[1];
> vertex_values[2] = dof_values[2];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_1_finite_element_0_1();
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_1_finite_element_0: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_1_finite_element_0() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_1_finite_element_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 6;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 1;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 2;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> values[0] = 0;
> values[1] = 0;
>
> if (0 <= i && i <= 2)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> values[0] = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> if (3 <= i && i <= 5)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i - 3;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> values[1] = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 2*num_derivatives; j++)
> values[j] = 0;
>
> if (0 <= i && i <= 2)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> if (3 <= i && i <= 5)
> {
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i - 3;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[num_derivatives + row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[6][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}, {{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[6][1] = {{1}, {1}, {1}, {1}, {1}, {1}};
> static const double D[6][1][2] = {{{1, 0}}, {{1, 0}}, {{1, 0}}, {{0, 1}}, {{0, 1}}, {{0, 1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[2];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 2; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[2] = dof_values[1];
> vertex_values[4] = dof_values[2];
> // Evaluate at vertices and use affine mapping
> vertex_values[1] = dof_values[3];
> vertex_values[3] = dof_values[4];
> vertex_values[5] = dof_values[5];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 2;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> switch ( i )
> {
> case 0:
> return new poisson_1_finite_element_0_0();
> break;
> case 1:
> return new poisson_1_finite_element_0_1();
> break;
> }
> return 0;
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_1_finite_element_1: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_1_finite_element_1() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_1_finite_element_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 3;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[3][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[3][1] = {{1}, {1}, {1}};
> static const double D[3][1][1] = {{{1}}, {{1}}, {{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[1];
> vertex_values[2] = dof_values[2];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_1_finite_element_1();
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_1_finite_element_2: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_1_finite_element_2() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_1_finite_element_2()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 3;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[3][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[3][1] = {{1}, {1}, {1}};
> static const double D[3][1][1] = {{{1}}, {{1}}, {{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[1];
> vertex_values[2] = dof_values[2];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_1_finite_element_2();
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_1_dof_map_0_0: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
>
>
> public:
>
> /// Constructor
> poisson_1_dof_map_0_0() :ufc::dof_map()
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_1_dof_map_0_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[0];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension ;
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 3;
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 3;
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 2;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[0][0];
> dofs[1] = c.entity_indices[0][1];
> dofs[2] = c.entity_indices[0][2];
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> return new poisson_1_dof_map_0_0();
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_1_dof_map_0_1: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
> const std::vector<const pum::GenericPUM*>& pums;
>
> public:
>
> /// Constructor
> poisson_1_dof_map_0_1(const std::vector<const pum::GenericPUM*>& pums) :ufc::dof_map(), pums(pums)
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_1_dof_map_0_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = 0;
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension + pums[0]->enriched_global_dimension();
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return pums[0]->enriched_local_dimension(c);
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return pums[0]->enriched_max_local_dimension();
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 2;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> // Generate code for tabulating extra degrees of freedom.
> unsigned int local_offset = 0;
> unsigned int global_offset = 0;
>
> // Calculate local-to-global mapping for the enriched dofs related to the discontinuous field 0
> pums[0]->tabulate_enriched_dofs(dofs, c, local_offset, global_offset);
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> const std::vector<const pum::GenericPUM*>& p0 = boost::assign::list_of(pums[0]);
>
> return new poisson_1_dof_map_0_1(p0);
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_1_dof_map_0: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
> const std::vector<const pum::GenericPUM*>& pums;
>
> public:
>
> /// Constructor
> poisson_1_dof_map_0(const std::vector<const pum::GenericPUM*>& pums) :ufc::dof_map(), pums(pums)
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_1_dof_map_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[0];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension + pums[0]->enriched_global_dimension();
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 3 + pums[0]->enriched_local_dimension(c);
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 3 + pums[0]->enriched_max_local_dimension();
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 4;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[0][0];
> dofs[1] = c.entity_indices[0][1];
> dofs[2] = c.entity_indices[0][2];\
>
> // Generate code for tabulating extra degrees of freedom.
> unsigned int local_offset = 3;
> unsigned int global_offset = m.num_entities[0];
>
> // Calculate local-to-global mapping for the enriched dofs related to the discontinuous field 0
> pums[0]->tabulate_enriched_dofs(dofs, c, local_offset, global_offset);
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> dofs[2] = 4;
> dofs[3] = 5;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> dofs[2] = 3;
> dofs[3] = 5;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> dofs[2] = 3;
> dofs[3] = 4;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> coordinates[3][0] = x[0][0];
> coordinates[3][1] = x[0][1];
> coordinates[4][0] = x[1][0];
> coordinates[4][1] = x[1][1];
> coordinates[5][0] = x[2][0];
> coordinates[5][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 2;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> const std::vector<const pum::GenericPUM*>& p1 = boost::assign::list_of(pums[0]);
>
> switch ( i )
> {
> case 0:
> return new poisson_1_dof_map_0_0();
> break;
> case 1:
> return new poisson_1_dof_map_0_1(p1);
> break;
> }
> return 0;
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_1_dof_map_1: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
>
>
> public:
>
> /// Constructor
> poisson_1_dof_map_1() :ufc::dof_map()
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_1_dof_map_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[0];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension ;
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 3;
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 3;
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 2;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[0][0];
> dofs[1] = c.entity_indices[0][1];
> dofs[2] = c.entity_indices[0][2];
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> return new poisson_1_dof_map_1();
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_1_dof_map_2: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
>
>
> public:
>
> /// Constructor
> poisson_1_dof_map_2() :ufc::dof_map()
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_1_dof_map_2()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[0];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension ;
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 3;
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 3;
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 2;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[0][0];
> dofs[1] = c.entity_indices[0][1];
> dofs[2] = c.entity_indices[0][2];
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> return new poisson_1_dof_map_2();
> }
>
> };
>
> /// This class defines the interface for the tabulation of the cell
> /// tensor corresponding to the local contribution to a form from
> /// the integral over a cell.
>
> class poisson_1_cell_integral_0_quadrature: public ufc::cell_integral
> {
>
> const std::vector<const pum::GenericPUM*>& pums;
> mutable std::vector <double> Aa;
> mutable std::vector <double> Af;
>
>
>
> /// Tabulate the regular entities of tensor for the contribution from a local cell
> virtual void tabulate_regular_tensor(double* A,
> const double * const * w,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * x = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = x[1][0] - x[0][0];
> const double J_01 = x[2][0] - x[0][0];
> const double J_10 = x[1][1] - x[0][1];
> const double J_11 = x[2][1] - x[0][1];
>
> // Compute determinant of Jacobian
> double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Set scale factor
> const double det = std::abs(detJ);
>
>
> // Array of quadrature weights
> static const double W4[4] = {0.159020690871988, 0.0909793091280112, 0.159020690871988, 0.0909793091280112};
> // Quadrature points on the UFC reference element: (0.178558728263616, 0.155051025721682), (0.0750311102226081, 0.644948974278318), (0.666390246014701, 0.155051025721682), (0.280019915499074, 0.644948974278318)
>
> // Value of basis functions at quadrature points.
> static const double FE0[4][3] = \
> {{0.666390246014701, 0.178558728263616, 0.155051025721682},
> {0.280019915499074, 0.0750311102226081, 0.644948974278318},
> {0.178558728263616, 0.666390246014701, 0.155051025721682},
> {0.0750311102226081, 0.280019915499074, 0.644948974278318}};
>
> static const double FE1_C0[4][6] = \
> {{0.666390246014701, 0.178558728263616, 0.155051025721682, 0, 0, 0},
> {0.280019915499074, 0.0750311102226081, 0.644948974278318, 0, 0, 0},
> {0.178558728263616, 0.666390246014701, 0.155051025721682, 0, 0, 0},
> {0.0750311102226081, 0.280019915499074, 0.644948974278318, 0, 0, 0}};
>
> static const double FE1_C1[4][6] = \
> {{0, 0, 0, 0.666390246014701, 0.178558728263616, 0.155051025721682},
> {0, 0, 0, 0.280019915499074, 0.0750311102226081, 0.644948974278318},
> {0, 0, 0, 0.178558728263616, 0.666390246014701, 0.155051025721682},
> {0, 0, 0, 0.0750311102226081, 0.280019915499074, 0.644948974278318}};
>
>
> // local dimension of the current cell
> unsigned int offset = 3 + pums[0]->enriched_local_dimension(c);
>
>
> // Remove regular local dimension to obtain number of enriched dofs
> offset -= 3;
>
> // Compute element tensor using UFL quadrature representation
> // Optimisations: ('simplify expressions', False), ('ignore zero tables', False), ('non zero columns', False), ('remove zero terms', False), ('ignore ones', False)
> // Total number of operations to compute element tensor: 144
>
> // Loop quadrature points for integral
> // Number of operations to compute element tensor for following IP loop = 144
> for (unsigned int ip = 0; ip < 4; ip++)
> {
>
> // Function declarations
> double F0 = 0;
>
> // Total number of operations to compute function values = 6
> for (unsigned int r = 0; r < 3; r++)
> {
> F0 += FE0[ip][r]*w[0][r];
> }// end loop over 'r'
> unsigned int m = 0;
>
> // Number of operations for primary indices = 30
> for (unsigned int j = 0; j < 6; j++)
> {
> if ((((0 <= j && j < 3))))
> {
> // Number of operations to compute entry = 5
> A[m] += (FE1_C0[ip][j] + FE1_C1[ip][j])*F0*W4[ip]*det;
>
> ++m;
> }
> }// end loop over 'j'
> }// end loop over 'ip'
> }
>
> public:
>
> /// Constructor
> poisson_1_cell_integral_0_quadrature(const std::vector<const pum::GenericPUM*>& pums) : ufc::cell_integral(), pums(pums)
> {
> //Do nothing
> }
>
> /// Destructor
> virtual ~poisson_1_cell_integral_0_quadrature()
> {
> //Do nothing
> }
>
>
> /// Tabulate the tensor for the contribution from a local cell
> virtual void tabulate_tensor(double* A,
> const double * const * w,
> const ufc::cell& c) const
> {
> // Tabulate regular entires of element tensor
> tabulate_regular_tensor(A, w, c);
>
> // local dimension of the current cell
> unsigned int num_entries = 3 + pums[0]->enriched_local_dimension(c);
>
>
> // Remove regular local dimension to obtain number of enriched dofs
> num_entries -= 3;
>
> if (num_entries == 0)
> return;
>
>
> // Extract vertex coordinates
> const double * const * x = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = x[1][0] - x[0][0];
> const double J_01 = x[2][0] - x[0][0];
> const double J_10 = x[1][1] - x[0][1];
> const double J_11 = x[2][1] - x[0][1];
>
> // Compute determinant of Jacobian
> double detJ = J_00*J_11 - J_01*J_10;
>
>
> // Set scale factor
> const double det = std::abs(detJ);
>
> // FIXME: It will crash for multiple discontinuities, if we don't have at least one cell which all dofs are enriched
> const unsigned int min_entries = 6;
> const unsigned int _num_entries = std::max(num_entries, min_entries);
>
> // Resizing and reseting auxiliary tensors
> Aa.resize(_num_entries);
> std::fill(Aa.begin(), Aa.end(), 0.0);
>
> // Define an array to save current quadrature point
> double coordinate[2];
>
> // Define ufc::finite_element object(s) to evalaute shape functions or their derivatives on runtime
> poisson_1_finite_element_1 element_0;
> poisson_1_finite_element_0 element_1;
>
> // Array of quadrature weights
> static const double W4[4] = {0.159020690871988, 0.0909793091280112, 0.159020690871988, 0.0909793091280112};
>
>
> // Array of quadrature points
> static const double P4[8] = \
> {0.178558728263616, 0.155051025721682,
> 0.0750311102226081, 0.644948974278318,
> 0.666390246014701, 0.155051025721682,
> 0.280019915499074, 0.644948974278318};
>
> // Define vectors for quadrature points and weights(note that the sizes are determined in compile time)
> std::vector <double> Wn4;
> std::vector <double> Pn4;
>
>
> // Check whether there is any need to use modified integration scheme
> if ((pums[0]->modified_quadrature(c)))
> {
>
> const std::vector<double> weight4(W4, W4 + 4);
> const std::vector<double> point4(P4, P4 + 8);
>
> ConstQuadratureRule standard_gauss = std::make_pair(point4, weight4);
> QuadratureRule modified_gauss;
>
> pums[0]->cell_quadrature_rule(modified_gauss, standard_gauss, c);
>
> Pn4 = modified_gauss.first;
> Wn4 = modified_gauss.second;
>
> }
> else
> {
> // Map quadrature points from the reference cell to the physical cell
> Wn4.resize(4);;
> Pn4.resize(8);;
>
>
> for (unsigned int i = 0; i < 4; i++)
> {
> Wn4[i] = W4[i];
> for (unsigned int j = 0; j < 2; j++)
> Pn4[2*i + j] = x[0][j]*(1.0 - P4[2*i] - P4[2*i + 1]) + x[1][j]*P4[2*i + 1] + x[2][j]*P4[2*i];
> }
> }
>
>
> // Return the values of enriched function at the quadrature points
> std::vector<double> enriched_values_4;
> pums[0]->tabulate_enriched_basis(enriched_values_4, Pn4, c);
>
> // Define an auxilary index: m
> unsigned int m = 0;
>
>
> // Loop over new quadrature points for integral
> for (unsigned int ip = 0; ip < Wn4.size(); ip++)
> {
> // Evalaute tables and entries in the element tensor, if the enhanced value at this quadrature point is non-zero
> if (enriched_values_4[ip] != 0)
> {
> // Pick up the coordinates of the current quadrature point
> coordinate[0] = Pn4[2*ip];
> coordinate[1] = Pn4[2*ip + 1];
>
>
> // Creating a table to save the values of shape functions at the current guass point for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)
> double value_0[1];
> double table_0_D0[3][1];
> for (unsigned int j = 0; j < 3; j++)
> {
> element_0.evaluate_basis(j, value_0, coordinate, c);
> for (unsigned int k = 0; k < 1; k++)
> table_0_D0[j][k] = value_0[k];
> }
>
>
> // Creating a table to save the values of shape functions at the current guass point for MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })
> double value_1[2];
> double table_1_D0[6][2];
> for (unsigned int j = 0; j < 6; j++)
> {
> element_1.evaluate_basis(j, value_1, coordinate, c);
> for (unsigned int k = 0; k < 2; k++)
> table_1_D0[j][k] = value_1[k];
> }
>
> // Function declarations
> double F0 = 0;
>
> // Total number of operations to compute function values = 6
> for (unsigned int r = 0; r < 3; r++)
> {
> F0 += table_0_D0[r][0]*w[0][r];
> }// end loop over 'r'
>
> // Number of operations for primary indices = 30
> for (unsigned int j = 0; j < 6; j++)
> {
> if (!(((0 <= j && j < 3))))
> {
> // Move the indices of discontinuous spaces to the end of mixed space
> if ((3 <= j && j < 6))
> {
> m = j;
> }
> // Number of operations to compute entry = 5
> Aa[m] += (table_1_D0[j][0] + table_1_D0[j][1])*F0*Wn4[ip]*det;
> }// end check for enriched entiries
> }// end loop over 'j'
> }
> }// end loop over 'ip'
>
>
> // Pick up entries from the total element tensor for the nodes active in the enrichment
>
> // Determine a vector that contains the local numbering of enriched degrees of freedom in ufc::cell c for the field 0
> std::vector<unsigned int> active_dofs_0;
> pums[0]->tabulate_enriched_local_dofs(active_dofs_0, c);
> std::vector<unsigned int>::iterator it_0_0;
>
>
> m = 0;
> for (unsigned int j = 0; j < 6; j++)
> if ((0 <= j && j < 3))
> ++m;
> else
> {
> it_0_0 = find(active_dofs_0.begin(), active_dofs_0.end(), j - 3);
>
>
> // Check whether the entry is coressponding to the active enriched node
> if (it_0_0 != active_dofs_0.end())
> {
> A[m] = Aa[j];
> ++m;
> }
> }
> }
>
> };
>
> /// This class defines the interface for the tabulation of the cell
> /// tensor corresponding to the local contribution to a form from
> /// the integral over a cell.
>
> class poisson_1_cell_integral_0: public ufc::cell_integral
> {
> private:
>
> poisson_1_cell_integral_0_quadrature* integral_0_quadrature;
>
>
> const std::vector<const pum::GenericPUM*>& pums;
> mutable std::vector <double> Aa;
> mutable std::vector <double> Af;
>
>
>
> /// Tabulate the regular entities of tensor for the contribution from a local cell
> virtual void tabulate_regular_tensor(double* A,
> const double * const * w,
> const ufc::cell& c) const
> {
> // Do nothing
> }
>
> public:
>
> /// Constructor
> poisson_1_cell_integral_0(const std::vector<const pum::GenericPUM*>& pums) : ufc::cell_integral(), pums(pums)
> {
> integral_0_quadrature = new poisson_1_cell_integral_0_quadrature(pums);
> }
>
> /// Destructor
> virtual ~poisson_1_cell_integral_0()
> {
> delete integral_0_quadrature;
> }
>
>
> /// Tabulate the tensor for the contribution from a local cell
> virtual void tabulate_tensor(double* A,
> const double * const * w,
> const ufc::cell& c) const
> {
> const unsigned int num_entries = (3 + pums[0]->enriched_local_dimension(c));
>
> for (unsigned int j = 0; j < num_entries; j++)
> A[j] = 0;
>
> // Add all contributions to element tensor
> integral_0_quadrature->tabulate_tensor(A, w, c);
> }
>
> };
>
> /// This class defines the interface for the tabulation of the
> /// exterior facet tensor corresponding to the local contribution to
> /// a form from the integral over an exterior facet.
>
> class poisson_1_exterior_facet_integral_0_quadrature: public ufc::exterior_facet_integral
> {
>
> const std::vector<const pum::GenericPUM*>& pums;
> mutable std::vector <double> Aa;
> mutable std::vector <double> Af;
>
>
>
> /// Tabulate the regular entities of the tensor for the contribution from a local exterior facet
> virtual void tabulate_regular_tensor(double* A,
> const double * const * w,
> const ufc::cell& c,
> unsigned int facet) const
> {
> // Extract vertex coordinates
> const double * const * x = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
>
> // Compute determinant of Jacobian
>
> // Compute inverse of Jacobian
>
> // Vertices on edges
> static unsigned int edge_vertices[3][2] = {{1, 2}, {0, 2}, {0, 1}};
>
> // Get vertices
> const unsigned int v0 = edge_vertices[facet][0];
> const unsigned int v1 = edge_vertices[facet][1];
>
> // Compute scale factor (length of edge scaled by length of reference interval)
> const double dx0 = x[v1][0] - x[v0][0];
> const double dx1 = x[v1][1] - x[v0][1];
> const double det = std::sqrt(dx0*dx0 + dx1*dx1);
>
>
> // Compute facet normals from the facet scale factor constants
>
>
> // Array of quadrature weights
> static const double W2[2] = {0.5, 0.5};
> // Quadrature points on the UFC reference element: (0.211324865405187), (0.788675134594813)
>
> // Value of basis functions at quadrature points.
> static const double FE0_f0[2][3] = \
> {{0, 0.788675134594813, 0.211324865405187},
> {0, 0.211324865405187, 0.788675134594813}};
>
> static const double FE0_f1[2][3] = \
> {{0.788675134594813, 0, 0.211324865405187},
> {0.211324865405187, 0, 0.788675134594813}};
>
> static const double FE0_f2[2][3] = \
> {{0.788675134594813, 0.211324865405187, 0},
> {0.211324865405187, 0.788675134594813, 0}};
>
> static const double FE1_f0_C0[2][6] = \
> {{0, 0.788675134594813, 0.211324865405187, 0, 0, 0},
> {0, 0.211324865405187, 0.788675134594813, 0, 0, 0}};
>
> static const double FE1_f0_C1[2][6] = \
> {{0, 0, 0, 0, 0.788675134594813, 0.211324865405187},
> {0, 0, 0, 0, 0.211324865405187, 0.788675134594813}};
>
> static const double FE1_f1_C0[2][6] = \
> {{0.788675134594813, 0, 0.211324865405187, 0, 0, 0},
> {0.211324865405187, 0, 0.788675134594813, 0, 0, 0}};
>
> static const double FE1_f1_C1[2][6] = \
> {{0, 0, 0, 0.788675134594813, 0, 0.211324865405187},
> {0, 0, 0, 0.211324865405187, 0, 0.788675134594813}};
>
> static const double FE1_f2_C0[2][6] = \
> {{0.788675134594813, 0.211324865405187, 0, 0, 0, 0},
> {0.211324865405187, 0.788675134594813, 0, 0, 0, 0}};
>
> static const double FE1_f2_C1[2][6] = \
> {{0, 0, 0, 0.788675134594813, 0.211324865405187, 0},
> {0, 0, 0, 0.211324865405187, 0.788675134594813, 0}};
>
>
> // local dimension of the current cell
> unsigned int offset = 3 + pums[0]->enriched_local_dimension(c);
>
>
> // Remove regular local dimension to obtain number of enriched dofs
> offset -= 3;
>
> // Compute element tensor using UFL quadrature representation
> // Optimisations: ('simplify expressions', False), ('ignore zero tables', False), ('non zero columns', False), ('remove zero terms', False), ('ignore ones', False)
> switch ( facet )
> {
> case 0:
> {
> // Total number of operations to compute element tensor (from this point): 84
>
> // Loop quadrature points for integral
> // Number of operations to compute element tensor for following IP loop = 84
> for (unsigned int ip = 0; ip < 2; ip++)
> {
>
> // Function declarations
> double F0 = 0;
>
> // Total number of operations to compute function values = 6
> for (unsigned int r = 0; r < 3; r++)
> {
> F0 += FE0_f0[ip][r]*w[1][r];
> }// end loop over 'r'
> unsigned int m = 0;
>
> // Number of operations for primary indices = 36
> for (unsigned int j = 0; j < 6; j++)
> {
> if ((((0 <= j && j < 3))))
> {
> // Number of operations to compute entry = 6
> A[m] += (FE1_f0_C0[ip][j] + FE1_f0_C1[ip][j])*F0*-1*W2[ip]*det;
>
> ++m;
> }
> }// end loop over 'j'
> }// end loop over 'ip'
> }
> break;
> case 1:
> {
> // Total number of operations to compute element tensor (from this point): 84
>
> // Loop quadrature points for integral
> // Number of operations to compute element tensor for following IP loop = 84
> for (unsigned int ip = 0; ip < 2; ip++)
> {
>
> // Function declarations
> double F0 = 0;
>
> // Total number of operations to compute function values = 6
> for (unsigned int r = 0; r < 3; r++)
> {
> F0 += FE0_f1[ip][r]*w[1][r];
> }// end loop over 'r'
> unsigned int m = 0;
>
> // Number of operations for primary indices = 36
> for (unsigned int j = 0; j < 6; j++)
> {
> if ((((0 <= j && j < 3))))
> {
> // Number of operations to compute entry = 6
> A[m] += (FE1_f1_C0[ip][j] + FE1_f1_C1[ip][j])*F0*-1*W2[ip]*det;
>
> ++m;
> }
> }// end loop over 'j'
> }// end loop over 'ip'
> }
> break;
> case 2:
> {
> // Total number of operations to compute element tensor (from this point): 84
>
> // Loop quadrature points for integral
> // Number of operations to compute element tensor for following IP loop = 84
> for (unsigned int ip = 0; ip < 2; ip++)
> {
>
> // Function declarations
> double F0 = 0;
>
> // Total number of operations to compute function values = 6
> for (unsigned int r = 0; r < 3; r++)
> {
> F0 += FE0_f2[ip][r]*w[1][r];
> }// end loop over 'r'
> unsigned int m = 0;
>
> // Number of operations for primary indices = 36
> for (unsigned int j = 0; j < 6; j++)
> {
> if ((((0 <= j && j < 3))))
> {
> // Number of operations to compute entry = 6
> A[m] += (FE1_f2_C1[ip][j] + FE1_f2_C0[ip][j])*F0*-1*W2[ip]*det;
>
> ++m;
> }
> }// end loop over 'j'
> }// end loop over 'ip'
> }
> break;
> }
> }
>
> public:
>
> /// Constructor
> poisson_1_exterior_facet_integral_0_quadrature(const std::vector<const pum::GenericPUM*>& pums) : ufc::exterior_facet_integral(), pums(pums)
> {
> //Do nothing
> }
>
> /// Destructor
> virtual ~poisson_1_exterior_facet_integral_0_quadrature()
> {
> //Do nothing
> }
>
> /// Tabulate the tensor for the contribution from a local exterior facet
> virtual void tabulate_tensor(double* A,
> const double * const * w,
> const ufc::cell& c,
> unsigned int facet) const
> {
> // Tabulate regular entires of element tensor
> tabulate_regular_tensor(A, w, c, facet);
>
> // local dimension of the current cell
> unsigned int num_entries = 3 + pums[0]->enriched_local_dimension(c);
>
>
> // Remove regular local dimension to obtain number of enriched dofs
> num_entries -= 3;
>
> if (num_entries == 0)
> return;
>
>
> // Extract vertex coordinates
> const double * const * x = c.coordinates;
>
> // Vertices on edges
> static unsigned int edge_vertices[3][2] = {{1, 2}, {0, 2}, {0, 1}};
>
> // Get vertices
> const unsigned int v0 = edge_vertices[facet][0];
> const unsigned int v1 = edge_vertices[facet][1];
>
> // Compute scale factor (length of edge scaled by length of reference interval)
> const double dx0 = x[v1][0] - x[v0][0];
> const double dx1 = x[v1][1] - x[v0][1];
> const double det = std::sqrt(dx0*dx0 + dx1*dx1);
>
>
> // Compute facet normals from the facet scale factor constants
>
> // FIXME: It will crash for multiple discontinuities, if we don't have at least one cell which all dofs are enriched
> const unsigned int min_entries = 6;
> const unsigned int _num_entries = std::max(num_entries, min_entries);
>
> // Resizing and reseting auxiliary tensors
> Aa.resize(_num_entries);
> std::fill(Aa.begin(), Aa.end(), 0.0);
>
> // Define an array to save current quadrature point
> double coordinate[2];
>
> // Define ufc::finite_element object(s) to evalaute shape functions or their derivatives on runtime
> poisson_1_finite_element_1 element_0;
> poisson_1_finite_element_0 element_1;
>
> // Array of quadrature weights
> static const double W2[2] = {0.5, 0.5};
>
>
> // Array of quadrature points
> static const double P2[2] = \
> {0.211324865405187,
> 0.788675134594813};
>
> // Define vectors for quadrature points and weights(note that the sizes are determined in compile time)
> std::vector <double> Wn2;
> std::vector <double> Pn2;
>
>
> // Check whether there is any need to use modified integration scheme
> if ((pums[0]->modified_quadrature(c, facet)))
> {
>
> const std::vector<double> weight2(W2, W2 + 2);
> const std::vector<double> point2(P2, P2 + 2);
>
> ConstQuadratureRule standard_gauss = std::make_pair(point2, weight2);
> QuadratureRule modified_gauss;
>
> pums[0]->facet_quadrature_rule(modified_gauss, standard_gauss, c, facet);
>
> Pn2 = modified_gauss.first;
> Wn2 = modified_gauss.second;
>
> }
> else
> {
> // Map quadrature points from the reference cell to the physical cell
> Wn2.resize(2);;
> Pn2.resize(4);;
>
>
> for (unsigned int i = 0; i < 2; i++)
> {
> Wn2[i] = W2[i];
> for (unsigned int j = 0; j < 2; j++)
> Pn2[2*i + j] = x[v0][j]*(1.0 - P2[i]) + x[v1][j]*P2[i];
> }
> }
>
>
> // Return the values of enriched function at the quadrature points
> std::vector<double> enriched_values_2;
> pums[0]->tabulate_enriched_basis(enriched_values_2, Pn2, c);
>
> // Define an auxilary index: m
> unsigned int m = 0;
>
>
> // Loop over new quadrature points for integral
> for (unsigned int ip = 0; ip < Wn2.size(); ip++)
> {
> // Evalaute tables and entries in the element tensor, if the enhanced value at this quadrature point is non-zero
> if (enriched_values_2[ip] != 0)
> {
> // Pick up the coordinates of the current quadrature point
> coordinate[0] = Pn2[2*ip];
> coordinate[1] = Pn2[2*ip + 1];
>
>
> // Creating a table to save the values of shape functions at the current guass point for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)
> double value_0[1];
> double table_0_D0[3][1];
> for (unsigned int j = 0; j < 3; j++)
> {
> element_0.evaluate_basis(j, value_0, coordinate, c);
> for (unsigned int k = 0; k < 1; k++)
> table_0_D0[j][k] = value_0[k];
> }
>
>
> // Creating a table to save the values of shape functions at the current guass point for MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })
> double value_1[2];
> double table_1_D0[6][2];
> for (unsigned int j = 0; j < 6; j++)
> {
> element_1.evaluate_basis(j, value_1, coordinate, c);
> for (unsigned int k = 0; k < 2; k++)
> table_1_D0[j][k] = value_1[k];
> }
>
> // Function declarations
> double F0 = 0;
>
> // Total number of operations to compute function values = 6
> for (unsigned int r = 0; r < 3; r++)
> {
> F0 += table_0_D0[r][0]*w[1][r];
> }// end loop over 'r'
>
> // Number of operations for primary indices = 36
> for (unsigned int j = 0; j < 6; j++)
> {
> if (!(((0 <= j && j < 3))))
> {
> // Move the indices of discontinuous spaces to the end of mixed space
> if ((3 <= j && j < 6))
> {
> m = j;
> }
> // Number of operations to compute entry = 6
> Aa[m] += (table_1_D0[j][0] + table_1_D0[j][1])*F0*-1*Wn2[ip]*det;
> }// end check for enriched entiries
> }// end loop over 'j'
> }
> }// end loop over 'ip'
>
>
> // Pick up entries from the total element tensor for the nodes active in the enrichment
>
> // Determine a vector that contains the local numbering of enriched degrees of freedom in ufc::cell c for the field 0
> std::vector<unsigned int> active_dofs_0;
> pums[0]->tabulate_enriched_local_dofs(active_dofs_0, c);
> std::vector<unsigned int>::iterator it_0_0;
>
>
> m = 0;
> for (unsigned int j = 0; j < 6; j++)
> if ((0 <= j && j < 3))
> ++m;
> else
> {
> it_0_0 = find(active_dofs_0.begin(), active_dofs_0.end(), j - 3);
>
>
> // Check whether the entry is coressponding to the active enriched node
> if (it_0_0 != active_dofs_0.end())
> {
> A[m] = Aa[j];
> ++m;
> }
> }
> }
>
> };
>
> /// This class defines the interface for the tabulation of the
> /// exterior facet tensor corresponding to the local contribution to
> /// a form from the integral over an exterior facet.
>
> class poisson_1_exterior_facet_integral_0: public ufc::exterior_facet_integral
> {
> private:
>
> poisson_1_exterior_facet_integral_0_quadrature* integral_0_quadrature;
>
>
> const std::vector<const pum::GenericPUM*>& pums;
> mutable std::vector <double> Aa;
> mutable std::vector <double> Af;
>
>
>
> /// Tabulate the regular entities of the tensor for the contribution from a local exterior facet
> virtual void tabulate_regular_tensor(double* A,
> const double * const * w,
> const ufc::cell& c,
> unsigned int facet) const
> {
> // Do nothing
> }
>
> public:
>
> /// Constructor
> poisson_1_exterior_facet_integral_0(const std::vector<const pum::GenericPUM*>& pums) : ufc::exterior_facet_integral(), pums(pums)
> {
> integral_0_quadrature = new poisson_1_exterior_facet_integral_0_quadrature(pums);
> }
>
> /// Destructor
> virtual ~poisson_1_exterior_facet_integral_0()
> {
> delete integral_0_quadrature;
> }
>
> /// Tabulate the tensor for the contribution from a local exterior facet
> virtual void tabulate_tensor(double* A,
> const double * const * w,
> const ufc::cell& c,
> unsigned int facet) const
> {
> const unsigned int num_entries = (3 + pums[0]->enriched_local_dimension(c));
>
> for (unsigned int j = 0; j < num_entries; j++)
> A[j] = 0;
>
> // Add all contributions to element tensor
> integral_0_quadrature->tabulate_tensor(A, w, c, facet);
> }
>
> };
>
> /// This class defines the interface for the assembly of the global
> /// tensor corresponding to a form with r + n arguments, that is, a
> /// mapping
> ///
> /// a : V1 x V2 x ... Vr x W1 x W2 x ... x Wn -> R
> ///
> /// with arguments v1, v2, ..., vr, w1, w2, ..., wn. The rank r
> /// global tensor A is defined by
> ///
> /// A = a(V1, V2, ..., Vr, w1, w2, ..., wn),
> ///
> /// where each argument Vj represents the application to the
> /// sequence of basis functions of Vj and w1, w2, ..., wn are given
> /// fixed functions (coefficients).
>
> class poisson_form_1: public ufc::form
> {
> const std::vector<const pum::GenericPUM*>& pums;
> public:
>
> /// Constructor
> poisson_form_1(const std::vector<const pum::GenericPUM*>& pums) : ufc::form(), pums(pums)
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_form_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the form
> virtual const char* signature() const
> {
> return "Form([Integral(Product(Function(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), 0), Sum(Indexed(BasisFunction(MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) }), 0), MultiIndex((FixedIndex(0),), {FixedIndex(0): 2})), Indexed(BasisFunction(MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) }), 0), MultiIndex((FixedIndex(1),), {FixedIndex(1): 2})))), Measure('cell', 0, None)), Integral(Product(IntValue(-1, (), (), {}), Product(Function(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), 1), Sum(Indexed(BasisFunction(MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) }), 0), MultiIndex((FixedIndex(0),), {FixedIndex(0): 2})), Indexed(BasisFunction(MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) }), 0), MultiIndex((FixedIndex(1),), {FixedIndex(1): 2}))))), Measure('exterior_facet', 0, None))])";
> }
>
> /// Return the rank of the global tensor (r)
> virtual unsigned int rank() const
> {
> return 1;
> }
>
> /// Return the number of coefficients (n)
> virtual unsigned int num_coefficients() const
> {
> return 2;
> }
>
> /// Return the number of cell integrals
> virtual unsigned int num_cell_integrals() const
> {
> return 1;
> }
>
> /// Return the number of exterior facet integrals
> virtual unsigned int num_exterior_facet_integrals() const
> {
> return 1;
> }
>
> /// Return the number of interior facet integrals
> virtual unsigned int num_interior_facet_integrals() const
> {
> return 0;
> }
>
> /// Create a new finite element for argument function i
> virtual ufc::finite_element* create_finite_element(unsigned int i) const
> {
> switch ( i )
> {
> case 0:
> return new poisson_1_finite_element_0();
> break;
> case 1:
> return new poisson_1_finite_element_1();
> break;
> case 2:
> return new poisson_1_finite_element_2();
> break;
> }
> return 0;
> }
>
> /// Create a new dof map for argument function i
> virtual ufc::dof_map* create_dof_map(unsigned int i) const
> {
> switch ( i )
> {
> case 0:
> return new poisson_1_dof_map_0(pums);
> break;
> case 1:
> return new poisson_1_dof_map_1();
> break;
> case 2:
> return new poisson_1_dof_map_2();
> break;
> }
> return 0;
> }
>
> /// Create a new cell integral on sub domain i
> virtual ufc::cell_integral* create_cell_integral(unsigned int i) const
> {
> return new poisson_1_cell_integral_0(pums);
> }
>
> /// Create a new exterior facet integral on sub domain i
> virtual ufc::exterior_facet_integral* create_exterior_facet_integral(unsigned int i) const
> {
> return new poisson_1_exterior_facet_integral_0(pums);
> }
>
> /// Create a new interior facet integral on sub domain i
> virtual ufc::interior_facet_integral* create_interior_facet_integral(unsigned int i) const
> {
> return 0;
> }
>
> };
>
> /// This class defines the interface for a finite element.
>
> class poisson_auxiliary_1_finite_element_0: public ufc::finite_element
> {
> public:
>
> /// Constructor
> poisson_auxiliary_1_finite_element_0() : ufc::finite_element()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_auxiliary_1_finite_element_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the finite element
> virtual const char* signature() const
> {
> return "FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return the cell shape
> virtual ufc::shape cell_shape() const
> {
> return ufc::triangle;
> }
>
> /// Return the dimension of the finite element function space
> virtual unsigned int space_dimension() const
> {
> return 3;
> }
>
> /// Return the rank of the value space
> virtual unsigned int value_rank() const
> {
> return 0;
> }
>
> /// Return the dimension of the value space for axis i
> virtual unsigned int value_dimension(unsigned int i) const
> {
> return 1;
> }
>
> /// Evaluate basis function i at given point in cell
> virtual void evaluate_basis(unsigned int i,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Reset values
> *values = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Extract relevant coefficients
> const double coeff0_0 = coefficients0[dof][0];
> const double coeff0_1 = coefficients0[dof][1];
> const double coeff0_2 = coefficients0[dof][2];
>
> // Compute value(s)
> *values = coeff0_0*basisvalue0 + coeff0_1*basisvalue1 + coeff0_2*basisvalue2;
> }
>
> /// Evaluate all basis functions at given point in cell
> virtual void evaluate_basis_all(double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis() is not yet implemented.");
> }
>
> /// Evaluate order n derivatives of basis function i at given point in cell
> virtual void evaluate_basis_derivatives(unsigned int i,
> unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> // Extract vertex coordinates
> const double * const * element_coordinates = c.coordinates;
>
> // Compute Jacobian of affine map from reference cell
> const double J_00 = element_coordinates[1][0] - element_coordinates[0][0];
> const double J_01 = element_coordinates[2][0] - element_coordinates[0][0];
> const double J_10 = element_coordinates[1][1] - element_coordinates[0][1];
> const double J_11 = element_coordinates[2][1] - element_coordinates[0][1];
>
> // Compute determinant of Jacobian
> const double detJ = J_00*J_11 - J_01*J_10;
>
> // Compute inverse of Jacobian
>
> // Get coordinates and map to the reference (UFC) element
> double x = (element_coordinates[0][1]*element_coordinates[2][0] -\
> element_coordinates[0][0]*element_coordinates[2][1] +\
> J_11*coordinates[0] - J_01*coordinates[1]) / detJ;
> double y = (element_coordinates[1][1]*element_coordinates[0][0] -\
> element_coordinates[1][0]*element_coordinates[0][1] -\
> J_10*coordinates[0] + J_00*coordinates[1]) / detJ;
>
> // Map coordinates to the reference square
> if (std::abs(y - 1.0) < 1e-14)
> x = -1.0;
> else
> x = 2.0 *x/(1.0 - y) - 1.0;
> y = 2.0*y - 1.0;
>
> // Compute number of derivatives
> unsigned int num_derivatives = 1;
>
> for (unsigned int j = 0; j < n; j++)
> num_derivatives *= 2;
>
>
> // Declare pointer to two dimensional array that holds combinations of derivatives and initialise
> unsigned int **combinations = new unsigned int *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> combinations[j] = new unsigned int [n];
> for (unsigned int k = 0; k < n; k++)
> combinations[j][k] = 0;
> }
>
> // Generate combinations of derivatives
> for (unsigned int row = 1; row < num_derivatives; row++)
> {
> for (unsigned int num = 0; num < row; num++)
> {
> for (unsigned int col = n-1; col+1 > 0; col--)
> {
> if (combinations[row][col] + 1 > 1)
> combinations[row][col] = 0;
> else
> {
> combinations[row][col] += 1;
> break;
> }
> }
> }
> }
>
> // Compute inverse of Jacobian
> const double Jinv[2][2] = {{J_11 / detJ, -J_01 / detJ}, {-J_10 / detJ, J_00 / detJ}};
>
> // Declare transformation matrix
> // Declare pointer to two dimensional array and initialise
> double **transform = new double *[num_derivatives];
>
> for (unsigned int j = 0; j < num_derivatives; j++)
> {
> transform[j] = new double [num_derivatives];
> for (unsigned int k = 0; k < num_derivatives; k++)
> transform[j][k] = 1;
> }
>
> // Construct transformation matrix
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> for (unsigned int k = 0; k < n; k++)
> transform[row][col] *= Jinv[combinations[col][k]][combinations[row][k]];
> }
> }
>
> // Reset values
> for (unsigned int j = 0; j < 1*num_derivatives; j++)
> values[j] = 0;
>
> // Map degree of freedom to element degree of freedom
> const unsigned int dof = i;
>
> // Generate scalings
> const double scalings_y_0 = 1;
> const double scalings_y_1 = scalings_y_0*(0.5 - 0.5*y);
>
> // Compute psitilde_a
> const double psitilde_a_0 = 1;
> const double psitilde_a_1 = x;
>
> // Compute psitilde_bs
> const double psitilde_bs_0_0 = 1;
> const double psitilde_bs_0_1 = 1.5*y + 0.5;
> const double psitilde_bs_1_0 = 1;
>
> // Compute basisvalues
> const double basisvalue0 = 0.707106781186548*psitilde_a_0*scalings_y_0*psitilde_bs_0_0;
> const double basisvalue1 = 1.73205080756888*psitilde_a_1*scalings_y_1*psitilde_bs_1_0;
> const double basisvalue2 = psitilde_a_0*scalings_y_0*psitilde_bs_0_1;
>
> // Table(s) of coefficients
> static const double coefficients0[3][3] = \
> {{0.471404520791032, -0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0.288675134594813, -0.166666666666667},
> {0.471404520791032, 0, 0.333333333333333}};
>
> // Interesting (new) part
> // Tables of derivatives of the polynomial base (transpose)
> static const double dmats0[3][3] = \
> {{0, 0, 0},
> {4.89897948556636, 0, 0},
> {0, 0, 0}};
>
> static const double dmats1[3][3] = \
> {{0, 0, 0},
> {2.44948974278318, 0, 0},
> {4.24264068711928, 0, 0}};
>
> // Compute reference derivatives
> // Declare pointer to array of derivatives on FIAT element
> double *derivatives = new double [num_derivatives];
>
> // Declare coefficients
> double coeff0_0 = 0;
> double coeff0_1 = 0;
> double coeff0_2 = 0;
>
> // Declare new coefficients
> double new_coeff0_0 = 0;
> double new_coeff0_1 = 0;
> double new_coeff0_2 = 0;
>
> // Loop possible derivatives
> for (unsigned int deriv_num = 0; deriv_num < num_derivatives; deriv_num++)
> {
> // Get values from coefficients array
> new_coeff0_0 = coefficients0[dof][0];
> new_coeff0_1 = coefficients0[dof][1];
> new_coeff0_2 = coefficients0[dof][2];
>
> // Loop derivative order
> for (unsigned int j = 0; j < n; j++)
> {
> // Update old coefficients
> coeff0_0 = new_coeff0_0;
> coeff0_1 = new_coeff0_1;
> coeff0_2 = new_coeff0_2;
>
> if(combinations[deriv_num][j] == 0)
> {
> new_coeff0_0 = coeff0_0*dmats0[0][0] + coeff0_1*dmats0[1][0] + coeff0_2*dmats0[2][0];
> new_coeff0_1 = coeff0_0*dmats0[0][1] + coeff0_1*dmats0[1][1] + coeff0_2*dmats0[2][1];
> new_coeff0_2 = coeff0_0*dmats0[0][2] + coeff0_1*dmats0[1][2] + coeff0_2*dmats0[2][2];
> }
> if(combinations[deriv_num][j] == 1)
> {
> new_coeff0_0 = coeff0_0*dmats1[0][0] + coeff0_1*dmats1[1][0] + coeff0_2*dmats1[2][0];
> new_coeff0_1 = coeff0_0*dmats1[0][1] + coeff0_1*dmats1[1][1] + coeff0_2*dmats1[2][1];
> new_coeff0_2 = coeff0_0*dmats1[0][2] + coeff0_1*dmats1[1][2] + coeff0_2*dmats1[2][2];
> }
>
> }
> // Compute derivatives on reference element as dot product of coefficients and basisvalues
> derivatives[deriv_num] = new_coeff0_0*basisvalue0 + new_coeff0_1*basisvalue1 + new_coeff0_2*basisvalue2;
> }
>
> // Transform derivatives back to physical element
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> for (unsigned int col = 0; col < num_derivatives; col++)
> {
> values[row] += transform[row][col]*derivatives[col];
> }
> }
> // Delete pointer to array of derivatives on FIAT element
> delete [] derivatives;
>
> // Delete pointer to array of combinations of derivatives and transform
> for (unsigned int row = 0; row < num_derivatives; row++)
> {
> delete [] combinations[row];
> delete [] transform[row];
> }
>
> delete [] combinations;
> delete [] transform;
> }
>
> /// Evaluate order n derivatives of all basis functions at given point in cell
> virtual void evaluate_basis_derivatives_all(unsigned int n,
> double* values,
> const double* coordinates,
> const ufc::cell& c) const
> {
> throw std::runtime_error("The vectorised version of evaluate_basis_derivatives() is not yet implemented.");
> }
>
> /// Evaluate linear functional for dof i on the function f
> virtual double evaluate_dof(unsigned int i,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> // The reference points, direction and weights:
> static const double X[3][1][2] = {{{0, 0}}, {{1, 0}}, {{0, 1}}};
> static const double W[3][1] = {{1}, {1}, {1}};
> static const double D[3][1][1] = {{{1}}, {{1}}, {{1}}};
>
> const double * const * x = c.coordinates;
> double result = 0.0;
> // Iterate over the points:
> // Evaluate basis functions for affine mapping
> const double w0 = 1.0 - X[i][0][0] - X[i][0][1];
> const double w1 = X[i][0][0];
> const double w2 = X[i][0][1];
>
> // Compute affine mapping y = F(X)
> double y[2];
> y[0] = w0*x[0][0] + w1*x[1][0] + w2*x[2][0];
> y[1] = w0*x[0][1] + w1*x[1][1] + w2*x[2][1];
>
> // Evaluate function at physical points
> double values[1];
> f.evaluate(values, y, c);
>
> // Map function values using appropriate mapping
> // Affine map: Do nothing
>
> // Note that we do not map the weights (yet).
>
> // Take directional components
> for(int k = 0; k < 1; k++)
> result += values[k]*D[i][0][k];
> // Multiply by weights
> result *= W[i][0];
>
> return result;
> }
>
> /// Evaluate linear functionals for all dofs on the function f
> virtual void evaluate_dofs(double* values,
> const ufc::function& f,
> const ufc::cell& c) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Interpolate vertex values from dof values
> virtual void interpolate_vertex_values(double* vertex_values,
> const double* dof_values,
> const ufc::cell& c) const
> {
> // Evaluate at vertices and use affine mapping
> vertex_values[0] = dof_values[0];
> vertex_values[1] = dof_values[1];
> vertex_values[2] = dof_values[2];
> }
>
> /// Return the number of sub elements (for a mixed element)
> virtual unsigned int num_sub_elements() const
> {
> return 1;
> }
>
> /// Create a new finite element for sub element i (for a mixed element)
> virtual ufc::finite_element* create_sub_element(unsigned int i) const
> {
> return new poisson_auxiliary_1_finite_element_0();
> }
>
> };
>
> /// This class defines the interface for a local-to-global mapping of
> /// degrees of freedom (dofs).
>
>
> class poisson_auxiliary_1_dof_map_0: public ufc::dof_map
> {
> private:
>
> unsigned int __global_dimension;
>
>
> public:
>
> /// Constructor
> poisson_auxiliary_1_dof_map_0() :ufc::dof_map()
> {
> __global_dimension = 0;
> }
> /// Destructor
> virtual ~poisson_auxiliary_1_dof_map_0()
> {
> // Do nothing
> }
>
> /// Return a string identifying the dof map
> virtual const char* signature() const
> {
> return "FFC dof map for FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1)";
> }
>
> /// Return true iff mesh entities of topological dimension d are needed
> virtual bool needs_mesh_entities(unsigned int d) const
> {
> switch ( d )
> {
> case 0:
> return true;
> break;
> case 1:
> return false;
> break;
> case 2:
> return false;
> break;
> }
> return false;
> }
>
> /// Initialize dof map for mesh (return true iff init_cell() is needed)
> virtual bool init_mesh(const ufc::mesh& m)
> {
> __global_dimension = m.num_entities[0];
> return false;
> }
>
> /// Initialize dof map for given cell
> virtual void init_cell(const ufc::mesh& m,
> const ufc::cell& c)
> {
> // Do nothing
> }
>
> /// Finish initialization of dof map for cells
> virtual void init_cell_finalize()
> {
> // Do nothing
> }
>
> /// Return the dimension of the global finite element function space
> virtual unsigned int global_dimension() const
> {
> return __global_dimension ;
> }
>
> /// Return the dimension of the local finite element function space for a cell
> virtual unsigned int local_dimension(const ufc::cell& c) const
> {
> return 3;
> }
>
> /// Return the maximum dimension of the local finite element function space
> virtual unsigned int max_local_dimension() const
> {
> return 3;
> }
>
>
> // Return the geometric dimension of the coordinates this dof map provides
> virtual unsigned int geometric_dimension() const
> {
> return 2;
> }
>
> /// Return the number of dofs on each cell facet
> virtual unsigned int num_facet_dofs() const
> {
> return 2;
> }
>
> /// Return the number of dofs associated with each cell entity of dimension d
> virtual unsigned int num_entity_dofs(unsigned int d) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the local-to-global mapping of dofs on a cell
> virtual void tabulate_dofs(unsigned int* dofs,
> const ufc::mesh& m,
> const ufc::cell& c) const
> {
> dofs[0] = c.entity_indices[0][0];
> dofs[1] = c.entity_indices[0][1];
> dofs[2] = c.entity_indices[0][2];
> }
>
> /// Tabulate the local-to-local mapping from facet dofs to cell dofs
> virtual void tabulate_facet_dofs(unsigned int* dofs,
> unsigned int facet) const
> {
> switch ( facet )
> {
> case 0:
> dofs[0] = 1;
> dofs[1] = 2;
> break;
> case 1:
> dofs[0] = 0;
> dofs[1] = 2;
> break;
> case 2:
> dofs[0] = 0;
> dofs[1] = 1;
> break;
> }
> }
>
> /// Tabulate the local-to-local mapping of dofs on entity (d, i)
> virtual void tabulate_entity_dofs(unsigned int* dofs,
> unsigned int d, unsigned int i) const
> {
> throw std::runtime_error("Not implemented (introduced in UFC v1.1).");
> }
>
> /// Tabulate the coordinates of all dofs on a cell
> virtual void tabulate_coordinates(double** coordinates,
> const ufc::cell& c) const
> {
> const double * const * x = c.coordinates;
> coordinates[0][0] = x[0][0];
> coordinates[0][1] = x[0][1];
> coordinates[1][0] = x[1][0];
> coordinates[1][1] = x[1][1];
> coordinates[2][0] = x[2][0];
> coordinates[2][1] = x[2][1];
> }
>
> /// Return the number of sub dof maps (for a mixed element)
> virtual unsigned int num_sub_dof_maps() const
> {
> return 1;
> }
>
> /// Create a new dof_map for sub dof map i (for a mixed element)
> virtual ufc::dof_map* create_sub_dof_map(unsigned int i) const
> {
> return new poisson_auxiliary_1_dof_map_0();
> }
>
> };
>
> /// This class defines the interface for the assembly of the global
> /// tensor corresponding to a form with r + n arguments, that is, a
> /// mapping
> ///
> /// a : V1 x V2 x ... Vr x W1 x W2 x ... x Wn -> R
> ///
> /// with arguments v1, v2, ..., vr, w1, w2, ..., wn. The rank r
> /// global tensor A is defined by
> ///
> /// A = a(V1, V2, ..., Vr, w1, w2, ..., wn),
> ///
> /// where each argument Vj represents the application to the
> /// sequence of basis functions of Vj and w1, w2, ..., wn are given
> /// fixed functions (coefficients).
>
> class poisson_auxiliary_form_1: public ufc::form
> {
> public:
>
> /// Constructor
> poisson_auxiliary_form_1() : ufc::form()
> {
> // Do nothing
> }
>
> /// Destructor
> virtual ~poisson_auxiliary_form_1()
> {
> // Do nothing
> }
>
> /// Return a string identifying the form
> virtual const char* signature() const
> {
> return "Auxiliary ufc::form to initialize standard functions, apply boundary conditions and obtain ufc::dof_map objects for continuous space(required for PUM objects) for a form containing discontinuous spaces.";
> }
>
> /// Return the rank of the global tensor (r)
> virtual unsigned int rank() const
> {
> return 1;
> }
>
> /// Return the number of coefficients (n)
> virtual unsigned int num_coefficients() const
> {
> return 0;
> }
>
> /// Return the number of cell integrals
> virtual unsigned int num_cell_integrals() const
> {
> return 0;
> }
>
> /// Return the number of exterior facet integrals
> virtual unsigned int num_exterior_facet_integrals() const
> {
> return 0;
> }
>
> /// Return the number of interior facet integrals
> virtual unsigned int num_interior_facet_integrals() const
> {
> return 0;
> }
>
> /// Create a new finite element for argument function i
> virtual ufc::finite_element* create_finite_element(unsigned int i) const
> {
> switch ( i )
> {
> case 0:
> return new poisson_auxiliary_1_finite_element_0();
> break;
> case 1:
> return new poisson_auxiliary_1_finite_element_0();
> break;
> }
> return 0;
> }
>
> /// Create a new dof map for argument function i
> virtual ufc::dof_map* create_dof_map(unsigned int i) const
> {
> switch ( i )
> {
> case 0:
> return new poisson_auxiliary_1_dof_map_0();
> break;
> case 1:
> return new poisson_auxiliary_1_dof_map_0();
> break;
> }
> return 0;
> }
>
> /// Create a new cell integral on sub domain i
> virtual ufc::cell_integral* create_cell_integral(unsigned int i) const
> {
> return 0;
> }
>
> /// Create a new exterior facet integral on sub domain i
> virtual ufc::exterior_facet_integral* create_exterior_facet_integral(unsigned int i) const
> {
> return 0;
> }
>
> /// Create a new interior facet integral on sub domain i
> virtual ufc::interior_facet_integral* create_interior_facet_integral(unsigned int i) const
> {
> return 0;
> }
>
> };
>
> /// This class defines the interface for post-processing on vector x
> /// to obtain x0, u and j where,
> ///
> /// - x is the solution vector containing standard and enriched degrees of freedom
> /// defined on continuous/discontinuous space
> /// - u is the standard part of solution vector defined on continuous space
> /// - j is the enriched part pf solution vector defined on continuous space
> /// - x0 is the result vector, equall to u + j, defined on continuous space
> /// by considering enrichement function
> //
>
> // Dolfin includes
> #include <dolfin/common/NoDeleter.h>
> #include <dolfin/mesh/Mesh.h>
> #include <dolfin/fem/DofMap.h>
> #include <dolfin/la/GenericVector.h>
>
> // PartitionOfUnity includes
> #include <pum/PostProcess.h>
> #include <pum/FunctionSpace.h>
>
> namespace Poisson
> {
> class PostProcess: public pum::PostProcess
> {
> dolfin::Mesh& mesh;
> std::vector<const pum::GenericPUM*>& pums;
>
> public:
>
> /// Constructor
> PostProcess(dolfin::Mesh& mesh, std::vector<const pum::GenericPUM*>& pums): pum::PostProcess(mesh), mesh(mesh), pums(pums)
> {
> // Do nothing
> }
>
> /// Destructor
> ~PostProcess()
> {
> // Do nothing
> }
>
> /// Return a string identifying the underling element
> const char* signature() const
> {
> return "Interpolating results to the continuous space of MixedElement(*[FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), ElementRestriction(FiniteElement('Lagrange', Cell('triangle', 1, Space(2)), 1), Measure('surface', 0, None))], **{'value_shape': (2,) })";
> }
>
> /// Obtain result vector 'x0' from solution vector 'x'
> void interpolate(const dolfin::GenericVector& x, dolfin::GenericVector& x0) const
> {
>
> //poisson_1_dof_map_0_0 ufc_dof_map_0;
> //dolfin::DofMap dof_map_0(ufc_dof_map_0, mesh);
> //dolfin::DofMap dof_map_0(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_0_0()), dolfin::reference_to_no_delete_pointer(mesh));
> dolfin::DofMap dof_map_0(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_0_0()), mesh);
> unsigned int num_standard_dofs_0 = dof_map_0.global_dimension();
>
> double value, h;
>
> /// selecting standard degrees of freedom related to field 0 from the solution vector
>
> double* values_0 = new double[num_standard_dofs_0];
> unsigned int* positions_0 = new unsigned int [num_standard_dofs_0];
>
> for (unsigned int i = 0; i < num_standard_dofs_0; ++i)
> positions_0[i] = i;
>
> x.get(values_0, num_standard_dofs_0, positions_0);
> x0.set(values_0, num_standard_dofs_0, positions_0);
>
>
>
> /// selecting enriched degrees of freedom related to field 0 from the solution vector
> std::vector <std::vector<unsigned int> > enhanced_dof_maps_0;
> enhanced_dof_maps_0.resize(num_standard_dofs_0);
>
> std::vector<unsigned int> enhanced_dof_values_0;
> enhanced_dof_values_0.resize(num_standard_dofs_0);
>
> compute_enhanced_dof_maps(*pums[0], dof_map_0, enhanced_dof_maps_0);
> compute_enhanced_dof_values(*pums[0], dof_map_0, enhanced_dof_values_0);
>
>
> for (unsigned int i = 0; i != num_standard_dofs_0; ++i)
> {
> unsigned int pos = i;
>
> for (std::vector<unsigned int>::const_iterator it = enhanced_dof_maps_0[i].begin();
> it != enhanced_dof_maps_0[i].end(); ++it)
> {
> //h = pums[0]->enhanced_node_value(*it);
> h = enhanced_dof_values_0[i];
> unsigned int pos_n = *it + num_standard_dofs_0;
>
> x.get(&value, 1, &pos_n);
> value *= h;
> x0.add(&value, 1, &pos);
> }
> }
>
>
> // memory clean up
>
> delete[] values_0;
> delete[] positions_0;
>
> x0.apply();
> }
>
> /// Obtain continuous u and discontinuous j parts of solution vector 'x'
> void interpolate(const dolfin::GenericVector& x, dolfin::GenericVector& u, dolfin::GenericVector& j) const
> {
>
> //poisson_1_dof_map_0_0 ufc_dof_map_0;
> //dolfin::DofMap dof_map_0(ufc_dof_map_0, mesh);
> //dolfin::DofMap dof_map_0(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_0_0()), dolfin::reference_to_no_delete_pointer(mesh));
> dolfin::DofMap dof_map_0(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_0_0()), mesh);
> unsigned int num_standard_dofs_0 = dof_map_0.global_dimension();
>
> double value;
>
> /// selecting standard degrees of freedom related to field 0 from the solution vector
> double* values_0 = new double[num_standard_dofs_0];
> unsigned int* positions_0 = new unsigned int [num_standard_dofs_0];
>
> for (unsigned int i = 0; i < num_standard_dofs_0; ++i)
> positions_0[i] = i;
>
> x.get(values_0, num_standard_dofs_0, positions_0);
> u.set(values_0, num_standard_dofs_0, positions_0);
>
>
>
> /// selecting enriched degrees of freedom related to field 0 from the solution vector
> std::vector <std::vector<unsigned int> > enhanced_dof_maps_0;
> enhanced_dof_maps_0.resize(num_standard_dofs_0);
>
> compute_enhanced_dof_maps(*pums[0], dof_map_0, enhanced_dof_maps_0);
>
> for (unsigned int i = 0; i != num_standard_dofs_0; ++i)
> {
> unsigned int pos = i ;
>
> for (std::vector<unsigned int>::const_iterator it = enhanced_dof_maps_0[i].begin();
> it != enhanced_dof_maps_0[i].end(); ++it)
> {
> unsigned int pos_n = *it + num_standard_dofs_0;
>
> x.get(&value, 1, &pos_n);
> j.set(&value, 1, &pos);
> }
> }
>
>
> // memory clean up
>
> delete[] values_0;
> delete[] positions_0;
>
> u.apply();
> j.apply();
> }
>
> };
> }
>
> // DOLFIN wrappers
>
> // Standard library includes
> #include <string>
>
> // DOLFIN includes
> #include <dolfin/common/NoDeleter.h>
> #include <dolfin/fem/FiniteElement.h>
> #include <dolfin/fem/DofMap.h>
> #include <dolfin/fem/Form.h>
> #include <dolfin/function/FunctionSpace.h>
> #include <dolfin/function/Function.h>
> #include <dolfin/function/GenericFunction.h>
> #include <dolfin/function/CoefficientAssigner.h>
>
> namespace Poisson
> {
>
> class CoefficientSpace_f: public dolfin::FunctionSpace
> {
> public:
>
>
> CoefficientSpace_f(const dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement
> (boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_1()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>
> (new poisson_1_dof_map_1()), mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_f(dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_1()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_1()), mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_f(boost::shared_ptr<dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_1()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_1()), *mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_f(boost::shared_ptr<const dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_1()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_1()), *mesh)))
> {
> // Do nothing
> }
>
>
> ~CoefficientSpace_f()
> {
> }
>
> };
>
> class CoefficientSpace_g: public dolfin::FunctionSpace
> {
> public:
>
>
> CoefficientSpace_g(const dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement
> (boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_2()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>
> (new poisson_1_dof_map_2()), mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_g(dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_2()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_2()), mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_g(boost::shared_ptr<dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_2()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_2()), *mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_g(boost::shared_ptr<const dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_2()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_2()), *mesh)))
> {
> // Do nothing
> }
>
>
> ~CoefficientSpace_g()
> {
> }
>
> };
>
> class CoefficientSpace_k: public dolfin::FunctionSpace
> {
> public:
>
>
> CoefficientSpace_k(const dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement
> (boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_2()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>
> (new poisson_0_dof_map_2()), mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_k(dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_2()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_2()), mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_k(boost::shared_ptr<dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_2()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_2()), *mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_k(boost::shared_ptr<const dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_2()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_2()), *mesh)))
> {
> // Do nothing
> }
>
>
> ~CoefficientSpace_k()
> {
> }
>
> };
>
> class CoefficientSpace_w: public dolfin::FunctionSpace
> {
> public:
>
>
> CoefficientSpace_w(const dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement
> (boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_3()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>
> (new poisson_0_dof_map_3()), mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_w(dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_3()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_3()), mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_w(boost::shared_ptr<dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_3()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_3()), *mesh)))
> {
> // Do nothing
> }
>
> CoefficientSpace_w(boost::shared_ptr<const dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_3()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_3()), *mesh)))
> {
> // Do nothing
> }
>
>
> ~CoefficientSpace_w()
> {
> }
>
> };
>
> class Form_0_FunctionSpace_0: public pum::FunctionSpace
> {
> public:
>
>
> Form_0_FunctionSpace_0(const dolfin::Mesh & mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement
> (boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>
> (new poisson_0_dof_map_0(pums)), mesh)) ,pums)
> {
> // Do nothing
> }
>
> Form_0_FunctionSpace_0(dolfin::Mesh & mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_0(pums)), mesh)) ,pums)
> {
> // Do nothing
> }
>
> Form_0_FunctionSpace_0(boost::shared_ptr<dolfin::Mesh> mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_0(pums)), *mesh)) ,pums)
> {
> // Do nothing
> }
>
> Form_0_FunctionSpace_0(boost::shared_ptr<const dolfin::Mesh> mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_0(pums)), *mesh)) ,pums)
> {
> // Do nothing
> }
>
>
> ~Form_0_FunctionSpace_0()
> {
> }
>
> };
>
> class Form_0_FunctionSpace_1: public pum::FunctionSpace
> {
> public:
>
>
> Form_0_FunctionSpace_1(const dolfin::Mesh & mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement
> (boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_1()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>
> (new poisson_0_dof_map_1(pums)), mesh)) ,pums)
> {
> // Do nothing
> }
>
> Form_0_FunctionSpace_1(dolfin::Mesh & mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_1()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_1(pums)), mesh)) ,pums)
> {
> // Do nothing
> }
>
> Form_0_FunctionSpace_1(boost::shared_ptr<dolfin::Mesh> mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_1()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_1(pums)), *mesh)) ,pums)
> {
> // Do nothing
> }
>
> Form_0_FunctionSpace_1(boost::shared_ptr<const dolfin::Mesh> mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_0_finite_element_1()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_0_dof_map_1(pums)), *mesh)) ,pums)
> {
> // Do nothing
> }
>
>
> ~Form_0_FunctionSpace_1()
> {
> }
>
> };
>
> typedef CoefficientSpace_k Form_0_FunctionSpace_2;
>
> typedef CoefficientSpace_w Form_0_FunctionSpace_3;
>
> class Form_0: public dolfin::Form
> {
> public:
>
> // Constructor
> Form_0(const pum::FunctionSpace& V0, const pum::FunctionSpace& V1):
> dolfin::Form(2, 2), k(*this, 0), w(*this, 1)
> {
> _function_spaces[0] = reference_to_no_delete_pointer(V0);
> _function_spaces[1] = reference_to_no_delete_pointer(V1);
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_0(V0.pums));
> }
>
> // Constructor
> Form_0(const pum::FunctionSpace& V0, const pum::FunctionSpace& V1, dolfin::GenericFunction & k, dolfin::GenericFunction & w):
> dolfin::Form(2, 2), k(*this, 0), w(*this, 1)
> {
> _function_spaces[0] = reference_to_no_delete_pointer(V0);
> _function_spaces[1] = reference_to_no_delete_pointer(V1);
>
> this->k = k;
> this->w = w;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_0(V0.pums));
> }
>
> // Constructor
> Form_0(const pum::FunctionSpace& V0, const pum::FunctionSpace& V1, boost::shared_ptr<dolfin::GenericFunction> k, boost::shared_ptr<dolfin::GenericFunction> w):
> dolfin::Form(2, 2), k(*this, 0), w(*this, 1)
> {
> _function_spaces[0] = reference_to_no_delete_pointer(V0);
> _function_spaces[1] = reference_to_no_delete_pointer(V1);
>
> this->k = *k;
> this->w = *w;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_0(V0.pums));
> }
>
> // Constructor
> Form_0(boost::shared_ptr<const pum::FunctionSpace> V0, boost::shared_ptr<const pum::FunctionSpace> V1):
> dolfin::Form(2, 2), k(*this, 0), w(*this, 1)
> {
> _function_spaces[0] = V0;
> _function_spaces[1] = V1;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_0(V0->pums));
> }
>
> // Constructor
> Form_0(boost::shared_ptr<const pum::FunctionSpace> V0, boost::shared_ptr<const pum::FunctionSpace> V1, dolfin::GenericFunction & k, dolfin::GenericFunction & w):
> dolfin::Form(2, 2), k(*this, 0), w(*this, 1)
> {
> _function_spaces[0] = V0;
> _function_spaces[1] = V1;
>
> this->k = k;
> this->w = w;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_0(V0->pums));
> }
>
> // Constructor
> Form_0(boost::shared_ptr<const pum::FunctionSpace> V0, boost::shared_ptr<const pum::FunctionSpace> V1, boost::shared_ptr<dolfin::GenericFunction> k, boost::shared_ptr<dolfin::GenericFunction> w):
> dolfin::Form(2, 2), k(*this, 0), w(*this, 1)
> {
> _function_spaces[0] = V0;
> _function_spaces[1] = V1;
>
> this->k = *k;
> this->w = *w;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_0(V0->pums));
> }
>
> // Destructor
> ~Form_0()
> {}
>
> /// Return the number of the coefficient with this name
> virtual dolfin::uint coefficient_number(const std::string& name) const
> {
> if(name == "k") return 0;
> else if(name == "w") return 1;
> dolfin::error("Invalid coefficient.");
> return 0;
> }
>
> /// Return the name of the coefficient with this number
> virtual std::string coefficient_name(dolfin::uint i) const
> {
> switch(i)
> {
> case 0: return "k";
> case 1: return "w";
> }
> dolfin::error("Invalid coefficient.");
> return "unnamed";
> }
>
> // Typedefs
> typedef Form_0_FunctionSpace_0 TestSpace;
> typedef Form_0_FunctionSpace_1 TrialSpace;
> typedef Form_0_FunctionSpace_2 CoefficientSpace_k;
> typedef Form_0_FunctionSpace_3 CoefficientSpace_w;
>
> // Coefficients
> dolfin::CoefficientAssigner k;
> dolfin::CoefficientAssigner w;
> };
>
> class Form_1_FunctionSpace_0: public pum::FunctionSpace
> {
> public:
>
>
> Form_1_FunctionSpace_0(const dolfin::Mesh & mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement
> (boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>
> (new poisson_1_dof_map_0(pums)), mesh)) ,pums)
> {
> // Do nothing
> }
>
> Form_1_FunctionSpace_0(dolfin::Mesh & mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_0(pums)), mesh)) ,pums)
> {
> // Do nothing
> }
>
> Form_1_FunctionSpace_0(boost::shared_ptr<dolfin::Mesh> mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_0(pums)), *mesh)) ,pums)
> {
> // Do nothing
> }
>
> Form_1_FunctionSpace_0(boost::shared_ptr<const dolfin::Mesh> mesh ,const std::vector<const pum::GenericPUM*>& pums):
> pum::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_1_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_1_dof_map_0(pums)), *mesh)) ,pums)
> {
> // Do nothing
> }
>
>
> ~Form_1_FunctionSpace_0()
> {
> }
>
> };
>
> typedef CoefficientSpace_f Form_1_FunctionSpace_1;
>
> typedef CoefficientSpace_g Form_1_FunctionSpace_2;
>
> class Form_1: public dolfin::Form
> {
> public:
>
> // Constructor
> Form_1(const pum::FunctionSpace& V0):
> dolfin::Form(1, 2), f(*this, 0), g(*this, 1)
> {
> _function_spaces[0] = reference_to_no_delete_pointer(V0);
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_1(V0.pums));
> }
>
> // Constructor
> Form_1(const pum::FunctionSpace& V0, dolfin::GenericFunction & f, dolfin::GenericFunction & g):
> dolfin::Form(1, 2), f(*this, 0), g(*this, 1)
> {
> _function_spaces[0] = reference_to_no_delete_pointer(V0);
>
> this->f = f;
> this->g = g;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_1(V0.pums));
> }
>
> // Constructor
> Form_1(const pum::FunctionSpace& V0, boost::shared_ptr<dolfin::GenericFunction> f, boost::shared_ptr<dolfin::GenericFunction> g):
> dolfin::Form(1, 2), f(*this, 0), g(*this, 1)
> {
> _function_spaces[0] = reference_to_no_delete_pointer(V0);
>
> this->f = *f;
> this->g = *g;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_1(V0.pums));
> }
>
> // Constructor
> Form_1(boost::shared_ptr<const pum::FunctionSpace> V0):
> dolfin::Form(1, 2), f(*this, 0), g(*this, 1)
> {
> _function_spaces[0] = V0;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_1(V0->pums));
> }
>
> // Constructor
> Form_1(boost::shared_ptr<const pum::FunctionSpace> V0, dolfin::GenericFunction & f, dolfin::GenericFunction & g):
> dolfin::Form(1, 2), f(*this, 0), g(*this, 1)
> {
> _function_spaces[0] = V0;
>
> this->f = f;
> this->g = g;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_1(V0->pums));
> }
>
> // Constructor
> Form_1(boost::shared_ptr<const pum::FunctionSpace> V0, boost::shared_ptr<dolfin::GenericFunction> f, boost::shared_ptr<dolfin::GenericFunction> g):
> dolfin::Form(1, 2), f(*this, 0), g(*this, 1)
> {
> _function_spaces[0] = V0;
>
> this->f = *f;
> this->g = *g;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_form_1(V0->pums));
> }
>
> // Destructor
> ~Form_1()
> {}
>
> /// Return the number of the coefficient with this name
> virtual dolfin::uint coefficient_number(const std::string& name) const
> {
> if(name == "f") return 0;
> else if(name == "g") return 1;
> dolfin::error("Invalid coefficient.");
> return 0;
> }
>
> /// Return the name of the coefficient with this number
> virtual std::string coefficient_name(dolfin::uint i) const
> {
> switch(i)
> {
> case 0: return "f";
> case 1: return "g";
> }
> dolfin::error("Invalid coefficient.");
> return "unnamed";
> }
>
> // Typedefs
> typedef Form_1_FunctionSpace_0 TestSpace;
> typedef Form_1_FunctionSpace_1 CoefficientSpace_f;
> typedef Form_1_FunctionSpace_2 CoefficientSpace_g;
>
> // Coefficients
> dolfin::CoefficientAssigner f;
> dolfin::CoefficientAssigner g;
> };
>
> // Class typedefs
> typedef Form_0 BilinearForm;
> typedef Form_1 LinearForm;
> typedef Form_0::TestSpace FunctionSpace;
>
> } // namespace Poisson
>
> // DOLFIN wrappers
>
> // Standard library includes
> #include <string>
>
> // DOLFIN includes
> #include <dolfin/common/NoDeleter.h>
> #include <dolfin/fem/FiniteElement.h>
> #include <dolfin/fem/DofMap.h>
> #include <dolfin/fem/Form.h>
> #include <dolfin/function/FunctionSpace.h>
> #include <dolfin/function/Function.h>
> #include <dolfin/function/GenericFunction.h>
> #include <dolfin/function/CoefficientAssigner.h>
>
> namespace Poisson
> {
>
> class Form_auxiliary_0_FunctionSpace_auxiliary_0: public dolfin::FunctionSpace
> {
> public:
>
>
> Form_auxiliary_0_FunctionSpace_auxiliary_0(const dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement
> (boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>
> (new poisson_auxiliary_0_dof_map_0()), mesh)))
> {
> // Do nothing
> }
>
> Form_auxiliary_0_FunctionSpace_auxiliary_0(dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_auxiliary_0_dof_map_0()), mesh)))
> {
> // Do nothing
> }
>
> Form_auxiliary_0_FunctionSpace_auxiliary_0(boost::shared_ptr<dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_auxiliary_0_dof_map_0()), *mesh)))
> {
> // Do nothing
> }
>
> Form_auxiliary_0_FunctionSpace_auxiliary_0(boost::shared_ptr<const dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_auxiliary_0_dof_map_0()), *mesh)))
> {
> // Do nothing
> }
>
>
> ~Form_auxiliary_0_FunctionSpace_auxiliary_0()
> {
> }
>
> };
>
> class Form_auxiliary_0_FunctionSpace_auxiliary_1: public dolfin::FunctionSpace
> {
> public:
>
>
> Form_auxiliary_0_FunctionSpace_auxiliary_1(const dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement
> (boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>
> (new poisson_auxiliary_0_dof_map_0()), mesh)))
> {
> // Do nothing
> }
>
> Form_auxiliary_0_FunctionSpace_auxiliary_1(dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_auxiliary_0_dof_map_0()), mesh)))
> {
> // Do nothing
> }
>
> Form_auxiliary_0_FunctionSpace_auxiliary_1(boost::shared_ptr<dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_auxiliary_0_dof_map_0()), *mesh)))
> {
> // Do nothing
> }
>
> Form_auxiliary_0_FunctionSpace_auxiliary_1(boost::shared_ptr<const dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_0_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_auxiliary_0_dof_map_0()), *mesh)))
> {
> // Do nothing
> }
>
>
> ~Form_auxiliary_0_FunctionSpace_auxiliary_1()
> {
> }
>
> };
>
> class Form_auxiliary_0: public dolfin::Form
> {
> public:
>
> // Constructor
> Form_auxiliary_0(const dolfin::FunctionSpace& V0, const dolfin::FunctionSpace& V1):
> dolfin::Form(2, 0)
> {
> _function_spaces[0] = reference_to_no_delete_pointer(V0);
> _function_spaces[1] = reference_to_no_delete_pointer(V1);
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_auxiliary_form_0());
> }
>
> // Constructor
> Form_auxiliary_0(boost::shared_ptr<const dolfin::FunctionSpace> V0, boost::shared_ptr<const dolfin::FunctionSpace> V1):
> dolfin::Form(2, 0)
> {
> _function_spaces[0] = V0;
> _function_spaces[1] = V1;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_auxiliary_form_0());
> }
>
> // Destructor
> ~Form_auxiliary_0()
> {}
>
> /// Return the number of the coefficient with this name
> virtual dolfin::uint coefficient_number(const std::string& name) const
> {
> dolfin::error("No coefficients.");
> return 0;
> }
>
> /// Return the name of the coefficient with this number
> virtual std::string coefficient_name(dolfin::uint i) const
> {
> dolfin::error("No coefficients.");
> return "unnamed";
> }
>
> // Typedefs
> typedef Form_auxiliary_0_FunctionSpace_auxiliary_0 TestSpace;
> typedef Form_auxiliary_0_FunctionSpace_auxiliary_1 TrialSpace;
>
> // Coefficients
> };
>
> class Form_auxiliary_1_FunctionSpace_auxiliary_0: public dolfin::FunctionSpace
> {
> public:
>
>
> Form_auxiliary_1_FunctionSpace_auxiliary_0(const dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement
> (boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_1_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>
> (new poisson_auxiliary_1_dof_map_0()), mesh)))
> {
> // Do nothing
> }
>
> Form_auxiliary_1_FunctionSpace_auxiliary_0(dolfin::Mesh & mesh):
> dolfin::FunctionSpace(dolfin::reference_to_no_delete_pointer(mesh),
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_1_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_auxiliary_1_dof_map_0()), mesh)))
> {
> // Do nothing
> }
>
> Form_auxiliary_1_FunctionSpace_auxiliary_0(boost::shared_ptr<dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_1_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_auxiliary_1_dof_map_0()), *mesh)))
> {
> // Do nothing
> }
>
> Form_auxiliary_1_FunctionSpace_auxiliary_0(boost::shared_ptr<const dolfin::Mesh> mesh):
> dolfin::FunctionSpace(mesh,
> boost::shared_ptr<const dolfin::FiniteElement>(new dolfin::FiniteElement(boost::shared_ptr<ufc::finite_element>(new poisson_auxiliary_1_finite_element_0()))),
> boost::shared_ptr<const dolfin::DofMap>(new dolfin::DofMap(boost::shared_ptr<ufc::dof_map>(new poisson_auxiliary_1_dof_map_0()), *mesh)))
> {
> // Do nothing
> }
>
>
> ~Form_auxiliary_1_FunctionSpace_auxiliary_0()
> {
> }
>
> };
>
> class Form_auxiliary_1: public dolfin::Form
> {
> public:
>
> // Constructor
> Form_auxiliary_1(const dolfin::FunctionSpace& V0):
> dolfin::Form(1, 0)
> {
> _function_spaces[0] = reference_to_no_delete_pointer(V0);
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_auxiliary_form_0());
> }
>
> // Constructor
> Form_auxiliary_1(boost::shared_ptr<const dolfin::FunctionSpace> V0):
> dolfin::Form(1, 0)
> {
> _function_spaces[0] = V0;
>
> _ufc_form = boost::shared_ptr<const ufc::form>(new poisson_auxiliary_form_0());
> }
>
> // Destructor
> ~Form_auxiliary_1()
> {}
>
> /// Return the number of the coefficient with this name
> virtual dolfin::uint coefficient_number(const std::string& name) const
> {
> dolfin::error("No coefficients.");
> return 0;
> }
>
> /// Return the name of the coefficient with this number
> virtual std::string coefficient_name(dolfin::uint i) const
> {
> dolfin::error("No coefficients.");
> return "unnamed";
> }
>
> // Typedefs
> typedef Form_auxiliary_1_FunctionSpace_auxiliary_0 TestSpace;
>
> // Coefficients
> };
>
> // Class typedefs
> typedef Form_auxiliary_0 BilinearForm_auxiliary;
> typedef Form_auxiliary_1 LinearForm_auxiliary;
> typedef Form_auxiliary_0::TestSpace FunctionSpace_auxiliary;
>
> } // namespace Poisson
>
> #endif
> # Copyright (C) 2008-2009 Mehdi Nikbakht and Garth N. Wells.
> # Licensed under the GNU GPL Version 3.0 or any later version.
> #
> # The bilinear form a(v, u) and linear form L(v) for
> # Poisson's equation with discontinuities.
> #
> # Compile this form with FFC: ffc-pum -l dolfin Poisson.ufl
> #
>
> elem_cont = FiniteElement("CG", triangle, 1)
> elem_discont = ElementRestriction(elem_cont, dc) # or ec[dc]
>
> element = elem_cont + elem_discont
>
> (vc, vd) = TestFunctions(element)
> (uc, ud) = TrialFunctions(element)
>
> v = vc + vd
> u = uc + ud
>
>
> k = Constant(triangle)
> f = Coefficient(elem_cont)
> w = Coefficient(elem_cont)
> g = Coefficient(elem_cont)
>
> a = w*dot(grad(v), grad(u))*dx + k*inner(vd, ud)*dc #+ (u*v)('-')*dS
> L = v*f*dx - v*g*ds
>
Attachment:
signature.asc
Description: Digital signature
Follow ups
References