How use scalar type and complex type at the same time?

Barry Smith bsmith at
Wed Aug 20 08:44:43 CDT 2008

On Aug 20, 2008, at 7:42 AM, Matthew Knepley wrote:

> On Wed, Aug 20, 2008 at 7:19 AM, Zhifeng Sheng  
> <z.sheng at> wrote:
>> Dear all
>> I am working on a FEM program, which can be used to solve time  
>> domain and
>> frequency domain EM problems. I finished the time domain solver  
>> part and now
>> I need to implement the frequency domain solver.... So I built  
>> Petsc with
>> --scalar-type = complex, and then my time domain solver can not be  
>> compiled,
>> it says " can not convert double to PetscScalar".
>> Is there any way that I can handle both real matrix and complex  
>> matrix at
>> the same time? (without changing my old code too much?)
> Right now, there is no way to do this, and there seems to be little
> possibility in C.
> Templating can handle this smoothly, but we would have to convert to  
> C++. We

     Templating this can handle it; but it definitely cannot handle it  
SMOOTHLY! If it could
handle it smoothly we would have switched a long time ago!  The  
problem with C++
templating is that since it is compile time (and source code based,  
that is the template information
must be directly wired into the source code), one must indicate  
directly in the code the
type it is templated over, this then eliminates the awesome power of  
the data encapsulation.
Yes, since C++ is a Turing language one can get around this, but the  
extra complexity of working
around the basic design of templates in C++ makes the "getting around"  
worrisomely painful
thus we have not penetrated in that direction.

    Convince me otherwise!


> are weighing the options.
>  Matt
>> Thanks
>> Best regards
>> Zhifeng Sheng
> -- 
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which
> their experiments lead.
> -- Norbert Wiener

More information about the petsc-users mailing list