From: KIRK, BENJAMIN (JSC-EG) (NASA) <benjamin.kirk-1@na...> - 2005-02-14 15:49:31
I've never been pleased with the whole "attach_assemble_function" approach.
One thought I've had is to leave the assemble() member virtual in the system
and allow the user to define a specific system that overloads the method:
class Poisson: public LinearImplicitSystem
But in some cases this would be overkill. In those cases the user should be
able to provide a functor, as Roy describes. This could then be default
method for the case when the user does not overload the appropriate method.
Roy, could you sketch out the definition of such a functor as you see it so
I can work on incorporating it?
[mailto:libmesh-users-admin@...] On Behalf Of Roy Stogner
Sent: Wednesday, February 09, 2005 12:18 PM
To: Mark Blome
Subject: Re: [Libmesh-users] attach_assemble_function
On Wed, 9 Feb 2005, Mark Blome wrote:
> The problem seems to be that I try to attach an assemble function
> which is defined in my class rather than in global scope.
Exactly. In a sense, the arguments given to a member function are
different: in addition to the stuff like EquationSystems& that you write out
explicitly, the function has to receive a pointer to whatever type "this"
is. The EquationSystems class doesn't know how to give it one.
> However I need to have access to several class members within the
> "assemble_hybridfem" function and hence it has to be defined within my
> class. For the same reason I cannot define the function
> "assemble_hybridfem" as a static member function (then it works).
> My knowledge about C++ seems to be too limited to work around this. Is
> there any way to solve this, or do I have to go back to the
> "put-everything-in-the-main-function" style like in the examples?
The ideal C++ way to solve this is for attach_assemble_function to take a
pointer to some sort of functor class instead of a pointer to a function.
Until such a feature is added, however, you'll have to work around the
I suggest you keep a pointer to your hybridFEM object in global scope,
initialize it before the assembly function ever needs to be called, then
have a static assemble_hybridfem function that uses that global pointer to
call global_object->assemble_hybridfem(...). This works if you've got a
single hybridFEM object to deal with - maybe keep any assignments to the
pointer behind something like assert(global_object == NULL) to catch
failures in that assumption.
If you've got multiple hybridFEM objects to juggle but you have an upper
limit on how many will exist at once, you can create an array of static
"assemble1", "assemble2", etc. functions and assign each to its own object.
The hybridFEM constructor can pick an unassigned function and point the
associated pointer to itself, and the destructor can NULL the pointer again.
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
Libmesh-users mailing list