/* This file is part of Lemma, a geophysical modelling and inversion API. * More information is available at http://lemmasoftware.org */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /** * @file * @date 03/21/2016 02:10:08 PM * @version $Id$ * @author Trevor Irons (ti) * @email tirons@egi.utah.edu * @copyright Copyright (c) 2016, University of Utah * @copyright Copyright (c) 2016, Lemma Software, LLC */ #include "LinearMag.h" namespace Lemma { // ==================== FRIEND METHODS ===================== #ifdef HAVE_YAMLCPP std::ostream &operator << (std::ostream &stream, const LinearMag &ob) { stream << ob.Serialize() << "\n---\n"; // End of doc --- as a direct stream should encapsulate thingy return stream; } #else std::ostream &operator<<(std::ostream &stream, const LinearMag& ob) { stream << *(FEM4EllipticPDE*)(&ob); return stream; } #endif // ==================== LIFECYCLE ======================= //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: LinearMag // Description: constructor (protected) //-------------------------------------------------------------------------------------- LinearMag::LinearMag (const std::string& name) : FEM4EllipticPDE(name) { } // ----- end of method LinearMag::LinearMag (constructor) ----- #ifdef HAVE_YAMLCPP //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: LinearMag // Description: DeSerializing constructor (protected) //-------------------------------------------------------------------------------------- LinearMag::LinearMag (const YAML::Node& node) : FEM4EllipticPDE(node) { } // ----- end of method LinearMag::LinearMag (constructor) ----- #endif //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: New() // Description: public constructor //-------------------------------------------------------------------------------------- LinearMag* LinearMag::New() { LinearMag* Obj = new LinearMag("LinearMag"); Obj->AttachTo(Obj); return Obj; } //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: ~LinearMag // Description: destructor (protected) //-------------------------------------------------------------------------------------- LinearMag::~LinearMag () { } // ----- end of method LinearMag::~LinearMag (destructor) ----- //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: Delete // Description: public destructor //-------------------------------------------------------------------------------------- void LinearMag::Delete() { this->DetachFrom(this); } //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: Release // Description: destructor (protected) //-------------------------------------------------------------------------------------- void LinearMag::Release() { delete this; } #ifdef HAVE_YAMLCPP //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: Serialize //-------------------------------------------------------------------------------------- YAML::Node LinearMag::Serialize ( ) const { YAML::Node node = FEM4EllipticPDE::Serialize();; node.SetTag( this->Name ); // FILL IN CLASS SPECIFICS HERE node["B0"] = B0; return node; } // ----- end of method LinearMag::Serialize ----- //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: DeSerialize //-------------------------------------------------------------------------------------- LinearMag* LinearMag::DeSerialize ( const YAML::Node& node ) { LinearMag* Object = new LinearMag(node); Object->AttachTo(Object); DESERIALIZECHECK( node, Object ) return Object ; } // ----- end of method LinearMag::DeSerialize ----- #endif //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: SetInducingMagField //-------------------------------------------------------------------------------------- void LinearMag::SetInducingMagField ( const Real& intensity, const Real& inc, const Real& dec, const MAGUNITS& U ) { B0(0) = intensity * std::cos(inc) * std::cos(dec); // northing B0(1) = intensity * std::cos(inc) * std::sin(dec); // easting B0(2) = intensity * std::sin(inc); // z ScaleB0(U); return ; } // ----- end of method LinearMag::SetInducingMagField ----- //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: SetInducingMagFieldVector //-------------------------------------------------------------------------------------- void LinearMag::SetInducingMagFieldVector ( const Vector3r& BB0, const MAGUNITS& U ) { B0 = BB0; ScaleB0(U); return ; } // ----- end of method LinearMag::SetInducingMagFieldVector ----- //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: ScaleB0 //-------------------------------------------------------------------------------------- void LinearMag::ScaleB0 ( const MAGUNITS& U ) { switch ( U ) { case TESLA: break; case NANOTESLA: B0 *= 1e-9; break; case GAUSS: B0 *= 1e-4; break; } return ; } // ----- end of method LinearMag::ScaleB0 ----- //-------------------------------------------------------------------------------------- // Class: LinearMag // Method: CalculateRHS //-------------------------------------------------------------------------------------- void LinearMag::CalculateRHS ( const std::string& susName ) { vtkDoubleArray* G = vtkDoubleArray::New(); G->SetNumberOfComponents(1); G->SetNumberOfTuples( vtkGrid->GetNumberOfPoints() ); G->SetName("G"); // Iterate over all the points or all of the cells? for (int ic=0; ic < vtkGrid->GetNumberOfCells(); ++ic) { Real cellSus = vtkGrid->GetCellData()->GetScalars(susName.c_str())->GetTuple(ic)[0]; Eigen::Matrix C = Eigen::Matrix::Zero() ; for (int ii=0; ii<4; ++ii) { double* pts = vtkGrid->GetCell(ic)->GetPoints()->GetPoint(ii); C(ii, 0) = 1; C(ii, 1) = pts[0]; C(ii, 2) = pts[1]; C(ii, 3) = pts[2]; } /* The indices */ vtkIdList* Ids = vtkGrid->GetCell(ic)->GetPointIds(); int ID[4]; ID[0] = Ids->GetId(0); ID[1] = Ids->GetId(1); ID[2] = Ids->GetId(2); ID[3] = Ids->GetId(3); /* the 4 faces of the tetrahedra ID[0] ID[1] ID[2] ID[0] ID[1] ID[3] ID[0] ID[2] ID[3] ID[1] ID[2] ID[3] */ // Face 0, ID 0,1,2 /* Eigen::Matrix CC = Eigen::Matrix::Ones() ; { CC.col(1) = C.row(0).tail<3>() - C.row(1).tail<3>(); CC.col(2) = C.row(0).tail<3>() - C.row(2).tail<3>(); Vector3r nhat = CC.col(1).cross(CC.col(2)); nhat.array() /= nhat.norm(); Real flux = cellSus*nhat.dot(B0); g(ID[0]) += flux; g(ID[1]) += flux; g(ID[2]) += flux; // vtkGrid->GetPointData()->GetScalars("G")->GetTuple1(ID[2])*TA/3. * i4pi ; } */ } vtkGrid->GetPointData()->AddArray( G ); return ; } // ----- end of method LinearMag::CalculateRHS ----- } // ----- end of Lemma name -----