dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #18553
Re: [Question #114825]: DirichletBC virtual methods
Question #114825 on DOLFIN changed:
https://answers.launchpad.net/dolfin/+question/114825
Status: Open => Answered
Andre Massing proposed the following answer:
Onsdag 16. juni 2010 17.55.35 skrev Phil Marinier :
> New question #114825 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/114825
>
> I need to make many instances of DirichletBC, but I exactly how many is a
> user function. As such, I am using a loop to create my bcs.
>
>
> for(int j = 0; j < numberCathodes; j++){
>
> cathode = &cathodes[j];
>
> //assemble
> CathodeBC(iInit, cathode, phiCBC0);
>
> // create anodic and cathodic boundary condition Functions from BCs
> numRows = PhiCBC0.vector().size();
> rows = new dolfin::uint[numRows];
> for(dolfin::uint j = 0; j < numRows; j ++)
> rows[j] = j;
> PhiCBC0.vector().set(phiCBC0, numRows, rows);
> delete [] rows;
>
> //Define boundary condition
> DirichletBC cbc0(V, PhiCBC0, *cathode);
> bcsTEMP.push_back(cbc0);
> }
>
> where bcsTEMP is a std::vector<dolfin::DirichletBC>
>
> This does not work, since DirichletBC is abstract and so I can't make it a
> type for a vector.
As far as I can see is DirichletBC is not abstract. Did you mean the
BoundaryCondition class?
> Trying to use pointers will obviously not work, since
> once the object goes out of scope, it is cleaned up, and I end up
> following a dangling pointer to nowhere.
Hmm, maybe I miss a point here, but why does it not work for pointers?
If you add your boundary conditions by
std::vector<const BoundaryCondition*> bcs;
bcs.push_back( new YourFancyBoundaryConditionClass(.....) );
you can just go through the vector bcs and delete your objects before bcs is
going out of scope.
>
> I am going to make my own class called dirichletBC, the only difference
> being that I over load the apply() method, since it is the one that is
> virtual. My question is which apply() should I use?
>
> Since my VariationalProblem is Laplaces equation with a single bilinear
> form and a single linear form ( a(V, V) and L(V) ), I assume that I need
> to apply the boundary condition to a matrix and a vector, hence using:
>
> 00171 void DirichletBC::apply(GenericMatrix& A, GenericVector& b) const
> 00172 {
> 00173 apply(&A, &b, 0);
> 00174 }
>
> Is that right? Is there something else I need to do to make this work? is
> there an easier way to make this work? Do you need more information about
> my problem?
>
> Thank you for your help.
--
You received this question notification because you are a member of
DOLFIN Team, which is an answer contact for DOLFIN.