1
// Copyright (C) 2002 Johan Hoffman and Anders Logg.
2
// Licensed under the GNU GPL Version 2.
4
#include "GlobalField.hh"
11
//-----------------------------------------------------------------------------
12
GlobalField::GlobalField(Grid *grid, real constant)
16
representation = CONSTANT;
17
this->constant = constant;
21
//-----------------------------------------------------------------------------
22
GlobalField::GlobalField(Grid *grid, Vector *x, int nvd = 1)
26
representation = NODAL;
29
no_dof = x->Size()/nvd;
32
if ( x->Size() % nvd != 0 )
33
display->InternalError("GlobalField:GlobalField",
34
"Vector dimension (%d) does not match length of vector (%d).",nvd,x->Size());
36
//-----------------------------------------------------------------------------
37
GlobalField::GlobalField(Grid *grid, const char *field)
41
representation = FUNCTION;
42
function = settings->GetFunction(field);
44
//-----------------------------------------------------------------------------
45
GlobalField::GlobalField(GlobalField *f1, GlobalField *f2)
49
if ( f1->grid != f2->grid )
50
display->InternalError("GlobalField:GlobalField()",
51
"Collection of global fields must have the same grid.");
53
representation = LIST;
56
list = new (GlobalField *)[2];
62
//-----------------------------------------------------------------------------
63
GlobalField::GlobalField(GlobalField *f1, GlobalField *f2, GlobalField *f3)
67
if ( (f1->grid != f2->grid) | (f2->grid != f3->grid) )
68
display->InternalError("GlobalField:GlobalField()",
69
"Collection of global fields must have the same grid.");
71
representation = LIST;
74
list = new (GlobalField *)[3];
81
//-----------------------------------------------------------------------------
82
GlobalField::GlobalField(GlobalField **f, int n)
87
display->InternalError("GlobalField::GlobalField()",
88
"The number of fields in a collection of fields must be positive.");
89
for (int i=0;i<(n-1);i++)
90
if ( f[i]->grid != f[i+1]->grid )
91
display->InternalError("GlobalField:GlobalField()",
92
"Collection of global fields must have the same grid.");
94
representation = LIST;
97
list = new (GlobalField *)[n];
100
for (int i=0;i<n;i++)
104
for (int i=0;i<n;i++)
105
dimensions[i] = f[i]->nvd;
107
//-----------------------------------------------------------------------------
108
GlobalField::~GlobalField()
118
//-----------------------------------------------------------------------------
119
void GlobalField::SetSize(int no_data, ...)
122
va_start(aptr,no_data);
126
output = new Output(no_data,aptr);
130
//-----------------------------------------------------------------------------
131
void GlobalField::SetLabel(const char *name, const char *label, int i = 0)
134
output = new Output(1,nvd);
136
output->SetLabel(i,name,label);
138
//-----------------------------------------------------------------------------
139
int GlobalField::GetNoDof()
143
//-----------------------------------------------------------------------------
144
int GlobalField::GetVectorDim()
148
//-----------------------------------------------------------------------------
149
int GlobalField::GetDim(int cell)
151
// FIXME: no shapefunctions does not have to be same as no nodes
152
return ( grid->GetCell(cell)->GetSize() );
154
//-----------------------------------------------------------------------------
155
void GlobalField::GetLocalDof(int cell, real t, real *local_dof, int component = 0)
157
// FIXME: no shapefunctions does not have to be same as no nodes
158
Cell *c = grid->GetCell(cell);
159
int local_dim = c->GetSize();
161
switch( representation ){
163
for (int i=0;i<local_dim;i++)
164
local_dof[i] = dof_values->Get(grid->GetCell(cell)->GetNode(i)*nvd + component);
167
for (int i=0;i<local_dim;i++)
168
local_dof[i] = constant;
172
// Return zero if the function is not specified
174
for (int i=0;i<local_dim;i++)
179
// Get the value from the function
181
for (int i=0;i<local_dim;i++){
182
p = grid->GetNode(c->GetNode(i))->GetCoord();
183
local_dof[i] = function(p.x,p.y,p.z,t);
188
display->InternalError("GlobalField::GetLocalDof()","Not available for collection of fields.");
191
display->InternalError("GlobalField::GetLocalDof()","GlobalField is not initialized");
194
display->InternalError("GlobalField::GetLocalDof()","Unknown representation for GlobalField: %d",representation);
198
//-----------------------------------------------------------------------------
199
void GlobalField::Save()
203
//-----------------------------------------------------------------------------
204
void GlobalField::Save(real t)
206
// If Output is not initialised, assume the simplest possible
208
output = new Output(1,nvd);
210
Vector **vectors = 0;
212
switch ( representation ){
214
output->AddFrame(grid,&dof_values,t);
217
vectors = new (Vector *)[listsize];
218
for (int i=0;i<listsize;i++){
219
if ( list[i]->representation != NODAL )
220
display->InternalError("GlobalField:Save()","Output for collection of fields only implemented for nodal representation.");
221
vectors[i] = list[i]->dof_values;
223
output->AddFrame(grid,vectors,t,listsize);
230
display->Message(0,"representation = %d",representation);
231
display->InternalError("GlobalField:Save()",
232
"Output only implemented for nodal representation (possibly collections).");
236
//-----------------------------------------------------------------------------
237
void GlobalField::InitCommon(Grid *grid)
241
representation = NONE;
253
sprintf(label,"unknown field");
255
//-----------------------------------------------------------------------------