|
| 1 | +/* |
| 2 | +For more information, please see: http://software.sci.utah.edu |
| 3 | +
|
| 4 | +The MIT License |
| 5 | +
|
| 6 | +Copyright (c) 2015 Scientific Computing and Imaging Institute, |
| 7 | +University of Utah. |
| 8 | +
|
| 9 | +
|
| 10 | +Permission is hereby granted, free of charge, to any person obtaining a |
| 11 | +copy of this software and associated documentation files (the "Software"), |
| 12 | +to deal in the Software without restriction, including without limitation |
| 13 | +the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 14 | +and/or sell copies of the Software, and to permit persons to whom the |
| 15 | +Software is furnished to do so, subject to the following conditions: |
| 16 | +
|
| 17 | +The above copyright notice and this permission notice shall be included |
| 18 | +in all copies or substantial portions of the Software. |
| 19 | +
|
| 20 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 21 | +OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 23 | +THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 25 | +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 26 | +DEALINGS IN THE SOFTWARE. |
| 27 | +*/ |
| 28 | + |
| 29 | +/* |
| 30 | +* ApplyFEMVoltageSource.cc: Builds the RHS of the FE matrix for voltage sources |
| 31 | +* |
| 32 | +* Written by: |
| 33 | +* David Weinstein |
| 34 | +* University of Utah |
| 35 | +* May 1999 |
| 36 | +* Modified by: |
| 37 | +* Alexei Samsonov, March 2001 |
| 38 | +* Frank B. Sachse, February 2006 |
| 39 | +* |
| 40 | +*/ |
| 41 | + |
| 42 | +#include <Core/Algorithms/Legacy/FiniteElements/ApplyFEM/ApplyFEMVoltageSourceAlgo.h> |
| 43 | + |
| 44 | +#include <Core/Datatypes/Matrix.h> |
| 45 | +#include <Core/Datatypes/DenseMatrix.h> |
| 46 | +#include <Core/Datatypes/DenseColumnMatrix.h> |
| 47 | +#include <Core/Datatypes/SparseRowMatrix.h> |
| 48 | +#include <Core/Datatypes/MatrixTypeConversions.h> |
| 49 | +#include <Core/Datatypes/Legacy/Field/Mesh.h> |
| 50 | +#include <Core/Datatypes/Legacy/Field/VMesh.h> |
| 51 | +#include <Core/Datatypes/Legacy/Field/VField.h> |
| 52 | +#include <Core/Datatypes/Legacy/Field/Field.h> |
| 53 | +#include <Core/Datatypes/Legacy/Field/FieldInformation.h> |
| 54 | +#include <Core/Logging/LoggerInterface.h> |
| 55 | + |
| 56 | +#include <Dataflow/Network/Module.h> |
| 57 | +#include <vector> |
| 58 | + |
| 59 | +using namespace SCIRun; |
| 60 | +using namespace SCIRun::Core::Algorithms; |
| 61 | +using namespace SCIRun::Core::Algorithms::FiniteElements; |
| 62 | +using namespace SCIRun::Core::Datatypes; |
| 63 | +using namespace SCIRun::Core::Geometry; |
| 64 | + |
| 65 | +ApplyFEMVoltageSourceAlgo::ApplyFEMVoltageSourceAlgo() |
| 66 | +{ |
| 67 | + |
| 68 | +} |
| 69 | + |
| 70 | + |
| 71 | +void ApplyFEMVoltageSourceAlgo::ExecuteAlgorithm(const DenseMatrixHandle& dirBC, DenseColumnMatrixHandle& rhs, SparseRowMatrixHandle& mat) |
| 72 | +{ |
| 73 | + //! adjusting matrix for Dirichlet BC |
| 74 | + index_type *idcNz; |
| 75 | + double *valNz; |
| 76 | + index_type idcNzsize; |
| 77 | + |
| 78 | + std::vector<double> dbc; |
| 79 | + index_type idx; |
| 80 | + size_type size = dirBC->nrows(); |
| 81 | + for(idx = 0; idx<size; ++idx) |
| 82 | + { |
| 83 | + index_type ni = (*dirBC)(idx, 1); |
| 84 | + double val = (*dirBC)(idx, 2); |
| 85 | + |
| 86 | + // -- getting column indices of non-zero elements for the current row |
| 87 | + mat->getRowNonzerosNoCopy(ni, idcNzsize, idcNz, valNz); |
| 88 | + |
| 89 | + // -- updating rhs |
| 90 | + for (index_type i=0; i<idcNzsize; ++i) |
| 91 | + { |
| 92 | + index_type j = idcNz ? idcNz[i] : i; |
| 93 | + (*rhs)[j] += -val * valNz[i]; |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + //! zeroing matrix row and column corresponding to the dirichlet nodes |
| 98 | + size = dirBC->nrows(); |
| 99 | + for(idx = 0; idx<size; ++idx) |
| 100 | + { |
| 101 | + index_type ni = (*dirBC)(idx, 1); |
| 102 | + double val = (*dirBC)(idx, 2); |
| 103 | + |
| 104 | + mat->getRowNonzerosNoCopy(ni, idcNzsize, idcNz, valNz); |
| 105 | + |
| 106 | + for (index_type i=0; i<idcNzsize; ++i) |
| 107 | + { |
| 108 | + index_type j = idcNz?idcNz[i]:i; |
| 109 | + mat->put(ni, j, 0.0); |
| 110 | + mat->put(j, ni, 0.0); |
| 111 | + } |
| 112 | + |
| 113 | + //! updating dirichlet node and corresponding entry in rhs |
| 114 | + mat->put(ni, ni, 1); |
| 115 | + (*rhs)[ni] = val; |
| 116 | + } |
| 117 | + |
| 118 | +} |
0 commit comments