This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Error with Dirichlet BC in C++ implementation

0 votes

Hello,

I am trying to modifiy the undocumented elastodynamics [demo][1] which deals with a nonlinear weak form, to a linear weak form. However, post editing, when I generated and ran the demo file, it gives the following error:

Error: Unable to create Dirichlet boundary condition.
*** Reason: Expecting a vector-valued boundary value but given function is scalar.
*** Where: This error was encountered inside DirichletBC.cpp.

The DBC has been defined as:

  DirichletBC bcl(V, S, left);
  DirichletBC bct(V, c, top);
  DirichletBC bcr(V, c, right);
  DirichletBC bcb(V, c, bottom);

  // Collect all DBC in one container 'bcs'
  // std::vector<const DirichletBC*> bcs = {{&bcl, &bcr, &bcb, &bct}};
  std::vector<const DirichletBC*> bcs;
  bcs.push_back(&bcl); bcs.push_back(&bcr); bcs.push_back(&bcb); bcs.push_back(&bct);
asked Jun 11, 2016 by Chaitanya_Raj_Goyal FEniCS User (4,150 points)
edited Jun 14, 2016 by Chaitanya_Raj_Goyal

1 Answer

0 votes
 
Best answer

Hi,
the error is encountered inside of the Source class (you have not defined the dimension of the Source objects and in consequence by default is taken as 1).

To solve your problem change the Source to:

class Source : public Expression
{
public:

  //Constructor
  Source() : Expression(2), t(0) {}

  // Evaluate incoming wave
  void eval(Array<double>& values, const Array<double>& x) const
  {
  values[0] = sin(2.0*DOLFIN_PI*5.0*t);
  values[1] = 0.0;
  }

  //Current time
  double t;
};
answered Jun 11, 2016 by hernan_mella FEniCS Expert (19,460 points)
selected Jun 11, 2016 by Chaitanya_Raj_Goyal

Thanks a lot Hernan!

...