Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "TSFPoissonBoltzmannOp.hpp"
00030
00031
00032 #ifndef HAVE_TEUCHOS_EXPLICIT_INSTANTIATION
00033 #include "TSFVectorImpl.hpp"
00034 #include "TSFLinearOperatorImpl.hpp"
00035 #endif
00036
00037 using namespace TSFExtended;
00038 using namespace Teuchos;
00039
00040
00041 PoissonBoltzmannOp::PoissonBoltzmannOp(int nLocal, const VectorType<double>& vecType)
00042 : NonlinearOperatorBase<double>(), J_(nLocal, vecType), importer_(),
00043 uLeftBC_(0.0), uRightBC_(2.0*log(cosh(1.0/sqrt(2.0))))
00044 {
00045 setDomainAndRange(J_.domain(), J_.range());
00046
00047 int rank = MPIComm::world().getRank();
00048 int nProc = MPIComm::world().getNProc();
00049 if (nProc > 1)
00050 {
00051 Array<int> ghosts;
00052 int low = J_.domain().lowestLocallyOwnedIndex();
00053 int high = low + J_.domain().numLocalElements();
00054 if (rank != nProc - 1)
00055 {
00056 ghosts.append(high);
00057 }
00058 if (rank != 0)
00059 {
00060 ghosts.append(low-1);
00061 }
00062
00063 importer_ = vecType.createGhostImporter(J_.domain(), ghosts.size(), &(ghosts[0]));
00064 }
00065 else
00066 {
00067 importer_ = vecType.createGhostImporter(J_.domain(), 0, 0);
00068 }
00069 }
00070
00071 Vector<double> PoissonBoltzmannOp::getInitialGuess() const
00072 {
00073 Vector<double> rtn = J_.domain().createMember();
00074
00075 rtn.setToConstant(0.5);
00076
00077 return rtn;
00078 }
00079
00080
00081 LinearOperator<double>
00082 PoissonBoltzmannOp::computeJacobianAndFunction(Vector<double>& functionValue) const
00083 {
00084 J_.setEvalPoint(currentEvalPt());
00085
00086 RCP<GhostView<double> > u;
00087 importer_->importView(currentEvalPt(), u);
00088
00089 int low = J_.domain().lowestLocallyOwnedIndex();
00090 int high = low + J_.domain().numLocalElements();
00091
00092 functionValue = J_.range().createMember();
00093 double h= J_.h();
00094
00095 for (int r=low; r<high; r++)
00096 {
00097 double u_i = u->getElement(r);
00098 double f = 0.0;
00099 if (r==0)
00100 {
00101 f = u_i - uLeftBC_;
00102 }
00103 else if (r==J_.domain().dim()-1)
00104 {
00105 f = u_i - uRightBC_;
00106 }
00107 else
00108 {
00109 double u_plus = u->getElement(r+1);
00110 double u_minus = u->getElement(r-1);
00111 f = (u_plus + u_minus - 2.0*u_i)/h/h - exp(-u_i);
00112 }
00113 functionValue.setElement(r, f);
00114 }
00115
00116 return J_.getOp();
00117 }
00118
00119 Vector<double> PoissonBoltzmannOp::exactSoln() const
00120 {
00121 Vector<double> rtn = J_.domain().createMember();
00122
00123 int low = J_.domain().lowestLocallyOwnedIndex();
00124 int high = low + J_.domain().numLocalElements();
00125 double h= J_.h();
00126
00127 for (int r=low; r<high; r++)
00128 {
00129 double x = r*h;
00130 double u = 2.0*log(cosh(x/sqrt(2.0)));
00131 std::cerr << x << " " << u << std::endl;
00132 rtn.setElement(r, u);
00133 }
00134
00135 return rtn;
00136 }
00137