[Dune] PSI Summer Student Dune Question

Jö Fahlke jorrit at jorrit.de
Mon Jul 27 13:59:21 CEST 2009


Am Mon, 27. Jul 2009, 13:27:11 +0200 schrieb Aleksejs Fomins:
> I am a summer student working at PSI.
> I am working on a project Hades with Dr. Benedikt Oswald.
> My task at the moment is implementing base functions.
> 
> Could you please suggest a way to declare a constant FieldVector using 3 
> given coordinates in Dune.
> If it was just an array, I would have written something like
> const double myVector[3] = {myXcoordinate, myYcoordinate, myZcoordinate};

This is really difficult in C++ -- the new upcoming standars supports this
kind of stuff, but with the current standard it is a pain.  There are two
possibilities:

 a) don't make the vector constant, and assign values to the elements after
    initialization:

    FieldVector<double, 3> unity_x(0);
    unity_x[0] = 1;

 b) make a function which will create a FieldVector and use that to initialize
    the other vector:

    template<typename ct>
    FieldVector<ct,3> makeFieldVector(ct x, ct y, ct z) {
      FieldVector<ct,3> ret;
      ret[0] = x;
      ret[1] = y;
      ret[2] = z;
      return ret;
    }
    const FieldVector<double, 3> unity_x(makeFieldVector(1.0, 0.0, 0.0));

    Of course, this solution is only really possible if you really only want
    to support FieldVectors of a certain length.  And it is probably much more
    inefficient than a) due to the two copying operations required.

Bye,
Jö.

-- 
It is my conviction that killing under the cloak of war is nothing but
an act of murder.
-- Albert Einstein
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20090727/8b14b3e5/attachment.sig>


More information about the Dune mailing list