Source

enzo-dev-problem-types / src / enzo / FieldContainer.C

Full commit
/***********************************************************************
/
/  FIELD CONTAINER CLASS
/
/  written by: Matthew Turk, Devin Silvia
/  date:       January 2012
/
/  PURPOSE:
/
************************************************************************/

#ifdef NEW_PROBLEM_TYPES
#include <string.h>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <iostream>
#include "ErrorExceptions.h"
#include "macros_and_parameters.h"
#include "typedefs.h"
#include "global_data.h"
#include "Fluxes.h"
#include "GridList.h"
#include "ExternalBoundary.h"
#include "Grid.h"
#include "Hierarchy.h"
#include "TopGridData.h"
#include "ProblemType.h"
#include "EventHooks.h"

FieldContainer::FieldContainer()
{
    return;
}

FieldContainer::FieldContainer(FieldContainer *fields)
{
    std::map<std::string, float>::iterator it;
    std::string field_name;
    for(it = fields->start(); it != fields->end(); it++)
    {
        field_name = (*it).first;
        this->AddField(field_name, fields->field_numbers[field_name],
                        (*fields)[field_name]);
    }
}

void FieldContainer::AddField(std::string field_name, int FieldNumber,
                               float value)
{
    if (this->field_values.count(field_name) != 0)
        ENZO_VFAIL("Tried to reset default for %s", field_name.c_str())
    this->field_values[field_name] = value;
    this->field_numbers[field_name] = FieldNumber;
    this->field_names.push_back(field_name);
    return;
}

void FieldContainer::Clear()
{
    for (std::map<std::string, float>::iterator it =
            this->field_values.begin();
         it != this->field_values.end();
         it++)
    {
        this->field_values[it->first] = 0.0;
    }
    return;
}

int FieldContainer::Needs(std::string field_name)
{
    if (this->field_values.count(field_name) == 0) return FALSE;
    else return TRUE;
}

float& FieldContainer::operator[](std::string field_name)
{
    if (this->field_values.count(field_name) == 0)
        ENZO_VFAIL("Asked for %s but it did not exist as a field.", field_name.c_str())
    return this->field_values[field_name];
}

std::map<std::string, float>::iterator FieldContainer::start()
{
    return this->field_values.begin();
}

std::map<std::string, float>::iterator FieldContainer::end()
{
    return this->field_values.end();
}

void FieldContainer::SetupGrid(ProblemTypeGrid *thisgrid)
{
    /* We get our size ... */
    int size = 1, dim;
    for (dim = 0; dim < thisgrid->GridRank; dim++)
      size *= thisgrid->GridDimension[dim];

    /* Here we add on all the appropriate field numbers and whatnot. */
    thisgrid->NumberOfBaryonFields = 0;
    std::vector<std::string>::iterator it;
    for (it = this->field_names.begin();
         it != this->field_names.end();
         it++)
    {
      thisgrid->FieldType[thisgrid->NumberOfBaryonFields] =
        this->field_numbers[(*it)];
      thisgrid->BaryonField[thisgrid->NumberOfBaryonFields++] =
        new float[size];
    }
    return;
}

void FieldContainer::SetupDataLabels(EnzoProblemType *ptype)
{
    std::vector<std::string>::iterator it;
    for (it = this->field_names.begin();
         it != this->field_names.end();
         it++)
    {
        ptype->AddDataLabel((*it).c_str());
    }
}

void FieldContainer::Apply(ProblemTypeGrid *thisgrid, int cellindex)
{
    
    return;
}

#endif