示例#1
0
//-----------------------------------------------------------------------------
void AssemblerBase::check(const Form& a)
{
    dolfin_assert(a.ufc_form());

    // Check the form
    a.check();

    // Extract mesh and coefficients
    const Mesh& mesh = a.mesh();
    const std::vector<std::shared_ptr<const GenericFunction>>
            coefficients = a.coefficients();

    // Check that we get the correct number of coefficients
    if (coefficients.size() != a.num_coefficients())
    {
        dolfin_error("AssemblerBase.cpp",
                     "assemble form",
                     "Incorrect number of coefficients (got %d but expecting %d)",
                     coefficients.size(), a.num_coefficients());
    }

    // Check that all coefficients have valid value dimensions
    for (std::size_t i = 0; i < coefficients.size(); ++i)
    {
        if (!coefficients[i])
        {
            dolfin_error("AssemblerBase.cpp",
                         "assemble form",
                         "Coefficient number %d (\"%s\") has not been set",
                         i, a.coefficient_name(i).c_str());
        }

        // unique_ptr deletes its object when it exits its scope
        std::unique_ptr<ufc::finite_element>
        fe(a.ufc_form()->create_finite_element(i + a.rank()));

        // Checks out-commented since they only work for Functions, not
        // Expressions
        const std::size_t r = coefficients[i]->value_rank();
        const std::size_t fe_r = fe->value_rank();
        if (fe_r != r)
        {
            dolfin_error("AssemblerBase.cpp",
                         "assemble form",
                         "Invalid value rank for coefficient %d (got %d but expecting %d). \
You might have forgotten to specify the value rank correctly in an Expression subclass", i, r, fe_r);
        }

        for (std::size_t j = 0; j < r; ++j)
        {
            const std::size_t dim = coefficients[i]->value_dimension(j);
            const std::size_t fe_dim = fe->value_dimension(j);
            if (dim != fe_dim)
            {
                dolfin_error("AssemblerBase.cpp",
                             "assemble form",
                             "Invalid value dimension %d for coefficient %d (got %d but expecting %d). \
You might have forgotten to specify the value dimension correctly in an Expression subclass", j, i, dim, fe_dim);
            }
        }
// ----------------------------------------------------------------------------
double AdaptiveLinearVariationalSolver::
evaluate_goal(Form& M, std::shared_ptr<const Function> u) const
{
  dolfin_assert(M.num_coefficients() > 0);
  M.set_coefficient(M.num_coefficients() - 1, u);
  return assemble(M);
}