You have to be a bit careful - unfortunately, C++ has one of the most convoluted rules when objects are zero initialized or not.
As a rule of thumb: * whenever you are working with a plain "double", "float", "int", etc. it is best to explicitly initialize the variable (because C++ in most cases does not initialize the variable for you): unsigned int i = 0; double d = 0.; float f = 0.; * in case of a "container" like std::vector, dealii::Vector, dealii::Tensor elements are default initialized: dealii::Tensor<1, dim> t; // zeroes elements dealii::Vector<double> V; V.reinit(10); // zeroes elements std::vector<double> v; v.resize(10); // zeroes elements I do not understand your second question :-( Best, Matthias On Wed, Dec 9, 2020, at 09:43 CST, Chenyi LUO <swan...@gmail.com> wrote: > Hi dealii developers, > > I would like to ask(confirm)whether zero is the initial value of > different-type data, e.g. for double, int, Vector and Tensor. For > example, if I just define double x;. Does x have an initial value of 0.0? > > Moreover, in my task, I set initial values of a variable, e.g. "a", to > be one in the whole domain. When I assemble the residual vector, I need > to first compute the value of "a" at quadrature points (which turns out > not exactly 1.0). Consequently, when I compute, e.g. "3*a^4-2*a^3+a^2", > the answer is not zero. Is it avoidable? > > Best, > > Chenyi -- The deal.II project is located at http://www.dealii.org/ For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en --- You received this message because you are subscribed to the Google Groups "deal.II User Group" group. To unsubscribe from this group and stop receiving emails from it, send an email to dealii+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/87blf2ud45.fsf%4043-1.org.