#ifndef NONLINCF_H #define NONLINCF_H #include <fem.hpp> #include <solve.hpp> #include <ngstd.hpp> #include <vector> #include <cmath> #include <memory> #include <iostream> #include <cmath> #include <cstring> #include "../basicClasses/ngData_class.h" #include "../basicClasses/magCurve.h" using namespace ngstd; using namespace ngfem; using namespace ngsolve; using namespace ngcomp; // #define _Pi 3.141592653589793 template <unsigned int DIM> std::pair<unsigned int, unsigned int> findNearestNeighbour(const vector<vector<MappedIntegrationPoint<DIM, DIM>> > & mips, const BaseMappedIntegrationPoint& mip); template <typename T, unsigned int DIM> class nonLinCF:public ngScalar_class<T, DIM> { public: nonLinCF(shared_ptr<MeshAccess>& mesh, IntegrationRule& intrule, const shared_ptr<CoefficientFunction>& ptrInput, vector<double> H_KL, vector<double> B_KL, const std::string cFieldIn="H", const std::string cFieldOut="B", const shared_ptr<CoefficientFunction>& ptrMask=nullptr, unsigned int order=1); ~nonLinCF() = default; bool HasConverged(double aMeanError, double aMaxError, bool print_it=true); void Update(); void UpdateEnergyDensity(); const shared_ptr<ngScalar_class<T, DIM>> GetEnergyDensity(); const shared_ptr<ngScalar_class<T, DIM>> GetIterationError(); nonLinCF<T, DIM> Integrate(); unsigned int getOrder() const; KL GetKL(); shared_ptr<CoefficientFunction> GetInputCF() const; void SetInputCF(shared_ptr<CoefficientFunction>) ; NGS_DLL_HEADER AutoDiff<1,double> operator() (AutoDiff<1,double> x) const; virtual void Evaluate (const BaseMappedIntegrationRule & ir, BareSliceMatrix<AutoDiff<1,double>> values) const{ // cout << ir.Size() << " " << 2*values.Dist() << " " << &values(0).Value() << endl; // SliceMatrix<double> hvalues(ir.Size(), 1, 2*values.Dist(), &values(0).Value()); // Evaluate (ir, hvalues); for (size_t i = 0; i < ir.Size(); i++) for (size_t j = this->Dimension(); j-- > 0; ) values(i,j) = this->operator()(values(i,j)); // // MappedIntegrationRule<DIM_MESH, DIM_MESH> mappedrule(intrule, mesh->GetTrafo(el, global_alloc), global_alloc); // mips[el].resize(intrule.GetNIP()); // for (ip = 0;ip < intrule.GetNIP();ip++) { // // MappedIntegrationPoint<DIM_MESH, DIM_MESH> mip((intrule)[ip], mesh->GetTrafo(el, global_alloc)); // mips[el][ip] = { (intrule)[ip], mesh->GetTrafo(el, global_alloc) }; // *values.Data() = this->operator()(*(values.Data())); } // NGS_DLL_HEADER SIMD<Complex> operator() (SIMD<Complex> x) const; private: shared_ptr<CoefficientFunction> ptrInput; const std::string sFieldIn; const std::string sFieldOut; using ngScalar_class<T, DIM>::data; using ngScalar_class<T, DIM>::mips; // data shared_ptr<ngScalar_class<double, DIM>> ptrError; shared_ptr<ngScalar_class<T, DIM>> ptrEnergyDens; std::shared_ptr<KL> oKL; double meanError; double maxError; }; #endif /* NONLINCF_H */