[SOLVED] Cmake compilation error, fix identifier is undefined

Hi everyone,

I am trying to write a new fix derived from ave/time to compute the variance of data the same way the latter fix computes averages. I’ve given them the generic name fix_variance_time.h/cpp.

In my header file, I’ve changed the style macro to

#ifdef FIX_CLASS
// clang-format off
FixStyle(variance/time,FixVarTime);
// clang-format on
#else

and renamed the class FixVarTime everywhere the FixAveTime name was present. I’ve done this in the .cpp file as well.

However when compiling (using cmake), I get the following error:

error: identifier "FixVarTime" is undefined
  (*fix_map)["variance/time"] = &style_creator<Fix, FixVarTime>;;

I understand this comes from the macros and that this happens when compiling the modify.cpp file. But looking at the generated styles_fix.h file, I see that the imported file is correctly named fix_variance_time.h. When looking at where the FixAveTime and FixVarTime where changed using grep, I see no other place where I might have forgotten to change it in both files (this was done automatically using a vim command).

Is there anything I am missing here? Where could this error stem from? Any help is welcome since I am a bit unsure on how these macro work and where to look.

I am not addressing the topic directly, but a quick workaround is to average a quantity and its squared value simultaneously and then compute and propagate the variance in post-processing.

The most common reason is that you have misspelled the class name.
The second most common reason is that you have copied and modified the header file and forgot to change the include guards.

1 Like

Spot on: the file still contained

#ifndef LMP_FIX_AVE_TIME_H
#define LMP_FIX_AVE_TIME_H

I didn’t pay attention and overlooked those in the header file. Many thanks. I hope this pops up if anyone else has the same issue. I didn’t find it in the forum.

@hothello: The goal is to avoid using this trick since it is numerically less stable than traditional two pass algorithm or the Welford’s method I am trying to implement, especially for big numbers. See this blog post for an example.

1 Like

I wasn’t aware of Welford’s method. Thank you for pointing that out.