Thank you, Roy.
Code runs but sets the Dirichlet b.c to zero, instead to the value I want.
This is what I have done:
class BcFunction : public FunctionBase<Number>
{
 virtual Number    component (unsigned int i, const Point &p, Real time=0.)
  {
    if (i == 0) return 2.0;
    if (i == 1) return 2.0;
    if (i == 2) return 300.0;
    if (i == 3) return 300.0;
  }
  virtual Number     operator() (const Point &p, const Real time=0.)
  {
    libmesh_error();
  }

virtual void operator() (const Point &p, const Real time, DenseVector< Number > &output)
  {
    libmesh_error();
  }

  virtual UniquePtr<FunctionBase<Number> > clone() const
  {
    return UniquePtr<FunctionBase<Number> >(new BcFunction());
  }
};
BcFunction  func;

DirichletBoundary dirichlet_bc_v(boundary_ids, variables, func,LOCAL_VARIABLE_ORDER);

system.get_dof_map().add_dirichlet_boundary(dirichlet_bc_v);

Does it look correct? May be I should implement something else in addition to component()?
Thank you,
Michael.

On 6/15/2017 5:32 PM, Roy Stogner wrote:

On Thu, 15 Jun 2017, Michael Povolotskyi wrote:

 I'm fine with creating a child of FunctionBase.
 Will it be enough to override only the component() method?

You'll have to override operator() with *something*, even if only
libmesh_error(), since IIRC it's pure virtual.  If you do go the
libmesh_error() route your code should work fine for now, but be
forewarned that it may then break with some libMesh release in the
future.
---
Roy

 On 6/15/2017 5:08 PM, Roy Stogner wrote:
> >   On Thu, 15 Jun 2017, Michael Povolotskyi wrote:
> > >   AnalyticFunction<> dirichlet_function_object(zero1);
> > >   void zero1(DenseVector<Number> & output,
> >                       const Point & p,
> >                       const Real)
> >   {
> >    output(0) = 0;  output(1) = 0;
> >     output(2) = 10; output(3) = 10;
> > > >   }
> > > > Unfortunately, this does not work. Somehow argument output in the > > function zero1 has 2 components. Most likely I'm doing something wrong. > > You're suffering from the interaction of a couple questionable design
>   decisions, is all.  Sorry!
> > AnalyticFunction::component(i) only resizes output to be large enough > to fill i, because it doesn't actually know how large an output vector
>   your C function is ready to handle.
> > The internal dirichlet boundary constraint code iterates one variable > at a time, and uses component() to query values of just that variable,
>   because it's complicated enough code even without trying to project
>   multiple variables at once.
> > >   Could you, please, tell me how to achieve what I want
> > Most easily? Just test output.size() and only fill indices below that
>   size.
> >   Most efficiently?  Subclass FunctionBase yourself and override
>   component() too.
> > >   or point me to a similar example?
> >   I don't think there is one!  introduction_ex4 and ex5 use
>   AnalyticFunction with DirichletBoundary, but only for a single
> solution variable. All the multi-variable DirichletBoundary examples
>   appear to be using subclassing.
>   ---
>   Roy




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Libmesh-users mailing list
Libmesh-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libmesh-users



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Libmesh-users mailing list
Libmesh-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libmesh-users

Reply via email to