diff --git a/include/utils/ComplexTypes.h b/include/utils/ComplexTypes.h new file mode 100644 index 00000000..3caddeb3 --- /dev/null +++ b/include/utils/ComplexTypes.h @@ -0,0 +1,57 @@ +/**********************************************************************/ +/* DO NOT MODIFY THIS HEADER */ +/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */ +/* */ +/* Copyright 2017 Battelle Energy Alliance, LLC */ +/* ALL RIGHTS RESERVED */ +/**********************************************************************/ + +#pragma once + +#include + +#include "RankTwoTensor.h" +#include "RankThreeTensor.h" +#include "RankFourTensor.h" + +#include "libmesh/vector_value.h" + +typedef std::complex Complex; +typedef VectorValue> ComplexVectorValue; +typedef RankTwoTensorTempl> ComplexRankTwoTensor; +typedef RankThreeTensorTempl> ComplexRankThreeTensor; +typedef RankFourTensorTempl> ComplexRankFourTensor; + +// helper template to select the corresponding complex tensor type +template +struct ComplexType; + +template <> +struct ComplexType +{ + using type = Complex; +}; + +template <> +struct ComplexType +{ + using type = ComplexVectorValue; +}; + +template <> +struct ComplexType +{ + using type = ComplexRankTwoTensor; +}; + +template <> +struct ComplexType +{ + using type = ComplexRankThreeTensor; +}; + +template <> +struct ComplexType +{ + using type = ComplexRankFourTensor; +}; diff --git a/src/utils/ComplexTypes.C b/src/utils/ComplexTypes.C new file mode 100644 index 00000000..489ea50e --- /dev/null +++ b/src/utils/ComplexTypes.C @@ -0,0 +1,44 @@ +/**********************************************************************/ +/* DO NOT MODIFY THIS HEADER */ +/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */ +/* */ +/* Copyright 2017 Battelle Energy Alliance, LLC */ +/* ALL RIGHTS RESERVED */ +/**********************************************************************/ + +#include "ComplexTypes.h" +#include "MooseError.h" +#include "MooseUtils.h" + +namespace MooseUtils +{ + +template <> +bool +absoluteFuzzyEqual(const std::complex & var1, + const std::complex & var2, + const std::complex & tol) +{ + return (std::abs(var1 - var2) <= std::abs(tol)); +} + +template <> +bool +absoluteFuzzyEqual(const std::complex & var1, + const Real & var2, + const std::complex & tol) +{ + return (std::abs(var1 - var2) <= std::abs(tol)); +} + +} // namespace MooseUtils + +#include "RankTwoTensorImplementation.h" +#include "RankThreeTensorImplementation.h" +#include "RankFourTensorImplementation.h" + +template class VectorValue>; + +template class RankTwoTensorTempl>; +template class RankThreeTensorTempl>; +template class RankFourTensorTempl>; diff --git a/unit/src/ComplexTypesTest.C b/unit/src/ComplexTypesTest.C new file mode 100644 index 00000000..98635a43 --- /dev/null +++ b/unit/src/ComplexTypesTest.C @@ -0,0 +1,36 @@ +/****************************************************************/ +/* DO NOT MODIFY THIS HEADER */ +/* MOOSE - Multiphysics Object Oriented Simulation Environment */ +/* */ +/* (c) 2010 Battelle Energy Alliance, LLC */ +/* ALL RIGHTS RESERVED */ +/* */ +/* Prepared by Battelle Energy Alliance, LLC */ +/* Under Contract No. DE-AC07-05ID14517 */ +/* With the U. S. Department of Energy */ +/* */ +/* See COPYRIGHT for full restrictions */ +/****************************************************************/ +#include +#include + +#include "ComplexTypes.h" + +TEST(ComplexTypesTest, rankTwo) +{ + Complex c_1; + ComplexType::type c_2; + auto c = c_1 + c_2; + + ComplexVectorValue v_1; + ComplexType::type v_2; + auto v = v_1 + v_2; + + ComplexRankTwoTensor r2_1; + ComplexType::type r2_2; + auto r2 = r2_1 + r2_2; + + ComplexRankThreeTensor r3_1; + ComplexType::type r3_2; + auto r3 = r3_1 + r3_2; +}