////////////////////////////////////////////////////////////////////////////////
// 
// Volumes.cc
//
//    produced: 18/02/2020 jr
// 
////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <ctype.h>
#include <string.h>

#include "ConfData.hh"
#include "Permutation.hh"
#include "Volumes.hh"

namespace topcom {

  Volumes::Volumes(const ConfData& confdata) :
    volumes_data(),
    _min_volume(Field(std::numeric_limits<size_type>::max())) {
    if (!confdata.has_points()) {
      MessageStreams::forced() << message::lock
			       << "Volumes::Volumes(const ConfData&): points needed for volumes - exiting." << std::endl
			       << message::unlock;
      exit(1);
    }
    size_type count(0);
    const size_type no(confdata.no());
    const size_type rank(confdata.rank());
    Permutation perm(no, rank);
    do {
      Simplex simp(perm);
      Field simp_vol;
      if (confdata.has_chiro()) {
	simp_vol = abs(confdata.chiro().det(simp));
      }
      else {
	simp_vol = confdata.points().volume(simp);
      }
      if (simp_vol != FieldConstants::ZERO) {
	(*this)[simp] = simp_vol;
	if (simp_vol < _min_volume) {
	  _min_volume = simp_vol;
	}
      }
    } while (perm.lexnext());
    MessageStreams::verbose() << message::lock
			      << size() << " valid simplices." << std::endl
			      << message::unlock;
  }
  
  // stream input/output:
  std::istream& Volumes::read(std::istream& ist) {
    return (ist >> static_cast<volumes_data&>(*this));
  }

  std::ostream& Volumes::write(std::ostream& ost) const {
    return (ost << static_cast<const volumes_data&>(*this));
  }

}; // namespace topcom

// eof Volumes.cc
