MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_RigidBodyModeFactory_def.hpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// MueLu: A package for multigrid based preconditioning
6// Copyright 2013 Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact
39// Jonathan Hu (jhu@sandia.gov)
40// Andrey Prokopenko (aprokop@sandia.gov)
41// Ray Tuminaro (rstumin@sandia.gov)
42//
43// ***********************************************************************
44//
45// @HEADER
46#ifndef MUELU_RIGIDBODYMODEFACTORY_DEF_HPP
47#define MUELU_RIGIDBODYMODEFACTORY_DEF_HPP
48
49#include <Xpetra_Matrix.hpp>
50#include <Xpetra_MultiVectorFactory.hpp>
51#include <Xpetra_VectorFactory.hpp>
52
54#include "MueLu_Level.hpp"
55#include "MueLu_Monitor.hpp"
56
57namespace MueLu {
58
59 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
61
62 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
64 if (currentLevel.IsAvailable(nspName_, NoFactory::get()) == false && currentLevel.GetLevelID() == 0) {
65 Input(currentLevel, "A");
66 //Input(currentLevel,"Coordinates");
67 }
68 if (currentLevel.GetLevelID() !=0) {
69 currentLevel.DeclareInput("Nullspace", GetFactory(nspName_).get(), this); /* ! "Nullspace" and nspName_ mismatch possible here */
70 }
71 }
72
73 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
75 FactoryMonitor m(*this, "Rigid body mode factory", currentLevel);
76 RCP<MultiVector> nullspace;
77 if (currentLevel.GetLevelID() == 0) {
78 if (currentLevel.IsAvailable(nspName_, NoFactory::get())) {
79 nullspace = currentLevel.Get< RCP<MultiVector> >(nspName_, NoFactory::get());
80 GetOStream(Runtime1) << "Use user-given rigid body modes " << nspName_ << ": nullspace dimension=" << nullspace->getNumVectors() << " nullspace length=" << nullspace->getGlobalLength() << std::endl;
81 }
82 else {
83 RCP<Matrix> A = Get< RCP<Matrix> >(currentLevel, "A");
84 GetOStream(Runtime1) << "Generating rigid body modes: dimension = " << numPDEs_ << std::endl;
85 RCP<const Map> xmap=A->getDomainMap();
86 if(numPDEs_==1) { nullspace = MultiVectorFactory::Build(xmap, 1); }
87 else if(numPDEs_==2) { nullspace = MultiVectorFactory::Build(xmap, 3); }
88 else if(numPDEs_==3) { nullspace = MultiVectorFactory::Build(xmap, 6); }
89 Scalar zero(0.0);
90 nullspace -> putScalar(zero);
91 RCP<MultiVector> Coords = Get< RCP<MultiVector> >(currentLevel,"Coordinates");
92 ArrayRCP<Scalar> xnodes, ynodes, znodes;
93 Scalar cx, cy, cz;
94 ArrayRCP<Scalar> nsValues0, nsValues1, nsValues2, nsValues3, nsValues4, nsValues5;
95 int nDOFs=xmap->getLocalNumElements();
96 if(numPDEs_==1) {
97 nsValues0 = nullspace->getDataNonConst(0);
98 for(int j=0; j<nDOFs; j++) {
99 // constant null space for scalar PDE
100 nsValues0[j]=1.0;
101 }
102 }
103 else if(numPDEs_==2) {
104 xnodes = Coords->getDataNonConst(0);
105 ynodes = Coords->getDataNonConst(1);
106 cx = Coords->getVector(0)->meanValue();
107 cy = Coords->getVector(1)->meanValue();
108 nsValues0 = nullspace->getDataNonConst(0);
109 nsValues1 = nullspace->getDataNonConst(1);
110 nsValues2 = nullspace->getDataNonConst(2);
111 for (int j=0; j<nDOFs; j+=numPDEs_) {
112 // translation
113 nsValues0[j+0] = 1.0;
114 nsValues1[j+1] = 1.0;
115 // rotate around z-axis (x-y plane)
116 nsValues2[j+0] = -(ynodes[j]-cy);
117 nsValues2[j+1] = (xnodes[j]-cx);
118 }
119 }
120 else if(numPDEs_==3) {
121 xnodes = Coords->getDataNonConst(0);
122 ynodes = Coords->getDataNonConst(1);
123 znodes = Coords->getDataNonConst(2);
124 cx = Coords->getVector(0)->meanValue();
125 cy = Coords->getVector(1)->meanValue();
126 cz = Coords->getVector(2)->meanValue();
127 nsValues0 = nullspace->getDataNonConst(0);
128 nsValues1 = nullspace->getDataNonConst(1);
129 nsValues2 = nullspace->getDataNonConst(2);
130 nsValues3 = nullspace->getDataNonConst(3);
131 nsValues4 = nullspace->getDataNonConst(4);
132 nsValues5 = nullspace->getDataNonConst(5);
133 for (int j=0; j<nDOFs; j+=numPDEs_) {
134 // translation
135 nsValues0[j+0] = 1.0;
136 nsValues1[j+1] = 1.0;
137 nsValues2[j+2] = 1.0;
138 // rotate around z-axis (x-y plane)
139 nsValues3[j+0] = -(ynodes[j]-cy);
140 nsValues3[j+1] = (xnodes[j]-cx);
141 // rotate around x-axis (y-z plane)
142 nsValues4[j+1] = -(znodes[j]-cz);
143 nsValues4[j+2] = (ynodes[j]-cy);
144 // rotate around y-axis (x-z plane)
145 nsValues5[j+0] = (znodes[j]-cz);
146 nsValues5[j+2] = -(xnodes[j]-cx);
147 }
148 }
149 } // end if "Nullspace" not available
150 }
151 else {
152 nullspace = currentLevel.Get< RCP<MultiVector> >("Nullspace", GetFactory(nspName_).get());
153 }
154 Set(currentLevel, "Nullspace", nullspace);
155 }
156
157} // namespace MueLu
158
159#define MUELU_RIGIDBODYMODEFACTORY_SHORT
160#endif // MUELU_RIGIDBODYMODEFACTORY_DEF_HPP
MueLu::DefaultScalar Scalar
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:99
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
int GetLevelID() const
Return level number.
Definition: MueLu_Level.cpp:76
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
static const NoFactory * get()
void Build(Level &currentLevel) const
Build an object with this factory.
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.
Namespace for MueLu classes and methods.
@ Runtime1
Description of what is happening (more verbose)