Binding an Object to Each Node

Asked by Ted Kord on 2010-01-10

Hello

Is there away to :

1. create and bind an object to each node in space.

2. have the object automatically update its state at every time step.

My original approach was to create a pointer to the object in a subclass of expression ...... but the solution turns out to be the same the same at each time step. So, I know I'm definitely doing something wrong.

Thanks in advance

Ted

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Ted Kord
Solved:
2010-01-10
Last query:
2010-01-10
Last reply:
2010-01-10
Anders Logg (logg) said : #1

On Sun, Jan 10, 2010 at 07:02:22AM -0000, Ted Kord wrote:
> New question #96848 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/96848
>
> Hello
>
> Is there away to :
>
> 1. create and bind an object to each node in space.
>
> 2. have the object automatically update its state at every time step.
>
> My original approach was to create a pointer to the object in a subclass of expression ...... but the solution turns out to be the same the same at each time step. So, I know I'm definitely doing something wrong.
>
> Thanks in advance
>
> Ted

When you create a subclass of Expression, you can do whatever you like
as part of that class, for example by putting a vector of objects as a
member variable of your class.

But remember that for a time-dependent problem, you must yourself
update the value of t between time steps. Here's a sketch:

class MyExpression : public Expression
{
public:

   MyExpression(const Mesh& mesh)
   {
     for (int i = 0; i < mesh.num_vertices(); ++i)
     {
       objects.push_back(...);
     }
   }

   void eval(...)
   {
     ...
   }

   void update(double t)
   {
     this->t = t;
   }

private:

   double t;
   std::vector<Class> objects;

};

Then do something like this in your code:

  MyExpression w(mesh);

  while (t < T)
  {
    w.update(t);

    solve

    t += dt;
  }

--
Anders

Ted Kord (teddy-kord) said : #2

Thanks, Anders. That solves some parts of my question. It may actually solve all of it but maybe I'm just not aware of it.

Does this uniquely associate a vertex to a cell though?

I'm thinking of doing the following:

1. Creating a Vertex class
2. Returning the coordinates of each vertex and binding each coordinate to a different object.
3. Testing for equality of coordinates in the eval function of the Expresssion class.

Does this seem reasonable or is it overkill?

Incidentally, what does the index argument in the Vertex class definition below refer to, i.e.,

Vertex (const Mesh &mesh, uint index)

Thanks.

Ted

Ted Kord (teddy-kord) said : #3

I was finally able to resolve this with a combination of what you suggested Anders and the procedure I outlined above. But, instead of just the Vertex class, I used the VertexIterator and a MeshGeometry instance.

Thanks.

Ted