1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
// This file is part of ff3d - http://www.freefem.org/ff3d
// Copyright (C) 2001, 2002, 2003 Stphane Del Pino
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// $Id: UserFunction.cpp,v 1.9 2005/04/20 22:35:44 delpinux Exp $
#include <fstream>
#include <Types.hpp>
#include <Structured3DMesh.hpp>
#include <UserFunction.hpp>
#include <Scene.hpp>
#include <FunctionExpression.hpp>
/*! Unary minus for UserFunctions
\todo Make this function virtual.
*/
UserFunction UserFunction::operator- () const
{
return UnaryMinusUserFunction(this);
}
real_t UserFunctionLanguage::operator()(const TinyVector<3>& X) const
{
return (*__function).value(X[0], X[1], X[2]);
}
void UserFunctionLanguage::gradient(TinyVector<3>& gradient,
const TinyVector<3>& X) const
{
#warning BAD TRICK TO AVOID CONST PROBLEM
FunctionExpression* f = __function;
switch((*(*f).value()).type()) {
case (FunctionExpression::fem): {
const FunctionExpressionFEM& F
= dynamic_cast<const FunctionExpressionFEM&>(*(*f).value());
gradient[0] = F.dx(X,FunctionExpressionDx::x);
gradient[1] = F.dx(X,FunctionExpressionDx::y);
gradient[2] = F.dx(X,FunctionExpressionDx::z);
break;
}
default: {
throw ErrorHandler(__FILE__,__LINE__,
"unexpected function type",
ErrorHandler::unexpected);
}
}
}
UserFunctionLanguage::
UserFunctionLanguage(UserFunctionLanguage& U)
: __function(U.__function)
{
;
}
UserFunctionLanguage::
UserFunctionLanguage(ReferenceCounting<FunctionExpression> f)
: __function(f)
{
;
}
UserFunctionLanguage::~UserFunctionLanguage()
{
;
}
//! Constructs a OneUserFunction using the POV-Ray reference \a r.
OneUserFunction::OneUserFunction(TinyVector<3>& r)
{
fferr(2) << __FILE__ << ':' << __LINE__ << ": Not Implemented\n";
/*
extern Scene* CurrentScene;
for (size_t i =0; i<CurrentScene->NbObj() ; i++) {
if (CurrentScene->Objects(i).Ref() == r)
o.push_back(&(CurrentScene->Objects(i)));
}
if (o.size() == 0)
fferr(2) << "warning: no object in the Scene has reference " << r << '\n';
*/
}
//! Evalutes \f$ 1_{\cup_i o_i} \f$ at point \a X.
real_t OneUserFunction::operator()(const TinyVector<3>& X) const
{
for (size_t i=0; i<o.size(); i++)
if (o[i]->inside(X))
return 1;
return 0;
}
//! Constructor.
OneMeshUserFunction::OneMeshUserFunction(ConstReferenceCounting<Structured3DMesh> givenMesh)
: __mesh(givenMesh)
{
;
}
//! Destructor.
OneMeshUserFunction::~OneMeshUserFunction()
{
;
}
real_t OneDomainUserFunction::operator()(const TinyVector<3>& x) const
{
return (*__domain).inside(x);
}
OneDomainUserFunction::
OneDomainUserFunction(ConstReferenceCounting<Domain> domain)
: __domain(domain)
{
;
}
OneDomainUserFunction::~OneDomainUserFunction()
{
;
}
//! Evalutes the characteristic function of the \a mesh at point \a X
real_t OneMeshUserFunction::operator()(const TinyVector<3>& X) const
{
return ((*__mesh).inside(X));
}
//! Constructs a FEM0UserFunction using a pointer on a Structured3DMesh and a UserFunction
FEM0UserFunction::FEM0UserFunction(ReferenceCounting<Mesh> pmesh,
const Vector<real_t>& F)
: __mesh(pmesh),
__values(F)
{
assert((*__mesh).numberOfCells() == __values.size());
}
/*!
Constructs a FEM0UserFunction using a pointer on a Structured3DMesh and a Vector of data.
\warning Will have to change this for the vectorial case.
*/
FEM0UserFunction::FEM0UserFunction(ReferenceCounting<Mesh> pmesh, const UserFunction& F)
: __mesh(pmesh),
__values((*__mesh).numberOfVertices())
{
throw ErrorHandler(__FILE__,__LINE__,
"not implemented",
ErrorHandler::unexpected);
}
//! Constructs a FEM0UserFunction using a pointer on a Structured3DMesh and a real_t
FEM0UserFunction::FEM0UserFunction(ReferenceCounting<Mesh> pmesh, const real_t d)
: __mesh(pmesh),
__values((*__mesh).numberOfVertices())
{
__values = d;
}
//! Evaluates the FEM0UserFunction at point \a X.
real_t FEM0UserFunction::operator()(const TinyVector<3>& V) const
{
switch((*__mesh).type()) {
case Mesh::cartesianHexahedraMesh: {
const Structured3DMesh& mesh = static_cast<const Structured3DMesh&>(*__mesh);
Structured3DMesh::const_iterator icell = mesh.find(V);
if (not(icell.end())) {
assert(icell.number() < __values.size());
return __values(icell.number());
} else {
return 0;
}
break;
}
default: {
throw ErrorHandler(__FILE__,__LINE__,
"unexpected mesh type",
ErrorHandler::unexpected);
}
}
return 0;
}
//! Affects a \a Vector of data to the FEM0UserFunction.
void FEM0UserFunction::operator=(Vector<real_t>& u)
{
assert(__values.size() == u.size());
__values = u;
}
FEM0UserFunction::~FEM0UserFunction()
{
;
}
|