dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #19910
Re: [Question #129296]: defining a discrete function
On Thursday October 14 2010 15:34:09 Jack wrote:
> Question #129296 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/129296
>
> Jack requested for more information:
> Thanks again, Johan, works brilliantly.
>
> If I may just impose on you again.
>
> The only part of my code that now breaks down with MPI is where I have
> to allocate to each member of a std::vector, the corresponding values
> from a Function u, i.e.,
>
> int j = 0;
> for (std::vector<foo*>::iterator p = instances.begin(); p !=
> instances.end(); ++p) { (*p)->set_value( u.vector()[j] );
> ++j;
> }
If instances is a std::vector of size v.local_size() then you should be able
to do something like:
Array<double> values(v.size());
v.get_local(values);
for (std::vector<foo*>::iterator p = instances.begin(); p !=
instances.end(); ++p) { (*p)->set_value( values[j] );
++j;
}
Johan
> Is there a way to reduce this to the local size of the u vector and
> associate the correct local range?
>
> Many thanks
>
> Jack
Follow ups
References